[asterisk-commits] rizzo: branch rizzo/astobj2 r76334 - /team/rizzo/astobj2/channels/chan_sip.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Jul 22 04:08:04 CDT 2007
Author: rizzo
Date: Sun Jul 22 04:08:03 2007
New Revision: 76334
URL: http://svn.digium.com/view/asterisk?view=rev&rev=76334
Log:
sync management of 'realtime' and 'debug' flags with trunk
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=76334&r1=76333&r2=76334
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sun Jul 22 04:08:03 2007
@@ -768,7 +768,7 @@
#define SIP_PROMISCREDIR (1 << 8) /*!< DP: Promiscuous redirection */
#define SIP_TRUSTRPID (1 << 9) /*!< DP: Trust RPID headers? */
#define SIP_USEREQPHONE (1 << 10) /*!< DP: Add user=phone to numeric URI. Default off */
-#define SIP_REALTIME (1 << 11) /*!< P: Flag for realtime users */
+#define __SIP_REALTIME (1 << 11) /*!< P: Flag for realtime users */
#define SIP_USECLIENTCODE (1 << 12) /*!< DP: Trust X-ClientCode info message */
#define SIP_OUTGOING (1 << 13) /*!< D: Direction of the last transaction in this dialog */
#define SIP_FREE_BIT (1 << 14) /*!< ---- */
@@ -825,9 +825,9 @@
#define SIP_PAGE2_RTSAVE_SYSNAME (1 << 5)
/* Space for addition of other realtime flags in the future */
#define SIP_PAGE2_IGNOREREGEXPIRE (1 << 10)
-#define SIP_PAGE2_DEBUG (3 << 11)
-#define SIP_PAGE2_DEBUG_CONFIG (1 << 11)
-#define SIP_PAGE2_DEBUG_CONSOLE (1 << 12)
+#define __SIP_PAGE2_DEBUG (3 << 11)
+#define __SIP_PAGE2_DEBUG_CONFIG (1 << 11)
+#define __SIP_PAGE2_DEBUG_CONSOLE (1 << 12)
#define SIP_PAGE2_DYNAMIC (1 << 13) /*!< Dynamic Peers register with Asterisk */
#define SIP_PAGE2_SELFDESTRUCT (1 << 14) /*!< Automatic peers need to destruct themselves */
#define SIP_PAGE2_VIDEOSUPPORT (1 << 15)
@@ -847,7 +847,7 @@
#define SIP_PAGE2_BUGGY_MWI (1 << 26) /*!< 26: Buggy CISCO MWI fix */
#define SIP_PAGE2_NOTEXT (1 << 27) /*!< 27: Text not supported */
#define SIP_PAGE2_TEXTSUPPORT (1 << 28) /*!< 28: Global text enable */
-#define SIP_PAGE2_DEBUG_TEXT (1 << 29) /*!< 29: Global text debug */
+#define __SIP_PAGE2_DEBUG_TEXT (1 << 29) /*!< 29: Global text debug */
#define SIP_PAGE2_OUTGOING_CALL (1 << 30) /*!< 30: Is this an outgoing call? */
#define SIP_PAGE2_FLAGS_TO_COPY \
@@ -881,10 +881,25 @@
/*!< This is default: NO MMR and JBIG transcoding, NO fill bit removal, transferredTCF TCF, UDP FEC, Version 0 and 9600 max fax rate */
static int global_t38_capability = T38FAX_VERSION_0 | T38FAX_RATE_2400 | T38FAX_RATE_4800 | T38FAX_RATE_7200 | T38FAX_RATE_9600;
-#define sipdebug ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG)
-#define sipdebug_config ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONFIG)
-#define sipdebug_console ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE)
-#define sipdebug_text ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_TEXT)
+/*! \brief debugging state
+ * We store separately the debugging requests from the config file
+ * and requests from the CLI. Debugging is enabled if either is set
+ * (which means that if sipdebug is set in the config file, we can
+ * only turn it off by reloading the config).
+ */
+enum sip_debug_e {
+ sip_debug_none = 0,
+ sip_debug_config = 1,
+ sip_debug_console = 2,
+};
+
+static enum sip_debug_e sipdebug;
+
+/*! \brief extra debugging for 'text' related events.
+ * At thie moment this is set together with sip_debug_console.
+ * It should either go away or be implemented properly.
+ */
+static int sipdebug_text;
/*! \brief T38 States for a call */
enum t38state {
@@ -1170,6 +1185,10 @@
ast_group_t pickupgroup; /*!< Pickup Group */
unsigned int sipoptions; /*!< Supported SIP options */
struct ast_flags flags[2]; /*!< SIP_ flags */
+
+ /* things that don't belong in flags */
+ char is_realtime; /*!< this is a 'realtime' user */
+
int amaflags; /*!< AMA flags for billing */
int callingpres; /*!< Calling id presentation */
int capability; /*!< Codec capability */
@@ -1204,6 +1223,10 @@
struct sip_proxy *outboundproxy; /*!< Outbound proxy for this peer */
unsigned int sipoptions; /*!< Supported SIP options */
struct ast_flags flags[2]; /*!< SIP_ flags */
+
+ /* things that don't belong in flags */
+ char is_realtime; /*!< this is a 'realtime' peer */
+
int amaflags; /*!< AMA Flags (for billing) */
int callingpres; /*!< Calling id presentation */
int capability; /*!< Codec capability */
@@ -2946,7 +2969,7 @@
ast_free_ha(peer->ha);
if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SELFDESTRUCT))
apeerobjs--;
- else if (ast_test_flag(&peer->flags[0], SIP_REALTIME)) {
+ else if (peer->is_realtime) {
rpeerobjs--;
ast_debug(3,"-REALTIME- peer Destroyed. Name: %s. Realtime Peer objects: %d\n", peer->name, rpeerobjs);
} else
@@ -2963,7 +2986,7 @@
{
int rtcachefriends = ast_test_flag(&p->flags[1], SIP_PAGE2_RTCACHEFRIENDS);
if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTUPDATE) &&
- (ast_test_flag(&p->flags[0], SIP_REALTIME) || rtcachefriends)) {
+ (p->is_realtime || rtcachefriends)) {
realtime_update_peer(p->name, &p->addr, p->username, rtcachefriends ? p->fullcontact : NULL, expiry);
}
}
@@ -3058,7 +3081,7 @@
}
ASTOBJ_CONTAINER_LINK(&peerl,peer);
} else {
- ast_set_flag(&peer->flags[0], SIP_REALTIME);
+ peer->is_realtime = 1;
}
ast_variables_destroy(var);
@@ -3102,7 +3125,7 @@
ast_variables_destroy(user->chanvars);
user->chanvars = NULL;
}
- if (ast_test_flag(&user->flags[0], SIP_REALTIME))
+ if (user->is_realtime)
ruserobjs--;
else
suserobjs--;
@@ -3146,7 +3169,7 @@
/* Move counter from s to r... */
suserobjs--;
ruserobjs++;
- ast_set_flag(&user->flags[0], SIP_REALTIME);
+ user->is_realtime = 1;
}
ast_variables_destroy(var);
return user;
@@ -8531,7 +8554,7 @@
/* Do we need to release this peer from memory?
Only for realtime peers and autocreated peers
*/
- if (ast_test_flag(&peer->flags[0], SIP_REALTIME))
+ if (peer->is_realtime)
ast_debug(3,"-REALTIME- peer expired registration. Name: %s. Realtime peer objects now %d\n", peer->name, rpeerobjs);
if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SELFDESTRUCT) ||
@@ -8791,7 +8814,7 @@
expiry = max_expiry;
if (expiry < min_expiry)
expiry = min_expiry;
- peer->expire = ast_test_flag(&peer->flags[0], SIP_REALTIME) ? -1 :
+ peer->expire = peer->is_realtime ? -1 :
ast_sched_add(sched, (expiry + 10) * 1000, expire_register, peer);
pvt->expiry = expiry;
snprintf(data, sizeof(data), "%s:%d:%d:%s:%s", ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port), expiry, peer->username, peer->fullcontact);
@@ -10710,7 +10733,7 @@
ast_test_flag(&iterator->flags[0], SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */
iterator->ha ? " A " : " ", /* permit/deny */
ntohs(iterator->addr.sin_port), status,
- realtimepeers ? (ast_test_flag(&iterator->flags[0], SIP_REALTIME) ? "Cached RT":"") : "");
+ realtimepeers ? (iterator->is_realtime ? "Cached RT":"") : "");
if (!s) {/* Normal CLI list */
ast_cli(fd, FORMAT, name,
@@ -10720,7 +10743,7 @@
iterator->ha ? " A " : " ", /* permit/deny */
ntohs(iterator->addr.sin_port), status,
- realtimepeers ? (ast_test_flag(&iterator->flags[0], SIP_REALTIME) ? "Cached RT":"") : "");
+ realtimepeers ? (iterator->is_realtime ? "Cached RT":"") : "");
} else { /* Manager format */
/* The names here need to be the same as other channels */
astman_append(s,
@@ -10749,7 +10772,7 @@
iterator->ha ? "yes" : "no", /* permit/deny */
status,
iterator->register_from_hdr,
- realtimepeers ? (ast_test_flag(&iterator->flags[0], SIP_REALTIME) ? "yes":"no") : "no");
+ realtimepeers ? (iterator->is_realtime ? "yes":"no") : "no");
}
ASTOBJ_UNLOCK(iterator);
@@ -11137,7 +11160,7 @@
ast_cli(fd,"\n\n");
ast_cli(fd, " * Name : %s\n", peer->name);
if (realtimepeers) { /* Realtime is enabled */
- ast_cli(fd, " Realtime peer: %s\n", ast_test_flag(&peer->flags[0], SIP_REALTIME) ? "Yes, cached" : "No");
+ ast_cli(fd, " Realtime peer: %s\n", peer->is_realtime ? "Yes, cached" : "No");
}
ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"<Not set>":"<Set>");
ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(peer->md5secret)?"<Not set>":"<Set>");
@@ -12206,7 +12229,7 @@
else
ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(debugaddr.sin_addr), port);
- ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
+ sipdebug |= sip_debug_console;
return CLI_SUCCESS;
}
@@ -12225,7 +12248,7 @@
debugaddr.sin_port = peer->addr.sin_port;
ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n",
ast_inet_ntoa(debugaddr.sin_addr), ntohs(debugaddr.sin_port));
- ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
+ sipdebug |= sip_debug_console;
}
if (peer)
unref_peer(peer);
@@ -12235,7 +12258,7 @@
/*! \brief Turn on SIP debugging (CLI command) */
static char *sip_do_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- int oldsipdebug = sipdebug_console;
+ int oldsipdebug = sipdebug & sip_debug_console;
char *what;
if (cmd == CLI_INIT) {
@@ -12255,14 +12278,14 @@
what = a->argv[e->args-1]; /* guaranteed to exist */
if (a->argc == e->args) { /* on/off */
if (!strcasecmp(what, "on")) {
- ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
- ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_TEXT); /*! \note this can be a special debug command - "sip debug text" or something */
+ sipdebug |= sip_debug_console;
+ sipdebug_text = 1; /*! \note this can be a special debug command - "sip debug text" or something */
memset(&debugaddr, 0, sizeof(debugaddr));
ast_cli(a->fd, "SIP Debugging %senabled\n", oldsipdebug ? "re-" : "");
return CLI_SUCCESS;
} else if (!strcasecmp(what, "off")) {
- ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
- ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_TEXT);
+ sipdebug &= ~sip_debug_console;
+ sipdebug_text = 0;
ast_cli(a->fd, "SIP Debugging Disabled\n");
return CLI_SUCCESS;
}
@@ -17559,7 +17582,7 @@
ast_copy_flags(&peer->flags[1], &peerflags[1], mask[1].flags);
if (ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))
global_allowsubscribe = TRUE; /* No global ban any more */
- if (!found && ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC) && !ast_test_flag(&peer->flags[0], SIP_REALTIME))
+ if (!found && ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC) && !peer->is_realtime)
reg_source_db(peer);
/* If they didn't request that MWI is sent *only* on subscribe, go ahead and
@@ -17607,7 +17630,6 @@
int auto_sip_domains = FALSE;
struct sockaddr_in old_bindaddr = bindaddr;
int registry_count = 0, peer_count = 0, user_count = 0;
- struct ast_flags debugflag = {0};
cfg = ast_config_load(config);
@@ -17623,10 +17645,9 @@
/* Clear all flags before setting default values */
/* Preserve debugging settings for console */
- ast_copy_flags(&debugflag, &global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
+ sipdebug &= sip_debug_console;
ast_clear_flag(&global_flags[0], AST_FLAGS_ALL);
ast_clear_flag(&global_flags[1], AST_FLAGS_ALL);
- ast_copy_flags(&global_flags[1], &debugflag, SIP_PAGE2_DEBUG_CONSOLE);
/* Reset IP addresses */
memset(&bindaddr, 0, sizeof(bindaddr));
@@ -17703,7 +17724,7 @@
/* Debugging settings, always default to off */
dumphistory = FALSE;
recordhistory = FALSE;
- ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONFIG);
+ sipdebug &= ~sip_debug_config;
/* Misc settings for the channel */
global_relaxdtmf = FALSE;
@@ -17799,7 +17820,10 @@
M_INT_GE("|maxexpirey|maxexpiry|", max_expiry, 1, DEFAULT_MAX_EXPIRY)
M_INT_GE("|minexpirey|minexpiry|", min_expiry, 1, DEFAULT_MIN_EXPIRY)
M_INT_GE("|defaultexpirey|defaultexpiry|", default_expiry, 1, DEFAULT_DEFAULT_EXPIRY)
- M_FLAG("sipdebug", global_flags[1], SIP_PAGE2_DEBUG_CONFIG)
+ M_F("sipdebug", {
+ if (ast_true(v->value))
+ sipdebug |= sip_debug_config;
+ } )
M_BOOL("dumphistory", dumphistory)
M_BOOL("recordhistory", recordhistory)
M_INT_GE("registertimeout", global_reg_timeout, 1, DEFAULT_REGISTRATION_TIMEOUT)
More information about the asterisk-commits
mailing list