MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / ph_getColVals

Function ph_getColVals

modules/pi_http/http_fnc.c:867–942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

865}
866
867int ph_getColVals(ph_mod_t *module, ph_cmd_t *cmd,
868 ph_vals_t *cmd_col_vals, xmlNodePtr col_node)
869{
870 xmlNodePtr node;
871 str *vals, *col_vals = NULL;
872 str *ids, *col_ids = NULL;
873 int size = 0;
874 int i;
875 str attr;
876 str val;
877
878 for(node=col_node->children;node;node=node->next){
879 if (xmlStrcasecmp(node->name,
880 (const xmlChar*)PI_HTTP_XML_VALUE_NODE) == 0) {
881 if(size){
882 vals = (str*)shm_realloc(col_vals,
883 (size+1)*sizeof(str));
884 ids = (str*)shm_realloc(col_ids,
885 (size+1)*sizeof(str));
886 }else{
887 vals = (str*)shm_malloc(sizeof(str));
888 ids = (str*)shm_malloc(sizeof(str));
889 }
890 if(vals==NULL||ids==NULL) {LM_ERR("oom\n"); return -1;}
891 col_vals = vals; col_ids = ids;
892 vals = &col_vals[size]; ids = &col_ids[size];
893 memset(vals, 0, sizeof *vals); memset(ids, 0, sizeof *ids);
894 /* Retrieve the node attribute */
895 attr.s = ph_xmlNodeGetAttrContentByName(node,
896 PI_HTTP_XML_ID_ATTR);
897 if(attr.s==NULL){
898 LM_ERR("No attribute for node\n");
899 return -1;
900 }
901 attr.len = strlen(attr.s);
902 if(attr.len==0){
903 LM_ERR("No attribute for node\n");
904 return -1;
905 }
906 if(shm_str_dup(ids, &attr)!=0) return -1;
907 xmlFree(attr.s); attr.s = NULL; attr.len = 0;
908 /* Retrieve the node value */
909 val.s = (char*)xmlNodeGetContent(node);
910 if(val.s==NULL){
911 LM_ERR("No content for node\n");
912 return -1;
913 }
914 val.len = strlen(val.s);
915 if(val.len==0){
916 LM_ERR("No content for node\n");
917 return -1;
918 }
919 if(shm_str_dup(vals, &val)!=0) return -1;
920 xmlFree(val.s); val.s = NULL; val.len = 0;
921 /*
922 LM_DBG("> > [%d] [%p]->[%s] [%p]->[%s]\n",
923 size, ids, ids->s, vals, vals->s);
924 */

Callers 1

ph_getColsFunction · 0.85

Calls 3

shm_reallocFunction · 0.85
shm_mallocFunction · 0.85

Tested by

no test coverage detected