[asterisk-commits] anthonyl: branch anthonyl/testing-branch r42874 - in /team/anthonyl/testing-b...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Sep 12 14:40:39 MST 2006


Author: anthonyl
Date: Tue Sep 12 16:40:38 2006
New Revision: 42874

URL: http://svn.digium.com/view/asterisk?rev=42874&view=rev
Log:
updat to module_user_remove to prevent segfaults like in 7944

Modified:
    team/anthonyl/testing-branch/channels/chan_agent.c
    team/anthonyl/testing-branch/channels/chan_jingle.c
    team/anthonyl/testing-branch/channels/chan_zap.c
    team/anthonyl/testing-branch/include/asterisk/channel.h
    team/anthonyl/testing-branch/include/asterisk/manager.h
    team/anthonyl/testing-branch/main/loader.c
    team/anthonyl/testing-branch/main/manager.c
    team/anthonyl/testing-branch/main/rtp.c

Modified: team/anthonyl/testing-branch/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/testing-branch/channels/chan_agent.c?rev=42874&r1=42873&r2=42874&view=diff
==============================================================================
--- team/anthonyl/testing-branch/channels/chan_agent.c (original)
+++ team/anthonyl/testing-branch/channels/chan_agent.c Tue Sep 12 16:40:38 2006
@@ -739,8 +739,10 @@
 	 * agent_request() is followed immediately by agent_hangup()
 	 * as in apps/app_chanisavail.c:chanavail_exec()
 	 */
-
-	ast_module_user_remove(p->u);
+	
+	if(p->u != NULL) {
+		ast_module_user_remove(p->u);
+	}
 
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Hangup called for state %s\n", ast_state2str(ast->_state));

Modified: team/anthonyl/testing-branch/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/testing-branch/channels/chan_jingle.c?rev=42874&r1=42873&r2=42874&view=diff
==============================================================================
--- team/anthonyl/testing-branch/channels/chan_jingle.c (original)
+++ team/anthonyl/testing-branch/channels/chan_jingle.c Tue Sep 12 16:40:38 2006
@@ -188,6 +188,8 @@
 							   struct ast_rtp *vrtp, int codecs, int nat_active);
 static enum ast_rtp_get_result jingle_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
 static int jingle_get_codec(struct ast_channel *chan);
