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

Function ph_getDbTableCols

modules/pi_http/http_fnc.c:557–712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555}
556
557int ph_getDbTableCols(ph_db_url_t *ph_db_urls, ph_db_table_t *db_tables,
558 const xmlNodePtr table_node)
559{
560 int i;
561 char *val;
562 int val_len;
563 xmlNodePtr node;
564 ph_table_col_t *cols;
565 str field;
566
567 for(node=table_node->children,db_tables->cols_size=0;node;node=node->next){
568 if (xmlStrcasecmp(node->name,
569 (const xmlChar*)PI_HTTP_XML_COLUMN_NODE) == 0) {
570 if(db_tables->cols_size)
571 cols = (ph_table_col_t*)shm_realloc(db_tables->cols,
572 (db_tables->cols_size+1)*
573 sizeof(ph_table_col_t));
574 else
575 cols = (ph_table_col_t*)
576 shm_malloc(sizeof(ph_table_col_t));
577 if(cols==NULL) {LM_ERR("oom\n");return -1;}
578 db_tables->cols = cols;
579 cols = &db_tables->cols[db_tables->cols_size];
580 memset(cols, 0, sizeof(ph_table_col_t));
581 cols->type=(db_type_t)-1;
582 /* Populate the field */
583 field.s =
584 ph_xmlNodeGetNodeContentByName(node->children,
585 PI_HTTP_XML_FIELD_NODE);
586 if(field.s==NULL){
587 LM_ERR("missing node %s [%.*s] %s %s\n",
588 table_node->name,
589 db_tables->name.len, db_tables->name.s,
590 node->name, PI_HTTP_XML_FIELD_NODE);
591 return -1;
592 }
593 field.len = strlen(field.s);
594 if(field.len==0){
595 LM_ERR("empty node %s [%.*s] %s %s \n",
596 table_node->name,
597 db_tables->name.len, db_tables->name.s,
598 node->name, PI_HTTP_XML_FIELD_NODE);
599 return -1;
600 }
601 if(shm_str_dup(&cols->field, &field)!=0) return -1;
602 xmlFree(field.s);field.s=NULL;field.len=0;
603 /* Each field MUST be unique */
604 for(i=0;i<db_tables->cols_size;i++){
605 if(cols->field.len==db_tables->cols[i].field.len &&
606 strncmp(db_tables->cols[i].field.s,
607 cols->field.s,
608 cols->field.len)==0){
609 LM_ERR("duplicated %s %s [%.*s] in %s [%.*s]\n",
610 node->name, PI_HTTP_XML_FIELD_NODE,
611 cols->field.len, cols->field.s,
612 table_node->name,
613 db_tables->name.len, db_tables->name.s);
614 return -1;

Callers 1

ph_getDbTablesFunction · 0.85

Calls 3

shm_reallocFunction · 0.85
shm_mallocFunction · 0.85

Tested by

no test coverage detected