[asterisk-commits] branch oej/disable-ol-and-sub r12506 - /team/oej/disable-ol-and-sub/channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Mar 12 03:10:31 MST 2006


Author: oej
Date: Sun Mar 12 04:10:29 2006
New Revision: 12506

URL: http://svn.digium.com/view/asterisk?rev=12506&view=rev
Log:
- Fix peer/user flags and subscribe implementation
- Set global flags properly for backwards compatibility
- Add flags_page2 to pvt - we can't stop that any more

Modified:
    team/oej/disable-ol-and-sub/channels/chan_sip.c

Modified: team/oej/disable-ol-and-sub/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/disable-ol-and-sub/channels/chan_sip.c?rev=12506&r1=12505&r2=12506&view=diff
==============================================================================
--- team/oej/disable-ol-and-sub/channels/chan_sip.c (original)
+++ team/oej/disable-ol-and-sub/channels/chan_sip.c Sun Mar 12 04:10:29 2006
@@ -402,11 +402,10 @@
 static int global_reg_timeout;	
 static int global_regattempts_max;	/*!< Registration attempts before giving up */
 static int global_allowguest;		/*!< allow unauthenticated users/peers to connect? */
+static int global_allowsubscribe;	/*!< Flag for disabling ALL subscriptions */
 static int global_mwitime;		/*!< Time between MWI checks for peers */
 static int global_tos;			/*!< IP Type of service */
 static int global_videosupport;		/*!< Videosupport on or off */
-static int global_allowsubscribe;	/*!< Allow subscriptions ? */
-static int global_allowoverlap;		/*!< Allow overlab dialing ? */
 static int compactheaders;		/*!< send compact sip headers */
 static int recordhistory;		/*!< Record SIP history. Off by default */
 static int dumphistory;			/*!< Dump history to verbose before destroying SIP dialog */
@@ -611,6 +610,9 @@
 #define SIP_PAGE2_ALLOWSUBSCRIBE	(1 << 10)	/*!< Allow subscriptions from this peer? */
 #define SIP_PAGE2_ALLOWOVERLAP		(1 << 11)	/*!< Allow overlap dialing ? */
 
+#define SIP_PAGE2_FLAGS_TO_COPY \
+	(SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP)
+
 /* SIP packet flags */
 #define SIP_PKT_DEBUG		(1 << 0)	/*!< Debug this packet */
 #define SIP_PKT_WITH_TOTAG	(1 << 1)	/*!< This packet has a to-tag */
@@ -671,6 +673,7 @@
 	ast_group_t pickupgroup;		/*!< Pickup group */
 	int lastinvite;				/*!< Last Cseq of invite */
 	unsigned int flags;			/*!< SIP_ flags */	
+	struct ast_flags flags_page2;		/*!< SIP PAGE2 flags */
 	int timer_t1;				/*!< SIP timer T1, ms rtt */
 	unsigned int sipoptions;		/*!< Supported SIP sipoptions on the other end */
 	int capability;				/*!< Special capability (codec) */
