From 2c2d49fe7b662c2a1e39c2d8162bdcd5c356480c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 31 Mar 2010 23:12:12 +0200 Subject: Whitespace --- src/mainwindow.c | 316 +++++++++++++++++------------------ src/msnprotocol.c | 492 +++++++++++++++++++++++++++--------------------------- src/routines.c | 180 ++++++++++---------- 3 files changed, 494 insertions(+), 494 deletions(-) diff --git a/src/mainwindow.c b/src/mainwindow.c index addb978..da83d4a 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -1,6 +1,6 @@ /* * mainwindow.c - * + * * The main (contact list) window * * (c) 2002-2007 Thomas White @@ -8,17 +8,17 @@ * * This package is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 dated June, 1991. + * the Free Software Foundation; version 2 dated June, 1991. * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this package; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * 02111-1307, USA. * */ @@ -71,18 +71,18 @@ static struct { int quitting; /* Whether or not to quit on disconnection. */ int was_menustatuschange; /* Locks to avoid comical looping */ int just_updating; /* when changing status. */ - + /* Common to both states */ GtkWidget *window; /* Overall window */ GtkWidget *swindow; /* Scrolled Window inside window */ GtkWidget *vbox; /* vbox inside swindow */ GtkWidget *top_hbox; /* hbox at top of window */ GtkWidget *bigvbox; /* vbox to put scrolled window and menu bar into */ - + /* For the dispatch state */ GtkWidget *signin_button; /* The Big Red Button */ char *signin_text; /* The text inside the big red button */ - + /* For the online state */ GtkWidget *online_vbox; /* vbox to hold online contacts plus "Online" heading */ GtkWidget *offline_vbox; /* vbox to hold offline contacts plus "Offline" heading */ @@ -98,9 +98,9 @@ static struct { GtkWidget *offline_label; /* "Offline" heading */ GtkWidget *status_vbox; /* vbox to sort out size of status */ GtkActionGroup *action_group; - + char *menu_subject; - + } mainwindow = { MAINWINDOW_STATE_UNDEFINED, @@ -117,7 +117,7 @@ static struct { NULL, NULL, - + NULL, NULL, NULL, @@ -150,7 +150,7 @@ static void mainwindow_signin() { } mainwindow_setonline(); msnprotocol_connect("", 0); - + } /* Internally-called function to undo the effects of mainwindow_setonline */ @@ -183,7 +183,7 @@ static void mainwindow_unsetonline() { gtk_widget_destroy(mainwindow.top_vbox); mainwindow.state = MAINWINDOW_STATE_UNDEFINED; - + if ( mainwindow.quitting ) { /* Bye Bye... */ gtk_widget_destroy(mainwindow.window); @@ -198,7 +198,7 @@ static void mainwindow_unsetdispatch() { gtk_widget_destroy(mainwindow.signin_button); free(mainwindow.signin_text); - + mainwindow.state = MAINWINDOW_STATE_UNDEFINED; } @@ -206,7 +206,7 @@ static void mainwindow_unsetdispatch() { static void mainwindow_fname_labelize() { gfloat yalign; - + gtk_widget_destroy(mainwindow.fname_entry); mainwindow.fname_entry = NULL; mainwindow.friendlyname = gtk_label_new(""); @@ -223,18 +223,18 @@ static void mainwindow_csm_labelize() { gfloat yalign; char *csm; - + gtk_widget_destroy(mainwindow.csm_entry); mainwindow.csm_entry = NULL; mainwindow.csm = gtk_label_new(""); assert(mainwindow.csm != NULL); gtk_misc_get_alignment(GTK_MISC(mainwindow.csm), NULL, &yalign); gtk_misc_set_alignment(GTK_MISC(mainwindow.csm), 0, yalign); - + csm = listcache_getcsm(); mainwindow_setcsm(csm); free(csm); - + gtk_container_add(GTK_CONTAINER(mainwindow.csm_eventbox), mainwindow.csm); gtk_widget_show(mainwindow.csm); @@ -252,10 +252,10 @@ static void mainwindow_fname_activate() { /* Switch back to a label... */ mainwindow_fname_labelize(); - + /* NOW change the name... currently the widget displays the old name, meaning it'll still be accurate if the name change fails. */ - msnprotocol_setmfn(new_mfn); + msnprotocol_setmfn(new_mfn); } @@ -265,15 +265,15 @@ static void mainwindow_csm_activate() { assert(mainwindow.csm_entry != NULL); assert(mainwindow.csm == NULL); - - new_csm = gtk_entry_get_text(GTK_ENTRY(mainwindow.csm_entry)); + + new_csm = strdup(gtk_entry_get_text(GTK_ENTRY(mainwindow.csm_entry))); debug_print("MA: New CSM: %s\n", new_csm); msnprotocol_setcsm(new_csm); /* Switch back to a label... */ mainwindow_csm_labelize(); - + } static int mainwindow_fname_keypress(GtkWidget *widget, GdkEventKey *event) { @@ -281,7 +281,7 @@ static int mainwindow_fname_keypress(GtkWidget *widget, GdkEventKey *event) { if ( event->keyval == GDK_Escape ) { mainwindow_fname_labelize(); } - + return 0; } @@ -291,7 +291,7 @@ static int mainwindow_csm_keypress(GtkWidget *widget, GdkEventKey *event) { if ( event->keyval == GDK_Escape ) { mainwindow_csm_labelize(); } - + return 0; } @@ -305,15 +305,15 @@ void mainwindow_fname_startchange() { /* Already editing! */ return; } - + if ( msnprotocol_signedin() != 1 ) { /* Not ready. */ return; } - + old_mfn = listcache_getmfn(); mfn_decode = routines_urldecode(old_mfn); - + /* Replace friendly name display with editable box. */ gtk_widget_destroy(mainwindow.friendlyname); mainwindow.friendlyname = NULL; @@ -325,12 +325,12 @@ void mainwindow_fname_startchange() { g_signal_connect(GTK_OBJECT(mainwindow.fname_entry), "key-press-event", GTK_SIGNAL_FUNC(mainwindow_fname_keypress), NULL); gtk_container_add(GTK_CONTAINER(mainwindow.fname_eventbox), mainwindow.fname_entry); gtk_widget_show(mainwindow.fname_entry); - + gtk_editable_set_position(GTK_EDITABLE(mainwindow.fname_entry), -1); gtk_widget_grab_focus(mainwindow.fname_entry); - + free(mfn_decode); - + } void mainwindow_csm_startchange() { @@ -341,15 +341,15 @@ void mainwindow_csm_startchange() { /* Already editing! */ return; } - + if ( msnprotocol_signedin() != 1 ) { /* Not ready. */ return; } - + if ( !GTK_WIDGET_VISIBLE(mainwindow.csm_eventbox) ) { - - /* CSM bar is hidden... better fix that first... */ + + /* CSM bar is hidden... better fix that first... */ GtkAction *action; action = gtk_action_group_get_action(mainwindow.action_group, "ShowCSMAction"); @@ -361,9 +361,9 @@ void mainwindow_csm_startchange() { } } - + old_csm = listcache_getcsm_noentities(); - + /* Replace friendly name display with editable box. */ gtk_widget_destroy(mainwindow.csm); mainwindow.csm = NULL; @@ -376,10 +376,10 @@ void mainwindow_csm_startchange() { g_signal_connect(GTK_OBJECT(mainwindow.csm_entry), "key-press-event", GTK_SIGNAL_FUNC(mainwindow_csm_keypress), NULL); gtk_container_add(GTK_CONTAINER(mainwindow.csm_eventbox), mainwindow.csm_entry); gtk_widget_show(mainwindow.csm_entry); - + gtk_editable_set_position(GTK_EDITABLE(mainwindow.csm_entry), -1); gtk_widget_grab_focus(mainwindow.csm_entry); - + } /* Entry point when local friendly name is clicked (to change it) */ @@ -388,9 +388,9 @@ static void mainwindow_fname_clicked(GtkWidget *widget, GdkEventButton *button) if ( button->type != GDK_2BUTTON_PRESS ) { return; } - + mainwindow_fname_startchange(); - + } static void mainwindow_csm_clicked(GtkWidget *widget, GdkEventButton *button) { @@ -398,9 +398,9 @@ static void mainwindow_csm_clicked(GtkWidget *widget, GdkEventButton *button) { if ( button->type != GDK_2BUTTON_PRESS ) { return; } - + mainwindow_csm_startchange(); - + } /* Called by src/msnprotocol.c's CHG handler to update the window. Normally, this won't change anything @@ -414,7 +414,7 @@ void mainwindow_forcestatus(OnlineState status) { /* Order of items in this list MUST match those in mainwindow_setonline() */ switch ( status ) { - + case ONLINE_NLN : newstatus = 0; break; case ONLINE_AWY : newstatus = 1; break; case ONLINE_BSY : newstatus = 2; break; @@ -423,11 +423,11 @@ void mainwindow_forcestatus(OnlineState status) { case ONLINE_LUN : newstatus = 5; break; case ONLINE_HDN : newstatus = 6; break; default : newstatus = -1; break; /* Should never happen */ - + } gtk_combo_box_set_active(GTK_COMBO_BOX(mainwindow.setstatus), newstatus); - + } /* Combobox "changed" handler. */ @@ -435,13 +435,13 @@ static int mainwindow_setstatus() { int newstatus; OnlineState status; - + g_object_get(G_OBJECT(mainwindow.setstatus), "active", &newstatus, NULL); debug_print("MA: mainwindow_setstatus: %i\n", newstatus); - + /* Order of items in this list MUST match those in mainwindow_setonline() */ switch ( newstatus ) { - + case 0 : status = ONLINE_NLN; break; case 1 : status = ONLINE_AWY; break; case 2 : status = ONLINE_BSY; break; @@ -450,9 +450,9 @@ static int mainwindow_setstatus() { case 5 : status = ONLINE_LUN; break; case 6 : status = ONLINE_HDN; break; default : status = ONLINE_ERR; break; - + } - + msnprotocol_setstatus(status); /* If this DIDN'T originate from the menu, update the menu. */ @@ -475,9 +475,9 @@ static int mainwindow_setstatus() { mainwindow.just_updating = 1; gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE); } - + return FALSE; - + } /* Put the main window into its main "online" state */ @@ -494,12 +494,12 @@ void mainwindow_setonline() { } assert(mainwindow.state == MAINWINDOW_STATE_UNDEFINED); - mainwindow.online_vbox = gtk_vbox_new(FALSE, 0); + mainwindow.online_vbox = gtk_vbox_new(FALSE, 0); mainwindow.offline_vbox = gtk_vbox_new(FALSE, 0); mainwindow.top_vbox = gtk_vbox_new(FALSE, 0); mainwindow.status_vbox = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(mainwindow.top_hbox), mainwindow.top_vbox, TRUE, TRUE, 5); - + mainwindow.fname_eventbox = gtk_event_box_new(); assert(mainwindow.fname_eventbox != NULL); mainwindow.friendlyname = gtk_label_new("Connecting..."); @@ -525,7 +525,7 @@ void mainwindow_setonline() { csm = listcache_getcsm(); mainwindow_setcsm(csm); free(csm); - + mainwindow.setstatus = gtk_combo_box_new_text(); gtk_combo_box_append_text(GTK_COMBO_BOX(mainwindow.setstatus), "Online"); gtk_combo_box_append_text(GTK_COMBO_BOX(mainwindow.setstatus), "Away"); @@ -537,7 +537,7 @@ void mainwindow_setonline() { gtk_signal_connect_object(GTK_OBJECT(mainwindow.setstatus), "changed", GTK_SIGNAL_FUNC(mainwindow_setstatus), NULL); gtk_box_pack_end(GTK_BOX(mainwindow.status_vbox), mainwindow.setstatus, TRUE, FALSE, 0); gtk_box_pack_end(GTK_BOX(mainwindow.top_hbox), mainwindow.status_vbox, FALSE, FALSE, 0); - + /* Add "Online" and "Offline" headings */ mainwindow.online_label = gtk_label_new("---- Online ----"); gtk_box_pack_start(GTK_BOX(mainwindow.online_vbox), mainwindow.online_label, FALSE, FALSE, 0); @@ -550,7 +550,7 @@ void mainwindow_setonline() { gtk_widget_set_usize(GTK_WIDGET(mainwindow.online_vbox), 10, -1); gtk_widget_set_usize(GTK_WIDGET(mainwindow.offline_label), 10, -1); gtk_widget_set_usize(GTK_WIDGET(mainwindow.online_label), 10, -1); - + gtk_widget_show(mainwindow.online_label); gtk_widget_show(mainwindow.offline_label); gtk_widget_show(mainwindow.online_vbox); @@ -578,7 +578,7 @@ void mainwindow_setonline() { gtk_widget_set_sensitive(menuitem, TRUE); menuitem = gtk_ui_manager_get_widget(mainwindow.ui, "/mainwindow/view/show_csm"); gtk_widget_set_sensitive(menuitem, TRUE); - + menuitem = gtk_ui_manager_get_widget(mainwindow.ui, "/mainwindow/status/status_nln"); gtk_widget_set_sensitive(menuitem, TRUE); menuitem = gtk_ui_manager_get_widget(mainwindow.ui, "/mainwindow/status/status_awy"); @@ -613,39 +613,39 @@ void mainwindow_kickdispatch() { const char *username; username = options_username(); - + if ( mainwindow.state != MAINWINDOW_STATE_DISPATCH ) { return; } - + if ( (strlen(username) != 0) && (strlen(options_password()) != 0) && (strlen(options_hostname()) != 0) ) { - + GtkWidget *menuitem; - + strcpy(mainwindow.signin_text, "Not signed in.\n\n"); - strncat(mainwindow.signin_text, username, 200); + strncat(mainwindow.signin_text, username, 200); mainwindow.signin_text[255] = '\0'; strcat(mainwindow.signin_text, "\n\nClick here to connect"); mainwindow.signin_text[255] = '\0'; gtk_label_set_text(GTK_LABEL(GTK_BIN(mainwindow.signin_button)->child), mainwindow.signin_text); - + gtk_widget_set_sensitive(mainwindow.signin_button, TRUE); menuitem = gtk_ui_manager_get_widget(mainwindow.ui, "/mainwindow/connection/sign_in"); gtk_widget_set_sensitive(menuitem, TRUE); - + } else { - + GtkWidget *menuitem; - + gtk_widget_set_sensitive(mainwindow.signin_button, FALSE); menuitem = gtk_ui_manager_get_widget(mainwindow.ui, "/mainwindow/connection/sign_in"); gtk_widget_set_sensitive(menuitem, FALSE); - + strcpy(mainwindow.signin_text, "Please configure your account details"); gtk_label_set_text(GTK_LABEL(GTK_BIN(mainwindow.signin_button)->child), mainwindow.signin_text); /* If this is being called from accountwindow_apply(), this won't re-open the already-open window. */ accountwindow_open(); - + } } @@ -658,7 +658,7 @@ void mainwindow_setdispatch() { if (mainwindow.state == MAINWINDOW_STATE_DISPATCH) { return; /* Nothing to do! */ } else if (mainwindow.state == MAINWINDOW_STATE_ONLINE) { - mainwindow_unsetonline(); + mainwindow_unsetonline(); } assert(mainwindow.state == MAINWINDOW_STATE_UNDEFINED); @@ -669,9 +669,9 @@ void mainwindow_setdispatch() { mainwindow.signin_text = malloc(256); assert(mainwindow.signin_text != NULL); - + gtk_box_pack_start(GTK_BOX(mainwindow.vbox), mainwindow.signin_button, TRUE, TRUE, 5); - + GTK_WIDGET_SET_FLAGS(mainwindow.signin_button, GTK_CAN_DEFAULT); gtk_widget_grab_default(mainwindow.signin_button); gtk_widget_grab_focus(mainwindow.signin_button); @@ -730,8 +730,8 @@ void mainwindow_setdispatch() { gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(gtk_action_group_get_action(mainwindow.action_group, "StatusNLNAction")), TRUE); mainwindow.state = MAINWINDOW_STATE_DISPATCH; - mainwindow_kickdispatch(); - + mainwindow_kickdispatch(); + } static void mainwindow_addui_callback(GtkUIManager *ui, GtkWidget *widget, GtkContainer *container) { @@ -742,7 +742,7 @@ static void mainwindow_addui_callback(GtkUIManager *ui, GtkWidget *widget, GtkCo if ( GTK_IS_TOOLBAR(widget) ) { gtk_toolbar_set_show_arrow(GTK_TOOLBAR(widget), TRUE); } - + } static void mainwindow_connection_signout() { @@ -761,7 +761,7 @@ static int mainwindow_confirm_quit_response(GtkWidget *widget, int response) { gtk_widget_destroy(widget); return FALSE; } - + /* Sign out */ if ( msnprotocol_signedin() ) { mainwindow.quitting = 1; @@ -797,19 +797,19 @@ static int mainwindow_togglecsm(GtkWidget *widget) { gboolean active; GtkAction *action; - + action = gtk_action_group_get_action(mainwindow.action_group, "ShowCSMAction"); assert(action != NULL); active = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)); - + if ( active ) { - + /* Show CSM */ gtk_widget_show(mainwindow.csm_eventbox); options_sethidecsm(FALSE); - + } else { - + /* Hide CSM - see also mainwindow_sethidecsm() above. */ if ( mainwindow.csm_entry != NULL ) { mainwindow_csm_labelize(); @@ -819,7 +819,7 @@ static int mainwindow_togglecsm(GtkWidget *widget) { } options_save(); - + return FALSE; } @@ -837,8 +837,8 @@ static int mainwindow_toggleoffline(GtkWidget *widget) { action = gtk_action_group_get_action(mainwindow.action_group, "ShowOfflineAction"); assert(action != NULL); active = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)); - - if ( active ) { + + if ( active ) { /* Show Offline Contacts */ gtk_widget_show(mainwindow.offline_vbox); options_sethideoffline(FALSE); @@ -848,13 +848,13 @@ static int mainwindow_toggleoffline(GtkWidget *widget) { options_sethideoffline(TRUE); } options_save(); - + return FALSE; } static int mainwindow_menubarstatuschange(GtkRadioAction *action, GtkRadioAction *current, gpointer data) { - + debug_print("MA: mainwindow_menubarstatuschange\n"); if ( !msnprotocol_signedin() ) { @@ -880,32 +880,32 @@ static int mainwindow_menubarstatuschange(GtkRadioAction *action, GtkRadioAction static gint mainwindow_deletecontact(GtkWidget *widget, gpointer data) { printf("MA: Chosen to delete '%s'\n", mainwindow.menu_subject); - + #if 0 GtkWidget *hbox; GtkWidget *vbox; GtkWidget *icon; AddContactWindow *item; - + item = malloc(sizeof(AddContactWindow)); item->window = gtk_dialog_new_with_buttons("Add New Contact", mainwindow_gtkwindow(), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); - + g_signal_connect(item->window, "response", G_CALLBACK(addcontact_response), item); g_signal_connect_swapped(item->window, "response", G_CALLBACK(gtk_widget_destroy), item->window); g_signal_connect(item->window, "destroy", G_CALLBACK(addcontact_destroyed), item); - + hbox = gtk_hbox_new(FALSE, 20); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(item->window)->vbox), hbox); icon = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_DIALOG); gtk_box_pack_start(GTK_BOX(hbox), icon, TRUE, TRUE, 0); - + vbox = gtk_vbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); - + gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new("Enter the Passport address of your new contact:"), TRUE, TRUE, 0); item->username_entry = gtk_entry_new(); @@ -915,7 +915,7 @@ static gint mainwindow_deletecontact(GtkWidget *widget, gpointer data) { item->allow_toggle = gtk_check_button_new_with_label("Allow this new contact to message you."); gtk_box_pack_start(GTK_BOX(vbox), item->allow_toggle, TRUE, TRUE, 0); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item->allow_toggle), TRUE); - + gtk_container_set_border_width(GTK_CONTAINER(hbox), 10); gtk_widget_show_all(item->window); #endif @@ -929,7 +929,7 @@ static void mainwindow_addmenubar() { GtkActionEntry entries[] = { { "ConnectionAction", NULL, "_Connection", NULL, NULL, NULL }, - + #ifdef HAVE_GTK_2_6_0 { "SignInAction", GTK_STOCK_CONNECT, "_Sign In", NULL, NULL, G_CALLBACK(mainwindow_signin) }, { "SignOutAction", GTK_STOCK_DISCONNECT, "Sign _Out", NULL, NULL, G_CALLBACK(mainwindow_connection_signout) }, @@ -939,32 +939,32 @@ static void mainwindow_addmenubar() { { "SignOutAction", NULL, "Sign _Out", NULL, NULL, G_CALLBACK(mainwindow_connection_signout) }, { "AboutAction", NULL, "_About TuxMessenger", NULL, NULL, G_CALLBACK(about_open) }, #endif /* HAVE_GTK_2_6_0 */ - + { "AccountAction", GTK_STOCK_PROPERTIES, "_Account Details...", NULL, NULL, G_CALLBACK(accountwindow_open) }, { "QuitAction", GTK_STOCK_QUIT, NULL, "Q", "Quit the application", G_CALLBACK(mainwindow_connection_quit) }, { "ViewAction", NULL, "_View", NULL, NULL, NULL }, { "StatusAction", NULL, "_Status", NULL, NULL, NULL }, - { "ChangeNameAction", NULL, "Change Screen _Name...", NULL, NULL, G_CALLBACK(mainwindow_fname_startchange) }, - { "ChangeCSMAction", NULL, "Change Custom _Message...", NULL, NULL, G_CALLBACK(mainwindow_csm_startchange) }, - { "ChangeAvatarAction", NULL, "Change A_vatar...", NULL, NULL, NULL }, + { "ChangeNameAction", NULL, "Change Screen _Name...", NULL, NULL, G_CALLBACK(mainwindow_fname_startchange) }, + { "ChangeCSMAction", NULL, "Change Custom _Message...", NULL, NULL, G_CALLBACK(mainwindow_csm_startchange) }, + { "ChangeAvatarAction", NULL, "Change A_vatar...", NULL, NULL, NULL }, { "ToolsAction", NULL, "_Tools", NULL, NULL, NULL }, - { "AddContactAction", GTK_STOCK_ADD, "_Add Contact...", NULL, NULL,G_CALLBACK(addcontact_open) }, - { "BlockAllowAction", NULL, "_Block and Allow Lists", NULL, NULL, NULL }, - { "ReverseAction", NULL, "_Reverse List", NULL, NULL, NULL }, - { "PreferencesAction", GTK_STOCK_PREFERENCES, "_Preferences...", NULL, NULL, G_CALLBACK(prefswindow_open) }, - { "ListCleanupAction", NULL, "_List Cleanup...", NULL, NULL, G_CALLBACK(listcleanup_open) }, + { "AddContactAction", GTK_STOCK_ADD, "_Add Contact...", NULL, NULL,G_CALLBACK(addcontact_open) }, + { "BlockAllowAction", NULL, "_Block and Allow Lists", NULL, NULL, NULL }, + { "ReverseAction", NULL, "_Reverse List", NULL, NULL, NULL }, + { "PreferencesAction", GTK_STOCK_PREFERENCES, "_Preferences...", NULL, NULL, G_CALLBACK(prefswindow_open) }, + { "ListCleanupAction", NULL, "_List Cleanup...", NULL, NULL, G_CALLBACK(listcleanup_open) }, { "HelpAction", NULL, "_Help", NULL, NULL, NULL }, - - { "ContactMessageAction", GTK_STOCK_NEW, "New _Message", NULL, NULL, NULL }, - { "ContactSendFileAction", GTK_STOCK_OPEN, "Send _File", NULL, NULL, NULL }, - { "ContactBlockAction", GTK_STOCK_NO, "_Block Contact", NULL, NULL, NULL }, - { "ContactUnblockAction", GTK_STOCK_YES, "_Unblock Contact", NULL, NULL, NULL }, - { "ContactDeleteAction", GTK_STOCK_DELETE, "_Delete Contact", NULL, NULL, G_CALLBACK(mainwindow_deletecontact) }, - + + { "ContactMessageAction", GTK_STOCK_NEW, "New _Message", NULL, NULL, NULL }, + { "ContactSendFileAction", GTK_STOCK_OPEN, "Send _File", NULL, NULL, NULL }, + { "ContactBlockAction", GTK_STOCK_NO, "_Block Contact", NULL, NULL, NULL }, + { "ContactUnblockAction", GTK_STOCK_YES, "_Unblock Contact", NULL, NULL, NULL }, + { "ContactDeleteAction", GTK_STOCK_DELETE, "_Delete Contact", NULL, NULL, G_CALLBACK(mainwindow_deletecontact) }, + }; GtkToggleActionEntry toggles[] = { @@ -976,12 +976,12 @@ static void mainwindow_addmenubar() { GtkRadioActionEntry radios_status[] = { { "StatusNLNAction", NULL, "_Online", "O", NULL, ONLINE_NLN }, - { "StatusAWYAction", NULL, "_Away", "A", NULL, ONLINE_AWY }, - { "StatusBSYAction", NULL, "_Busy", NULL, NULL, ONLINE_BSY }, - { "StatusBRBAction", NULL, "Be _Right Back", "B", NULL, ONLINE_BRB }, - { "StatusPHNAction", NULL, "On The _Phone", NULL, NULL, ONLINE_PHN }, - { "StatusLUNAction", NULL, "Out To _Lunch", "L", NULL, ONLINE_LUN }, - { "StatusHDNAction", NULL, "Appear O_ffline", NULL, NULL, ONLINE_HDN }, + { "StatusAWYAction", NULL, "_Away", "A", NULL, ONLINE_AWY }, + { "StatusBSYAction", NULL, "_Busy", NULL, NULL, ONLINE_BSY }, + { "StatusBRBAction", NULL, "Be _Right Back", "B", NULL, ONLINE_BRB }, + { "StatusPHNAction", NULL, "On The _Phone", NULL, NULL, ONLINE_PHN }, + { "StatusLUNAction", NULL, "Out To _Lunch", "L", NULL, ONLINE_LUN }, + { "StatusHDNAction", NULL, "Appear O_ffline", NULL, NULL, ONLINE_HDN }, }; GtkRadioActionEntry radios_sorting[] = { @@ -1007,16 +1007,16 @@ static void mainwindow_addmenubar() { g_signal_connect(mainwindow.ui, "add_widget", G_CALLBACK(mainwindow_addui_callback), mainwindow.bigvbox); gtk_widget_show(mainwindow.bigvbox); if ( gtk_ui_manager_add_ui_from_file(mainwindow.ui, DATADIR"/tuxmessenger/mainwindow.ui", &error) == 0 ) { - + /* :( */ debug_print("MA: Error loading main window menu bar: %s\n", error->message); exit(1); - + } - + gtk_window_add_accel_group(GTK_WINDOW(mainwindow.window), gtk_ui_manager_get_accel_group(mainwindow.ui)); gtk_ui_manager_ensure_update(mainwindow.ui); - + } /* Create and open the main window, in dispatch state */ @@ -1034,7 +1034,7 @@ void mainwindow_open() { /* Add menu bar */ mainwindow_addmenubar(); - + /* Create a scrolled window to hold the contacts. */ mainwindow.swindow = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(mainwindow.swindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); @@ -1046,12 +1046,12 @@ void mainwindow_open() { mainwindow.top_hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(mainwindow.vbox), mainwindow.top_hbox, FALSE, FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(mainwindow.vbox), 6); - + g_signal_connect(G_OBJECT(mainwindow.window), "delete-event", GTK_SIGNAL_FUNC(mainwindow_confirm_quit), NULL); mainwindow.state = MAINWINDOW_STATE_UNDEFINED; mainwindow_setdispatch(); gtk_widget_show_all(mainwindow.window); - + } /* Trivial function to add an accelerator group to the window, e.g. for the "statusmenu" */ @@ -1076,7 +1076,7 @@ static char *mainwindow_decodestatus(OnlineState status) { } else if ( status == ONLINE_LUN ) { return "[Food] "; } - + return "[Whoops] "; } @@ -1089,9 +1089,9 @@ void mainwindow_setmfn(const char *new_friendlyname) { assert(new_friendlyname != NULL); assert(mainwindow.friendlyname != NULL); - + decoded_fname = routines_urldecode(new_friendlyname); - + final_fname = malloc(strlen(new_friendlyname) + 11); sprintf(final_fname, "––– %s", decoded_fname); gtk_label_set_text(GTK_LABEL(mainwindow.friendlyname), final_fname); @@ -1107,11 +1107,11 @@ void mainwindow_setcsm(const char *new_csm) { assert(new_csm != NULL); assert(mainwindow.csm != NULL); - + csm_markup = malloc(strlen(new_csm)+50); new_csm_edited = routines_killtriangles(new_csm); sprintf(csm_markup, "%s", new_csm_edited); - + gtk_label_set_markup(GTK_LABEL(mainwindow.csm), csm_markup); free(new_csm_edited); free(csm_markup); @@ -1121,9 +1121,9 @@ void mainwindow_setcsm(const char *new_csm) { static void mainwindow_adjustmenu_popup(GtkWidget *adjust_button, char *username, guint button, guint time) { GtkWidget *menu; - + menu = gtk_ui_manager_get_widget(mainwindow.ui, "/ui/contact"); - + /* It is conceivable that neither of these would be true */ if ( contactlist_isonlist("BL", username) ) { GtkWidget *disable = gtk_ui_manager_get_widget(mainwindow.ui, "/ui/contact/block"); @@ -1133,8 +1133,8 @@ static void mainwindow_adjustmenu_popup(GtkWidget *adjust_button, char *username GtkWidget *disable = gtk_ui_manager_get_widget(mainwindow.ui, "/ui/contact/unblock"); gtk_widget_set_sensitive(GTK_WIDGET(disable), FALSE); } - - + + gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, time); mainwindow.menu_subject = username; @@ -1148,19 +1148,19 @@ static gint mainwindow_contact_event(GtkWidget *button, GdkEvent *event, char *u mainwindow_adjustmenu_popup(button, username, ((GdkEventButton *)event)->button, ((GdkEventButton *)event)->time); } } - + return 0; - + } /* Contact button clicked */ static gint mainwindow_contact_clicked(GtkWidget *button, char *username) { - if ( msnprotocol_status() == ONLINE_HDN ) { + if ( msnprotocol_status() == ONLINE_HDN ) { error_report("You can't send messages while you are Invisible!"); return 0; } - + messagewindow_create_if_none(username, NULL); return 0; @@ -1178,14 +1178,14 @@ static void mainwindow_userdnd_get(GtkWidget *widget, GdkDragContext *drag_conte static void mainwindow_userdnd_receive(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *seldata, guint info, guint time, char *username1) { char *username2; - + username2 = (char *)seldata->data; - - if ( msnprotocol_status() == ONLINE_HDN ) { + + if ( msnprotocol_status() == ONLINE_HDN ) { error_report("You can't send messages while you are Invisible!"); return; } - + if ( strcmp(username1, username2) == 0 ) { debug_print("MA: Try just clicking...\n"); return; @@ -1207,7 +1207,7 @@ static void mainwindow_addcontactui(UIContact *uicontact, char *username, char * char *csmtext2; char *tooltips_string; char *csmtext_noentities; - + assert(uicontact->hbox == NULL); assert(uicontact->adjustbutton == NULL); assert(uicontact->button == NULL); @@ -1216,25 +1216,25 @@ static void mainwindow_addcontactui(UIContact *uicontact, char *username, char * assert(uicontact->tooltips == NULL); assert(status != ONLINE_HDN); /* Doesn't happen for contacts */ - + /* Create the button */ uicontact->button = gtk_button_new(); assert(uicontact->button != NULL); GTK_WIDGET_UNSET_FLAGS(uicontact->button, GTK_CAN_FOCUS); gtk_button_set_relief(GTK_BUTTON(uicontact->button), GTK_RELIEF_NONE); - + uicontact->hbox = gtk_hbox_new(FALSE, 0); assert(uicontact->hbox != NULL); gtk_container_add(GTK_CONTAINER(uicontact->button), uicontact->hbox); - + uicontact->pixmap = statusicons_pixmap(status); gtk_box_pack_start(GTK_BOX(uicontact->hbox), uicontact->pixmap, FALSE, FALSE, 0); - + /* Label containing status, friendly name and CSM */ friendlynametext = routines_urldecode(friendlyname); friendlynametext2 = routines_killtriangles_and_ampersands(friendlynametext); if ( status != ONLINE_FLN ) { - + csmtext = contactlist_csm(username, 0); csmtext_noentities = contactlist_csm(username, 1); if ( csmtext == NULL ) { @@ -1267,9 +1267,9 @@ static void mainwindow_addcontactui(UIContact *uicontact, char *username, char * free(csmtext2); g_signal_connect(uicontact->button, "clicked", GTK_SIGNAL_FUNC(mainwindow_contact_clicked), (gpointer)username); - + } else { - + friendlynametext = routines_urldecode(friendlyname); uicontact->label = gtk_label_new(friendlynametext); assert(uicontact->label != NULL); @@ -1280,7 +1280,7 @@ static void mainwindow_addcontactui(UIContact *uicontact, char *username, char * } gtk_box_pack_start(GTK_BOX(uicontact->hbox), uicontact->label, TRUE, TRUE, 3); - + /* Packing and signal handling */ if ( status != ONLINE_FLN ) { gtk_box_pack_end(GTK_BOX(mainwindow.online_vbox), uicontact->button, TRUE, FALSE, 0); @@ -1288,13 +1288,13 @@ static void mainwindow_addcontactui(UIContact *uicontact, char *username, char * gtk_box_pack_end(GTK_BOX(mainwindow.offline_vbox), uicontact->button, TRUE, FALSE, 0); } g_signal_connect(uicontact->button, "event", GTK_SIGNAL_FUNC(mainwindow_contact_event), (gpointer)username); - + /* Tooltips */ uicontact->tooltips = gtk_tooltips_new(); assert(uicontact->tooltips != NULL); gtk_tooltips_set_tip(uicontact->tooltips, uicontact->button, tooltips_string, NULL); free(tooltips_string); - + /* Drag and Drop */ targets[0].target = "tm_username"; targets[0].flags = GTK_TARGET_SAME_APP; @@ -1308,9 +1308,9 @@ static void mainwindow_addcontactui(UIContact *uicontact, char *username, char * /* Sort out the size of the new item */ gtk_widget_set_usize(uicontact->hbox, 10, -1); - + gtk_widget_show_all(uicontact->button); - + } /* Called from src/contactlist.c to add a contact (on the FL) to the list UI @@ -1318,7 +1318,7 @@ static void mainwindow_addcontactui(UIContact *uicontact, char *username, char * UIContact *mainwindow_addcontact(char *username, char *friendlyname, OnlineState status) { UIContact *uicontact; - + uicontact = malloc(sizeof(UIContact)); assert(uicontact != NULL); @@ -1329,9 +1329,9 @@ UIContact *mainwindow_addcontact(char *username, char *friendlyname, OnlineState uicontact->eventbox = NULL; uicontact->tooltips = NULL; uicontact->pixmap = NULL; - + mainwindow_addcontactui(uicontact, username, friendlyname, status); - + return uicontact; } @@ -1340,7 +1340,7 @@ UIContact *mainwindow_addcontact(char *username, char *friendlyname, OnlineState void mainwindow_setcontactstatus(UIContact *uicontact, char *username, char *friendlyname, OnlineState status) { debug_print("MA: Setting contact status for %s.\n", username); - mainwindow_removecontact(uicontact); + mainwindow_removecontact(uicontact); mainwindow_addcontactui(uicontact, username, friendlyname, status); } @@ -1366,7 +1366,7 @@ void mainwindow_removecontact(UIContact *uicontact) { uicontact->tooltips = NULL; uicontact->button = NULL; uicontact->pixmap = NULL; - + } /* Pass bits of information to src/pixmap.c so it can do its stuff */ diff --git a/src/msnprotocol.c b/src/msnprotocol.c index fe7635e..680783e 100644 --- a/src/msnprotocol.c +++ b/src/msnprotocol.c @@ -8,17 +8,17 @@ * * This package is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 dated June, 1991. + * the Free Software Foundation; version 2 dated June, 1991. * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this package; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * 02111-1307, USA. * */ @@ -96,7 +96,7 @@ static struct { NSConMode conmode; /* What's being read at the moment? */ size_t expect_length; /* Amount of MSG/UBX etc expected. */ char *msg_source; /* Source of MSG/UBX etc */ - + /* Read/write buffers */ char *wbuffer; /* Buffer for outgoing data */ unsigned int wbufsize; /* Current size of the write buffer */ @@ -123,7 +123,7 @@ static struct { NSCONMODE_LINE, 0, NULL, - + NULL, 0, 0, @@ -150,7 +150,7 @@ static void msnprotocol_cleanup_internal() { cstate.wbufsize = 0; cstate.wbuffer = NULL; cstate.woffset = 0; - + if ( cstate.rcallback != 0 ) { gdk_input_remove(cstate.rcallback); } @@ -159,7 +159,7 @@ static void msnprotocol_cleanup_internal() { gdk_input_remove(cstate.wcallback); } cstate.wcallback = 0; - + if ( cstate.disconnect_callback != 0 ) { gtk_timeout_remove(cstate.disconnect_callback); cstate.disconnect_callback = 0; @@ -169,24 +169,24 @@ static void msnprotocol_cleanup_internal() { gtk_timeout_remove(cstate.ping_callback); cstate.ping_callback = 0; } - + cstate.connect_lock = 0; cstate.trid = 1; cstate.disconnect_expected = 0; cstate.connected = CSTATE_DISCONNECTED; - + sbsessions_destroy_all(); messagewindow_disable_all(); contactlist_clear(); - + } /* Free buffers, remove callbacks, return main window to dispatch mode, etc. */ static void msnprotocol_cleanup() { - msnprotocol_cleanup_internal(); + msnprotocol_cleanup_internal(); mainwindow_setdispatch(); - + } /* If a disconnection hasn't happened ten seconds after requesting it, pull the plug. */ @@ -197,15 +197,15 @@ static gint msnprotocol_forcedisconnect() { debug_print("NS: Waited too long for disconnection... pulling the plug.\n"); cstate.disconnect_callback = 0; - + closeval = close(cstate.socket); if ( closeval != 0 ) { /* Grrr.. now it won't close - not much we can do. */ debug_print("NS: Couldn't close socket after write error.\n"); } - + msnprotocol_cleanup(); - + return FALSE; } @@ -230,12 +230,12 @@ static void msnprotocol_writeable() { if ( debug_string[i] == '\n' ) { debug_string[i] = 'n'; } - } + } debug_print("NS: send: '%s'\n", debug_string); free(debug_string); if ( wlen > 0 ) { - + /* wlen holds the number of bytes written. Sort the buffer out accordingly... */ memmove(cstate.wbuffer, cstate.wbuffer + wlen, cstate.wbufsize - wlen); new_wbufsize = cstate.wbufsize - wlen; @@ -243,19 +243,19 @@ static void msnprotocol_writeable() { cstate.wbuffer = realloc(cstate.wbuffer, new_wbufsize); if ( new_wbufsize == 0 ) { - + gdk_input_remove(cstate.wcallback); cstate.wcallback = 0; cstate.wbuffer = NULL; - + } cstate.wbufsize = new_wbufsize; - cstate.woffset -= wlen; + cstate.woffset -= wlen; } else { - + if ( wlen == -1 ) { - + /* Write error! :( */ if ( errno != EAGAIN ) { /* EAGAIN should never happen here */ @@ -269,11 +269,11 @@ static void msnprotocol_writeable() { error_report("Write error! Signed out."); msnprotocol_cleanup(); return; - + } - + } - + } } @@ -286,13 +286,13 @@ static int msnprotocol_sendtr_internal(char *instr, char *args, int newline, int len = strlen(instr); if ( send_trid ) { - + trid_string = malloc(8); assert(cstate.trid < 999999); /* Sanity check */ sprintf(trid_string, "%i", cstate.trid); len += 1; /* Space before the TrId */ len += strlen(trid_string); - + } if ( strlen(args) > 0 ) { len += strlen(args); @@ -309,7 +309,7 @@ static int msnprotocol_sendtr_internal(char *instr, char *args, int newline, int assert(cstate.wbuffer != NULL); cstate.wbufsize = len; cstate.woffset = 0; - + } if ( (cstate.wbufsize - cstate.woffset) < len ) { @@ -318,37 +318,37 @@ static int msnprotocol_sendtr_internal(char *instr, char *args, int newline, int assert(cstate.wbuffer != NULL); cstate.wbufsize = len + cstate.woffset; assert(cstate.wbufsize < 1024*1024); /* Stop the buffer from getting insane */ - + } - + /* Do the write (to memory). Deliberately verbose... */ memcpy(cstate.wbuffer + cstate.woffset, instr, strlen(instr)); cstate.woffset += strlen(instr); if ( send_trid ) { - + *(cstate.wbuffer + cstate.woffset) = ' '; cstate.woffset += 1; - + memcpy(cstate.wbuffer + cstate.woffset, trid_string, strlen(trid_string)); cstate.woffset += strlen(trid_string); free(trid_string); - + } if ( strlen(args) > 0 ) { - + *(cstate.wbuffer + cstate.woffset) = ' '; cstate.woffset += 1; memcpy(cstate.wbuffer + cstate.woffset, args, strlen(args)); cstate.woffset += strlen(args); - + } if ( newline ) { - + *(cstate.wbuffer + cstate.woffset) = '\r'; cstate.woffset += 1; *(cstate.wbuffer + cstate.woffset) = '\n'; cstate.woffset += 1; - + } /* Note the lack of a \0 terminator. It's done using records of the buffer data lengths. */ @@ -372,7 +372,7 @@ static gint msnprotocol_sendping() { msnprotocol_sendtr_internal("PNG", "", 1, 0); cstate.ping_callback = 0; - + return FALSE; } @@ -394,11 +394,11 @@ static void msnprotocol_handle_lst(char *line) { int finished = 0; int field_num = 1; int list_coming = 0; - + /* Step through the LST data and look for friendlyname, username and list number */ - + while ( !finished ) { - + char *field; int field_used = 0; field = routines_lindex(line, field_num); @@ -406,9 +406,9 @@ static void msnprotocol_handle_lst(char *line) { if ( strlen(field) == 0 ) { finished = 1; } else { - + if ( strlen(field) > 2 ) { - + if ( (field[0] == 'F') && (field[1] == '=') ) { friendlyname = strdup(field+2); list_coming = 1; @@ -422,22 +422,22 @@ static void msnprotocol_handle_lst(char *line) { list_coming = 1; field_used = 1; } - + } /* "list" is the first field without "X=" */ if ( list_coming && !field_used ) { list = strdup(field); finished = 1; /* Otherwise the next field will get used instead. */ } - + } free(field); - + } /* Need at least a username and list to continue */ if ( (username == NULL) || (list == NULL) ) { - + debug_print("NS: Didn't get enough information from LST: missing"); if ( username == NULL ) { debug_print(" username"); @@ -453,15 +453,15 @@ static void msnprotocol_handle_lst(char *line) { free(friendlyname); /* Don't leak memory */ } debug_print("\n"); - + } else { - + list_num = atoi(list); free(list); if ( list_num > 31 ) { debug_print("NS: Warning: contact is on unrecognised list(s).\n"); } - + if ( list_num & 1 ) { contactlist_fldetails(CONTACT_SOURCE_LST, username, friendlyname, 0, NULL, ONLINE_FLN, guid); } @@ -481,17 +481,17 @@ static void msnprotocol_handle_lst(char *line) { /* If contact is ONLY on the RL, add them to the PL as well. This should never happen with MSNP11+, but ensures that caching takes place properly. */ contactlist_pldetails(CONTACT_SOURCE_LST, username, friendlyname, ONLINE_FLN); - } + } if ( (list_num == 8) || (list_num & 16) ) { - + /* On RL but not FL, AL or BL indicates new user. On PL also indicates new user. */ addcontact_added(username, friendlyname); - + } - + } - + } /* Despite the name, handles ILN and NLN */ @@ -505,27 +505,27 @@ static void msnprotocol_handle_nln(nln_t nln, char *line) { char *dpobject; char *status_string; int lindex_sub; - + /* Subtract one from all the list indices if this isn't ILN, since there's no TrID */ if ( nln == NLN_ILN ) { lindex_sub = 0; } else { lindex_sub = 1; } - + status_string = routines_lindex(line, 2-lindex_sub); new_status = msngenerics_decodestatus(status_string); assert(new_status != ONLINE_FLN); /* This would be handled elsewhere. */ assert(new_status != ONLINE_HDN); /* Nonsense */ free(status_string); - + username = routines_lindex(line, 3-lindex_sub); friendlyname = routines_lindex(line, 4-lindex_sub); features_string = routines_lindex(line, 5-lindex_sub); features = atoi(features_string); free(features_string); dpobject = routines_lindex(line, 6-lindex_sub); - + /* Pass NULL if there's no "dpobject" */ if ( strlen(dpobject) == 0 ) { free(dpobject); @@ -541,7 +541,7 @@ static void msnprotocol_handle_nln(nln_t nln, char *line) { /* contactlist_fldetails won't overwrite the GUID with NULL. */ contactlist_fldetails(CONTACT_SOURCE_NLN, username, friendlyname, features, dpobject, new_status, NULL); - + /* contactlist_fldetails copies anything it's interested in */ free(username); free(friendlyname); @@ -556,12 +556,12 @@ static void msnprotocol_doneconnect() { cstate.connected = CSTATE_CONNECTED; mainwindow_forcestatus(ONLINE_HDN); - + /* Start pinging. */ if ( cstate.ping_callback == 0 ) { cstate.ping_callback = gtk_timeout_add(50000, (GtkFunction)msnprotocol_sendping, NULL); } - + if ( cstate.protocol_version >= 11 ) { msnprotocol_sendtr("GCF", "Shields.xml"); } @@ -578,22 +578,22 @@ static int msnprotocol_parseline(char *line) { int trid; debug_print("NS: recv: '%s'\n", line); - + /* Prevent blank or short lines from being a problem */ if ( strlen(line) < 4 ) { return 0; } - + instr = malloc(4); strncpy(instr, line, 3); instr[3] = '\0'; - + if ( line[3] != ' ' ) { line[0] = ' '; line[1] = ' '; line[2] = ' '; /* Prevent bogus interpretations of things that aren't three letters */ } - + err_num = atoi(instr); err_str = malloc(4); assert(err_num < 1000); @@ -608,7 +608,7 @@ static int msnprotocol_parseline(char *line) { } } free(err_str); - + trid_string = routines_lindex(line, 1); trid = atoi(trid_string); free(trid_string); @@ -620,16 +620,16 @@ static int msnprotocol_parseline(char *line) { error_report("Signed in somewhere else."); } free(sit); - } + } if ( strcmp("VER", instr) == 0 ) { - + char *string; char *protocol; int got_cvr = FALSE; int highest_msnp = 0; int pos = 1; - + protocol = routines_lindex(line, pos++); while ( strlen(protocol) ) { if ( strncmp(protocol, "MSNP", 4) == 0 ) { @@ -653,18 +653,18 @@ static int msnprotocol_parseline(char *line) { return -1; } cstate.protocol_version = highest_msnp; - + string = malloc(128); strcpy(string, "0x0409 winnt 5.1 i386 MSNMSGR 7.5.0311 msmsgs "); strncat(string, options_username(), 64); string[127] = '\0'; msnprotocol_sendtr("CVR", string); free(string); - + } - + if ( strcmp("CVR", instr) == 0 ) { - + char *string; string = malloc(128); strcpy(string, "TWN I "); @@ -672,16 +672,16 @@ static int msnprotocol_parseline(char *line) { string[127] = '\0'; msnprotocol_sendtr("USR", string); free(string); - + } - + if ( strcmp("XFR", instr) == 0 ) { - + char *mbuffer_type; mbuffer_type = routines_lindex(line, 2); - + if ( strcmp("NS", mbuffer_type) == 0 ) { - + /* got transferred to a different NS */ unsigned int new_port; char *new_hostname; @@ -698,16 +698,16 @@ static int msnprotocol_parseline(char *line) { msnprotocol_cleanup_internal(); msnprotocol_connect(new_hostname, new_port); - + /* ...and now for some "tedious mucking-about in hyperspace"... */ free(target); free(new_hostname); free(mbuffer_type); free(instr); return -1; - + } else if ( strcmp("SB", mbuffer_type) == 0 ) { - + /* SB transfer - part of an SbSession negotiation. */ unsigned int port; char *hostname; @@ -724,7 +724,7 @@ static int msnprotocol_parseline(char *line) { port = DEFAULT_SB_PORT; debug_print("NS: Corrected to %i\n", port); } - + authtype = routines_lindex(line, 4); if ( strcmp(authtype, "CKI") != 0 ) { @@ -741,26 +741,26 @@ static int msnprotocol_parseline(char *line) { cki_key = routines_lindex(line, 5); trid_char = routines_lindex(line, 1); sbprotocol_initiate_local(atoi(trid_char), hostname, port, cki_key); - + free(trid_char); free(cki_key); free(hostname); free(target); } - + free(mbuffer_type); - + } - + if ( strcmp("USR", instr) == 0 ) { - + if ( line[10] == 'S' ) { - + char *auth_string; char *auth_data; char *auth_ticket; - + auth_string = malloc(1024); strcpy(auth_string, "TWN S "); auth_data = routines_lindex(line, 4); @@ -780,41 +780,41 @@ static int msnprotocol_parseline(char *line) { } free(auth_data); free(auth_string); - + } else { - + if ( ( line[6] == 'O' ) && ( line[7] == 'K' ) ) { /* Success! */ char *syn_max; - + cstate.connected = CSTATE_LIST; syn_max = listcache_loadtag(); msnprotocol_sendtr("SYN", syn_max); - + } } - + } - + if ( strcmp("LST", instr) == 0 ) { - + msnprotocol_handle_lst(line); cstate.lst_num++; if ( cstate.lst_num == cstate.lst_num_max ) { msnprotocol_doneconnect(); } - + } - + if ( strcmp("REM", instr) == 0 ) { - + char *list = routines_lindex(line, 2); char *usernameguid = routines_lindex(line, 3); /* Could be either! */ - + if ( strcmp(list, "FL") == 0 ) { contactlist_removecontactguid(list, usernameguid); } else { @@ -822,31 +822,31 @@ static int msnprotocol_parseline(char *line) { } free(list); free(usernameguid); - + } if ( strcmp("ADC", instr) == 0 ) { - + char *list; unsigned int field_num = 2; int finished = 0; char *friendlyname = NULL; char *username = NULL; char *guid = NULL; - + while ( !finished ) { - + char *field; - + field = routines_lindex(line, field_num); field_num++; - + if ( strlen(field) == 0 ) { finished = 1; } else { - + if ( strlen(field) > 2 ) { - + if ( (field[0] == 'F') && (field[1] == '=') ) { friendlyname = strdup(field+2); } else if ( (field[0] == 'N') && (field[1] == '=') ) { @@ -854,14 +854,14 @@ static int msnprotocol_parseline(char *line) { } else if ( (field[0] == 'C') && (field[1] == '=') ) { guid = strdup(field+2); } - + } - + } free(field); - + } - + list = routines_lindex(line, 2); if ( guid != NULL ) { if ( strlen(guid) == 0 ) { @@ -903,29 +903,29 @@ static int msnprotocol_parseline(char *line) { if ( guid != NULL ) { free(guid); } - + } - + if ( strcmp("NLN", instr) == 0 ) { msnprotocol_handle_nln(NLN_NLN, line); } - + if ( strcmp("ILN", instr) == 0 ) { msnprotocol_handle_nln(NLN_ILN, line); } if ( strcmp("FLN", instr) == 0 ) { - + char *username = routines_lindex(line, 1); /* NULL values won't overwrite anything since CONTACT_SOURCE_FLN has extremely low priority */ contactlist_fldetails(CONTACT_SOURCE_FLN, username, NULL, 0, NULL, ONLINE_FLN, NULL); messagewindow_notifyoffline(username); free(username); - + } if ( strcmp("CHL", instr) == 0 ) { - + char *response; char *challenge; challenge = routines_lindex(line, 2); @@ -933,8 +933,8 @@ static int msnprotocol_parseline(char *line) { if ( cstate.protocol_version < 11 ) { unsigned char *md5; - unsigned int i; - + unsigned int i; + response = malloc(1024); strncpy(response, challenge, 64); response[1023] = '\0'; @@ -954,79 +954,79 @@ static int msnprotocol_parseline(char *line) { } } else { - + char *hex; hex = msnp11chl_response(challenge); response = malloc(strlen(hex)+strlen(CLIENT_ID)+7); sprintf(response, CLIENT_ID" 32\n%s", hex); free(hex); - + } free(challenge); msnprotocol_sendtr_nonewline("QRY", response); free(response); - + } - + if ( strcmp("PRP", instr) == 0 ) { - + char *prp_field; int check; - + /* Format #1: from SYN */ prp_field = routines_lindex(line, 1); if ( strcmp(prp_field, "MFN") == 0 ) { - + char *new_friendlyname; new_friendlyname = routines_lindex(line, 2); mainwindow_setmfn(new_friendlyname); listcache_setmfn(new_friendlyname); free(new_friendlyname); - + } - + check = atoi(prp_field); if ( check > 0 ) { - + char *prp_field2; - + /* Format #2: from PRP - only attempt if TrID is present. */ prp_field2 = routines_lindex(line, 2); if ( strcmp(prp_field2, "MFN") == 0 ) { - + char *new_friendlyname; new_friendlyname = routines_lindex(line, 3); mainwindow_setmfn(new_friendlyname); listcache_setmfn(new_friendlyname); free(new_friendlyname); - + } free(prp_field2); - + } free(prp_field); - - - + + + } - + if ( strcmp("SYN", instr) == 0 ) { - + char *newest_tag_1; char *newest_tag_2; char *full_tag; char *num_contacts; - + newest_tag_1 = routines_lindex(line, 2); newest_tag_2 = routines_lindex(line, 3); num_contacts = routines_lindex(line, 4); /* num_groups = routines_lindex(line, 5); */ - + assert(num_contacts != NULL); cstate.lst_num_max = atoi(num_contacts); free(num_contacts); - if ( cstate.lst_num_max == 0 ) { + if ( cstate.lst_num_max == 0 ) { /* This indicates an empty list OR an up-to-date list */ listcache_load(); msnprotocol_doneconnect(); @@ -1034,63 +1034,63 @@ static int msnprotocol_parseline(char *line) { cstate.connected = CSTATE_LIST; } cstate.lst_num = 0; - + assert(newest_tag_1 != NULL); assert(newest_tag_2 != NULL); - + full_tag = malloc(strlen(newest_tag_1) + strlen(newest_tag_2) + 2); assert(full_tag != NULL); - + strcpy(full_tag, newest_tag_1); strcat(full_tag, " "); strcat(full_tag, newest_tag_2); - + listcache_settag(full_tag); - + free(full_tag); free(newest_tag_1); free(newest_tag_2); - + } - + if ( strcmp("QNG", instr) == 0 ) { - + /* The time interval given by the QNG is ignored to keep things under program control. Let me know if this causes any problems for you... */ if ( cstate.ping_callback == 0 ) { cstate.ping_callback = gtk_timeout_add(50000, (GtkFunction)msnprotocol_sendping, NULL); } - + } - + if ( strcmp("RNG", instr) == 0 ) { - + /* Yay! */ char *sessionid; char *callinguser; char *switchboardaddress; char *authchallenge; char *authtype; - + sessionid = routines_lindex(line, 1); callinguser = routines_lindex(line, 5); switchboardaddress = routines_lindex(line, 2); authchallenge = routines_lindex(line, 4); - + debug_print("NS: Received SB invitation from %s (ID=%s, Key=%s, Addr=%s)\n", callinguser, sessionid, authchallenge, switchboardaddress); - + /* Check if the friendly name is available for this user. If not, TL them. This could actually happen if the user is on another list but has no friendlyname. This situation doesn't matter. */ if ( contactlist_friendlyname(callinguser) == NULL ) { - + char *friendlyname = routines_lindex(line, 6); debug_print("NS: Creating TL record: '%s'/'%s'\n", callinguser, friendlyname); contactlist_tldetails(CONTACT_SOURCE_RNG, callinguser, friendlyname, ONLINE_NLN); free(friendlyname); - + } - + authtype = routines_lindex(line, 3); if ( strcmp(authtype, "CKI") != 0 ) { @@ -1101,19 +1101,19 @@ static int msnprotocol_parseline(char *line) { return 0; } - free(authtype); + free(authtype); sbsessions_create_remote(callinguser, switchboardaddress, sessionid, authchallenge); free(callinguser); free(switchboardaddress); free(authchallenge); free(sessionid); - + } - + if ( strcmp("MSG", instr) == 0 ) { - + char *length; - + length = routines_lindex(line, 3); cstate.expect_length = atoi(length); free(length); @@ -1123,13 +1123,13 @@ static int msnprotocol_parseline(char *line) { } else { debug_print("NS: Zero-sized MSG??\n"); } - + } if ( strcmp("UBX", instr) == 0 ) { - + char *length; - + length = routines_lindex(line, 2); cstate.expect_length = atoi(length); free(length); @@ -1139,13 +1139,13 @@ static int msnprotocol_parseline(char *line) { } else { debug_print("NS: Zero-sized UBX??\n"); /* This seems to happen sometimes. */ } - + } - + if ( strcmp("NOT", instr) == 0 ) { - + char *length; - + length = routines_lindex(line, 1); cstate.expect_length = atoi(length); free(length); @@ -1154,14 +1154,14 @@ static int msnprotocol_parseline(char *line) { } else { debug_print("NS: Zero-sized NOT??\n"); } - + } if ( strcmp("GCF", instr) == 0 ) { - + char *length; char *file; - + length = routines_lindex(line, 3); file = routines_lindex(line, 2); cstate.expect_length = atoi(length); @@ -1176,25 +1176,25 @@ static int msnprotocol_parseline(char *line) { debug_print("NS: Zero-sized GCF??\n"); } free(file); - + } if ( strcmp("CHG", instr) == 0 ) { - + OnlineState old_state = cstate.status; - + char *state = routines_lindex(line, 2); cstate.status = msngenerics_decodestatus(state); free(state); - + if ( (old_state == ONLINE_HDN) && (cstate.status != ONLINE_HDN) ) { messagewindow_enable_all(); } - + } free(instr); - + return 0; } @@ -1209,7 +1209,7 @@ static void msnprotocol_parsemsg(const char *msg, size_t msglen) { static void msnprotocol_parseubx(const char *msg, size_t msglen) { debug_print("NS: Got UBX data for '%s' (%i bytes) '%s'\n", cstate.msg_source, msglen, msg); - contactlist_setubx(cstate.msg_source, msg, msglen); + contactlist_setubx(cstate.msg_source, msg, msglen); free(cstate.msg_source); } @@ -1243,13 +1243,13 @@ static void msnprotocol_readable() { if ( (rlen == 0) || (rlen == -1) ) { int closeval; - + closeval = close(cstate.socket); - + if ( closeval != 0 ) { debug_print("NS: Couldn't close socket after read error.\n"); } - + /* A variety of ways to express this to the user... */ if ( cstate.connected == CSTATE_CONNECTED ) { if ( !cstate.disconnect_expected ) { @@ -1264,75 +1264,75 @@ static void msnprotocol_readable() { error_report("Read error in unrecognised connection state. This never happens :P"); debug_print("NS: Connection state %i\n", cstate.connected); } - + msnprotocol_cleanup(); return; - + } - + while ( (!no_string) && (cstate.roffset > 0) ) { - + int block_ready = 0; size_t i = 0; /* See if there's a full "block" in the buffer yet */ if ( cstate.conmode == NSCONMODE_LINE ) { - + for ( i=0; i= cstate.expect_length ) { i = cstate.expect_length - 2; block_ready = 1; } - + } else if ( cstate.conmode == NSCONMODE_UBX ) { - + if ( cstate.roffset >= cstate.expect_length ) { i = cstate.expect_length - 2; block_ready = 1; } - + } else if ( cstate.conmode == NSCONMODE_NOT ) { - + if ( cstate.roffset >= cstate.expect_length ) { i = cstate.expect_length - 2; block_ready = 1; } - + } else if ( cstate.conmode == NSCONMODE_GCF_SHIELDS ) { - + if ( cstate.roffset >= cstate.expect_length ) { i = cstate.expect_length - 2; block_ready = 1; } - + } else { /* "Never happens". */ debug_print("NS: Can't determine end of block for NsConMode %i!\n", cstate.conmode); } - + if ( block_ready == 1 ) { - + char *block_buffer = NULL; unsigned int new_rbufsize; unsigned int endbit_length; NSConMode next_mode = cstate.conmode; - + if ( cstate.conmode == NSCONMODE_LINE ) { assert(cstate.rbuffer[i] == '\r'); assert(cstate.rbuffer[i+1] == '\n'); } - - + + if ( cstate.conmode == NSCONMODE_LINE ) { - + block_buffer = malloc(i+1); memcpy(block_buffer, cstate.rbuffer, i); block_buffer[i] = '\0'; @@ -1342,55 +1342,55 @@ static void msnprotocol_readable() { free(block_buffer); return; } - + /* Check to see if sbprotocol_parseline changed the mode. If so, make sure it stays changed. */ if ( cstate.conmode != NSCONMODE_LINE ) { next_mode = cstate.conmode; } - + } else if ( cstate.conmode == NSCONMODE_MSG ) { - + block_buffer = malloc(i+3); /* Exactly the number of bytes we were told to expect, plus one for terminator. */ memcpy(block_buffer, cstate.rbuffer, i+2); /* Copy it in */ block_buffer[i+2] = '\0'; /* Terminate */ - + msnprotocol_parsemsg(block_buffer, i+2); next_mode = NSCONMODE_LINE; - + } else if ( cstate.conmode == NSCONMODE_UBX ) { - + block_buffer = malloc(i+3); /* Exactly the number of bytes we were told to expect, plus one for terminator. */ memcpy(block_buffer, cstate.rbuffer, i+2); /* Copy it in */ block_buffer[i+2] = '\0'; /* Terminate */ - + msnprotocol_parseubx(block_buffer, i+2); next_mode = NSCONMODE_LINE; - + } else if ( cstate.conmode == NSCONMODE_NOT ) { - + block_buffer = malloc(i+3); /* Exactly the number of bytes we were told to expect, plus one for terminator. */ memcpy(block_buffer, cstate.rbuffer, i+2); /* Copy it in */ block_buffer[i+2] = '\0'; /* Terminate */ - + msnprotocol_parsenotification(block_buffer, i+2); next_mode = NSCONMODE_LINE; - + } else if ( cstate.conmode == NSCONMODE_GCF_SHIELDS ) { - + block_buffer = malloc(i+3); /* Exactly the number of bytes we were told to expect, plus one for terminator. */ memcpy(block_buffer, cstate.rbuffer, i+2); /* Copy it in */ block_buffer[i+2] = '\0'; /* Terminate */ - + msnprotocol_parseshields(block_buffer, i+2); next_mode = NSCONMODE_LINE; - + } else { debug_print("NS: No handler for NsConMode %i !\n", cstate.conmode); } - + free(block_buffer); - + /* Now the block's been parsed, it should be forgotten about */ if ( cstate.conmode == NSCONMODE_LINE ) { assert(cstate.rbuffer[i+1] == '\n'); /* Should still be the case. Paranoid. */ @@ -1405,19 +1405,19 @@ static void msnprotocol_readable() { cstate.rbuffer = realloc(cstate.rbuffer, new_rbufsize); cstate.rbufsize = new_rbufsize; cstate.conmode = next_mode; - + } else { if ( cstate.roffset == cstate.rbufsize ) { - + /* More buffer space is needed */ cstate.rbuffer = realloc(cstate.rbuffer, cstate.rbufsize + 32); cstate.rbufsize = cstate.rbufsize + 32; /* The new space gets used at the next read, shortly... */ - + } no_string = 1; - + } } @@ -1430,7 +1430,7 @@ int msnprotocol_signedin() { if ( cstate.connected == CSTATE_CONNECTED ) { return 1; } - + return 0; } @@ -1441,7 +1441,7 @@ int msnprotocol_disconnected() { if ( cstate.connected == CSTATE_DISCONNECTED ) { return 1; } - + return 0; } @@ -1494,7 +1494,7 @@ void msnprotocol_connect(const char *hostname, unsigned short int port) { } sockopts = fcntl(cstate.socket, F_GETFL); fcntl(cstate.socket, F_SETFL, sockopts | O_NONBLOCK); - + /* Resolve the server name */ server = gethostbyname(hostname); if ( server == NULL ) { @@ -1502,7 +1502,7 @@ void msnprotocol_connect(const char *hostname, unsigned short int port) { msnprotocol_cleanup(); return; } - + memset(&sa_desc, 0, sizeof(sa_desc)); sa_desc.sin_family = AF_INET; memcpy(&sa_desc.sin_addr.s_addr, server->h_addr, server->h_length); @@ -1512,15 +1512,15 @@ void msnprotocol_connect(const char *hostname, unsigned short int port) { assert(cstate.rbuffer != NULL); cstate.rbufsize = 256; /* wbuffer starts at NULL and gets created when data is written */ - + conn_error = connect(cstate.socket, (struct sockaddr *)&sa_desc, sizeof(sa_desc)); if ( (conn_error < 0) && (errno != EINPROGRESS) ) { - + debug_print("NS: Couldn't connect to server - %i\n", errno); error_report("Couldn't connect to server"); msnprotocol_cleanup(); return; - + } else { cstate.wcallback = gdk_input_add(cstate.socket, GDK_INPUT_WRITE, (GdkInputFunction) msnprotocol_ready, NULL); } @@ -1538,7 +1538,7 @@ void msnprotocol_setstatus(OnlineState newstatus) { char *dpobj; char *string; unsigned int clientid; - + /* Don't change status too early (MSN server bug) unless signing out */ if ( (cstate.connected != CSTATE_CONNECTED) && (newstatus != ONLINE_FLN) ) { debug_print("NS: Not ready for status change - aborting.\n"); @@ -1549,7 +1549,7 @@ void msnprotocol_setstatus(OnlineState newstatus) { mode = "NLN"; /* Fallback */ switch ( newstatus ) { - + case ONLINE_NLN : mode = "NLN"; break; case ONLINE_AWY : mode = "AWY"; break; case ONLINE_BSY : mode = "BSY"; break; @@ -1566,7 +1566,7 @@ void msnprotocol_setstatus(OnlineState newstatus) { case ONLINE_ERR : mode = "NLN"; break; case ONLINE_IDL : mode = "AWY"; break; case ONLINE_FLN : { - + msnprotocol_sendtr("OUT", ""); if ( cstate.connected == CSTATE_CONNECTED ) { listcache_save(); @@ -1576,16 +1576,16 @@ void msnprotocol_setstatus(OnlineState newstatus) { cstate.disconnect_callback = gtk_timeout_add(10000, (GtkFunction)msnprotocol_forcedisconnect, NULL); } return; - + } - + } - + clientid = 0x50000000 + (1<<5) + (1<<3) + (1<<2); /* MSNC5, Multipacketing (bit 5), Ink (bits 2 and 3) */ capabilities = malloc(12); sprintf(capabilities, "%i", clientid); dpobj = avatars_localobject(); - + string = malloc(strlen(mode) + strlen(capabilities) + strlen(dpobj) + 3); strcpy(string, mode); strcat(string, " "); @@ -1593,11 +1593,11 @@ void msnprotocol_setstatus(OnlineState newstatus) { strcat(string, " "); strcat(string, dpobj); free(dpobj); - + msnprotocol_sendtr("CHG", string); free(string); free(capabilities); - + messagewindow_picturekick(NULL); } @@ -1617,14 +1617,14 @@ void msnprotocol_setmfn(const char *new_mfn) { char *mfn_string; char *mfn_code; - + mfn_code = routines_urlencode(new_mfn); mfn_string = malloc(strlen(mfn_code)+5); strcpy(mfn_string, "MFN "); strcat(mfn_string, mfn_code); msnprotocol_sendtr("PRP", mfn_string); - + free(mfn_string); } @@ -1633,11 +1633,11 @@ void msnprotocol_setcsm(const char *new_csm) { const char *template; char *uuxblock; char *sendage; - + if ( cstate.protocol_version >= 11 ) { template = ""; uuxblock = xml_setblock(template, strlen(template), "Data", "PSM", new_csm); - + sendage = malloc(strlen(uuxblock)+8); assert(strlen(uuxblock)<=99999); /* 5 chars max. */ sprintf(sendage, "%i\r\n%s", strlen(uuxblock), uuxblock); diff --git a/src/routines.c b/src/routines.c index 8ce937b..9e8de98 100644 --- a/src/routines.c +++ b/src/routines.c @@ -8,17 +8,17 @@ * * This package is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 dated June, 1991. + * the Free Software Foundation; version 2 dated June, 1991. * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this package; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * 02111-1307, USA. * */ @@ -71,11 +71,11 @@ char *routines_lindex(char *string, unsigned int pos) { char *minibuffer; unsigned int max_output_length = strlen(string); for ( i=0; i> 2; base64_output[j++] = routines_base64char(sextet); - + /* Second sextet */ sextet = ((base64_input[i] & 0x3) << 4) + ((base64_input[i+1] & 0xf0) >> 4); base64_output[j++] = routines_base64char(sextet); - + /* Third sextet */ sextet = ((base64_input[i+1] & 0x0f) << 2) + ((base64_input[i+2] & 0xc0) >> 6); base64_output[j++] = routines_base64char(sextet); - + /* Fourth sextet */ sextet = (base64_input[i+2] & 0x3f); base64_output[j++] = routines_base64char(sextet); - + } - + switch ((length) % 3) { - + case 1 : { - + /* One byte left over */ i = length-1; - + sextet = (base64_input[i] & 0xfc) >> 2; base64_output[j++] = routines_base64char(sextet); - + sextet = (base64_input[i] & 0x03) << 4; base64_output[j++] = routines_base64char(sextet); - + base64_output[j++] = '='; base64_output[j++] = '='; - + break; - + } - + case 2 : { - + /* Two bytes left over */ i = length-2; - + sextet = (base64_input[i] & 0xfc) >> 2; base64_output[j++] = routines_base64char(sextet); - + sextet = ((base64_input[i] & 0x3) << 4) + ((base64_input[i+1] & 0xf0) >> 4); base64_output[j++] = routines_base64char(sextet); - + sextet = (base64_input[i+1] & 0x0f) << 2; base64_output[j++] = routines_base64char(sextet); - + base64_output[j++] = '='; - + break; - + } - + } - + base64_output[j++] = '\0'; - + return base64_output; } @@ -605,25 +605,25 @@ size_t routines_base64decode(const char *base64_input, char **output) { char *op = malloc(strlen(base64_input)); assert(strlen(base64_input) % 4 == 0 ); - + while ( ptr < strlen(base64_input) ) { - + op[len] = (routines_unbase64char(base64_input[ptr]) << 2) + ((routines_unbase64char(base64_input[ptr+1]) & 48) >> 4); op[len+1] = ((routines_unbase64char(base64_input[ptr+1]) & 15) << 4) + ((routines_unbase64char(base64_input[ptr+2]) & 60) >> 2); op[len+2] = ((routines_unbase64char(base64_input[ptr+2]) & 3) << 6) + routines_unbase64char(base64_input[ptr+3]); - + len+=3; ptr+=4; - + } - + if ( base64_input[ptr-1] == '=' ) { len--; } if ( base64_input[ptr-2] == '=' ) { len--; } - + *output = op; return len; @@ -633,13 +633,13 @@ static char *routines_randomhexbyte() { int j; char *response = malloc(3); - + /* Taken from the "rand()" man page. */ j = 1 +(int)(256.0*rand()/(RAND_MAX+1.0)); sprintf(response, "%2hhx", j); - + return response; - + } /* Generate a GUID */ @@ -647,56 +647,56 @@ char *routines_guid() { int i, k; char *guid; - + guid = malloc(39); assert(guid != NULL); strcpy(guid, "{"); - + for ( i=0; i<4; i++ ) { - + char *byte; byte = routines_randomhexbyte(); strncat(guid, byte, 2); free(byte); - + } - + for ( k=0; k<3; k++ ) { strcat(guid, "-"); for ( i=0; i<2; i++ ) { - + char *byte; byte = routines_randomhexbyte(); strncat(guid, byte, 2); free(byte); - + } } - + /* To be a valid GUID, the version and variant fields need to be set appropriately. */ guid[15] = '4'; guid[20] = 'a'; - + strcat(guid, "-"); for ( i=0; i<6; i++ ) { - + char *byte; byte = routines_randomhexbyte(); strncat(guid, byte, 2); free(byte); - + } strcat(guid, "}"); - + /* Fix up spaces. */ for ( i=0; i<(strlen(guid)-1); i++ ) { if ( guid[i] == ' ' ) { guid[i] = '0'; } } - + return guid; } @@ -707,7 +707,7 @@ char *routines_killtriangles(const char *input) { char *output; size_t i; size_t j = 0; - + output = malloc(2*strlen(input)+1); for ( i=0; i<=strlen(input); i++ ) { if ( input[i] == '<' ) { @@ -735,7 +735,7 @@ char *routines_killtriangles_and_ampersands(const char *input) { char *output; size_t i; size_t j = 0; - + output = malloc(2*strlen(input)+1); for ( i=0; i<=strlen(input); i++ ) { if ( input[i] == '<' ) { @@ -769,27 +769,27 @@ char *routines_flipcolour(const char *colour) { char scratch; strncpy(flipped, colour, 6); flipped[6] = '\0'; - + scratch = flipped[0]; flipped[0] = flipped[4]; flipped[4] = scratch; - + scratch = flipped[1]; flipped[1] = flipped[5]; flipped[5] = scratch; - + return flipped; } char *routines_gdk_to_hashrgb(const GdkColor *colour) { - + char *string; - + if ( colour == NULL ) { return NULL; } - + string = malloc(8); /* RGB order */ snprintf(string, 8, "#%02hhx%02hhx%02hhx", colour->red >> 8, colour->green >> 8, colour->blue >> 8); -- cgit v1.2.3