source: skype/skype.c @ 3518933

Last change on this file since 3518933 was 3518933, checked in by Miklos Vajna <vmiklos@…>, at 2010-04-19T22:40:58Z

cosmetics

  • Property mode set to 100644
File size: 33.1 KB
RevLine 
[7daec06]1/*
2 *  skype.c - Skype plugin for BitlBee
[5adcc65]3 *
[7cf146f]4 *  Copyright (c) 2007, 2008, 2009, 2010 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);
[3518933]342        } else if (!strncmp(ptr, "FULLNAME ", 9))
[d7938f9]343                sd->info_fullname = g_strdup(ptr + 9);
[6e14204]344        else if (!strncmp(ptr, "PHONE_HOME ", 11))
[d7938f9]345                sd->info_phonehome = g_strdup(ptr + 11);
[6e14204]346        else if (!strncmp(ptr, "PHONE_OFFICE ", 13))
[d7938f9]347                sd->info_phoneoffice = g_strdup(ptr + 13);
[6e14204]348        else if (!strncmp(ptr, "PHONE_MOBILE ", 13))
[d7938f9]349                sd->info_phonemobile = g_strdup(ptr + 13);
[6e14204]350        else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20))
[d7938f9]351                sd->info_nrbuddies = g_strdup(ptr + 20);
[6e14204]352        else if (!strncmp(ptr, "TIMEZONE ", 9))
[d7938f9]353                sd->info_tz = g_strdup(ptr + 9);
[6e14204]354        else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20))
[d7938f9]355                sd->info_seen = g_strdup(ptr + 20);
[6e14204]356        else if (!strncmp(ptr, "BIRTHDAY ", 9))
[d7938f9]357                sd->info_birthday = g_strdup(ptr + 9);
[6e14204]358        else if (!strncmp(ptr, "SEX ", 4))
[d7938f9]359                sd->info_sex = g_strdup(ptr + 4);
[6e14204]360        else if (!strncmp(ptr, "LANGUAGE ", 9))
[d7938f9]361                sd->info_language = g_strdup(ptr + 9);
[6e14204]362        else if (!strncmp(ptr, "COUNTRY ", 8))
[d7938f9]363                sd->info_country = g_strdup(ptr + 8);
[6e14204]364        else if (!strncmp(ptr, "PROVINCE ", 9))
[d7938f9]365                sd->info_province = g_strdup(ptr + 9);
[6e14204]366        else if (!strncmp(ptr, "CITY ", 5))
[d7938f9]367                sd->info_city = g_strdup(ptr + 5);
[6e14204]368        else if (!strncmp(ptr, "HOMEPAGE ", 9))
[d7938f9]369                sd->info_homepage = g_strdup(ptr + 9);
[6e14204]370        else if (!strncmp(ptr, "ABOUT ", 6)) {
[d7938f9]371                sd->info_about = g_strdup(ptr + 6);
[6e14204]372
373                GString *st = g_string_new("Contact Information\n");
374                g_string_append_printf(st, "Skype Name: %s\n", user);
375                if (sd->info_fullname) {
376                        if (strlen(sd->info_fullname))
[62f51ee9]377                                g_string_append_printf(st, "Full Name: %s\n",
378                                        sd->info_fullname);
[6e14204]379                        g_free(sd->info_fullname);
380                }
381                if (sd->info_phonehome) {
382                        if (strlen(sd->info_phonehome))
[62f51ee9]383                                g_string_append_printf(st, "Home Phone: %s\n",
384                                        sd->info_phonehome);
[6e14204]385                        g_free(sd->info_phonehome);
386                }
387                if (sd->info_phoneoffice) {
388                        if (strlen(sd->info_phoneoffice))
[62f51ee9]389                                g_string_append_printf(st, "Office Phone: %s\n",
390                                        sd->info_phoneoffice);
[6e14204]391                        g_free(sd->info_phoneoffice);
392                }
393                if (sd->info_phonemobile) {
394                        if (strlen(sd->info_phonemobile))
[62f51ee9]395                                g_string_append_printf(st, "Mobile Phone: %s\n",
396                                        sd->info_phonemobile);
[6e14204]397                        g_free(sd->info_phonemobile);
398                }
399                g_string_append_printf(st, "Personal Information\n");
400                if (sd->info_nrbuddies) {
401                        if (strlen(sd->info_nrbuddies))
[62f51ee9]402                                g_string_append_printf(st,
403                                        "Contacts: %s\n", sd->info_nrbuddies);
[6e14204]404                        g_free(sd->info_nrbuddies);
405                }
406                if (sd->info_tz) {
407                        if (strlen(sd->info_tz)) {
408                                char ib[256];
409                                time_t t = time(NULL);
410                                t += atoi(sd->info_tz)-(60*60*24);
411                                struct tm *gt = gmtime(&t);
412                                strftime(ib, 256, "%H:%M:%S", gt);
[62f51ee9]413                                g_string_append_printf(st,
414                                        "Local Time: %s\n", ib);
[6e14204]415                        }
416                        g_free(sd->info_tz);
417                }
418                if (sd->info_seen) {
419                        if (strlen(sd->info_seen)) {
420                                char ib[256];
421                                time_t it = atoi(sd->info_seen);
422                                struct tm *tm = localtime(&it);
423                                strftime(ib, 256, ("%Y. %m. %d. %H:%M"), tm);
[62f51ee9]424                                g_string_append_printf(st,
425                                        "Last Seen: %s\n", ib);
[6e14204]426                        }
427                        g_free(sd->info_seen);
428                }
429                if (sd->info_birthday) {
[62f51ee9]430                        if (strlen(sd->info_birthday) &&
431                                strcmp(sd->info_birthday, "0")) {
[6e14204]432                                char ib[256];
433                                struct tm tm;
434                                strptime(sd->info_birthday, "%Y%m%d", &tm);
435                                strftime(ib, 256, "%B %d, %Y", &tm);
[62f51ee9]436                                g_string_append_printf(st,
437                                        "Birthday: %s\n", ib);
[6e14204]438
439                                strftime(ib, 256, "%Y", &tm);
440                                int year = atoi(ib);
441                                time_t t = time(NULL);
442                                struct tm *lt = localtime(&t);
[62f51ee9]443                                g_string_append_printf(st,
444                                        "Age: %d\n", lt->tm_year+1900-year);
[6e14204]445                        }
446                        g_free(sd->info_birthday);
447                }
448                if (sd->info_sex) {
449                        if (strlen(sd->info_sex)) {
450                                char *iptr = sd->info_sex;
451                                while (*iptr++)
452                                        *iptr = tolower(*iptr);
[62f51ee9]453                                g_string_append_printf(st,
454                                        "Gender: %s\n", sd->info_sex);
[6e14204]455                        }
456                        g_free(sd->info_sex);
457                }
458                if (sd->info_language) {
459                        if (strlen(sd->info_language)) {
460                                char *iptr = strchr(sd->info_language, ' ');
461                                if (iptr)
462                                        iptr++;
463                                else
464                                        iptr = sd->info_language;
[62f51ee9]465                                g_string_append_printf(st,
466                                        "Language: %s\n", iptr);
[6e14204]467                        }
468                        g_free(sd->info_language);
469                }
470                if (sd->info_country) {
471                        if (strlen(sd->info_country)) {
472                                char *iptr = strchr(sd->info_country, ' ');
473                                if (iptr)
474                                        iptr++;
475                                else
476                                        iptr = sd->info_country;
[62f51ee9]477                                g_string_append_printf(st,
478                                        "Country: %s\n", iptr);
[6e14204]479                        }
480                        g_free(sd->info_country);
481                }
482                if (sd->info_province) {
483                        if (strlen(sd->info_province))
[62f51ee9]484                                g_string_append_printf(st,
485                                        "Region: %s\n", sd->info_province);
[6e14204]486                        g_free(sd->info_province);
487                }
488                if (sd->info_city) {
489                        if (strlen(sd->info_city))
[62f51ee9]490                                g_string_append_printf(st,
491                                        "City: %s\n", sd->info_city);
[6e14204]492                        g_free(sd->info_city);
493                }
494                if (sd->info_homepage) {
495                        if (strlen(sd->info_homepage))
[62f51ee9]496                                g_string_append_printf(st,
497                                        "Homepage: %s\n", sd->info_homepage);
[6e14204]498                        g_free(sd->info_homepage);
499                }
500                if (sd->info_about) {
501                        if (strlen(sd->info_about))
[62f51ee9]502                                g_string_append_printf(st, "%s\n",
503                                        sd->info_about);
[6e14204]504                        g_free(sd->info_about);
505                }
506                imcb_log(ic, "%s", st->str);
507                g_string_free(st, TRUE);
508        }
509}
510
511static void skype_parse_chatmessage(struct im_connection *ic, char *line)
512{
513        struct skype_data *sd = ic->proto_data;
[c213d6b]514        char buf[IRC_LINE_SIZE];
[6e14204]515        char *id = strchr(line, ' ');
516
[6b9d22a]517        if (!++id)
518                return;
519        char *info = strchr(id, ' ');
520
521        if (!info)
522                return;
523        *info = '\0';
524        info++;
[7825f58]525        if (!strcmp(info, "STATUS RECEIVED") || !strncmp(info, "EDITED_TIMESTAMP", 16)) {
[6b9d22a]526                /* New message ID:
527                 * (1) Request its from field
528                 * (2) Request its body
529                 * (3) Request its type
530                 * (4) Query chatname
531                 */
[1f4fc80]532                skype_printf(ic, "GET CHATMESSAGE %s FROM_HANDLE\n", id);
[d1d5b34]533                if (!strcmp(info, "STATUS RECEIVED"))
534                        skype_printf(ic, "GET CHATMESSAGE %s BODY\n", id);
[d9ce18c]535                else
536                        sd->is_edit = 1;
[1f4fc80]537                skype_printf(ic, "GET CHATMESSAGE %s TYPE\n", id);
538                skype_printf(ic, "GET CHATMESSAGE %s CHATNAME\n", id);
[6b9d22a]539        } else if (!strncmp(info, "FROM_HANDLE ", 12)) {
540                info += 12;
541                /* New from field value. Store
542                 * it, then we can later use it
543                 * when we got the message's
544                 * body. */
545                g_free(sd->handle);
546                sd->handle = g_strdup_printf("%s@skype.com", info);
547        } else if (!strncmp(info, "EDITED_BY ", 10)) {
548                info += 10;
549                /* This is the same as
550                 * FROM_HANDLE, except that we
551                 * never request these lines
552                 * from Skype, we just get
553                 * them. */
554                g_free(sd->handle);
555                sd->handle = g_strdup_printf("%s@skype.com", info);
556        } else if (!strncmp(info, "BODY ", 5)) {
557                info += 5;
558                sd->body = g_list_append(sd->body, g_strdup(info));
559        }       else if (!strncmp(info, "TYPE ", 5)) {
560                info += 5;
561                g_free(sd->type);
562                sd->type = g_strdup(info);
[7825f58]563        } else if (!strncmp(info, "CHATNAME ", 9)) {
564                info += 9;
565                if (sd->handle && sd->body && sd->type) {
566                        struct groupchat *gc = skype_chat_by_name(ic, info);
567                        int i;
568                        for (i = 0; i < g_list_length(sd->body); i++) {
569                                char *body = g_list_nth_data(sd->body, i);
570                                if (!strcmp(sd->type, "SAID") ||
571                                        !strcmp(sd->type, "EMOTED")) {
572                                        if (!strcmp(sd->type, "SAID")) {
573                                                if (!sd->is_edit)
574                                                        g_snprintf(buf, IRC_LINE_SIZE, "%s",
575                                                                body);
576                                                else {
577                                                        g_snprintf(buf, IRC_LINE_SIZE, "%s %s",
578                                                                set_getstr(&ic->acc->set, "edit_prefix"),
579                                                                body);
580                                                        sd->is_edit = 0;
581                                                }
582                                        } else
583                                                g_snprintf(buf, IRC_LINE_SIZE, "/me %s",
584                                                        body);
585                                        if (!gc)
586                                                /* Private message */
587                                                imcb_buddy_msg(ic,
588                                                        sd->handle, buf, 0, 0);
589                                        else
590                                                /* Groupchat message */
591                                                imcb_chat_msg(gc,
592                                                        sd->handle, buf, 0, 0);
593                                } else if (!strcmp(sd->type, "SETTOPIC") && gc)
594                                        imcb_chat_topic(gc,
595                                                sd->handle, body, 0);
596                                else if (!strcmp(sd->type, "LEFT") && gc)
597                                        imcb_chat_remove_buddy(gc,
598                                                sd->handle, NULL);
[6e14204]599                        }
[7825f58]600                        g_list_free(sd->body);
601                        sd->body = NULL;
602                }
[6e14204]603        }
604}
605
[9f2f25f]606static void skype_parse_call(struct im_connection *ic, char *line)
607{
608        struct skype_data *sd = ic->proto_data;
609        char *id = strchr(line, ' ');
[c213d6b]610        char buf[IRC_LINE_SIZE];
[9f2f25f]611
[6b9d22a]612        if (!++id)
613                return;
614        char *info = strchr(id, ' ');
615
616        if (!info)
617                return;
618        *info = '\0';
619        info++;
620        if (!strncmp(info, "FAILUREREASON ", 14))
621                sd->failurereason = atoi(strchr(info, ' '));
622        else if (!strcmp(info, "STATUS RINGING")) {
623                if (sd->call_id)
624                        g_free(sd->call_id);
625                sd->call_id = g_strdup(id);
[1f4fc80]626                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]627                sd->call_status = SKYPE_CALL_RINGING;
628        } else if (!strcmp(info, "STATUS MISSED")) {
[1f4fc80]629                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]630                sd->call_status = SKYPE_CALL_MISSED;
631        } else if (!strcmp(info, "STATUS CANCELLED")) {
[1f4fc80]632                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]633                sd->call_status = SKYPE_CALL_CANCELLED;
634        } else if (!strcmp(info, "STATUS FINISHED")) {
[1f4fc80]635                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]636                sd->call_status = SKYPE_CALL_FINISHED;
637        } else if (!strcmp(info, "STATUS REFUSED")) {
[1f4fc80]638                skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
[6b9d22a]639                sd->call_status = SKYPE_CALL_REFUSED;
640        } else if (!strcmp(info, "STATUS UNPLACED")) {
641                if (sd->call_id)
642                        g_free(sd->call_id);
643                /* Save the ID for later usage (Cancel/Finish). */
644                sd->call_id = g_strdup(id);
645                sd->call_out = TRUE;
646        } else if (!strcmp(info, "STATUS FAILED")) {
[62f51ee9]647                imcb_error(ic, "Call failed: %s",
648                        skype_call_strerror(sd->failurereason));
[6b9d22a]649                sd->call_id = NULL;
650        } else if (!strncmp(info, "DURATION ", 9)) {
651                if (sd->call_duration)
652                        g_free(sd->call_duration);
653                sd->call_duration = g_strdup(info+9);
654        } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) {
655                info += 15;
[62f51ee9]656                if (!sd->call_status)
657                        return;
658                switch (sd->call_status) {
659                case SKYPE_CALL_RINGING:
660                        if (sd->call_out)
661                                imcb_log(ic, "You are currently ringing "
662                                        "the user %s.", info);
663                        else {
[c213d6b]664                                g_snprintf(buf, IRC_LINE_SIZE,
[62f51ee9]665                                        "The user %s is currently ringing you.",
666                                        info);
667                                skype_call_ask(ic, sd->call_id, buf);
[9f2f25f]668                        }
[62f51ee9]669                        break;
670                case SKYPE_CALL_MISSED:
671                        imcb_log(ic, "You have missed a call from user %s.",
672                                info);
673                        break;
674                case SKYPE_CALL_CANCELLED:
675                        imcb_log(ic, "You cancelled the call to the user %s.",
676                                info);
[6b9d22a]677                        sd->call_status = 0;
[62f51ee9]678                        sd->call_out = FALSE;
679                        break;
680                case SKYPE_CALL_REFUSED:
681                        if (sd->call_out)
682                                imcb_log(ic, "The user %s refused the call.",
683                                        info);
684                        else
685                                imcb_log(ic,
686                                        "You refused the call from user %s.",
687                                        info);
688                        sd->call_out = FALSE;
689                        break;
690                case SKYPE_CALL_FINISHED:
691                        if (sd->call_duration)
692                                imcb_log(ic,
693                                        "You finished the call to the user %s "
694                                        "(duration: %s seconds).",
695                                        info, sd->call_duration);
696                        else
697                                imcb_log(ic,
698                                        "You finished the call to the user %s.",
699                                        info);
700                        sd->call_out = FALSE;
701                        break;
702                default:
703                        /* Don't be noisy, ignore other statuses for now. */
704                        break;
[9f2f25f]705                }
[62f51ee9]706                sd->call_status = 0;
[9f2f25f]707        }
708}
709
[e200daf]710static void skype_parse_filetransfer(struct im_connection *ic, char *line)
711{
712        struct skype_data *sd = ic->proto_data;
713        char *id = strchr(line, ' ');
714
[6b9d22a]715        if (!++id)
716                return;
717        char *info = strchr(id, ' ');
718
719        if (!info)
720                return;
721        *info = '\0';
722        info++;
723        if (!strcmp(info, "STATUS NEW")) {
[1f4fc80]724                skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n",
[62f51ee9]725                        id);
[6b9d22a]726                sd->filetransfer_status = SKYPE_FILETRANSFER_NEW;
727        } else if (!strcmp(info, "STATUS FAILED")) {
[1f4fc80]728                skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n",
[62f51ee9]729                        id);
[6b9d22a]730                sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED;
731        } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) {
732                info += 15;
[62f51ee9]733                if (!sd->filetransfer_status)
734                        return;
735                switch (sd->filetransfer_status) {
736                case SKYPE_FILETRANSFER_NEW:
737                        imcb_log(ic, "The user %s offered a new file for you.",
738                                info);
739                        break;
740                case SKYPE_FILETRANSFER_FAILED:
741                        imcb_log(ic, "Failed to transfer file from user %s.",
742                                info);
743                        break;
[e200daf]744                }
[62f51ee9]745                sd->filetransfer_status = 0;
[e200daf]746        }
747}
748
[c35bf7a]749static void skype_parse_chat(struct im_connection *ic, char *line)
750{
751        struct skype_data *sd = ic->proto_data;
[c213d6b]752        char buf[IRC_LINE_SIZE];
[c35bf7a]753        char *id = strchr(line, ' ');
754
[6b9d22a]755        if (!++id)
756                return;
757        struct groupchat *gc;
758        char *info = strchr(id, ' ');
[c35bf7a]759
[6b9d22a]760        if (!info)
761                return;
762        *info = '\0';
763        info++;
764        /* Remove fake chat if we created one in skype_chat_with() */
765        gc = skype_chat_by_name(ic, "");
766        if (gc)
767                imcb_chat_free(gc);
768        if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) {
[72b60c7e]769                gc = imcb_chat_new(ic, id);
[b8c56a8]770#if BITLBEE_VERSION_CODE >= BITLBEE_VER(1, 2, 6)
[72b60c7e]771                imcb_chat_name_hint(gc, id);
772#endif
[1f4fc80]773                skype_printf(ic, "GET CHAT %s ADDER\n", id);
774                skype_printf(ic, "GET CHAT %s TOPIC\n", id);
[6b9d22a]775        } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) {
776                gc = imcb_chat_new(ic, id);
[b8c56a8]777#if BITLBEE_VERSION_CODE >= BITLBEE_VER(1, 2, 6)
[72b60c7e]778                imcb_chat_name_hint(gc, id);
779#endif
[6b9d22a]780                /* According to the docs this
781                 * is necessary. However it
782                 * does not seem the situation
783                 * and it would open an extra
784                 * window on our client, so
785                 * just leave it out. */
[1f4fc80]786                /*skype_printf(ic, "OPEN CHAT %s\n", id);*/
[5d9db76]787                g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com",
788                                sd->groupchat_with);
[6b9d22a]789                imcb_chat_add_buddy(gc, buf);
790                imcb_chat_add_buddy(gc, sd->username);
791                g_free(sd->groupchat_with);
792                sd->groupchat_with = NULL;
[1f4fc80]793                skype_printf(ic, "GET CHAT %s ADDER\n", id);
794                skype_printf(ic, "GET CHAT %s TOPIC\n", id);
[6b9d22a]795        } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) {
796                gc = skype_chat_by_name(ic, id);
[c35bf7a]797                if (gc)
[6b9d22a]798                        gc->data = (void *)FALSE;
799        } else if (!strncmp(info, "ADDER ", 6)) {
800                info += 6;
801                g_free(sd->adder);
802                sd->adder = g_strdup_printf("%s@skype.com", info);
803        } else if (!strncmp(info, "TOPIC ", 6)) {
804                info += 6;
805                gc = skype_chat_by_name(ic, id);
806                if (gc && (sd->adder || sd->topic_wait)) {
807                        if (sd->topic_wait) {
808                                sd->adder = g_strdup(sd->username);
809                                sd->topic_wait = 0;
[c35bf7a]810                        }
[6b9d22a]811                        imcb_chat_topic(gc, sd->adder, info, 0);
812                        g_free(sd->adder);
813                        sd->adder = NULL;
814                }
815        } else if (!strncmp(info, "ACTIVEMEMBERS ", 14)) {
816                info += 14;
817                gc = skype_chat_by_name(ic, id);
818                /* Hack! We set ->data to TRUE
819                 * while we're on the channel
820                 * so that we won't rejoin
821                 * after a /part. */
[62f51ee9]822                if (!gc || gc->data)
823                        return;
824                char **members = g_strsplit(info, " ", 0);
825                int i;
826                for (i = 0; members[i]; i++) {
827                        if (!strcmp(members[i], sd->username))
828                                continue;
[5d9db76]829                        g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com",
830                                        members[i]);
[62f51ee9]831                        if (!g_list_find_custom(gc->in_room, buf,
832                                (GCompareFunc)strcmp))
833                                imcb_chat_add_buddy(gc, buf);
[c35bf7a]834                }
[62f51ee9]835                imcb_chat_add_buddy(gc, sd->username);
836                g_strfreev(members);
[c35bf7a]837        }
838}
839
[2709f4c]840static void skype_parse_password(struct im_connection *ic, char *line)
841{
842        if (!strncmp(line+9, "OK", 2))
843                imcb_connected(ic);
844        else {
845                imcb_error(ic, "Authentication Failed");
846                imc_logout(ic, TRUE);
847        }
848}
849
[607f5e3]850static void skype_parse_profile(struct im_connection *ic, char *line)
851{
852        imcb_log(ic, "SkypeOut balance value is '%s'.", line+21);
853}
854
855static void skype_parse_ping(struct im_connection *ic, char *line)
856{
[1f4fc80]857        skype_printf(ic, "PONG\n");
[607f5e3]858}
859
860static void skype_parse_chats(struct im_connection *ic, char *line)
861{
862        char **i;
863        char **chats = g_strsplit(line + 6, ", ", 0);
864
865        i = chats;
866        while (*i) {
[1f4fc80]867                skype_printf(ic, "GET CHAT %s STATUS\n", *i);
868                skype_printf(ic, "GET CHAT %s ACTIVEMEMBERS\n", *i);
[607f5e3]869                i++;
870        }
871        g_strfreev(chats);
872}
873
[ff436ba]874typedef void (*skype_parser)(struct im_connection *ic, char *line);
875
[8c09bb3]876static gboolean skype_read_callback(gpointer data, gint fd,
877                                    b_input_condition cond)
[1323e36]878{
879        struct im_connection *ic = data;
880        struct skype_data *sd = ic->proto_data;
[c213d6b]881        char buf[IRC_LINE_SIZE];
[ff436ba]882        int st, i;
[6e14204]883        char **lines, **lineptr, *line;
[ff436ba]884        static struct parse_map {
885                char *k;
886                skype_parser v;
887        } parsers[] = {
888                { "USERS ", skype_parse_users },
889                { "USER ", skype_parse_user },
890                { "CHATMESSAGE ", skype_parse_chatmessage },
891                { "CALL ", skype_parse_call },
892                { "FILETRANSFER ", skype_parse_filetransfer },
893                { "CHAT ", skype_parse_chat },
894                { "PASSWORD ", skype_parse_password },
895                { "PROFILE PSTN_BALANCE ", skype_parse_profile },
896                { "PING", skype_parse_ping },
897                { "CHATS ", skype_parse_chats },
898        };
[1323e36]899
[5adcc65]900        if (!sd || sd->fd == -1)
[1323e36]901                return FALSE;
[7daec06]902        /* Read the whole data. */
[5adcc65]903        st = ssl_read(sd->ssl, buf, sizeof(buf));
904        if (st > 0) {
[1323e36]905                buf[st] = '\0';
[7daec06]906                /* Then split it up to lines. */
[9fd4241]907                lines = g_strsplit(buf, "\n", 0);
908                lineptr = lines;
[5adcc65]909                while ((line = *lineptr)) {
910                        if (!strlen(line))
[9fd4241]911                                break;
[b820226]912                        if (set_getbool(&ic->acc->set, "skypeconsole_receive"))
913                                imcb_buddy_msg(ic, "skypeconsole", line, 0, 0);
[6b9d22a]914                        for (i = 0; i < ARRAY_SIZE(parsers); i++)
915                                if (!strncmp(line, parsers[i].k,
916                                        strlen(parsers[i].k))) {
[ff436ba]917                                        parsers[i].v(ic, line);
918                                        break;
919                                }
[9fd4241]920                        lineptr++;
921                }
922                g_strfreev(lines);
[5adcc65]923        } else if (st == 0 || (st < 0 && !sockerr_again())) {
924                closesocket(sd->fd);
[1323e36]925                sd->fd = -1;
926
[5adcc65]927                imcb_error(ic, "Error while reading from server");
928                imc_logout(ic, TRUE);
[1323e36]929                return FALSE;
930        }
931        return TRUE;
932}
933
[5adcc65]934gboolean skype_start_stream(struct im_connection *ic)
[f06e3ac]935{
[1323e36]936        struct skype_data *sd = ic->proto_data;
[f06e3ac]937        int st;
938
[5adcc65]939        if (!sd)
[1fb89e3]940                return FALSE;
941
[5adcc65]942        if (sd->bfd <= 0)
[8c09bb3]943                sd->bfd = b_input_add(sd->fd, GAIM_INPUT_READ,
944                        skype_read_callback, ic);
[1323e36]945
[a0b206b]946        /* Log in */
[1f4fc80]947        skype_printf(ic, "USERNAME %s\n", ic->acc->user);
948        skype_printf(ic, "PASSWORD %s\n", ic->acc->pass);
[a0b206b]949
[7daec06]950        /* This will download all buddies. */
[1f4fc80]951        st = skype_printf(ic, "SEARCH FRIENDS\n");
952        skype_printf(ic, "SET USERSTATUS ONLINE\n");
[5acf9ab]953
954        /* Auto join to bookmarked chats if requested.*/
[1f4fc80]955        if (set_getbool(&ic->acc->set, "auto_join"))
956                skype_printf(ic, "SEARCH BOOKMARKEDCHATS\n");
[f06e3ac]957        return st;
958}
959
[5adcc65]960gboolean skype_connected(gpointer data, void *source, b_input_condition cond)
[f06e3ac]961{
962        struct im_connection *ic = data;
[c7304b2]963        struct skype_data *sd = ic->proto_data;
[5adcc65]964        if (!source) {
[c7304b2]965                sd->ssl = NULL;
[5adcc65]966                imcb_error(ic, "Could not connect to server");
967                imc_logout(ic, TRUE);
[c7304b2]968                return FALSE;
969        }
[5adcc65]970        imcb_log(ic, "Connected to server, logging in");
[f06e3ac]971        return skype_start_stream(ic);
972}
973
[5adcc65]974static void skype_login(account_t *acc)
[f06e3ac]975{
[5adcc65]976        struct im_connection *ic = imcb_new(acc);
977        struct skype_data *sd = g_new0(struct skype_data, 1);
[f06e3ac]978
979        ic->proto_data = sd;
980
[5adcc65]981        imcb_log(ic, "Connecting");
[8c09bb3]982        sd->ssl = ssl_connect(set_getstr(&acc->set, "server"),
983                set_getint(&acc->set, "port"), skype_connected, ic);
[5adcc65]984        sd->fd = sd->ssl ? ssl_getfd(sd->ssl) : -1;
985        sd->username = g_strdup(acc->user);
[f06e3ac]986
987        sd->ic = ic;
[08a355b]988
989        if (set_getbool(&acc->set, "skypeconsole"))
990                imcb_add_buddy(ic, "skypeconsole", NULL);
[f06e3ac]991}
992
[5adcc65]993static void skype_logout(struct im_connection *ic)
[f06e3ac]994{
995        struct skype_data *sd = ic->proto_data;
[98bca36]996
[1f4fc80]997        skype_printf(ic, "SET USERSTATUS OFFLINE\n");
[98bca36]998
[a3d6427]999        g_free(sd->username);
[7613670]1000        g_free(sd->handle);
[f06e3ac]1001        g_free(sd);
[98bca36]1002        ic->proto_data = NULL;
[f06e3ac]1003}
1004
[8c09bb3]1005static int skype_buddy_msg(struct im_connection *ic, char *who, char *message,
1006                           int flags)
[93ece66]1007{
[1f4fc80]1008        char *ptr, *nick;
[93ece66]1009        int st;
1010
[cbec0d6]1011        nick = g_strdup(who);
[77c1abe]1012        ptr = strchr(nick, '@');
[5adcc65]1013        if (ptr)
[0bb1b7f]1014                *ptr = '\0';
[93ece66]1015
[08a355b]1016        if (!strncmp(who, "skypeconsole", 12))
[1f4fc80]1017                st = skype_printf(ic, "%s\n", message);
[08a355b]1018        else
[1f4fc80]1019                st = skype_printf(ic, "MESSAGE %s %s\n", nick, message);
[77c1abe]1020        g_free(nick);
[93ece66]1021
1022        return st;
1023}
1024
[5adcc65]1025const struct skype_away_state *skype_away_state_by_name(char *name)
[23411c6]1026{
1027        int i;
1028
[5adcc65]1029        for (i = 0; skype_away_state_list[i].full_name; i++)
1030                if (g_strcasecmp(skype_away_state_list[i].full_name, name) == 0)
1031                        return skype_away_state_list + i;
[23411c6]1032
1033        return NULL;
1034}
1035
[8c09bb3]1036static void skype_set_away(struct im_connection *ic, char *state_txt,
1037                           char *message)
[f06e3ac]1038{
[23411c6]1039        const struct skype_away_state *state;
1040
[4b740c2]1041        if (state_txt == NULL)
1042                state = skype_away_state_by_name("Online");
[23411c6]1043        else
[5adcc65]1044                state = skype_away_state_by_name(state_txt);
[1f4fc80]1045        skype_printf(ic, "SET USERSTATUS %s\n", state->code);
[f06e3ac]1046}
1047
[5adcc65]1048static GList *skype_away_states(struct im_connection *ic)
[f06e3ac]1049{
[5adcc65]1050        static GList *l;
[adce2de]1051        int i;
[5adcc65]1052
1053        if (l == NULL)
1054                for (i = 0; skype_away_state_list[i].full_name; i++)
[8c09bb3]1055                        l = g_list_append(l,
1056                                (void *)skype_away_state_list[i].full_name);
[5adcc65]1057
[f06e3ac]1058        return l;
1059}
1060
[5adcc65]1061static char *skype_set_display_name(set_t *set, char *value)
[93dffea]1062{
1063        account_t *acc = set->data;
1064        struct im_connection *ic = acc->ic;
1065
[1f4fc80]1066        skype_printf(ic, "SET PROFILE FULLNAME %s", value);
[5adcc65]1067        return value;
[93dffea]1068}
1069
[5adcc65]1070static char *skype_set_balance(set_t *set, char *value)
[2af671a]1071{
1072        account_t *acc = set->data;
1073        struct im_connection *ic = acc->ic;
1074
[1f4fc80]1075        skype_printf(ic, "GET PROFILE PSTN_BALANCE");
[5adcc65]1076        return value;
[2af671a]1077}
1078
[5adcc65]1079static char *skype_set_call(set_t *set, char *value)
[b68b023]1080{
1081        account_t *acc = set->data;
1082        struct im_connection *ic = acc->ic;
[2eb4b1f]1083        struct skype_data *sd = ic->proto_data;
[1f4fc80]1084        char *nick, *ptr;
[b68b023]1085
[5adcc65]1086        if (value) {
[2eb4b1f]1087                user_t *u = user_find(acc->irc, value);
1088                /* We are starting a call */
[5adcc65]1089                if (!u)
[51dc72d]1090                        nick = g_strdup(value);
[a317ba6]1091                else
1092                        nick = g_strdup(u->handle);
[2eb4b1f]1093                ptr = strchr(nick, '@');
[5adcc65]1094                if (ptr)
[2eb4b1f]1095                        *ptr = '\0';
1096
[1f4fc80]1097                skype_printf(ic, "CALL %s", nick);
[2eb4b1f]1098                g_free(nick);
[5adcc65]1099        } else {
[2eb4b1f]1100                /* We are ending a call */
[5adcc65]1101                if (sd->call_id) {
[1f4fc80]1102                        skype_printf(ic, "SET CALL %s STATUS FINISHED",
[8c09bb3]1103                                sd->call_id);
[9fd7202]1104                        g_free(sd->call_id);
1105                        sd->call_id = NULL;
[5adcc65]1106                } else
[2eb4b1f]1107                        imcb_error(ic, "There are no active calls currently.");
[b68b023]1108        }
[5adcc65]1109        return value;
[b68b023]1110}
1111
[5adcc65]1112static void skype_add_buddy(struct im_connection *ic, char *who, char *group)
[f06e3ac]1113{
[1f4fc80]1114        char *nick, *ptr;
[6627d92]1115
[cbec0d6]1116        nick = g_strdup(who);
[6627d92]1117        ptr = strchr(nick, '@');
[5adcc65]1118        if (ptr)
[6627d92]1119                *ptr = '\0';
[1f4fc80]1120        skype_printf(ic, "SET USER %s BUDDYSTATUS 2 Please authorize me\n",
[8c09bb3]1121                nick);
[6627d92]1122        g_free(nick);
[f06e3ac]1123}
1124
[5adcc65]1125static void skype_remove_buddy(struct im_connection *ic, char *who, char *group)
[f06e3ac]1126{
[1f4fc80]1127        char *nick, *ptr;
[6627d92]1128
[cbec0d6]1129        nick = g_strdup(who);
[6627d92]1130        ptr = strchr(nick, '@');
[5adcc65]1131        if (ptr)
[6627d92]1132                *ptr = '\0';
[1f4fc80]1133        skype_printf(ic, "SET USER %s BUDDYSTATUS 1\n", nick);
[6627d92]1134        g_free(nick);
[f06e3ac]1135}
1136
[5adcc65]1137void skype_chat_msg(struct groupchat *gc, char *message, int flags)
[66c9558]1138{
[79e20f9]1139        struct im_connection *ic = gc->ic;
[1f4fc80]1140        skype_printf(ic, "CHATMESSAGE %s %s\n", gc->title, message);
[66c9558]1141}
1142
[5adcc65]1143void skype_chat_leave(struct groupchat *gc)
[b01dc6c]1144{
1145        struct im_connection *ic = gc->ic;
[1f4fc80]1146        skype_printf(ic, "ALTER CHAT %s LEAVE\n", gc->title);
[5adcc65]1147        gc->data = (void *)TRUE;
[760319d]1148}
1149
1150void skype_chat_invite(struct groupchat *gc, char *who, char *message)
1151{
1152        struct im_connection *ic = gc->ic;
[1f4fc80]1153        char *ptr, *nick;
[760319d]1154        nick = g_strdup(message);
1155        ptr = strchr(nick, '@');
[5adcc65]1156        if (ptr)
[760319d]1157                *ptr = '\0';
[1f4fc80]1158        skype_printf(ic, "ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick);
[760319d]1159        g_free(nick);
[b01dc6c]1160}
1161
[09e2a69]1162void skype_chat_topic(struct groupchat *gc, char *message)
1163{
1164        struct im_connection *ic = gc->ic;
[a5f76a2]1165        struct skype_data *sd = ic->proto_data;
[1f4fc80]1166        skype_printf(ic, "ALTER CHAT %s SETTOPIC %s\n",
[8c09bb3]1167                gc->title, message);
[a5f76a2]1168        sd->topic_wait = 1;
[09e2a69]1169}
1170
[86278cd]1171struct groupchat *skype_chat_with(struct im_connection *ic, char *who)
1172{
1173        struct skype_data *sd = ic->proto_data;
[1f4fc80]1174        char *ptr, *nick;
[86278cd]1175        nick = g_strdup(who);
1176        ptr = strchr(nick, '@');
[5adcc65]1177        if (ptr)
[86278cd]1178                *ptr = '\0';
[1f4fc80]1179        skype_printf(ic, "CHAT CREATE %s\n", nick);
[86278cd]1180        sd->groupchat_with = g_strdup(nick);
1181        g_free(nick);
[5652d43]1182        /* We create a fake chat for now. We will replace it with a real one in
1183         * the real callback. */
[5adcc65]1184        return imcb_chat_new(ic, "");
[86278cd]1185}
1186
[67454bd]1187static void skype_get_info(struct im_connection *ic, char *who)
1188{
[1f4fc80]1189        char *ptr, *nick;
[67454bd]1190        nick = g_strdup(who);
1191        ptr = strchr(nick, '@');
[5adcc65]1192        if (ptr)
[67454bd]1193                *ptr = '\0';
[1f4fc80]1194        skype_printf(ic, "GET USER %s FULLNAME\n", nick);
1195        skype_printf(ic, "GET USER %s PHONE_HOME\n", nick);
1196        skype_printf(ic, "GET USER %s PHONE_OFFICE\n", nick);
1197        skype_printf(ic, "GET USER %s PHONE_MOBILE\n", nick);
1198        skype_printf(ic, "GET USER %s NROF_AUTHED_BUDDIES\n", nick);
1199        skype_printf(ic, "GET USER %s TIMEZONE\n", nick);
1200        skype_printf(ic, "GET USER %s LASTONLINETIMESTAMP\n", nick);
1201        skype_printf(ic, "GET USER %s BIRTHDAY\n", nick);
1202        skype_printf(ic, "GET USER %s SEX\n", nick);
1203        skype_printf(ic, "GET USER %s LANGUAGE\n", nick);
1204        skype_printf(ic, "GET USER %s COUNTRY\n", nick);
1205        skype_printf(ic, "GET USER %s PROVINCE\n", nick);
1206        skype_printf(ic, "GET USER %s CITY\n", nick);
1207        skype_printf(ic, "GET USER %s HOMEPAGE\n", nick);
1208        skype_printf(ic, "GET USER %s ABOUT\n", nick);
[67454bd]1209}
1210
[5adcc65]1211static void skype_set_my_name(struct im_connection *ic, char *info)
[93dffea]1212{
[5adcc65]1213        skype_set_display_name(set_find(&ic->acc->set, "display_name"), info);
[93dffea]1214}
1215
[5adcc65]1216static void skype_init(account_t *acc)
[93dffea]1217{
1218        set_t *s;
1219
[8c09bb3]1220        s = set_add(&acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account,
1221                acc);
[93dffea]1222        s->flags |= ACC_SET_OFFLINE_ONLY;
1223
[5adcc65]1224        s = set_add(&acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc);
[93dffea]1225        s->flags |= ACC_SET_OFFLINE_ONLY;
1226
[8c09bb3]1227        s = set_add(&acc->set, "display_name", NULL, skype_set_display_name,
1228                acc);
[93dffea]1229        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
[b68b023]1230
[5adcc65]1231        s = set_add(&acc->set, "call", NULL, skype_set_call, acc);
[b68b023]1232        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
[2af671a]1233
[5adcc65]1234        s = set_add(&acc->set, "balance", NULL, skype_set_balance, acc);
[2af671a]1235        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
[bd417a1]1236
[5adcc65]1237        s = set_add(&acc->set, "skypeout_offline", "true", set_eval_bool, acc);
[08a355b]1238
[5adcc65]1239        s = set_add(&acc->set, "skypeconsole", "false", set_eval_bool, acc);
[08a355b]1240        s->flags |= ACC_SET_OFFLINE_ONLY;
[5acf9ab]1241
[8c09bb3]1242        s = set_add(&acc->set, "skypeconsole_receive", "false", set_eval_bool,
1243                acc);
[b820226]1244        s->flags |= ACC_SET_OFFLINE_ONLY;
1245
[5adcc65]1246        s = set_add(&acc->set, "auto_join", "false", set_eval_bool, acc);
[5acf9ab]1247        s->flags |= ACC_SET_OFFLINE_ONLY;
[f4d37c6]1248
[49a3c02]1249        s = set_add(&acc->set, "test_join", "false", set_eval_bool, acc);
1250        s->flags |= ACC_SET_OFFLINE_ONLY;
1251
[304aa33]1252        s = set_add(&acc->set, "show_moods", "false", set_eval_bool, acc);
1253
[f4d37c6]1254        s = set_add(&acc->set, "edit_prefix", "EDIT:",
[1e3120f]1255                        NULL, acc);
[93dffea]1256}
1257
[f06e3ac]1258void init_plugin(void)
1259{
[5adcc65]1260        struct prpl *ret = g_new0(struct prpl, 1);
[f06e3ac]1261
1262        ret->name = "skype";
1263        ret->login = skype_login;
1264        ret->init = skype_init;
1265        ret->logout = skype_logout;
[93ece66]1266        ret->buddy_msg = skype_buddy_msg;
[67454bd]1267        ret->get_info = skype_get_info;
[93dffea]1268        ret->set_my_name = skype_set_my_name;
[f06e3ac]1269        ret->away_states = skype_away_states;
[7daec06]1270        ret->set_away = skype_set_away;
[f06e3ac]1271        ret->add_buddy = skype_add_buddy;
1272        ret->remove_buddy = skype_remove_buddy;
[66c9558]1273        ret->chat_msg = skype_chat_msg;
[b01dc6c]1274        ret->chat_leave = skype_chat_leave;
[760319d]1275        ret->chat_invite = skype_chat_invite;
[86278cd]1276        ret->chat_with = skype_chat_with;
[f06e3ac]1277        ret->handle_cmp = g_strcasecmp;
[09e2a69]1278        ret->chat_topic = skype_chat_topic;
[5adcc65]1279        register_protocol(ret);
[f06e3ac]1280}
Note: See TracBrowser for help on using the repository browser.