Browse Source

Adding UacRegReload command

master
DanB 10 years ago
parent
commit
7e1aa2ec11
2 changed files with 33 additions and 3 deletions
  1. +19
    -2
      kamjsonrpc.go
  2. +14
    -1
      kamjsonrpc_local_test.go

+ 19
- 2
kamjsonrpc.go View File

@ -11,6 +11,7 @@ import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
@ -24,11 +25,17 @@ type KamJsonRpcRequest struct {
Id uint64 `json:"id"`
}
// {"jsonrpc":"2.0","error":{"code":-32000,"message":"Execution Error"},"id":0}
type KamError struct {
Code int `json:"code"`
Message string `json:"message"`
}
type KamJsonRpcResponse struct {
Jsonrpc string `json:"jsonrpc"`
Id uint64 `json:"id"`
Result *json.RawMessage `json:"result"`
Error error `json:"error"`
Error *KamError `json:"error"`
}
func NewKamailioJsonRpc(url string, skipTlsVerify bool) (*KamailioJsonRpc, error) {
@ -77,7 +84,7 @@ func (self *KamailioJsonRpc) Call(serviceMethod string, args interface{}, reply
return err
}
if kamResponse.Error != nil {
return kamResponse.Error
return errors.New(kamResponse.Error.Message)
}
if resp.StatusCode > 299 {
return fmt.Errorf("Unexpected status code received: %d", resp.StatusCode)
@ -90,6 +97,16 @@ func (self *KamailioJsonRpc) Call(serviceMethod string, args interface{}, reply
}
// Add inidividual methods over the generic one
func (self *KamailioJsonRpc) UacRegReload(params []string, reply *string) error {
var regRaw json.RawMessage
if err := self.Call("uac.reg_reload", params, &regRaw); err != nil {
return err
}
*reply = "OK"
return nil
}
type RegistrationInfo struct {
LocalUuid string `json:"l_uuid"`
LocalUsername string `json:"l_username"`


+ 14
- 1
kamjsonrpc_local_test.go View File

@ -27,13 +27,26 @@ func TestKamJsonRpcCall(t *testing.T) {
return
}
var reply json.RawMessage
if err := kamRpc.Call("uac.reg_info", []string{"l_uuid", "unknown"}, &reply); err != nil {
if err := kamRpc.Call("core.psx", []string{}, &reply); err != nil {
t.Error(err)
} else if reflect.DeepEqual(reply, json.RawMessage{}) {
t.Error("Empty reply")
}
}
func TestKamJsonRpcUacRegReload(t *testing.T) {
if !*testLocal {
return
}
eReply := "OK"
var reply string
if err := kamRpc.UacRegReload([]string{}, &reply); err != nil {
t.Error(err)
} else if eReply != reply {
t.Errorf("Expecting: %s, received: %s", eReply, reply)
}
}
func TestKamJsonRpcUacRegInfo(t *testing.T) {
if !*testLocal {
return


Loading…
Cancel
Save