source: skype/skype.c @ bc744df

Last change on this file since bc744df was bc744df, checked in by Miklos Vajna <vmiklos@…>, at 2009-01-07T02:36:25Z

whitespace cleanup in skype_away_state_list

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