[svn-commits] rizzo: branch rizzo/astobj2 r48541 - /team/rizzo/astobj2/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Dec 17 04:13:20 MST 2006


Author: rizzo
Date: Sun Dec 17 05:13:20 2006
New Revision: 48541

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48541
Log:
fix for http://bugs.digium.com/view.php?id=8601 :

+ handle_common_options() did not return true in all
  cases it should;
+ handle_common_options() accepted some [general] options
  even within a user/peer context;
 
(the actual code in trunk/1.4 may be marginally different
but this gives the idea of what to change).

In detail (all of these are trunk candidates)

+ make sure handle_common_options returns 0 if an option is
  not found, 1 otherwise;

+ moved the handling of "allowguest" to reload_config() as this
  is not significant in a user/peer section;

+ recognise the "type" option in build_user/build_peer so we can
  avoid comparing it to all supported options.

+ remove duplicate handlers for "t38pt_udptl", "t38pt_rtp", "t38pt_tcp"
  which are already in handle_common_options();

+ add an XXX comment to mark that "allowsubscribe" in a user/peer
  section also sets global_allowsubscribe. Not sure this is intentional.
  If it is, perhaps the option should be moved outside the individual
  section.

+ print LOG_NOTICE messages in case of unrecognised options.
  Even if you may not (yet) want to merge this in 1.4,
  with so many options around, this is fundamental to help detect
  the validity of configurations.

  At the moment this incorrectly flags some non-user options in
  a type=friend section. This will be improved at a later time.



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=48541&r1=48540&r2=48541
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sun Dec 17 05:13:20 2006
@@ -642,10 +642,9 @@
  * It makes sense to use a different data structure than the one for incoming
  * packets as the internal format is not the same (e.g. no '\0' between
  * the various lines).
- * XXX fields starting with _ are unused
  */
 struct sip_msg_out {
-	int len;                /*!< Length */
+	int len;                /*!< Length (also, offset for writing) */
 	int headers;            /*!< # of SIP Headers */
 	int method;             /*!< Method of this request */
 	int lines;              /*!< Body Content */
@@ -16057,24 +16056,18 @@
 */
 static int handle_common_options(struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v)
 {
-	int res = 0;
-
 	if (!strcasecmp(v->name, "trustrpid")) {
 		ast_set_flag(&mask[0], SIP_TRUSTRPID);
 		ast_set2_flag(&flags[0], ast_true(v->value), SIP_TRUSTRPID);
-		res = 1;
 	} else if (!strcasecmp(v->name, "sendrpid")) {
 		ast_set_flag(&mask[0], SIP_SENDRPID);
 		ast_set2_flag(&flags[0], ast_true(v->value), SIP_SENDRPID);
-		res = 1;
 	} else if (!strcasecmp(v->name, "g726nonstandard")) {
 		ast_set_flag(&mask[0], SIP_G726_NONSTANDARD);
 		ast_set2_flag(&flags[0], ast_true(v->value), SIP_G726_NONSTANDARD);
-		res = 1;
 	} else if (!strcasecmp(v->name, "useclientcode")) {
 		ast_set_flag(&mask[0], SIP_USECLIENTCODE);
 		ast_set2_flag(&flags[0], ast_true(v->value), SIP_USECLIENTCODE);
-		res = 1;
 	} else if (!strcasecmp(v->name, "dtmfmode")) {
 		ast_set_flag(&mask[0], SIP_DTMF);
 		ast_clear_flag(&flags[0], SIP_DTMF);
@@ -16147,12 +16140,9 @@
 			ast_set_flag(&flags[0], SIP_PROG_INBAND_YES);
 		else if (strcasecmp(v->value, "never"))
 			ast_set_flag(&flags[0], SIP_PROG_INBAND_NO);
-  	} else if (!strcasecmp(v->name, "allowguest")) {
-		global_allowguest = ast_true(v->value) ? 1 : 0;
 	} else if (!strcasecmp(v->name, "promiscredir")) {
 		ast_set_flag(&mask[0], SIP_PROMISCREDIR);
 		ast_set2_flag(&flags[0], ast_true(v->value), SIP_PROMISCREDIR);
-		res = 1;
 	} else if (!strcasecmp(v->name, "videosupport")) {
 		ast_set_flag(&mask[1], SIP_PAGE2_VIDEOSUPPORT);
 		ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_VIDEOSUPPORT);
@@ -16176,9 +16166,10 @@
 	} else if (!strcasecmp(v->name, "rfc2833compensate")) {
 		ast_set_flag(&mask[1], SIP_PAGE2_RFC2833_COMPENSATE);
 		ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_RFC2833_COMPENSATE);
-	}
-
-	return res;
+	} else
+		return 0;	/* not found */
+
+	return 1;
 }
 
 /*! \brief Add SIP domain to list of domains we are responsible for */