+static int jingle_show_stats(int fd, int argc, char **argv);
+static int jingle_show(int fd, int argc, char **argv);
 
 /*! \brief PBX interface structure for channel registration */
 static const struct ast_channel_tech jingle_tech = {
@@ -975,6 +977,9 @@
 
 	tmp = p->theircandidates;
 	p->laststun = time(NULL);
+
+
+	/* for each canididate in a message send a stun bind request out */
 	while (tmp) {
 		char username[256];
 		hp = ast_gethostbyname(tmp->ip, &ahp);
@@ -1425,6 +1430,7 @@
 	return RESULT_SUCCESS;
 }
 #endif
+
 
 static int jingle_parser(void *data, ikspak *pak)
 {
@@ -1668,10 +1674,50 @@
 	return 1;
 }
 
+
+/* starting to add some cli entries */
+
+static char jingle_show_usage[] = 
+  "Usage: jingle show\n"
+  "       Shows current Jingle information\n";
+
+static char jingle_show_stats_usage[] = 
+  "Usage: jingle show stats\n"
+  "       Show current Jingle stats\n";
+
+static char jingle_reload_usage[] = 
+  "Usage: jingle reload\n"
+  "       Reloads Jingle configuration from jingle.conf\n";
+  
+static struct ast_cli_entry jingle_clis[] = {
+  { {"jingle", "show", NULL, NULL}, jingle_show, "Show current jingle information\n", jingle_show_usage},
+  { {"jingle", "show", "stats", NULL},  jingle_show_stats, "Show current Jingle connections", jingle_show_stats_usage}
+  /*  { {"jingle", "reload", NULL, NULL),   jingle_reload, "Reload Jingle configuration", jingle_reload_usage} */
+};
+
+
+static int jingle_show(int fd, int argc, char **argv)
+{
+
+  return 0;
+}
+
+
+static int jingle_show_stats(int fd, int argc, char **argv)
+{
+  
+  return 0;
+}
+
+
+
 /*! \brief Load module into PBX, register channel */
 static int load_module(void)
 {
-	ASTOBJ_CONTAINER_INIT(&jingles);
+  
+        ast_cli_register_multiple(jingle_clis, sizeof(jingle_clis)/ sizeof(jingle_clis[0]));
+	
+        ASTOBJ_CONTAINER_INIT(&jingles);
 	if (!jingle_load_config()) {
 		ast_log(LOG_ERROR, "Unable to read config file %s. Not loading module.\n", JINGLE_CONFIG);
 		return AST_MODULE_LOAD_DECLINE;
@@ -1689,7 +1735,7 @@
 		ast_log(LOG_WARNING, "Unable to get own IP address, Jingle disabled\n");
 		return 0;
 	}
-
+	
 	ast_rtp_proto_register(&jingle_rtp);
 
 	/* Make sure we can register our channel type */

Modified: team/anthonyl/testing-branch/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/testing-branch/channels/chan_zap.c?rev=42874&r1=42873&r2=42874&view=diff
==============================================================================
--- team/anthonyl/testing-branch/channels/chan_zap.c (original)
+++ team/anthonyl/testing-branch/channels/chan_zap.c Tue Sep 12 16:40:38 2006
@@ -9031,6 +9031,7 @@
 									pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
 						} else {
 							pri_hangup(pri->pri, pri->pvts[chanpos]->call, e->hangup.cause);
+							pri->pvts[chanpos]->owner = NULL;
 							pri->pvts[chanpos]->call = NULL;
 						}
 						if (e->hangup.cause == PRI_CAUSE_REQUESTED_CHAN_UNAVAIL) {
@@ -9097,6 +9098,9 @@
 										pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span, (int)e->hangup.aoc_units, (e->hangup.aoc_units == 1) ? "" : "s");
 						} else {
 							pri_hangup(pri->pri, pri->pvts[chanpos]->call, e->hangup.cause);
+							ast_log(LOG_WARNING,"anthony Clearnig Owner on Channel %d/%d",pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset);
+							
+							pri->pvts[chanpos]->owner = NULL;
 							pri->pvts[chanpos]->call = NULL;
 						}
 						if (e->hangup.cause == PRI_CAUSE_REQUESTED_CHAN_UNAVAIL) {

Modified: team/anthonyl/testing-branch/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/anthonyl/testing-branch/include/asterisk/channel.h?rev=42874&r1=42873&r2=42874&view=diff
==============================================================================
--- team/anthonyl/testing-branch/include/asterisk/channel.h (original)
+++ team/anthonyl/testing-branch/include/asterisk/channel.h Tue Sep 12 16:40:38 2006
@@ -1348,61 +1348,6 @@
  */
 void ast_channel_whisper_stop(struct ast_channel *chan);
 
-/* Placing this in here for testing for res_openssl.c */
-
-/****** openssl specific ********/
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-/***** end openssl specific ******/
-
-#define AST_SSL_DIRECTORY ""
-
-#define ALLOC(x) malloc((x)+1)
-#define ZERO(p,i) memset((p),0x00,(i))
-#define SIZE 4092
-
-#define AST_SSL_DIR "/var/lib/asterisk/keys/"
-#define AST_SSL_CFG "/etc/asterisk/ssl.conf"
-
-
-/* these are the types i plan on using for socket_type */
-#define AST_SOCKET_TLS1  1
-#define AST_SOCKET_DTLS1 2
-#define AST_SOCKET_SSL2  3
-#define AST_SOCKET_SSL3  4
-
-#define AST_TLS_BUFSZ 2048
-
-struct ast_tls_context{
-  int sd;
-  int accept_sock;
-  int port;
-  int socket_type;
-  int packetsize;
-  struct sockaddr_in tls_saddr;
-  char *keyfile;
-  char *certfile;
-  char *password;
-  char *directory;
-  /* struct ast_netsock ns; */
-  
-  /*! the connection maintaining bits */
-  fd_set readfds;
- 
-  SSL *connection;
-  SSL_CIPHER *cipher;
-  SSL_METHOD *mehtod;
-  SSL_CTX    *context;
-  BIO        *io;
-  BIO        *ssl_bio;
-
-  struct timeval timeout;
-  struct timeval tv;
-};
-
-int ast_socket_openssl(int port,int type);
-/* removing once finished testing the res_openssl.c code */
-
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/anthonyl/testing-branch/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/team/anthonyl/testing-branch/include/asterisk/manager.h?rev=42874&r1=42873&r2=42874&view=diff
==============================================================================
--- team/anthonyl/testing-branch/include/asterisk/manager.h (original)
+++ team/anthonyl/testing-branch/include/asterisk/manager.h Tue Sep 12 16:40:38 2006
@@ -59,6 +59,10 @@
 /* Export manager structures */
 #define AST_MAX_MANHEADERS 80
 #define AST_MAX_MANHEADER_LEN 256
+
+/* SSL support defines */
+#define AST_MAN_SSL_ON  1
+#define AST_MAN_SSL_OFF 0 
 
 struct mansession;
 

Modified: team/anthonyl/testing-branch/main/loader.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/testing-branch/main/loader.c?rev=42874&r1=42873&r2=42874&view=diff
==============================================================================
--- team/anthonyl/testing-branch/main/loader.c (original)
+++ team/anthonyl/testing-branch/main/loader.c Tue Sep 12 16:40:38 2006
@@ -199,6 +199,16 @@
 
 void __ast_module_user_remove(struct ast_module *mod, struct ast_module_user *u)
 {
+	if (u <= 0) {
+		ast_log(LOG_ERROR,"ast_module_user invalid can not remove \n");		
+		return;
+	}
+
+	if (mod <= 0) {
+		ast_log(LOG_ERROR,"ast_module invalid can not remove \n");
+		return;
+	}
+	
 	AST_LIST_LOCK(&mod->users);
 	AST_LIST_REMOVE(&mod->users, u, entry);
 	AST_LIST_UNLOCK(&mod->users);

Modified: team/anthonyl/testing-branch/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/testing-branch/main/manager.c?rev=42874&r1=42873&r2=42874&view=diff
==============================================================================
--- team/anthonyl/testing-branch/main/manager.c (original)
+++ team/anthonyl/testing-branch/main/manager.c Tue Sep 12 16:40:38 2006
@@ -68,7 +68,8 @@
 #include "asterisk/http.h"
 #include "asterisk/threadstorage.h"
 #include "asterisk/linkedlists.h"
-
+/* include for the openssl info */
+#include "asterisk/openssl.h"
 
 
 struct fast_originate_helper {
@@ -140,7 +141,9 @@
 	struct sockaddr_in sin;
 	/*! TCP socket */
 	int fd;
-	/*! Whether or not we're busy doing an action */
+        /*! Per-Connection SSL Flag */
+        int flag_ssl;
+        /*! Whether or not we're busy doing an action */
 	int busy;
 	/*! Whether or not we're "dead" */
 	int dead;
@@ -178,42 +181,68 @@
 	AST_LIST_ENTRY(mansession) list;
 };
 
-
 static AST_LIST_HEAD_STATIC(sessions, mansession);
 
 static struct manager_action *first_action = NULL;
 AST_MUTEX_DEFINE_STATIC(actionlock);
 
-
+static void *session_do(void *data);
 /* this is the main thread for manaing ssl manager connections */
 static int *astman_ssl_thread(void)
 {
   	int ret;
 	pthread_attr_t attr;
-        
+	struct eventqent *eqe;
+	struct mansession *s;
+	struct protoent *p;
+	struct ast_openssl_context *openssl_context;
+	int arg = 1;
+	int flags;
+	time_t now;
+	struct pollfd pfds[1];
+       	int fd_ssl;
+	
         pthread_attr_init(&attr);
   	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-  	ret = ast_socket_openssl(5039,AST_SOCKET_TLS1);
-
-  	if (!ret) {
-        	ast_log(LOG_WARNING, "Error binding SSL socket\n");
-  	}
-    
+	
+	for(;;) {
+		/* modify to use the new version */	
+  	 	openssl_context = ast_socket_openssl(5039,AST_SOCKET_TLS1);
+		
+  		if (openssl_context == NULL) {
+        		ast_log(LOG_WARNING, "Error binding SSL socket\n");
+  		}
+
+		return 0;
+	}
+	
+	/* accept the connection then call do_session */
+	/* the mansession struct should just set the flag for a ssl connection */
+        /* then get_input..etc will go ssl specific */
+	
+	if (!(s = ast_calloc(1, sizeof(*s)))) {
+		/* out of memory */
+	} else {
+		/* we are all ok */
+	} 
+	
+	memset( (char *)s,0x00,sizeof(*s));
+	s->writetimeout = 100;
+	s->waiting_thread = AST_PTHREADT_NULL;
+	
+	s->fd = fd_ssl;
+	s->send_events = -1;
+	s->eventq = master_eventq;
+	
+	/* set the ssl flag on for the mansession */	
+	s->flag_ssl = 1;
+
+	if (ast_pthread_create(&s->t, &attr, session_do ,s)) {
+		/* we are done with the session destory it */
+	}
+	
   return 0;
 }
-
-static int get_input_ssl(void)
-{
-  
-  return 0;
-}
-
-
-void astman_send_response_ssl(struct mansession *s, struct message *m, char *resp, char *msg)
-{
-
-}
-
 
 
 /*! \brief Convert authority code to string with serveral options */
@@ -2041,12 +2070,15 @@
 			free(eqe);
 		}
 		AST_LIST_UNLOCK(&sessions);
+
 		if (s)
 			ast_atomic_fetchadd_int(&num_sessions, -1);
 
 		sinlen = sizeof(sin);
+
 		pfds[0].fd = asock;
 		pfds[0].events = POLLIN;
+
 		/* Wait for something to happen, but timeout every few seconds so
 		   we can ditch any old manager sessions */
 		if (poll(pfds, 1, 5000) < 1)
@@ -2084,10 +2116,14 @@
 		/* Find the last place in the master event queue and hook ourselves
 		   in there */
 		s->eventq = master_eventq;
+
 		while(s->eventq->next)
 			s->eventq = s->eventq->next;
 		AST_LIST_UNLOCK(&sessions);
 		ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
+		
+		s->flag_ssl = 0;
+
 		if (ast_pthread_create(&s->t, &attr, session_do, s))
 			destroy_session(s);
 	}
