? channels/.chan_sip.c.swp 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 02:29:03 -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? */ + struct ast_variable *notify_headers; /* 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 */ @@ -1690,6 +1691,10 @@ if (p->autokillid > -1) ast_sched_del(sched, p->autokillid); + if (p->notify_headers) { + ast_variables_destroy(p->notify_headers); + p->notify_headers = NULL; + } if (p->rtp) { ast_rtp_destroy(p->rtp); } @@ -4083,6 +4088,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 +4097,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->notify_headers ? 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 +4121,16 @@ { add_header(&req, "Alert-Info",distinctive_ring); } - add_header(&req, "Allow", ALLOWED_METHODS); + if(p->notify_headers) { + varlist = p->notify_headers; + 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 +4176,8 @@ ast_rtp_offered_from_local(p->rtp, 1); add_sdp(&req, p); } else { - add_header(&req, "Content-Length", "0"); + if(!p->notify_headers) + add_header(&req, "Content-Length", "0"); add_blank_header(&req); } @@ -7433,7 +7449,7 @@ for (i = 3; i < argc; i++) { struct sip_pvt *p; struct sip_request req; - struct ast_variable *var; + struct ast_variable *var, *newvar; p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY); if (!p) { @@ -7441,6 +7457,15 @@ return RESULT_FAILURE; } + /* copy invite vars */ + var = varlist; + p->notify_headers = newvar = ast_variable_new(var->name, var->value); + while(var->next) { + var = var->next; + newvar->next = ast_variable_new(var->name, var->value); + newvar = newvar->next; + } + if (create_addr(p, argv[i])) { /* Maybe they're not registered, etc. */ sip_destroy(p); @@ -7448,6 +7473,7 @@ continue; } + ast_set_flag(p, SIP_OUTGOING); initreqprep(&req, p, SIP_NOTIFY, NULL); for (var = varlist; var; var = var->next) @@ -7458,7 +7484,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 +8192,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) {