[asterisk-commits] oej: branch group/set-tonezone-1.4 r286371 - in /team/group/set-tonezone-1.4:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Sep 11 13:47:16 CDT 2010


Author: oej
Date: Sat Sep 11 13:47:11 2010
New Revision: 286371

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=286371
Log:
After thinking about it, I realize it's a bad idea to store the zone pointer in 
a device structure, since you can reload it and delete the zone. Storing
country name instead and adding pointer to zone in channel structure.

Modified:
    team/group/set-tonezone-1.4/channels/chan_sip.c
    team/group/set-tonezone-1.4/include/asterisk/indications.h

Modified: team/group/set-tonezone-1.4/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/set-tonezone-1.4/channels/chan_sip.c?view=diff&rev=286371&r1=286370&r2=286371
==============================================================================
--- team/group/set-tonezone-1.4/channels/chan_sip.c (original)
+++ team/group/set-tonezone-1.4/channels/chan_sip.c Sat Sep 11 13:47:11 2010
@@ -541,7 +541,7 @@
                                                     *   a bridged channel on hold */
 static int default_maxcallbitrate;	/*!< Maximum bitrate for call */
 static struct ast_codec_pref default_prefs;		/*!< Default codec prefs */
-static struct tone_zone *default_zone;	/*!< Global tone zone for indications generate by Asterisk (not Dahdi) */
+static char default_zone[MAX_TONEZONE_COUNTRY];  /*!< Global tone zone for indications generate by Asterisk (not Dahdi) */
 
 /* Global settings only apply to the channel */
 static int global_directrtpsetup;	/*!< Enable support for Direct RTP setup (no re-invites) */
@@ -1003,7 +1003,7 @@
 	long branch;				/*!< The branch identifier of this session */
 	long invite_branch;			/*!< The branch used when we sent the initial INVITE */
 	char tag[11];				/*!< Our tag for this session */
-	struct tone_zone *zone;			/*!< Default tone zone for this user */
+	char zone[MAX_TONEZONE_COUNTRY];	/*!< Default tone zone for this user */
 	int sessionid;				/*!< SDP Session ID */
 	int sessionversion;			/*!< SDP Session Version */
 	unsigned int portinuri:1;		/*!< Non zero if a port has been specified, will also disable srv lookups */
@@ -1129,7 +1129,7 @@
 	struct ast_variable *chanvars;	/*!< Variables to set for channel created by user */
 	int maxcallbitrate;		/*!< Maximum Bitrate for a video call */
 	int autoframing;
-	struct tone_zone *zone;		/*!< Default tone zone for this user */
+	char zone[MAX_TONEZONE_COUNTRY]; /*!< Default tone zone for this user */
 };
 
 /*! \brief Structure for SIP peer data, we place calls to peers if registered  or fixed IP address (host) */
@@ -1194,7 +1194,7 @@
 	struct sip_pvt *mwipvt;		/*!<  Subscription for MWI */
 	int lastmsg;
 	int autoframing;
-	struct tone_zone *zone;		/*!< Default tone zone for this user */
+	char zone[MAX_TONEZONE_COUNTRY]; /*!< Default tone zone for this user */
 };
 
 
@@ -3117,7 +3117,7 @@
 		ast_string_field_set(dialog, fromuser, peer->fromuser);
 	if (!ast_strlen_zero(peer->language))
 		ast_string_field_set(dialog, language, peer->language);
-	dialog->zone = peer->zone;
+	ast_copy_string(dialog->zone, peer->zone, sizeof(dialog->zone));
 	dialog->maxtime = peer->maxms;
 	dialog->callgroup = peer->callgroup;
 	dialog->pickupgroup = peer->pickupgroup;
@@ -4332,6 +4332,8 @@
 	int what;
 	int needvideo = 0, video = 0;
 	char *decoded_exten;
