source: skype/skype.c @ 039116a

Last change on this file since 039116a was 039116a, checked in by Miklos Vajna <vmiklos@…>, at 2008-06-28T00:09:25Z

add support for bitlbee-1.2.1

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