[asterisk-commits] bbryant: branch bbryant/sip-tcptls r74161 - in /team/bbryant/sip-tcptls: chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 9 15:52:47 CDT 2007


Author: bbryant
Date: Mon Jul  9 15:52:47 2007
New Revision: 74161

URL: http://svn.digium.com/view/asterisk?view=rev&rev=74161
Log:
* Added support for connection to an SSL server
* Updated configuration files for a register
* Closed all tcp connections when module unloaded

Modified:
    team/bbryant/sip-tcptls/channels/chan_sip.c
    team/bbryant/sip-tcptls/configs/sip.conf.sample
    team/bbryant/sip-tcptls/include/asterisk/server.h
    team/bbryant/sip-tcptls/main/server.c

Modified: team/bbryant/sip-tcptls/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/sip-tcptls/channels/chan_sip.c?view=diff&rev=74161&r1=74160&r2=74161
==============================================================================
--- team/bbryant/sip-tcptls/channels/chan_sip.c (original)
+++ team/bbryant/sip-tcptls/channels/chan_sip.c Mon Jul  9 15:52:47 2007
@@ -1241,7 +1241,16 @@
 	char lastmsg[256];		/*!< Last Message sent/received */
 };
 
+struct sip_threadinfo {
+	int stop;
+	pthread_t threadid;
+	AST_LIST_ENTRY(sip_threadinfo) list;
+};
+
 /* --- Linked lists of various objects --------*/
+
+/*! \brief  The thread list of TCP threads */
+static AST_LIST_HEAD_STATIC(threadl, sip_threadinfo);
 
 /*! \brief  The user list: Users and friends */
 static struct ast_user_list {
@@ -1750,6 +1759,15 @@
 	int cl;
 	char buf[1024];
 	struct sip_request req = { 0, }, reqcpy = { 0, };
+	struct sip_threadinfo *me;
+
+	me = ast_calloc(1, sizeof(*me));
+
+	if (!me)
+		goto cleanup2;
+
+	me->threadid = pthread_self();
+	AST_LIST_INSERT_TAIL(&threadl, me, list);
 
 	req.socket.lock = ast_calloc(1, sizeof(*req.socket.lock));
 
@@ -1765,6 +1783,8 @@
 		while (req.len < 4 || strncmp((char *)&req.data + req.len - 4, "\r\n\r\n", 4)) {
 			if (!fgets(buf, sizeof(buf), ser->f))
 				goto cleanup;
+
+			if (me->stop) goto cleanup;
 
 			strncat(req.data, buf, sizeof(req.data) - req.len);
 			req.len = strlen(req.data);
@@ -1776,6 +1796,8 @@
 			while (cl > 0) {
 				if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, ser->f))
 					goto cleanup;
+
+				if (me->stop) goto cleanup;
 
 				cl -= strlen(buf);
 				strncat(req.data, buf, sizeof(req.data) - req.len);
@@ -1799,6 +1821,9 @@
 	}
 
 cleanup:
+	AST_LIST_REMOVE(&threadl, me, list);
+	ast_free(me);
+cleanup2:
 	fclose(ser->f);
 	ast_free(ser);
 	ast_free(req.socket.lock);
@@ -18824,7 +18849,15 @@
 static int unload_module(void)
 {
 	struct sip_pvt *p, *pl;
+	struct sip_threadinfo *th;
 	
+	while(!AST_LIST_EMPTY(&threadl)) {
+		AST_LIST_TRAVERSE(&threadl, th, list) {
+			th->stop = 1;
+			pthread_kill(th->threadid, SIGURG);
+		}
+	}
+
 	/* First, take us out of the channel type list */
 	ast_channel_unregister(&sip_tech);
 

Modified: team/bbryant/sip-tcptls/configs/sip.conf.sample
URL: http://svn.digium.com/view/asterisk/team/bbryant/sip-tcptls/configs/sip.conf.sample?view=diff&rev=74161&r1=74160&r2=74161
==============================================================================
--- team/bbryant/sip-tcptls/configs/sip.conf.sample (original)
+++ team/bbryant/sip-tcptls/configs/sip.conf.sample Mon Jul  9 15:52:47 2007
@@ -262,7 +262,9 @@
 ;----------------------------------------- OUTBOUND SIP REGISTRATIONS  ------------------------
 ; Asterisk can register as a SIP user agent to a SIP proxy (provider)
 ; Format for the register statement is:
-;       register => user[:secret[:authuser]]@host[:port][/extension]
+;       register => [transport://]user[:secret[:authuser]]@host[:port][/extension]
+;
+; 
 ;
 ; If no extension is given, the 's' extension is used. The extension needs to
 ; be defined in extensions.conf to be able to accept calls from this SIP proxy

Modified: team/bbryant/sip-tcptls/include/asterisk/server.h
URL: http://svn.digium.com/view/asterisk/team/bbryant/sip-tcptls/include/asterisk/server.h?view=diff&rev=74161&r1=74160&r2=74161
==============================================================================
--- team/bbryant/sip-tcptls/include/asterisk/server.h (original)
+++ team/bbryant/sip-tcptls/include/asterisk/server.h Mon Jul  9 15:52:47 2007
@@ -106,6 +106,7 @@
 	FILE *f;    /* fopen/funopen result */
 	int fd;     /* the socket returned by accept() */
 	SSL *ssl;   /* ssl state */
+	int (*ssl_setup)(SSL *);
 	struct sockaddr_in requestor;
 	struct server_args *parent;
 };

Modified: team/bbryant/sip-tcptls/main/server.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/sip-tcptls/main/server.c?view=diff&rev=74161&r1=74160&r2=74161
==============================================================================
--- team/bbryant/sip-tcptls/main/server.c (original)
+++ team/bbryant/sip-tcptls/main/server.c Mon Jul  9 15:52:47 2007
@@ -109,6 +109,8 @@
 		ser->fd = fd;
 		ser->parent = desc;
 		memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
+
+		ser->ssl_setup = SSL_accept;
 			
 		if (ast_pthread_create_detached_background(&launched, NULL, ast_make_file_from_fd, ser)) {
 			ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
@@ -199,6 +201,7 @@
 	ser->parent->worker_fn = NULL;
 	memcpy(&ser->requestor, &desc->sin, sizeof(ser->requestor));
 
+	ser->ssl_setup = SSL_connect;
 	ast_make_file_from_fd(ser);
 
 	return ser;
@@ -297,7 +300,7 @@
 #ifdef DO_SSL
 	else if ( (ser->ssl = SSL_new(ser->parent->tls_cfg->ssl_ctx)) ) {
 		SSL_set_fd(ser->ssl, ser->fd);
-		if ((ret = SSL_accept(ser->ssl)) <= 0) {
+		if ((ret = ser->ssl_setup(ser->ssl)) <= 0) {
 			if(option_verbose > 1)
 				ast_verbose(VERBOSE_PREFIX_2 "Problem setting up ssl connection: %s\n", ERR_error_string(ERR_get_error(), err));
 		} else {




More information about the asterisk-commits mailing list