[asterisk-commits] twilson: trunk r98988 - in /trunk: configs/ doc/tex/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 16 21:09:33 CST 2008


Author: twilson
Date: Wed Jan 16 21:09:32 2008
New Revision: 98988

URL: http://svn.digium.com/view/asterisk?view=rev&rev=98988
Log:
Update res_phoneprov to default to setting the SERVER variable to the IP
the HTTP request for the config came in on and the SERVER_PORT to the
bindport setting in sip.conf.  I've left in the ability to override these
options, because I can't always guess how someone might decide to do something
weird with what is available to them--although needing to is pretty unlikely.

Documentation was updated to reflect preference for not setting serveraddr,
serveriface, or serverport.  Tested on Linux and OS X.

Modified:
    trunk/configs/phoneprov.conf.sample
    trunk/doc/tex/phoneprov.tex
    trunk/res/res_phoneprov.c

Modified: trunk/configs/phoneprov.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/phoneprov.conf.sample?view=diff&rev=98988&r1=98987&r2=98988
==============================================================================
--- trunk/configs/phoneprov.conf.sample (original)
+++ trunk/configs/phoneprov.conf.sample Wed Jan 16 21:09:32 2008
@@ -1,9 +1,14 @@
 [general]
-;serveraddr=192.168.1.1 ; Address to send to the phone to use as server address.
-serveriface=eth0        ; Same as above, except an ethernet interface.
-                        ; Useful for when the interface uses DHCP.
-                        ; There is no default for either of the above, and only one should be set.
-serverport=5060         ; Port to send to the phone to use as server port.  Default is 5060.
+; The default behavior of res_phoneprov will be to set the SERVER template variable to
+; the IP address that the phone uses to contact the provisioning server and the
+; SERVER_PORT variable to the bindport setting in sip.conf.  Unless you have a very
+; unusual setup, you should not need to set serveraddr, serveriface, or serverport.
+
+;serveraddr=192.168.1.1 ; Override address to send to the phone to use as server address.
+;serveriface=eth0       ; Same as above, except an ethernet interface.
+                        ; Useful for when the interface uses DHCP and the asterisk http
+                        ; server listens on a different IP than chan_sip.
+;serverport=5060        ; Override port to send to the phone to use as server port.
 default_profile=polycom ; The default profile to use if none specified in users.conf
 
 ; You can define profiles for different phones specifying what files to register

Modified: trunk/doc/tex/phoneprov.tex
URL: http://svn.digium.com/view/asterisk/trunk/doc/tex/phoneprov.tex?view=diff&rev=98988&r1=98987&r2=98988
==============================================================================
--- trunk/doc/tex/phoneprov.tex (original)
+++ trunk/doc/tex/phoneprov.tex Wed Jan 16 21:09:32 2008
@@ -21,20 +21,26 @@
 \begin{verbatim}
 [general]
 ;serveriface=eth0
-serveraddr=192.168.1.1
-serverport=5060
+;serveraddr=192.168.1.1
+;serverport=5060
 default_profile=polycom
 \end{verbatim}
 \end{astlisting}
 
-There are two choices for setting the SERVER variable. If the IP address of the server is 
-known, or the hostname resolvable by the phones, the appropriate \textbf{serveraddr} 
-value should be set.  Alternatively, the network interface that the server listens on can 
-be set by specifying a \textbf{serveriface} and SERVER will be set to the IP address of 
-that interface.  Only one of these options should be set.
-
-The SERVER\_PORT variable is set by setting the \textbf{serverport}.  If serverport is 
-not specified, it is set to a default value of 5060.
+By default, res\_phoneprov will set the SERVER variable to the IP address on the server
+that the requesting phone uses to contact the asterisk HTTP server.  The SERVER\_PORT
+variable will default to the \textbf{bindport} setting in sip.conf.
+
+Should the defaults be insufficient, there are two choices for overriding the default 
+setting of the SERVER variable. If the IP address of the server is known, or the hostname 
+resolvable by the phones, the appropriate \textbf{serveraddr} value should be set.  
+Alternatively, the network interface that the server listens on can be set by specifying a
+\textbf{serveriface} and SERVER will be set to the IP address of that interface.  Only one
+of these options should be set.
+
+The default SERVER\_PORT variable can be overridden by setting the \textbf{serverport}.
+If \textbf{bindport} is not set in \path{sip.conf} and serverport is not specified, it 
+is set to a default value of 5060.
 
 Any user set for auto-provisioning in users.conf without a specified profile will be 
 assumed to belong to the profile set with \textbf{default\_profile}.

