/** * @brief find dmq node by uri */ dmq_node_t* find_dmq_node_uri(dmq_node_list_t* list, str* uri) { dmq_node_t *ret, *find; find = build_dmq_node(uri, 0); if(find==NULL) return NULL; ret = find_dmq_node(list, find); destroy_dmq_node(find, 0); return ret; }
/** * @brief find dmq node by uri */ dmq_node_t *find_dmq_node_uri(dmq_node_list_t *list, str *uri) { dmq_node_t *ret, find; memset(&find, 0, sizeof(find)); if(parse_uri(uri->s, uri->len, &find.uri) < 0) { LM_ERR("error parsing uri\n"); return NULL; } ret = find_dmq_node(list, &find); return ret; }
/** * extract the node list from the body of a notification request SIP message * the SIP request will look something like: * KDMQ sip:10.0.0.0:5062 * To: ... * From: ... * Max-Forwards: ... * Content-Length: 22 * * sip:host1:port1;param1=value1 * sip:host2:port2;param2=value2 * ... */ int extract_node_list(dmq_node_list_t* update_list, struct sip_msg* msg) { int content_length, total_nodes = 0; str body; str tmp_uri; dmq_node_t *cur = NULL; dmq_node_t *ret, *find; char *tmp, *end, *match; if(!msg->content_length && (parse_headers(msg,HDR_CONTENTLENGTH_F,0)<0 || !msg->content_length)) { LM_ERR("no content length header found\n"); return -1; } content_length = get_content_length(msg); if(!content_length) { LM_DBG("content length is 0\n"); return total_nodes; } body.s = get_body(msg); body.len = content_length; tmp = body.s; end = body.s + body.len; /* acquire big list lock */ lock_get(&update_list->lock); while(tmp < end) { match = q_memchr(tmp, '\n', end - tmp); if(match) { match++; } else { /* for the last line - take all of it */ match = end; } /* create the orig_uri from the parsed uri line and trim it */ tmp_uri.s = tmp; tmp_uri.len = match - tmp - 1; tmp = match; /* trim the \r, \n and \0's */ trim_r(tmp_uri); find = build_dmq_node(&tmp_uri, 0); if(find==NULL) return -1; ret = find_dmq_node(update_list, find); if (!ret) { LM_DBG("found new node %.*s\n", STR_FMT(&tmp_uri)); cur = build_dmq_node(&tmp_uri, 1); if(!cur) { LM_ERR("error creating new dmq node\n"); goto error; } cur->next = update_list->nodes; update_list->nodes = cur; update_list->count++; total_nodes++; } else if (find->params && ret->status != find->status) { LM_DBG("updating status on %.*s from %d to %d\n", STR_FMT(&tmp_uri), ret->status, find->status); ret->status = find->status; total_nodes++; } destroy_dmq_node(find, 0); } /* release big list lock */ lock_release(&update_list->lock); return total_nodes; error: lock_release(&update_list->lock); return -1; }