//copy string between initial (<tag) and end (<\tag>) tags, in this case consider parms in initial tag char* copy_str_between_two_tags_simple(char* tag_begin, char* str_total){ char *ptr1,*ptr2; char *complete_tag_begin, *complete_tag_end; complete_tag_begin = pkg_malloc(sizeof(char) * (strlen(tag_begin)+ strlen("<"))); complete_tag_end = pkg_malloc(sizeof(char) * (strlen(tag_begin)+ strlen("</") + strlen(">"))); if(complete_tag_begin == NULL || complete_tag_end == NULL) return empty; strcpy (complete_tag_begin,"<"); strcat (complete_tag_begin,tag_begin); strcpy (complete_tag_end,"</"); strcat (complete_tag_end,tag_begin); strcat (complete_tag_end,">"); ptr1 = strstr(str_total,complete_tag_begin); ptr2 = strstr(str_total,complete_tag_end); if(ptr1 != NULL && ptr2 != NULL){ LM_DBG(" --- FOUND TAG %s",str_total); pkg_free(complete_tag_begin); pkg_free(complete_tag_end); return copy_str_between_two_pointers_simple(ptr1 + strlen(tag_begin) + 1,ptr2); }else{ LM_DBG(" --- NOT FOUND TAG %s",str_total); } pkg_free(complete_tag_begin); pkg_free(complete_tag_end); return empty; }
char* copy_str_between_two_tags_simple(char* tag_begin, char* str_total){ char *ptr1,*ptr2; char *complete_tag_begin, *complete_tag_end; //char* resp = pkg_malloc(sizeof(char)); //memset(resp,'\0',1); complete_tag_begin = pkg_malloc(sizeof(char) * (strlen(tag_begin)+ strlen("<"))); complete_tag_end = pkg_malloc(sizeof(char) * (strlen(tag_begin)+ strlen("</") + strlen(">"))); if(complete_tag_begin == NULL || complete_tag_end == NULL) //return resp; return NULL; strcpy (complete_tag_begin,"<"); strcat (complete_tag_begin,tag_begin); strcpy (complete_tag_end,"</"); strcat (complete_tag_end,tag_begin); strcat (complete_tag_end,">"); ptr1 = strstr(str_total,complete_tag_begin); ptr2 = strstr(str_total,complete_tag_end); if(ptr1 != NULL && ptr2 != NULL){ LM_DBG(" --- ENCONTROU A TAG %s",str_total); pkg_free(complete_tag_begin); pkg_free(complete_tag_end); return copy_str_between_two_pointers_simple(ptr1 + strlen(tag_begin) + 1,ptr2); }else{ LM_DBG(" --- NAO ENCONTROU A TAG %s",str_total); } pkg_free(complete_tag_begin); pkg_free(complete_tag_end); //return resp; return NULL; }
/* get data of Notify body and put in variable with the struct: - params: .version .state .entity - target: .dialog_id .callid .local_tag .direction - state */ struct notify_body* parse_notify(char* xml){ char* version = "version="; char* dlg_state = "state="; char* entity = "entity="; char* dialog = "dialog"; char* dialog_id = "id="; char* callid = "call-id"; char* local_tag = "local-tag"; char* direction = "direction"; char* state = "state"; char* pt_version; char* pt_dlg_state; char* pt_entity; char* pt_end_entity; char* pt_dialog_id; char* pt_callid; char* pt_local_tag; char* pt_direction; char* pt_end_direction; char* target_info; char* dialog_body; LM_DBG(" --- PARSES NOTYFY BODY \n"); dialog_body = check_dialog_init_tags(xml); if (dialog_body == NULL) return NULL; struct notify_body *notify = pkg_malloc(sizeof(struct notify_body)); notify->params = pkg_malloc(sizeof(struct dialog_params)); notify->target = pkg_malloc(sizeof(struct target_info)); if(notify == NULL || notify->params == NULL || notify->target == NULL) return NULL; pt_version = strstr(dialog_body,version); pt_dlg_state = strstr(dialog_body,dlg_state); pt_entity = strstr(dialog_body,entity); pt_end_entity = strstr(dialog_body,">"); if (pt_version == NULL || pt_dlg_state == NULL || pt_entity == NULL || pt_end_entity == NULL) return NULL; target_info = copy_str_between_two_tags_simple(dialog,dialog_body); if (target_info == NULL) return NULL; notify->state = copy_str_between_two_tags(state,dialog_body); if (notify->state == NULL) return NULL; pt_dialog_id = strstr(target_info,dialog_id); pt_callid = strstr(target_info,callid); pt_local_tag = strstr(target_info,local_tag); pt_direction = strstr(target_info,direction); pt_end_direction = strstr(target_info,">"); if (pt_dialog_id == NULL || pt_callid == NULL || pt_local_tag == NULL || pt_direction == NULL || pt_end_direction == NULL) return NULL; notify->params->version = copy_str_between_two_pointers_simple(pt_version + strlen(version), pt_dlg_state); notify->params->state = copy_str_between_two_pointers_simple(pt_dlg_state + strlen(dlg_state), pt_entity); notify->params->entity = copy_str_between_two_pointers_simple(pt_entity + strlen(entity), pt_end_entity); notify->target->dlg_id = copy_str_between_two_pointers_simple(pt_dialog_id + strlen(dialog_id), pt_callid); notify->target->callid = copy_str_between_two_pointers_simple(pt_callid + strlen(callid), pt_local_tag); notify->target->local_tag = copy_str_between_two_pointers_simple(pt_local_tag + strlen(local_tag), pt_direction); notify->target->direction = copy_str_between_two_pointers_simple(pt_direction + strlen(direction), pt_end_direction); return notify; }