int sdp_remove_str_codec_id_attrs(sip_msg_t* msg, sdp_stream_cell_t* sdp_stream, str *rm_codec) { str aline = {0, 0}; sdp_payload_attr_t *payload; struct lump *anchor; payload = sdp_stream->payload_attr; while (payload) { LM_DBG("a= ... for codec %.*s/%.*s\n", payload->rtp_payload.len, payload->rtp_payload.s, payload->rtp_enc.len, payload->rtp_enc.s); if(rm_codec->len==payload->rtp_payload.len && strncmp(payload->rtp_payload.s, rm_codec->s, rm_codec->len)==0) { if(payload->rtp_enc.s!=NULL) { if(sdp_locate_line(msg, payload->rtp_enc.s, &aline)==0) { LM_DBG("removing line: %.*s", aline.len, aline.s); anchor = del_lump(msg, aline.s - msg->buf, aline.len, 0); if (anchor == NULL) { LM_ERR("failed to remove [%.*s] inside [%.*s]\n", rm_codec->len, rm_codec->s, aline.len, aline.s); return -1; } } } if(payload->fmtp_string.s!=NULL) { if(sdp_locate_line(msg, payload->fmtp_string.s, &aline)==0) { LM_DBG("removing line: %.*s\n", aline.len, aline.s); anchor = del_lump(msg, aline.s - msg->buf, aline.len, 0); if (anchor == NULL) { LM_ERR("failed to remove [%.*s] inside [%.*s]\n", rm_codec->len, rm_codec->s, aline.len, aline.s); return -1; } } } } payload=payload->next; } return 0; }
/** * @brief remove all SDP lines that begin with prefix * @return -1 - error; 0 - no lines found ; 1..N - N lines deleted */ int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix) { str body = {NULL, 0}; if(parse_sdp(msg) < 0) { LM_ERR("Unable to parse SDP\n"); return -1; } if(msg->body == NULL) { LM_DBG("No SDP body\n"); return -1; } body.s = ((sdp_info_t*)msg->body)->raw_sdp.s; body.len = ((sdp_info_t*)msg->body)->raw_sdp.len; if (body.s==NULL) { LM_ERR("failed to get the message body\n"); return -1; } body.len = msg->len - (body.s - msg->buf); if (body.len==0) { LM_DBG("message body has zero length\n"); return -1; } char *ptr = NULL; str line = {NULL, 0}; str remove = {NULL, 0}; int found = 0; struct lump *anchor = NULL; ptr = find_sdp_line(body.s, body.s + body.len, prefix->s[0]); while (ptr) { if (sdp_locate_line(msg, ptr, &line) != 0) { LM_ERR("sdp_locate_line() failed\n"); return -1; } if (body.s + body.len < line.s + prefix->len) // check if strncmp would run too far { //LM_DBG("done searching, prefix string >%.*s< (%d) does not fit into remaining buffer space (%ld) \n", prefix->len, prefix->s, prefix->len, body.s + body.len - line.s); break; } if (strncmp(line.s, prefix->s, prefix->len ) == 0) { //LM_DBG("current remove >%.*s< (%d)\n", remove.len, remove.s, remove.len); if (!found) { //LM_DBG("first match >%.*s< (%d)\n", line.len,line.s,line.len); remove.s = line.s; remove.len = line.len; } else { //LM_DBG("cont. match >%.*s< (%d)\n", line.len,line.s,line.len); if (remove.s + remove.len == line.s) { //LM_DBG("this match is right after previous match\n"); remove.len += line.len; } else { //LM_DBG("there is gap between this and previous match, remove now\n"); anchor = del_lump(msg, remove.s - msg->buf, remove.len, HDR_OTHER_T); if (anchor==NULL) { LM_ERR("failed to remove lump\n"); return -1; } remove.s = line.s; remove.len = line.len; } } found++; //LM_DBG("updated remove >%.*s< (%d)\n", remove.len, remove.s, remove.len); } ptr = find_next_sdp_line(ptr, body.s + body.len, prefix->s[0], NULL); } if (found) { //LM_DBG("remove >%.*s< (%d)\n", remove.len, remove.s, remove.len); anchor = del_lump(msg, remove.s - msg->buf, remove.len, HDR_OTHER_T); if (anchor==NULL) { LM_ERR("failed to remove lump\n"); return -1; } return found; } LM_DBG("no match\n"); return 0; }
static int w_sdp_get_line_startswith(sip_msg_t *msg, char *avp, char *s_line) { sdp_info_t *sdp = NULL; str body = {NULL, 0}; str line = {NULL, 0}; char* p = NULL; str s; str sline; int_str avp_val; int_str avp_name; pv_spec_t *avp_spec = NULL; static unsigned short avp_type = 0; int sdp_missing=1; if (s_line == NULL || strlen(s_line) <= 0) { LM_ERR("Search string is null or empty\n"); return -1; } sline.s = s_line; sline.len = strlen(s_line); sdp_missing = parse_sdp(msg); if(sdp_missing < 0) { LM_ERR("Unable to parse sdp\n"); return -1; } sdp = (sdp_info_t *)msg->body; if (sdp_missing || sdp == NULL) { LM_DBG("No SDP\n"); return -2; } body.s = sdp->raw_sdp.s; body.len = sdp->raw_sdp.len; if (body.s==NULL) { LM_ERR("failed to get the message body\n"); return -1; } body.len = msg->len - (body.s - msg->buf); if (body.len==0) { LM_DBG("message body has zero length\n"); return -1; } if (avp == NULL || strlen(avp) <= 0) { LM_ERR("avp variable is null or empty\n"); return -1; } s.s = avp; s.len = strlen(s.s); if (pv_locate_name(&s) != s.len) { LM_ERR("invalid parameter\n"); return -1; } if (((avp_spec = pv_cache_get(&s)) == NULL) || avp_spec->type!=PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", avp); return -1; } if(pv_get_avp_name(0, &avp_spec->pvp, &avp_name, &avp_type)!=0) { LM_ERR("[%s]- invalid AVP definition\n", avp); return -1; } p = find_sdp_line(body.s, body.s+body.len, sline.s[0]); while (p != NULL) { if (sdp_locate_line(msg, p, &line) != 0) { LM_ERR("sdp_locate_line fail\n"); return -1; } if (strncmp(line.s, sline.s, sline.len) == 0) { avp_val.s.s = line.s; avp_val.s.len = line.len; /* skip ending \r\n if exists */ if (avp_val.s.s[line.len-2] == '\r' && avp_val.s.s[line.len-1] == '\n') { /* add_avp() clones to shm and adds 0-terminating char */ avp_val.s.len -= 2; } if (add_avp(AVP_VAL_STR | avp_type, avp_name, avp_val) != 0) { LM_ERR("Failed to add SDP line avp"); return -1; } return 1; } p = find_sdp_line(line.s + line.len, body.s + body.len, sline.s[0]); } return -1; }