Changeset 5adcc65


Ignore:
Timestamp:
2008-12-21T20:51:12Z (15 years ago)
Author:
Miklos Vajna <vmiklos@…>
Branches:
master
Children:
a349932
Parents:
a5f4040
Message:

whitespace cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skype/skype.c

    ra5f4040 r5adcc65  
    11/*
    22 *  skype.c - Skype plugin for BitlBee
    3  * 
     3 *
    44 *  Copyright (c) 2007, 2008 by Miklos Vajna <vmiklos@frugalware.org>
    55 *
     
    77 *
    88 *  Copyright (c) 2006 by Wilmer van der Gaast <wilmer@gaast.net>
    9  * 
     9 *
    1010 *  This program is free software; you can redistribute it and/or modify
    1111 *  it under the terms of the GNU General Public License as published by
     
    2020 *  You should have received a copy of the GNU General Public License
    2121 *  along with this program; if not, write to the Free Software
    22  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
     22 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    2323 *  USA.
    2424 */
     
    3838 */
    3939
    40 typedef enum
    41 {
     40typedef enum {
    4241        SKYPE_CALL_RINGING = 1,
    4342        SKYPE_CALL_MISSED,
     
    4746} skype_call_status;
    4847
    49 typedef enum
    50 {
     48typedef enum {
    5149        SKYPE_FILETRANSFER_NEW = 1,
    5250        SKYPE_FILETRANSFER_FAILED
     
    5755 */
    5856
    59 struct skype_data
    60 {
     57struct skype_data {
    6158        struct im_connection *ic;
    6259        char *username;
     
    8885        /* Using /j #nick we want to have a groupchat with two people. Usually
    8986         * not (default). */
    90         char* groupchat_with;
     87        char *groupchat_with;
    9188        /* The user who invited us to the chat. */
    92         char* adder;
     89        char *adder;
    9390        /* If we are waiting for a confirmation about we changed the topic. */
    9491        int topic_wait;
     
    114111};
    115112
    116 struct skype_away_state
    117 {
     113struct skype_away_state {
    118114        char *code;
    119115        char *full_name;
    120116};
    121117
    122 struct skype_buddy_ask_data
    123 {
     118struct skype_buddy_ask_data {
    124119        struct im_connection *ic;
    125120        /* This is also used for call IDs for simplicity */
     
    131126 */
    132127
    133 const struct skype_away_state skype_away_state_list[] =
    134 {
     128const struct skype_away_state skype_away_state_list[] = {
    135129        { "ONLINE",  "Online" },
    136130        { "SKYPEME",  "Skype Me" },
     
    147141 */
    148142
    149 int skype_write( struct im_connection *ic, char *buf )
     143int skype_write(struct im_connection *ic, char *buf)
    150144{
    151145        struct skype_data *sd = ic->proto_data;
     
    159153         * sd->fd. */
    160154        poll(pfd, 1, 1000);
    161         if(pfd[0].revents & POLLHUP)
    162         {
    163                 imc_logout( ic, TRUE );
     155        if (pfd[0].revents & POLLHUP) {
     156                imc_logout(ic, TRUE);
    164157                return FALSE;
    165158        }
    166         ssl_write( sd->ssl, buf, len );
     159        ssl_write(sd->ssl, buf, len);
    167160
    168161        return TRUE;
    169162}
    170163
    171 static void skype_buddy_ask_yes( void *data )
     164static void skype_buddy_ask_yes(void *data)
    172165{
    173166        struct skype_buddy_ask_data *bla = data;
    174167        char *buf = g_strdup_printf("SET USER %s ISAUTHORIZED TRUE", bla->handle);
    175         skype_write( bla->ic, buf );
     168        skype_write(bla->ic, buf);
    176169        g_free(buf);
    177170        g_free(bla->handle);
     
    179172}
    180173
    181 static void skype_buddy_ask_no( void *data )
     174static void skype_buddy_ask_no(void *data)
    182175{
    183176        struct skype_buddy_ask_data *bla = data;
    184177        char *buf = g_strdup_printf("SET USER %s ISAUTHORIZED FALSE", bla->handle);
    185         skype_write( bla->ic, buf );
     178        skype_write(bla->ic, buf);
    186179        g_free(buf);
    187180        g_free(bla->handle);
     
    189182}
    190183
    191 void skype_buddy_ask( struct im_connection *ic, char *handle, char *message)
    192 {
    193         struct skype_buddy_ask_data *bla = g_new0( struct skype_buddy_ask_data, 1 );
     184void skype_buddy_ask(struct im_connection *ic, char *handle, char *message)
     185{
     186        struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, 1);
    194187        char *buf;
    195188
     
    197190        bla->handle = g_strdup(handle);
    198191
    199         buf = g_strdup_printf( "The user %s wants to add you to his/her buddy list, saying: '%s'.", handle, message);
    200         imcb_ask( ic, buf, bla, skype_buddy_ask_yes, skype_buddy_ask_no );
    201         g_free( buf );
    202 }
    203 
    204 static void skype_call_ask_yes( void *data )
     192        buf = g_strdup_printf("The user %s wants to add you to his/her buddy list, saying: '%s'.", handle, message);
     193        imcb_ask(ic, buf, bla, skype_buddy_ask_yes, skype_buddy_ask_no);
     194        g_free(buf);
     195}
     196
     197static void skype_call_ask_yes(void *data)
    205198{
    206199        struct skype_buddy_ask_data *bla = data;
    207200        char *buf = g_strdup_printf("SET CALL %s STATUS INPROGRESS", bla->handle);
    208         skype_write( bla->ic, buf );
     201        skype_write(bla->ic, buf);
    209202        g_free(buf);
    210203        g_free(bla->handle);
     
    212205}
    213206
    214 static void skype_call_ask_no( void *data )
     207static void skype_call_ask_no(void *data)
    215208{
    216209        struct skype_buddy_ask_data *bla = data;
    217210        char *buf = g_strdup_printf("SET CALL %s STATUS FINISHED", bla->handle);
    218         skype_write( bla->ic, buf );
     211        skype_write(bla->ic, buf);
    219212        g_free(buf);
    220213        g_free(bla->handle);
     
    222215}
    223216
    224 void skype_call_ask( struct im_connection *ic, char *call_id, char *message)
    225 {
    226         struct skype_buddy_ask_data *bla = g_new0( struct skype_buddy_ask_data, 1 );
     217void skype_call_ask(struct im_connection *ic, char *call_id, char *message)
     218{
     219        struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, 1);
    227220
    228221        bla->ic = ic;
    229222        bla->handle = g_strdup(call_id);
    230223
    231         imcb_ask( ic, message, bla, skype_call_ask_yes, skype_call_ask_no );
    232 }
    233 struct groupchat *skype_chat_by_name( struct im_connection *ic, char *name )
     224        imcb_ask(ic, message, bla, skype_call_ask_yes, skype_call_ask_no);
     225}
     226struct groupchat *skype_chat_by_name(struct im_connection *ic, char *name)
    234227{
    235228        struct groupchat *ret;
    236229
    237         for( ret = ic->groupchats; ret; ret = ret->next )
    238         {
    239                 if(strcmp(name, ret->title ) == 0 )
     230        for (ret = ic->groupchats; ret; ret = ret->next)
     231                if (strcmp(name, ret->title) == 0)
    240232                        break;
     233
     234        return ret;
     235}
     236
     237static char *skype_call_strerror(int err)
     238{
     239        switch (err) {
     240        case 1:
     241                return "Miscellaneous error";
     242        case 2:
     243                return "User or phone number does not exist.";
     244        case 3:
     245                return "User is offline";
     246        case 4:
     247                return "No proxy found";
     248        case 5:
     249                return "Session terminated.";
     250        case 6:
     251                return "No common codec found.";
     252        case 7:
     253                return "Sound I/O error.";
     254        case 8:
     255                return "Problem with remote sound device.";
     256        case 9:
     257                return "Call blocked by recipient.";
     258        case 10:
     259                return "Recipient not a friend.";
     260        case 11:
     261                return "Current user not authorized by recipient.";
     262        case 12:
     263                return "Sound recording error.";
     264        default:
     265                return "Unknown error";
    241266        }
    242 
    243         return ret;
    244 }
    245 
    246 static char *skype_call_strerror(int err)
    247 {
    248         switch(err) {
    249                 case 1:
    250                         return "Miscellaneous error";
    251                 case 2:
    252                         return "User or phone number does not exist.";
    253                 case 3:
    254                         return "User is offline";
    255                 case 4:
    256                         return "No proxy found";
    257                 case 5:
    258                         return "Session terminated.";
    259                 case 6:
    260                         return "No common codec found.";
    261                 case 7:
    262                         return "Sound I/O error.";
    263                 case 8:
    264                         return "Problem with remote sound device.";
    265                 case 9:
    266                         return "Call blocked by recipient.";
    267                 case 10:
    268                         return "Recipient not a friend.";
    269                 case 11:
    270                         return "Current user not authorized by recipient.";
    271                 case 12:
    272                         return "Sound recording error.";
    273                 default:
    274                         return "Unknown error";
    275         }
    276 }
    277 
    278 static gboolean skype_read_callback( gpointer data, gint fd, b_input_condition cond )
     267}
     268
     269static gboolean skype_read_callback(gpointer data, gint fd, b_input_condition cond)
    279270{
    280271        struct im_connection *ic = data;
     
    284275        char **lines, **lineptr, *line, *ptr;
    285276
    286         if( !sd || sd->fd == -1 )
     277        if (!sd || sd->fd == -1)
    287278                return FALSE;
    288279        /* Read the whole data. */
    289         st = ssl_read( sd->ssl, buf, sizeof( buf ) );
    290         if( st > 0 )
    291         {
     280        st = ssl_read(sd->ssl, buf, sizeof(buf));
     281        if (st > 0) {
    292282                buf[st] = '\0';
    293283                /* Then split it up to lines. */
    294284                lines = g_strsplit(buf, "\n", 0);
    295285                lineptr = lines;
    296                 while((line = *lineptr))
    297                 {
    298                         if(!strlen(line))
     286                while ((line = *lineptr)) {
     287                        if (!strlen(line))
    299288                                break;
    300                         if(!strncmp(line, "USERS ", 6))
    301                         {
     289                        if (!strncmp(line, "USERS ", 6)) {
    302290                                char **i;
    303291                                char **nicks;
     
    305293                                nicks = g_strsplit(line + 6, ", ", 0);
    306294                                i = nicks;
    307                                 while(*i)
    308                                 {
     295                                while (*i) {
    309296                                        g_snprintf(buf, 1024, "GET USER %s ONLINESTATUS\n", *i);
    310                                         skype_write( ic, buf );
     297                                        skype_write(ic, buf);
    311298                                        i++;
    312299                                }
    313300                                g_strfreev(nicks);
    314                         }
    315                         else if(!strncmp(line, "USER ", 5))
    316                         {
     301                        } else if (!strncmp(line, "USER ", 5)) {
    317302                                int flags = 0;
    318303                                char *status = strrchr(line, ' ');
     
    322307                                *ptr = '\0';
    323308                                ptr++;
    324                                 if(!strncmp(ptr, "ONLINESTATUS ", 13) &&
     309                                if (!strncmp(ptr, "ONLINESTATUS ", 13) &&
    325310                                                strcmp(user, sd->username) != 0
    326                                                 && strcmp(user, "echo123") != 0)
    327                                 {
     311                                                && strcmp(user, "echo123") != 0) {
    328312                                        ptr = g_strdup_printf("%s@skype.com", user);
    329313                                        imcb_add_buddy(ic, ptr, NULL);
    330                                         if(strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || !set_getbool(&ic->acc->set, "skypeout_offline")))
     314                                        if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || !set_getbool(&ic->acc->set, "skypeout_offline")))
    331315                                                flags |= OPT_LOGGED_IN;
    332                                         if(strcmp(status, "ONLINE") != 0 && strcmp(status, "SKYPEME") != 0)
     316                                        if (strcmp(status, "ONLINE") != 0 && strcmp(status, "SKYPEME") != 0)
    333317                                                flags |= OPT_AWAY;
    334318                                        imcb_buddy_status(ic, ptr, flags, NULL, NULL);
    335319                                        g_free(ptr);
    336                                 }
    337                                 else if(!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20))
    338                                 {
     320                                } else if (!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) {
    339321                                        char *message = ptr + 20;
    340                                         if(strlen(message))
     322                                        if (strlen(message))
    341323                                                skype_buddy_ask(ic, user, message);
    342                                 }
    343                                 else if(!strncmp(ptr, "BUDDYSTATUS ", 12))
    344                                 {
     324                                } else if (!strncmp(ptr, "BUDDYSTATUS ", 12)) {
    345325                                        char *st = ptr + 12;
    346                                         if(!strcmp(st, "3"))
    347                                         {
     326                                        if (!strcmp(st, "3")) {
    348327                                                char *buf = g_strdup_printf("%s@skype.com", user);
    349328                                                imcb_add_buddy(ic, buf, NULL);
    350329                                                g_free(buf);
    351330                                        }
    352                                 }
    353                                 else if(!strncmp(ptr, "FULLNAME ", 9))
     331                                } else if (!strncmp(ptr, "FULLNAME ", 9))
    354332                                        sd->info_fullname = g_strdup_printf("%s", ptr + 9);
    355                                 else if(!strncmp(ptr, "PHONE_HOME ", 11))
     333                                else if (!strncmp(ptr, "PHONE_HOME ", 11))
    356334                                        sd->info_phonehome = g_strdup_printf("%s", ptr + 11);
    357                                 else if(!strncmp(ptr, "PHONE_OFFICE ", 13))
     335                                else if (!strncmp(ptr, "PHONE_OFFICE ", 13))
    358336                                        sd->info_phoneoffice = g_strdup_printf("%s", ptr + 13);
    359                                 else if(!strncmp(ptr, "PHONE_MOBILE ", 13))
     337                                else if (!strncmp(ptr, "PHONE_MOBILE ", 13))
    360338                                        sd->info_phonemobile = g_strdup_printf("%s", ptr + 13);
    361                                 else if(!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20))
     339                                else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20))
    362340                                        sd->info_nrbuddies = g_strdup_printf("%s", ptr + 20);
    363                                 else if(!strncmp(ptr, "TIMEZONE ", 9))
     341                                else if (!strncmp(ptr, "TIMEZONE ", 9))
    364342                                        sd->info_tz = g_strdup_printf("%s", ptr + 9);
    365                                 else if(!strncmp(ptr, "LASTONLINETIMESTAMP ", 20))
     343                                else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20))
    366344                                        sd->info_seen = g_strdup_printf("%s", ptr + 20);
    367                                 else if(!strncmp(ptr, "BIRTHDAY ", 9))
     345                                else if (!strncmp(ptr, "BIRTHDAY ", 9))
    368346                                        sd->info_birthday = g_strdup_printf("%s", ptr + 9);
    369                                 else if(!strncmp(ptr, "SEX ", 4))
     347                                else if (!strncmp(ptr, "SEX ", 4))
    370348                                        sd->info_sex = g_strdup_printf("%s", ptr + 4);
    371                                 else if(!strncmp(ptr, "LANGUAGE ", 9))
     349                                else if (!strncmp(ptr, "LANGUAGE ", 9))
    372350                                        sd->info_language = g_strdup_printf("%s", ptr + 9);
    373                                 else if(!strncmp(ptr, "COUNTRY ", 8))
     351                                else if (!strncmp(ptr, "COUNTRY ", 8))
    374352                                        sd->info_country = g_strdup_printf("%s", ptr + 8);
    375                                 else if(!strncmp(ptr, "PROVINCE ", 9))
     353                                else if (!strncmp(ptr, "PROVINCE ", 9))
    376354                                        sd->info_province = g_strdup_printf("%s", ptr + 9);
    377                                 else if(!strncmp(ptr, "CITY ", 5))
     355                                else if (!strncmp(ptr, "CITY ", 5))
    378356                                        sd->info_city = g_strdup_printf("%s", ptr + 5);
    379                                 else if(!strncmp(ptr, "HOMEPAGE ", 9))
     357                                else if (!strncmp(ptr, "HOMEPAGE ", 9))
    380358                                        sd->info_homepage = g_strdup_printf("%s", ptr + 9);
    381                                 else if(!strncmp(ptr, "ABOUT ", 6))
    382                                 {
     359                                else if (!strncmp(ptr, "ABOUT ", 6)) {
    383360                                        sd->info_about = g_strdup_printf("%s", ptr + 6);
    384361
    385362                                        GString *st = g_string_new("Contact Information\n");
    386363                                        g_string_append_printf(st, "Skype Name: %s\n", user);
    387                                         if(sd->info_fullname)
    388                                         {
    389                                                 if(strlen(sd->info_fullname))
     364                                        if (sd->info_fullname) {
     365                                                if (strlen(sd->info_fullname))
    390366                                                        g_string_append_printf(st, "Full Name: %s\n", sd->info_fullname);
    391367                                                g_free(sd->info_fullname);
    392368                                        }
    393                                         if(sd->info_phonehome)
    394                                         {
    395                                                 if(strlen(sd->info_phonehome))
     369                                        if (sd->info_phonehome) {
     370                                                if (strlen(sd->info_phonehome))
    396371                                                        g_string_append_printf(st, "Home Phone: %s\n", sd->info_phonehome);
    397372                                                g_free(sd->info_phonehome);
    398373                                        }
    399                                         if(sd->info_phoneoffice)
    400                                         {
    401                                                 if(strlen(sd->info_phoneoffice))
     374                                        if (sd->info_phoneoffice) {
     375                                                if (strlen(sd->info_phoneoffice))
    402376                                                        g_string_append_printf(st, "Office Phone: %s\n", sd->info_phoneoffice);
    403377                                                g_free(sd->info_phoneoffice);
    404378                                        }
    405                                         if(sd->info_phonemobile)
    406                                         {
    407                                                 if(strlen(sd->info_phonemobile))
     379                                        if (sd->info_phonemobile) {
     380                                                if (strlen(sd->info_phonemobile))
    408381                                                        g_string_append_printf(st, "Mobile Phone: %s\n", sd->info_phonemobile);
    409382                                                g_free(sd->info_phonemobile);
    410383                                        }
    411384                                        g_string_append_printf(st, "Personal Information\n");
    412                                         if(sd->info_nrbuddies)
    413                                         {
    414                                                 if(strlen(sd->info_nrbuddies))
     385                                        if (sd->info_nrbuddies) {
     386                                                if (strlen(sd->info_nrbuddies))
    415387                                                        g_string_append_printf(st, "Contacts: %s\n", sd->info_nrbuddies);
    416388                                                g_free(sd->info_nrbuddies);
    417389                                        }
    418                                         if(sd->info_tz)
    419                                         {
    420                                                 if(strlen(sd->info_tz))
    421                                                 {
     390                                        if (sd->info_tz) {
     391                                                if (strlen(sd->info_tz)) {
    422392                                                        char ib[256];
    423393                                                        time_t t = time(NULL);
     
    429399                                                g_free(sd->info_tz);
    430400                                        }
    431                                         if(sd->info_seen)
    432                                         {
    433                                                 if(strlen(sd->info_seen))
    434                                                 {
     401                                        if (sd->info_seen) {
     402                                                if (strlen(sd->info_seen)) {
    435403                                                        char ib[256];
    436404                                                        time_t it = atoi(sd->info_seen);
     
    441409                                                g_free(sd->info_seen);
    442410                                        }
    443                                         if(sd->info_birthday)
    444                                         {
    445                                                 if(strlen(sd->info_birthday) && strcmp(sd->info_birthday, "0"))
    446                                                 {
     411                                        if (sd->info_birthday) {
     412                                                if (strlen(sd->info_birthday) && strcmp(sd->info_birthday, "0")) {
    447413                                                        char ib[256];
    448414                                                        struct tm tm;
     
    459425                                                g_free(sd->info_birthday);
    460426                                        }
    461                                         if(sd->info_sex)
    462                                         {
    463                                                 if(strlen(sd->info_sex))
    464                                                 {
     427                                        if (sd->info_sex) {
     428                                                if (strlen(sd->info_sex)) {
    465429                                                        char *iptr = sd->info_sex;
    466                                                         while(*iptr++)
     430                                                        while (*iptr++)
    467431                                                                *iptr = tolower(*iptr);
    468432                                                        g_string_append_printf(st, "Gender: %s\n", sd->info_sex);
     
    470434                                                g_free(sd->info_sex);
    471435                                        }
    472                                         if(sd->info_language)
    473                                         {
    474                                                 if(strlen(sd->info_language))
    475                                                 {
     436                                        if (sd->info_language) {
     437                                                if (strlen(sd->info_language)) {
    476438                                                        char *iptr = strchr(sd->info_language, ' ');
    477                                                         if(iptr)
     439                                                        if (iptr)
    478440                                                                iptr++;
    479441                                                        else
     
    483445                                                g_free(sd->info_language);
    484446                                        }
    485                                         if(sd->info_country)
    486                                         {
    487                                                 if(strlen(sd->info_country))
    488                                                 {
     447                                        if (sd->info_country) {
     448                                                if (strlen(sd->info_country)) {
    489449                                                        char *iptr = strchr(sd->info_country, ' ');
    490                                                         if(iptr)
     450                                                        if (iptr)
    491451                                                                iptr++;
    492452                                                        else
     
    496456                                                g_free(sd->info_country);
    497457                                        }
    498                                         if(sd->info_province)
    499                                         {
    500                                                 if(strlen(sd->info_province))
     458                                        if (sd->info_province) {
     459                                                if (strlen(sd->info_province))
    501460                                                        g_string_append_printf(st, "Region: %s\n", sd->info_province);
    502461                                                g_free(sd->info_province);
    503462                                        }
    504                                         if(sd->info_city)
    505                                         {
    506                                                 if(strlen(sd->info_city))
     463                                        if (sd->info_city) {
     464                                                if (strlen(sd->info_city))
    507465                                                        g_string_append_printf(st, "City: %s\n", sd->info_city);
    508466                                                g_free(sd->info_city);
    509467                                        }
    510                                         if(sd->info_homepage)
    511                                         {
    512                                                 if(strlen(sd->info_homepage))
     468                                        if (sd->info_homepage) {
     469                                                if (strlen(sd->info_homepage))
    513470                                                        g_string_append_printf(st, "Homepage: %s\n", sd->info_homepage);
    514471                                                g_free(sd->info_homepage);
    515472                                        }
    516                                         if(sd->info_about)
    517                                         {
    518                                                 if(strlen(sd->info_about))
     473                                        if (sd->info_about) {
     474                                                if (strlen(sd->info_about))
    519475                                                        g_string_append_printf(st, "%s\n", sd->info_about);
    520476                                                g_free(sd->info_about);
     
    523479                                        g_string_free(st, TRUE);
    524480                                }
    525                         }
    526                         else if(!strncmp(line, "CHATMESSAGE ", 12))
    527                         {
     481                        } else if (!strncmp(line, "CHATMESSAGE ", 12)) {
    528482                                char *id = strchr(line, ' ');
    529                                 if(++id)
    530                                 {
     483                                if (++id) {
    531484                                        char *info = strchr(id, ' ');
    532485                                        *info = '\0';
    533486                                        info++;
    534                                         if(!strcmp(info, "STATUS RECEIVED"))
    535                                         {
     487                                        if (!strcmp(info, "STATUS RECEIVED")) {
    536488                                                /* New message ID:
    537489                                                 * (1) Request its from field
     
    541493                                                 */
    542494                                                g_snprintf(buf, 1024, "GET CHATMESSAGE %s FROM_HANDLE\n", id);
    543                                                 skype_write( ic, buf );
     495                                                skype_write(ic, buf);
    544496                                                g_snprintf(buf, 1024, "GET CHATMESSAGE %s BODY\n", id);
    545                                                 skype_write( ic, buf );
     497                                                skype_write(ic, buf);
    546498                                                g_snprintf(buf, 1024, "GET CHATMESSAGE %s TYPE\n", id);
    547                                                 skype_write( ic, buf );
     499                                                skype_write(ic, buf);
    548500                                                g_snprintf(buf, 1024, "GET CHATMESSAGE %s CHATNAME\n", id);
    549                                                 skype_write( ic, buf );
    550                                         }
    551                                         else if(!strncmp(info, "FROM_HANDLE ", 12))
    552                                         {
     501                                                skype_write(ic, buf);
     502                                        } else if (!strncmp(info, "FROM_HANDLE ", 12)) {
    553503                                                info += 12;
    554504                                                /* New from field value. Store
     
    558508                                                g_free(sd->handle);
    559509                                                sd->handle = g_strdup_printf("%s@skype.com", info);
    560                                         }
    561                                         else if(!strncmp(info, "EDITED_BY ", 10))
    562                                         {
     510                                        } else if (!strncmp(info, "EDITED_BY ", 10)) {
    563511                                                info += 10;
    564512                                                /* This is the same as
     
    569517                                                g_free(sd->handle);
    570518                                                sd->handle = g_strdup_printf("%s@skype.com", info);
    571                                         }
    572                                         else if(!strncmp(info, "BODY ", 5))
    573                                         {
     519                                        } else if (!strncmp(info, "BODY ", 5)) {
    574520                                                info += 5;
    575521                                                sd->body = g_list_append(sd->body, g_strdup(info));
    576                                         }
    577                                         else if(!strncmp(info, "TYPE ", 5))
    578                                         {
     522                                        }       else if (!strncmp(info, "TYPE ", 5)) {
    579523                                                info += 5;
    580524                                                g_free(sd->type);
    581525                                                sd->type = g_strdup(info);
    582                                         }
    583                                         else if(!strncmp(info, "CHATNAME ", 9))
    584                                         {
     526                                        } else if (!strncmp(info, "CHATNAME ", 9)) {
    585527                                                info += 9;
    586                                                 if(sd->handle && sd->body && sd->type)
    587                                                 {
     528                                                if (sd->handle && sd->body && sd->type) {
    588529                                                        struct groupchat *gc = skype_chat_by_name(ic, info);
    589530                                                        int i;
    590                                                         for(i=0;i<g_list_length(sd->body);i++)
    591                                                         {
     531                                                        for (i = 0; i < g_list_length(sd->body); i++) {
    592532                                                                char *body = g_list_nth_data(sd->body, i);
    593                                                                 if(!strcmp(sd->type, "SAID") || !strcmp(sd->type, "EMOTED"))
    594                                                                 {
     533                                                                if (!strcmp(sd->type, "SAID") || !strcmp(sd->type, "EMOTED")) {
    595534                                                                        char *st;
    596                                                                         if(!strcmp(sd->type, "SAID"))
     535                                                                        if (!strcmp(sd->type, "SAID"))
    597536                                                                                st = g_strdup(body);
    598537                                                                        else
    599                                                                         {
    600538                                                                                st = g_strdup_printf("/me %s", body);
    601                                                                         }
    602                                                                         if(!gc)
     539                                                                        if (!gc)
    603540                                                                                /* Private message */
    604541                                                                                imcb_buddy_msg(ic, sd->handle, st, 0, 0);
     
    607544                                                                                imcb_chat_msg(gc, sd->handle, st, 0, 0);
    608545                                                                        g_free(st);
    609                                                                 }
    610                                                                 else if(!strcmp(sd->type, "SETTOPIC"))
    611                                                                 {
    612                                                                         if(gc)
     546                                                                } else if (!strcmp(sd->type, "SETTOPIC")) {
     547                                                                        if (gc)
    613548                                                                                imcb_chat_topic(gc, sd->handle, body, 0);
    614                                                                 }
    615                                                                 else if(!strcmp(sd->type, "LEFT"))
    616                                                                 {
    617                                                                         if(gc)
     549                                                                } else if (!strcmp(sd->type, "LEFT")) {
     550                                                                        if (gc)
    618551                                                                                imcb_chat_remove_buddy(gc, sd->handle, NULL);
    619552                                                                }
     
    624557                                        }
    625558                                }
    626                         }
    627                         else if(!strncmp(line, "CALL ", 5))
    628                         {
     559                        } else if (!strncmp(line, "CALL ", 5)) {
    629560                                char *id = strchr(line, ' ');
    630                                 if(++id)
    631                                 {
     561                                if (++id) {
    632562                                        char *info = strchr(id, ' ');
    633563                                        *info = '\0';
    634564                                        info++;
    635                                         if(!strncmp(info, "FAILUREREASON ", 14))
     565                                        if (!strncmp(info, "FAILUREREASON ", 14))
    636566                                                sd->failurereason = atoi(strchr(info, ' '));
    637                                         else if(!strcmp(info, "STATUS RINGING"))
    638                                         {
    639                                                 if(sd->call_id)
     567                                        else if (!strcmp(info, "STATUS RINGING")) {
     568                                                if (sd->call_id)
    640569                                                        g_free(sd->call_id);
    641570                                                sd->call_id = g_strdup(id);
    642571                                                g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id);
    643                                                 skype_write( ic, buf );
     572                                                skype_write(ic, buf);
    644573                                                sd->call_status = SKYPE_CALL_RINGING;
    645                                         }
    646                                         else if(!strcmp(info, "STATUS MISSED"))
    647                                         {
     574                                        } else if (!strcmp(info, "STATUS MISSED")) {
    648575                                                g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id);
    649                                                 skype_write( ic, buf );
     576                                                skype_write(ic, buf);
    650577                                                sd->call_status = SKYPE_CALL_MISSED;
    651                                         }
    652                                         else if(!strcmp(info, "STATUS CANCELLED"))
    653                                         {
     578                                        } else if (!strcmp(info, "STATUS CANCELLED")) {
    654579                                                        g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id);
    655                                                         skype_write( ic, buf );
     580                                                        skype_write(ic, buf);
    656581                                                        sd->call_status = SKYPE_CALL_CANCELLED;
    657                                         }
    658                                         else if(!strcmp(info, "STATUS FINISHED"))
    659                                         {
     582                                        } else if (!strcmp(info, "STATUS FINISHED")) {
    660583                                                g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id);
    661                                                 skype_write( ic, buf );
     584                                                skype_write(ic, buf);
    662585                                                sd->call_status = SKYPE_CALL_FINISHED;
    663                                         }
    664                                         else if(!strcmp(info, "STATUS REFUSED"))
    665                                         {
     586                                        } else if (!strcmp(info, "STATUS REFUSED")) {
    666587                                                g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id);
    667                                                 skype_write( ic, buf );
     588                                                skype_write(ic, buf);
    668589                                                sd->call_status = SKYPE_CALL_REFUSED;
    669                                         }
    670                                         else if(!strcmp(info, "STATUS UNPLACED"))
    671                                         {
    672                                                 if(sd->call_id)
     590                                        } else if (!strcmp(info, "STATUS UNPLACED")) {
     591                                                if (sd->call_id)
    673592                                                        g_free(sd->call_id);
    674593                                                /* Save the ID for later usage (Cancel/Finish). */
    675594                                                sd->call_id = g_strdup(id);
    676595                                                sd->call_out = TRUE;
    677                                         }
    678                                         else if(!strcmp(info, "STATUS FAILED"))
    679                                         {
     596                                        } else if (!strcmp(info, "STATUS FAILED")) {
    680597                                                imcb_error(ic, "Call failed: %s", skype_call_strerror(sd->failurereason));
    681598                                                sd->call_id = NULL;
    682                                         }
    683                                         else if(!strncmp(info, "DURATION ", 9))
    684                                         {
    685                                                 if(sd->call_duration)
     599                                        } else if (!strncmp(info, "DURATION ", 9)) {
     600                                                if (sd->call_duration)
    686601                                                        g_free(sd->call_duration);
    687602                                                sd->call_duration = g_strdup(info+9);
    688                                         }
    689                                         else if(!strncmp(info, "PARTNER_HANDLE ", 15))
    690                                         {
     603                                        } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) {
    691604                                                info += 15;
    692                                                 if(sd->call_status) {
    693                                                         switch(sd->call_status)
    694                                                         {
    695                                                                 case SKYPE_CALL_RINGING:
    696                                                                         if(sd->call_out)
    697                                                                                 imcb_log(ic, "You are currently ringing the user %s.", info);
    698                                                                         else
    699                                                                         {
    700                                                                                 g_snprintf(buf, 1024, "The user %s is currently ringing you.", info);
    701                                                                                 skype_call_ask(ic, sd->call_id, buf);
    702                                                                         }
    703                                                                         break;
    704                                                                 case SKYPE_CALL_MISSED:
    705                                                                         imcb_log(ic, "You have missed a call from user %s.", info);
    706                                                                         break;
    707                                                                 case SKYPE_CALL_CANCELLED:
    708                                                                         imcb_log(ic, "You cancelled the call to the user %s.", info);
    709                                                                         sd->call_status = 0;
    710                                                                         sd->call_out = FALSE;
    711                                                                         break;
    712                                                                 case SKYPE_CALL_REFUSED:
    713                                                                         if(sd->call_out)
    714                                                                                 imcb_log(ic, "The user %s refused the call.", info);
    715                                                                         else
    716                                                                                 imcb_log(ic, "You refused the call from user %s.", info);
    717                                                                         sd->call_out = FALSE;
    718                                                                         break;
    719                                                                 case SKYPE_CALL_FINISHED:
    720                                                                         if(sd->call_duration)
    721                                                                                 imcb_log(ic, "You finished the call to the user %s (duration: %s seconds).", info, sd->call_duration);
    722                                                                         else
    723                                                                                 imcb_log(ic, "You finished the call to the user %s.", info);
    724                                                                         sd->call_out = FALSE;
    725                                                                         break;
    726                                                                 default:
    727                                                                         /* Don't be noisy, ignore other statuses for now. */
    728                                                                         break;
     605                                                if (sd->call_status) {
     606                                                        switch (sd->call_status) {
     607                                                        case SKYPE_CALL_RINGING:
     608                                                                if (sd->call_out)
     609                                                                        imcb_log(ic, "You are currently ringing the user %s.", info);
     610                                                                else {
     611                                                                        g_snprintf(buf, 1024, "The user %s is currently ringing you.", info);
     612                                                                        skype_call_ask(ic, sd->call_id, buf);
     613                                                                }
     614                                                                break;
     615                                                        case SKYPE_CALL_MISSED:
     616                                                                imcb_log(ic, "You have missed a call from user %s.", info);
     617                                                                break;
     618                                                        case SKYPE_CALL_CANCELLED:
     619                                                                imcb_log(ic, "You cancelled the call to the user %s.", info);
     620                                                                sd->call_status = 0;
     621                                                                sd->call_out = FALSE;
     622                                                                break;
     623                                                        case SKYPE_CALL_REFUSED:
     624                                                                if (sd->call_out)
     625                                                                        imcb_log(ic, "The user %s refused the call.", info);
     626                                                                else
     627                                                                        imcb_log(ic, "You refused the call from user %s.", info);
     628                                                                sd->call_out = FALSE;
     629                                                                break;
     630                                                        case SKYPE_CALL_FINISHED:
     631                                                                if (sd->call_duration)
     632                                                                        imcb_log(ic, "You finished the call to the user %s (duration: %s seconds).", info, sd->call_duration);
     633                                                                else
     634                                                                        imcb_log(ic, "You finished the call to the user %s.", info);
     635                                                                sd->call_out = FALSE;
     636                                                                break;
     637                                                        default:
     638                                                                /* Don't be noisy, ignore other statuses for now. */
     639                                                                break;
    729640                                                        }
    730641                                                        sd->call_status = 0;
     
    732643                                        }
    733644                                }
    734                         }
    735                         else if(!strncmp(line, "FILETRANSFER ", 13))
    736                         {
     645                        } else if (!strncmp(line, "FILETRANSFER ", 13)) {
    737646                                char *id = strchr(line, ' ');
    738                                 if(++id)
    739                                 {
     647                                if (++id) {
    740648                                        char *info = strchr(id, ' ');
    741649                                        *info = '\0';
    742650                                        info++;
    743                                         if(!strcmp(info, "STATUS NEW"))
    744                                         {
     651                                        if (!strcmp(info, "STATUS NEW")) {
    745652                                                g_snprintf(buf, 1024, "GET FILETRANSFER %s PARTNER_HANDLE\n", id);
    746                                                 skype_write( ic, buf );
     653                                                skype_write(ic, buf);
    747654                                                sd->filetransfer_status = SKYPE_FILETRANSFER_NEW;
    748                                         }
    749                                         else if(!strcmp(info, "STATUS FAILED"))
    750                                         {
     655                                        } else if (!strcmp(info, "STATUS FAILED")) {
    751656                                                g_snprintf(buf, 1024, "GET FILETRANSFER %s PARTNER_HANDLE\n", id);
    752                                                 skype_write( ic, buf );
     657                                                skype_write(ic, buf);
    753658                                                sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED;
    754                                         }
    755                                         else if(!strncmp(info, "PARTNER_HANDLE ", 15))
    756                                         {
     659                                        } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) {
    757660                                                info += 15;
    758                                                 if(sd->filetransfer_status) {
    759                                                         switch(sd->filetransfer_status)
    760                                                         {
    761                                                                 case SKYPE_FILETRANSFER_NEW:
    762                                                                         imcb_log(ic, "The user %s offered a new file for you.", info);
    763                                                                         break;
    764                                                                 case SKYPE_FILETRANSFER_FAILED:
    765                                                                         imcb_log(ic, "Failed to transfer file from user %s.", info);
    766                                                                         break;
     661                                                if (sd->filetransfer_status) {
     662                                                        switch (sd->filetransfer_status) {
     663                                                        case SKYPE_FILETRANSFER_NEW:
     664                                                                imcb_log(ic, "The user %s offered a new file for you.", info);
     665                                                                break;
     666                                                        case SKYPE_FILETRANSFER_FAILED:
     667                                                                imcb_log(ic, "Failed to transfer file from user %s.", info);
     668                                                                break;
    767669                                                        }
    768670                                                        sd->filetransfer_status = 0;
     
    770672                                        }
    771673                                }
    772                         }
    773                         else if(!strncmp(line, "CHAT ", 5))
    774                         {
     674                        } else if (!strncmp(line, "CHAT ", 5)) {
    775675                                char *id = strchr(line, ' ');
    776                                 if(++id)
    777                                 {
     676                                if (++id) {
    778677                                        char *info = strchr(id, ' ');
    779                                         if(info)
     678                                        if (info)
    780679                                                *info = '\0';
    781680                                        info++;
    782681                                        /* Remove fake chat if we created one in skype_chat_with() */
    783682                                        struct groupchat *gc = skype_chat_by_name(ic, "");
    784                                         if(gc)
     683                                        if (gc)
    785684                                                imcb_chat_free(gc);
    786                                         if(!strcmp(info, "STATUS MULTI_SUBSCRIBED"))
    787                                         {
    788                                                 imcb_chat_new( ic, id );
     685                                        if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) {
     686                                                imcb_chat_new(ic, id);
    789687                                                g_snprintf(buf, 1024, "GET CHAT %s ADDER\n", id);
    790688                                                skype_write(ic, buf);
    791689                                                g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id);
    792690                                                skype_write(ic, buf);
    793                                         }
    794                                         else if(!strcmp(info, "STATUS DIALOG") && sd->groupchat_with)
    795                                         {
    796                                                 gc = imcb_chat_new( ic, id );
     691                                        } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) {
     692                                                gc = imcb_chat_new(ic, id);
    797693                                                /* According to the docs this
    798694                                                 * is necessary. However it
     
    812708                                                g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id);
    813709                                                skype_write(ic, buf);
    814                                         }
    815                                         else if(!strcmp(info, "STATUS UNSUBSCRIBED"))
    816                                         {
     710                                        } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) {
    817711                                                gc = skype_chat_by_name(ic, id);
    818                                                 if(gc)
    819                                                         gc->data = (void*)FALSE;
    820                                         }
    821                                         else if(!strncmp(info, "ADDER ", 6))
    822                                         {
     712                                                if (gc)
     713                                                        gc->data = (void *)FALSE;
     714                                        } else if (!strncmp(info, "ADDER ", 6)) {
    823715                                                info += 6;
    824716                                                g_free(sd->adder);
    825717                                                sd->adder = g_strdup_printf("%s@skype.com", info);
    826                                         }
    827                                         else if(!strncmp(info, "TOPIC ", 6))
    828                                         {
     718                                        } else if (!strncmp(info, "TOPIC ", 6)) {
    829719                                                info += 6;
    830720                                                gc = skype_chat_by_name(ic, id);
    831                                                 if(gc && (sd->adder || sd->topic_wait))
    832                                                 {
    833                                                         if(sd->topic_wait)
    834                                                         {
     721                                                if (gc && (sd->adder || sd->topic_wait)) {
     722                                                        if (sd->topic_wait) {
    835723                                                                sd->adder = g_strdup(sd->username);
    836724                                                                sd->topic_wait = 0;
     
    840728                                                        sd->adder = NULL;
    841729                                                }
    842                                         }
    843                                         else if(!strncmp(info, "ACTIVEMEMBERS ", 14))
    844                                         {
     730                                        } else if (!strncmp(info, "ACTIVEMEMBERS ", 14)) {
    845731                                                info += 14;
    846732                                                gc = skype_chat_by_name(ic, id);
     
    849735                                                 * so that we won't rejoin
    850736                                                 * after a /part. */
    851                                                 if(gc && !gc->data)
    852                                                 {
     737                                                if (gc && !gc->data) {
    853738                                                        char **members = g_strsplit(info, " ", 0);
    854739                                                        int i;
    855                                                         for(i=0;members[i];i++)
    856                                                         {
    857                                                                 if(!strcmp(members[i], sd->username))
     740                                                        for (i = 0; members[i]; i++) {
     741                                                                if (!strcmp(members[i], sd->username))
    858742                                                                        continue;
    859743                                                                g_snprintf(buf, 1024, "%s@skype.com", members[i]);
    860                                                                 if(!g_list_find_custom(gc->in_room, buf, (GCompareFunc)strcmp))
     744                                                                if (!g_list_find_custom(gc->in_room, buf, (GCompareFunc)strcmp))
    861745                                                                        imcb_chat_add_buddy(gc, buf);
    862746                                                        }
     
    866750                                        }
    867751                                }
    868                         }
    869                         else if(!strncmp(line, "PASSWORD ", 9))
    870                         {
    871                                 if(!strncmp(line+9, "OK", 2))
     752                        } else if (!strncmp(line, "PASSWORD ", 9)) {
     753                                if (!strncmp(line+9, "OK", 2))
    872754                                        imcb_connected(ic);
    873                                 else
    874                                 {
     755                                else {
    875756                                        imcb_error(ic, "Authentication Failed");
    876                                         imc_logout( ic, TRUE );
     757                                        imc_logout(ic, TRUE);
    877758                                }
    878                         }
    879                         else if(!strncmp(line, "PROFILE PSTN_BALANCE ", 21))
    880                         {
     759                        } else if (!strncmp(line, "PROFILE PSTN_BALANCE ", 21))
    881760                                imcb_log(ic, "SkypeOut balance value is '%s'.", line+21);
    882                         }
    883                         else if(!strncmp(line, "PING", 4))
    884                         {
     761                        else if (!strncmp(line, "PING", 4)) {
    885762                                g_snprintf(buf, 1024, "PONG\n");
    886763                                skype_write(ic, buf);
    887                         }
    888                         else if(!strncmp(line, "CHATS ", 6))
    889                         {
     764                        } else if (!strncmp(line, "CHATS ", 6)) {
    890765                                char **i;
    891766                                char **chats = g_strsplit(line + 6, ", ", 0);
    892767
    893768                                i = chats;
    894                                 while (*i)
    895                                 {
     769                                while (*i) {
    896770                                        g_snprintf(buf, 1024, "GET CHAT %s STATUS\n", *i);
    897                                         skype_write( ic, buf );
     771                                        skype_write(ic, buf);
    898772                                        g_snprintf(buf, 1024, "GET CHAT %s ACTIVEMEMBERS\n", *i);
    899                                         skype_write( ic, buf );
     773                                        skype_write(ic, buf);
    900774                                        i++;
    901775                                }
     
    905779                }
    906780                g_strfreev(lines);
    907         }
    908         else if( st == 0 || ( st < 0 && !sockerr_again() ) )
    909         {
    910                 closesocket( sd->fd );
     781        } else if (st == 0 || (st < 0 && !sockerr_again())) {
     782                closesocket(sd->fd);
    911783                sd->fd = -1;
    912784
    913                 imcb_error( ic, "Error while reading from server" );
    914                 imc_logout( ic, TRUE );
     785                imcb_error(ic, "Error while reading from server");
     786                imc_logout(ic, TRUE);
    915787                return FALSE;
    916788        }
     
    918790}
    919791
    920 gboolean skype_start_stream( struct im_connection *ic )
     792gboolean skype_start_stream(struct im_connection *ic)
    921793{
    922794        struct skype_data *sd = ic->proto_data;
     
    924796        int st;
    925797
    926         if(!sd)
     798        if (!sd)
    927799                return FALSE;
    928800
    929         if( sd->bfd <= 0 )
    930                 sd->bfd = b_input_add( sd->fd, GAIM_INPUT_READ, skype_read_callback, ic );
     801        if (sd->bfd <= 0)
     802                sd->bfd = b_input_add(sd->fd, GAIM_INPUT_READ, skype_read_callback, ic);
    931803
    932804        /* Log in */
    933805        buf = g_strdup_printf("USERNAME %s\n", ic->acc->user);
    934         st = skype_write( ic, buf );
     806        st = skype_write(ic, buf);
    935807        g_free(buf);
    936808        buf = g_strdup_printf("PASSWORD %s\n", ic->acc->pass);
    937         st = skype_write( ic, buf );
     809        st = skype_write(ic, buf);
    938810        g_free(buf);
    939811
    940812        /* This will download all buddies. */
    941813        buf = g_strdup_printf("SEARCH FRIENDS\n");
    942         st = skype_write( ic, buf );
     814        st = skype_write(ic, buf);
    943815        g_free(buf);
    944816        buf = g_strdup_printf("SET USERSTATUS ONLINE\n");
    945         skype_write( ic, buf );
     817        skype_write(ic, buf);
    946818        g_free(buf);
    947819
     
    949821        if (set_getbool(&ic->acc->set, "auto_join")) {
    950822                buf = g_strdup_printf("SEARCH BOOKMARKEDCHATS\n");
    951                 skype_write( ic, buf );
     823                skype_write(ic, buf);
    952824                g_free(buf);
    953825        }
     
    955827}
    956828
    957 gboolean skype_connected( gpointer data, void *source, b_input_condition cond )
     829gboolean skype_connected(gpointer data, void *source, b_input_condition cond)
    958830{
    959831        struct im_connection *ic = data;
    960832        struct skype_data *sd = ic->proto_data;
    961         if(!source)
    962         {
     833        if (!source) {
    963834                sd->ssl = NULL;
    964                 imcb_error( ic, "Could not connect to server" );
    965                 imc_logout( ic, TRUE );
     835                imcb_error(ic, "Could not connect to server");
     836                imc_logout(ic, TRUE);
    966837                return FALSE;
    967838        }
    968         imcb_log( ic, "Connected to server, logging in" );
     839        imcb_log(ic, "Connected to server, logging in");
    969840        return skype_start_stream(ic);
    970841}
    971842
    972 static void skype_login( account_t *acc )
    973 {
    974         struct im_connection *ic = imcb_new( acc );
    975         struct skype_data *sd = g_new0( struct skype_data, 1 );
     843static void skype_login(account_t *acc)
     844{
     845        struct im_connection *ic = imcb_new(acc);
     846        struct skype_data *sd = g_new0(struct skype_data, 1);
    976847
    977848        ic->proto_data = sd;
    978849
    979         imcb_log( ic, "Connecting" );
    980         sd->ssl = ssl_connect(set_getstr( &acc->set, "server" ), set_getint( &acc->set, "port" ), skype_connected, ic );
    981         sd->fd = sd->ssl ? ssl_getfd( sd->ssl ) : -1;
    982         sd->username = g_strdup( acc->user );
     850        imcb_log(ic, "Connecting");
     851        sd->ssl = ssl_connect(set_getstr(&acc->set, "server"), set_getint(&acc->set, "port"), skype_connected, ic);
     852        sd->fd = sd->ssl ? ssl_getfd(sd->ssl) : -1;
     853        sd->username = g_strdup(acc->user);
    983854
    984855        sd->ic = ic;
     
    988859}
    989860
    990 static void skype_logout( struct im_connection *ic )
     861static void skype_logout(struct im_connection *ic)
    991862{
    992863        struct skype_data *sd = ic->proto_data;
     
    994865
    995866        buf = g_strdup_printf("SET USERSTATUS OFFLINE\n");
    996         skype_write( ic, buf );
     867        skype_write(ic, buf);
    997868        g_free(buf);
    998869
     
    1003874}
    1004875
    1005 static int skype_buddy_msg( struct im_connection *ic, char *who, char *message, int flags )
     876static int skype_buddy_msg(struct im_connection *ic, char *who, char *message, int flags)
    1006877{
    1007878        char *buf, *ptr, *nick;
     
    1010881        nick = g_strdup(who);
    1011882        ptr = strchr(nick, '@');
    1012         if(ptr)
     883        if (ptr)
    1013884                *ptr = '\0';
    1014885
     
    1018889                buf = g_strdup_printf("MESSAGE %s %s\n", nick, message);
    1019890        g_free(nick);
    1020         st = skype_write( ic, buf );
     891        st = skype_write(ic, buf);
    1021892        g_free(buf);
    1022893
     
    1024895}
    1025896
    1026 const struct skype_away_state *skype_away_state_by_name( char *name )
     897const struct skype_away_state *skype_away_state_by_name(char *name)
    1027898{
    1028899        int i;
    1029900
    1030         for( i = 0; skype_away_state_list[i].full_name; i ++ )
    1031                 if( g_strcasecmp( skype_away_state_list[i].full_name, name ) == 0 )
    1032                         return( skype_away_state_list + i );
     901        for (i = 0; skype_away_state_list[i].full_name; i++)
     902                if (g_strcasecmp(skype_away_state_list[i].full_name, name) == 0)
     903                        return skype_away_state_list + i;
    1033904
    1034905        return NULL;
    1035906}
    1036907
    1037 static void skype_set_away( struct im_connection *ic, char *state_txt, char *message )
     908static void skype_set_away(struct im_connection *ic, char *state_txt, char *message)
    1038909{
    1039910        const struct skype_away_state *state;
    1040911        char *buf;
    1041912
    1042         if( strcmp( state_txt, GAIM_AWAY_CUSTOM ) == 0 )
    1043                 state = skype_away_state_by_name( "Away" );
     913        if (strcmp(state_txt, GAIM_AWAY_CUSTOM) == 0)
     914                state = skype_away_state_by_name("Away");
    1044915        else
    1045                 state = skype_away_state_by_name( state_txt );
     916                state = skype_away_state_by_name(state_txt);
    1046917        buf = g_strdup_printf("SET USERSTATUS %s\n", state->code);
    1047         skype_write( ic, buf );
    1048         g_free(buf);
    1049 }
    1050 
    1051 static GList *skype_away_states( struct im_connection *ic )
    1052 {
    1053         static GList *l = NULL;
     918        skype_write(ic, buf);
     919        g_free(buf);
     920}
     921
     922static GList *skype_away_states(struct im_connection *ic)
     923{
     924        static GList *l;
    1054925        int i;
    1055        
    1056         if( l == NULL )
    1057                 for( i = 0; skype_away_state_list[i].full_name; i ++ )
    1058                         l = g_list_append( l, (void*) skype_away_state_list[i].full_name );
    1059        
     926
     927        if (l == NULL)
     928                for (i = 0; skype_away_state_list[i].full_name; i++)
     929                        l = g_list_append(l, (void *)skype_away_state_list[i].full_name);
     930
    1060931        return l;
    1061932}
    1062933
    1063 static char *skype_set_display_name( set_t *set, char *value )
     934static char *skype_set_display_name(set_t *set, char *value)
    1064935{
    1065936        account_t *acc = set->data;
     
    1068939
    1069940        buf = g_strdup_printf("SET PROFILE FULLNAME %s", value);
    1070         skype_write( ic, buf );
    1071         g_free(buf);
    1072         return(value);
    1073 }
    1074 
    1075 static char *skype_set_balance( set_t *set, char *value )
     941        skype_write(ic, buf);
     942        g_free(buf);
     943        return value;
     944}
     945
     946static char *skype_set_balance(set_t *set, char *value)
    1076947{
    1077948        account_t *acc = set->data;
     
    1080951
    1081952        buf = g_strdup_printf("GET PROFILE PSTN_BALANCE");
    1082         skype_write( ic, buf );
    1083         g_free(buf);
    1084         return(value);
    1085 }
    1086 
    1087 static char *skype_set_call( set_t *set, char *value )
     953        skype_write(ic, buf);
     954        g_free(buf);
     955        return value;
     956}
     957
     958static char *skype_set_call(set_t *set, char *value)
    1088959{
    1089960        account_t *acc = set->data;
     
    1092963        char *nick, *ptr, *buf;
    1093964
    1094         if(value)
    1095         {
     965        if (value) {
    1096966                user_t *u = user_find(acc->irc, value);
    1097967                /* We are starting a call */
    1098                 if(!u)
     968                if (!u)
    1099969                        nick = g_strdup(value);
    1100970                else
    1101971                        nick = g_strdup(u->handle);
    1102972                ptr = strchr(nick, '@');
    1103                 if(ptr)
     973                if (ptr)
    1104974                        *ptr = '\0';
    1105975
    1106976                buf = g_strdup_printf("CALL %s", nick);
    1107                 skype_write( ic, buf );
     977                skype_write(ic, buf);
    1108978                g_free(buf);
    1109979                g_free(nick);
    1110         }
    1111         else
    1112         {
     980        } else {
    1113981                /* We are ending a call */
    1114                 if(sd->call_id)
    1115                 {
     982                if (sd->call_id) {
    1116983                        buf = g_strdup_printf("SET CALL %s STATUS FINISHED", sd->call_id);
    1117                         skype_write( ic, buf );
     984                        skype_write(ic, buf);
    1118985                        g_free(buf);
    1119986                        g_free(sd->call_id);
    1120987                        sd->call_id = NULL;
    1121                 }
    1122                 else
    1123                 {
     988                } else
    1124989                        imcb_error(ic, "There are no active calls currently.");
    1125                 }
    1126990        }
    1127         return(value);
    1128 }
    1129 
    1130 static void skype_add_buddy( struct im_connection *ic, char *who, char *group )
     991        return value;
     992}
     993
     994static void skype_add_buddy(struct im_connection *ic, char *who, char *group)
    1131995{
    1132996        char *buf, *nick, *ptr;
     
    1134998        nick = g_strdup(who);
    1135999        ptr = strchr(nick, '@');
    1136         if(ptr)
     1000        if (ptr)
    11371001                *ptr = '\0';
    11381002        buf = g_strdup_printf("SET USER %s BUDDYSTATUS 2 Please authorize me\n", nick);
    1139         skype_write( ic, buf );
     1003        skype_write(ic, buf);
    11401004        g_free(nick);
    11411005}
    11421006
    1143 static void skype_remove_buddy( struct im_connection *ic, char *who, char *group )
     1007static void skype_remove_buddy(struct im_connection *ic, char *who, char *group)
    11441008{
    11451009        char *buf, *nick, *ptr;
     
    11471011        nick = g_strdup(who);
    11481012        ptr = strchr(nick, '@');
    1149         if(ptr)
     1013        if (ptr)
    11501014                *ptr = '\0';
    11511015        buf = g_strdup_printf("SET USER %s BUDDYSTATUS 1\n", nick);
    1152         skype_write( ic, buf );
     1016        skype_write(ic, buf);
    11531017        g_free(nick);
    11541018}
    11551019
    1156 void skype_chat_msg( struct groupchat *gc, char *message, int flags )
     1020void skype_chat_msg(struct groupchat *gc, char *message, int flags)
    11571021{
    11581022        struct im_connection *ic = gc->ic;
    11591023        char *buf;
    11601024        buf = g_strdup_printf("CHATMESSAGE %s %s\n", gc->title, message);
    1161         skype_write( ic, buf );
    1162         g_free(buf);
    1163 }
    1164 
    1165 void skype_chat_leave( struct groupchat *gc )
     1025        skype_write(ic, buf);
     1026        g_free(buf);
     1027}
     1028
     1029void skype_chat_leave(struct groupchat *gc)
    11661030{
    11671031        struct im_connection *ic = gc->ic;
    11681032        char *buf;
    11691033        buf = g_strdup_printf("ALTER CHAT %s LEAVE\n", gc->title);
    1170         skype_write( ic, buf );
    1171         g_free(buf);
    1172         gc->data = (void*)TRUE;
     1034        skype_write(ic, buf);
     1035        g_free(buf);
     1036        gc->data = (void *)TRUE;
    11731037}
    11741038
     
    11791043        nick = g_strdup(message);
    11801044        ptr = strchr(nick, '@');
    1181         if(ptr)
     1045        if (ptr)
    11821046                *ptr = '\0';
    11831047        buf = g_strdup_printf("ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick);
    1184         skype_write( ic, buf );
     1048        skype_write(ic, buf);
    11851049        g_free(buf);
    11861050        g_free(nick);
     
    11931057        char *buf;
    11941058        buf = g_strdup_printf("ALTER CHAT %s SETTOPIC %s\n", gc->title, message);
    1195         skype_write( ic, buf );
     1059        skype_write(ic, buf);
    11961060        g_free(buf);
    11971061        sd->topic_wait = 1;
     
    12041068        nick = g_strdup(who);
    12051069        ptr = strchr(nick, '@');
    1206         if(ptr)
     1070        if (ptr)
    12071071                *ptr = '\0';
    12081072        buf = g_strdup_printf("CHAT CREATE %s\n", nick);
     
    12131077        /* We create a fake chat for now. We will replace it with a real one in
    12141078         * the real callback. */
    1215         return(imcb_chat_new( ic, "" ));
     1079        return imcb_chat_new(ic, "");
    12161080}
    12171081
     
    12211085        nick = g_strdup(who);
    12221086        ptr = strchr(nick, '@');
    1223         if(ptr)
     1087        if (ptr)
    12241088                *ptr = '\0';
    12251089        buf = g_strdup_printf("GET USER %s FULLNAME\n", nick);
     
    12701134}
    12711135
    1272 static void skype_set_my_name( struct im_connection *ic, char *info )
    1273 {
    1274         skype_set_display_name( set_find( &ic->acc->set, "display_name" ), info );
    1275 }
    1276 
    1277 static void skype_init( account_t *acc )
     1136static void skype_set_my_name(struct im_connection *ic, char *info)
     1137{
     1138        skype_set_display_name(set_find(&ic->acc->set, "display_name"), info);
     1139}
     1140
     1141static void skype_init(account_t *acc)
    12781142{
    12791143        set_t *s;
    12801144
    1281         s = set_add( &acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, acc );
     1145        s = set_add(&acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, acc);
    12821146        s->flags |= ACC_SET_OFFLINE_ONLY;
    12831147
    1284         s = set_add( &acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc );
     1148        s = set_add(&acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc);
    12851149        s->flags |= ACC_SET_OFFLINE_ONLY;
    12861150
    1287         s = set_add( &acc->set, "display_name", NULL, skype_set_display_name, acc );
     1151        s = set_add(&acc->set, "display_name", NULL, skype_set_display_name, acc);
    12881152        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
    12891153
    1290         s = set_add( &acc->set, "call", NULL, skype_set_call, acc );
     1154        s = set_add(&acc->set, "call", NULL, skype_set_call, acc);
    12911155        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
    12921156
    1293         s = set_add( &acc->set, "balance", NULL, skype_set_balance, acc );
     1157        s = set_add(&acc->set, "balance", NULL, skype_set_balance, acc);
    12941158        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
    12951159
    1296         s = set_add( &acc->set, "skypeout_offline", "true", set_eval_bool, acc );
    1297 
    1298         s = set_add( &acc->set, "skypeconsole", "false", set_eval_bool, acc );
     1160        s = set_add(&acc->set, "skypeout_offline", "true", set_eval_bool, acc);
     1161
     1162        s = set_add(&acc->set, "skypeconsole", "false", set_eval_bool, acc);
    12991163        s->flags |= ACC_SET_OFFLINE_ONLY;
    13001164
    1301         s = set_add( &acc->set, "auto_join", "false", set_eval_bool, acc );
     1165        s = set_add(&acc->set, "auto_join", "false", set_eval_bool, acc);
    13021166        s->flags |= ACC_SET_OFFLINE_ONLY;
    13031167}
     
    13051169void init_plugin(void)
    13061170{
    1307         struct prpl *ret = g_new0( struct prpl, 1 );
     1171        struct prpl *ret = g_new0(struct prpl, 1);
    13081172
    13091173        ret->name = "skype";
     
    13241188        ret->handle_cmp = g_strcasecmp;
    13251189        ret->chat_topic = skype_chat_topic;
    1326         register_protocol( ret );
     1190        register_protocol(ret);
    13271191}
    13281192
Note: See TracChangeset for help on using the changeset viewer.