[sr-dev] git:5.5:0ad72e16: acc: Fix reason code for locally generated replies. (#3137)
Henning Westerholt
hw at gilawa.com
Mon Nov 28 14:32:51 CET 2022
Module: kamailio
Branch: 5.5
Commit: 0ad72e16757e86b6e3be9095d2e6282e9ba1690f
URL: https://github.com/kamailio/kamailio/commit/0ad72e16757e86b6e3be9095d2e6282e9ba1690f
Author: Frits Wiersma <cfwiersma at solcon.nl>
Committer: Henning Westerholt <hw at gilawa.com>
Date: 2022-11-28T13:30:11Z
acc: Fix reason code for locally generated replies. (#3137)
* acc: Fix reason code for locally generated replies.
- Use heap memory for the reason code instead of the stack memory.
- See issue #2981
* acc: Remove code which was commented out.
- Code was commented out in the previous pull request. (#3137).
- This has now been corrected.
(cherry picked from commit e74cb2371ab879874a8981818139024f1c2beb9e)
---
Modified: src/modules/acc/acc_logic.c
---
Diff: https://github.com/kamailio/kamailio/commit/0ad72e16757e86b6e3be9095d2e6282e9ba1690f.diff
Patch: https://github.com/kamailio/kamailio/commit/0ad72e16757e86b6e3be9095d2e6282e9ba1690f.patch
---
diff --git a/src/modules/acc/acc_logic.c b/src/modules/acc/acc_logic.c
index e045b8c95ac..169a4222fbf 100644
--- a/src/modules/acc/acc_logic.c
+++ b/src/modules/acc/acc_logic.c
@@ -93,25 +93,20 @@ 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;
+int env_set_reason(struct sip_msg *reply, str *buff, int code) {
+
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++;
- }
+
+ /* Set the reason to a pointer in heap memory. It will contain the last seen FAKED_REPLY */
+ acc_env.reason.s = error_text(code);
+ acc_env.reason.len = strlen(acc_env.reason.s);
+ LM_DBG("reason[%.*s]\n", acc_env.reason.len, acc_env.reason.s);
+
return 0;
}
@@ -139,7 +134,8 @@ 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 */
- if (acc_env.reason.len == 0) { /* already extracted in case of locally generated replies */
+ /* In case of an ACK the reply == NULL, but the reason must be set when report_ack is 1 */
+ if (acc_env.reason.len == 0 || reply==NULL) { /* already extracted in case of locally generated replies */
acc_env.reason.s = error_text(code);
acc_env.reason.len = strlen(acc_env.reason.s);
}
@@ -719,7 +715,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);
+ env_set_reason(ps->rpl, &ps->send_buf, ps->code);
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