[svn-commits] branch oej/peermatch r11843 - /team/oej/peermatch/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Mar 5 01:43:43 MST 2006


Author: oej
Date: Sun Mar  5 02:43:35 2006
New Revision: 11843

URL: http://svn.digium.com/view/asterisk?rev=11843&view=rev
Log:
Small fixes inspired by Rizzo

Modified:
    team/oej/peermatch/channels/chan_sip.c

Modified: team/oej/peermatch/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/peermatch/channels/chan_sip.c?rev=11843&r1=11842&r2=11843&view=diff
==============================================================================
--- team/oej/peermatch/channels/chan_sip.c (original)
+++ team/oej/peermatch/channels/chan_sip.c Sun Mar  5 02:43:35 2006
@@ -174,7 +174,6 @@
 enum objecttype {
 	SIP_USER = (1 << 0),		/* USER places calls to the PBX */
 	SIP_PEER = (1 << 1),		/* Peer receives calls from PBX (and places calls) */
-	SIP_FRIEND = (1 << 2),		/* Friend receives calls from PBX (and places calls) */
 };
 
 enum subscriptiontype { 
@@ -1654,7 +1653,7 @@
 static void sip_destroy_device(struct sip_peer *device)
 {
 	if (option_debug > 2)
-		ast_log(LOG_DEBUG, "Destroying SIP %s %s\n", device->type == SIP_USER ? "user" : "peer", device->name);
+		ast_log(LOG_DEBUG, "Destroying SIP %s %s\n", device->type & SIP_USER ? "user" : "peer", device->name);
 
 	/* Delete it, it needs to disappear */
 	if (device->call)
@@ -1668,7 +1667,8 @@
 	if (device->pokeexpire > -1)
 		ast_sched_del(sched, device->pokeexpire);
 	ast_free_ha(device->ha);
-	if ( device->type == SIP_PEER) {
+
+	if (device->type & SIP_PEER) {
 		register_peer_exten(device, FALSE);
 		clear_realm_authentication(device->auth);
 		if (ast_test_flag((&device->flags_page2), SIP_PAGE2_SELFDESTRUCT))
@@ -1677,7 +1677,8 @@
 			rpeerobjs--;
 		else
 			speerobjs--;
-	} else {	/* SIP_USER */
+	} 
+	if (device->type & SIP_USER) {	/* SIP_USER */
 		if (ast_test_flag(device, SIP_REALTIME))
 			ruserobjs--;
 		else
@@ -2270,13 +2271,13 @@
 				device->inUse= 0;
 			}
 			if (option_debug > 1 || sipdebug) {
-				ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", device->type == SIP_USER ? "user":"peer", name, device->call_limit);
+				ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", device->type & SIP_USER ? "user":"peer", name, device->call_limit);
 			}
 			break;
 		case INC_CALL_LIMIT:
 			if (device->call_limit > 0 ) {
 				if (device->inUse >= device->call_limit) {
-					ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", device->type == SIP_USER ? "user":"peer", name, device->call_limit);
+					ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", device->type & SIP_USER ? "user":"peer", name, device->call_limit);
 					ASTOBJ_UNREF(device, sip_destroy_device);
 					return -1; 
 				}
@@ -2284,7 +2285,7 @@
 			device->inUse++;
 			ast_set_flag(fup, SIP_INC_COUNT);
 			if (option_debug > 1 || sipdebug) {
-				ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", device->type == SIP_USER ? "user":"peer", name, device->inUse, device->call_limit);
+				ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", device->type & SIP_USER ? "user" : "peer", name, device->inUse, device->call_limit);
 			}
 			break;
 		default:
@@ -7015,6 +7016,7 @@
 	char calleridname[50];
 	int debug=sip_debug_test_addr(sin);
 	struct ast_variable *tmpvar = NULL, *v = NULL;
+	enum objecttype devicematch = SIP_UNKNOWN;
 
 	/* Terminate URI */
 	t = uri;
@@ -7079,6 +7081,8 @@
 		ASTOBJ_UNREF(device,sip_destroy_device);
 		device = NULL;
 	}
+	if (device)
+		devicematch = SIP_USER;			/* We matched on a user */
 
 	if (!device) {
 		/* Secondly, match on peer name */
@@ -7100,6 +7104,8 @@
 			ASTOBJ_UNREF(device,sip_destroy_device);
 			device = NULL;
 		}
+		if (device)
+			devicematch = SIP_PEER;		/* We matched on a peer */
 	}
 
 	/* No user or peer found */
@@ -7191,7 +7197,7 @@
 		}
 		if (!ast_strlen_zero(device->cid_name) && !ast_strlen_zero(p->cid_num))
 			ast_string_field_set(p, cid_name, device->cid_name);
-		if (device->type == SIP_USER) {
+		if (devicematch == SIP_USER) {
 			ast_string_field_set(p, username, device->name);
 		} else { /* SIP_PEER */
 			ast_string_field_set(p, peersecret, device->secret);
@@ -7234,7 +7240,7 @@
 			snprintf(mailbox, mailboxlen, ",%s,", device->mailbox);
 	}
 	if (device && debug)
-		ast_verbose("Found %s '%s'\n", device->type == SIP_USER ? "user" : "peer", device->name);
+		ast_verbose("Found %s '%s'\n", device->type & SIP_USER ? "user" : "peer", device->name);
 
 	if (device)
 		ASTOBJ_UNREF(device, sip_destroy_device);
@@ -11892,7 +11898,7 @@
 		
 	suserobjs++;
 	ASTOBJ_INIT(user);
-	user-> type = SIP_USER;
+	user->type &= SIP_USER;
 	ast_copy_string(user->name, name, sizeof(user->name));
 	oldha = user->ha;
 	user->ha = NULL;
@@ -12021,7 +12027,7 @@
 		peer->expire = -1;
 		peer->pokeexpire = -1;
 	}
-	peer->type = SIP_PEER;
+	peer->type &= SIP_PEER;
 
 	/* Note that our peer HAS had its reference count incrased */
 
@@ -12224,7 +12230,7 @@
 {
 	struct ast_config *cfg;
 	struct ast_variable *v;
-	struct sip_peer *device;
+	struct sip_peer *device = (struct sip_peer *) NULL;
 	struct ast_hostent ahp;
 	char *cat;
 	struct hostent *hp;
@@ -12524,17 +12530,18 @@
 			continue;
 		} else {
 			enum objecttype type;
+
 			if (!strcasecmp(utype, "user"))
 				type = SIP_USER;
 			else if (!strcasecmp(utype, "friend"))
-				type = SIP_FRIEND;
+				type = SIP_USER | SIP_PEER;
 			else if (!strcasecmp(utype, "peer"))
 				type = SIP_PEER;
 			else {
 				ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf");
 				continue;
 			}
-			if (type == SIP_PEER || type == SIP_FRIEND) {
+			if (type & SIP_PEER) {
 				device = build_peer(cat, ast_variable_browse(cfg, cat), 0);
 				if (device) {
 					ASTOBJ_CONTAINER_LINK(&peerl,device);
@@ -12542,9 +12549,9 @@
 					peer_count++;
 				}
 			}
-			if (type == SIP_USER || type == SIP_FRIEND) {
+			if (type & SIP_USER) {
 				/* We already have a device for a friend, link it in again */
-				if (type != SIP_FRIEND)
+				if (!(type & SIP_PEER))	/* Friend ? Don't build a new object, just re-use the peer object */
 					device = build_user(cat, ast_variable_browse(cfg, cat), 0);
 				if (device) {
 					ASTOBJ_CONTAINER_LINK(&userl,device);



More information about the svn-commits mailing list