[Freeswitch-branches] [commit] r10682 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax

FreeSWITCH SVN gmaruzz at freeswitch.org
Tue Dec 9 09:10:42 PST 2008


Author: gmaruzz
Date: Tue Dec  9 12:10:41 2008
New Revision: 10682

Log:
skypiax: no more crashes on unloading on linux

Modified:
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	Tue Dec  9 12:10:41 2008
@@ -29,8 +29,8 @@
 int option_debug = 100;
 switch_endpoint_interface_t *skypiax_endpoint_interface;
 switch_memory_pool_t *skypiax_module_pool = NULL;
-static int running = 1;
-static skypiax_interface_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
+int running = 1;
+skypiax_interface_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
 switch_core_session_t *global_session = NULL;
 /*************************************************/
 /*************************************************/
@@ -443,7 +443,7 @@
 int skypiax_skype_call(struct skypiax_interface *p, char *idest, int timeout,
                        switch_core_session_t * session)
 {
-  char rdest[80];
+  char *rdest;
   char msg_to_skype[1024];
 
   if (option_debug > 10) {
@@ -451,10 +451,12 @@
   }
   switch_sleep(5000);
 
-  //FIXME strncpy(rdest, idest, sizeof(rdest) - 1);
-  strncpy(rdest, "echo123", sizeof(rdest) - 1);
+  rdest = strchr(idest, '/');
+  *rdest++ = '\0';
+
   if (option_debug)
     DEBUGA_SKYPE("Calling Skype, rdest is: %s\n", SKYPIAX_P_LOG, rdest);
+  NOTICA("Calling Skype, rdest is: %s\n", SKYPIAX_P_LOG, rdest);
   skypiax_skype_write(p, "SET AGC OFF");
   switch_sleep(10000);
   skypiax_skype_write(p, "SET AEC OFF");
@@ -516,7 +518,7 @@
       return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
     }
 
-    skypiax_skype_call(tech_pvt->p, outbound_profile->destination_number, 30,
+    skypiax_skype_call(tech_pvt->p, caller_profile->destination_number, 30,
                        *new_session);
 
     switch_channel_set_flag(channel, CF_OUTBOUND);
@@ -546,25 +548,33 @@
                (void *) p);
 
   while (forever) {
+	  if(!running)
+		  break;
     switch_sleep(1000);
     res = skypiax_skype_read(p);
     //if (res == CALLFLOW_INCOMING_HANGUP && p->interface_state != SKYPIAX_STATE_DOWN) 
-    if (res == CALLFLOW_INCOMING_HANGUP) {
-      switch_core_session_t *session = NULL;
-      private_t *tech_pvt;
-      switch_channel_t *channel;
-
-      DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG);
-
-      tech_pvt = p->tech_pvt;
-      session = tech_pvt->session;
-
-      channel = switch_core_session_get_channel(session);
-      DEBUGA_SKYPE("before channel_on_hangup\n", SKYPIAX_P_LOG);
-
-      switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-      DEBUGA_SKYPE("after channel_on_hangup\n", SKYPIAX_P_LOG);
-    }
+	if (res == CALLFLOW_INCOMING_HANGUP) {
+		switch_core_session_t *session = NULL;
+		private_t *tech_pvt = NULL;
+		switch_channel_t *channel = NULL;
+
+		DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG);
+
+		tech_pvt = p->tech_pvt;
+		if(tech_pvt){
+			session = tech_pvt->session;
+
+			if(session){
+				channel = switch_core_session_get_channel(session);
+				DEBUGA_SKYPE("before channel_on_hangup\n", SKYPIAX_P_LOG);
+
+				if(channel) {
+					switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+					DEBUGA_SKYPE("after channel_on_hangup\n", SKYPIAX_P_LOG);
+				}
+			}
+		}
+	}
   }
 
   //if (option_debug > 10) {
@@ -833,13 +843,13 @@
   memset(&globals, '\0', sizeof(globals));
   memset(SKYPIAX_INTERFACES, '\0', sizeof(SKYPIAX_INTERFACES));
 
