Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.827 diff -u -r1.827 chan_sip.c --- channels/chan_sip.c 30 Aug 2005 02:12:09 -0000 1.827 +++ channels/chan_sip.c 30 Aug 2005 19:39:56 -0000 @@ -1225,6 +1225,15 @@ struct sip_pvt *p = data; p->autokillid = -1; + + /* If this is a subscription, tell the phone that we got a timeout */ + if (p->subscribed) { + p->subscribed = TIMEOUT; + transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, 1); /* Send first notification */ + p->subscribed = NONE; + append_history(p, "Subscribestatus", "timeout"); + return 10000; /* Reschedule this destruction so that we know that it's gone */ + } ast_log(LOG_DEBUG, "Auto destroying call '%s'\n", p->callid); append_history(p, "AutoDestroy", ""); if (p->owner) { @@ -1247,11 +1256,6 @@ append_history(p, "SchedDestroy", tmp); } - /* If this is a subscription, tell the phone that we got a timeout */ - if (p->subscribed) { - p->subscribed = TIMEOUT; - transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, 1); /* Send first notification */ - } if (p->autokillid > -1) ast_sched_del(sched, p->autokillid); p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, p); @@ -5919,6 +5923,7 @@ ast_verbose(VERBOSE_PREFIX_2 "Extension state: Watcher for hint %s %s. Notify User %s\n", exten, state == AST_EXTENSION_DEACTIVATED ? "deactivated" : "removed", p->username); p->stateid = -1; p->subscribed = NONE; + append_history(p, "Subscribestatus", state == AST_EXTENSION_REMOVED ? "HintRemoved" : "Deactivated"); break; default: /* Tell user */ p->laststate = state; @@ -7981,7 +7986,7 @@ if (!strncasecmp(cur->callid, argv[3],len)) { ast_cli(fd,"\n"); if (cur->subscribed != NONE) - ast_cli(fd, " * Subscription\n"); + ast_cli(fd, " * Subscription (type: %s)\n", subscription_type2str(cur->subscribed)); else ast_cli(fd, " * SIP Call\n"); ast_cli(fd, " Direction: %s\n", ast_test_flag(cur, SIP_OUTGOING)?"Outgoing":"Incoming"); @@ -9972,9 +9977,8 @@ int gotdest; int res = 0; int firststate = 0; - struct ast_channel *c=NULL; - if (p->initreq.headers) { + if (p->initreq.headers) { /* We already have a dialog */ if (p->initreq.method != SIP_SUBSCRIBE) { /* This is a SUBSCRIBE within another SIP dialog, which we do not support */ @@ -9988,7 +9992,7 @@ ast_log(LOG_DEBUG, "Got a re-subscribe on existing subscription %s\n", p->callid); } } - if (!ignore) { + if (!ignore && !p->initreq.headers) { /* Use this as the basis */ if (debug) ast_verbose("Using latest SUBSCRIBE request as basis request\n"); @@ -9996,7 +10000,7 @@ ast_clear_flag(p, SIP_OUTGOING); copy_request(&p->initreq, req); check_via(p, req); - } else if (debug) + } else if (debug && ignore) ast_verbose("Ignoring this SUBSCRIBE request\n"); if (!p->lastinvite) { @@ -10030,8 +10034,9 @@ char *event = get_header(req, "Event"); /* Get Event package name */ char *accept = get_header(req, "Accept"); - /* Initialize tag */ - p->tag = rand(); + /* Initialize tag for new subscriptions */ + if (!p->tag) + p->tag = rand(); if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */ @@ -10098,8 +10103,7 @@ return 0; } } - } else - c = p->owner; + } if (!ignore && p) p->lastinvite = seqno; @@ -10118,8 +10122,11 @@ if (sipdebug || option_debug > 1) ast_log(LOG_DEBUG, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username); transmit_response(p, "200 OK", req); + if (p->autokillid > -1) + sip_cancel_destroy(p); /* Remove subscription expiry for renewals */ sip_scheddestroy(p, (p->expiry + 10) * 1000); /* Set timer for destruction of call at expiration */ transmit_state_notify(p, firststate, 1, 1); /* Send first notification */ + append_history(p, "Subscribestatus", "active"); } return 1; }