source: skype/skype.c @ 8b8d1bed

Last change on this file since 8b8d1bed was 8b8d1bed, checked in by Miklos Vajna <vmiklos@…>, at 2011-01-01T16:55:20Z

Read list of groups on startup

This is just the begining, we do not

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