|
@@ -37,87 +37,79 @@
|
|
|
#include "../presence/hash.h"
|
|
|
|
|
|
|
|
|
-#define ETAG_HDR "Etag: "
|
|
|
-#define ETAG_HDR_LEN strlen("Etag: ")
|
|
|
+#define ETAG_HDR "Etag: "
|
|
|
+#define ETAG_HDR_LEN strlen("Etag: ")
|
|
|
|
|
|
-size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream);
|
|
|
-char* get_xcap_path(xcap_get_req_t req);
|
|
|
+size_t write_function(void *ptr, size_t size, size_t nmemb, void *stream);
|
|
|
+char *get_xcap_path(xcap_get_req_t req);
|
|
|
|
|
|
-int bind_xcap(xcap_api_t* api)
|
|
|
+int bind_xcap(xcap_api_t *api)
|
|
|
{
|
|
|
- if (!api)
|
|
|
- {
|
|
|
+ if(!api) {
|
|
|
LM_ERR("Invalid parameter value\n");
|
|
|
return -1;
|
|
|
}
|
|
|
- api->int_node_sel= xcapInitNodeSel;
|
|
|
- api->add_step= xcapNodeSelAddStep;
|
|
|
- api->add_terminal= xcapNodeSelAddTerminal;
|
|
|
- api->free_node_sel= xcapFreeNodeSel;
|
|
|
- api->register_xcb= register_xcapcb;
|
|
|
- api->getNewDoc= xcapGetNewDoc;
|
|
|
+ api->int_node_sel = xcapInitNodeSel;
|
|
|
+ api->add_step = xcapNodeSelAddStep;
|
|
|
+ api->add_terminal = xcapNodeSelAddTerminal;
|
|
|
+ api->free_node_sel = xcapFreeNodeSel;
|
|
|
+ api->register_xcb = register_xcapcb;
|
|
|
+ api->getNewDoc = xcapGetNewDoc;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-void xcapFreeNodeSel(xcap_node_sel_t* node)
|
|
|
+void xcapFreeNodeSel(xcap_node_sel_t *node)
|
|
|
{
|
|
|
- step_t* s, *p;
|
|
|
- ns_list_t* n, *m;
|
|
|
-
|
|
|
- s= node->steps;
|
|
|
- while(s)
|
|
|
- {
|
|
|
- p= s;
|
|
|
- s= s->next;
|
|
|
+ step_t *s, *p;
|
|
|
+ ns_list_t *n, *m;
|
|
|
+
|
|
|
+ s = node->steps;
|
|
|
+ while(s) {
|
|
|
+ p = s;
|
|
|
+ s = s->next;
|
|
|
pkg_free(p->val.s);
|
|
|
pkg_free(p);
|
|
|
}
|
|
|
|
|
|
- n= node->ns_list;
|
|
|
- while(n)
|
|
|
- {
|
|
|
- m= n;
|
|
|
- n= n->next;
|
|
|
+ n = node->ns_list;
|
|
|
+ while(n) {
|
|
|
+ m = n;
|
|
|
+ n = n->next;
|
|
|
pkg_free(m->value.s);
|
|
|
pkg_free(m);
|
|
|
}
|
|
|
|
|
|
pkg_free(node);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-xcap_node_sel_t* xcapInitNodeSel(void)
|
|
|
+xcap_node_sel_t *xcapInitNodeSel(void)
|
|
|
{
|
|
|
- xcap_node_sel_t* nsel= NULL;
|
|
|
+ xcap_node_sel_t *nsel = NULL;
|
|
|
|
|
|
- nsel= (xcap_node_sel_t*)pkg_malloc(sizeof(xcap_node_sel_t));
|
|
|
- if(nsel== NULL)
|
|
|
- {
|
|
|
+ nsel = (xcap_node_sel_t *)pkg_malloc(sizeof(xcap_node_sel_t));
|
|
|
+ if(nsel == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
memset(nsel, 0, sizeof(xcap_node_sel_t));
|
|
|
- nsel->steps= (step_t*)pkg_malloc(sizeof(step_t));
|
|
|
- if(nsel->steps== NULL)
|
|
|
- {
|
|
|
+ nsel->steps = (step_t *)pkg_malloc(sizeof(step_t));
|
|
|
+ if(nsel->steps == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
memset(nsel->steps, 0, sizeof(step_t));
|
|
|
- nsel->last_step= nsel->steps;
|
|
|
+ nsel->last_step = nsel->steps;
|
|
|
|
|
|
- nsel->ns_list= (ns_list_t*)pkg_malloc(sizeof(ns_list_t));
|
|
|
- if(nsel->ns_list== NULL)
|
|
|
- {
|
|
|
+ nsel->ns_list = (ns_list_t *)pkg_malloc(sizeof(ns_list_t));
|
|
|
+ if(nsel->ns_list == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
memset(nsel->ns_list, 0, sizeof(ns_list_t));
|
|
|
- nsel->last_ns= nsel->ns_list;
|
|
|
+ nsel->last_ns = nsel->ns_list;
|
|
|
|
|
|
return nsel;
|
|
|
|
|
|
error:
|
|
|
- if(nsel)
|
|
|
- {
|
|
|
+ if(nsel) {
|
|
|
if(nsel->steps)
|
|
|
pkg_free(nsel->steps);
|
|
|
if(nsel->ns_list)
|
|
@@ -128,104 +120,93 @@ error:
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-xcap_node_sel_t* xcapNodeSelAddStep(xcap_node_sel_t* curr_sel, str* name,
|
|
|
- str* namespace, int pos, attr_test_t* attr_test, str* extra_sel)
|
|
|
+xcap_node_sel_t *xcapNodeSelAddStep(xcap_node_sel_t *curr_sel, str *name,
|
|
|
+ str *namespace, int pos, attr_test_t *attr_test, str *extra_sel)
|
|
|
{
|
|
|
- int size= 0;
|
|
|
- str new_step= {NULL, 0};
|
|
|
- step_t* s= NULL;
|
|
|
- char ns_card= 'a';
|
|
|
- ns_list_t* ns= NULL;
|
|
|
+ int size = 0;
|
|
|
+ str new_step = {NULL, 0};
|
|
|
+ step_t *s = NULL;
|
|
|
+ char ns_card = 'a';
|
|
|
+ ns_list_t *ns = NULL;
|
|
|
|
|
|
if(name)
|
|
|
- size+= name->len;
|
|
|
+ size += name->len;
|
|
|
else
|
|
|
- size+= 1;
|
|
|
+ size += 1;
|
|
|
|
|
|
if(namespace)
|
|
|
- size+= 2;
|
|
|
- if(pos> 0)
|
|
|
- size+= 7;
|
|
|
+ size += 2;
|
|
|
+ if(pos > 0)
|
|
|
+ size += 7;
|
|
|
if(attr_test)
|
|
|
- size+= 2+ attr_test->name.len+ attr_test->value.len;
|
|
|
+ size += 2 + attr_test->name.len + attr_test->value.len;
|
|
|
if(extra_sel)
|
|
|
- size+= 2+ extra_sel->len;
|
|
|
+ size += 2 + extra_sel->len;
|
|
|
|
|
|
- new_step.s= (char*)pkg_malloc(size* sizeof(char));
|
|
|
- if(new_step.s== NULL)
|
|
|
- {
|
|
|
+ new_step.s = (char *)pkg_malloc(size * sizeof(char));
|
|
|
+ if(new_step.s == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
- if(name)
|
|
|
- {
|
|
|
- if(namespace)
|
|
|
- {
|
|
|
- ns_card= curr_sel->ns_no+ 'a';
|
|
|
+ if(name) {
|
|
|
+ if(namespace) {
|
|
|
+ ns_card = curr_sel->ns_no + 'a';
|
|
|
curr_sel->ns_no++;
|
|
|
|
|
|
- if(ns_card> 'z')
|
|
|
- {
|
|
|
+ if(ns_card > 'z') {
|
|
|
LM_ERR("Insufficient name cards for namespaces\n");
|
|
|
goto error;
|
|
|
}
|
|
|
- new_step.len= sprintf(new_step.s, "%c:", ns_card);
|
|
|
+ new_step.len = sprintf(new_step.s, "%c:", ns_card);
|
|
|
}
|
|
|
- memcpy(new_step.s+new_step.len, name->s, name->len);
|
|
|
- new_step.len+= name->len;
|
|
|
+ memcpy(new_step.s + new_step.len, name->s, name->len);
|
|
|
+ new_step.len += name->len;
|
|
|
+ } else
|
|
|
+ memcpy(new_step.s + new_step.len, "*", 1);
|
|
|
+
|
|
|
+ if(attr_test) {
|
|
|
+ new_step.len += sprintf(new_step.s + new_step.len, "[%.*s=%.*s]",
|
|
|
+ attr_test->name.len, attr_test->name.s, attr_test->value.len,
|
|
|
+ attr_test->value.s);
|
|
|
}
|
|
|
- else
|
|
|
- memcpy(new_step.s+new_step.len, "*", 1);
|
|
|
+ if(pos > 0)
|
|
|
+ new_step.len += sprintf(new_step.s + new_step.len, "[%d]", pos);
|
|
|
|
|
|
- if(attr_test)
|
|
|
- {
|
|
|
- new_step.len+= sprintf(new_step.s+ new_step.len, "[%.*s=%.*s]", attr_test->name.len,
|
|
|
- attr_test->name.s, attr_test->value.len, attr_test->value.s);
|
|
|
+ if(extra_sel) {
|
|
|
+ memcpy(new_step.s + new_step.len, extra_sel->s, extra_sel->len);
|
|
|
+ new_step.len = extra_sel->len;
|
|
|
}
|
|
|
- if(pos> 0)
|
|
|
- new_step.len+= sprintf(new_step.s+ new_step.len, "[%d]", pos);
|
|
|
|
|
|
- if(extra_sel)
|
|
|
- {
|
|
|
- memcpy(new_step.s+ new_step.len, extra_sel->s, extra_sel->len);
|
|
|
- new_step.len= extra_sel->len;
|
|
|
- }
|
|
|
-
|
|
|
- s= (step_t*)pkg_malloc(sizeof(step_t));
|
|
|
- if(s== NULL)
|
|
|
- {
|
|
|
+ s = (step_t *)pkg_malloc(sizeof(step_t));
|
|
|
+ if(s == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
- s->val= new_step;
|
|
|
- s->next= NULL;
|
|
|
+ s->val = new_step;
|
|
|
+ s->next = NULL;
|
|
|
|
|
|
- curr_sel->last_step->next= s;
|
|
|
- curr_sel->last_step= s;
|
|
|
+ curr_sel->last_step->next = s;
|
|
|
+ curr_sel->last_step = s;
|
|
|
|
|
|
/* add the namespace binding if present */
|
|
|
- if(namespace)
|
|
|
- {
|
|
|
- ns= (ns_list_t*)pkg_malloc(sizeof(ns_list_t));
|
|
|
- if(ns== NULL)
|
|
|
- {
|
|
|
+ if(namespace) {
|
|
|
+ ns = (ns_list_t *)pkg_malloc(sizeof(ns_list_t));
|
|
|
+ if(ns == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
- ns->name= ns_card;
|
|
|
- ns->value.s= (char*)pkg_malloc(namespace->len* sizeof(char));
|
|
|
- if(ns->value.s== NULL)
|
|
|
- {
|
|
|
+ ns->name = ns_card;
|
|
|
+ ns->value.s = (char *)pkg_malloc(namespace->len * sizeof(char));
|
|
|
+ if(ns->value.s == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
memcpy(ns->value.s, namespace->s, namespace->len);
|
|
|
- ns->value.len= namespace->len;
|
|
|
+ ns->value.len = namespace->len;
|
|
|
|
|
|
- curr_sel->last_ns->next= ns;
|
|
|
- curr_sel->last_ns= ns;
|
|
|
+ curr_sel->last_ns->next = ns;
|
|
|
+ curr_sel->last_ns = ns;
|
|
|
}
|
|
|
|
|
|
- curr_sel->size+= 1+ new_step.len;
|
|
|
- if(namespace && namespace->len)
|
|
|
- {
|
|
|
- curr_sel->size+= namespace->len+ 3;
|
|
|
+ curr_sel->size += 1 + new_step.len;
|
|
|
+ if(namespace && namespace->len) {
|
|
|
+ curr_sel->size += namespace->len + 3;
|
|
|
}
|
|
|
|
|
|
return curr_sel;
|
|
@@ -235,8 +216,7 @@ error:
|
|
|
pkg_free(new_step.s);
|
|
|
if(s)
|
|
|
pkg_free(s);
|
|
|
- if(ns)
|
|
|
- {
|
|
|
+ if(ns) {
|
|
|
if(ns->value.s)
|
|
|
pkg_free(ns->value.s);
|
|
|
pkg_free(ns);
|
|
@@ -245,51 +225,48 @@ error:
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-xcap_node_sel_t* xcapNodeSelAddTerminal(xcap_node_sel_t* curr_sel,
|
|
|
- char* attr_sel, char* namespace_sel, char* extra_sel )
|
|
|
+xcap_node_sel_t *xcapNodeSelAddTerminal(xcap_node_sel_t *curr_sel,
|
|
|
+ char *attr_sel, char *namespace_sel, char *extra_sel)
|
|
|
{
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-char* get_node_selector(xcap_node_sel_t* node_sel)
|
|
|
+char *get_node_selector(xcap_node_sel_t *node_sel)
|
|
|
{
|
|
|
- char* buf= NULL;
|
|
|
- step_t* s;
|
|
|
- int len= 0;
|
|
|
- ns_list_t* ns_elem;
|
|
|
-
|
|
|
- buf= (char*)pkg_malloc((node_sel->size+ 10)* sizeof(char));
|
|
|
- if(buf== NULL)
|
|
|
- {
|
|
|
+ char *buf = NULL;
|
|
|
+ step_t *s;
|
|
|
+ int len = 0;
|
|
|
+ ns_list_t *ns_elem;
|
|
|
+
|
|
|
+ buf = (char *)pkg_malloc((node_sel->size + 10) * sizeof(char));
|
|
|
+ if(buf == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
|
|
|
- s= node_sel->steps->next;
|
|
|
+ s = node_sel->steps->next;
|
|
|
|
|
|
- while(1)
|
|
|
- {
|
|
|
- memcpy(buf+ len, s->val.s, s->val.len);
|
|
|
- len+= s->val.len;
|
|
|
- s= s->next;
|
|
|
+ while(1) {
|
|
|
+ memcpy(buf + len, s->val.s, s->val.len);
|
|
|
+ len += s->val.len;
|
|
|
+ s = s->next;
|
|
|
if(s)
|
|
|
- buf[len++]= '/';
|
|
|
+ buf[len++] = '/';
|
|
|
else
|
|
|
break;
|
|
|
}
|
|
|
- ns_elem= node_sel->ns_list;
|
|
|
+ ns_elem = node_sel->ns_list;
|
|
|
|
|
|
if(ns_elem)
|
|
|
- buf[len++]= '?';
|
|
|
+ buf[len++] = '?';
|
|
|
|
|
|
- while(ns_elem)
|
|
|
- {
|
|
|
- len+= sprintf(buf+ len, "xmlns(%c=%.*s)", ns_elem->name,
|
|
|
+ while(ns_elem) {
|
|
|
+ len += sprintf(buf + len, "xmlns(%c=%.*s)", ns_elem->name,
|
|
|
ns_elem->value.len, ns_elem->value.s);
|
|
|
- ns_elem= ns_elem->next;
|
|
|
+ ns_elem = ns_elem->next;
|
|
|
}
|
|
|
|
|
|
- buf[len]= '\0';
|
|
|
+ buf[len] = '\0';
|
|
|
|
|
|
return buf;
|
|
|
|
|
@@ -297,34 +274,31 @@ error:
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-char* xcapGetNewDoc(xcap_get_req_t req, str user, str domain)
|
|
|
+char *xcapGetNewDoc(xcap_get_req_t req, str user, str domain)
|
|
|
{
|
|
|
- char* etag= NULL;
|
|
|
- char* doc= NULL;
|
|
|
+ char *etag = NULL;
|
|
|
+ char *doc = NULL;
|
|
|
db_key_t query_cols[9];
|
|
|
db_val_t query_vals[9];
|
|
|
int n_query_cols = 0;
|
|
|
- char* path= NULL;
|
|
|
+ char *path = NULL;
|
|
|
|
|
|
- path= get_xcap_path(req);
|
|
|
- if(path== NULL)
|
|
|
- {
|
|
|
+ path = get_xcap_path(req);
|
|
|
+ if(path == NULL) {
|
|
|
LM_ERR("while constructing xcap path\n");
|
|
|
return NULL;
|
|
|
}
|
|
|
/* send HTTP request */
|
|
|
- doc= send_http_get(path, req.port, NULL, 0, &etag);
|
|
|
- if(doc== NULL)
|
|
|
- {
|
|
|
+ doc = send_http_get(path, req.port, NULL, 0, &etag);
|
|
|
+ if(doc == NULL) {
|
|
|
LM_DBG("the searched document was not found\n");
|
|
|
goto done;
|
|
|
}
|
|
|
|
|
|
- if(etag== NULL)
|
|
|
- {
|
|
|
+ if(etag == NULL) {
|
|
|
LM_ERR("no etag found\n");
|
|
|
pkg_free(doc);
|
|
|
- doc= NULL;
|
|
|
+ doc = NULL;
|
|
|
goto done;
|
|
|
}
|
|
|
/* insert in xcap table*/
|
|
@@ -343,47 +317,46 @@ char* xcapGetNewDoc(xcap_get_req_t req, str user, str domain)
|
|
|
query_cols[n_query_cols] = &str_doc_type_col;
|
|
|
query_vals[n_query_cols].type = DB1_INT;
|
|
|
query_vals[n_query_cols].nul = 0;
|
|
|
- query_vals[n_query_cols].val.int_val= req.doc_sel.doc_type;
|
|
|
+ query_vals[n_query_cols].val.int_val = req.doc_sel.doc_type;
|
|
|
n_query_cols++;
|
|
|
|
|
|
query_cols[n_query_cols] = &str_doc_col;
|
|
|
query_vals[n_query_cols].type = DB1_STRING;
|
|
|
query_vals[n_query_cols].nul = 0;
|
|
|
- query_vals[n_query_cols].val.string_val= doc;
|
|
|
+ query_vals[n_query_cols].val.string_val = doc;
|
|
|
n_query_cols++;
|
|
|
|
|
|
query_cols[n_query_cols] = &str_etag_col;
|
|
|
query_vals[n_query_cols].type = DB1_STRING;
|
|
|
query_vals[n_query_cols].nul = 0;
|
|
|
- query_vals[n_query_cols].val.string_val= etag;
|
|
|
+ query_vals[n_query_cols].val.string_val = etag;
|
|
|
n_query_cols++;
|
|
|
|
|
|
query_cols[n_query_cols] = &str_source_col;
|
|
|
query_vals[n_query_cols].type = DB1_INT;
|
|
|
query_vals[n_query_cols].nul = 0;
|
|
|
- query_vals[n_query_cols].val.int_val= XCAP_CL_MOD;
|
|
|
+ query_vals[n_query_cols].val.int_val = XCAP_CL_MOD;
|
|
|
n_query_cols++;
|
|
|
|
|
|
query_cols[n_query_cols] = &str_doc_uri_col;
|
|
|
query_vals[n_query_cols].type = DB1_STRING;
|
|
|
query_vals[n_query_cols].nul = 0;
|
|
|
- query_vals[n_query_cols].val.string_val= path;
|
|
|
+ query_vals[n_query_cols].val.string_val = path;
|
|
|
n_query_cols++;
|
|
|
|
|
|
query_cols[n_query_cols] = &str_port_col;
|
|
|
query_vals[n_query_cols].type = DB1_INT;
|
|
|
query_vals[n_query_cols].nul = 0;
|
|
|
- query_vals[n_query_cols].val.int_val= req.port;
|
|
|
+ query_vals[n_query_cols].val.int_val = req.port;
|
|
|
n_query_cols++;
|
|
|
|
|
|
- if (xcap_dbf.use_table(xcap_db, &xcap_db_table) < 0)
|
|
|
- {
|
|
|
- LM_ERR("in use_table-[table]= %.*s\n", xcap_db_table.len, xcap_db_table.s);
|
|
|
+ if(xcap_dbf.use_table(xcap_db, &xcap_db_table) < 0) {
|
|
|
+ LM_ERR("in use_table-[table]= %.*s\n", xcap_db_table.len,
|
|
|
+ xcap_db_table.s);
|
|
|
goto done;
|
|
|
}
|
|
|
|
|
|
- if(xcap_dbf.insert(xcap_db, query_cols, query_vals, n_query_cols)< 0)
|
|
|
- {
|
|
|
+ if(xcap_dbf.insert(xcap_db, query_cols, query_vals, n_query_cols) < 0) {
|
|
|
LM_ERR("in sql insert\n");
|
|
|
goto done;
|
|
|
}
|
|
@@ -393,52 +366,48 @@ done:
|
|
|
return doc;
|
|
|
}
|
|
|
|
|
|
-char* get_xcap_path(xcap_get_req_t req)
|
|
|
+char *get_xcap_path(xcap_get_req_t req)
|
|
|
{
|
|
|
- int len= 0, size;
|
|
|
- char* path= NULL;
|
|
|
- char* node_selector= NULL;
|
|
|
+ int len = 0, size;
|
|
|
+ char *path = NULL;
|
|
|
+ char *node_selector = NULL;
|
|
|
|
|
|
- len= (strlen(req.xcap_root)+ 1+ req.doc_sel.auid.len+ 5+
|
|
|
- req.doc_sel.xid.len+ req.doc_sel.filename.len+ 50)* sizeof(char);
|
|
|
+ len = (strlen(req.xcap_root) + 1 + req.doc_sel.auid.len + 5
|
|
|
+ + req.doc_sel.xid.len + req.doc_sel.filename.len + 50)
|
|
|
+ * sizeof(char);
|
|
|
|
|
|
if(req.node_sel)
|
|
|
- len+= req.node_sel->size;
|
|
|
+ len += req.node_sel->size;
|
|
|
|
|
|
- path= (char*)pkg_malloc(len);
|
|
|
- if(path== NULL)
|
|
|
- {
|
|
|
+ path = (char *)pkg_malloc(len);
|
|
|
+ if(path == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
|
|
|
- if(req.node_sel)
|
|
|
- {
|
|
|
- node_selector= get_node_selector(req.node_sel);
|
|
|
- if(node_selector== NULL)
|
|
|
- {
|
|
|
+ if(req.node_sel) {
|
|
|
+ node_selector = get_node_selector(req.node_sel);
|
|
|
+ if(node_selector == NULL) {
|
|
|
LM_ERR("while constructing node selector\n");
|
|
|
goto error;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- size= sprintf(path, "%s/%.*s/", req.xcap_root, req.doc_sel.auid.len,
|
|
|
+ size = sprintf(path, "%s/%.*s/", req.xcap_root, req.doc_sel.auid.len,
|
|
|
req.doc_sel.auid.s);
|
|
|
|
|
|
- if(req.doc_sel.type==USERS_TYPE)
|
|
|
- size+= sprintf(path+ size, "%s/%.*s/", "users", req.doc_sel.xid.len,
|
|
|
+ if(req.doc_sel.type == USERS_TYPE)
|
|
|
+ size += sprintf(path + size, "%s/%.*s/", "users", req.doc_sel.xid.len,
|
|
|
req.doc_sel.xid.s);
|
|
|
else
|
|
|
- size+= sprintf(path+ size, "%s/", "global");
|
|
|
- size+= sprintf(path+ size, "%.*s", req.doc_sel.filename.len,
|
|
|
+ size += sprintf(path + size, "%s/", "global");
|
|
|
+ size += sprintf(path + size, "%.*s", req.doc_sel.filename.len,
|
|
|
req.doc_sel.filename.s);
|
|
|
|
|
|
- if(node_selector)
|
|
|
- {
|
|
|
- size+= sprintf(path+ size, "/~~%s", node_selector);
|
|
|
+ if(node_selector) {
|
|
|
+ size += sprintf(path + size, "/~~%s", node_selector);
|
|
|
}
|
|
|
|
|
|
- if(size> len)
|
|
|
- {
|
|
|
+ if(size > len) {
|
|
|
LM_ERR("buffer size overflow\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -454,22 +423,20 @@ error:
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-size_t get_xcap_etag( void *ptr, size_t size, size_t nmemb, void *stream)
|
|
|
+size_t get_xcap_etag(void *ptr, size_t size, size_t nmemb, void *stream)
|
|
|
{
|
|
|
- int len= 0;
|
|
|
- char* etag= NULL;
|
|
|
-
|
|
|
- if(strncasecmp(ptr, ETAG_HDR, ETAG_HDR_LEN)== 0)
|
|
|
- {
|
|
|
- len= size* nmemb- ETAG_HDR_LEN;
|
|
|
- etag= (char*)pkg_malloc((len+ 1)* sizeof(char));
|
|
|
- if(etag== NULL)
|
|
|
- {
|
|
|
+ int len = 0;
|
|
|
+ char *etag = NULL;
|
|
|
+
|
|
|
+ if(strncasecmp(ptr, ETAG_HDR, ETAG_HDR_LEN) == 0) {
|
|
|
+ len = size * nmemb - ETAG_HDR_LEN;
|
|
|
+ etag = (char *)pkg_malloc((len + 1) * sizeof(char));
|
|
|
+ if(etag == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
- memcpy(etag, ptr+ETAG_HDR_LEN, len);
|
|
|
- etag[len]= '\0';
|
|
|
- *((char**)stream)= etag;
|
|
|
+ memcpy(etag, ptr + ETAG_HDR_LEN, len);
|
|
|
+ etag[len] = '\0';
|
|
|
+ *((char **)stream) = etag;
|
|
|
}
|
|
|
return len;
|
|
|
|
|
@@ -477,29 +444,28 @@ error:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-char* send_http_get(char* path, unsigned int xcap_port, char* match_etag,
|
|
|
- int match_type, char** etag)
|
|
|
+char *send_http_get(char *path, unsigned int xcap_port, char *match_etag,
|
|
|
+ int match_type, char **etag)
|
|
|
{
|
|
|
int len;
|
|
|
- char* stream= NULL;
|
|
|
+ char *stream = NULL;
|
|
|
CURLcode ret_code;
|
|
|
- CURL* curl_handle= NULL;
|
|
|
+ CURL *curl_handle = NULL;
|
|
|
static char buf[128];
|
|
|
- char* match_header= NULL;
|
|
|
- *etag= NULL;
|
|
|
+ char *match_header = NULL;
|
|
|
+ *etag = NULL;
|
|
|
|
|
|
- if(match_etag)
|
|
|
- {
|
|
|
- char* hdr_name= NULL;
|
|
|
+ if(match_etag) {
|
|
|
+ char *hdr_name = NULL;
|
|
|
|
|
|
- memset(buf, 0, 128* sizeof(char));
|
|
|
- match_header= buf;
|
|
|
+ memset(buf, 0, 128 * sizeof(char));
|
|
|
+ match_header = buf;
|
|
|
|
|
|
- hdr_name= (match_type==IF_MATCH)?"If-Match":"If-None-Match";
|
|
|
+ hdr_name = (match_type == IF_MATCH) ? "If-Match" : "If-None-Match";
|
|
|
|
|
|
- len=sprintf(match_header, "%s: %s\n", hdr_name, match_etag);
|
|
|
+ len = sprintf(match_header, "%s: %s\n", hdr_name, match_etag);
|
|
|
|
|
|
- match_header[len]= '\0';
|
|
|
+ match_header[len] = '\0';
|
|
|
}
|
|
|
|
|
|
curl_handle = curl_easy_init();
|
|
@@ -510,15 +476,15 @@ char* send_http_get(char* path, unsigned int xcap_port, char* match_etag,
|
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
|
|
|
|
|
|
- curl_easy_setopt(curl_handle, CURLOPT_STDERR, stdout);
|
|
|
+ curl_easy_setopt(curl_handle, CURLOPT_STDERR, stdout);
|
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_function);
|
|
|
|
|
|
- curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void*)(&stream));
|
|
|
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)(&stream));
|
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, get_xcap_etag);
|
|
|
|
|
|
- curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void*)(&etag));
|
|
|
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *)(&etag));
|
|
|
|
|
|
if(match_header)
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_HEADER, (long)match_header);
|
|
@@ -526,14 +492,13 @@ char* send_http_get(char* path, unsigned int xcap_port, char* match_etag,
|
|
|
/* non-2xx => error */
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, 1);
|
|
|
|
|
|
- ret_code= curl_easy_perform(curl_handle );
|
|
|
+ ret_code = curl_easy_perform(curl_handle);
|
|
|
|
|
|
- if( ret_code== CURLE_WRITE_ERROR)
|
|
|
- {
|
|
|
+ if(ret_code == CURLE_WRITE_ERROR) {
|
|
|
LM_ERR("while performing curl option\n");
|
|
|
if(stream)
|
|
|
pkg_free(stream);
|
|
|
- stream= NULL;
|
|
|
+ stream = NULL;
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
@@ -541,22 +506,21 @@ char* send_http_get(char* path, unsigned int xcap_port, char* match_etag,
|
|
|
return stream;
|
|
|
}
|
|
|
|
|
|
-size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream)
|
|
|
+size_t write_function(void *ptr, size_t size, size_t nmemb, void *stream)
|
|
|
{
|
|
|
/* allocate memory and copy */
|
|
|
- char* data;
|
|
|
+ char *data;
|
|
|
|
|
|
- data= (char*)pkg_malloc(size* nmemb);
|
|
|
- if(data== NULL)
|
|
|
- {
|
|
|
+ data = (char *)pkg_malloc(size * nmemb);
|
|
|
+ if(data == NULL) {
|
|
|
ERR_MEM(PKG_MEM_STR);
|
|
|
}
|
|
|
|
|
|
- memcpy(data, (char*)ptr, size* nmemb);
|
|
|
+ memcpy(data, (char *)ptr, size * nmemb);
|
|
|
|
|
|
- *((char**) stream)= data;
|
|
|
+ *((char **)stream) = data;
|
|
|
|
|
|
- return size* nmemb;
|
|
|
+ return size * nmemb;
|
|
|
|
|
|
error:
|
|
|
return CURLE_WRITE_ERROR;
|