source: skype/skype.c @ d87daf3

Last change on this file since d87daf3 was d87daf3, checked in by Miklos Vajna <vmiklos@…>, at 2008-02-29T01:40:12Z

replace the fake SKYPE_CALL_RINGING_OUT with a proper call_out variable

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