Modified: trunk/res/res_phoneprov.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_phoneprov.c?view=diff&rev=98988&r1=98987&r2=98988
==============================================================================
--- trunk/res/res_phoneprov.c (original)
+++ trunk/res/res_phoneprov.c Wed Jan 16 21:09:32 2008
@@ -153,7 +153,7 @@
 };
 
 char global_server[80] = "";	/*!< Server to substitute into templates */
-char global_serverport[6] = "5060";	/*!< Server port to substitute into templates */
+char global_serverport[6] = "";	/*!< Server port to substitute into templates */
 char global_default_profile[80] = "";	/*!< Default profile to use if one isn't specified */	
 
 /*! \brief List of global variables currently available: VOICEMAIL_EXTEN, EXTENSION_LENGTH */
@@ -395,6 +395,23 @@
 			if (file)
 				ast_free(file);
 			goto out500;
+		}
+
+		/* Unless we are overridden by serveriface or serveraddr, we set the SERVER variable to
+		 * the IP address we are listening on that the phone contacted for this config file */
+		if (ast_strlen_zero(global_server)) {
+			struct sockaddr name;
+			socklen_t namelen = sizeof(name);
+			int res;
+
+			if ((res = getsockname(ser->fd, &name, &namelen)))
+				ast_log(LOG_WARNING, "Could not get server IP, breakage likely.\n");
+			else {
+				struct ast_var_t *var;
+
+				if ((var = ast_var_assign("SERVER", ast_inet_ntoa(((struct sockaddr_in *)&name)->sin_addr))))
+					AST_LIST_INSERT_TAIL(route->user->headp, var, entries);
+			}
 		}
 
 		pbx_substitute_variables_varshead(route->user->headp, file, tmp, bufsize);
