[Freeswitch-branches] [commit] r11579 - in freeswitch/branches/gmaruzz/mod_skypiax: . asterisk

FreeSWITCH SVN gmaruzz at freeswitch.org
Sat Jan 31 08:48:15 PST 2009


Author: gmaruzz
Date: Sat Jan 31 10:48:15 2009
New Revision: 11579

Log:
skypiax: same skyiax_protocol.c for FS and *. FS: works as before. Incoming audio not yet working on *, outgoing audio, incoming dtmf, IVR, works

Modified:
   freeswitch/branches/gmaruzz/mod_skypiax/asterisk/Makefile
   freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c
   freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax_protocol.c
   freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c

Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/Makefile
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/Makefile	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/Makefile	Sat Jan 31 10:48:15 2009
@@ -23,6 +23,9 @@
 #AST_INCLUDE_DIR=/home/maruzz/devel/svn_asterisk_branches_14/include
 AST_INCLUDE_DIR=/home/maruzz/devel/svn_celliax_trunk/asterisk-1.2.rev137401/include
 
+#ASTERISK
+CFLAGS+=-DASTERISK
+
 #ASTERISK VERSION
 #Uncomment one of the following lines to match your Asterisk series
 #CFLAGS+=-DASTERISK_VERSION_1_4

Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c	Sat Jan 31 10:48:15 2009
@@ -2236,6 +2236,71 @@
 	return skypiax_do_tcp_cli_thread_func(obj);
 }
 
+int skypiax_skypeaudio_write(struct skypiax_pvt *p, struct ast_frame *f)
+{
+  int sent;
+
+  if (option_debug > 100) {
+    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
+  }
+  sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen);
+
+  if (option_debug > 100) {
+    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+  }
+  return 0;
+}
+int skypiax_console_skype(int fd, int argc, char *argv[])
+{
+  struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
+  char skype_msg[1024];
+  int i, a, c;
+
+  if (argc == 1) {
+    return RESULT_SHOWUSAGE;
+  }
+  if (!p) {
+    ast_cli(fd,
+            "No \"current\" console for skypiax_skype, please enter 'help console'\n");
+    return RESULT_SUCCESS;
+  }
+  if (option_debug > 10) {
+    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
+  }
+  if (!p->skype) {
+    ast_cli(fd, "The \"current\" console is not connected to a Skype client'\n");
+    if (option_debug > 10) {
+      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+    }
+    if (option_debug > 10) {
+      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+    }
+    return RESULT_SUCCESS;
+  }
+
+  memset(skype_msg, 0, sizeof(skype_msg));
+  c = 0;
+  for (i = 1; i < argc; i++) {
+    for (a = 0; a < strlen(argv[i]); a++) {
+      skype_msg[c] = argv[i][a];
+      c++;
+      if (c == 1022)
+        break;
+    }
+    if (i != argc - 1) {
+      skype_msg[c] = ' ';
+      c++;
+    }
+    if (c == 1023)
+      break;
+  }
+  skypiax_skype_write(p, skype_msg);
+  if (option_debug > 10) {
+    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+  }
+  return RESULT_SUCCESS;
+}
+
 /************************************************/
 #ifdef ASTERISK_VERSION_1_4
 #ifndef AST_MODULE

Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax_protocol.c	Sat Jan 31 10:48:15 2009
@@ -1,19 +1,23 @@
 #include "skypiax.h"
 
+#ifdef ASTERISK
 #define skypiax_sleep usleep
-#define skypiax_file_write switch_file_write
-#define skypiax_file_read switch_file_read
-
 #define tech_pvt p
-
 #define SKYPIAX_DIR_CONFIG "directoriax.conf"
-
 extern int skypiax_debug;
-//extern switch_memory_pool_t *skypiax_module_pool;
+#define skypiax_file_write switch_file_write
+#define skypiax_file_read switch_file_read
+extern char *skypiax_console_active;
+#else /* FREESWITCH */
+#define skypiax_sleep switch_sleep
+extern switch_memory_pool_t *skypiax_module_pool;
+extern switch_endpoint_interface_t *skypiax_endpoint_interface;
+#define skypiax_file_write switch_file_write
+#define skypiax_file_read switch_file_read
+#endif /* ASTERISK */
+
 extern int option_debug;