+	struct tone_zone *new_zone;
+
 	{
 		const char *my_name;    /* pick a good name */
 
@@ -4442,7 +4444,11 @@
 		tmp->amaflags = i->amaflags;
 	if (!ast_strlen_zero(i->language))
 		ast_string_field_set(tmp, language, i->language);
-	tmp->zone = i->zone;
+	if (!(new_zone = ast_get_indication_zone(i->zone))) {
+		ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", i->zone);
+	} else {
+		tmp->zone = new_zone;
+	}
 	i->owner = tmp;
 	ast_module_ref(ast_module_info->self);
 	ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
@@ -4819,7 +4825,7 @@
 	p->subscribed = NONE;
 	p->stateid = -1;
 	p->prefs = default_prefs;		/* Set default codecs for this call */
-	p->zone = default_zone;			/* Set default tone zone */
+	ast_copy_string(p->zone, default_zone, sizeof(p->zone));
 
 	if (intended_method != SIP_OPTIONS)	/* Peerpoke has it's own system */
 		p->timer_t1 = 500;	/* Default SIP retransmission timer T1 (RFC 3261) */
@@ -10516,7 +10522,7 @@
 			ast_string_field_set(p, language, user->language);
 			ast_string_field_set(p, mohsuggest, user->mohsuggest);
 			ast_string_field_set(p, mohinterpret, user->mohinterpret);
-			p->zone = user->zone;
+			ast_copy_string(p->zone, user->zone, sizeof(p->zone));
 			p->allowtransfer = user->allowtransfer;
 			p->amaflags = user->amaflags;
 			p->callgroup = user->callgroup;
@@ -10652,7 +10658,7 @@
 				ast_string_field_set(p, peermd5secret, peer->md5secret);
 				ast_string_field_set(p, language, peer->language);
 				ast_string_field_set(p, accountcode, peer->accountcode);
-				p->zone = peer->zone;
+				ast_copy_string(p->zone, peer->zone, sizeof(p->zone));
 				p->amaflags = peer->amaflags;
 				p->callgroup = peer->callgroup;
 				p->pickupgroup = peer->pickupgroup;
@@ -11462,7 +11468,7 @@
 		ast_cli(fd, "  Context      : %s\n", peer->context);
 		ast_cli(fd, "  Subscr.Cont. : %s\n", S_OR(peer->subscribecontext, "<Not set>") );
 		ast_cli(fd, "  Language     : %s\n", peer->language);
-		ast_cli(fd, "  Tonezone     : %s\n", peer->zone != NULL ? peer->zone->country : "<Not set>");
+		ast_cli(fd, "  Tonezone     : %s\n", S_OR(peer->zone, "<Not set>"));
 		if (!ast_strlen_zero(peer->accountcode))
 			ast_cli(fd, "  Accountcode  : %s\n", peer->accountcode);
 		ast_cli(fd, "  AMA flags    : %s\n", ast_cdr_flags2str(peer->amaflags));
@@ -11554,7 +11560,7 @@
 		astman_append(s, "MD5SecretExist: %s\r\n", ast_strlen_zero(peer->md5secret)?"N":"Y");
 		astman_append(s, "Context: %s\r\n", peer->context);
 		astman_append(s, "Language: %s\r\n", peer->language);
-		astman_append(s, "ToneZone: %s\r\n", peer->zone ? peer->zone->country : "<Not set>");
+		astman_append(s, "ToneZone: %s\r\n", peer->zone);
 		if (!ast_strlen_zero(peer->accountcode))
 			astman_append(s, "Accountcode: %s\r\n", peer->accountcode);
 		astman_append(s, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags));
@@ -11651,7 +11657,7 @@
 		ast_cli(fd, "  MD5Secret    : %s\n", ast_strlen_zero(user->md5secret)?"<Not set>":"<Set>");
 		ast_cli(fd, "  Context      : %s\n", user->context);
 		ast_cli(fd, "  Language     : %s\n", user->language);
-		ast_cli(fd, "  Tonezone     : %s\n", user->zone ? user->zone->country : "<Not set>");
+		ast_cli(fd, "  Tonezone     : %s\n", S_OR(user->zone, "<Not set>"));
 		if (!ast_strlen_zero(user->accountcode))
 			ast_cli(fd, "  Accountcode  : %s\n", user->accountcode);
 		ast_cli(fd, "  AMA flags    : %s\n", ast_cdr_flags2str(user->amaflags));
@@ -11803,7 +11809,7 @@
 	ast_cli(fd, "  Use ClientCode:         %s\n", ast_test_flag(&global_flags[0], SIP_USECLIENTCODE) ? "Yes" : "No");
 	ast_cli(fd, "  Progress inband:        %s\n", (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER) ? "Never" : (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NO) ? "No" : "Yes" );
 	ast_cli(fd, "  Language:               %s\n", S_OR(default_language, "(Defaults to English)"));
