[Freeswitch-svn] [commit] r11627 - freeswitch/branches/gmaruzz/mod_skypiax/asterisk

FreeSWITCH SVN gmaruzz at freeswitch.org
Tue Feb 3 15:39:17 PST 2009


Author: gmaruzz
Date: Tue Feb  3 17:39:16 2009
New Revision: 11627

Log:
skypiax: works on *. Starting tomorrow, cleaning all the code, making it readable, washing, rinsing, repeat, repeat, repeat... :-)

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

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	Tue Feb  3 17:39:16 2009
@@ -12,6 +12,7 @@
 
 /* GLOBAL VARIABLES */
 int running = 1;
+int skypiax_dir_entry_extension=1; //FIXME one var for each interface!
 char skypiax_console_active_array[50] = "";
 char *skypiax_console_active = skypiax_console_active_array;
 /*! \brief Count of active channels for this module */
@@ -2085,7 +2086,7 @@
 
 }
 int start_audio_threads(private_t *p) {
-                if (!p->tcp_srv_thread) {
+                //if (!p->tcp_srv_thread) {
                   if (ast_pthread_create
                       (&p->tcp_srv_thread, NULL, skypiax_do_tcp_srv_thread, p) < 0) {
                     ERRORA("Unable to start tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
@@ -2096,8 +2097,8 @@
                   } else {
                     DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
                   }
-                }
-                if (!p->tcp_cli_thread) {
+                //}
+                //if (!p->tcp_cli_thread) {
                   if (ast_pthread_create
                       (&p->tcp_cli_thread, NULL, skypiax_do_tcp_cli_thread, p) < 0) {
                     ERRORA("Unable to start tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
@@ -2108,7 +2109,7 @@
                   } else {
                     DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
                   }
-                }
+                //}
 
 
 #ifdef NOTDEF
@@ -2287,6 +2288,377 @@
   return RESULT_SUCCESS;
 }
 
+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;
+}
 /************************************************/
 #ifdef ASTERISK_VERSION_1_4
 #ifndef AST_MODULE

Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h	Tue Feb  3 17:39:16 2009
@@ -111,6 +111,7 @@
 /* DEFINITIONS */
 #define SAMPLERATE_SKYPIAX 8000
 #define SAMPLES_PER_FRAME SAMPLERATE_SKYPIAX/50
+#define SKYPIAX_DIR_CONFIG "directoriax.conf"
 
 /* LUIGI RIZZO's magic */
 /* boost support. BOOST_SCALE * 10 ^(BOOST_MAX/20) must

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	Tue Feb  3 17:39:16 2009
@@ -3,7 +3,6 @@
 #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
@@ -19,8 +18,6 @@
 extern int option_debug;
 extern int running;
 
-/* GLOBALS */
-int skypiax_dir_entry_extension=1;
 /*************************************/
 #ifndef WIN32
 XErrorHandler old_handler = 0;
@@ -1638,376 +1635,3 @@
   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-svn mailing list