-//extern switch_endpoint_interface_t *skypiax_endpoint_interface;
 extern int running;
-extern char *skypiax_console_active;
 
 /* GLOBALS */
 int skypiax_dir_entry_extension=1;
@@ -1028,7 +1032,6 @@
           howmany = strlen(b) + 1;
 
           howmany = write(SkypiaxHandles->fdesc[1], b, howmany);
-      //DEBUGA_PBX("HERE: %s\n", SKYPIAX_P_LOG, b);
           memset(buffer, '\0', 17000);
         }
 
@@ -1632,110 +1635,7 @@
   return 0;
 }
 
-#if 0
-static switch_status_t channel_write_frame(switch_core_session_t * session,
-                                           switch_frame_t * frame, switch_io_flag_t flags,
-                                           int stream_id)
-{
-  switch_channel_t *channel = NULL;
-  private_t *tech_pvt = NULL;
-  unsigned int sent;
-
-  channel = switch_core_session_get_channel(session);
-  assert(channel != NULL);
-
-  tech_pvt = switch_core_session_get_private(session);
-  assert(tech_pvt != NULL);
-
-  if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
-    ERRORA("CIAPA \n", SKYPIAX_P_LOG);
-    return SWITCH_STATUS_FALSE;
-  }
-#ifdef BIGENDIAN
-  if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
-    switch_swap_linear(frame->data, (int) frame->datalen / 2);
-  }
-#endif
-
-  sent = frame->datalen;
-#ifdef WIN32
-  switch_file_write(tech_pvt->audioskypepipe[1], frame->data, &sent);
-#else /* WIN32 */
-  sent = write(tech_pvt->audioskypepipe[1], frame->data, sent);
-#endif /* WIN32 */
-  if (sent != frame->datalen && sent != -1) {
-    DEBUGA_SKYPE("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
-  }
-
-  return SWITCH_STATUS_SUCCESS;
-}
-#endif
-
-
-int skypiax_skypeaudio_write(struct skypiax_pvt *p, struct ast_frame *f)
-{
-  int sent;
-
-  if (option_debug > 100) {
-    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
-  }
-  sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen);
-
-  if (option_debug > 100) {
-    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-  }
-  return 0;
-}
-int skypiax_console_skype(int fd, int argc, char *argv[])
-{
-  struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
-  char skype_msg[1024];
-  int i, a, c;
-
-  if (argc == 1) {
-    return RESULT_SHOWUSAGE;
-  }
-  if (!p) {
-    ast_cli(fd,
-            "No \"current\" console for skypiax_skype, please enter 'help console'\n");
-    return RESULT_SUCCESS;
-  }
-  if (option_debug > 10) {
-    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
-  }
-  if (!p->skype) {
-    ast_cli(fd, "The \"current\" console is not connected to a Skype client'\n");
-    if (option_debug > 10) {
-      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-    }
-    if (option_debug > 10) {
-      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-    }
-    return RESULT_SUCCESS;
-  }
-
-  memset(skype_msg, 0, sizeof(skype_msg));
-  c = 0;
-  for (i = 1; i < argc; i++) {
-    for (a = 0; a < strlen(argv[i]); a++) {
-      skype_msg[c] = argv[i][a];
-      c++;
-      if (c == 1022)
-        break;
-    }
-    if (i != argc - 1) {
-      skype_msg[c] = ' ';
-      c++;
-    }
-    if (c == 1023)
-      break;
-  }
-  skypiax_skype_write(p, skype_msg);
-  if (option_debug > 10) {
-    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-  }
-  return RESULT_SUCCESS;
-}
+#ifdef ASTERISK
 int skypiax_console_skypiax_dir_import(int fd, int argc, char *argv[])
 {
   //int res;
@@ -2107,3 +2007,4 @@
 
   return RESULT_SUCCESS;
 }
+#endif /* ASTERISK */

Modified: freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c	Sat Jan 31 10:48:15 2009
@@ -1,14 +1,26 @@
 #include "skypiax.h"
 
