Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.722 diff -u -r1.722 chan_sip.c --- channels/chan_sip.c 3 May 2005 03:22:14 -0000 1.722 +++ channels/chan_sip.c 4 May 2005 00:41:57 -0000 @@ -403,6 +403,7 @@ struct sip_pvt *refer_call; /* Call we are referring */ struct sip_route *route; /* Head of linked list of routing steps (fm Record-Route) */ int route_persistant; /* Is this the "real" route? */ + char notifyType[256]; /* Custom notify type */ char from[256]; /* The From: header */ char useragent[256]; /* User agent in SIP request */ char context[AST_MAX_EXTENSION]; /* Context for this call */ @@ -4083,6 +4084,8 @@ static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, char *auth, char *authheader, char *vxml_url, char *distinctive_ring, char *osptoken, int addsipheaders, int init) { struct sip_request req; + struct ast_variable *varlist; + struct ast_variable *var; if (init) { /* Bump branch even on initial requests */ @@ -4090,11 +4093,10 @@ build_via(p, p->via, sizeof(p->via)); initreqprep(&req, p, sipmethod, vxml_url); } else - reqprep(&req, p, sipmethod, 0, 1); + reqprep(&req, p, sipmethod, 0, (p->notifyType ? 0 : 1)); if (auth) add_header(&req, authheader, auth); - append_date(&req); if (sipmethod == SIP_REFER) { if (!ast_strlen_zero(p->refer_to)) add_header(&req, "Refer-To", p->refer_to); @@ -4115,7 +4117,21 @@ { add_header(&req, "Alert-Info",distinctive_ring); } - add_header(&req, "Allow", ALLOWED_METHODS); + if(p->notifyType) { + varlist = ast_variable_browse(notify_types, p->notifyType); + if(!varlist) { + ast_log(LOG_DEBUG, "Unable to find notify type '%s'\n", p->notifyType); + } else { + ast_log(LOG_DEBUG, "Reasserting headers for NOTIFY type %s\n", p->notifyType); + for (var = varlist; var; var = var->next) { + ast_log(LOG_DEBUG, " Adding pair %s=%s\n", var->name, var->value); + add_header(&req, var->name, var->value); + } + } + } else { + append_date(&req); + add_header(&req, "Allow", ALLOWED_METHODS); + } if (addsipheaders && init) { struct ast_channel *ast; char *header = (char *) NULL; @@ -4161,7 +4177,8 @@ ast_rtp_offered_from_local(p->rtp, 1); add_sdp(&req, p); } else { - add_header(&req, "Content-Length", "0"); + if(!p->notifyType) + add_header(&req, "Content-Length", "0"); add_blank_header(&req); } @@ -7440,6 +7457,7 @@ ast_log(LOG_WARNING, "Unable to build sip pvt data for notify\n"); return RESULT_FAILURE; } + ast_copy_string(p->notifyType, argv[2], sizeof(p->notifyType)); if (create_addr(p, argv[i])) { /* Maybe they're not registered, etc. */ @@ -7448,6 +7466,7 @@ continue; } + ast_set_flag(p, SIP_OUTGOING); initreqprep(&req, p, SIP_NOTIFY, NULL); for (var = varlist; var; var = var->next) @@ -7458,7 +7477,6 @@ if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); build_via(p, p->via, sizeof(p->via)); - build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain); ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[2], argv[i]); transmit_sip_request(p, &req); sip_scheddestroy(p, 15000); @@ -8167,6 +8185,12 @@ p->theirtag[0]='\0'; /* forget their old tag, so we don't match tags when getting response */ if ((p->authtries > 1) || do_proxy_auth(p, req, "WWW-Authenticate", "Authorization", SIP_INVITE, 1)) { ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From")); + ast_set_flag(p, SIP_NEEDDESTROY); + } + } else if (sipmethod == SIP_NOTIFY) { + p->theirtag[0]='\0'; /* forget their old tag, so we don't match tags when getting response */ + if ((p->authtries > 1) || do_proxy_auth(p, req, "WWW-Authenticate", "Authorization", SIP_NOTIFY, 1)) { + ast_log(LOG_NOTICE, "Failed to authenticate on NOTIFY to '%s'\n", get_header(&p->initreq, "From")); ast_set_flag(p, SIP_NEEDDESTROY); } } else if (p->registry && sipmethod == SIP_REGISTER) {