-	ast_cli(fd, "  Tone zone:              %s\n", default_zone != NULL ? default_zone->country : "<Not set>");
+	ast_cli(fd, "  Tone zone:              %s\n", S_OR(default_zone, "<Not set>"));
 	ast_cli(fd, "  MOH Interpret:          %s\n", default_mohinterpret);
 	ast_cli(fd, "  MOH Suggest:            %s\n", default_mohsuggest);
 	ast_cli(fd, "  Voice Mail Extension:   %s\n", default_vmexten);
@@ -18128,7 +18134,7 @@
 	user->maxcallbitrate = default_maxcallbitrate;
 	user->autoframing = global_autoframing;
 	user->prefs = default_prefs;
-	user->zone = default_zone;
+	ast_copy_string(user->zone, default_zone, sizeof(user->zone));
 	/* set default context */
 	strcpy(user->context, default_context);
 	strcpy(user->language, default_language);
@@ -18182,7 +18188,7 @@
 			if (!(new_zone = ast_get_indication_zone(v->value))) {
 				ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", v->value);
 			} else {
-				user->zone = new_zone;
+				ast_copy_string(user->zone, v->value, sizeof(user->zone));
 			}
 		} else if (!strcasecmp(v->name, "mohinterpret") 
 			|| !strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) {
@@ -18269,7 +18275,7 @@
 	peer->pickupgroup = 0;
 	peer->maxms = default_qualify;
 	peer->prefs = default_prefs;
-	peer->zone = default_zone;
+	ast_copy_string(peer->zone, default_zone, sizeof(peer->zone));
 }
 
 /*! \brief Create temporary peer (used in autocreatepeer mode) */
@@ -18487,7 +18493,7 @@
 				if (!(new_zone = ast_get_indication_zone(v->value))) {
 					ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", v->value);
 				} else {
-					peer->zone = new_zone;
+					ast_copy_string(peer->zone, v->value, sizeof(peer->zone));
 				}
 			} else if (!strcasecmp(v->name, "regexten")) {
 				ast_copy_string(peer->regexten, v->value, sizeof(peer->regexten));
@@ -18772,7 +18778,7 @@
 	default_language[0] = '\0';
 	default_fromdomain[0] = '\0';
 	default_qualify = DEFAULT_QUALIFY;
-	default_zone = NULL;
+	default_zone[0] = '\0';
 	default_maxcallbitrate = DEFAULT_MAX_CALL_BITRATE;
 	ast_copy_string(default_mohinterpret, DEFAULT_MOHINTERPRET, sizeof(default_mohinterpret));
 	ast_copy_string(default_mohsuggest, DEFAULT_MOHSUGGEST, sizeof(default_mohsuggest));
@@ -18896,7 +18902,7 @@
 			if (!(new_zone = ast_get_indication_zone(v->value))) {
 				ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", v->value);
 			} else {
-				default_zone = new_zone;
+				ast_copy_string(default_zone, v->value, sizeof(default_zone));
 			}
 		} else if (!strcasecmp(v->name, "language")) {
 			ast_copy_string(default_language, v->value, sizeof(default_language));

Modified: team/group/set-tonezone-1.4/include/asterisk/indications.h
URL: http://svnview.digium.com/svn/asterisk/team/group/set-tonezone-1.4/include/asterisk/indications.h?view=diff&rev=286371&r1=286370&r2=286371
==============================================================================
--- team/group/set-tonezone-1.4/include/asterisk/indications.h (original)
+++ team/group/set-tonezone-1.4/include/asterisk/indications.h Sat Sep 11 13:47:11 2010
@@ -34,6 +34,8 @@
 
 #include "asterisk/lock.h"
 
+#define MAX_TONEZONE_COUNTRY 5
+
 struct tone_zone_sound {
 	struct tone_zone_sound *next;		/* next element */
 	const char *name;			/* Identifing name */
@@ -47,8 +49,8 @@
 
 struct tone_zone {
 	struct tone_zone* next;				/* next in list */
-	char country[5];				/* Country code */
-	char alias[5];					/* is this an alias? */
+	char country[MAX_TONEZONE_COUNTRY];		/* Country code */
+	char alias[MAX_TONEZONE_COUNTRY];		/* is this an alias? */
 	char description[40];				/* Description */
 	int  nrringcadence;				/* # registered ringcadence elements */
 	int *ringcadence;				/* Ring cadence */




More information about the asterisk-commits mailing list