[asterisk-commits] bbryant: branch bbryant/ssl-tcp-tls r72721 - /team/bbryant/ssl-tcp-tls/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 29 16:11:54 CDT 2007


Author: bbryant
Date: Fri Jun 29 16:11:53 2007
New Revision: 72721

URL: http://svn.digium.com/view/asterisk?view=rev&rev=72721
Log:
Trying to add support for sip registrations

Modified:
    team/bbryant/ssl-tcp-tls/channels/chan_sip.c

Modified: team/bbryant/ssl-tcp-tls/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/ssl-tcp-tls/channels/chan_sip.c?view=diff&rev=72721&r1=72720&r2=72721
==============================================================================
--- team/bbryant/ssl-tcp-tls/channels/chan_sip.c (original)
+++ team/bbryant/ssl-tcp-tls/channels/chan_sip.c Fri Jun 29 16:11:53 2007
@@ -1215,6 +1215,7 @@
 		AST_STRING_FIELD(callback);	/*!< Contact extension */
 		AST_STRING_FIELD(random);
 	);
+	int transport;
 	int portno;			/*!<  Optional port override */
 	int expire;			/*!< Sched ID of expiration */
 	int expiry;			/*!< Value to use for the Expires header */
@@ -5005,14 +5006,41 @@
 {
 	struct sip_registry *reg;
 	int portnum = 0;
+	int transport = SIP_TRANSPORT_UDP;
 	char username[256] = "";
 	char *hostname=NULL, *secret=NULL, *authuser=NULL;
 	char *porta=NULL;
 	char *callback=NULL;
+	char *trans=NULL;
 
 	if (!value)
 		return -1;
 	ast_copy_string(username, value, sizeof(username));
+
+	trans = strstr(username, "://");
+
+	if (trans) {
+		if (trans - username == 3 && 
+		  strncasecmp(username, "udp", 3) &&
+		  strncasecmp(username, "tcp", 3) &&
+		  strncasecmp(username, "tls", 3)) {
+			switch(username[1] + ((username[1] < 97) ? 32 : 0)) { // Ensure lowercase
+				case 'c':
+					transport = SIP_TRANSPORT_TCP;
+					break;
+				case 'l':
+					transport = SIP_TRANSPORT_TLS;
+					break;
+			}
+		} else {
+			*trans = '\0';
+		    ast_log(LOG_WARNING, "Invalid transport type '%s' given at line %d\n", username, lineno);
+			ast_copy_string(username, trans + 3, sizeof(username));
+		}
+	}
+
+	ast_log(LOG_DEBUG, "Transport type is '%d' for register URI '%s'\n", transport, username);
+
 	/* First split around the last '@' then parse the two components. */
 	hostname = strrchr(username, '@'); /* allow @ in the first part */
 	if (hostname)
@@ -5066,6 +5094,7 @@
 		ast_string_field_set(reg, authuser, authuser);
 	if (secret)
 		ast_string_field_set(reg, secret, secret);
+	reg->transport = transport;
 	reg->expire = -1;
 	reg->expiry = default_expiry;
 	reg->timeout =  -1;
@@ -7969,6 +7998,35 @@
 			ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n");
 			return 0;
 		}
+
+		p->transport = r->transport;
+
+		if(!(p->transport & SIP_TRANSPORT_UDP)) {
+			char name[256];
+			struct server_args ca;
+
+			snprintf(name, sizeof(name), "SIP Register to %s", p->peername);
+
+			ca.name = name;
+			ca.accept_fd = -1;
+			ca.tls_cfg = (p->ser) ? p->ser->parent->tls_cfg : NULL;
+			ca.sin = p->sa;
+			p->ser = (!p->ser) ? client_start(&ca) : p->ser;
+
+			if (!p->ser)
+				return -1;
+
+			p->fd = ca.accept_fd;
+
+			if (ast_pthread_create_background(&ca.master, NULL, sip_tcp_helper_thread, p->ser)) {
+				ast_debug(1, "Unable to launch '%s'.", ca.name);
+				close(ca.accept_fd);
+				p->fd = ca.accept_fd = -1;
+				return -1;
+			}
+		}
+
+
 		if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
 




More information about the asterisk-commits mailing list