pgkamtools

package module
v0.0.0-...-b364457 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 13 Imported by: 0

README

pgparse

pgkamtools is Part of pgrtools. See main repo for license/warranty (tl;dr MIT).

pgkamtools is designed to help with commonly needed jsonrpc calls to kamailio.

Documentation Welcome

Documentation / contributions gladly accepted.

Background

pgkamtools expects a JSONRPC listener on Kamailio via http. Such as...

...
loadmodule "jsonrpcs.so"
loadmodule "xhttp.so"
...
modparam("jsonrpcs", "pretty_format", 1)
modparam("jsonrpcs", "transport", 1)
...
event_route[xhttp:request] {
	if ($hu =~ "^/RPC") {
		jsonrpc_dispatch();
		exit;
	} else {
		xhttp_reply("404", "NOT FOUND", "text/html", "$<html><body>404 - $hu [$si:$sp]</body></html>\n");
		exit;
	}

	return;
}

Functions

CheckFields

Expects

  • map[string]string (values from form, etc)
  • []string (list of required fields)

Returns

  • bool
  • error
Example
body, err := ioutil.ReadAll(r.Body)
...
keyVal := pgparse.LowerKeys(pgparse.ParseBody(body))
...
_, err = pgkamtools.CheckFields(keyVal, []string{"group","address","url"})
...

(returns true if group, address, url are in keyVal)

DispatcherAdd

See Kamailio RPC dispatcher.add documentation.

Expects

  • group (string)
  • address (string)
  • url (string) (url for kamailio rpc)

Returns

  • json string (result from kamailio)
  • error
DispatcherList

Returns all dispatcher info from kamailio

Expects

  • url (string) (url for kamailio rpc)
DispatcherListSimple

Returns simplified list of dispatcher nodes

Expects

  • url (string) (url for kamailio rpc)
DispatcherListByGroup

Expects

  • url (string) (url for kamailio rpc)

Returns

  • string (json)
  • error

Example response:

[{"id":38,"nodes":[{"uri":"sip:172.16.1.1:5060","flags":"AP","priority":20},{"uri":"sip:172.16.0.1:5060","flags":"AP","priority":20}]}]

DispatcherRemove

Expects

  • group (string)
  • address (string)
  • url (string) (url for kamailio rpc)

Returns

  • string
  • error
HtableDelete

Deletes a key from htables

Expects

  • htable (string)
  • key (string)
  • url (string) (url for kamailio rpc)

Returns

  • bool
  • error

Example

_, err := pgkamtools.HtableDelete("ipban","1.1.1.1","http://localhost/RPC")
HtableDump

Expects

  • htable (string)
  • url (string) (url for kamailio rpc)

Returns

  • string (json)
  • error

Example

jsonData, err := pgkamtools.HtableDump("ipban","http://localhost/RPC")
HtableFlush
HtableGet
HtableSetInt
HtableSetString
HtableParseNameOnly
HtableParseNameValue
HtableParseValueOnly
HtableParseValueOnly
RegDeleteAOR
RegGetAOR
RegAorParse
RegsAors
RegsFullContactInfo
RegsGet
RegsSimpleParse
RegsTotal
RemoveDuplicatesUnordered
SendJsonhttp
SendJsonhttpTimeout
SendJsonhttpIgnoreCert
SendJsonhttpIgnoreCertTimeout
SendGethttp
SendGethttpIgnoreCert
SendGethttpIgnoreCertTimeout
Uptime
UptimeParse
Version
VersionParse
getId
formatLastModifed

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFields

func CheckFields(mapstring map[string]string, reqfields []string) (bool, error)

func DispatcherAdd

func DispatcherAdd(groupval string, addressval string, urlval string) (string, error)

func DispatcherList

func DispatcherList(urlval string) (string, error)

func DispatcherListByGroup

func DispatcherListByGroup(urlval string) (string, error)

func DispatcherListSimple

func DispatcherListSimple(urlval string) (string, error)

func DispatcherRemove

func DispatcherRemove(groupval string, addressval string, urlval string) (string, error)

func HtableDelete

func HtableDelete(tableval string, keyval string, urlval string) (bool, error)

func HtableDump

func HtableDump(tableval string, urlval string) (string, error)

func HtableFlush

func HtableFlush(tableval string, urlval string) (bool, error)

func HtableGet

func HtableGet(tableval string, keyval string, urlval string) (string, error)

func HtableParseNameOnly

func HtableParseNameOnly(jsonval string) (string, error)

func HtableParseNameValue

func HtableParseNameValue(jsonval string) (string, error)

func HtableParseValueOnly

func HtableParseValueOnly(jsonval string) (string, error)

func HtableParseValueSingle

func HtableParseValueSingle(jsonval string) (string, error)

func HtableSetInt

func HtableSetInt(tableval string, keyval string, valval string, urlval string) (bool, error)

changed 2023-01-18 to treat string as int in json for seti.

func HtableSetString

func HtableSetString(tableval string, keyval string, valval string, urlval string) (bool, error)

func RegAorParse

func RegAorParse(jsonval string) (string, error)

func RegDeleteAOR