@@ -698,10 +715,11 @@
 	if (!ast_strlen_zero(global_server)) {
 		if ((var = ast_var_assign("SERVER", global_server)))
 			AST_LIST_INSERT_TAIL(user->headp, var, entries);
-		if (!ast_strlen_zero(global_serverport)) {
-			if ((var = ast_var_assign("SERVER_PORT", global_serverport)))
-				AST_LIST_INSERT_TAIL(user->headp, var, entries);
-		}
+	}
+
+	if (!ast_strlen_zero(global_serverport)) {
+		if ((var = ast_var_assign("SERVER_PORT", global_serverport)))
+			AST_LIST_INSERT_TAIL(user->headp, var, entries);
 	}
 
 	/* Append profile variables here, and substitute variables on profile
@@ -736,20 +754,27 @@
 /* \brief Parse config files and create appropriate structures */
 static int set_config(void)
 {
-	struct ast_config *phoneprov_cfg, *users_cfg;
+	struct ast_config *cfg;
 	char *cat;
 	struct ast_variable *v;
 	struct ast_flags config_flags = { 0 };
 
-	if (!(phoneprov_cfg = ast_config_load("phoneprov.conf", config_flags))) {
+	/* Try to grab the port from sip.conf.  If we don't get it here, we'll set it
+	 * to whatever is set in phoneprov.conf or default to 5060 */
+	if ((cfg = ast_config_load("sip.conf", config_flags))) {
+		ast_copy_string(global_serverport, S_OR(ast_variable_retrieve(cfg, "general", "bindport"), "5060"), sizeof(global_serverport));
+		ast_config_destroy(cfg);
+	}
+
+	if (!(cfg = ast_config_load("phoneprov.conf", config_flags))) {
 		ast_log(LOG_ERROR, "Unable to load config phoneprov.conf\n");
 		return -1;
 	}
 
 	cat = NULL;
-	while ((cat = ast_category_browse(phoneprov_cfg, cat))) {
+	while ((cat = ast_category_browse(cfg, cat))) {
 		if (!strcasecmp(cat, "general")) {
-			for (v = ast_variable_browse(phoneprov_cfg, cat); v; v = v->next) {
+			for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
 				if (!strcasecmp(v->name, "serveraddr"))
 					ast_copy_string(global_server, v->value, sizeof(global_server));
 				else if (!strcasecmp(v->name, "serveriface")) {
@@ -761,28 +786,26 @@
 				else if (!strcasecmp(v->name, "default_profile"))
 					ast_copy_string(global_default_profile, v->value, sizeof(global_default_profile));
 			}
-			if (ast_strlen_zero(global_server))
-				ast_log(LOG_WARNING, "No serveraddr/serveriface set in phoneprov.conf.  Breakage likely.\n");
 		} else 
-			build_profile(cat, ast_variable_browse(phoneprov_cfg, cat));
-	}
-
-	ast_config_destroy(phoneprov_cfg);
-
-	if (!(users_cfg = ast_config_load("users.conf", config_flags))) {
+			build_profile(cat, ast_variable_browse(cfg, cat));
+	}
+
+	ast_config_destroy(cfg);
+
+	if (!(cfg = ast_config_load("users.conf", config_flags))) {
 		ast_log(LOG_WARNING, "Unable to load users.cfg\n");
 		return 0;
 	}
 
 	cat = NULL;
-	while ((cat = ast_category_browse(users_cfg, cat))) {
+	while ((cat = ast_category_browse(cfg, cat))) {
 		const char *tmp, *mac;
 		struct user *user;
 		struct phone_profile *profile;
 		struct ast_var_t *var;
 
 		if (!strcasecmp(cat, "general")) {
-			for (v = ast_variable_browse(users_cfg, cat); v; v = v->next) {
+			for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
 				if (!strcasecmp(v->name, "vmexten")) {
 					if ((var = ast_var_assign("VOICEMAIL_EXTEN", v->value)))
 						AST_LIST_INSERT_TAIL(&global_variables, var, entries);
@@ -797,15 +820,15 @@
 		if (!strcasecmp(cat, "authentication"))
 			continue;
 
-		if (!((tmp = ast_variable_retrieve(users_cfg, cat, "autoprov")) && ast_true(tmp)))	
+		if (!((tmp = ast_variable_retrieve(cfg, cat, "autoprov")) && ast_true(tmp)))	
 			continue;
 
-		if (!(mac = ast_variable_retrieve(users_cfg, cat, "macaddress"))) {
+		if (!(mac = ast_variable_retrieve(cfg, cat, "macaddress"))) {
 			ast_log(LOG_WARNING, "autoprov set for %s, but no mac address - skipping.\n", cat);
 			continue;
 		}
 
-		tmp = S_OR(ast_variable_retrieve(users_cfg, cat, "profile"), global_default_profile);
+		tmp = S_OR(ast_variable_retrieve(cfg, cat, "profile"), global_default_profile);
 		if (ast_strlen_zero(tmp)) {
 			ast_log(LOG_WARNING, "No profile for user [%s] with mac '%s' - skipping\n", cat, mac);
 			continue;
@@ -816,7 +839,7 @@
 			continue;
 		}
 
-		if (!(user = build_user(users_cfg, cat, mac, profile))) {
+		if (!(user = build_user(cfg, cat, mac, profile))) {
 			ast_log(LOG_WARNING, "Could not create user %s - skipping.\n", cat);
 			continue;
 		}
@@ -832,7 +855,7 @@
 		AST_RWLIST_UNLOCK(&users);
 	}
 
-	ast_config_destroy(users_cfg);
+	ast_config_destroy(cfg);
 
 	return 0;
 }




More information about the asterisk-commits mailing list