source: skype/skype.c @ d1d5b34

Last change on this file since d1d5b34 was d1d5b34, checked in by Miklos Vajna <vmiklos@…>, at 2010-03-07T19:04:36Z

Fix handling of edited messages.

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