+#ifdef ASTERISK
+#define skypiax_sleep usleep
+#define tech_pvt p
+#define SKYPIAX_DIR_CONFIG "directoriax.conf"
+extern int skypiax_debug;
+#define skypiax_file_write switch_file_write
+#define skypiax_file_read switch_file_read
+extern char *skypiax_console_active;
+#else /* FREESWITCH */
 #define skypiax_sleep switch_sleep
+extern switch_memory_pool_t *skypiax_module_pool;
+extern switch_endpoint_interface_t *skypiax_endpoint_interface;
 #define skypiax_file_write switch_file_write
 #define skypiax_file_read switch_file_read
+#endif /* ASTERISK */
 
-extern switch_memory_pool_t *skypiax_module_pool;
 extern int option_debug;
-extern switch_endpoint_interface_t *skypiax_endpoint_interface;
 extern int running;
 
+/* GLOBALS */
+int skypiax_dir_entry_extension=1;
 /*************************************/
 #ifndef WIN32
 XErrorHandler old_handler = 0;
@@ -118,8 +130,8 @@
 
         if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
 
-          ERRORA("tech_pvt->audiopipe[0] = %d\n", SKYPIAX_P_LOG, tech_pvt->audiopipe[0]);
-          ERRORA("tech_pvt->audiopipe[1] = %d\n", SKYPIAX_P_LOG, tech_pvt->audiopipe[1]);
+          //ERRORA("tech_pvt->audiopipe[0] = %d\n", SKYPIAX_P_LOG, tech_pvt->audiopipe[0]);
+          //ERRORA("tech_pvt->audiopipe[1] = %d\n", SKYPIAX_P_LOG, tech_pvt->audiopipe[1]);
           if (len > 0) {
             a = 0;
             for (i = 0; i < len / sizeof(short); i++) {
@@ -509,7 +521,7 @@
     if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
       //if (samples)
       //ERRORA("SRV PIPE READ=====> NOT GOOD samples=%u expected=%lu\n", SKYPIAX_P_LOG, samples, SAMPLES_PER_FRAME * sizeof(short));
-      assert(samples == SAMPLES_PER_FRAME * sizeof(short)); //do a crash, please
+      //assert(samples == SAMPLES_PER_FRAME * sizeof(short)); //do a crash, please
       return 0;
     } else {
       /* A real frame */
@@ -925,6 +937,15 @@
 
   DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
 
+  if(!strlen(tech_pvt->X11_display))
+  	strcpy(tech_pvt->X11_display, getenv("DISPLAY"));
+
+  if(!tech_pvt->tcp_srv_port)
+  	tech_pvt->tcp_srv_port = 10160;
+
+  if(!tech_pvt->tcp_cli_port)
+  	tech_pvt->tcp_cli_port = 10161;
+
   if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
     fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
     fcntl(tech_pvt->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
@@ -1613,3 +1634,377 @@
   //FIXME ast_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_RINGING);
   return 0;
 }
+
+#ifdef ASTERISK
+int skypiax_console_skypiax_dir_import(int fd, int argc, char *argv[])
+{
+  //int res;
+  struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
+  //char list_command[64];
+  char fn[256];
+  char date[256] = "";
+  time_t t;
+  char *configfile = SKYPIAX_DIR_CONFIG;
+  int add_to_skypiax_dir_conf = 1;
+  //int fromskype = 0;
+  //int fromcell = 0;
+
+#if 0
+  if(directoriax_entry_extension){
+    skypiax_dir_entry_extension=directoriax_entry_extension;
+  }else{
+    ast_cli(fd, "No 'directoriax_entry_extension', you MUST have loaded directoriax.so\n");
+    return RESULT_SUCCESS;
+  }
+#endif
+
+  if (argc != 2)
+    return RESULT_SHOWUSAGE;
+  if (!p) {
+    ast_cli(fd, "No \"current\" console ???, please enter 'help skypiax_console'\n");
+    return RESULT_SUCCESS;
+  }
+
+  if (!strcasecmp(argv[1], "add"))
+    add_to_skypiax_dir_conf = 1;
+  else if (!strcasecmp(argv[1], "replace"))
+    add_to_skypiax_dir_conf = 0;
+  else {
+    ast_cli(fd, "\n\nYou have neither specified 'add' nor 'replace'\n\n");
+    return RESULT_SHOWUSAGE;
+  }
+
+#if 0
+  if (!strcasecmp(argv[2], "fromskype"))
+    fromskype = 1;
+  else if (!strcasecmp(argv[2], "fromcell"))
+    fromcell = 1;
+  else {
+    ast_cli(fd, "\n\nYou have neither specified 'fromskype' nor 'fromcell'\n\n");
+    return RESULT_SHOWUSAGE;
+  }
+
+  if (fromcell) {
+    ast_cli(fd,
+            "Importing from cellphone is currently supported only on \"AT\" cellphones :( !\n");
+    //fclose(p->phonebook_writing_fp);
+    //skypiax_dir_create_extensions();
+    return RESULT_SUCCESS;
+  }
+
+  if (fromskype)
+    if (!p->skype) {
+      ast_cli(fd, "Importing from skype is supported by skypiax_dir on chan_skypiax!\n");
+      //fclose(p->phonebook_writing_fp);
+      //skypiax_dir_create_extensions();
+      return RESULT_SUCCESS;
+    }
+
+  if (fromcell || fromskype)
+    if (argc != 3) {
+      ast_cli(fd,
+              "\n\nYou don't have to specify a filename with 'fromcell' or with 'fromskype'\n\n");
+      return RESULT_SHOWUSAGE;
+    }
+#endif
+
+  /*******************************************************************************************/
+
+  if (configfile[0] == '/') {
+    ast_copy_string(fn, configfile, sizeof(fn));
+  } else {
+    snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
+  }
+  if (option_debug)
+    NOTICA("Opening '%s'\n", SKYPIAX_P_LOG, fn);
+  time(&t);
+  ast_copy_string(date, ctime(&t), sizeof(date));
+
+  if (add_to_skypiax_dir_conf)
+    p->phonebook_writing_fp = fopen(fn, "a+");
+  else
+    p->phonebook_writing_fp = fopen(fn, "w+");
+
+  if (p->phonebook_writing_fp) {
+    if (add_to_skypiax_dir_conf) {
+      if (option_debug)
+        NOTICA("Opened '%s' for appending \n", SKYPIAX_P_LOG, fn);
+      fprintf(p->phonebook_writing_fp, ";!\n");
+      fprintf(p->phonebook_writing_fp, ";! Update Date: %s", date);
+      fprintf(p->phonebook_writing_fp, ";! Updated by: %s, %d\n", __FILE__, __LINE__);
+      fprintf(p->phonebook_writing_fp, ";!\n");
+    } else {
+      if (option_debug)
+        NOTICA("Opened '%s' for writing \n", SKYPIAX_P_LOG, fn);
+      fprintf(p->phonebook_writing_fp, ";!\n");
+      fprintf(p->phonebook_writing_fp, ";! Automatically generated configuration file\n");
+      fprintf(p->phonebook_writing_fp, ";! Filename: %s (%s)\n", configfile, fn);
+      fprintf(p->phonebook_writing_fp, ";! Creation Date: %s", date);
+      fprintf(p->phonebook_writing_fp, ";! Generated by: %s, %d\n", __FILE__, __LINE__);
+      fprintf(p->phonebook_writing_fp, ";!\n");
+      fprintf(p->phonebook_writing_fp, "[general]\n\n");
+      fprintf(p->phonebook_writing_fp, "[default]\n");
+    }
+
+  /*******************************************************************************************/
+    //if (fromskype) {
+      if (p->skype) {
+        WARNINGA
+          ("About to querying the Skype client 'Contacts', it may take some moments... Don't worry.\n",
+           SKYPIAX_P_LOG);
+        if (p->skype_thread != AST_PTHREADT_NULL) {
+          char msg_to_skype[1024];
+
+          p->skype_friends[0] = '\0';
+          sprintf(msg_to_skype, "#333 SEARCH FRIENDS");
+          if (skypiax_skype_write(p, msg_to_skype) < 0) {
+            return -1;
+          }
+
+          int friends_count = 0;
+          while (p->skype_friends[0] == '\0') {
+            /* FIXME needs a timeout, can't wait forever! 
+             * eg. when skype is running but not connected! */
+            usleep(100);
+            friends_count++;
+            if (friends_count > 20000) {
+              return -1;        /* FIXME */
+            }
+          }
+
+        }
+
+        if (p->skype_thread != AST_PTHREADT_NULL) {
+          char msg_to_skype[1024];
+
+          if (p->skype_friends[0] != '\0') {
+            char *buf, *where;
+            char **stringp;
+            int skype_dir_file_written = 0;
+
+            buf = p->skype_friends;
+            stringp = &buf;
+            where = strsep(stringp, ", ");
+            while (where) {
+              if (where[0] != '\0') {
+                /*
+                 * So, we have the Skype username (the HANDLE, I think is called).
+                 * But we want to call the names we see in the Skype contact list
+                 * So, let's check the DISPLAYNAME (the end user modified contact name)
+                 * Then, we check the FULLNAME (that appears as it was the DISPLAYNAME 
+                 * if the end user has not modify it)
+                 * If we still have neither DISPLAYNAME nor FULLNAME, we'll use the 
+                 * Skipe username (the HANDLE)
+                 */
+
+                p->skype_displayname[0] = '\0';
+                sprintf(msg_to_skype, "#765 GET USER %s DISPLAYNAME", where);
+                skypiax_skype_write(p, msg_to_skype);
+                int displayname_count = 0;
+                while (p->skype_displayname[0] == '\0') {
+                  /* FIXME needs a timeout, can't wait forever! 
+                   * eg. when skype is running but not connected! */
+                  usleep(100);
+                  displayname_count++;
+                  if (displayname_count > 20000)
+                    return -1;  /* FIXME */
+                }
+                if (p->skype_displayname[0] != '\0') {
+                  char *where2;
+                  char sanitized[300];
+
+                  sanitized[0] = '\0';
+
+                  where2 = strstr(p->skype_displayname, "DISPLAYNAME ");
+                  if (where2) {
+
+                    /* there can be some *smart* that makes a displayname 
+                     * that is different than first<space>last, */
+                    /* maybe initials, simbols, slashes, 
+                     * something smartish... let's check */
+
+                    if (where2[12] != '\0') {
+                      int i = 12;
+                      int x = 0;
+                      int spaces = 0;
+                      int last_char_was_space = 0;
+
+                      for (i = 12; i < strlen(where2) && x < 299; i++) {
+                        if (!isalnum(where2[i])) {
+                          if (!isblank(where2[i])) {
+                            /* bad char */
+                            continue;
+                          }
+                          /* is a space */
+                          if (last_char_was_space == 1) /* do not write 2 consecutive spaces */
+                            continue;
+                          last_char_was_space = 1;
+                          sanitized[x] = ' ';
+                          x++;
+                          continue;
+                        }
+                        /* is alphanum */
+                        last_char_was_space = 0;
+                        sanitized[x] = where2[i];
+                        x++;
+                        continue;
+                      }
+
+                      sanitized[x] = '\0';
+                      if (spaces == 0) {
+                      }
+                      DEBUGA_SKYPE("sanitized=|%s|, where=|%s|, where2=|%s|\n",
+                                   SKYPIAX_P_LOG, sanitized, where, &where2[12]);
+                    }
+
+                    if (where2[12] != '\0') {
+                      skypiax_dir_entry_extension++;
+                      if (where[0] == '+' || isdigit(where[0])) {   /* is a skypeout number */
+                        fprintf(p->phonebook_writing_fp,
+                                "%s  => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+                                where, sanitized, "no",
+                                p->skypiax_dir_entry_extension_prefix, "2",
+                                skypiax_dir_entry_extension, "yes", "not_specified");
+                      } else {  /* is a skype name */
+                        fprintf(p->phonebook_writing_fp,
+                                "%s  => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+                                where, sanitized, "no",
+                                p->skypiax_dir_entry_extension_prefix, "1",
+                                skypiax_dir_entry_extension, "yes", "not_specified");
+                      }
+                      skype_dir_file_written = 1;
+
+                    }
+                  }
+                }
+                p->skype_displayname[0] = '\0';
+
+                p->skype_fullname[0] = '\0';
+                sprintf(msg_to_skype, "#222 GET USER %s FULLNAME", where);
+                skypiax_skype_write(p, msg_to_skype);
+                int fullname_count = 0;
+                while (p->skype_fullname[0] == '\0') {
+                  /* FIXME needs a timeout, can't wait forever! 
+                   * eg. when skype is running but not connected! */
+                  usleep(100);
+                  fullname_count++;
+                  if (fullname_count > 20000)
+                    return -1;  /* FIXME */
+                }
+                if (p->skype_fullname[0] != '\0') {
+                  char *where2;
+                  char sanitized[300];
+
+                  where2 = strstr(p->skype_fullname, "FULLNAME ");
+                  if (where2) {
+
+                    /* there can be some *smart* that makes a fullname 
+                     * that is different than first<space>last, */
+                    /* maybe initials, simbols, slashes,
+                     *  something smartish... let's check */
+
+                    if (where2[9] != '\0') {
+                      int i = 9;
+                      int x = 0;
+                      int spaces = 0;
+                      int last_char_was_space = 0;
+
+                      for (i = 9; i < strlen(where2) && x < 299; i++) {
+                        if (!isalnum(where2[i])) {
+                          if (!isblank(where2[i])) {
+                            /* bad char */
+                            continue;
+                          }
+                          /* is a space */
+                          if (last_char_was_space == 1) /* do not write 2 consecutive spaces */
+                            continue;
+                          last_char_was_space = 1;
+                          sanitized[x] = ' ';
+                          x++;
+                          continue;
+                        }
+                        /* alphanum */
+                        last_char_was_space = 0;
+                        sanitized[x] = where2[i];
+                        x++;
+                        continue;
+                      }
+
+                      sanitized[x] = '\0';
+                      if (spaces == 0) {
+                      }
+                      DEBUGA_SKYPE("sanitized=|%s|, where=|%s|, where2=|%s|\n",
+                                   SKYPIAX_P_LOG, sanitized, where, &where2[9]);
+                    }
+
+                    if (skype_dir_file_written == 0) {
+                      skypiax_dir_entry_extension++;
+                      if (where2[9] != '\0') {
+                        if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */
+                          fprintf(p->phonebook_writing_fp,
+                                  "%s  => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+                                  where, sanitized, "no",
+                                  p->skypiax_dir_entry_extension_prefix, "2",
+                                  skypiax_dir_entry_extension, "yes", "not_specified");
+                        } else {    /* is a skype name */
+                          fprintf(p->phonebook_writing_fp,
+                                  "%s  => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+                                  where, sanitized, "no",
+                                  p->skypiax_dir_entry_extension_prefix, "1",
+                                  skypiax_dir_entry_extension, "yes", "not_specified");
+
+                        }
+
+                      } else {
+                        if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */
+                          fprintf(p->phonebook_writing_fp,
+                                  "%s  => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+                                  where, where, "no",
+                                  p->skypiax_dir_entry_extension_prefix, "2",
+                                  skypiax_dir_entry_extension, "yes", "not_specified");
+                        } else {    /* is a skype name */
+                          fprintf(p->phonebook_writing_fp,
+                                  "%s  => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+                                  where, where, "no",
+                                  p->skypiax_dir_entry_extension_prefix, "1",
+                                  skypiax_dir_entry_extension, "yes", "not_specified");
+
+                        }
+                      }
+                    }
+
+                    skype_dir_file_written = 0;
+
+                  }
+
+                }
+                p->skype_fullname[0] = '\0';
+
+              }
+              where = strsep(stringp, ", ");
+            }
+
+            p->skype_friends[0] = '\0';
+          }
+        }
+      } else {
+
+        ast_cli(fd,
+                "Skype not configured on the 'current' console, not importing from Skype client!\n");
+      }
+    //}
+  /*******************************************************************************************/
+  /*******************************************************************************************/
+  } else {
+    ast_cli(fd, "\n\nfailed to open the skypiax_dir.conf configuration file: %s\n", fn);
+    ERRORA("failed to open the skypiax_dir.conf configuration file: %s\n", SKYPIAX_P_LOG,
+           fn);
+    return RESULT_FAILURE;
+  }
+
+  fclose(p->phonebook_writing_fp);
+  //skypiax_dir_create_extensions();
+
+  return RESULT_SUCCESS;
+}
+#endif /* ASTERISK */



More information about the Freeswitch-branches mailing list