return res;
}
+#define DEFAULT_MAX_FORWARDS 70
+
/*--- sip_transfer: Transfer SIP call */
static int sip_transfer(struct ast_channel *ast, const char *dest)
char from[256];
char *of, *c;
char referto[256];
+ char tmp[80];
if (ast_test_flag(p, SIP_OUTGOING))
of = get_header(&p->initreq, "To");
} else
of += 4;
/* Get just the username part */
- if ((c = strchr(of, '@'))) {
+ if ((c = strchr(dest, '@'))) {
+ c = NULL;
+ } else if ((c = strchr(of, '@'))) {
*c = '\0';
c++;
}
snprintf(referto, sizeof(referto), "<sip:%s>", dest);
}
- /* save in case we get 407 challenge */
- ast_copy_string(p->refer_to, referto, sizeof(p->refer_to));
- ast_copy_string(p->referred_by, p->our_contact, sizeof(p->referred_by));
-
- reqprep(&req, p, SIP_REFER, 0, 1);
- add_header(&req, "Refer-To", referto);
- if (!ast_strlen_zero(p->our_contact))
- add_header(&req, "Referred-By", p->our_contact);
- add_blank_header(&req);
- return send_request(p, &req, 1, p->ocseq);
+ ast_copy_string(tmp, get_header(&p->initreq, "Max-Forwards"), sizeof(tmp));
+ if (strlen(tmp) && atoi(tmp)) {
+ p->maxforwards = atoi(tmp) - 1;
+ } else {
+ p->maxforwards = DEFAULT_MAX_FORWARDS - 1;
+ }
+ if (p->maxforwards > -1) {
+ /* save in case we get 407 challenge */
+ ast_copy_string(p->refer_to, referto, sizeof(p->refer_to));
+ ast_copy_string(p->referred_by, p->our_contact, sizeof(p->referred_by));
+
+ reqprep(&req, p, SIP_REFER, 0, 1);
+ add_header(&req, "Refer-To", referto);
+ if (!ast_strlen_zero(p->our_contact))
+ add_header(&req, "Referred-By", p->our_contact);
+ add_blank_header(&req);
+ return send_request(p, &req, 1, p->ocseq);
+ } else {
+ return -1;
+ }
}
/*--- transmit_info_with_digit: Send SIP INFO dtmf message, see Cisco documentation on cisco.co
return 0;
}
-#define DEFAULT_MAX_FORWARDS 70
-
/*--- sip_sipredirect: Transfer call before connect with a 302 redirect ---*/
/* Called by the transfer() dialplan application through the sip_transfer() */
/* pbx interface function if the call is in ringing state */