[asterisk-commits] rizzo: branch rizzo/astobj2 r47561 -
/team/rizzo/astobj2/channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Nov 13 11:01:44 MST 2006
Author: rizzo
Date: Mon Nov 13 12:01:43 2006
New Revision: 47561
URL: http://svn.digium.com/view/asterisk?view=rev&rev=47561
Log:
wrap setting of the NEEDDESTROY in functions/macros to make things
more readable.
Modified:
team/rizzo/astobj2/channels/chan_sip.c
Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=47561&r1=47560&r2=47561
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Mon Nov 13 12:01:43 2006
@@ -1046,6 +1046,24 @@
return NULL;
}
+/*! \brief set the SIP_NEEDDESTROY flag on a dialog */
+static inline void set_destroy(struct sip_pvt *pvt)
+{
+ ast_set_flag(&pvt->flags[0], SIP_NEEDDESTROY);
+}
+
+/*! \brief clear the SIP_NEEDDESTROY flag on a dialog */
+static inline void clear_destroy(struct sip_pvt *pvt)
+{
+ ast_set_flag(&pvt->flags[0], SIP_NEEDDESTROY);
+}
+
+/*! \brief test the SIP_NEEDDESTROY flag on a dialog */
+static inline int test_destroy(const struct sip_pvt *pvt)
+{
+ return ast_test_flag(&pvt->flags[0], SIP_NEEDDESTROY);
+}
+
#define FLAG_RESPONSE (1 << 0)
#define FLAG_FATAL (1 << 1)
@@ -2021,7 +2039,7 @@
ast_channel_unlock(pvt->owner);
} else {
/* If no channel owner, destroy now */
- ast_set_flag(&pvt->flags[0], SIP_NEEDDESTROY);
+ set_destroy(pvt);
}
}
@@ -3474,7 +3492,7 @@
ast_log(LOG_DEBUG, "SIP Transfer: Not hanging up right now... Rescheduling hangup for %s.\n", p->callid);
sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); /* also cancels previous one if there */
ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Really hang up next time */
- ast_clear_flag(&p->flags[0], SIP_NEEDDESTROY);
+ clear_destroy(p);
/* XXX assert(p->owner == ast); */
if (p->owner->tech_pvt) /* i believe that's always */
p->owner->tech_pvt = pvt_unref(p->owner->tech_pvt);
@@ -3591,7 +3609,7 @@
}
}
if (needdestroy)
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
sip_pvt_unlock(p);
return 0;
}
@@ -7295,7 +7313,7 @@
r->register_pvt = NULL;
if (p->registry)
unref_registry(p->registry);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
/* Pretend to ACK anything just in case */
__sip_pretend_ack(p); /* XXX we need p locked, not sure we have */
sip_destroy(p); /* reference goes away */
@@ -10683,7 +10701,7 @@
cur->ocseq, cur->icseq,
ast_getformatname(cur->owner ? cur->owner->nativeformats : 0),
ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD) ? "Yes" : "No",
- ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY) ? "(d)" : "",
+ test_destroy(cur) ? "(d)" : "",
cur->lastmsg ,
referstatus
);
@@ -10934,7 +10952,7 @@
ast_cli(fd, " Original uri: %s\n", cur->uri);
if (!ast_strlen_zero(cur->cid_num))
ast_cli(fd, " Caller-ID: %s\n", cur->cid_num);
- ast_cli(fd, " Need Destroy: %d\n", ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY));
+ ast_cli(fd, " Need Destroy: %d\n", test_destroy(cur));
ast_cli(fd, " Last Message: %s\n", cur->lastmsg);
ast_cli(fd, " Promiscuous Redir: %s\n", ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR) ? "Yes" : "No");
ast_cli(fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A");
@@ -12108,7 +12126,7 @@
if (!req_ignore(req)) {
if (p->authtries == MAX_AUTHTRIES || do_proxy_auth(p, req, resp, SIP_INVITE, 1)) {
ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From"));
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
ast_set_flag(&p->flags[0], SIP_ALREADYGONE);
if (p->owner)
ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
@@ -12122,7 +12140,7 @@
ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", get_header(&p->initreq, "From"));
if (!req_ignore(req) && p->owner)
ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
ast_set_flag(&p->flags[0], SIP_ALREADYGONE);
break;
@@ -12146,7 +12164,7 @@
transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
if (p->owner && !req_ignore(req))
ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
break;
case 501: /* Not implemented */
@@ -12181,12 +12199,12 @@
if (ast_strlen_zero(p->authname)) {
ast_log(LOG_WARNING, "Asked to authenticate REFER to %s:%d but we have no matching peer or realm auth!\n",
ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port));
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
if (p->authtries > 1 || do_proxy_auth(p, req, resp, SIP_REFER, 0)) {
ast_log(LOG_NOTICE, "Failed to authenticate on REFER to '%s'\n", get_header(&p->initreq, "From"));
p->refer->status = REFER_NOAUTH;
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
break;
@@ -12196,13 +12214,13 @@
/* Return to the current call onhold */
/* Status flag needed to be reset */
ast_log(LOG_NOTICE, "SIP transfer to %s failed, call miserably fails. \n", p->refer->refer_to);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
p->refer->status = REFER_FAILED;
break;
case 603: /* Transfer declined */
ast_log(LOG_NOTICE, "SIP transfer to %s declined, call miserably fails. \n", p->refer->refer_to);
p->refer->status = REFER_FAILED;
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
break;
}
}
@@ -12217,7 +12235,7 @@
case 401: /* Unauthorized */
if (p->authtries == MAX_AUTHTRIES || do_register_auth(p, req, resp)) {
ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s@%s' (Tries %d)\n", p->registry->username, p->registry->hostname, p->authtries);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
break;
case 403: /* Forbidden */
@@ -12225,13 +12243,13 @@
if (global_regattempts_max)
p->registry->regattempts = global_regattempts_max+1;
ast_sched_del(sched, r->timeout);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
break;
case 404: /* Not found */
ast_log(LOG_WARNING, "Got 404 Not found on SIP register to service %s@%s, giving up\n", p->registry->username,p->registry->hostname);
if (global_regattempts_max)
p->registry->regattempts = global_regattempts_max+1;
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
if (r->register_pvt) /* XXX are we sure about destroy ? */
r->register_pvt = sip_destroy(r->register_pvt);
ast_sched_del(sched, r->timeout);
@@ -12239,7 +12257,7 @@
case 407: /* Proxy auth */
if (p->authtries == MAX_AUTHTRIES || do_register_auth(p, req, resp)) {
ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s' (tries '%d')\n", get_header(&p->initreq, "From"), p->authtries);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
break;
case 423: /* Interval too brief */
@@ -12249,7 +12267,7 @@
r->timeout = -1;
if (r->register_pvt) { /* XXX are we sure about destroy ? */
r->register_pvt = sip_destroy(r->register_pvt);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
if (r->expiry > max_expiry) {
ast_log(LOG_WARNING, "Required expiration time from %s@%s is too high, giving up\n", p->registry->username, p->registry->hostname);
@@ -12265,7 +12283,7 @@
ast_log(LOG_WARNING, "Got error 479 on register to %s@%s, giving up (check config)\n", p->registry->username,p->registry->hostname);
if (global_regattempts_max)
p->registry->regattempts = global_regattempts_max+1;
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
if (r->register_pvt) /* XXX are we sure about destroy ? */
r->register_pvt = sip_destroy(r->register_pvt);
ast_sched_del(sched, r->timeout);
@@ -12273,7 +12291,7 @@
case 200: /* 200 OK */
if (!r) {
ast_log(LOG_WARNING, "Got 200 OK on REGISTER that isn't a register\n");
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
return 0;
}
@@ -12390,7 +12408,7 @@
if (peer->pokeexpire > -1)
ast_sched_del(sched, peer->pokeexpire);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
/* Try again eventually */
peer->pokeexpire = ast_sched_add(sched,
@@ -12467,7 +12485,7 @@
p->authtries = 0; /* Reset authentication counter */
if (sipmethod == SIP_MESSAGE) {
/* We successfully transmitted a message */
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
} else if (sipmethod == SIP_INVITE) {
handle_response_invite(p, resp, rest, req, seqno);
} else if (sipmethod == SIP_NOTIFY) {
@@ -12480,12 +12498,12 @@
ast_log(LOG_DEBUG, "Got OK on REFER Notify message\n");
} else {
if (p->subscribed == NONE)
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
} else if (sipmethod == SIP_REGISTER)
res = handle_response_register(p, resp, rest, req, seqno);
else if (sipmethod == SIP_BYE) /* Ok, we're ready to go */
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
break;
case 202: /* Transfer accepted */
if (sipmethod == SIP_REFER)
@@ -12500,7 +12518,7 @@
res = handle_response_register(p, resp, rest, req, seqno);
else {
ast_log(LOG_WARNING, "Got authentication request (401) on unknown %s to '%s'\n", sip_methods[sipmethod].text, get_header(req, "To"));
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
break;
case 403: /* Forbidden - we failed authentication */
@@ -12510,7 +12528,7 @@
res = handle_response_register(p, resp, rest, req, seqno);
else {
ast_log(LOG_WARNING, "Forbidden - maybe wrong password on authentication for %s\n", msg);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
break;
case 404: /* Not found */
@@ -12532,13 +12550,13 @@
if (ast_strlen_zero(p->authname))
ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n",
msg, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port));
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
if (p->authtries == MAX_AUTHTRIES || do_proxy_auth(p, req, 407, sipmethod, 0)) {
ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From"));
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
} else /* We can't handle this, giving up in a bad way */
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
break;
case 423: /* Interval too brief */
@@ -12560,7 +12578,7 @@
ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid);
if (owner)
ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
} else if (sipmethod == SIP_BYE) {
/* The other side has no transaction to bye,
just assume it's all right then */
@@ -12580,7 +12598,7 @@
else {
if (option_debug)
ast_log(LOG_DEBUG, "Got 491 on %s, unspported. Call ID %s\n", sip_methods[sipmethod].text, p->callid);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
break;
case 501: /* Not Implemented */
@@ -12663,7 +12681,7 @@
transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
ast_set_flag(&p->flags[0], SIP_ALREADYGONE);
if (!p->owner)
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
} else if ((resp >= 100) && (resp < 200)) {
if (sipmethod == SIP_INVITE) {
if (!req_ignore(req))
@@ -12709,17 +12727,17 @@
/* ast_queue_hangup(p->owner); Disabled */
} else {
if (!p->subscribed && !p->refer)
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
} else if (sipmethod == SIP_BYE)
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
else if (sipmethod == SIP_MESSAGE)
/* We successfully transmitted a message */
/* XXX Why destroy this pvt after message transfer? Bad */
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
else if (sipmethod == SIP_BYE)
/* Ok, we're ready to go */
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
break;
case 202: /* Transfer accepted */
if (sipmethod == SIP_REFER)
@@ -12734,7 +12752,7 @@
else if (sipmethod == SIP_BYE) {
if (p->authtries == MAX_AUTHTRIES || do_proxy_auth(p, req, resp, sipmethod, 0)) {
ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From"));
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
}
break;
@@ -12743,7 +12761,7 @@
/* Re-invite failed */
handle_response_invite(p, resp, rest, req, seqno);
} else if (sipmethod == SIP_BYE) {
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
} else if (sipdebug) {
ast_log (LOG_DEBUG, "Remote host can't match request %s to call '%s'. Giving up\n", sip_methods[sipmethod].text, p->callid);
}
@@ -14073,7 +14091,7 @@
if (!req_ignore(req)) {
append_history(p, "Xfer", "Refer failed. Outside of dialog.");
ast_set_flag(&p->flags[0], SIP_ALREADYGONE);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
return 0;
}
@@ -14476,7 +14494,7 @@
*/
if (!global_allowsubscribe) {
transmit_response(p, "403 Forbidden (policy)", req);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
return 0;
}
@@ -14495,7 +14513,7 @@
transmit_response(p, "489 Bad Event", req);
if (option_debug > 1)
ast_log(LOG_DEBUG, "Received SIP subscribe for unknown event package: <none>\n");
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
return 0;
}
@@ -14520,7 +14538,7 @@
ast_log(LOG_NOTICE, "Failed to authenticate user %s for SUBSCRIBE\n", get_header(req, "From"));
transmit_response_reliable(p, "403 Forbidden", req);
}
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
return 0;
}
@@ -14532,7 +14550,7 @@
/* Check if this user/peer is allowed to subscribe at all */
if (!ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) {
transmit_response(p, "403 Forbidden (policy)", req);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
if (authpeer)
unref_peer(authpeer);
return 0;
@@ -14554,7 +14572,7 @@
build_contact(p);
if (gotdest) {
transmit_response(p, "404 Not Found", req);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
if (authpeer)
unref_peer(authpeer);
return 0;
@@ -14586,7 +14604,7 @@
} else {
/* Can't find a format for events that we know about */
transmit_response(p, "489 Bad Event", req);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
return 0;
}
} else if (!strcmp(event, "message-summary")) {
@@ -14595,7 +14613,7 @@
transmit_response(p, "406 Not Acceptable", req);
if (option_debug > 1)
ast_log(LOG_DEBUG, "Received SIP mailbox subscription for unknown format: %s\n", accept);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
if (authpeer)
unref_peer(authpeer);
return 0;
@@ -14607,7 +14625,7 @@
*/
if (!authpeer || ast_strlen_zero(authpeer->mailbox)) {
transmit_response(p, "404 Not found (no mailbox)", req);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
ast_log(LOG_NOTICE, "Received SIP subscribe for peer without mailbox: %s\n",
authpeer ? authpeer->name : "(no peer)");
if (authpeer)
@@ -14630,7 +14648,7 @@
transmit_response(p, "489 Bad Event", req);
if (option_debug > 1)
ast_log(LOG_DEBUG, "Received SIP subscribe for unknown event package: %s\n", event);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
if (authpeer)
unref_peer(authpeer);
return 0;
@@ -14674,7 +14692,7 @@
ast_log(LOG_ERROR, "Got SUBSCRIBE for extension %s@%s from %s, but there is no hint for that extension\n", p->exten, p->context, ast_inet_ntoa(p->sa.sin_addr));
transmit_response(p, "404 Not found", req);
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
return 0;
}
@@ -14705,7 +14723,7 @@
if (!strcmp(p_old->username, p->username)) {
if (!strcmp(p_old->exten, p->exten) &&
!strcmp(p_old->context, p->context)) {
- ast_set_flag(&p_old->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p_old);
sip_pvt_unlock(p_old);
ao2_ref(p_old, -1);
break;
@@ -14726,7 +14744,7 @@
if (!strcmp(p_old->username, p->username)) {
if (!strcmp(p_old->exten, p->exten) &&
!strcmp(p_old->context, p->context)) {
- ast_set_flag(&p_old->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p_old);
sip_pvt_unlock(p_old);
break;
}
@@ -14738,7 +14756,7 @@
}
}
if (!p->expiry)
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
}
return 1;
}
@@ -14822,7 +14840,7 @@
}
if (error) {
if (!p->initreq.header) /* New call */
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); /* Make sure we destroy this dialog */
+ set_destroy(p); /* Make sure we destroy this dialog */
return -1;
}
/* Get the command XXX */
@@ -14973,7 +14991,7 @@
}
/* Got an ACK that we did not match. Ignore silently */
if (!p->lastinvite && ast_strlen_zero(p->randdata))
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
break;
default:
transmit_response_with_allow(p, "501 Method Not Implemented", req, 0);
@@ -14981,7 +14999,7 @@
cmd, ast_inet_ntoa(p->sa.sin_addr));
/* If this is some new method, and we don't have a call, destroy it now */
if (!p->initreq.headers)
- ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ set_destroy(p);
break;
}
return res;
More information about the asterisk-commits
mailing list