Browse code

acc: use sent reason phrase for locally generated

replies

Julien Chavanton authored on 12/08/2020 21:40:42
Showing 1 changed files
... ...
@@ -93,6 +93,28 @@ void env_set_totag(struct cell *t, struct sip_msg *reply)
93 93
 		tmb.t_get_reply_totag(t->uas.request, &acc_env.to_tag);
94 94
 }
95 95
 
96
+int env_set_reason(struct sip_msg *reply, str *buff) {
97
+	int i;
98
+	char *p;
99
+	if (reply!=FAKED_REPLY || !buff || !buff->s || buff->len < 20)
100
+		return 0;
101
+	if (strncmp(buff->s, "SIP/2.0 ", 8) != 0) {
102
+		LM_ERR("not a SIP reply\n");
103
+		return 0;
104
+	}
105
+	p = buff->s + 12;
106
+	for (i=12;i<buff->len;i++) {
107
+		if (*p == '\r' || *p == '\n') {
108
+			acc_env.reason.s = buff->s+12;
109
+			acc_env.reason.len = i-12;
110
+			LM_DBG("reason[%.*s]\n", acc_env.reason.len, acc_env.reason.s);
111
+			return 1;
112
+		}
113
+		p++;
114
+	}
115
+	return 0;
116
+}
117
+
96 118
 static inline void env_set_to(struct hdr_field *to)
97 119
 {
98 120
 	acc_env.to = to;
... ...
@@ -117,8 +139,10 @@ static inline void env_set_code_status( int code, struct sip_msg *reply)
117 139
 		acc_env.code_s.s =
118 140
 			int2bstr((unsigned long)code, code_buf, &acc_env.code_s.len);
119 141
 		/* reason */
120
-		acc_env.reason.s = error_text(code);
121
-		acc_env.reason.len = strlen(acc_env.reason.s);
142
+		if (acc_env.reason.len == 0) { /* already extracted in case of locally generated replies */
143
+			acc_env.reason.s = error_text(code);
144
+			acc_env.reason.len = strlen(acc_env.reason.s);
145
+		}
122 146
 	} else {
123 147
 		acc_env.code_s = reply->first_line.u.reply.status;
124 148
 		hf = NULL;
... ...
@@ -695,6 +719,7 @@ static void tmcb_func( struct cell* t, int type, struct tmcb_params *ps )
695 719
 	LM_DBG("acc callback called for t(%p) event type %d, reply code %d\n",
696 720
 			t, type, ps->code);
697 721
 	if (type&TMCB_RESPONSE_OUT) {
722
+		env_set_reason(ps->rpl, &ps->send_buf);
698 723
 		acc_onreply( t, ps->req, ps->rpl, ps->code);
699 724
 	} else if (type&TMCB_E2EACK_IN) {
700 725
 		acc_onack( t, t->uas.request, ps->req, ps->code);