[sr-dev] git:master:c5f6ff37: acc: use sent reason phrase for locally generated

Julien Chavanton jchavanton at gmail.com
Mon Aug 24 09:23:30 CEST 2020


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

Author: Julien Chavanton <jchavanton at gmail.com>
Committer: Julien Chavanton <jchavanton at gmail.com>
Date: 2020-08-12T14:40:42-07:00

acc: use sent reason phrase for locally generated

 replies

---

Modified: src/modules/acc/acc_logic.c

---

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

---

diff --git a/src/modules/acc/acc_logic.c b/src/modules/acc/acc_logic.c
index 818c7aa101..e045b8c95a 100644
--- a/src/modules/acc/acc_logic.c
+++ b/src/modules/acc/acc_logic.c
@@ -93,6 +93,28 @@ void env_set_totag(struct cell *t, struct sip_msg *reply)
 		tmb.t_get_reply_totag(t->uas.request, &acc_env.to_tag);
 }
 
+int env_set_reason(struct sip_msg *reply, str *buff) {
+	int i;
+	char *p;
+	if (reply!=FAKED_REPLY || !buff || !buff->s || buff->len < 20)
+		return 0;
+	if (strncmp(buff->s, "SIP/2.0 ", 8) != 0) {
+		LM_ERR("not a SIP reply\n");
+		return 0;
+	}
+	p = buff->s + 12;
+	for (i=12;i<buff->len;i++) {
+		if (*p == '\r' || *p == '\n') {
+			acc_env.reason.s = buff->s+12;
+			acc_env.reason.len = i-12;
+			LM_DBG("reason[%.*s]\n", acc_env.reason.len, acc_env.reason.s);
+			return 1;
+		}
+		p++;
+	}
+	return 0;
+}
+
 static inline void env_set_to(struct hdr_field *to)
 {
 	acc_env.to = to;
@@ -117,8 +139,10 @@ static inline void env_set_code_status( int code, struct sip_msg *reply)
 		acc_env.code_s.s =
 			int2bstr((unsigned long)code, code_buf, &acc_env.code_s.len);
 		/* reason */
-		acc_env.reason.s = error_text(code);
-		acc_env.reason.len = strlen(acc_env.reason.s);
+		if (acc_env.reason.len == 0) { /* already extracted in case of locally generated replies */
+			acc_env.reason.s = error_text(code);
+			acc_env.reason.len = strlen(acc_env.reason.s);
+		}
 	} else {
 		acc_env.code_s = reply->first_line.u.reply.status;
 		hf = NULL;
@@ -695,6 +719,7 @@ static void tmcb_func( struct cell* t, int type, struct tmcb_params *ps )
 	LM_DBG("acc callback called for t(%p) event type %d, reply code %d\n",
 			t, type, ps->code);
 	if (type&TMCB_RESPONSE_OUT) {
+		env_set_reason(ps->rpl, &ps->send_buf);
 		acc_onreply( t, ps->req, ps->rpl, ps->code);
 	} else if (type&TMCB_E2EACK_IN) {
 		acc_onack( t, t->uas.request, ps->req, ps->code);




More information about the sr-dev mailing list