[asterisk-commits] branch russell/config-macros - r7283 in /team/russell/config-macros: ./ chann...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Dec 2 02:37:32 CST 2005


Author: russell
Date: Fri Dec  2 02:37:28 2005
New Revision: 7283

URL: http://svn.digium.com/view/asterisk?rev=7283&view=rev
Log:
parse the 'general' section of sip.conf using the config parsing macros.
Add new macros and change little things along the way as needed ...

Modified:
    team/russell/config-macros/acl.c
    team/russell/config-macros/channels/chan_iax2.c
    team/russell/config-macros/channels/chan_sip.c
    team/russell/config-macros/include/asterisk/acl.h
    team/russell/config-macros/include/asterisk/config.h

Modified: team/russell/config-macros/acl.c
URL: http://svn.digium.com/view/asterisk/team/russell/config-macros/acl.c?rev=7283&r1=7282&r2=7283&view=diff
==============================================================================
--- team/russell/config-macros/acl.c (original)
+++ team/russell/config-macros/acl.c Fri Dec  2 02:37:28 2005
@@ -141,7 +141,7 @@
 	return ret;    			/* Return start of list */
 }
 
-struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path)
+struct ast_ha *ast_append_ha(char *sense, const char *stuff, struct ast_ha *path)
 {
 	struct ast_ha *ha = malloc(sizeof(struct ast_ha));
 	char *nm = "255.255.255.255";
@@ -247,9 +247,10 @@
 	return 0;
 }
 
-int ast_str2tos(const char *value, int *tos)
+int ast_str2tos(const char *value, int *tos, int lineno, const char *file)
 {
 	int fval;
+
 	if (sscanf(value, "%i", &fval) == 1)
 		*tos = fval & 0xff;
 	else if (!strcasecmp(value, "lowdelay"))
@@ -262,8 +263,11 @@
 		*tos = IPTOS_MINCOST;
 	else if (!strcasecmp(value, "none"))
 		*tos = 0;
-	else
-		return -1;
+	else {
+		ast_log(LOG_WARNING, "Invalid tos value at line '%d' of '%s', should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", lineno, file);
+		return -1;
+	}
+	
 	return 0;
 }
 

Modified: team/russell/config-macros/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/config-macros/channels/chan_iax2.c?rev=7283&r1=7282&r2=7283&view=diff
==============================================================================
--- team/russell/config-macros/channels/chan_iax2.c (original)
+++ team/russell/config-macros/channels/chan_iax2.c Fri Dec  2 02:37:28 2005
@@ -8608,11 +8608,10 @@
 
 	/* Seed initial tos value */
 	tosval = ast_variable_retrieve(cfg, "general", "tos");
