rem: str body; int level, added_len, offset, len, nextisip; char *buf, *cp, *cp1;
add: str body, mediaip; int level, added_len, offset, len; char *buf, *cp;
context: fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2){	str body;	int level, added_len, offset, len, nextisip;	char *buf, *cp, *cp1;	struct lump* anchor;	str mediaip;	level = (int)str1;	added_len = 0;	if (extract_body(msg, &body) == -1 || body.len == 0) {		LOG(L_ERR,"ERROR: fix_nated_sdp: cannot extract body from msg!\n");		return -1;	}	if (level & ADD_ADIRECTION) {		anchor = anchor_lump(&(msg->add_rm),		    body.s + body.len - msg->buf, 0, 0);		if (anchor == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: anchor_lump failed\n");			return -1;		}		buf = pkg_malloc(ADIRECTION_LEN * sizeof(char));		if (buf == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: out of memory\n");			return -1;		}		memcpy(buf, ADIRECTION, ADIRECTION_LEN);		if (insert_new_lump_after(anchor, buf, ADIRECTION_LEN - 1, 0) == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: insert_new_lump_after failed\n");			pkg_free(buf);			return -1;		}		added_len += ADIRECTION_LEN - 1;	}	if (level & FIX_MEDIAIP) {		for (cp = body.s; (len = body.s + body.len - cp) > 0;) {			cp1 = ser_memmem(cp, "c=", len, 2);			if (cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')				break;			cp = cp1 + 2;		}		if (cp1 == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: no `c=' in SDP\n");			goto finalise;		}		mediaip.s = cp1 + 2;		mediaip.len = eat_line(mediaip.s, body.s + body.len - mediaip.s) - mediaip.s;		trim_len(mediaip.len, mediaip.s, mediaip);		nextisip = 0;		for (cp = mediaip.s; cp < mediaip.s + mediaip.len;) {			len = eat_token_end(cp, mediaip.s + mediaip.len) - cp;			if (nextisip == 1) {				mediaip.s = cp;				mediaip.len = len;				nextisip++;				break;			}			if (len == 3 && memcmp(cp, "IP4", 3) == 0)				nextisip = 1;			cp = eat_space_end(cp + len, mediaip.s + mediaip.len);		}		if (nextisip != 2 || mediaip.len == 0) {			LOG(L_ERR, "ERROR: fix_nated_sdp: no `IP4' in `c=' field\n");			goto finalise;		}		cp = ip_addr2a(&msg->rcv.src_ip);		len = strlen(cp);		/* check that updating mediaip is really necessary */		if (len == mediaip.len && memcmp(cp, mediaip.s, len) == 0)			goto finalise;		buf = pkg_malloc(len);		if (buf == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: out of memory\n");			return -1;		}		offset = mediaip.s - msg->buf;		anchor = del_lump(&msg->add_rm, offset, mediaip.len, 0);		if (anchor == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: del_lump failed\n");			pkg_free(buf);			return -1;		}		memcpy(buf, cp, len);		if (insert_new_lump_after(anchor, buf, len, 0) == 0) {			LOG(L_ERR, "ERROR: fix_nated_sdp: insert_new_lump_after failed\n");			pkg_free(buf);			return -1;		}		added_len += len - mediaip.len;	}finalise:	/* Check that Content-Length needs to be updated */	if (added_len != 0) {		buf = pkg_malloc(CLEN_LEN * sizeof(char));		if (buf == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: out of memory\n");			return -1;		}		offset = msg->content_length->body.s - msg->buf;		len = msg->content_length->body.len;		anchor = del_lump(&msg->add_rm, offset, len, HDR_CONTENTLENGTH);		if (anchor == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: del_lump failed\n");			pkg_free(buf);			return -1;		}		len = snprintf(buf, CLEN_LEN, "%d", body.len + added_len);		if (len >= CLEN_LEN)			len = CLEN_LEN - 1;		if (insert_new_lump_after(anchor, buf, len, HDR_CONTENTLENGTH) == NULL) {			LOG(L_ERR, "ERROR: fix_nated_sdp: insert_new_lump_after failed\n");			pkg_free(buf);			return -1;		}	}	return 1;}