@@ -7159,6 +7162,7 @@
 	/* Find user based on user name in the from header */
 	if (user && ast_apply_ha(user->ha, sin)) {
 		ast_copy_flags(p, user, SIP_FLAGS_TO_COPY);
+		ast_copy_flags(p, &user->flags_page2, SIP_PAGE2_FLAGS_TO_COPY);
 		/* copy channel vars */
 		for (v = user->chanvars ; v ; v = v->next) {
 			if ((tmpvar = ast_variable_new(v->name, v->value))) {
@@ -8109,6 +8113,8 @@
 		ast_cli(fd, "  User=Phone   : %s\n", (ast_test_flag(peer, SIP_USEREQPHONE)?"Yes":"No"));
 		ast_cli(fd, "  Trust RPID   : %s\n", (ast_test_flag(peer, SIP_TRUSTRPID) ? "Yes" : "No"));
 		ast_cli(fd, "  Send RPID    : %s\n", (ast_test_flag(peer, SIP_SENDRPID) ? "Yes" : "No"));
+		ast_cli(fd, "  Subscriptions: %s\n", ast_test_flag(&peer->flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE) ? "Yes" : "No");
+		ast_cli(fd, "  Overlap dial : %s\n", ast_test_flag(&peer->flags_page2, SIP_PAGE2_ALLOWOVERLAP) ? "Yes" : "No");
 
 		/* - is enumerated */
 		ast_cli(fd, "  DTMFmode     : %s\n", dtmfmode2str(ast_test_flag(peer, SIP_DTMF)));
@@ -8332,8 +8338,8 @@
 	ast_cli(fd, "  Videosupport:           %s\n", global_videosupport ? "Yes" : "No");
 	ast_cli(fd, "  AutoCreatePeer:         %s\n", autocreatepeer ? "Yes" : "No");
 	ast_cli(fd, "  Allow unknown access:   %s\n", global_allowguest ? "Yes" : "No");
-	ast_cli(fd, "  Allow subscriptions:    %s\n", global_allowsubscribe ? "Yes" : "No");
-	ast_cli(fd, "  Allow overlap dialing:  %s\n", global_allowoverlap ? "Yes" : "No");
+	ast_cli(fd, "  Allow subscriptions:    %s\n", ast_test_flag(&global_flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE) ? "Yes" : "No");
+	ast_cli(fd, "  Allow overlap dialing:  %s\n", ast_test_flag(&global_flags_page2, SIP_PAGE2_ALLOWOVERLAP) ? "Yes" : "No");
 	ast_cli(fd, "  Promsic. redir:         %s\n", ast_test_flag(&global_flags, SIP_PROMISCREDIR) ? "Yes" : "No");
 	ast_cli(fd, "  SIP domain support:     %s\n", AST_LIST_EMPTY(&domain_list) ? "No" : "Yes");
 	ast_cli(fd, "  Call to non-local dom.: %s\n", allow_external_domains ? "Yes" : "No");
@@ -10512,7 +10518,7 @@
 		build_contact(p);			/* Build our contact header */
 
 		if (gotdest) {
-			if (gotdest == 1 && global_allowoverlap) {
+			if (gotdest == 1 && ast_test_flag(&p->flags_page2, SIP_PAGE2_ALLOWOVERLAP)) {
 				transmit_response_reliable(p, "484 Address Incomplete", req);
 				update_call_counter(p, DEC_CALL_LIMIT);
 			} else {
@@ -10659,9 +10665,12 @@
 	if (ast_strlen_zero(p->context))
 		ast_string_field_set(p, context, default_context);
 	res = get_refer_info(p, req);
-	if (global_allowoverlap && res > 0)
-		transmit_response_with_allow(p, "484 Address Incomplete", req, 1);
-	else if (res < 0)
+	if (res > 0) {
+		if (ast_test_flag(&p->flags_page2, SIP_PAGE2_ALLOWOVERLAP)) 
+			transmit_response_with_allow(p, "484 Address Incomplete", req, 1);
+		else
+			transmit_response_with_allow(p, "404 Not Found", req, 1);
+	} else if (res < 0)
 		transmit_response_with_allow(p, "404 Not Found", req, 1);
 	else {
 		int nobye = 0;
@@ -10829,10 +10838,15 @@
 				ast_log(LOG_DEBUG, "Got a re-subscribe on existing subscription %s\n", p->callid);
 		}
 	}
-	if (global_allowsubscribe == FALSE) {
-		transmit_response(p, "403 Forbidden (policy)", &p->initreq);
+
+	/* Check if we have a global disallow setting on subscriptions. 
+		if so, we don't have to check peer/user settings after auth, which saves a lot of processing
+	*/
+	if (!global_allowsubscribe) {
+ 		transmit_response(p, "403 Forbidden (policy)", req);
 		ast_set_flag(p, SIP_NEEDDESTROY);	
 		return 0;
+
 	}
 
 	if (!ignore && !p->initreq.headers) {
@@ -10867,6 +10881,14 @@
 			}
 			return 0;
 		}
+
+		/* Check if this user/peer is allowed to subscribe at all */
+		if (! ast_test_flag(&p->flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE)) {
+ 			transmit_response(p, "403 Forbidden (policy)", req);
+			ast_set_flag(p, SIP_NEEDDESTROY);	
+			return 0;
+		}
+
 		/* Initialize the context if it hasn't been already */
 		if (!ast_strlen_zero(p->subscribecontext))
 			ast_string_field_set(p, context, p->subscribecontext);
@@ -10876,7 +10898,7 @@
 		gotdest = get_destination(p, NULL);
 		build_contact(p);
 		if (gotdest) {
-			if (global_allowoverlap && gotdest == 1)
+			if (gotdest == 1 && ast_test_flag(&p->flags_page2, SIP_PAGE2_ALLOWOVERLAP)) 
 				transmit_response(p, "484 Address Incomplete", req);	/* Overlap dialing on SUBSCRIBE?? */
 			else 
 				transmit_response(p, "404 Not Found", req);
@@ -11813,9 +11835,16 @@
 		else if (strcasecmp(v->value, "never"))
 			ast_set_flag(flags, SIP_PROG_INBAND_NO);
   	} else if (!strcasecmp(v->name, "allowsubscribe")) {
-		global_allowsubscribe = ast_true(v->value);
+		if (ast_true(v->value)) {
+			global_allowsubscribe = FALSE;
+			ast_set_flag(&global_flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE);
+		} else
+			ast_clear_flag(&global_flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE);
   	} else if (!strcasecmp(v->name, "allowoverlap")) {
-		global_allowoverlap = ast_true(v->value);
+		if (ast_true(v->value)) {
+			ast_set_flag(&global_flags_page2, SIP_PAGE2_ALLOWOVERLAP);
+		} else
+			ast_clear_flag(&global_flags_page2, SIP_PAGE2_ALLOWOVERLAP);
   	} else if (!strcasecmp(v->name, "allowguest")) {
 #ifdef OSP_SUPPORT
   		if (!strcasecmp(v->value, "osp"))
@@ -12022,6 +12051,7 @@
 	oldha = user->ha;
 	user->ha = NULL;
 	ast_copy_flags(user, &global_flags, SIP_FLAGS_TO_COPY);
+	ast_copy_flags(user, &global_flags_page2, SIP_PAGE2_FLAGS_TO_COPY);
 	user->capability = global_capability;
 	user->prefs = default_prefs;
 	/* set default context */
@@ -12065,6 +12095,17 @@
 			ast_copy_string(user->musicclass, v->value, sizeof(user->musicclass));
 		} else if (!strcasecmp(v->name, "accountcode")) {
 			ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode));
+		} else if (!strcasecmp(v->name, "allowsubscribe")) {
+			if (ast_true(v->value)) {
+				global_allowsubscribe = TRUE;	/* No global ban any more */
+				ast_set_flag(&user->flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE);
+			} else
+				ast_clear_flag(&user->flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE);
+		} else if (!strcasecmp(v->name, "allowoverlap")) {
+			if (ast_true(v->value)) {
+				ast_set_flag(&user->flags_page2, SIP_PAGE2_ALLOWOVERLAP);
+			} else
+				ast_clear_flag(&user->flags_page2, SIP_PAGE2_ALLOWOVERLAP);
 		} else if (!strcasecmp(v->name, "call-limit")) {
 			user->call_limit = atoi(v->value);
 			if (user->call_limit < 0)
@@ -12103,6 +12144,7 @@
 		peer->addr.sin_port = htons(DEFAULT_SIP_PORT);
 	}
 	ast_copy_flags(peer, &global_flags, SIP_FLAGS_TO_COPY);
+	ast_copy_flags(&peer->flags_page2, &global_flags_page2, SIP_PAGE2_FLAGS_TO_COPY);
 	strcpy(peer->context, default_context);
 	strcpy(peer->subscribecontext, default_subscribecontext);
 	strcpy(peer->language, default_language);
@@ -12127,10 +12169,6 @@
 	peer->pickupgroup = 0;
 	peer->maxms = default_qualify;
 	peer->prefs = default_prefs;
-	if (global_allowoverlap)
-		ast_set_flag((&peer->flags_page2), SIP_PAGE2_ALLOWOVERLAP);
-	if (global_allowsubscribe)
-		ast_set_flag((&peer->flags_page2), SIP_PAGE2_ALLOWSUBSCRIBE);
 }
 
 /*! \brief Create temporary peer (used in autocreatepeer mode) */
@@ -12218,10 +12256,6 @@
 		else if (realtime && !strcasecmp(v->name, "fullcontact")) {
 			ast_copy_string(peer->fullcontact, v->value, sizeof(peer->fullcontact));
 			ast_set_flag((&peer->flags_page2), SIP_PAGE2_RT_FROMCONTACT);
-  		} else if (!strcasecmp(v->name, "allowsubscribe")) {
-			ast_set_flag((&peer->flags_page2), SIP_PAGE2_ALLOWSUBSCRIBE);
-  		} else if (!strcasecmp(v->name, "allowoverlap")) {
-			ast_set_flag((&peer->flags_page2), SIP_PAGE2_ALLOWOVERLAP);
 		} else if (!strcasecmp(v->name, "secret")) 
 			ast_copy_string(peer->secret, v->value, sizeof(peer->secret));
 		else if (!strcasecmp(v->name, "md5secret")) 
@@ -12234,6 +12268,17 @@
 			ast_copy_string(peer->context, v->value, sizeof(peer->context));
 		} else if (!strcasecmp(v->name, "subscribecontext")) {
 			ast_copy_string(peer->subscribecontext, v->value, sizeof(peer->subscribecontext));
+		} else if (!strcasecmp(v->name, "allowsubscribe")) {
+			if (ast_true(v->value)) {
+				global_allowsubscribe = TRUE;	/* No global ban any more */
+				ast_set_flag(&peer->flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE);
+			} else
+				ast_clear_flag(&peer->flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE);
+		} else if (!strcasecmp(v->name, "allowoverlap")) {
+			if (ast_true(v->value)) {
+				ast_set_flag(&peer->flags_page2, SIP_PAGE2_ALLOWOVERLAP);
+			} else
+				ast_clear_flag(&peer->flags_page2, SIP_PAGE2_ALLOWOVERLAP);
 		} else if (!strcasecmp(v->name, "fromdomain"))
 			ast_copy_string(peer->fromdomain, v->value, sizeof(peer->fromdomain));
 		else if (!strcasecmp(v->name, "usereqphone"))
@@ -12431,8 +12476,6 @@
 	ourport = DEFAULT_SIP_PORT;
 	srvlookup = DEFAULT_SRVLOOKUP;
 	global_tos = DEFAULT_TOS;
-	global_allowsubscribe = TRUE;
-	global_allowoverlap = TRUE;
 	externhost[0] = '\0';			/* External host name (for behind NAT DynDNS support) */
 	externexpire = 0;			/* Expiration for DNS re-issuing */
 	externrefresh = 10;
@@ -12443,6 +12486,7 @@
 	regcontext[0] = '\0';
 	expiry = DEFAULT_EXPIRY;
 	global_notifyringing = DEFAULT_NOTIFYRINGING;
+	global_allowsubscribe = TRUE;
 	ast_copy_string(global_useragent, DEFAULT_USERAGENT, sizeof(global_useragent));
 	ast_copy_string(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime));
 	ast_copy_string(global_realm, DEFAULT_REALM, sizeof(global_realm));
@@ -12458,6 +12502,10 @@
 	global_rtptimeout = 0;
 	global_rtpholdtimeout = 0;
 	global_rtpkeepalive = 0;
+	global_allowsubscribe = TRUE;					/* Global flag, default = TRUE */
+	ast_set_flag(&global_flags_page2, SIP_PAGE2_ALLOWSUBSCRIBE);	/* Default for peers, users: TRUE */
+	ast_set_flag(&global_flags_page2, SIP_PAGE2_ALLOWOVERLAP);	/* Default for peers, users: TRUE */
+
 	ast_set_flag(&global_flags_page2, SIP_PAGE2_RTUPDATE);
 
 	/* Initialize some reasonable defaults at SIP reload (used both for channel and as default for peers and users */



More information about the asterisk-commits mailing list