* 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.
... | ... |
@@ -93,25 +93,20 @@ 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; |
|
96 |
+int env_set_reason(struct sip_msg *reply, str *buff, int code) { |
|
97 |
+ |
|
99 | 98 |
if (reply!=FAKED_REPLY || !buff || !buff->s || buff->len < 20) |
100 | 99 |
return 0; |
101 | 100 |
if (strncmp(buff->s, "SIP/2.0 ", 8) != 0) { |
102 | 101 |
LM_ERR("not a SIP reply\n"); |
103 | 102 |
return 0; |
104 | 103 |
} |
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 |
- } |
|
104 |
+ |
|
105 |
+ /* Set the reason to a pointer in heap memory. It will contain the last seen FAKED_REPLY */ |
|
106 |
+ acc_env.reason.s = error_text(code); |
|
107 |
+ acc_env.reason.len = strlen(acc_env.reason.s); |
|
108 |
+ LM_DBG("reason[%.*s]\n", acc_env.reason.len, acc_env.reason.s); |
|
109 |
+ |
|
115 | 110 |
return 0; |
116 | 111 |
} |
117 | 112 |
|
... | ... |
@@ -139,7 +134,8 @@ static inline void env_set_code_status( int code, struct sip_msg *reply) |
139 | 134 |
acc_env.code_s.s = |
140 | 135 |
int2bstr((unsigned long)code, code_buf, &acc_env.code_s.len); |
141 | 136 |
/* reason */ |
142 |
- if (acc_env.reason.len == 0) { /* already extracted in case of locally generated replies */ |
|
137 |
+ /* In case of an ACK the reply == NULL, but the reason must be set when report_ack is 1 */ |
|
138 |
+ if (acc_env.reason.len == 0 || reply==NULL) { /* already extracted in case of locally generated replies */ |
|
143 | 139 |
acc_env.reason.s = error_text(code); |
144 | 140 |
acc_env.reason.len = strlen(acc_env.reason.s); |
145 | 141 |
} |
... | ... |
@@ -719,7 +715,7 @@ static void tmcb_func( struct cell* t, int type, struct tmcb_params *ps ) |
719 | 715 |
LM_DBG("acc callback called for t(%p) event type %d, reply code %d\n", |
720 | 716 |
t, type, ps->code); |
721 | 717 |
if (type&TMCB_RESPONSE_OUT) { |
722 |
- env_set_reason(ps->rpl, &ps->send_buf); |
|
718 |
+ env_set_reason(ps->rpl, &ps->send_buf, ps->code); |
|
723 | 719 |
acc_onreply( t, ps->req, ps->rpl, ps->code); |
724 | 720 |
} else if (type&TMCB_E2EACK_IN) { |
725 | 721 |
acc_onack( t, t->uas.request, ps->req, ps->code); |