[asterisk-commits] rizzo: branch rizzo/astobj2 r47949 -
/team/rizzo/astobj2/channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Nov 22 16:26:18 MST 2006
Author: rizzo
Date: Wed Nov 22 17:26:18 2006
New Revision: 47949
URL: http://svn.digium.com/view/asterisk?view=rev&rev=47949
Log:
add a function that lets the M_F() family of macros match
multiple keywords. So we can write
M_F("|expiry|expirey|", ... code for expiry ...)
without too much convoluted coding.
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=47949&r1=47948&r2=47949
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Wed Nov 22 17:26:18 2006
@@ -15832,8 +15832,23 @@
char *__s = var; char *__val = val;
#define M_END(x) x;
+/*!
+ * helper function to match keywords.
+ * A list has the keywords separated by '|' (also at begin and end),
+ * otherwise we match a single keyword.
+ */
+static int match_keyword(const char *pattern, const char *keyword)
+{
+ const char *pos;
+
+ if (pattern[0] != '|')
+ return !strcasecmp( pattern, keyword);
+ pos = strcasestr(pattern, keyword);
+ return (pos && pos > pattern && pos[-1] == '|' && pos[strlen(keyword)] == '|');
+}
+
/*! \brief generic block */
-#define M_F(tag, f) if (!strcasecmp((__s), tag)) { f; } else
+#define M_F(tag, f) if (match_keyword(tag, __s)) { f; } else
/* set a boolean */
#define M_BOOL(tag, dst) M_F(tag, (dst) = ast_true(__val) )
@@ -16209,8 +16224,7 @@
M_STR("context", user->context)
M_STR("subscribecontext", user->subscribecontext)
M_F("setvar", user->chanvars = add_var(v->value, user->chanvars))
- M_F("permit", user->ha = ast_append_ha(v->name, v->value, user->ha))
- M_F("deny", user->ha = ast_append_ha(v->name, v->value, user->ha))
+ M_F("|permit|deny|", user->ha = ast_append_ha(v->name, v->value, user->ha))
M_F("allowtransfer", user->allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED)
M_STR("secret", user->secret)
M_STR("md5secret", user->md5secret)
@@ -16220,9 +16234,7 @@
M_F("callgroup", user->callgroup = ast_get_group(v->value))
M_F("pickupgroup", user->pickupgroup = ast_get_group(v->value))
M_STR("language", user->language)
- M_STR("mohinterpret", user->mohinterpret)
- M_STR("musicclass", user->mohinterpret)
- M_STR("musiconhold", user->mohinterpret)
+ M_STR("|mohinterpret|musicclass|musiconhold|", user->mohinterpret)
M_STR("mohsuggest", user->mohsuggest)
M_STR("accountcode", user->accountcode)
M_INT_GE0("call-limit", user->call_limit, 0)
@@ -16400,7 +16412,7 @@
M_STR("fromdomain", peer->fromdomain)
M_F("usereqphone", ast_set2_flag(&peer->flags[0], ast_true(v->value), SIP_USEREQPHONE);)
M_STR("fromuser", peer->fromuser)
- if (!strcasecmp(v->name, "host") || !strcasecmp(v->name, "outboundproxy")) {
+ M_F("|host|outboundproxy|", {
if (!strcasecmp(v->value, "dynamic")) {
if (!strcasecmp(v->name, "outboundproxy") || obproxyfound) {
ast_log(LOG_WARNING, "You can't have a dynamic outbound proxy, you big silly head at line %d.\n", v->lineno);
@@ -16437,16 +16449,13 @@
if (!peer->addr.sin_port)
peer->addr.sin_port = htons(STANDARD_SIP_PORT);
}
- }
- } else
+ }} )
M_F("defaultip", {
if (ast_get_ip(&peer->defaddr, v->value)) {
unref_peer(peer);
return NULL; /* XXX why ? */
}} )
- if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
- peer->ha = ast_append_ha(v->name, v->value, peer->ha);
- } else
+ M_F("|permit|deny|", peer->ha = ast_append_ha(v->name, v->value, peer->ha) )
M_F("port", {
if (!realtime && ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC))
peer->defaddr.sin_port = htons(atoi(v->value));
@@ -16466,9 +16475,7 @@
peer->amaflags = format;
} } )
M_STR("accountcode", peer->accountcode)
- M_STR("mohinterpret", peer->mohinterpret)
- M_STR("musicclass", peer->mohinterpret)
- M_STR("musiconhold", peer->mohinterpret)
+ M_STR("|mohinterpret|musicclass|musiconhold", peer->mohinterpret)
M_STR("mohsuggest", peer->mohsuggest)
M_STR("mailbox", peer->mailbox)
M_F("subscribemwi", ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_SUBSCRIBEMWIONLY);)
@@ -16692,9 +16699,7 @@
M_BOOL("limitpeersonly", global_limitonpeers)
M_BOOL("notifyhold", global_notifyhold)
M_BOOL("alwaysauthreject", global_alwaysauthreject)
- M_STR("mohinterpret", default_mohinterpret)
- M_STR("musicclass", default_mohinterpret)
- M_STR("musiconhold", default_mohinterpret)
+ M_STR("|mohinterpret|musicclass|musiconhold", default_mohinterpret)
M_STR("mohsuggest", default_mohsuggest)
M_STR("language", default_language)
M_F("regcontext", {
@@ -16721,12 +16726,9 @@
M_BOOL("match_auth_username", global_match_auth_username)
M_BOOL("global_srvlookup", global_srvlookup)
M_BOOL("pedantic", pedanticsipchecking)
- M_INT_GE("maxexpirey", max_expiry, 1, DEFAULT_MAX_EXPIRY)
- M_INT_GE("maxexpiry", max_expiry, 1, DEFAULT_MAX_EXPIRY)
- M_INT_GE("minexpirey", min_expiry, 1, DEFAULT_MIN_EXPIRY)
- M_INT_GE("minexpiry", min_expiry, 1, DEFAULT_MIN_EXPIRY)
- M_INT_GE("defaultexpirey", default_expiry, 1, DEFAULT_DEFAULT_EXPIRY)
- M_INT_GE("defaultexpiry", default_expiry, 1, DEFAULT_DEFAULT_EXPIRY)
+ 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_BOOL("dumphistory", dumphistory)
M_BOOL("recordhistory", recordhistory)
More information about the asterisk-commits
mailing list