-#ifndef WIN32                   //FIXME
+#ifndef WIN32                   
   if (!XInitThreads()) {
     ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
   } else {
     DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
   }
-  switch_sleep(10000);          //FIXME
+  switch_sleep(100);  
 #endif /* _WINDOWS_ */
 
   load_config();
@@ -865,16 +875,16 @@
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown)
 {
-  int x = 0;
+  int x = 100;
+  struct skypiax_interface *p = NULL;
 
-  running = -1;
+  running = 0;
 
-  while (running) {
-    if (x++ > 100) {
-      break;
-    }
+  while (x) {
+	x--;
     switch_yield(20000);
   }
+  NOTICA("EXITING FUNC!\n", SKYPIAX_P_LOG);
   return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	Tue Dec  9 12:10:41 2008
@@ -4,6 +4,8 @@
 extern int option_debug;
 extern switch_core_session_t *global_session;
 extern switch_endpoint_interface_t *skypiax_endpoint_interface;
+extern int running;
+extern skypiax_interface_t SKYPIAX_INTERFACES;
 
 #define SKYPE_AUDIO
 #ifdef SKYPE_AUDIO
@@ -68,6 +70,8 @@
   sin_size = sizeof(remote_addr);
   while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
     DEBUGA_SKYPE("ACCEPTED\n", SKYPIAX_P_LOG);
+	  if(!running)
+		  break;
     while (p->interface_state != SKYPIAX_STATE_DOWN
            && (p->skype_callflow == CALLFLOW_STATUS_INPROGRESS
                || p->skype_callflow == SKYPIAX_STATE_UP)) {
@@ -81,6 +85,8 @@
       fd_set fs;
       struct timeval to;
 
+	  if(!running)
+		  break;
       exit = 1;
 
       fdselect = fd;
@@ -232,6 +238,8 @@
   sin_size = sizeof(remote_addr);
   while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
     DEBUGA_SKYPE("ACCEPTED\n", SKYPIAX_P_LOG);
+	  if(!running)
+		  break;
     while (p->interface_state != SKYPIAX_STATE_DOWN
            && (p->skype_callflow == CALLFLOW_STATUS_INPROGRESS
                || p->skype_callflow == SKYPIAX_STATE_UP)) {
@@ -244,6 +252,8 @@
       fd_set fs;
       struct timeval to;
 
+	  if(!running)
+		  break;
       fdselect = 1;
       FD_ZERO(&fs);
       FD_SET(fdselect, &fs);
@@ -567,6 +577,7 @@
 
   switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0],
                              &p->AsteriskHandlesAst.fdesc[1], 2, skypiax_module_pool);
+  switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100000);
 
   win32_AsteriskHandlesSkype = &p->AsteriskHandlesAst;
 
@@ -588,8 +599,12 @@
               win32_hInit_MainWindowHandle;
             while (1) {
               MSG oMessage;
+	  if(!running)
+		  break;
 
               while (GetMessage(&oMessage, 0, 0, 0) != FALSE) {
+	  if(!running)
+		  break;
                 TranslateMessage(&oMessage);
                 DispatchMessage(&oMessage);
               }
@@ -754,6 +769,7 @@
   switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0],
                              &p->AsteriskHandlesAst.fdesc[1], 2, skypiax_module_pool);
 
+  switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100000);
   AsteriskHandlesAst = &p->AsteriskHandlesAst;
   //disp = XOpenDisplay(getenv("DISPLAY"));
   disp = XOpenDisplay(p->X11_display);
@@ -819,6 +835,8 @@
 
     while (1) {
       XNextEvent(disp, &an_event);
+	  if(!running)
+		  break;
       switch (an_event.type) {
       case ClientMessage:
 
@@ -859,7 +877,7 @@
        SKYPIAX_P_LOG);
     return NULL;
   }
-  //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+  DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
   return NULL;
 
 }



More information about the Freeswitch-branches mailing list