/* * rpc cmd: refreshXcapDoc * <document uri> * <xcap_port> * */ void xcap_client_rpc_refreshXcapDoc(rpc_t* rpc, void* ctx) { str doc_url; xcap_doc_sel_t doc_sel; char* serv_addr; char* stream= NULL; int type; unsigned int xcap_port; char* etag= NULL; if(rpc->scan(ctx, "S", &doc_url, (int*)(&xcap_port))<1) { LM_WARN("not enough parameters\n"); rpc->fault(ctx, 500, "Not enough parameters"); return; } /* send GET HTTP request to the server */ stream= send_http_get(doc_url.s, xcap_port, NULL, 0, &etag); if(stream== NULL) { LM_ERR("in http get\n"); rpc->fault(ctx, 500, "Failed http get"); return; } /* call registered functions with document argument */ if(parse_doc_url(doc_url, &serv_addr, &doc_sel)< 0) { LM_ERR("parsing document url\n"); if(stream) pkg_free(stream); rpc->fault(ctx, 500, "Failed parsing url"); return; } type= get_auid_flag(doc_sel.auid); if(type<0) { LM_ERR("incorrect auid: %.*s\n", doc_sel.auid.len, doc_sel.auid.s); if(stream) pkg_free(stream); rpc->fault(ctx, 500, "Invalid auid"); return; } run_xcap_update_cb(type, doc_sel.xid, stream); if(stream) pkg_free(stream); }
struct mi_root* refreshXcapDoc(struct mi_root* cmd, void* param) { struct mi_node* node= NULL; str doc_url; xcap_doc_sel_t doc_sel; char* serv_addr; char* stream= NULL; int type; unsigned int xcap_port; char* etag= NULL; node = cmd->node.kids; if(node == NULL) return 0; 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; } if(node->next!= NULL) return 0; /* send GET HTTP request to the server */ stream= send_http_get(doc_url.s, xcap_port, NULL, 0, &etag); if(stream== NULL) { LM_ERR("in http get\n"); return 0; } /* call registered functions with document argument */ if(parse_doc_url(doc_url, &serv_addr, &doc_sel)< 0) { LM_ERR("parsing document url\n"); return 0; } type= get_auid_flag(doc_sel.auid); if(type< 0) { LM_ERR("incorect auid: %.*s\n", doc_sel.auid.len, doc_sel.auid.s); goto error; } run_xcap_update_cb(type, doc_sel.xid, stream); return init_mi_tree(200, "OK", 2); error: if(stream) pkg_free(stream); return 0; }