func RegDeleteAOR(aorval string, urlval string) (bool, error)

func RegGetAOR

func RegGetAOR(aorval string, urlval string) (string, error)

func RegsAors

func RegsAors(jsonval string) (string, error)

func RegsFullContactInfo

func RegsFullContactInfo(jsonval string) (string, error)

func RegsGet

func RegsGet(urlval string) (string, error)

func RegsSimpleParse

func RegsSimpleParse(jsonval string) (string, error)

func RegsTotal

func RegsTotal(jsonval string) (string, error)

func RemoveDuplicatesUnordered

func RemoveDuplicatesUnordered(elements []string) []string

func SendGethttp

func SendGethttp(urlstr string) (string, error)

send a get request via http and return the response

func SendGethttpIgnoreCert

func SendGethttpIgnoreCert(urlstr string) (string, error)

func SendGethttpIgnoreCertTimeout

func SendGethttpIgnoreCertTimeout(urlstr string, seconds time.Duration) (string, error)

func SendJsonhttp

func SendJsonhttp(jsonstr string, urlstr string) (string, error)

func SendJsonhttpIgnoreCert

func SendJsonhttpIgnoreCert(jsonstr string, urlstr string) (string, error)

func SendJsonhttpIgnoreCertTimeout

func SendJsonhttpIgnoreCertTimeout(jsonstr string, urlstr string, seconds time.Duration) (string, error)

func SendJsonhttpTimeout

func SendJsonhttpTimeout(jsonstr string, urlstr string, seconds time.Duration) (string, error)

func Uptime

func Uptime(urlval string) (string, error)

func UptimeParse

func UptimeParse(jsonval string) (string, error)

func Version

func Version(urlval string) (string, error)

func VersionParse

func VersionParse(jsonval string) (string, error)

Types

type StructAoRParse

type StructAoRParse struct {
	AoR          json.RawMessage `json:"aor"`
	Address      json.RawMessage `json:"address"`
	Expires      json.RawMessage `json:"expires"`
	UA           json.RawMessage `json:"user-agent"`
	LastModified string          `json:"last-modified"`
}

type StructHtableDump

type StructHtableDump struct {
	Jsonrpc string          `json:"jsonrpc"`
	Id      json.RawMessage `json:"id"`
	Result  []struct {
		Entry any `json:"entry"`
		Size  any `json:"size"`
		Slot  []struct {
			Name  json.RawMessage `json:"name"`
			Value json.RawMessage `json:"value"`
			Type  string          `json:"type"`
		} `json:"slot"`
	} `json:"result"`
}

type StructName

type StructName struct {
	Name json.RawMessage `json:"name"`
}

type StructNameValue

type StructNameValue struct {
	Name  json.RawMessage `json:"name"`
	Value json.RawMessage `json:"value"`
}

type StructUserDump

type StructUserDump struct {
	Jsonrpc json.RawMessage `json:"jsonrpc"`
	Id      json.RawMessage `json:"id"`
	Result  struct {
		Domains []struct {
			Domain struct {
				Domain json.RawMessage `json:"Domain"`
				Size   json.RawMessage `json:"Size"`
				AoRs   []struct {
					Info struct {
						AoR      json.RawMessage `json:"AoR"`
						HashID   json.RawMessage `json:"HashID"`
						Contacts []struct {
							Contact struct {
								Address       json.RawMessage `json:"Address,omitempty"`
								Expires       json.RawMessage `json:"Expires,omitempty"`
								Q             json.RawMessage `json:"Q,omitempty"`
								CallID        json.RawMessage `json:"Call-ID,omitempty"`
								CSeq          json.RawMessage `json:"CSeq,omitempty"`
								UserAgent     json.RawMessage `json:"User-Agent,omitempty"`
								Received      json.RawMessage `json:"Received,omitempty"`
								Path          json.RawMessage `json:"Path,omitempty"`
								Socket        json.RawMessage `json:"Socket,omitempty"`
								Methods       json.RawMessage `json:"Methods,omitempty"`
								Ruid          json.RawMessage `json:"Ruid,omitempty"`
								Instance      json.RawMessage `json:"Instance,omitempty"`
								RegID         json.RawMessage `json:"Reg-Id,omitempty"`
								ServerID      json.RawMessage `json:"Server-Id,omitempty"`
								TcpconID      json.RawMessage `json:"Tcpconn-Id,omitempty"`
								Keepalive     json.RawMessage `json:"Keepalive,omitempty"`
								LastKeepAlive json.RawMessage `json:"Last-Keepalive,omitempty"`
								KARoundtrip   json.RawMessage `json:"KA-Roundtrip,omitempty"`
								LastModified  json.RawMessage `json:"Last-Modified,omitempty"`
							} `json:"Contact"`
						} `json:"Contacts"`
					} `json:"Info"`
				} `json:"AoRs"`
				Stats struct {
					Records  json.RawMessage `json:"Records"`
					MaxSlots json.RawMessage `json:"Max-Slots"`
				} `json:"Stats"`
			} `json:"Domain"`
		} `json:"Domains"`
	} `json:"result"`
}

type StructValue

type StructValue struct {
	Value json.RawMessage `json:"value"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL