From: Piotr S. <ps...@us...> - 2009-09-17 12:05:44
|
Update of /cvsroot/ayttm/ayttm/modules/importers In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv12682/modules/importers Modified Files: import_everybuddy.c import_gaim.c import_gnomeicu.c importicq.c importlicq.c Log Message: reformatted source code Index: import_everybuddy.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/importers/import_everybuddy.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- import_everybuddy.c 26 Aug 2009 16:25:56 -0000 1.14 +++ import_everybuddy.c 17 Sep 2009 12:04:58 -0000 1.15 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ - + #include "intl.h" #include <stdlib.h> @@ -37,63 +37,66 @@ #include "plugin_api.h" #include "messages.h" - /************************************************************************************* * Begin Module Code ************************************************************************************/ /* Module defines */ #ifndef USE_POSIX_DLOPEN - #define plugin_info import_everybuddy_LTX_plugin_info - #define plugin_init import_everybuddy_LTX_plugin_init - #define plugin_finish import_everybuddy_LTX_plugin_finish - #define module_version import_everybuddy_LTX_module_version +#define plugin_info import_everybuddy_LTX_plugin_info +#define plugin_init import_everybuddy_LTX_plugin_init +#define plugin_finish import_everybuddy_LTX_plugin_finish +#define module_version import_everybuddy_LTX_module_version #endif - /* Function Prototypes */ void import_eb_accounts(ebmCallbackData *data); int plugin_init(); int plugin_finish(); -static int ref_count=0; +static int ref_count = 0; /* Module Exports */ PLUGIN_INFO plugin_info = { - PLUGIN_IMPORTER, - "Everybuddy Settings", - "Imports your Everybuddy settings into Ayttm", + PLUGIN_IMPORTER, + "Everybuddy Settings", + "Imports your Everybuddy settings into Ayttm", "$Revision$", "$Date$", &ref_count, plugin_init, plugin_finish }; + /* End Module Exports */ -static void *buddy_list_tag=NULL; +static void *buddy_list_tag = NULL; -unsigned int module_version() {return CORE_VERSION;} +unsigned int module_version() +{ + return CORE_VERSION; +} int plugin_init() { - eb_debug(DBG_MOD,"EB Buddy List init\n"); - buddy_list_tag=eb_add_menu_item("Everybuddy Settings", EB_IMPORT_MENU, - import_eb_accounts, ebmIMPORTDATA, NULL); - if(!buddy_list_tag) - return(-1); - return(0); + eb_debug(DBG_MOD, "EB Buddy List init\n"); + buddy_list_tag = eb_add_menu_item("Everybuddy Settings", EB_IMPORT_MENU, + import_eb_accounts, ebmIMPORTDATA, NULL); + if (!buddy_list_tag) + return (-1); + return (0); } int plugin_finish() { int result; - result=eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); - if(result) { - g_warning("Unable to remove eb Buddy List menu item from menu!"); - return(-1); + result = eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); + if (result) { + g_warning + ("Unable to remove eb Buddy List menu item from menu!"); + return (-1); } - return(0); + return (0); } /************************************************************************************ @@ -112,47 +115,55 @@ static GtkWidget *label; static int eb_imp_window_open = 0; -static void ok_callback(GtkWidget * widget, gpointer data) { - +static void ok_callback(GtkWidget *widget, gpointer data) +{ + char buff[1024]; - int a=0,c=0,p=0,m=0; - + int a = 0, c = 0, p = 0, m = 0; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(accountsbutton))) { snprintf(buff, 1024, "%s/.everybuddy/accounts", getenv("HOME")); if (!load_accounts_from_file(buff)) { - ay_do_error(_("Import error"), _("Cannot import accounts.\n" + ay_do_error(_("Import error"), + _("Cannot import accounts.\n" "Check that ~/.everybuddy/accounts exists " "and is readable.")); } else { - a=1; + a = 1; } } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(contactsbutton))) { snprintf(buff, 1024, "%s/.everybuddy/contacts", getenv("HOME")); if (!load_contacts_from_file(buff)) { - ay_do_error(_("Import error"), _("Cannot import contacts.\n" + ay_do_error(_("Import error"), + _("Cannot import contacts.\n" "Check that ~/.everybuddy/contacts exists " "and is readable.")); } else - c=1; + c = 1; } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prefsbutton))) { /* prefs we want to save */ char saved[7][MAX_PREF_LEN]; FILE *in; - - strncpy(saved[0], cGetLocalPref("BuddyArriveFilename"), MAX_PREF_LEN); - strncpy(saved[1], cGetLocalPref("BuddyAwayFilename"), MAX_PREF_LEN); - strncpy(saved[2], cGetLocalPref("BuddyLeaveFilename"), MAX_PREF_LEN); + + strncpy(saved[0], cGetLocalPref("BuddyArriveFilename"), + MAX_PREF_LEN); + strncpy(saved[1], cGetLocalPref("BuddyAwayFilename"), + MAX_PREF_LEN); + strncpy(saved[2], cGetLocalPref("BuddyLeaveFilename"), + MAX_PREF_LEN); strncpy(saved[3], cGetLocalPref("SendFilename"), MAX_PREF_LEN); - strncpy(saved[4], cGetLocalPref("ReceiveFilename"), MAX_PREF_LEN); - strncpy(saved[5], cGetLocalPref("FirstMsgFilename"), MAX_PREF_LEN); + strncpy(saved[4], cGetLocalPref("ReceiveFilename"), + MAX_PREF_LEN); + strncpy(saved[5], cGetLocalPref("FirstMsgFilename"), + MAX_PREF_LEN); strncpy(saved[6], cGetLocalPref("modules_path"), MAX_PREF_LEN); snprintf(buff, 1024, "%s/.everybuddy/prefs", getenv("HOME")); in = fopen(buff, "r"); if (in) { - fclose (in); + fclose(in); ayttm_prefs_read_file(buff); cSetLocalPref("BuddyArriveFilename", saved[0]); @@ -164,56 +175,55 @@ cSetLocalPref("modules_path", saved[6]); ayttm_prefs_write(); - p=1; + p = 1; } else { - ay_do_error(_("Import error"), - _("Cannot import preferences.\n" + ay_do_error(_("Import error"), + _("Cannot import preferences.\n" "Check that ~/.everybuddy/preferences " - "exists and is readable.")); + "exists and is readable.")); } - + } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(awaybutton))) { FILE *in = NULL, *out = NULL; - snprintf(buff, 1024, "%s/.everybuddy/away_messages", getenv("HOME")); + snprintf(buff, 1024, "%s/.everybuddy/away_messages", + getenv("HOME")); in = fopen(buff, "r"); if (in) { snprintf(buff, 1024, "%saway_messages", config_dir); out = fopen(buff, "a"); if (!out) { ay_do_error(_("Import error"), - _("Cannot save away messages.\n" + _("Cannot save away messages.\n" "Check that ~/.ayttm/away_messages " "is writable.")); } else { while (fgets(buff, 1024, in) != NULL) fputs(buff, out); fclose(out); - m=1; + m = 1; } fclose(in); } else { - ay_do_error(_("Import error"), - _("Cannot import away messages.\n" + ay_do_error(_("Import error"), + _("Cannot import away messages.\n" "Check that ~/.everybuddy/away_messages " - "exists and is readable.")); + "exists and is readable.")); } } - + if (!a && !c && !p && !m) { return; } else { char message[1024]; snprintf(message, 1024, "Successfully imported %s%s%s%s%s%s%s." - "from Everybuddy.", - a?"accounts":"", - (a && (c||p||m))?", ":"", - c?"contacts":"", - (c && (p||m))?", ":"", - p?"preferences":"", - (p && m)?", ":"", - m?"away messages":"" - ); + "from Everybuddy.", + a ? "accounts" : "", + (a && (c || p || m)) ? ", " : "", + c ? "contacts" : "", + (c && (p || m)) ? ", " : "", + p ? "preferences" : "", + (p && m) ? ", " : "", m ? "away messages" : ""); ay_do_info(_("Import success"), message); } gtk_widget_destroy(window); @@ -221,58 +231,69 @@ set_menu_sensitivity(); } -static void cancel_callback(GtkWidget * widget, gpointer data) { +static void cancel_callback(GtkWidget *widget, gpointer data) +{ gtk_widget_destroy(window); } -static void destroy_callback(GtkWidget * widget, gpointer data) { +static void destroy_callback(GtkWidget *widget, gpointer data) +{ eb_imp_window_open = 0; } - void import_eb_accounts(ebmCallbackData *data) { if (!eb_imp_window_open) { eb_imp_window_open = 1; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE); - gtk_window_set_title(GTK_WINDOW(window), _("Import parameters")); + gtk_window_set_title(GTK_WINDOW(window), + _("Import parameters")); gtk_widget_realize(window); gtk_container_set_border_width(GTK_CONTAINER(window), 5); - + vbox = gtk_vbox_new(FALSE, 5); - + label = gtk_label_new(_("Select which parts of your everybuddy " "configuration to import.\n")); - - accountsbutton = gtk_check_button_new_with_label( - _("Import local accounts")); - contactsbutton = gtk_check_button_new_with_label( - _("Import contacts")); - prefsbutton = gtk_check_button_new_with_label( - _("Import preferences")); - awaybutton = gtk_check_button_new_with_label( - _("Import away messages")); - + + accountsbutton = + gtk_check_button_new_with_label(_ + ("Import local accounts")); + contactsbutton = + gtk_check_button_new_with_label(_("Import contacts")); + prefsbutton = + gtk_check_button_new_with_label(_ + ("Import preferences")); + awaybutton = + gtk_check_button_new_with_label(_ + ("Import away messages")); + okbutton = gtk_button_new_from_stock(GTK_STOCK_OK); cancelbutton = gtk_button_new_from_stock(GTK_STOCK_CANCEL); hbox = gtk_hbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox), okbutton, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(hbox), cancelbutton, FALSE, FALSE, 2); + gtk_box_pack_start(GTK_BOX(hbox), cancelbutton, FALSE, FALSE, + 2); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(vbox), accountsbutton, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(vbox), contactsbutton, FALSE, FALSE, 2); + gtk_box_pack_start(GTK_BOX(vbox), accountsbutton, FALSE, FALSE, + 2); + gtk_box_pack_start(GTK_BOX(vbox), contactsbutton, FALSE, FALSE, + 2); gtk_box_pack_start(GTK_BOX(vbox), prefsbutton, FALSE, FALSE, 2); gtk_box_pack_start(GTK_BOX(vbox), awaybutton, FALSE, FALSE, 2); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 2); - - gtk_container_add (GTK_CONTAINER(window), vbox); - g_signal_connect(okbutton, "clicked", G_CALLBACK(ok_callback), NULL); - g_signal_connect(cancelbutton, "clicked", G_CALLBACK(cancel_callback), NULL); - g_signal_connect(window, "destroy", G_CALLBACK(destroy_callback), NULL); - + + gtk_container_add(GTK_CONTAINER(window), vbox); + g_signal_connect(okbutton, "clicked", G_CALLBACK(ok_callback), + NULL); + g_signal_connect(cancelbutton, "clicked", + G_CALLBACK(cancel_callback), NULL); + g_signal_connect(window, "destroy", + G_CALLBACK(destroy_callback), NULL); + gtk_widget_show(vbox); gtk_widget_show(hbox); gtk_widget_show(accountsbutton); Index: import_gaim.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/importers/import_gaim.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- import_gaim.c 27 Jul 2009 16:42:03 -0000 1.11 +++ import_gaim.c 17 Sep 2009 12:04:58 -0000 1.12 @@ -38,62 +38,67 @@ #include "plugin_api.h" #include "messages.h" - /************************************************************************************* * Begin Module Code ************************************************************************************/ /* Module defines */ #ifndef USE_POSIX_DLOPEN - #define plugin_info import_gaim_LTX_plugin_info - #define plugin_init import_gaim_LTX_plugin_init - #define plugin_finish import_gaim_LTX_plugin_finish - #define module_version import_gaim_LTX_module_version +#define plugin_info import_gaim_LTX_plugin_info +#define plugin_init import_gaim_LTX_plugin_init +#define plugin_finish import_gaim_LTX_plugin_finish +#define module_version import_gaim_LTX_module_version #endif - /* Function Prototypes */ void import_gaim_accounts(ebmCallbackData *data); int plugin_init(); int plugin_finish(); -static int ref_count=0; +static int ref_count = 0; /* Module Exports */ PLUGIN_INFO plugin_info = { - PLUGIN_IMPORTER, - "Gaim Buddy List", - "Imports your Gaim buddy list into Ayttm", + PLUGIN_IMPORTER, + "Gaim Buddy List", + "Imports your Gaim buddy list into Ayttm", "$Revision$", "$Date$", &ref_count, plugin_init, plugin_finish }; + /* End Module Exports */ -static void *buddy_list_tag=NULL; +static void *buddy_list_tag = NULL; -unsigned int module_version() {return CORE_VERSION;} +unsigned int module_version() +{ + return CORE_VERSION; +} int plugin_init() { - eb_debug(DBG_MOD,"Gaim Buddy List init\n"); - buddy_list_tag=eb_add_menu_item("Gaim Buddy List", EB_IMPORT_MENU, import_gaim_accounts, ebmIMPORTDATA, NULL); - if(!buddy_list_tag) - return(-1); - return(0); + eb_debug(DBG_MOD, "Gaim Buddy List init\n"); + buddy_list_tag = + eb_add_menu_item("Gaim Buddy List", EB_IMPORT_MENU, + import_gaim_accounts, ebmIMPORTDATA, NULL); + if (!buddy_list_tag) + return (-1); + return (0); } int plugin_finish() { int result; - result=eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); - if(result) { - g_warning("Unable to remove Gaim Buddy List menu item from import menu!"); - return(-1); + result = eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); + if (result) { + g_warning + ("Unable to remove Gaim Buddy List menu item from import menu!"); + return (-1); } - return(0); + return (0); } /******************************************************************************* @@ -102,54 +107,55 @@ void import_gaim_accounts(ebmCallbackData *data) { - gchar buff[1024]; - gchar c[1024]; - gchar group[1024]; - gchar *fname = NULL; + gchar buff[1024]; + gchar c[1024]; + gchar group[1024]; + gchar *fname = NULL; gchar *handle = NULL; - FILE * fp; - - gint AIM_ID=-1; - g_snprintf(buff, 1024, "%s/gaim.buddy", getenv("HOME")); - if( !(fp = fopen(buff, "r")) ) { - g_snprintf(c, 1024, "Unable to import gaim accounts from %s: %s", buff, strerror(errno)); - ay_do_error( "Import Error", c ); - return; - } - AIM_ID=get_service_id("AIM"); - while(!feof(fp)) - { - fgets(c, 1024, fp); - g_strchomp(c); - if (*c == 'g') { - strncpy(group,c+2, 1024); - if(!find_grouplist_by_name(group)) - { - add_group(group); - } - } else if (*c == 'b') { - handle = c+2; - if (strchr(handle,':')) { - fname = strchr(handle,':') + 1; - *(strchr(handle,':')) = '\0'; + FILE *fp; + + gint AIM_ID = -1; + g_snprintf(buff, 1024, "%s/gaim.buddy", getenv("HOME")); + if (!(fp = fopen(buff, "r"))) { + g_snprintf(c, 1024, + "Unable to import gaim accounts from %s: %s", buff, + strerror(errno)); + ay_do_error("Import Error", c); + return; + } + AIM_ID = get_service_id("AIM"); + while (!feof(fp)) { + fgets(c, 1024, fp); + g_strchomp(c); + if (*c == 'g') { + strncpy(group, c + 2, 1024); + if (!find_grouplist_by_name(group)) { + add_group(group); + } + } else if (*c == 'b') { + handle = c + 2; + if (strchr(handle, ':')) { + fname = strchr(handle, ':') + 1; + *(strchr(handle, ':')) = '\0'; + } else + fname = handle; + + if (!find_account_by_handle(handle, AIM_ID)) { + eb_account *ea = + eb_services[AIM_ID].sc-> + new_account(NULL, handle); + add_account(fname, ea); + move_contact(group, + find_contact_by_nick(fname)); + } + } else if (*c == 'p') { + /*no need */ + } else if (*c == 'd') { + /*no need */ + } else if (*c == 'm') { + /*no need */ } - else - fname = handle; - - if(!find_account_by_handle(handle, AIM_ID)) - { - eb_account * ea = eb_services[AIM_ID].sc->new_account(NULL,handle); - add_account( fname, ea ); - move_contact (group, find_contact_by_nick(fname)); - } - } else if (*c == 'p') { - /*no need*/ - } else if (*c == 'd') { - /*no need*/ - } else if (*c == 'm') { - /*no need*/ - } - } - fclose(fp); - ay_do_info( "Import", "Successfully imported gaim BuddyList" ); + } + fclose(fp); + ay_do_info("Import", "Successfully imported gaim BuddyList"); } Index: import_gnomeicu.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/importers/import_gnomeicu.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- import_gnomeicu.c 27 Jul 2009 16:42:03 -0000 1.9 +++ import_gnomeicu.c 17 Sep 2009 12:04:58 -0000 1.10 @@ -38,61 +38,67 @@ #include "plugin_api.h" #include "messages.h" - /******************************************************************************* * Begin Module Code ******************************************************************************/ /* Module defines */ #ifndef USE_POSIX_DLOPEN - #define plugin_info import_gnomeicu_LTX_plugin_info - #define plugin_init import_gnomeicu_LTX_plugin_init - #define plugin_finish import_gnomeicu_LTX_plugin_finish - #define module_version import_gnomeicu_LTX_module_version +#define plugin_info import_gnomeicu_LTX_plugin_info +#define plugin_init import_gnomeicu_LTX_plugin_init +#define plugin_finish import_gnomeicu_LTX_plugin_finish +#define module_version import_gnomeicu_LTX_module_version #endif - /* Function Prototypes */ void import_gnomeicu_accounts(ebmCallbackData *data); int plugin_init(); int plugin_finish(); -static int ref_count=0; +static int ref_count = 0; /* Module Exports */ PLUGIN_INFO plugin_info = { - PLUGIN_IMPORTER, - "GnomeICU Contact List", - "Imports your GnomeICU contact list into Ayttm", + PLUGIN_IMPORTER, + "GnomeICU Contact List", + "Imports your GnomeICU contact list into Ayttm", "$Revision$", "$Date$", &ref_count, plugin_init, plugin_finish }; + /* End Module Exports */ -static void *buddy_list_tag=NULL; +static void *buddy_list_tag = NULL; + +unsigned int module_version() +{ + return CORE_VERSION; +} -unsigned int module_version() {return CORE_VERSION;} int plugin_init() { eb_debug(DBG_MOD, "GnomeICU Contact List init\n"); - buddy_list_tag=eb_add_menu_item("GnomeICU Contact List", EB_IMPORT_MENU, import_gnomeicu_accounts, ebmIMPORTDATA, NULL); - if(!buddy_list_tag) - return(-1); - return(0); + buddy_list_tag = + eb_add_menu_item("GnomeICU Contact List", EB_IMPORT_MENU, + import_gnomeicu_accounts, ebmIMPORTDATA, NULL); + if (!buddy_list_tag) + return (-1); + return (0); } int plugin_finish() { int result; - result=eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); - if(result) { - g_warning("Unable to remove GnomeICU Contact List menu item from import menu!"); - return(-1); + result = eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); + if (result) { + g_warning + ("Unable to remove GnomeICU Contact List menu item from import menu!"); + return (-1); } - return(0); + return (0); } /******************************************************************************* @@ -101,63 +107,61 @@ void import_gnomeicu_accounts(ebmCallbackData *data) { - gchar buff[1024]; - gchar c[1024]; - gchar ** tokens = NULL; - gchar * uin = NULL, * nick = NULL; - gint ICQ_ID=-1; - FILE * fp; - - g_snprintf(buff, 1024, "%s/.gnome/GnomeICU", getenv("HOME")); - if( !(fp = fopen(buff, "r")) ) { - g_snprintf(c, 1024, "Unable to import GnomeICU accounts from %s: %s", buff, strerror(errno)); - ay_do_error( "Import Error", c ); - return; - } - ICQ_ID=get_service_id("ICQ"); - while(!feof(fp)) - { + gchar buff[1024]; + gchar c[1024]; + gchar **tokens = NULL; + gchar *uin = NULL, *nick = NULL; + gint ICQ_ID = -1; + FILE *fp; + + g_snprintf(buff, 1024, "%s/.gnome/GnomeICU", getenv("HOME")); + if (!(fp = fopen(buff, "r"))) { + g_snprintf(c, 1024, + "Unable to import GnomeICU accounts from %s: %s", buff, + strerror(errno)); + ay_do_error("Import Error", c); + return; + } + ICQ_ID = get_service_id("ICQ"); + while (!feof(fp)) { fgets(c, 1024, fp); g_strchomp(c); - if(!g_strncasecmp( c, "[NewContacts]", strlen("[NewContacts]")+1)) + if (!g_strncasecmp(c, "[NewContacts]", + strlen("[NewContacts]") + 1)) break; } - if(feof(fp)) - { + if (feof(fp)) { fclose(fp); - ay_do_warning( "Import Warning", "No GnomeICU contacts added" ); + ay_do_warning("Import Warning", "No GnomeICU contacts added"); return; } - if(!find_grouplist_by_name("GnomeICU Users")) + if (!find_grouplist_by_name("GnomeICU Users")) add_group("GnomeICU Users"); - while(!feof(fp)) - { - fgets(c, 1024, fp); - if(feof(fp)) + while (!feof(fp)) { + fgets(c, 1024, fp); + if (feof(fp)) break; - g_strchomp(c); + g_strchomp(c); - tokens = g_strsplit(c,"=",2); - uin = *tokens; - nick = *(tokens+1); - - if(find_account_by_handle(uin, ICQ_ID)) - { - continue; - } - if(!find_contact_by_nick(nick)) - { - add_new_contact( "GnomeICU Users", nick, ICQ_ID ); - } - if(!find_account_by_handle(uin, ICQ_ID)) - { - eb_account * ea = eb_services[ICQ_ID].sc->new_account(NULL,uin); - ea->service_id = ICQ_ID; - add_account( nick, ea ); + tokens = g_strsplit(c, "=", 2); + uin = *tokens; + nick = *(tokens + 1); + + if (find_account_by_handle(uin, ICQ_ID)) { + continue; + } + if (!find_contact_by_nick(nick)) { + add_new_contact("GnomeICU Users", nick, ICQ_ID); + } + if (!find_account_by_handle(uin, ICQ_ID)) { + eb_account *ea = + eb_services[ICQ_ID].sc->new_account(NULL, uin); + ea->service_id = ICQ_ID; + add_account(nick, ea); // RUN_SERVICE(ea)->add_user(ea); - } - g_strfreev (tokens); - } + } + g_strfreev(tokens); + } fclose(fp); - ay_do_info( "Import", "Successfully GnomeICU contacts list" ); + ay_do_info("Import", "Successfully GnomeICU contacts list"); } Index: importicq.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/importers/importicq.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- importicq.c 27 Jul 2009 16:42:03 -0000 1.9 +++ importicq.c 17 Sep 2009 12:04:58 -0000 1.10 @@ -21,7 +21,7 @@ #ifdef HAVE_CONFIG_H # include <config.h> #endif -#include <fcntl.h> +#include <fcntl.h> #include <gtk/gtk.h> #include <string.h> #ifdef __MINGW32__ @@ -41,23 +41,25 @@ /* Module defines */ #ifndef USE_POSIX_DLOPEN - #define plugin_info importicq_LTX_plugin_info - #define module_version importicq_LTX_module_version +#define plugin_info importicq_LTX_plugin_info +#define module_version importicq_LTX_module_version #endif - /* Function Prototypes */ static int plugin_init(); static int plugin_finish(); -unsigned int module_version() {return CORE_VERSION;} +unsigned int module_version() +{ + return CORE_VERSION; +} -static int ref_count=0; +static int ref_count = 0; /* Module Exports */ PLUGIN_INFO plugin_info = { - PLUGIN_IMPORTER, - "ICQ99 Contact List", - "Imports your ICQ99 contact list into Ayttm", + PLUGIN_IMPORTER, + "ICQ99 Contact List", + "Imports your ICQ99 contact list into Ayttm", "$Revision$", "$Date$", &ref_count, @@ -94,7 +96,7 @@ #define USERS_DATA 2000 #define LAST_FOLDER 998 -#define IGNORE_FOLDER 999 /*own definition */ +#define IGNORE_FOLDER 999 /*own definition */ #define FIRST_IDX 0 #define NEXT_IDX 1 @@ -108,29 +110,32 @@ guint32 uin; }; -static void import_icq99_contacts(ebmCallbackData * data); +static void import_icq99_contacts(ebmCallbackData *data); -static void *buddy_list_tag=NULL; +static void *buddy_list_tag = NULL; static int plugin_init() { - eb_debug(DBG_MOD,"ICQ99 Contact List init\n"); - buddy_list_tag=eb_add_menu_item("ICQ99 Contact List", EB_IMPORT_MENU, import_icq99_contacts, ebmIMPORTDATA, NULL); - if(!buddy_list_tag) - return(-1); - return(0); + eb_debug(DBG_MOD, "ICQ99 Contact List init\n"); + buddy_list_tag = + eb_add_menu_item("ICQ99 Contact List", EB_IMPORT_MENU, + import_icq99_contacts, ebmIMPORTDATA, NULL); + if (!buddy_list_tag) + return (-1); + return (0); } static int plugin_finish() { int result; - result=eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); - if(result) { - g_warning("Unable to remove ICQ99 Contact List menu item from import menu!"); - return(-1); + result = eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); + if (result) { + g_warning + ("Unable to remove ICQ99 Contact List menu item from import menu!"); + return (-1); } - return(0); + return (0); } /******************************************************************************* @@ -139,276 +144,273 @@ static int wrong_type(struct idxEntry *entry, long type) { - if(type==USERS_DATA) - { - if(entry->dat_number > type) - return 0; - } - else - { - if(entry->dat_number == type) - return 0; - } - return 1; + if (type == USERS_DATA) { + if (entry->dat_number > type) + return 0; + } else { + if (entry->dat_number == type) + return 0; + } + return 1; } -gint find_idx_entry(int handle, struct idxEntry * entry,guint32 type, gint mode) +gint find_idx_entry(int handle, struct idxEntry *entry, guint32 type, gint mode) { - if(mode==FIRST_IDX) - lseek(handle,225,SEEK_SET); - else - { - if(entry->next !=-1) - lseek(handle,entry->next,SEEK_SET); - entry->dat_number=0; - } - while(wrong_type(entry, type) && (entry->next != -1)) - { - read(handle, entry, 20); - while(entry->status != -2 && (entry->next != -1)) - { - read(handle, entry, 20); - if(entry->next !=-1) - lseek(handle,entry->next,SEEK_SET); + if (mode == FIRST_IDX) + lseek(handle, 225, SEEK_SET); + else { + if (entry->next != -1) + lseek(handle, entry->next, SEEK_SET); + entry->dat_number = 0; + } + while (wrong_type(entry, type) && (entry->next != -1)) { + read(handle, entry, 20); + while (entry->status != -2 && (entry->next != -1)) { + read(handle, entry, 20); + if (entry->next != -1) + lseek(handle, entry->next, SEEK_SET); } - if(entry->next !=-1) - lseek(handle,entry->next,SEEK_SET); + if (entry->next != -1) + lseek(handle, entry->next, SEEK_SET); } - if(!wrong_type(entry,type) && (entry->next == -1)) + if (!wrong_type(entry, type) && (entry->next == -1)) return -1; else return 1; } + void pass_strings(int handle, guint32 number, gint loop_pre_inc, gint post_inc) { - guint16 length, i; - for(i=0;i<number;i++) - { - lseek(handle,loop_pre_inc, SEEK_CUR); - read(handle, &length, 2); /*get the length of the string*/ - lseek(handle,length, SEEK_CUR); + guint16 length, i; + for (i = 0; i < number; i++) { + lseek(handle, loop_pre_inc, SEEK_CUR); + read(handle, &length, 2); /*get the length of the string */ + lseek(handle, length, SEEK_CUR); } - lseek(handle,post_inc, SEEK_CUR); + lseek(handle, post_inc, SEEK_CUR); } -void parse_my_details(int dat, struct my_details * my_details) + +void parse_my_details(int dat, struct my_details *my_details) { guint8 property_value; guint32 length; - lseek(dat,0x2a,SEEK_CUR); /*step to number of vaw entries 47*/ - read(dat,&length,4); - pass_strings(dat,length,10,40); - read(dat,&length,4); - for(;length>0;length--) - { - pass_strings(dat,1,0,0); - read(dat,&property_value,1); - switch (property_value) - { - case 'e': - lseek(dat,1,SEEK_CUR); - break; - case 'f': - case 'k': - lseek(dat,2,SEEK_CUR); - break; - case 'h': - case 'i': - lseek(dat,4,SEEK_CUR); - break; - default: - eb_debug(DBG_MOD,"oh-oh....we haven't seen this one before!\n"); - break; + lseek(dat, 0x2a, SEEK_CUR); /*step to number of vaw entries 47 */ + read(dat, &length, 4); + pass_strings(dat, length, 10, 40); + read(dat, &length, 4); + for (; length > 0; length--) { + pass_strings(dat, 1, 0, 0); + read(dat, &property_value, 1); + switch (property_value) { + case 'e': + lseek(dat, 1, SEEK_CUR); + break; + case 'f': + case 'k': + lseek(dat, 2, SEEK_CUR); + break; + case 'h': + case 'i': + lseek(dat, 4, SEEK_CUR); + break; + default: + eb_debug(DBG_MOD, + "oh-oh....we haven't seen this one before!\n"); + break; } } - read(dat,&length,2); - if(length==0) - my_details->user_name[0]='\0'; - read(dat,&my_details->user_name,length); - read(dat,&length,2); - if(length==0) - my_details->nick_name[0]='\0'; - read(dat,&my_details->nick_name,length); - pass_strings(dat,3,0,0); /*step over, first name, last name and primary e-mail*/ - read(dat,&my_details->uin,4); - lseek(dat,15,SEEK_CUR); /*gender, country and age*/ - pass_strings(dat,6,0,12); /*step over city, state, add. text, homepage, home phone, notes, zip code*/ - read(dat,&length,4); /*number of phonebook entries*/ - for(;length>0;length--) - { - pass_strings(dat,4,0,2); - pass_strings(dat,1,0,0); - } - lseek(dat,14,SEEK_CUR); /*unused and timestamp of my details*/ - pass_strings(dat,2,0,18); /*secondary and old e-mail, birth data, languages spoken*/ - pass_strings(dat,3,0,4); /*home address, fax and cellular*/ - pass_strings(dat,1,0,5); /*company, occupation*/ - pass_strings(dat,5,0,8); /*company position name and address, company zip and country*/ - pass_strings(dat,4,0,2); /*work phone fax and URL and past bkg*/ - pass_strings(dat,1,0,2); /*past bkg 2*/ - pass_strings(dat,1,0,2); /*past bkg 3*/ - pass_strings(dat,1,0,2); /*Affiliation*/ - pass_strings(dat,1,0,2); /*Affiliation 2*/ - pass_strings(dat,1,0,22); /*Affiliation 3*/ - pass_strings(dat,1,0,2); /*interest keyword*/ - pass_strings(dat,1,0,2); /*interest keyword 2*/ - pass_strings(dat,1,0,2); /*interest keyword 3*/ - pass_strings(dat,1,0,42); /*interest keyword 4*/ - -} -static gint icq_get_groups(int idx, int dat,struct groups group_array[], struct my_details * my_details) -{ - struct idxEntry entry={0,0,0,0,0}; - guint32 length=0; - guint16 i, group_length; - - if(!find_idx_entry(idx,&entry, MY_DETAILS,FIRST_IDX)) - { - eb_debug(DBG_MOD,"Can't find my details\n"); + read(dat, &length, 2); + if (length == 0) + my_details->user_name[0] = '\0'; + read(dat, &my_details->user_name, length); + read(dat, &length, 2); + if (length == 0) + my_details->nick_name[0] = '\0'; + read(dat, &my_details->nick_name, length); + pass_strings(dat, 3, 0, 0); /*step over, first name, last name and primary e-mail */ + read(dat, &my_details->uin, 4); + lseek(dat, 15, SEEK_CUR); /*gender, country and age */ + pass_strings(dat, 6, 0, 12); /*step over city, state, add. text, homepage, home phone, notes, zip code */ + read(dat, &length, 4); /*number of phonebook entries */ + for (; length > 0; length--) { + pass_strings(dat, 4, 0, 2); + pass_strings(dat, 1, 0, 0); + } + lseek(dat, 14, SEEK_CUR); /*unused and timestamp of my details */ + pass_strings(dat, 2, 0, 18); /*secondary and old e-mail, birth data, languages spoken */ + pass_strings(dat, 3, 0, 4); /*home address, fax and cellular */ + pass_strings(dat, 1, 0, 5); /*company, occupation */ + pass_strings(dat, 5, 0, 8); /*company position name and address, company zip and country */ + pass_strings(dat, 4, 0, 2); /*work phone fax and URL and past bkg */ + pass_strings(dat, 1, 0, 2); /*past bkg 2 */ + pass_strings(dat, 1, 0, 2); /*past bkg 3 */ + pass_strings(dat, 1, 0, 2); /*Affiliation */ + pass_strings(dat, 1, 0, 2); /*Affiliation 2 */ + pass_strings(dat, 1, 0, 22); /*Affiliation 3 */ + pass_strings(dat, 1, 0, 2); /*interest keyword */ + pass_strings(dat, 1, 0, 2); /*interest keyword 2 */ + pass_strings(dat, 1, 0, 2); /*interest keyword 3 */ + pass_strings(dat, 1, 0, 42); /*interest keyword 4 */ + +} + +static gint icq_get_groups(int idx, int dat, struct groups group_array[], + struct my_details *my_details) +{ + struct idxEntry entry = { 0, 0, 0, 0, 0 }; + guint32 length = 0; + guint16 i, group_length; + + if (!find_idx_entry(idx, &entry, MY_DETAILS, FIRST_IDX)) { + eb_debug(DBG_MOD, "Can't find my details\n"); return 0; } - lseek(dat,entry.dat_offset,SEEK_SET); - lseek(dat,12,SEEK_CUR); - read(dat,&length,1); - if(length!=0xe4) + lseek(dat, entry.dat_offset, SEEK_SET); + lseek(dat, 12, SEEK_CUR); + read(dat, &length, 1); + if (length != 0xe4) return 0; - - lseek(dat,29,SEEK_CUR); - parse_my_details(dat,my_details); - pass_strings(dat,1,0,18); /*PASSWORD!*/ - pass_strings(dat,3,0,21); /*???*/ - read(dat,&length,4); - for(i=0;length>0;length--) - { - read(dat,&group_array[i].number,4); - read(dat,&group_length,2); - read(dat,group_array[i].name,group_length); - lseek(dat,6,SEEK_CUR); /*unused and open/closed flag*/ + + lseek(dat, 29, SEEK_CUR); + parse_my_details(dat, my_details); + pass_strings(dat, 1, 0, 18); /*PASSWORD! */ + pass_strings(dat, 3, 0, 21); /*??? */ + read(dat, &length, 4); + for (i = 0; length > 0; length--) { + read(dat, &group_array[i].number, 4); + read(dat, &group_length, 2); + read(dat, group_array[i].name, group_length); + lseek(dat, 6, SEEK_CUR); /*unused and open/closed flag */ i++; } - group_array[i].number=IGNORE_FOLDER; - memcpy(group_array[i++].name,"Ignore\0",sizeof("Ignore\0")); - group_array[i].number=LAST_FOLDER; - group_array[i++].name[0]=0; - return 1; + group_array[i].number = IGNORE_FOLDER; + memcpy(group_array[i++].name, "Ignore\0", sizeof("Ignore\0")); + group_array[i].number = LAST_FOLDER; + group_array[i++].name[0] = 0; + return 1; } -char * match_group(struct groups groupies[], struct my_details * my_details) +char *match_group(struct groups groupies[], struct my_details *my_details) { - gint i=0; - while((groupies[i].number!=LAST_FOLDER) && (groupies[i].number!=my_details->folder)) + gint i = 0; + while ((groupies[i].number != LAST_FOLDER) + && (groupies[i].number != my_details->folder)) i++; return groupies[i].name; } -guint32 get_contact(int idx, int dat,struct groups groups[], struct my_details * my_details, struct idxEntry *entry) +guint32 get_contact(int idx, int dat, struct groups groups[], + struct my_details *my_details, struct idxEntry *entry) { - gchar* group_name; - guint8 type,i=0; - guint32 stored, folder, magic; - - if(my_details->uin==0) - find_idx_entry(idx,entry, USERS_DATA, FIRST_IDX); + gchar *group_name; + guint8 type, i = 0; + guint32 stored, folder, magic; + + if (my_details->uin == 0) + find_idx_entry(idx, entry, USERS_DATA, FIRST_IDX); else - find_idx_entry(idx,entry, USERS_DATA, NEXT_IDX); - while(entry->next!=-1) - { - lseek(dat,entry->dat_offset,SEEK_SET); - lseek(dat,4,SEEK_CUR); - read(dat,&stored,4); - if((stored==1) || (stored==2)) - { - lseek(dat,4,SEEK_CUR); - read(dat,&type,1); - if(type==0xe5) - { - lseek(dat,21,SEEK_CUR); - read(dat,&magic,4); /*status flag, 5==deleted???*/ - if((magic==2) || (magic==3) || (magic==12)) - { - read(dat,&folder,4); - my_details->folder=((stored==1)?folder:IGNORE_FOLDER); - parse_my_details(dat,my_details); - while((groups[i].number!=LAST_FOLDER) && (groups[i].number!=my_details->folder)) { + find_idx_entry(idx, entry, USERS_DATA, NEXT_IDX); + while (entry->next != -1) { + lseek(dat, entry->dat_offset, SEEK_SET); + lseek(dat, 4, SEEK_CUR); + read(dat, &stored, 4); + if ((stored == 1) || (stored == 2)) { + lseek(dat, 4, SEEK_CUR); + read(dat, &type, 1); + if (type == 0xe5) { + lseek(dat, 21, SEEK_CUR); + read(dat, &magic, 4); /*status flag, 5==deleted??? */ + if ((magic == 2) || (magic == 3) + || (magic == 12)) { + read(dat, &folder, 4); + my_details->folder = + ((stored == + 1) ? folder : + IGNORE_FOLDER); + parse_my_details(dat, my_details); + while ((groups[i].number != LAST_FOLDER) + && (groups[i].number != + my_details->folder)) { i++; } - - group_name=groups[i].name; - i=0; - while(group_name!=0 && i<30) { - my_details->group[i++]=*group_name++; + + group_name = groups[i].name; + i = 0; + while (group_name != 0 && i < 30) { + my_details->group[i++] = + *group_name++; } - my_details->group[i++]=0; + my_details->group[i++] = 0; return 1; - } + } } } - find_idx_entry(idx,entry, USERS_DATA,NEXT_IDX); + find_idx_entry(idx, entry, USERS_DATA, NEXT_IDX); } return entry->next; -} - +} -void import_icq99_ok( GtkFileChooser *fs ) +void import_icq99_ok(GtkFileChooser *fs) { - char * selected, *fileext, uin[11]; - gint dat,idx; + char *selected, *fileext, uin[11]; + gint dat, idx; struct groups *groups_ptr; - struct my_details contact; - struct idxEntry entry={0,0,0,0,0}; - eb_account * ea; - gint ICQ_ID=-1; - - ICQ_ID=get_service_id("ICQ"); + struct my_details contact; + struct idxEntry entry = { 0, 0, 0, 0, 0 }; + eb_account *ea; + gint ICQ_ID = -1; + + ICQ_ID = get_service_id("ICQ"); // Is there an ICQ service loaded? - if(ICQ_ID < 0) { + if (ICQ_ID < 0) { return; } - selected=(char *)gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fs)); - - fileext=strrchr(selected,'.'); - if(!fileext || strlen(fileext) !=3) + selected = (char *)gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)); + + fileext = strrchr(selected, '.'); + if (!fileext || strlen(fileext) != 3) return; - memcpy(fileext,".idx",4); - if( (idx = open(selected, O_RDONLY)) == -1 ) + memcpy(fileext, ".idx", 4); + if ((idx = open(selected, O_RDONLY)) == -1) return; - memcpy(fileext,".dat",4); - if( (dat = open(selected, O_RDONLY)) == -1 ) + memcpy(fileext, ".dat", 4); + if ((dat = open(selected, O_RDONLY)) == -1) return; - groups_ptr=g_malloc(sizeof(groups)*50); + groups_ptr = g_malloc(sizeof(groups) * 50); icq_get_groups(idx, dat, groups_ptr, &contact); - contact.uin=0; - while(get_contact(idx, dat, groups_ptr, &contact, &entry)!=-1) - { - g_snprintf(uin,11,"%i",contact.uin); - if(!find_grouplist_by_name(contact.group)) + contact.uin = 0; + while (get_contact(idx, dat, groups_ptr, &contact, &entry) != -1) { + g_snprintf(uin, 11, "%i", contact.uin); + if (!find_grouplist_by_name(contact.group)) add_group(contact.group); - if(find_account_by_handle(uin, ICQ_ID)) + if (find_account_by_handle(uin, ICQ_ID)) continue; - if((!find_contact_by_nick(contact.nick_name)) && (!find_contact_by_nick(contact.user_name))) - { - if(contact.nick_name[0]!=0) - add_new_contact(contact.group, contact.nick_name, ICQ_ID ); - else - { - if(contact.user_name[0]==0) - memcpy(contact.user_name,"NoName",7); - add_new_contact(contact.group, contact.user_name, ICQ_ID ); + if ((!find_contact_by_nick(contact.nick_name)) + && (!find_contact_by_nick(contact.user_name))) { + if (contact.nick_name[0] != 0) + add_new_contact(contact.group, + contact.nick_name, ICQ_ID); + else { + if (contact.user_name[0] == 0) + memcpy(contact.user_name, "NoName", 7); + add_new_contact(contact.group, + contact.user_name, ICQ_ID); } } - ea = eb_services[ICQ_ID].sc->new_account(NULL,uin); - - if(find_contact_by_nick(contact.user_name)) - add_account( contact.user_name, ea ); + ea = eb_services[ICQ_ID].sc->new_account(NULL, uin); + + if (find_contact_by_nick(contact.user_name)) + add_account(contact.user_name, ea); else - add_account( contact.nick_name, ea ); - + add_account(contact.nick_name, ea); + // RUN_SERVICE(ea)->add_user(ea); } - update_contact_list (); + update_contact_list(); write_contact_list(); g_free(groups_ptr); close(idx); @@ -417,19 +419,17 @@ void import_icq99_contacts(ebmCallbackData *data) { - GtkWidget *filew; + GtkWidget *filew; - filew = gtk_file_chooser_dialog_new ("ICQ99 IDX file to import", - NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - if(gtk_dialog_run(GTK_DIALOG(filew)) == GTK_RESPONSE_ACCEPT) { - import_icq99_ok(GTK_FILE_CHOOSER(filew)); - } + filew = gtk_file_chooser_dialog_new("ICQ99 IDX file to import", + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - gtk_widget_destroy(filew); -} + if (gtk_dialog_run(GTK_DIALOG(filew)) == GTK_RESPONSE_ACCEPT) { + import_icq99_ok(GTK_FILE_CHOOSER(filew)); + } + gtk_widget_destroy(filew); +} Index: importlicq.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/importers/importlicq.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- importlicq.c 27 Jul 2009 16:42:03 -0000 1.8 +++ importlicq.c 17 Sep 2009 12:04:58 -0000 1.9 @@ -38,61 +38,65 @@ #include "service.h" #include "messages.h" - /******************************************************************************* * Begin Module Code ******************************************************************************/ /* Module defines */ #ifndef USE_POSIX_DLOPEN - #define plugin_info importlicq_LTX_plugin_info - #define module_version importlicq_LTX_module_version +#define plugin_info importlicq_LTX_plugin_info +#define module_version importlicq_LTX_module_version #endif - /* Function Prototypes */ void import_licq_accounts(ebmCallbackData *data); static int plugin_init(); static int plugin_finish(); -unsigned int module_version() {return CORE_VERSION;} - +unsigned int module_version() +{ + return CORE_VERSION; +} -static int ref_count=0; +static int ref_count = 0; /* Module Exports */ PLUGIN_INFO plugin_info = { - PLUGIN_IMPORTER, - "Licq Contact List", - "Imports your Licq contact list into Ayttm", + PLUGIN_IMPORTER, + "Licq Contact List", + "Imports your Licq contact list into Ayttm", "$Revision$", "$Date$", &ref_count, plugin_init, plugin_finish }; + /* End Module Exports */ -static void *buddy_list_tag=NULL; +static void *buddy_list_tag = NULL; static int plugin_init() { - eb_debug(DBG_MOD,"Licq Contact List init\n"); - buddy_list_tag=eb_add_menu_item("Licq Contact List", EB_IMPORT_MENU, import_licq_accounts, ebmIMPORTDATA, NULL); - if(!buddy_list_tag) - return(-1); - return(0); + eb_debug(DBG_MOD, "Licq Contact List init\n"); + buddy_list_tag = + eb_add_menu_item("Licq Contact List", EB_IMPORT_MENU, + import_licq_accounts, ebmIMPORTDATA, NULL); + if (!buddy_list_tag) + return (-1); + return (0); } static int plugin_finish() { int result; - result=eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); - if(result) { - g_warning("Unable to remove Licq Contact List menu item from import menu!"); - return(-1); + result = eb_remove_menu_item(EB_IMPORT_MENU, buddy_list_tag); + if (result) { + g_warning + ("Unable to remove Licq Contact List menu item from import menu!"); + return (-1); } - return(0); + return (0); } /******************************************************************************* @@ -100,144 +104,140 @@ ******************************************************************************/ /* Removes the spaces surrounding a token */ -char* remove_spaces(char* token) +char *remove_spaces(char *token) { - g_strchomp(token); /* Remove spaces at the end */ - while (*token == ' ') token++; /* Remove spaces at the beginning */ - return token; + g_strchomp(token); /* Remove spaces at the end */ + while (*token == ' ') + token++; /* Remove spaces at the beginning */ + return token; } /* Gets your nickname for an licq buddy */ -char* get_licq_nick(const char* uin, int licq_version) +char *get_licq_nick(const char *uin, int licq_version) { - gchar buff[1024]; - static gchar c[1024]; - FILE *fp; - char *token, *nick; - - g_snprintf(buff, 1024, "%s/.licq/%s/%s.uin", getenv("HOME"), - (licq_version < 7 ? "conf" : "users"), uin); - if (!(fp = fopen(buff, "r"))) - return NULL; - - while (!feof(fp)) - { - fgets(c, 1024, fp); - token = remove_spaces(strtok(c, "=")); - if (g_strcasecmp(token, "Alias")) - continue; - - nick = remove_spaces(strtok(NULL, "=")); - fclose(fp); - return nick; - } - fclose(fp); - return NULL; + gchar buff[1024]; + static gchar c[1024]; + FILE *fp; + char *token, *nick; + + g_snprintf(buff, 1024, "%s/.licq/%s/%s.uin", getenv("HOME"), + (licq_version < 7 ? "conf" : "users"), uin); + if (!(fp = fopen(buff, "r"))) + return NULL; + + while (!feof(fp)) { + fgets(c, 1024, fp); + token = remove_spaces(strtok(c, "=")); + if (g_strcasecmp(token, "Alias")) + continue; + + nick = remove_spaces(strtok(NULL, "=")); + fclose(fp); + return nick; + } + fclose(fp); + return NULL; } - /* Imports licq accounts * Supports newer and older contact list formats (0.7x and 0.6x) */ void import_licq_accounts(ebmCallbackData *data) { - gchar group_name[] = "Licq Users"; - int num_users; - int unused_num; - int licq_version; - int ICQ_ID=-1; - - gchar c[1024], msg[1024]; - char *nick, *uin, *token; - - FILE *fp; - - ICQ_ID=get_service_id("ICQ"); - - g_snprintf(c, 1024, "%s/.licq/users.conf", getenv("HOME")); - if ((fp = fopen(c, "r"))) - licq_version = 7; - else - { - g_snprintf(c, 1024, "%s/.licq/conf/users.conf", getenv("HOME")); - if (!(fp = fopen(c, "r"))) { - g_snprintf(msg, 1024, "Unable to import licq accounts from neither %s/.licq/users.conf, nor %s\n", getenv("HOME"), c); - ay_do_error( "Import Error", msg ); - return; + gchar group_name[] = "Licq Users"; + int num_users; + int unused_num; + int licq_version; + int ICQ_ID = -1; + + gchar c[1024], msg[1024]; + char *nick, *uin, *token; + + FILE *fp; + + ICQ_ID = get_service_id("ICQ"); + + g_snprintf(c, 1024, "%s/.licq/users.conf", getenv("HOME")); + if ((fp = fopen(c, "r"))) + licq_version = 7; + else { + g_snprintf(c, 1024, "%s/.licq/conf/users.conf", getenv("HOME")); + if (!(fp = fopen(c, "r"))) { + g_snprintf(msg, 1024, + "Unable to import licq accounts from neither %s/.licq/users.conf, nor %s\n", + getenv("HOME"), c); + ay_do_error("Import Error", msg); + return; } - licq_version = 6; - } + licq_version = 6; + } + + while (!feof(fp)) { + fgets(c, 1024, fp); + token = remove_spaces(c); + if (!g_strcasecmp(token, "[users]")) + break; + } + if (feof(fp)) { + fclose(fp); + ay_do_warning("Import Warning", + "No users found in licq file to import"); + return; + } - while(!feof(fp)) - { - fgets(c, 1024, fp); - token = remove_spaces(c); - if(!g_strcasecmp(token, "[users]")) - break; - } - if(feof(fp)) - { - fclose(fp); - ay_do_warning( "Import Warning", "No users found in licq file to import" ); - return; - } - - while (!feof(fp)) - { - fgets(c, 1024, fp); - token = remove_spaces(strtok(c, "=")); - if (!g_strncasecmp(token, "NumOfUsers", strlen("NumOfUsers") + 1)) - break; - } - if (feof(fp)) - { - fclose(fp); - ay_do_warning( "Import Warning", "No users found in licq file to import" ); - return; - } - - token = strtok(NULL, "="); - num_users = atoi(token); - if (num_users < 1) - { - fclose(fp); - ay_do_warning( "Import Warning", "No users found in licq file to import" ); - return; - } - - if(!find_grouplist_by_name(group_name)) - add_group(group_name); - - while(!feof(fp)) - { - fgets(c, 1024, fp); - if(feof(fp)) - break; - token = strtok(c, "="); - if (sscanf(token, "User%d", &unused_num) <= 0) - continue; - - uin = remove_spaces(strtok(NULL, "=")); - nick = get_licq_nick(uin, licq_version); - if (!nick) - nick = uin; - - if(find_account_by_handle(uin, ICQ_ID)) - { - continue; - } - if(!find_contact_by_nick(nick)) - { - add_new_contact(group_name, nick, ICQ_ID ); - } - if(!find_account_by_handle(uin, ICQ_ID)) - { - eb_account * ea = eb_services[ICQ_ID].sc->new_account(NULL,uin); - add_account( nick, ea ); + while (!feof(fp)) { + fgets(c, 1024, fp); + token = remove_spaces(strtok(c, "=")); + if (!g_strncasecmp(token, "NumOfUsers", + strlen("NumOfUsers") + 1)) + break; + } + if (feof(fp)) { + fclose(fp); + ay_do_warning("Import Warning", + "No users found in licq file to import"); + return; + } + + token = strtok(NULL, "="); + num_users = atoi(token); + if (num_users < 1) { + fclose(fp); + ay_do_warning("Import Warning", + "No users found in licq file to import"); + return; + } + + if (!find_grouplist_by_name(group_name)) + add_group(group_name); + + while (!feof(fp)) { + fgets(c, 1024, fp); + if (feof(fp)) + break; + token = strtok(c, "="); + if (sscanf(token, "User%d", &unused_num) <= 0) + continue; + + uin = remove_spaces(strtok(NULL, "=")); + nick = get_licq_nick(uin, licq_version); + if (!nick) + nick = uin; + + if (find_account_by_handle(uin, ICQ_ID)) { + continue; + } + if (!find_contact_by_nick(nick)) { + add_new_contact(group_name, nick, ICQ_ID); + } + if (!find_account_by_handle(uin, ICQ_ID)) { + eb_account *ea = + eb_services[ICQ_ID].sc->new_account(NULL, uin); + add_account(nick, ea); // RUN_SERVICE(ea)->add_user(ea); - } - } - fclose(fp); - - ay_do_info( "Import", "Successfully imported licq contact list" ); + } + } + fclose(fp); + + ay_do_info("Import", "Successfully imported licq contact list"); } |