[sr-dev] git:master:6fadac0f: textopsx: use functions from core to apply changes

Daniel-Constantin Mierla miconda at gmail.com
Mon Sep 3 08:41:13 CEST 2018


Module: kamailio
Branch: master
Commit: 6fadac0fc8107a80663da7f975f066738151456b
URL: https://github.com/kamailio/kamailio/commit/6fadac0fc8107a80663da7f975f066738151456b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-09-02T12:42:37+02:00

textopsx: use functions from core to apply changes

---

Modified: src/modules/textopsx/textopsx.c

---

Diff:  https://github.com/kamailio/kamailio/commit/6fadac0fc8107a80663da7f975f066738151456b.diff
Patch: https://github.com/kamailio/kamailio/commit/6fadac0fc8107a80663da7f975f066738151456b.patch

---

diff --git a/src/modules/textopsx/textopsx.c b/src/modules/textopsx/textopsx.c
index 24bdf0c84f..cf2fe52b84 100644
--- a/src/modules/textopsx/textopsx.c
+++ b/src/modules/textopsx/textopsx.c
@@ -145,8 +145,6 @@ static int mod_init(void)
  */
 static int ki_msg_update_buffer(sip_msg_t *msg, str *obuf)
 {
-	sip_msg_t tmp;
-
 	if(obuf==NULL || obuf->s==NULL || obuf->len<=0) {
 		LM_ERR("invalid buffer parameter\n");
 		return -1;
@@ -156,52 +154,8 @@ static int ki_msg_update_buffer(sip_msg_t *msg, str *obuf)
 		LM_ERR("new buffer is too large (%d)\n", obuf->len);
 		return -1;
 	}
-	/* temporary copy */
-	memcpy(&tmp, msg, sizeof(sip_msg_t));
-
-	/* reset dst uri and path vector to avoid freeing - restored later */
-	if(msg->dst_uri.s != NULL) {
-		msg->dst_uri.s = NULL;
-		msg->dst_uri.len = 0;
-	}
-	if(msg->path_vec.s != NULL) {
-		msg->path_vec.s = NULL;
-		msg->path_vec.len = 0;
-	}
-
-	/* free old msg structure */
-	free_sip_msg(msg);
-	memset(msg, 0, sizeof(sip_msg_t));
-
-	/* restore msg fields */
-	msg->buf = tmp.buf;
-	msg->id = tmp.id;
-	msg->rcv = tmp.rcv;
-	msg->set_global_address = tmp.set_global_address;
-	msg->set_global_port = tmp.set_global_port;
-	msg->flags = tmp.flags;
-	msg->msg_flags = tmp.msg_flags;
-	msg->hash_index = tmp.hash_index;
-	msg->force_send_socket = tmp.force_send_socket;
-	msg->fwd_send_flags = tmp.fwd_send_flags;
-	msg->rpl_send_flags = tmp.rpl_send_flags;
-	msg->dst_uri = tmp.dst_uri;
-	msg->path_vec = tmp.path_vec;
-
-	memcpy(msg->buf, obuf->s, obuf->len);
-	msg->len = obuf->len;
-	msg->buf[msg->len] = '\0';
-
-	/* reparse the message */
-	LM_DBG("SIP message content updated - reparsing\n");
-	if(parse_msg(msg->buf, msg->len, msg) != 0) {
-		LM_ERR("parsing new sip message failed [[%.*s]]\n", msg->len, msg->buf);
-		/* exit config execution - sip_msg_t structure is no longer
-		 * valid/safe for config */
-		return 0;
-	}
 
-	return 1;
+	return sip_msg_update_buffer(msg, obuf);
 }
 
 /**
@@ -222,39 +176,12 @@ static int ki_msg_set_buffer(sip_msg_t *msg, str *obuf)
  */
 static int ki_msg_apply_changes(sip_msg_t *msg)
 {
-	int ret;
-	dest_info_t dst;
-	str obuf;
-
 	if(msg->first_line.type != SIP_REPLY && get_route_type() != REQUEST_ROUTE) {
 		LM_ERR("invalid usage - not in request route or a reply\n");
 		return -1;
 	}
 
-	init_dest_info(&dst);
-	dst.proto = PROTO_UDP;
-	if(msg->first_line.type == SIP_REPLY) {
-		obuf.s = generate_res_buf_from_sip_res(
-				msg, (unsigned int *)&obuf.len, BUILD_NO_VIA1_UPDATE);
-	} else {
-		if(msg->msg_flags & FL_RR_ADDED) {
-			LM_ERR("cannot apply msg changes after adding record-route"
-				   " header - it breaks conditional 2nd header\n");
-			return -1;
-		}
-		obuf.s = build_req_buf_from_sip_req(msg, (unsigned int *)&obuf.len,
-				&dst,
-				BUILD_NO_PATH | BUILD_NO_LOCAL_VIA | BUILD_NO_VIA1_UPDATE);
-	}
-	if(obuf.s == NULL) {
-		LM_ERR("couldn't update msg buffer content\n");
-		return -1;
-	}
-	ret = ki_msg_update_buffer(msg, &obuf);
-	/* free new buffer - copied in the static buffer from old sip_msg_t */
-	pkg_free(obuf.s);
-
-	return ret;
+	return sip_msg_apply_changes(msg);
 }
 
 /**




More information about the sr-dev mailing list