-	if (tosval) {
-		if (ast_str2tos(tosval, &tos))
-			ast_log(LOG_WARNING, "Invalid tos value, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n");
-	}
-	while(v) {
+	if (tosval)
+		ast_str2tos(tosval, &tos, 0, __FILE__);
+
+	while (v) {
 		if (!strcasecmp(v->name, "bindport")){ 
 			if (reload)
 				ast_log(LOG_NOTICE, "Ignoring bindport on reload\n");
@@ -8747,8 +8746,7 @@
 			if (!ast_context_find(regcontext))
 				ast_context_create(NULL, regcontext, channeltype);
 		} else if (!strcasecmp(v->name, "tos")) {
-			if (ast_str2tos(v->value, &tos))
-				ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
+			ast_str2tos(v->value, &tos, v->lineno, __FILE__);
 		} else if (!strcasecmp(v->name, "accountcode")) {
 			ast_copy_string(accountcode, v->value, sizeof(accountcode));
 		} else if (!strcasecmp(v->name, "amaflags")) {

Modified: team/russell/config-macros/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/russell/config-macros/channels/chan_sip.c?rev=7283&r1=7282&r2=7283&view=diff
==============================================================================
--- team/russell/config-macros/channels/chan_sip.c (original)
+++ team/russell/config-macros/channels/chan_sip.c Fri Dec  2 02:37:28 2005
@@ -541,6 +541,7 @@
 #define SIP_CAN_REINVITE	(1 << 20)	/*!< allow peers to be reinvited to send media directly p2p */
 #define SIP_REINVITE_UPDATE	(2 << 20)	/*!< use UPDATE (RFC3311) when reinviting this peer */
 /* "insecure" settings */
+#define SIP_INSECURE_PORTINVITE	(3 << 22)
 #define SIP_INSECURE_PORT	(1 << 22)	/*!< don't require matching port for incoming requests */
 #define SIP_INSECURE_INVITE	(1 << 23)	/*!< don't require authentication for incoming INVITEs */
 /* Sending PROGRESS in-band settings */
@@ -575,6 +576,62 @@
 /* SIP packet flags */
 #define SIP_PKT_DEBUG		(1 << 0)	/*!< Debug this packet */
 #define SIP_PKT_WITH_TOTAG	(1 << 1)	/*!< This packet has a to-tag */
+
+#ifdef OSP_SUPPORT
+#define OSP_ALLOWGUEST_OPTION AST_CONFIG_VAL_CUSTOM("osp", global_allowguest = 2)
+#define OSP_AUTH_OPTIONS \
+		AST_CONFIG_CHECK_VAL_BEGIN("ospauth") \
+			AST_CONFIG_VAL_FLAG_DIRECT("proxy", dst, SIP_OSPAUTH_PROXY) \
+			AST_CONFIG_VAL_FLAG_DIRECT("gateway", dst, SIP_OSPAUTH_GATEWAY) \
+			AST_CONFIG_VAL_FLAG_DIRECT("exclusive", dst, SIP_OSPAUTH_EXCLUSIVE) \
+		AST_CONFIG_CHECK_VAL_END
+#else
+#define OSP_ALLOWGUEST_OPTION
+#define OSP_AUTH_OPTIONS
+#endif
+
+#define SIP_COMMON_OPTIONS(dst) \
+	AST_CONFIG_FLAG("trustrpid", dst, SIP_TRUSTRPID) \
+	AST_CONFIG_FLAG("sendrpid", dst, SIP_SENDRPID) \
+	AST_CONFIG_FLAG("useclientcode", dst, SIP_USECLIENTCODE) \
+	AST_CONFIG_FLAG("promiscredir", dst, SIP_PROMISCREDIR) \
+	AST_CONFIG_CHECK_VAL_BEGIN("dtmfmode") \
+		AST_CONFIG_VAL_FLAG_DIRECT("inband", dst, SIP_DTMF_INBAND) \
+		AST_CONFIG_VAL_FLAG_DIRECT("rfc2833", dst, SIP_DTMF_RFC2833) \
+		AST_CONFIG_VAL_FLAG_DIRECT("info", dst, SIP_DTMF_INFO) \
+		AST_CONFIG_VAL_FLAG_DIRECT("auto", dst, SIP_DTMF_AUTO) \
+		AST_CONFIG_VAL_DEFAULT_FLAG(dst, SIP_DTMF_RFC2833, ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n", val)) \
+	AST_CONFIG_CHECK_VAL_END \
+	AST_CONFIG_CHECK_VAL_BEGIN("nat") \
+		AST_CONFIG_VAL_FLAG_DIRECT("never", dst, SIP_NAT_NEVER) \
+		AST_CONFIG_VAL_FLAG_DIRECT("route", dst, SIP_NAT_ROUTE) \
+		AST_CONFIG_VAL_FLAG_DIRECT("rfc3581", dst, SIP_NAT_RFC3581) \
+		AST_CONFIG_VAL_FLAG(dst, SIP_NAT_ALWAYS) \
+		AST_CONFIG_VAL_DEFAULT_FLAG(dst, SIP_NAT_RFC3581, ast_log(LOG_WARNING, "Unkown nat mode '%s', using rfc3581\n", val)) \
+	AST_CONFIG_CHECK_VAL_END \
+	AST_CONFIG_CHECK_VAL_BEGIN("canreinvite") \
+		AST_CONFIG_VAL_FLAG_DIRECT("update", dst, SIP_REINVITE_UPDATE | SIP_CAN_REINVITE) \
+		AST_CONFIG_VAL_FLAG(dst, SIP_CAN_REINVITE) \
+		AST_CONFIG_VAL_DEFAULT(ast_log(LOG_WARNING, "Unknown canreinvite setting '%s'\n", val)) \
+	AST_CONFIG_CHECK_VAL_END \
+	AST_CONFIG_CHECK_VAL_BEGIN("insecure") \
+		AST_CONFIG_VAL_FLAG_DIRECT("very", dst, SIP_INSECURE_PORTINVITE) \
+		AST_CONFIG_VAL_FLAG(dst, SIP_INSECURE_PORT) \
+		AST_CONFIG_VAL_FLAG_DIRECT("port", dst, SIP_INSECURE_PORT) \
+		AST_CONFIG_VAL_FLAG_DIRECT("invite", dst, SIP_INSECURE_INVITE) \
+		AST_CONFIG_VAL_FLAG_DIRECT("port,invite", dst, SIP_INSECURE_PORTINVITE) \
+		AST_CONFIG_VAL_FLAG_DIRECT("invite,port", dst, SIP_INSECURE_PORTINVITE) \
+		AST_CONFIG_VAL_DEFAULT(ast_log(LOG_WARNING, "Unknown insecure mode '%s'\n", val)) \
+	AST_CONFIG_CHECK_VAL_END \
+	AST_CONFIG_CHECK_VAL_BEGIN("progressinband") \
+		AST_CONFIG_VAL_FLAG(dst, SIP_PROG_INBAND_YES) \
+		AST_CONFIG_VAL_FLAG_DIRECT("never", dst, SIP_PROG_INBAND_NO) \
+	AST_CONFIG_CHECK_VAL_END \
+	AST_CONFIG_CHECK_VAL_BEGIN("allowguest") \
+		OSP_ALLOWGUEST_OPTION \
+		AST_CONFIG_VAL_DEFAULT(global_allowguest = ast_true(val)) \
+	AST_CONFIG_CHECK_VAL_END \
+	OSP_AUTH_OPTIONS
 
 static int global_rtautoclear = 120;
 
@@ -3179,7 +3236,7 @@
 }
 
 /*! \brief  sip_register: Parse register=> line in sip.conf and add to registry */
-static int sip_register(char *value, int lineno)
+static int sip_register(const char *value, int lineno)
 {
 	struct sip_registry *reg;
 	char copy[256];
@@ -12217,6 +12274,127 @@
 	return peer;
 }
 
+void parse_rtautoclear(const char *val)
+{
+	int i;
+
+	i = atoi(val);
+
+	if (i > 0)
+		global_rtautoclear = i;
+	else 
+		i = 0;
+
+	ast_set2_flag((&global_flags_page2), i || ast_true(val), SIP_PAGE2_RTAUTOCLEAR);
+}
+
+void parse_regcontext(const char *val)
+{
+	ast_copy_string(regcontext, val, sizeof(regcontext));
+
+	/* Create context if it doesn't exist already */
+	if (!ast_context_find(regcontext))
+		ast_context_create(NULL, regcontext, channeltype);
+}
+
+void parse_outboundproxy(const char *val)
+{
+	if (ast_get_ip_or_srv(&outboundproxyip, val, "_sip._udp") < 0)
+		ast_log(LOG_WARNING, "Unable to locate host '%s'\n", val);
+}
+
+void parse_outboundproxyport(const char *val)
+{
+	int port;
+
+	/* Port needs to be after IP */
+	
+	if (sscanf(val, "%d", &port) != 1)
+		port = 5060;
+
+	outboundproxyip.sin_port = htons(port);
+}
+
+void parse_bindaddr(const char *val)
+{
+	struct hostent *hp;
+	struct ast_hostent ahp;
+
+	if (!(hp = ast_gethostbyname(val, &ahp))) {
+		ast_log(LOG_WARNING, "Invalid address: %s\n", val);
+	} else {
+		memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
+	}
+}
+
+void parse_localnet(const char *val)
+{
+	struct ast_ha *na;
+
+	if (!(na = ast_append_ha("d", val, localaddr)))
+		ast_log(LOG_WARNING, "Invalid localnet value: %s\n", val);
+	else
+		localaddr = na;
+}
+
+void parse_externip(const char *val)
+{
+	struct hostent *hp;
+	struct ast_hostent ahp;
+
+	if (!(hp = ast_gethostbyname(val, &ahp))) 
+		ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", val);
+	else
+		memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
+
+	externexpire = 0;
+}
+
+void parse_externhost(const char *val)
+{
+	struct hostent *hp;
+	struct ast_hostent ahp;
+
+	ast_copy_string(externhost, val, sizeof(externhost));
+	
+	if (!(hp = ast_gethostbyname(externhost, &ahp))) 
+		ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost);
+	else
+		memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
+	
+	time(&externexpire);
+}
+
+void parse_domain(const char *val, int lineno)
+{
+	char *domain = ast_strdupa(val);
+	char *context = strchr(domain, ',');
+
+	context = ast_strdupa(val);
+	if (!context) {
+		ast_log(LOG_ERROR, "Out of Memory!\n");
+		return;
+	}
+
+	domain = strsep(&context, ",");
+
+	if (ast_strlen_zero(domain))
+		ast_log(LOG_WARNING, "Empty domain specified at line %d\n", lineno);
+	else if (ast_strlen_zero(context))
+		ast_log(LOG_WARNING, "Empty context specified at line %d for domain '%s'\n", lineno, domain);
+	else
+		add_sip_domain(ast_strip(domain), SIP_DOMAIN_CONFIG, ast_strip(context));
+}
+
+void parse_bindport(const char *val, int lineno)
+{
+	if (sscanf(val, "%d", &ourport) == 1) {
+		bindaddr.sin_port = htons(ourport);
+	} else {
+		ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", val, lineno, config);
+	}
+}
+
 /*! \brief  reload_config: Re-read SIP.conf config file ---*/
 /*	This function reloads all config data, except for
 	active peers (with registrations). They will only
@@ -12229,13 +12407,9 @@
 	struct ast_variable *v;
 	struct sip_peer *peer;
 	struct sip_user *user;
-	struct ast_hostent ahp;
 	char *cat;
 	char *utype;
-	struct hostent *hp;
-	int format;
 	char iabuf[INET_ADDRSTRLEN];
-	struct ast_flags dummy;
 	int auto_sip_domains = 0;
 	struct sockaddr_in old_bindaddr = bindaddr;
 
@@ -12300,198 +12474,68 @@
 	expiry = DEFAULT_EXPIRY;
 	global_allowguest = 1;
 
-	/* Read the [general] config section of sip.conf (or from realtime config) */
-	v = ast_variable_browse(cfg, "general");
-	while(v) {
-		if (handle_common_options(&global_flags, &dummy, v)) {
-			v = v->next;
-			continue;
-		}
-
-		/* Create the interface list */
-		if (!strcasecmp(v->name, "context")) {
-			ast_copy_string(default_context, v->value, sizeof(default_context));
-		} else if (!strcasecmp(v->name, "realm")) {
-			ast_copy_string(global_realm, v->value, sizeof(global_realm));
-		} else if (!strcasecmp(v->name, "useragent")) {
-			ast_copy_string(default_useragent, v->value, sizeof(default_useragent));
-			ast_log(LOG_DEBUG, "Setting User Agent Name to %s\n",
-				default_useragent);
-		} else if (!strcasecmp(v->name, "rtcachefriends")) {
-			ast_set2_flag((&global_flags_page2), ast_true(v->value), SIP_PAGE2_RTCACHEFRIENDS);	
-		} else if (!strcasecmp(v->name, "rtupdate")) {
-			ast_set2_flag((&global_flags_page2), ast_true(v->value), SIP_PAGE2_RTUPDATE);	
-		} else if (!strcasecmp(v->name, "ignoreregexpire")) {
-			ast_set2_flag((&global_flags_page2), ast_true(v->value), SIP_PAGE2_IGNOREREGEXPIRE);	
-		} else if (!strcasecmp(v->name, "rtautoclear")) {
-			int i = atoi(v->value);
-			if (i > 0)
-				global_rtautoclear = i;
-			else
-				i = 0;
-			ast_set2_flag((&global_flags_page2), i || ast_true(v->value), SIP_PAGE2_RTAUTOCLEAR);
-		} else if (!strcasecmp(v->name, "usereqphone")) {
-			ast_set2_flag((&global_flags), ast_true(v->value), SIP_USEREQPHONE);	
-		} else if (!strcasecmp(v->name, "relaxdtmf")) {
-			relaxdtmf = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "checkmwi")) {
-			if ((sscanf(v->value, "%d", &global_mwitime) != 1) || (global_mwitime < 0)) {
-				ast_log(LOG_WARNING, "'%s' is not a valid MWI time setting at line %d.  Using default (10).\n", v->value, v->lineno);
-				global_mwitime = DEFAULT_MWITIME;
-			}
-		} else if (!strcasecmp(v->name, "vmexten")) {
-			ast_copy_string(global_vmexten, v->value, sizeof(global_vmexten));
-		} else if (!strcasecmp(v->name, "rtptimeout")) {
-			if ((sscanf(v->value, "%d", &global_rtptimeout) != 1) || (global_rtptimeout < 0)) {
-				ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d.  Using default.\n", v->value, v->lineno);
-				global_rtptimeout = 0;
-			}
-		} else if (!strcasecmp(v->name, "rtpholdtimeout")) {
-			if ((sscanf(v->value, "%d", &global_rtpholdtimeout) != 1) || (global_rtpholdtimeout < 0)) {
-				ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d.  Using default.\n", v->value, v->lineno);
-				global_rtpholdtimeout = 0;
-			}
-		} else if (!strcasecmp(v->name, "rtpkeepalive")) {
-			if ((sscanf(v->value, "%d", &global_rtpkeepalive) != 1) || (global_rtpkeepalive < 0)) {
-				ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d.  Using default.\n", v->value, v->lineno);
-				global_rtpkeepalive = 0;
-			}
-		} else if (!strcasecmp(v->name, "videosupport")) {
-			videosupport = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "compactheaders")) {
-			compactheaders = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "notifymimetype")) {
-			ast_copy_string(default_notifymime, v->value, sizeof(default_notifymime));
-		} else if (!strcasecmp(v->name, "notifyringing")) {
-			global_notifyringing = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) {
-			ast_copy_string(global_musicclass, v->value, sizeof(global_musicclass));
-		} else if (!strcasecmp(v->name, "language")) {
-			ast_copy_string(default_language, v->value, sizeof(default_language));
-		} else if (!strcasecmp(v->name, "regcontext")) {
-			ast_copy_string(regcontext, v->value, sizeof(regcontext));
-			/* Create context if it doesn't exist already */
-			if (!ast_context_find(regcontext))
-				ast_context_create(NULL, regcontext, channeltype);
-		} else if (!strcasecmp(v->name, "callerid")) {
-			ast_copy_string(default_callerid, v->value, sizeof(default_callerid));
-		} else if (!strcasecmp(v->name, "fromdomain")) {
-			ast_copy_string(default_fromdomain, v->value, sizeof(default_fromdomain));
-		} else if (!strcasecmp(v->name, "outboundproxy")) {
-			if (ast_get_ip_or_srv(&outboundproxyip, v->value, "_sip._udp") < 0)
-				ast_log(LOG_WARNING, "Unable to locate host '%s'\n", v->value);
-		} else if (!strcasecmp(v->name, "outboundproxyport")) {
-			/* Port needs to be after IP */
-			sscanf(v->value, "%d", &format);
-			outboundproxyip.sin_port = htons(format);
-		} else if (!strcasecmp(v->name, "autocreatepeer")) {
-			autocreatepeer = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "srvlookup")) {
-			srvlookup = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "pedantic")) {
-			pedanticsipchecking = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "maxexpirey") || !strcasecmp(v->name, "maxexpiry")) {
-			max_expiry = atoi(v->value);
-			if (max_expiry < 1)
-				max_expiry = DEFAULT_MAX_EXPIRY;
-		} else if (!strcasecmp(v->name, "defaultexpiry") || !strcasecmp(v->name, "defaultexpirey")) {
-			default_expiry = atoi(v->value);
-			if (default_expiry < 1)
-				default_expiry = DEFAULT_DEFAULT_EXPIRY;
-		} else if (!strcasecmp(v->name, "sipdebug")) {
-			if (ast_true(v->value))
-				sipdebug |= SIP_DEBUG_CONFIG;
-		} else if (!strcasecmp(v->name, "dumphistory")) {
-			dumphistory = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "recordhistory")) {
-			recordhistory = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "registertimeout")) {
-			global_reg_timeout = atoi(v->value);
-			if (global_reg_timeout < 1)
-				global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT;
-		} else if (!strcasecmp(v->name, "registerattempts")) {
-			global_regattempts_max = atoi(v->value);
-		} else if (!strcasecmp(v->name, "bindaddr")) {
-			if (!(hp = ast_gethostbyname(v->value, &ahp))) {
-				ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
-			} else {
-				memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
-			}
-		} else if (!strcasecmp(v->name, "localnet")) {
-			struct ast_ha *na;
-			if (!(na = ast_append_ha("d", v->value, localaddr)))
-				ast_log(LOG_WARNING, "Invalid localnet value: %s\n", v->value);
-			else
-				localaddr = na;
-		} else if (!strcasecmp(v->name, "localmask")) {
-			ast_log(LOG_WARNING, "Use of localmask is no long supported -- use localnet with mask syntax\n");
-		} else if (!strcasecmp(v->name, "externip")) {
-			if (!(hp = ast_gethostbyname(v->value, &ahp))) 
-				ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", v->value);
-			else
-				memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
-			externexpire = 0;
-		} else if (!strcasecmp(v->name, "externhost")) {
-			ast_copy_string(externhost, v->value, sizeof(externhost));
-			if (!(hp = ast_gethostbyname(externhost, &ahp))) 
-				ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost);
-			else
-				memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
-			time(&externexpire);
-		} else if (!strcasecmp(v->name, "externrefresh")) {
-			if (sscanf(v->value, "%d", &externrefresh) != 1) {
-				ast_log(LOG_WARNING, "Invalid externrefresh value '%s', must be an integer >0 at line %d\n", v->value, v->lineno);
-				externrefresh = 10;
-			}
-		} else if (!strcasecmp(v->name, "allow")) {
-			ast_parse_allow_disallow(&prefs, &global_capability, v->value, 1);
-		} else if (!strcasecmp(v->name, "disallow")) {
-			ast_parse_allow_disallow(&prefs, &global_capability, v->value, 0);
-		} else if (!strcasecmp(v->name, "allowexternaldomains")) {
-			allow_external_domains = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "autodomain")) {
-			auto_sip_domains = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "domain")) {
-			char *domain = ast_strdupa(v->value);
-			char *context = strchr(domain, ',');
-
-			if (context)
-				*context++ = '\0';
-
-			if (ast_strlen_zero(domain))
-				ast_log(LOG_WARNING, "Empty domain specified at line %d\n", v->lineno);
-			else if (ast_strlen_zero(context))
-				ast_log(LOG_WARNING, "Empty context specified at line %d for domain '%s'\n", v->lineno, domain);
-			else
-				add_sip_domain(ast_strip(domain), SIP_DOMAIN_CONFIG, context ? ast_strip(context) : "");
-		} else if (!strcasecmp(v->name, "register")) {
-			sip_register(v->value, v->lineno);
-		} else if (!strcasecmp(v->name, "tos")) {
-			if (ast_str2tos(v->value, &tos))
-				ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
-		} else if (!strcasecmp(v->name, "bindport")) {
-			if (sscanf(v->value, "%d", &ourport) == 1) {
-				bindaddr.sin_port = htons(ourport);
-			} else {
-				ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config);
-			}
-		} else if (!strcasecmp(v->name, "qualify")) {
-			if (!strcasecmp(v->value, "no")) {
-				default_qualify = 0;
-			} else if (!strcasecmp(v->value, "yes")) {
-				default_qualify = DEFAULT_MAXMS;
-			} else if (sscanf(v->value, "%d", &default_qualify) != 1) {
-				ast_log(LOG_WARNING, "Qualification default should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", v->lineno);
-				default_qualify = 0;
-			}
-		} else if (!strcasecmp(v->name, "callevents")) {
-			callevents = ast_true(v->value);
-		}
-		/* else if (strcasecmp(v->name,"type"))
-		 *	ast_log(LOG_WARNING, "Ignoring %s\n", v->name);
-		 */
-		 v = v->next;
-	}
+	AST_CONFIG_PARSE_BEGIN(cfg, "general")
+		SIP_COMMON_OPTIONS(&global_flags)
+		AST_CONFIG_STR("context", default_context)
+		AST_CONFIG_STR("realm", global_realm)
+		AST_CONFIG_STR("useragent", default_useragent)
+		AST_CONFIG_FLAG("rtcachefriends", &global_flags_page2, SIP_PAGE2_RTCACHEFRIENDS)
+		AST_CONFIG_FLAG("rtupdate", &global_flags_page2, SIP_PAGE2_RTUPDATE)
+		AST_CONFIG_FLAG("ignoregexpire", &global_flags_page2, SIP_PAGE2_IGNOREREGEXPIRE)
+		AST_CONFIG_CUSTOM("rtautoclear", parse_rtautoclear(val))
+		AST_CONFIG_FLAG("usereqphone", &global_flags, SIP_USEREQPHONE)
+		AST_CONFIG_BOOL("relaxdtmf", relaxdtmf)
+		AST_CONFIG_UINT("checkmwi", global_mwitime)
+		AST_CONFIG_STR("vmexten", global_vmexten)
+		AST_CONFIG_UINT("rtptimeout", global_rtptimeout)	
+		AST_CONFIG_UINT("rtpholdtimeout", global_rtpholdtimeout)	
+		AST_CONFIG_UINT("rtpkeepalive", global_rtpkeepalive)	
+		AST_CONFIG_BOOL("videosupport", videosupport)
+		AST_CONFIG_BOOL("compactheaders", compactheaders)
+		AST_CONFIG_STR("notifymimetype", default_notifymime)
+		AST_CONFIG_BOOL("notifyringing", global_notifyringing)
+		AST_CONFIG_STR("musicclass", global_musicclass)
+		AST_CONFIG_STR("musiconhold", global_musicclass)
+		AST_CONFIG_STR("language", default_language)
+		AST_CONFIG_CUSTOM("regcontext", parse_regcontext(val))
+		AST_CONFIG_STR("callerid", default_callerid)
+		AST_CONFIG_STR("fromdomain", default_fromdomain)
+		AST_CONFIG_CUSTOM("outboundproxy", parse_outboundproxy(val))
+		AST_CONFIG_CUSTOM("outboundproxyport", parse_outboundproxyport(val))
+		AST_CONFIG_BOOL("autocreatepeer", autocreatepeer)
+		AST_CONFIG_BOOL("srvlookup", srvlookup)
+		AST_CONFIG_BOOL("pedantic", pedanticsipchecking)
+		AST_CONFIG_UINT("maxexpirey", max_expiry)
+		AST_CONFIG_UINT("maxexpiry", max_expiry)
+		AST_CONFIG_UINT("defaultexpirey", default_expiry)
+		AST_CONFIG_UINT("defaultexpiry", default_expiry)
+		AST_CONFIG_CUSTOM("sipdebug", if (ast_true(val)) sipdebug |= SIP_DEBUG_CONFIG)
+		AST_CONFIG_BOOL("dumphistory", dumphistory)
+		AST_CONFIG_BOOL("recordhistory", recordhistory)
+		/* XXX a lot of these UINT opts want something > 1, and a default val otherwise ... XXX */
+		AST_CONFIG_UINT("registertimeout", global_reg_timeout)
+		AST_CONFIG_BOOL("registerattempts", global_regattempts_max)
+		AST_CONFIG_CUSTOM("bindaddr", parse_bindaddr(val))
+		AST_CONFIG_CUSTOM("localnet", parse_localnet(val))
+		AST_CONFIG_CUSTOM("localmask", ast_log(LOG_WARNING, "Use of localmask is no long supported -- use localnet with mask syntax\n"))
+		AST_CONFIG_CUSTOM("externip", parse_externip(val))
+		AST_CONFIG_CUSTOM("externhost", parse_externhost(val))
+		AST_CONFIG_UINT("externrefresh", externrefresh)
+		AST_CONFIG_CUSTOM("allow", ast_parse_allow_disallow(&prefs, &global_capability, val, 1))
+		AST_CONFIG_CUSTOM("disallow", ast_parse_allow_disallow(&prefs, &global_capability, val, 0))
+		AST_CONFIG_BOOL("allowexternaldomains", allow_external_domains)
+		AST_CONFIG_BOOL("autodomain", auto_sip_domains)
+		AST_CONFIG_CUSTOM("domain", parse_domain(val, lineno))
+		AST_CONFIG_CUSTOM("register", sip_register(val, lineno))
+		AST_CONFIG_CUSTOM("tos", ast_str2tos(val, &tos, lineno, __FILE__))
+		AST_CONFIG_CUSTOM("bindport", parse_bindport(val, lineno))
+		AST_CONFIG_CHECK_VAL_BEGIN("qualify")
+			AST_CONFIG_VAL_CUSTOM("no", default_qualify = 0)
+			AST_CONFIG_VAL_CUSTOM("yes", default_qualify = DEFAULT_MAXMS)
+			AST_CONFIG_VAL_UINT(default_qualify)
+		AST_CONFIG_CHECK_VAL_END
+		AST_CONFIG_BOOL("callevents", callevents)
+	AST_CONFIG_PARSE_END
 
 	if (!allow_external_domains && AST_LIST_EMPTY(&domain_list)) {
 		ast_log(LOG_WARNING, "To disallow external domains, you need to configure local SIP domains.\n");
@@ -12500,17 +12544,16 @@
 	
 	/* Build list of authentication to various SIP realms, i.e. service providers */
  	v = ast_variable_browse(cfg, "authentication");
- 	while(v) {
+	for (; v; v = v->next) {
  		/* Format for authentication is auth = username:password at realm */
  		if (!strcasecmp(v->name, "auth")) {
  			authl = add_realm_authentication(authl, v->value, v->lineno);
  		}
- 		v = v->next;
  	}
 	
 	/* Load peers, users and friends */
 	cat = ast_category_browse(cfg, NULL);
-	while(cat) {
+	while (cat) {
 		if (strcasecmp(cat, "general") && strcasecmp(cat, "authentication")) {
 			utype = ast_variable_retrieve(cfg, cat, "type");
 			if (utype) {

Modified: team/russell/config-macros/include/asterisk/acl.h
URL: http://svn.digium.com/view/asterisk/team/russell/config-macros/include/asterisk/acl.h?rev=7283&r1=7282&r2=7283&view=diff
==============================================================================
--- team/russell/config-macros/include/asterisk/acl.h (original)
+++ team/russell/config-macros/include/asterisk/acl.h Fri Dec  2 02:37:28 2005
@@ -39,7 +39,7 @@
 struct ast_ha;
 
 extern void ast_free_ha(struct ast_ha *ha);
-extern struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path);
+extern struct ast_ha *ast_append_ha(char *sense, const char *stuff, struct ast_ha *path);
 extern int ast_apply_ha(struct ast_ha *ha, struct sockaddr_in *sin);
 extern int ast_get_ip(struct sockaddr_in *sin, const char *value);
 extern int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *service);
@@ -47,7 +47,7 @@
 extern int ast_lookup_iface(char *iface, struct in_addr *address);
 extern struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original);
 extern int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr);
-extern int ast_str2tos(const char *value, int *tos);
+extern int ast_str2tos(const char *value, int *tos, int lineno, const char *file);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/russell/config-macros/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/team/russell/config-macros/include/asterisk/config.h?rev=7283&r1=7282&r2=7283&view=diff
==============================================================================
--- team/russell/config-macros/include/asterisk/config.h (original)
+++ team/russell/config-macros/include/asterisk/config.h Fri Dec  2 02:37:28 2005
@@ -219,27 +219,6 @@
 */
 
 /*!
-  \brief If 'tag' matches the current option, execute the function 'f'.
-*/
-#define AST_CONFIG_CUSTOM(tag, f)	if (!strcasecmp((__v->name), tag)) { f; } else
-
-/*!
-  \brief If 'tag' matches the current option, set 'dst' to the result of ast_true() 
-*/
-#define AST_CONFIG_BOOL(tag, dst)	AST_CONFIG_CUSTOM(tag, (dst) = ast_true(val) )
-
-/*!
-  \brief If 'tag' matches the current option, interpret the value as an unsigned
-         integer and store it in 'dst'.
-*/
-#define AST_CONFIG_UINT(tag, dst)	AST_CONFIG_CUSTOM(tag, (dst) = strtoul(val, NULL, 0) )
-
-/*!
-  \brief If 'tag' matches the current option, copy the value directly to 'dst'.
-*/
-#define AST_CONFIG_STR(tag, dst)	AST_CONFIG_CUSTOM(tag, ast_copy_string(dst, val, sizeof(dst)))
-
-/*!
   \brief Begin parsing options from the given context in the configuration file
          that has already been loaded.
 
@@ -247,12 +226,14 @@
   the option needs to be directly accessed, it can be done with the variable,
   'val'.
 */
-#define AST_CONFIG_PARSE_BEGIN(cfg,context) \
+#define AST_CONFIG_PARSE_BEGIN(cfg, context) \
 	do { \
 		struct ast_variable *__v; \
+		int lineno; \
 		const char *val; \
 		for (__v = ast_variable_browse(cfg, context); __v; __v = __v->next) { \
-			val = __v->value;
+			val = __v->value; \
+			lineno = __v->lineno;
 
 /*!
   \brief End Config parsing.
@@ -260,6 +241,53 @@
   This is used after a call to AST_CONFIG_PARSE_BEGIN.
 */
 #define AST_CONFIG_PARSE_END ; } } while (0);
+
+#define AST_CONFIG_CHECK(name, tag, f)	if (!strcasecmp(name, tag)) { f; } else
+
+/*!
+  \brief If 'tag' matches the current option, execute the function 'f'.
+*/
+#define AST_CONFIG_CUSTOM(tag, f)	AST_CONFIG_CHECK(__v->name, tag, f)
+
+/*!
+  \brief If 'tag' matches the current option, set 'dst' to the result of ast_true() 
+*/
+#define AST_CONFIG_BOOL(tag, dst)	AST_CONFIG_CUSTOM(tag, (dst) = ast_true(val))
+
+/*!
+  \brief If 'tag' matches the current option, set the 'flag' in the 'flags'
+  member of the structure pointed to by 'dst'.
+*/
+#define AST_CONFIG_FLAG(tag, dst, flag)	AST_CONFIG_CUSTOM(tag, ast_set2_flag(dst, ast_true(val), flag))
+
+/*!
+  \brief If 'tag' matches the current option, interpret the value as an unsigned
+         integer and store it in 'dst'.
+*/
+#define AST_CONFIG_UINT(tag, dst)	AST_CONFIG_CUSTOM(tag, (dst) = strtoul(val, NULL, 0))
+
+/*!
+  \brief If 'tag' matches the current option, copy the value directly to 'dst'.
+*/
+#define AST_CONFIG_STR(tag, dst)	AST_CONFIG_CUSTOM(tag, ast_copy_string(dst, val, sizeof(dst)))
+
+#define AST_CONFIG_CHECK_VAL_BEGIN(tag)	if (!strcasecmp(__v->name, tag)) {
+
+#define AST_CONFIG_CHECK_VAL_END 	; } else
+
+#define AST_CONFIG_VAL_FLAG_DIRECT(tag, dst, flag) \
+		AST_CONFIG_CHECK(val, tag, ast_set_flag(dst, flag))
+
+#define AST_CONFIG_VAL_FLAG(dst, flag)	if (ast_true(val)) { ast_set_flag(dst, flag); } else	
+
+#define AST_CONFIG_VAL_UINT(dst)	(dst) = strtoul(val, NULL, 0)
+
+#define AST_CONFIG_VAL_DEFAULT(f)	f
+
+#define AST_CONFIG_VAL_CUSTOM(tag, f)	AST_CONFIG_CHECK(val, tag, f)
+
+#define AST_CONFIG_VAL_DEFAULT_FLAG(dst, flag, f) \
+		f; ast_set_flag(dst, flag)
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }



More information about the asterisk-commits mailing list