Skip to content

Commit

Permalink
xcap_client: port MI commands to jsonrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Jan 10, 2019
1 parent 3c3fac8 commit ea5296f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
4 changes: 2 additions & 2 deletions modules/xcap_client/doc/xcap_client_admin.xml
Expand Up @@ -146,10 +146,10 @@ modparam("xcap_client", "query_period", 50)
<para>Parameters:</para>
<itemizedlist>
<listitem>
<para>document uri: the uri of the document</para>
<para>doc_uri: the uri of the document</para>
</listitem>
<listitem>
<para>xcap server port: the port of the xcap server</para>
<para>port: the port of the xcap server</para>
</listitem>
</itemizedlist>

Expand Down
43 changes: 16 additions & 27 deletions modules/xcap_client/xcap_client.c
Expand Up @@ -54,7 +54,8 @@
static int mod_init(void);
static int child_init(int);
void destroy(void);
struct mi_root* refreshXcapDoc(struct mi_root* cmd, void* param);
mi_response_t *refreshXcapDoc(const mi_params_t *params,
struct mi_handler *async_hdl);
int get_auid_flag(str auid);
xcap_callback_t* xcapcb_list= NULL;
int periodical_query= 1;
Expand Down Expand Up @@ -96,8 +97,11 @@ static cmd_export_t cmds[]=
};

static mi_export_t mi_cmds[] = {
{ "refreshXcapDoc", 0, refreshXcapDoc, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0}
{ "refreshXcapDoc", 0, 0, 0, {
{refreshXcapDoc, {"doc_uri", "port", 0}},
{EMPTY_MI_RECIPE}}
},
{EMPTY_MI_EXPORT}
};

static dep_export_t deps = {
Expand Down Expand Up @@ -380,43 +384,28 @@ int parse_doc_url(str doc_url, char** serv_addr, xcap_doc_sel_t* doc_sel)
* <xcap_port>
* */

struct mi_root* refreshXcapDoc(struct mi_root* cmd, void* param)
mi_response_t *refreshXcapDoc(const mi_params_t *params,
struct mi_handler *async_hdl)
{
struct mi_node* node= NULL;
str doc_url;
xcap_doc_sel_t doc_sel;
char* serv_addr;
str stream= {0, 0};
int type;
unsigned int xcap_port;
int xcap_port;
char* etag= NULL;

node = cmd->node.kids;
if(node == NULL)
return 0;
if (get_mi_string_param(params, "doc_uri", &doc_url.s, &doc_url.len) < 0)
return init_mi_param_error();

doc_url = node->value;
if(doc_url.s == NULL || doc_url.len== 0)
{
LM_ERR("empty uri\n");
return init_mi_tree(404, "Empty document URL", 20);
}
node= node->next;
if(node== NULL)
return 0;
if(node->value.s== NULL || node->value.len== 0)
{
LM_ERR("port number\n");
return init_mi_tree(404, "Empty document URL", 20);
}
if(str2int(&node->value, &xcap_port)< 0)
{
LM_ERR("while converting string to int\n");
goto error;
return init_mi_error(404, MI_SSTR("Empty document URL"));
}

if(node->next!= NULL)
return 0;
if (get_mi_int_param(params, "port", &xcap_port) < 0)
return init_mi_param_error();

/* send GET HTTP request to the server */
stream.s = send_http_get(doc_url.s, xcap_port, NULL, 0, &etag, &stream.len);
Expand Down Expand Up @@ -444,7 +433,7 @@ struct mi_root* refreshXcapDoc(struct mi_root* cmd, void* param)
run_xcap_update_cb(type, doc_sel.xid, stream.s);
pkg_free(stream.s);

return init_mi_tree(200, "OK", 2);
return init_mi_result_ok();

error:
if(stream.s)
Expand Down

0 comments on commit ea5296f

Please sign in to comment.