@@ -2485,6 +2521,7 @@
 	static struct sockaddr_in ba;
 	int x = 1;
 	int ret = 0;
+	int ssl_on = 0;
 	int flags;
 	int webenabled = 0;
 	int newhttptimeout = 60;
@@ -2554,6 +2591,10 @@
 	if ((val = ast_variable_retrieve(cfg, "general", "httptimeout")))
 		newhttptimeout = atoi(val);
 
+	/* enable ssl, as ssl configuration is in ssl.conf */
+	if ((val = ast_variable_retrieve(cfg ,"general", "enable_ssl")))
+	        ssl_on = 1;
+
 	memset(&ba, 0, sizeof(ba));
 	ba.sin_family = AF_INET;
 	ba.sin_port = htons(portno);
@@ -2625,8 +2666,13 @@
 			ast_verbose("Asterisk Management interface listening on port %d\n", portno);
 		
 		ast_pthread_create(&t, NULL, accept_thread, NULL);
-		ast_pthread_create(&ssl_main_thread,NULL,astman_ssl_thread ,NULL);
-	      
+		
+		if(ssl_on) {
+		  ast_pthread_create(&ssl_main_thread,NULL,astman_ssl_thread ,NULL);
+		  if (option_verbose)
+		    ast_verbose("Asterisk Managment interface SSL starting\n");
+		}
+
 	}
 	return 0;
 }

