source: skype/skype.c @ 4c674bb

Last change on this file since 4c674bb was 4c674bb, checked in by Miklos Vajna <vmiklos@…>, at 2010-04-13T23:58:36Z

include mood text in whois output as well

  • Property mode set to 100644
File size: 33.1 KB
RevLine 
[7daec06]1/*
2 *  skype.c - Skype plugin for BitlBee
[5adcc65]3 *
[5258dcc9]4 *  Copyright (c) 2007, 2008, 2009 by Miklos Vajna <vmiklos@frugalware.org>
[f06e3ac]5 *
[7daec06]6 *  This program is free software; you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation; either version 2 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program; if not, write to the Free Software
[5adcc65]18 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
[7daec06]19 *  USA.
[f06e3ac]20 */
[7daec06]21
[f9c3e7b]22#define _XOPEN_SOURCE
[1f4fc80]23#define _BSD_SOURCE
[ed2e37f]24#include <poll.h>
[f06e3ac]25#include <bitlbee.h>
[c7304b2]26#include <bitlbee/ssl_client.h>
[f06e3ac]27
[f5aedd91]28#define SKYPE_DEFAULT_SERVER "localhost"
[4bbd9db]29#define SKYPE_DEFAULT_PORT "2727"
[c213d6b]30#define IRC_LINE_SIZE 1024
[ff436ba]31#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
[f06e3ac]32
[bbba374]33/*
34 * Enumerations
35 */
36
[359f4d9]37enum {
[df9255d]38        SKYPE_CALL_RINGING = 1,
[9db0234]39        SKYPE_CALL_MISSED,
[2eb4b1f]40        SKYPE_CALL_CANCELLED,
[acd9478]41        SKYPE_CALL_FINISHED,
[d87daf3]42        SKYPE_CALL_REFUSED
[5365f84]43};
[bbba374]44
[359f4d9]45enum {
[df9255d]46        SKYPE_FILETRANSFER_NEW = 1,
47        SKYPE_FILETRANSFER_FAILED
[5365f84]48};
[df9255d]49
[7daec06]50/*
51 * Structures
52 */
53
[5adcc65]54struct skype_data {
[f06e3ac]55        struct im_connection *ic;
[a3d6427]56        char *username;
[368861e]57        /* The effective file descriptor. We store it here so any function can
58         * write() to it. */
[f06e3ac]59        int fd;
[368861e]60        /* File descriptor returned by bitlbee. we store it so we know when
61         * we're connected and when we aren't. */
62        int bfd;
[c7304b2]63        /* ssl_getfd() uses this to get the file desciptor. */
64        void *ssl;
[2a0f99c]65        /* When we receive a new message id, we query the properties, finally
66         * the chatname. Store the properties here so that we can use
[c81d0ef]67         * imcb_buddy_msg() when we got the chatname. */
[77c1abe]68        char *handle;
[a7af5f0]69        /* List, because of multiline messages. */
70        GList *body;
[2a0f99c]71        char *type;
[bbba374]72        /* This is necessary because we send a notification when we get the
73         * handle. So we store the state here and then we can send a
74         * notification about the handle is in a given status. */
[359f4d9]75        int call_status;
[2eb4b1f]76        char *call_id;
[48181f0]77        char *call_duration;
[d87daf3]78        /* If the call is outgoing or not */
79        int call_out;
[df9255d]80        /* Same for file transfers. */
[359f4d9]81        int filetransfer_status;
[86278cd]82        /* Using /j #nick we want to have a groupchat with two people. Usually
83         * not (default). */
[5adcc65]84        char *groupchat_with;
[f8674db]85        /* The user who invited us to the chat. */
[5adcc65]86        char *adder;
[a5f76a2]87        /* If we are waiting for a confirmation about we changed the topic. */
88        int topic_wait;
[67454bd]89        /* These are used by the info command. */
90        char *info_fullname;
91        char *info_phonehome;
92        char *info_phoneoffice;
93        char *info_phonemobile;
94        char *info_nrbuddies;
95        char *info_tz;
96        char *info_seen;
97        char *info_birthday;
98        char *info_sex;
99        char *info_language;
100        char *info_country;
101        char *info_province;
102        char *info_city;
103        char *info_homepage;
104        char *info_about;
[b054fad]105        /* When a call fails, we get the reason and later we get the failure
106         * event, so store the failure code here till then */
107        int failurereason;
[d9ce18c]108        /* If this is just an update of an already received message. */
109        int is_edit;
[f06e3ac]110};
111
[5adcc65]112struct skype_away_state {
[adce2de]113        char *code;
114        char *full_name;
115};
116
[5adcc65]117struct skype_buddy_ask_data {
[7daec06]118        struct im_connection *ic;
[e0074cb]119        /* This is also used for call IDs for simplicity */
[7daec06]120        char *handle;
121};
122
123/*
124 * Tables
125 */
126
[5adcc65]127const struct skype_away_state skype_away_state_list[] = {
[bc744df]128        { "AWAY", "Away" },
129        { "NA", "Not available" },
130        { "DND", "Do Not Disturb" },
131        { "INVISIBLE", "Invisible" },
132        { "OFFLINE", "Offline" },
[4b740c2]133        { "SKYPEME", "Skype Me" },
134        { "ONLINE", "Online" },
[23411c6]135        { NULL, NULL}
[adce2de]136};
137
[7daec06]138/*
139 * Functions
140 */
[d3cbd17]141
[7c300bb]142int skype_write(struct im_connection *ic, char *buf, int len)
[f06e3ac]143{
144        struct skype_data *sd = ic->proto_data;
[1fb89e3]145        struct pollfd pfd[1];
146
147        pfd[0].fd = sd->fd;
148        pfd[0].events = POLLOUT;
[f06e3ac]149
[7daec06]150        /* This poll is necessary or we'll get a SIGPIPE when we write() to
151         * sd->fd. */
[1fb89e3]152        poll(pfd, 1, 1000);
[5adcc65]153        if (pfd[0].revents & POLLHUP) {
154                imc_logout(ic, TRUE);
[1fb89e3]155                return FALSE;
156        }
[5adcc65]157        ssl_write(sd->ssl, buf, len);
[f06e3ac]158
[9fd4241]159        return TRUE;
[f06e3ac]160}
161
[1f4fc80]162int skype_printf(struct im_connection *ic, char *fmt, ...)
163{
164        va_list args;
165        char str[IRC_LINE_SIZE];
[5d9db76]166
[1f4fc80]167        va_start(args, fmt);
168        vsnprintf(str, IRC_LINE_SIZE, fmt, args);
169        va_end(args);
170
[7c300bb]171        return skype_write(ic, str, strlen(str));
[1f4fc80]172}
173
[5adcc65]174static void skype_buddy_ask_yes(void *data)
[d3cbd17]175{
[039116a]176        struct skype_buddy_ask_data *bla = data;
[1f4fc80]177        skype_printf(bla->ic, "SET USER %s ISAUTHORIZED TRUE",
[8c09bb3]178                bla->handle);
[d3cbd17]179        g_free(bla->handle);
180        g_free(bla);
181}
182
[5adcc65]183static void skype_buddy_ask_no(void *data)
[d3cbd17]184{
[039116a]185        struct skype_buddy_ask_data *bla = data;
[1f4fc80]186        skype_printf(bla->ic, "SET USER %s ISAUTHORIZED FALSE",
[8c09bb3]187                bla->handle);
[d3cbd17]188        g_free(bla->handle);
189        g_free(bla);
190}
191
[5adcc65]192void skype_buddy_ask(struct im_connection *ic, char *handle, char *message)
[d3cbd17]193{
[8c09bb3]194        struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data,
195                1);
[d3cbd17]196        char *buf;
197
198        bla->ic = ic;
199        bla->handle = g_strdup(handle);
200
[8c09bb3]201        buf = g_strdup_printf("The user %s wants to add you to "
202                "his/her buddy list, saying: '%s'.", handle, message);
[5adcc65]203        imcb_ask(ic, buf, bla, skype_buddy_ask_yes, skype_buddy_ask_no);
204        g_free(buf);
[d3cbd17]205}
206
[5adcc65]207static void skype_call_ask_yes(void *data)
[e0074cb]208{
[039116a]209        struct skype_buddy_ask_data *bla = data;
[1f4fc80]210        skype_printf(bla->ic, "SET CALL %s STATUS INPROGRESS",
[8c09bb3]211                bla->handle);
[e0074cb]212        g_free(bla->handle);
213        g_free(bla);
214}
215
[5adcc65]216static void skype_call_ask_no(void *data)
[e0074cb]217{
[039116a]218        struct skype_buddy_ask_data *bla = data;
[1f4fc80]219        skype_printf(bla->ic, "SET CALL %s STATUS FINISHED",
[8c09bb3]220                bla->handle);
[e0074cb]221        g_free(bla->handle);
222        g_free(bla);
223}
224
[5adcc65]225void skype_call_ask(struct im_connection *ic, char *call_id, char *message)
[e0074cb]226{
[8c09bb3]227        struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data,
228                1);
[e0074cb]229
230        bla->ic = ic;
231        bla->handle = g_strdup(call_id);
232
[5adcc65]233        imcb_ask(ic, message, bla, skype_call_ask_yes, skype_call_ask_no);
[e0074cb]234}
[5adcc65]235struct groupchat *skype_chat_by_name(struct im_connection *ic, char *name)
[72aa7f0]236{
237        struct groupchat *ret;
238
[5adcc65]239        for (ret = ic->groupchats; ret; ret = ret->next)
240                if (strcmp(name, ret->title) == 0)
[72aa7f0]241                        break;
242
243        return ret;
244}
245
[b054fad]246static char *skype_call_strerror(int err)
247{
[5adcc65]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";
[b054fad]275        }
276}
277
[078b0b9]278static void skype_parse_users(struct im_connection *ic, char *line)
279{
[1f4fc80]280        char **i, **nicks;
[078b0b9]281
282        nicks = g_strsplit(line + 6, ", ", 0);
[1f4fc80]283        for (i = nicks; *i; i++)
284                skype_printf(ic, "GET USER %s ONLINESTATUS\n", *i);
[078b0b9]285        g_strfreev(nicks);
286}
287
[6e14204]288static void skype_parse_user(struct im_connection *ic, char *line)
289{
290        int flags = 0;
291        char *ptr;
292        struct skype_data *sd = ic->proto_data;
293        char *user = strchr(line, ' ');
294        char *status = strrchr(line, ' ');
295
296        status++;
297        ptr = strchr(++user, ' ');
298        if (!ptr)
299                return;
300        *ptr = '\0';
301        ptr++;
[49a3c02]302        if (!strncmp(ptr, "ONLINESTATUS ", 13)) {
303                        if (!strcmp(user, sd->username))
304                                return;
305                        if (!set_getbool(&ic->acc->set, "test_join")
306                                && !strcmp(user, "echo123"))
307                                return;
[6e14204]308                ptr = g_strdup_printf("%s@skype.com", user);
309                imcb_add_buddy(ic, ptr, NULL);
[62f51ee9]310                if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") ||
311                        !set_getbool(&ic->acc->set, "skypeout_offline")))
[6e14204]312                        flags |= OPT_LOGGED_IN;
[62f51ee9]313                if (strcmp(status, "ONLINE") && strcmp(status, "SKYPEME"))
[6e14204]314                        flags |= OPT_AWAY;
315                imcb_buddy_status(ic, ptr, flags, NULL, NULL);
316                g_free(ptr);
317        } else if (!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) {
318                char *message = ptr + 20;
319                if (strlen(message))
320                        skype_buddy_ask(ic, user, message);
321        } else if (!strncmp(ptr, "BUDDYSTATUS ", 12)) {
322                char *st = ptr + 12;
323                if (!strcmp(st, "3")) {
324                        char *buf = g_strdup_printf("%s@skype.com", user);
325                        imcb_add_buddy(ic, buf, NULL);
326                        g_free(buf);
327                }
[4c674bb]328        } else if (!strncmp(ptr, "MOOD_TEXT ", 10) && set_getbool(&ic->acc->set, "show_moods")) {
329                char *buf = g_strdup_printf("%s@skype.com", user);
330                user_t *u = user_findhandle(ic, buf);
331                g_free(buf);
332                buf = ptr + 10;
333                if (u) {
334                        if (u->status_msg)
335                                g_free(u->status_msg);
336                        if (strlen(buf))
337                                u->status_msg = g_strdup(buf);
338                        else
339                                u->status_msg = NULL;
340                }
341                imcb_log(ic, "User `%s' changed mood text to `%s'", user, buf);
342        }
[304aa33]343        else if (!strncmp(ptr, "FULLNAME ", 9))
[d7938f9]344                sd->info_fullname = g_strdup(ptr + 9);
[6e14204]345        else if (!strncmp(ptr, "PHONE_HOME ", 11))
[d7938f9]346                sd->info_phonehome = g_strdup(ptr + 11);
[6e14204]347        else if (!strncmp(ptr, "PHONE_OFFICE ", 13))
[d7938f9]348                sd->info_phoneoffice = g_strdup(ptr + 13);
[6e14204]349        else if (!strncmp(ptr, "PHONE_MOBILE ", 13))
[d7938f9]350                sd->info_phonemobile = g_strdup(ptr + 13);
[6e14204]351        else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20))
[d7938f9]352                sd->info_nrbuddies = g_strdup(ptr + 20);
[6e14204]353        else if (!strncmp(ptr, "TIMEZONE ", 9))
[d7938f9]354                sd->info_tz = g_strdup(ptr + 9);
[6e14204]355        else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20))
[d7938f9]356                sd->info_seen = g_strdup(ptr + 20);
[6e14204]357        else if (!strncmp(ptr, "BIRTHDAY ", 9))
[d7938f9]358                sd->info_birthday = g_strdup(ptr + 9);
[6e14204]359        else if (!strncmp(ptr, "SEX ", 4))
[d7938f9]360                sd->info_sex = g_strdup(ptr + 4);
[6e14204]361        else if (!strncmp(ptr, "LANGUAGE ", 9))
[d7938f9]362                sd->info_language = g_strdup(ptr + 9);
[6e14204]363        else if (!strncmp(ptr, "COUNTRY ", 8))
[d7938f9]364                sd->info_country = g_strdup(ptr + 8);
[6e14204]365        else if (!strncmp(ptr, "PROVINCE ", 9))
[d7938f9]366                sd->info_province = g_strdup(ptr + 9);
[6e14204]367        else if (!strncmp(ptr, "CITY ", 5))
[d7938f9]368                sd->info_city = g_strdup(ptr + 5);
[6e14204]369        else if (!strncmp(ptr, "HOMEPAGE ", 9))
[d7938f9]370                sd->info_homepage = g_strdup(ptr + 9);
[6e14204]371        else if (!strncmp(ptr, "ABOUT ", 6)) {
[d7938f9]372                sd->info_about = g_strdup(ptr + 6);
[6e14204]373
374                GString *st = g_string_new("Contact Information\n");
375                g_string_append_printf(st, "Skype Name: %s\n", user);
376                if (sd->info_fullname) {
377                        if (strlen(sd->info_fullname))
[62f51ee9]378                                g_string_append_printf(st, "Full Name: %s\n",
379                                        sd->info_fullname);
[6e14204]380                        g_free(sd->info_fullname);
381                }
382                if (sd->info_phonehome) {
383                        if (strlen(sd->info_phonehome))
[62f51ee9]384                                g_string_append_printf(st, "Home Phone: %s\n",
385                                        sd->info_phonehome);
[6e14204]386                        g_free(sd->info_phonehome);
387                }
388                if (sd->info_phoneoffice) {
389                        if (strlen(sd->info_phoneoffice))
[62f51ee9]390                                g_string_append_printf(st, "Office Phone: %s\n",
391                                        sd->info_phoneoffice);
[6e14204]392                        g_free(sd->info_phoneoffice);
393                }
394                if (sd->info_phonemobile) {
395                        if (strlen(sd->info_phonemobile))
[62f51ee9]396                                g_string_append_printf(st, "Mobile Phone: %s\n",
397                                        sd->info_phonemobile);
[6e14204]398                        g_free(sd->info_phonemobile);
399                }
400                g_string_append_printf(st, "Personal Information\n");
401                if (sd->info_nrbuddies) {
402                        if (strlen(sd->info_nrbuddies))
[62f51ee9]403                                g_string_append_printf(st,
404                                        "Contacts: %s\n", sd->info_nrbuddies);
[6e14204]405                        g_free(sd->info_nrbuddies);
406                }
407                if (sd->info_tz) {
408                        if (strlen(sd->info_tz)) {
409                                char ib[256];
410                                time_t t = time(NULL);
411                                t += atoi(sd->info_tz)-(60*60*24);
412                                struct tm *gt = gmtime(&t);
413                                strftime(ib, 256, "%H:%M:%S", gt);
[62f51ee9]414                                g_string_append_printf(st,
415                                        "Local Time: %s\n", ib);
[6e14204]416                        }
417                        g_free(sd->info_tz);
418                }
419                if (sd->info_seen) {
420                        if (strlen(sd->info_seen)) {
421                                char ib[256];
422                                time_t it = atoi(sd->info_seen);
423                                struct tm *tm = localtime(&it);
424                                strftime(ib, 256, ("%Y. %m. %d. %H:%M"), tm);
[62f51ee9]425                                g_string_append_printf(st,
426                                        "Last Seen: %s\n", ib);
[6e14204]427                        }
428                        g_free(sd->info_seen);
429                }
430                if (sd->info_birthday) {
[62f51ee9]431                        if (strlen(sd->info_birthday) &&
432                                strcmp(sd->info_birthday, "0")) {
[6e14204]433                                char ib[256];
434                                struct tm tm;
435                                strptime(sd->info_birthday, "%Y%m%d", &tm);
436                                strftime(ib, 256, "%B %d, %Y", &tm);
[62f51ee9]437                                g_string_append_printf(st,
438                                        "Birthday: %s\n", ib);
[6e14204]439
440                                strftime(ib, 256, "%Y", &tm);
441                                int year = atoi(ib);
442                                time_t t = time(NULL);
443                                struct tm *lt = localtime(&t);
[62f51ee9]444                                g_string_append_printf(st,
445                                        "Age: %d\n", lt->tm_year+1900-year);
[6e14204]446                        }
447                        g_free(sd->info_birthday);
448                }
449                if (sd->info_sex) {
450                        if (strlen(sd->info_sex)) {
451                                char *iptr = sd->info_sex;
452                                while (*iptr++)
453                                        *iptr = tolower(*iptr);
[62f51ee9]454                                g_string_append_printf(st,
455                                        "Gender: %s\n", sd->info_sex);
[6e14204]456                        }
457                        g_free(sd->info_sex);
458                }
459                if (sd->info_language) {
460                        if (strlen(sd->info_language)) {
461                                char *iptr = strchr(sd->info_language, ' ');
462                                if (iptr)
463                                        iptr++;
464                                else
465                                        iptr = sd->info_language;
[62f51ee9]466                                g_string_append_printf(st,
467                                        "Language: %s\n", iptr);
[6e14204]468                        }
469                        g_free(sd->info_language);
470                }
471                if (sd->info_country) {
472                        if (strlen(sd->info_country)) {
473                                char *iptr = strchr(sd->info_country, ' ');
474                                if (iptr)
475                                        iptr++;
476                                else
477                                        iptr = sd->info_country;
[62f51ee9]478                                g_string_append_printf(st,
479                                        "Country: %s\n", iptr);
[6e14204]480                        }
481                        g_free(sd->info_country);
482                }
483                if (sd->info_province) {
484                        if (strlen(sd->info_province))
[62f51ee9]485                                g_string_append_printf(st,
486                                        "Region: %s\n", sd->info_province);
[6e14204]487                        g_free(sd->info_province);
488                }
489                if (sd->info_city) {
490                        if (strlen(sd->info_city))
[62f51ee9]491                                g_string_append_printf(st,
492                                        "City: %s\n", sd->info_city);
[6e14204]493                        g_free(sd->info_city);
494                }
495                if (sd->info_homepage) {
496                        if (strlen(sd->info_homepage))
[62f51ee9]497                                g_string_append_printf(st,
498                                        "Homepage: %s\n", sd->info_homepage);
[6e14204]499                        g_free(sd->info_homepage);
500                }
501                if (sd->info_about) {
502                        if (strlen(sd->info_about))
[62f51ee9]503                                g_string_append_printf(st, "%s\n",
504                                        sd->info_about);
[6e14204]505                        g_free(sd->info_about);
506                }
507                imcb_log(ic, "%s", st->str);
508                g_string_free(st, TRUE);
509        }
510}
511
512static void skype_parse_chatmessage(struct im_connection *ic, char *line)
513{
514        struct skype_data *sd = ic->proto_data;
[c213d6b]515        char buf[IRC_LINE_SIZE];
[6e14204]516        char *id = strchr(line, ' ');
517
[6b9d22a]518        if (!++id)
519                return;
520        char *info = strchr(id, ' ');
521
522        if (!info)
523                return;
524        *info = '\0';
525        info++;
[7825f58]526        if (!strcmp(info, "STATUS RECEIVED") || !strncmp(info, "EDITED_TIMESTAMP", 16)) {
[6b9d22a]527                /* New message ID:
528                 * (1) Request its from field
529                 * (2) Request its body
530                 * (3) Request its type
531                 * (4) Query chatname
532                 */
[1f4fc80]533                skype_printf(ic, "GET CHATMESSAGE %s FROM_HANDLE\n", id);
[d1d5b34]534                if (!strcmp(info, "STATUS RECEIVED"))
535                        skype_printf(ic, "GET CHATMESSAGE %s BODY\n", id);
[d9ce18c]536                else
537                        sd->is_edit = 1;
[1f4fc80]538                skype_printf(ic, "GET CHATMESSAGE %s TYPE\n", id);
539                skype_printf(ic, "GET CHATMESSAGE %s CHATNAME\n", id);
[6b9d22a]540        } else if (!strncmp(info, "FROM_HANDLE ", 12)) {
541                info += 12;
542                /* New from field value. Store
543                 * it, then we can later use it
544                 * when we got the message's
545                 * body. */
546                g_free(sd->handle);
547                sd->handle = g_strdup_printf("%s@skype.com", info);
548        } else if (!strncmp(info, "EDITED_BY ", 10)) {
549                info += 10;
550                /* This is the same as
551                 * FROM_HANDLE, except that we
552                 * never request these lines
553                 * from Skype, we just get
554                 * them. */
555                g_free(sd->handle);
556                sd->handle = g_strdup_printf("%s@skype.com", info);
557        } else if (!strncmp(info, "BODY ", 5)) {
558                info += 5;
559                sd->body = g_list_append(sd->body, g_strdup(info));
560        }       else if (!strncmp(info, "TYPE ", 5)) {
561                info += 5;
562                g_free(sd->type);
563                sd->type = g_strdup(info);
[7825f58]564        } else if (!strncmp(info, "CHATNAME ", 9)) {
565                info += 9;
566                if (sd->handle && sd->body && sd->type) {
567                        struct groupchat *gc = skype_chat_by_name(ic, info);
568                        int i;
569                        for (i = 0; i < g_list_length(sd->body); i++) {
570                                char *body = g_list_nth_data(sd->body, i);
571                                if (!strcmp(sd->type, "SAID") ||
572                                        !strcmp(sd->type, "EMOTED")) {
573                                        if (!strcmp(sd->type, "SAID")) {
574                                                if (!sd->is_edit)
575                                                        g_snprintf(buf, IRC_LINE_SIZE, "%s",
576                                                                body);
577                                                else {
578                                                        g_snprintf(buf, IRC_LINE_SIZE, "%s %s",
579                                                                set_getstr(&ic->acc->set, "edit_prefix"),
580                                                                body);
581                                                        sd->is_edit = 0;
582                                                }
583                                        } else
584                                                g_snprintf(buf, IRC_LINE_SIZE, "/me %s",
585                                                        body);
586                                        if (!gc)
587                                                /* Private message */
588                                                imcb_buddy_msg(ic,
589                                                        sd->handle, buf, 0, 0);
590                                        else
591                                                /* Groupchat message */
592                                                imcb_chat_msg(gc,
593                                                        sd->handle, buf, 0, 0);
594                                } else if (!strcmp(sd->type, "SETTOPIC") && gc)
595                                        imcb_chat_topic(gc,
596                                                sd->handle, body, 0);
597                                else if (!strcmp(sd->type, "LEFT") && gc)
598                                        imcb_chat_remove_buddy(gc,
599                                                sd->handle, NULL);
[6e14204]600                        }
[7825f58]601                        g_list_free(sd->body);
602                        sd->body = NULL;
603                }
[6e14204]604        }
605}
606
[9f2f25f]607static void skype_parse_call(struct im_connection *ic, char *line)
608{
609        struct skype_data *sd = ic->proto_data;
610        char *id = strchr(line, ' ');
[c213d6b]611        char buf[IRC_LINE_SIZE];
[9f2f25f]612
[6b9d22a]613        if (!++id)
614                return;
615        char *info = strchr(id, ' ');
616
617        if (!info)
618                return;
619        *info = '\0';
620        info++;
621        if (!strncmp(info, "FAILUREREASON ", 14))
622                sd->failurereason = atoi(strchr(info, ' '));
623        else if (!strcmp(info, "STATUS RINGING")) {
624                if (sd->call_id)
625                        g_free(sd->call_id);
626                sd->call_id = g_strdup(id);
[1f4fc80]627                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]628                sd->call_status = SKYPE_CALL_RINGING;
629        } else if (!strcmp(info, "STATUS MISSED")) {
[1f4fc80]630                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]631                sd->call_status = SKYPE_CALL_MISSED;
632        } else if (!strcmp(info, "STATUS CANCELLED")) {
[1f4fc80]633                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]634                sd->call_status = SKYPE_CALL_CANCELLED;
635        } else if (!strcmp(info, "STATUS FINISHED")) {
[1f4fc80]636                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]637                sd->call_status = SKYPE_CALL_FINISHED;
638        } else if (!strcmp(info, "STATUS REFUSED")) {
[1f4fc80]639                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]640                sd->call_status = SKYPE_CALL_REFUSED;
641        } else if (!strcmp(info, "STATUS UNPLACED")) {
642                if (sd->call_id)
643                        g_free(sd->call_id);
644                /* Save the ID for later usage (Cancel/Finish). */
645                sd->call_id = g_strdup(id);
646                sd->call_out = TRUE;
647        } else if (!strcmp(info, "STATUS FAILED")) {
[62f51ee9]648                imcb_error(ic, "Call failed: %s",
649                        skype_call_strerror(sd->failurereason));
[6b9d22a]650                sd->call_id = NULL;
651        } else if (!strncmp(info, "DURATION ", 9)) {
652                if (sd->call_duration)
653                        g_free(sd->call_duration);
654                sd->call_duration = g_strdup(info+9);
655        } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) {
656                info += 15;
[62f51ee9]657                if (!sd->call_status)
658                        return;
659                switch (sd->call_status) {
660                case SKYPE_CALL_RINGING:
661                        if (sd->call_out)
662                                imcb_log(ic, "You are currently ringing "
663                                        "the user %s.", info);
664                        else {
[c213d6b]665                                g_snprintf(buf, IRC_LINE_SIZE,
[62f51ee9]666                                        "The user %s is currently ringing you.",
667                                        info);
668                                skype_call_ask(ic, sd->call_id, buf);
[9f2f25f]669                        }
[62f51ee9]670                        break;
671                case SKYPE_CALL_MISSED:
672                        imcb_log(ic, "You have missed a call from user %s.",
673                                info);
674                        break;
675                case SKYPE_CALL_CANCELLED:
676                        imcb_log(ic, "You cancelled the call to the user %s.",
677                                info);
[6b9d22a]678                        sd->call_status = 0;
[62f51ee9]679                        sd->call_out = FALSE;
680                        break;
681                case SKYPE_CALL_REFUSED:
682                        if (sd->call_out)
683                                imcb_log(ic, "The user %s refused the call.",
684                                        info);
685                        else
686                                imcb_log(ic,
687                                        "You refused the call from user %s.",
688                                        info);
689                        sd->call_out = FALSE;
690                        break;
691                case SKYPE_CALL_FINISHED:
692                        if (sd->call_duration)
693                                imcb_log(ic,
694                                        "You finished the call to the user %s "
695                                        "(duration: %s seconds).",
696                                        info, sd->call_duration);
697                        else
698                                imcb_log(ic,
699                                        "You finished the call to the user %s.",
700                                        info);
701                        sd->call_out = FALSE;
702                        break;
703                default:
704                        /* Don't be noisy, ignore other statuses for now. */
705                        break;
[9f2f25f]706                }
[62f51ee9]707                sd->call_status = 0;
[9f2f25f]708        }
709}
710
[e200daf]711static void skype_parse_filetransfer(struct im_connection *ic, char *line)
712{
713        struct skype_data *sd = ic->proto_data;
714        char *id = strchr(line, ' ');
715
[6b9d22a]716        if (!++id)
717                return;
718        char *info = strchr(id, ' ');
719
720        if (!info)
721                return;
722        *info = '\0';
723        info++;
724        if (!strcmp(info, "STATUS NEW")) {
[1f4fc80]725                skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n",
[62f51ee9]726                        id);
[6b9d22a]727                sd->filetransfer_status = SKYPE_FILETRANSFER_NEW;
728        } else if (!strcmp(info, "STATUS FAILED")) {
[1f4fc80]729                skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n",
[62f51ee9]730                        id);
[6b9d22a]731                sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED;
732        } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) {
733                info += 15;
[62f51ee9]734                if (!sd->filetransfer_status)
735                        return;
736                switch (sd->filetransfer_status) {
737                case SKYPE_FILETRANSFER_NEW:
738                        imcb_log(ic, "The user %s offered a new file for you.",
739                                info);
740                        break;
741                case SKYPE_FILETRANSFER_FAILED:
742                        imcb_log(ic, "Failed to transfer file from user %s.",
743                                info);
744                        break;
[e200daf]745                }
[62f51ee9]746                sd->filetransfer_status = 0;
[e200daf]747        }
748}
749
[c35bf7a]750static void skype_parse_chat(struct im_connection *ic, char *line)
751{
752        struct skype_data *sd = ic->proto_data;
[c213d6b]753        char buf[IRC_LINE_SIZE];
[c35bf7a]754        char *id = strchr(line, ' ');
755
[6b9d22a]756        if (!++id)
757                return;
758        struct groupchat *gc;
759        char *info = strchr(id, ' ');
[c35bf7a]760
[6b9d22a]761        if (!info)
762                return;
763        *info = '\0';
764        info++;
765        /* Remove fake chat if we created one in skype_chat_with() */
766        gc = skype_chat_by_name(ic, "");
767        if (gc)
768                imcb_chat_free(gc);
769        if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) {
[72b60c7e]770                gc = imcb_chat_new(ic, id);
771#if defined(BITLBEE_VERSION_CODE) && BITLBEE_VERSION_CODE >= BITLBEE_VER(1, 2, 6)
772                imcb_chat_name_hint(gc, id);
773#endif
[1f4fc80]774                skype_printf(ic, "GET CHAT %s ADDER\n", id);
775                skype_printf(ic, "GET CHAT %s TOPIC\n", id);
[6b9d22a]776        } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) {
777                gc = imcb_chat_new(ic, id);
[72b60c7e]778#if defined(BITLBEE_VERSION_CODE) && BITLBEE_VERSION_CODE >= BITLBEE_VER(1, 2, 6)
779                imcb_chat_name_hint(gc, id);
780#endif
[6b9d22a]781                /* According to the docs this
782                 * is necessary. However it
783                 * does not seem the situation
784                 * and it would open an extra
785                 * window on our client, so
786                 * just leave it out. */
[1f4fc80]787                /*skype_printf(ic, "OPEN CHAT %s\n", id);*/
[5d9db76]788                g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com",
789                                sd->groupchat_with);
[6b9d22a]790                imcb_chat_add_buddy(gc, buf);
791                imcb_chat_add_buddy(gc, sd->username);
792                g_free(sd->groupchat_with);
793                sd->groupchat_with = NULL;
[1f4fc80]794                skype_printf(ic, "GET CHAT %s ADDER\n", id);
795                skype_printf(ic, "GET CHAT %s TOPIC\n", id);
[6b9d22a]796        } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) {
797                gc = skype_chat_by_name(ic, id);
[c35bf7a]798                if (gc)
[6b9d22a]799                        gc->data = (void *)FALSE;
800        } else if (!strncmp(info, "ADDER ", 6)) {
801                info += 6;
802                g_free(sd->adder);
803                sd->adder = g_strdup_printf("%s@skype.com", info);
804        } else if (!strncmp(info, "TOPIC ", 6)) {
805                info += 6;
806                gc = skype_chat_by_name(ic, id);
807                if (gc && (sd->adder || sd->topic_wait)) {
808                        if (sd->topic_wait) {
809                                sd->adder = g_strdup(sd->username);
810                                sd->topic_wait = 0;
[c35bf7a]811                        }
[6b9d22a]812                        imcb_chat_topic(gc, sd->adder, info, 0);
813                        g_free(sd->adder);
814                        sd->adder = NULL;
815                }
816        } else if (!strncmp(info, "ACTIVEMEMBERS ", 14)) {
817                info += 14;
818                gc = skype_chat_by_name(ic, id);
819                /* Hack! We set ->data to TRUE
820                 * while we're on the channel
821                 * so that we won't rejoin
822                 * after a /part. */
[62f51ee9]823                if (!gc || gc->data)
824                        return;
825                char **members = g_strsplit(info, " ", 0);
826                int i;
827                for (i = 0; members[i]; i++) {
828                        if (!strcmp(members[i], sd->username))
829                                continue;
[5d9db76]830                        g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com",
831                                        members[i]);
[62f51ee9]832                        if (!g_list_find_custom(gc->in_room, buf,
833                                (GCompareFunc)strcmp))
834                                imcb_chat_add_buddy(gc, buf);
[c35bf7a]835                }
[62f51ee9]836                imcb_chat_add_buddy(gc, sd->username);
837                g_strfreev(members);
[c35bf7a]838        }
839}
840
[2709f4c]841static void skype_parse_password(struct im_connection *ic, char *line)
842{
843        if (!strncmp(line+9, "OK", 2))
844                imcb_connected(ic);
845        else {
846                imcb_error(ic, "Authentication Failed");
847                imc_logout(ic, TRUE);
848        }
849}
850
[607f5e3]851static void skype_parse_profile(struct im_connection *ic, char *line)
852{
853        imcb_log(ic, "SkypeOut balance value is '%s'.", line+21);
854}
855
856static void skype_parse_ping(struct im_connection *ic, char *line)
857{
[1f4fc80]858        skype_printf(ic, "PONG\n");
[607f5e3]859}
860
861static void skype_parse_chats(struct im_connection *ic, char *line)
862{
863        char **i;
864        char **chats = g_strsplit(line + 6, ", ", 0);
865
866        i = chats;
867        while (*i) {
[1f4fc80]868                skype_printf(ic, "GET CHAT %s STATUS\n", *i);
869                skype_printf(ic, "GET CHAT %s ACTIVEMEMBERS\n", *i);
[607f5e3]870                i++;
871        }
872        g_strfreev(chats);
873}
874
[ff436ba]875typedef void (*skype_parser)(struct im_connection *ic, char *line);
876
[8c09bb3]877static gboolean skype_read_callback(gpointer data, gint fd,
878                                    b_input_condition cond)
[1323e36]879{
880        struct im_connection *ic = data;
881        struct skype_data *sd = ic->proto_data;
[c213d6b]882        char buf[IRC_LINE_SIZE];
[ff436ba]883        int st, i;
[6e14204]884        char **lines, **lineptr, *line;
[ff436ba]885        static struct parse_map {
886                char *k;
887                skype_parser v;
888        } parsers[] = {
889                { "USERS ", skype_parse_users },
890                { "USER ", skype_parse_user },
891                { "CHATMESSAGE ", skype_parse_chatmessage },
892                { "CALL ", skype_parse_call },
893                { "FILETRANSFER ", skype_parse_filetransfer },
894                { "CHAT ", skype_parse_chat },
895                { "PASSWORD ", skype_parse_password },
896                { "PROFILE PSTN_BALANCE ", skype_parse_profile },
897                { "PING", skype_parse_ping },
898                { "CHATS ", skype_parse_chats },
899        };
[1323e36]900
[5adcc65]901        if (!sd || sd->fd == -1)
[1323e36]902                return FALSE;
[7daec06]903        /* Read the whole data. */
[5adcc65]904        st = ssl_read(sd->ssl, buf, sizeof(buf));
905        if (st > 0) {
[1323e36]906                buf[st] = '\0';
[7daec06]907                /* Then split it up to lines. */
[9fd4241]908                lines = g_strsplit(buf, "\n", 0);
909                lineptr = lines;
[5adcc65]910                while ((line = *lineptr)) {
911                        if (!strlen(line))
[9fd4241]912                                break;
[b820226]913                        if (set_getbool(&ic->acc->set, "skypeconsole_receive"))
914                                imcb_buddy_msg(ic, "skypeconsole", line, 0, 0);
[6b9d22a]915                        for (i = 0; i < ARRAY_SIZE(parsers); i++)
916                                if (!strncmp(line, parsers[i].k,
917                                        strlen(parsers[i].k))) {
[ff436ba]918                                        parsers[i].v(ic, line);
919                                        break;
920                                }
[9fd4241]921                        lineptr++;
922                }
923                g_strfreev(lines);
[5adcc65]924        } else if (st == 0 || (st < 0 && !sockerr_again())) {
925                closesocket(sd->fd);
[1323e36]926                sd->fd = -1;
927
[5adcc65]928                imcb_error(ic, "Error while reading from server");
929                imc_logout(ic, TRUE);
[1323e36]930                return FALSE;
931        }
932        return TRUE;
933}
934
[5adcc65]935gboolean skype_start_stream(struct im_connection *ic)
[f06e3ac]936{
[1323e36]937        struct skype_data *sd = ic->proto_data;
[f06e3ac]938        int st;
939
[5adcc65]940        if (!sd)
[1fb89e3]941                return FALSE;
942
[5adcc65]943        if (sd->bfd <= 0)
[8c09bb3]944                sd->bfd = b_input_add(sd->fd, GAIM_INPUT_READ,
945                        skype_read_callback, ic);
[1323e36]946
[a0b206b]947        /* Log in */
[1f4fc80]948        skype_printf(ic, "USERNAME %s\n", ic->acc->user);
949        skype_printf(ic, "PASSWORD %s\n", ic->acc->pass);
[a0b206b]950
[7daec06]951        /* This will download all buddies. */
[1f4fc80]952        st = skype_printf(ic, "SEARCH FRIENDS\n");
953        skype_printf(ic, "SET USERSTATUS ONLINE\n");
[5acf9ab]954
955        /* Auto join to bookmarked chats if requested.*/
[1f4fc80]956        if (set_getbool(&ic->acc->set, "auto_join"))
957                skype_printf(ic, "SEARCH BOOKMARKEDCHATS\n");
[f06e3ac]958        return st;
959}
960
[5adcc65]961gboolean skype_connected(gpointer data, void *source, b_input_condition cond)
[f06e3ac]962{
963        struct im_connection *ic = data;
[c7304b2]964        struct skype_data *sd = ic->proto_data;
[5adcc65]965        if (!source) {
[c7304b2]966                sd->ssl = NULL;
[5adcc65]967                imcb_error(ic, "Could not connect to server");
968                imc_logout(ic, TRUE);
[c7304b2]969                return FALSE;
970        }
[5adcc65]971        imcb_log(ic, "Connected to server, logging in");
[f06e3ac]972        return skype_start_stream(ic);
973}
974
[5adcc65]975static void skype_login(account_t *acc)
[f06e3ac]976{
[5adcc65]977        struct im_connection *ic = imcb_new(acc);
978        struct skype_data *sd = g_new0(struct skype_data, 1);
[f06e3ac]979
980        ic->proto_data = sd;
981
[5adcc65]982        imcb_log(ic, "Connecting");
[8c09bb3]983        sd->ssl = ssl_connect(set_getstr(&acc->set, "server"),
984                set_getint(&acc->set, "port"), skype_connected, ic);
[5adcc65]985        sd->fd = sd->ssl ? ssl_getfd(sd->ssl) : -1;
986        sd->username = g_strdup(acc->user);
[f06e3ac]987
988        sd->ic = ic;
[08a355b]989
990        if (set_getbool(&acc->set, "skypeconsole"))
991                imcb_add_buddy(ic, "skypeconsole", NULL);
[f06e3ac]992}
993
[5adcc65]994static void skype_logout(struct im_connection *ic)
[f06e3ac]995{
996        struct skype_data *sd = ic->proto_data;
[98bca36]997
[1f4fc80]998        skype_printf(ic, "SET USERSTATUS OFFLINE\n");
[98bca36]999
[a3d6427]1000        g_free(sd->username);
[7613670]1001        g_free(sd->handle);
[f06e3ac]1002        g_free(sd);
[98bca36]1003        ic->proto_data = NULL;
[f06e3ac]1004}
1005
[8c09bb3]1006static int skype_buddy_msg(struct im_connection *ic, char *who, char *message,
1007                           int flags)
[93ece66]1008{
[1f4fc80]1009        char *ptr, *nick;
[93ece66]1010        int st;
1011
[cbec0d6]1012        nick = g_strdup(who);
[77c1abe]1013        ptr = strchr(nick, '@');
[5adcc65]1014        if (ptr)
[0bb1b7f]1015                *ptr = '\0';
[93ece66]1016
[08a355b]1017        if (!strncmp(who, "skypeconsole", 12))
[1f4fc80]1018                st = skype_printf(ic, "%s\n", message);
[08a355b]1019        else
[1f4fc80]1020                st = skype_printf(ic, "MESSAGE %s %s\n", nick, message);
[77c1abe]1021        g_free(nick);
[93ece66]1022
1023        return st;
1024}
1025
[5adcc65]1026const struct skype_away_state *skype_away_state_by_name(char *name)
[23411c6]1027{
1028        int i;
1029
[5adcc65]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;
[23411c6]1033
1034        return NULL;
1035}
1036
[8c09bb3]1037static void skype_set_away(struct im_connection *ic, char *state_txt,
1038                           char *message)
[f06e3ac]1039{
[23411c6]1040        const struct skype_away_state *state;
1041
[4b740c2]1042        if (state_txt == NULL)
1043                state = skype_away_state_by_name("Online");
[23411c6]1044        else
[5adcc65]1045                state = skype_away_state_by_name(state_txt);
[1f4fc80]1046        skype_printf(ic, "SET USERSTATUS %s\n", state->code);
[f06e3ac]1047}
1048
[5adcc65]1049static GList *skype_away_states(struct im_connection *ic)
[f06e3ac]1050{
[5adcc65]1051        static GList *l;
[adce2de]1052        int i;
[5adcc65]1053
1054        if (l == NULL)
1055                for (i = 0; skype_away_state_list[i].full_name; i++)
[8c09bb3]1056                        l = g_list_append(l,
1057                                (void *)skype_away_state_list[i].full_name);
[5adcc65]1058
[f06e3ac]1059        return l;
1060}
1061
[5adcc65]1062static char *skype_set_display_name(set_t *set, char *value)
[93dffea]1063{
1064        account_t *acc = set->data;
1065        struct im_connection *ic = acc->ic;
1066
[1f4fc80]1067        skype_printf(ic, "SET PROFILE FULLNAME %s", value);
[5adcc65]1068        return value;
[93dffea]1069}
1070
[5adcc65]1071static char *skype_set_balance(set_t *set, char *value)
[2af671a]1072{
1073        account_t *acc = set->data;
1074        struct im_connection *ic = acc->ic;
1075
[1f4fc80]1076        skype_printf(ic, "GET PROFILE PSTN_BALANCE");
[5adcc65]1077        return value;
[2af671a]1078}
1079
[5adcc65]1080static char *skype_set_call(set_t *set, char *value)
[b68b023]1081{
1082        account_t *acc = set->data;
1083        struct im_connection *ic = acc->ic;
[2eb4b1f]1084        struct skype_data *sd = ic->proto_data;
[1f4fc80]1085        char *nick, *ptr;
[b68b023]1086
[5adcc65]1087        if (value) {
[2eb4b1f]1088                user_t *u = user_find(acc->irc, value);
1089                /* We are starting a call */
[5adcc65]1090                if (!u)
[51dc72d]1091                        nick = g_strdup(value);
[a317ba6]1092                else
1093                        nick = g_strdup(u->handle);
[2eb4b1f]1094                ptr = strchr(nick, '@');
[5adcc65]1095                if (ptr)
[2eb4b1f]1096                        *ptr = '\0';
1097
[1f4fc80]1098                skype_printf(ic, "CALL %s", nick);
[2eb4b1f]1099                g_free(nick);
[5adcc65]1100        } else {
[2eb4b1f]1101                /* We are ending a call */
[5adcc65]1102                if (sd->call_id) {
[1f4fc80]1103                        skype_printf(ic, "SET CALL %s STATUS FINISHED",
[8c09bb3]1104                                sd->call_id);
[9fd7202]1105                        g_free(sd->call_id);
1106                        sd->call_id = NULL;
[5adcc65]1107                } else
[2eb4b1f]1108                        imcb_error(ic, "There are no active calls currently.");
[b68b023]1109        }
[5adcc65]1110        return value;
[b68b023]1111}
1112
[5adcc65]1113static void skype_add_buddy(struct im_connection *ic, char *who, char *group)
[f06e3ac]1114{
[1f4fc80]1115        char *nick, *ptr;
[6627d92]1116
[cbec0d6]1117        nick = g_strdup(who);
[6627d92]1118        ptr = strchr(nick, '@');
[5adcc65]1119        if (ptr)
[6627d92]1120                *ptr = '\0';
[1f4fc80]1121        skype_printf(ic, "SET USER %s BUDDYSTATUS 2 Please authorize me\n",
[8c09bb3]1122                nick);
[6627d92]1123        g_free(nick);
[f06e3ac]1124}
1125
[5adcc65]1126static void skype_remove_buddy(struct im_connection *ic, char *who, char *group)
[f06e3ac]1127{
[1f4fc80]1128        char *nick, *ptr;
[6627d92]1129
[cbec0d6]1130        nick = g_strdup(who);
[6627d92]1131        ptr = strchr(nick, '@');
[5adcc65]1132        if (ptr)
[6627d92]1133                *ptr = '\0';
[1f4fc80]1134        skype_printf(ic, "SET USER %s BUDDYSTATUS 1\n", nick);
[6627d92]1135        g_free(nick);
[f06e3ac]1136}
1137
[5adcc65]1138void skype_chat_msg(struct groupchat *gc, char *message, int flags)
[66c9558]1139{
[79e20f9]1140        struct im_connection *ic = gc->ic;
[1f4fc80]1141        skype_printf(ic, "CHATMESSAGE %s %s\n", gc->title, message);
[66c9558]1142}
1143
[5adcc65]1144void skype_chat_leave(struct groupchat *gc)
[b01dc6c]1145{
1146        struct im_connection *ic = gc->ic;
[1f4fc80]1147        skype_printf(ic, "ALTER CHAT %s LEAVE\n", gc->title);
[5adcc65]1148        gc->data = (void *)TRUE;
[760319d]1149}
1150
1151void skype_chat_invite(struct groupchat *gc, char *who, char *message)
1152{
1153        struct im_connection *ic = gc->ic;
[1f4fc80]1154        char *ptr, *nick;
[760319d]1155        nick = g_strdup(message);
1156        ptr = strchr(nick, '@');
[5adcc65]1157        if (ptr)
[760319d]1158                *ptr = '\0';
[1f4fc80]1159        skype_printf(ic, "ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick);
[760319d]1160        g_free(nick);
[b01dc6c]1161}
1162
[09e2a69]1163void skype_chat_topic(struct groupchat *gc, char *message)
1164{
1165        struct im_connection *ic = gc->ic;
[a5f76a2]1166        struct skype_data *sd = ic->proto_data;
[1f4fc80]1167        skype_printf(ic, "ALTER CHAT %s SETTOPIC %s\n",
[8c09bb3]1168                gc->title, message);
[a5f76a2]1169        sd->topic_wait = 1;
[09e2a69]1170}
1171
[86278cd]1172struct groupchat *skype_chat_with(struct im_connection *ic, char *who)
1173{
1174        struct skype_data *sd = ic->proto_data;
[1f4fc80]1175        char *ptr, *nick;
[86278cd]1176        nick = g_strdup(who);
1177        ptr = strchr(nick, '@');
[5adcc65]1178        if (ptr)
[86278cd]1179                *ptr = '\0';
[1f4fc80]1180        skype_printf(ic, "CHAT CREATE %s\n", nick);
[86278cd]1181        sd->groupchat_with = g_strdup(nick);
1182        g_free(nick);
[5652d43]1183        /* We create a fake chat for now. We will replace it with a real one in
1184         * the real callback. */
[5adcc65]1185        return imcb_chat_new(ic, "");
[86278cd]1186}
1187
[67454bd]1188static void skype_get_info(struct im_connection *ic, char *who)
1189{
[1f4fc80]1190        char *ptr, *nick;
[67454bd]1191        nick = g_strdup(who);
1192        ptr = strchr(nick, '@');
[5adcc65]1193        if (ptr)
[67454bd]1194                *ptr = '\0';
[1f4fc80]1195        skype_printf(ic, "GET USER %s FULLNAME\n", nick);
1196        skype_printf(ic, "GET USER %s PHONE_HOME\n", nick);
1197        skype_printf(ic, "GET USER %s PHONE_OFFICE\n", nick);
1198        skype_printf(ic, "GET USER %s PHONE_MOBILE\n", nick);
1199        skype_printf(ic, "GET USER %s NROF_AUTHED_BUDDIES\n", nick);
1200        skype_printf(ic, "GET USER %s TIMEZONE\n", nick);
1201        skype_printf(ic, "GET USER %s LASTONLINETIMESTAMP\n", nick);
1202        skype_printf(ic, "GET USER %s BIRTHDAY\n", nick);
1203        skype_printf(ic, "GET USER %s SEX\n", nick);
1204        skype_printf(ic, "GET USER %s LANGUAGE\n", nick);
1205        skype_printf(ic, "GET USER %s COUNTRY\n", nick);
1206        skype_printf(ic, "GET USER %s PROVINCE\n", nick);
1207        skype_printf(ic, "GET USER %s CITY\n", nick);
1208        skype_printf(ic, "GET USER %s HOMEPAGE\n", nick);
1209        skype_printf(ic, "GET USER %s ABOUT\n", nick);
[67454bd]1210}
1211
[5adcc65]1212static void skype_set_my_name(struct im_connection *ic, char *info)
[93dffea]1213{
[5adcc65]1214        skype_set_display_name(set_find(&ic->acc->set, "display_name"), info);
[93dffea]1215}
1216
[5adcc65]1217static void skype_init(account_t *acc)
[93dffea]1218{
1219        set_t *s;
1220
[8c09bb3]1221        s = set_add(&acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account,
1222                acc);
[93dffea]1223        s->flags |= ACC_SET_OFFLINE_ONLY;
1224
[5adcc65]1225        s = set_add(&acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc);
[93dffea]1226        s->flags |= ACC_SET_OFFLINE_ONLY;
1227
[8c09bb3]1228        s = set_add(&acc->set, "display_name", NULL, skype_set_display_name,
1229                acc);
[93dffea]1230        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
[b68b023]1231
[5adcc65]1232        s = set_add(&acc->set, "call", NULL, skype_set_call, acc);
[b68b023]1233        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
[2af671a]1234
[5adcc65]1235        s = set_add(&acc->set, "balance", NULL, skype_set_balance, acc);
[2af671a]1236        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
[bd417a1]1237
[5adcc65]1238        s = set_add(&acc->set, "skypeout_offline", "true", set_eval_bool, acc);
[08a355b]1239
[5adcc65]1240        s = set_add(&acc->set, "skypeconsole", "false", set_eval_bool, acc);
[08a355b]1241        s->flags |= ACC_SET_OFFLINE_ONLY;
[5acf9ab]1242
[8c09bb3]1243        s = set_add(&acc->set, "skypeconsole_receive", "false", set_eval_bool,
1244                acc);
[b820226]1245        s->flags |= ACC_SET_OFFLINE_ONLY;
1246
[5adcc65]1247        s = set_add(&acc->set, "auto_join", "false", set_eval_bool, acc);
[5acf9ab]1248        s->flags |= ACC_SET_OFFLINE_ONLY;
[f4d37c6]1249
[49a3c02]1250        s = set_add(&acc->set, "test_join", "false", set_eval_bool, acc);
1251        s->flags |= ACC_SET_OFFLINE_ONLY;
1252
[304aa33]1253        s = set_add(&acc->set, "show_moods", "false", set_eval_bool, acc);
1254
[f4d37c6]1255        s = set_add(&acc->set, "edit_prefix", "EDIT:",
[1e3120f]1256                        NULL, acc);
[93dffea]1257}
1258
[f06e3ac]1259void init_plugin(void)
1260{
[5adcc65]1261        struct prpl *ret = g_new0(struct prpl, 1);
[f06e3ac]1262
1263        ret->name = "skype";
1264        ret->login = skype_login;
1265        ret->init = skype_init;
1266        ret->logout = skype_logout;
[93ece66]1267        ret->buddy_msg = skype_buddy_msg;
[67454bd]1268        ret->get_info = skype_get_info;
[93dffea]1269        ret->set_my_name = skype_set_my_name;
[f06e3ac]1270        ret->away_states = skype_away_states;
[7daec06]1271        ret->set_away = skype_set_away;
[f06e3ac]1272        ret->add_buddy = skype_add_buddy;
1273        ret->remove_buddy = skype_remove_buddy;
[66c9558]1274        ret->chat_msg = skype_chat_msg;
[b01dc6c]1275        ret->chat_leave = skype_chat_leave;
[760319d]1276        ret->chat_invite = skype_chat_invite;
[86278cd]1277        ret->chat_with = skype_chat_with;
[f06e3ac]1278        ret->handle_cmp = g_strcasecmp;
[09e2a69]1279        ret->chat_topic = skype_chat_topic;
[5adcc65]1280        register_protocol(ret);
[f06e3ac]1281}
Note: See TracBrowser for help on using the repository browser.