@@ -16385,6 +16376,7 @@
 		if (handle_common_options(&userflags[0], &mask[0], v))
 			continue;
 
+		M_F("type", ; )	/* just ignore the 'type' option */
 		M_STR("context", user->context)
 		M_STR("subscribecontext", user->subscribecontext)
 		M_F("setvar", user->chanvars = add_var(v->value, user->chanvars))
@@ -16414,15 +16406,12 @@
 		M_BOOL("autoframing", user->autoframing)
 		M_MAPSTR("callingpres", user->callingpres, ast_parse_caller_presentation)
 		M_INT_GE0("maxcallbitrate", user->maxcallbitrate, default_maxcallbitrate)
- 		M_F("t38pt_udptl", ast_set2_flag(&user->flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_UDPTL))
-#ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS
-		M_F("t38pt_rtp", ast_set2_flag(&user->flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_RTP))
-		M_F("t38pt_tcp", ast_set2_flag(&user->flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_TCP))
-#endif
-		M_END(/* */)
+		M_END(ast_log(LOG_NOTICE, "sip.conf user [%s]: unknown option %s = %s\n",
+			name, v->name, v->value); )
 	}
 	ast_copy_flags(&user->flags[0], &userflags[0], mask[0].flags);
 	ast_copy_flags(&user->flags[1], &userflags[1], mask[1].flags);
+	/* XXX watch out, an individual config option with global effect ? */
 	if (ast_test_flag(&user->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))
 		global_allowsubscribe = TRUE;	/* No global ban any more */
 	ast_free_ha(oldha);
@@ -16564,7 +16553,9 @@
 				ast_copy_string(peer->fullcontact, v->value, sizeof(peer->fullcontact));
 				ast_set_flag(&peer->flags[1], SIP_PAGE2_RT_FROMCONTACT); } )
 			M_END(;)
-		} else
+			continue;
+		}
+		M_F("type", ; )	/* just ignore the 'type' option */
 		M_STR("secret", peer->secret)
 		M_STR("md5secret", peer->md5secret)
 		M_F("auth", peer->auth = add_realm_authentication(peer->auth, v->value, v->lineno);)
@@ -16664,13 +16655,8 @@
 				peer->maxms = 0;
 			} } )
 		M_INT_GE0("maxcallbitrate", peer->maxcallbitrate, default_maxcallbitrate)
-		M_F("t38pt_udptl", ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_UDPTL);)
-#ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS
-		/* XXX this is different from the handling in the global section */
-		M_F("t38pt_rtp", ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_RTP);)
-		M_F("t38pt_tcp", ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_TCP);)
-#endif
-		M_END(;)
+		M_END(ast_log(LOG_NOTICE, "sip.conf peer [%s]: unknown option %s = %s\n",
+			name, v->name, v->value); )
 	}
 	if (!ast_test_flag(&global_flags[1], SIP_PAGE2_IGNOREREGEXPIRE) && ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC) && realtime) {
 		time_t nowtime = time(NULL);
@@ -16849,6 +16835,7 @@
 			ast_set2_flag(&global_flags[1], i || ast_true(v->value), SIP_PAGE2_RTAUTOCLEAR); } )
 		M_F("usereqphone", ast_set2_flag(&global_flags[0], ast_true(v->value), SIP_USEREQPHONE);)
 		M_BOOL("relaxdtmf", global_relaxdtmf)
+		M_BOOL("allowguest", global_allowguest)
 		M_INT_GE0("checkmwi", global_mwitime, DEFAULT_MWITIME)
 		M_STR("vmexten", default_vmexten)
 		M_INT_GE0("rtptimeout", global_rtptimeout, 0)
@@ -16970,13 +16957,8 @@
 			} } )
 		M_BOOL("callevents", global_callevents)
 		M_INT_GE0("maxcallbitrate", default_maxcallbitrate, DEFAULT_MAX_CALL_BITRATE)
-		M_FLAG("t38pt_udptl", global_flags[1], SIP_PAGE2_T38SUPPORT_UDPTL)
-#ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS
-		M_FLAG("t38pt_rtp", global_flags[1], SIP_PAGE2_T38SUPPORT_RTP)
-		M_FLAG("t38pt_tcp", global_flags[1], SIP_PAGE2_T38SUPPORT_TCP)
-#endif
-		M_FLAG("rfc2833compensate", global_flags[1], SIP_PAGE2_RFC2833_COMPENSATE)
-		M_END(/* */)
+		M_END(ast_log(LOG_NOTICE, "sip.conf [general]: unknown option %s = %s\n",
+			v->name, v->value); )
 	}
 
 	if (!allow_external_domains && AST_LIST_EMPTY(&domain_list)) {



More information about the svn-commits mailing list