Modified: team/anthonyl/testing-branch/main/rtp.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/testing-branch/main/rtp.c?rev=42874&r1=42873&r2=42874&view=diff
==============================================================================
--- team/anthonyl/testing-branch/main/rtp.c (original)
+++ team/anthonyl/testing-branch/main/rtp.c Tue Sep 12 16:40:38 2006
@@ -394,13 +394,18 @@
 	int reqlen, reqleft;
 	struct stun_attr *attr;
 
+	 ast_log(LOG_WARNING,"sending a stun request\n"); 
+
 	req = (struct stun_header *)reqdata;
 	stun_req_id(req);
 	reqlen = 0;
+
 	reqleft = sizeof(reqdata) - sizeof(struct stun_header);
 	req->msgtype = 0;
 	req->msglen = 0;
+
 	attr = (struct stun_attr *)req->ies;
+
 	if (username)
 		append_attr_string(&attr, STUN_USERNAME, username, &reqlen, &reqleft);
 	req->msglen = htons(reqlen);
@@ -460,7 +465,7 @@
 	respleft = sizeof(respdata) - sizeof(struct stun_header);
 	resp->id = hdr->id;
 	resp->msgtype = 0;
-	resp->msglen = 0;
+	resp->msglen = 0; /* length is zero it should be the size excluding the header */
 	attr = (struct stun_attr *)resp->ies;
 	if (!len) {
 		switch(ntohs(hdr->msgtype)) {
@@ -469,9 +474,11 @@
 				ast_verbose("STUN Bind Request, username: %s\n", 
 					st.username ? st.username : "<none>");
 			if (st.username)
-				append_attr_string(&attr, STUN_USERNAME, st.username, &resplen, &respleft);
+			      append_attr_string(&attr, STUN_USERNAME, st.username, &resplen, &respleft);
 			append_attr_address(&attr, STUN_MAPPED_ADDRESS, src, &resplen, &respleft);
+			/* the response */
 			resp->msglen = htons(resplen);
+			/* this is good */
 			resp->msgtype = htons(STUN_BINDRESP);
 			stun_send(s, src, resp);
 			ret = STUN_ACCEPT;



More information about the asterisk-commits mailing list