[svn-commits] rizzo: trunk r44750 - /trunk/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Oct 8 16:26:10 MST 2006


Author: rizzo
Date: Sun Oct  8 18:26:10 2006
New Revision: 44750

URL: http://svn.digium.com/view/asterisk?rev=44750&view=rev
Log:
update_call_counter(): indentation fixes and small simplifications
at the top of the function.


Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=44750&r1=44749&r2=44750&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sun Oct  8 18:26:10 2006
@@ -2910,7 +2910,7 @@
 static int update_call_counter(struct sip_pvt *fup, int event)
 {
 	char name[256];
-	int *inuse, *call_limit, *inringing = NULL;
+	int *inuse, *call_limit, *inringing;
 	int outgoing = ast_test_flag(&fup->flags[0], SIP_OUTGOING);
 	struct sip_user *u = NULL;
 	struct sip_peer *p = NULL;
@@ -2924,96 +2924,91 @@
 
 	ast_copy_string(name, fup->username, sizeof(name));
 
-	/* Check the list of users */
-	if (!outgoing)	/* Only check users for incoming calls */
-		u = find_user(name, 1);
-
-	if (u) {
+	/* Check the list of users only for incoming calls */
+	if (!outgoing && (u = find_user(name, 1)) ) {
 		inuse = &u->inUse;
 		call_limit = &u->call_limit;
-		p = NULL;
+		inringing = NULL;
+	} else if ( (p = find_peer(fup->peername, NULL, 1) ) ) { /* Try to find peer */
+		inuse = &p->inUse;
+		call_limit = &p->call_limit;
+		inringing = &p->inRinging;
+		ast_copy_string(name, fup->peername, sizeof(name));
 	} else {
-		/* Try to find peer */
-		if (!p)
-			p = find_peer(fup->peername, NULL, 1);
-		if (p) {
-			inuse = &p->inUse;
-			call_limit = &p->call_limit;
-			inringing = &p->inRinging;
-			ast_copy_string(name, fup->peername, sizeof(name));
+		if (option_debug > 1)
+			ast_log(LOG_DEBUG, "%s is not a local device, no call limit\n", name);
+		return 0;
+	}
+
+	switch(event) {
+	/* incoming and outgoing affects the inUse counter */
+	case DEC_CALL_LIMIT:
+		if ( *inuse > 0 ) {
+			if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT))
+				(*inuse)--;
 		} else {
-			if (option_debug > 1)
-				ast_log(LOG_DEBUG, "%s is not a local device, no call limit\n", name);
-			return 0;
-		}
-	}
-	switch(event) {
-		/* incoming and outgoing affects the inUse counter */
-		case DEC_CALL_LIMIT:
-			if ( *inuse > 0 ) {
-				if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT))
-					(*inuse)--;
-			} else {
-				*inuse = 0;
+			*inuse = 0;
+		}
+		if (inringing) {
+			if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
+				if (*inringing > 0)
+					(*inringing)--;
+				else
+					ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", fup->peername);
+				ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
 			}
-			if (inringing) {
-				if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
-					if (*inringing > 0)
-						(*inringing)--;
-					else
-						ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", fup->peername);
-					ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
-				}
+		}
+		if (option_debug > 1 || sipdebug) {
+			ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
+		}
+		break;
+
+	case INC_CALL_RINGING:
+	case INC_CALL_LIMIT:
+		if (*call_limit > 0 ) {
+			if (*inuse >= *call_limit) {
+				ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
+				if (u)
+					ASTOBJ_UNREF(u, sip_destroy_user);
+				else
+					ASTOBJ_UNREF(p, sip_destroy_peer);
+				return -1; 
 			}
-			if (option_debug > 1 || sipdebug) {
-				ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
+		}
+		if (inringing && (event == INC_CALL_RINGING)) {
+			if (!ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
+				(*inringing)++;
+				ast_set_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
 			}
-			break;
-		case INC_CALL_RINGING:
-		case INC_CALL_LIMIT:
-			if (*call_limit > 0 ) {
-				if (*inuse >= *call_limit) {
-					ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
-					if (u)
-						ASTOBJ_UNREF(u, sip_destroy_user);
-					else
-						ASTOBJ_UNREF(p, sip_destroy_peer);
-					return -1; 
-				}
+		}
+		/* Continue */
+		(*inuse)++;
+		ast_set_flag(&fup->flags[0], 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", u ? "user":"peer", name, *inuse, *call_limit);
+		}
+		break;
+
+	case DEC_CALL_RINGING:
+		if (inringing) {
+			if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
+				if (*inringing > 0)
+					(*inringing)--;
+				else
+					ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", p->name);
+				ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
 			}
-			if (inringing && (event == INC_CALL_RINGING)) {
-				if (!ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
-					(*inringing)++;
-					ast_set_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
-				}
-			}
-			/* Continue */
-			(*inuse)++;
-			ast_set_flag(&fup->flags[0], 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", u ? "user":"peer", name, *inuse, *call_limit);
-			}
-			break;
-		case DEC_CALL_RINGING:
-			if (inringing) {
-				if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
-					if (*inringing > 0)
-						(*inringing)--;
-					else
-						ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", p->name);
-					ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
-				}
-			}
-			break;
-		default:
-			ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
-	}
-	if (p)
+		}
+		break;
+
+	default:
+		ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
+	}
+	if (p) {
 		ast_device_state_changed("SIP/%s", p->name);
-	if (u)
+		ASTOBJ_UNREF(p, sip_destroy_peer);
+	} else /* u must be set */
 		ASTOBJ_UNREF(u, sip_destroy_user);
-	else
-		ASTOBJ_UNREF(p, sip_destroy_peer);
 	return 0;
 }
 



More information about the svn-commits mailing list