source: protocols/skype/skype.c @ 500419b

Last change on this file since 500419b was 500419b, checked in by Miklos Vajna <vmiklos@…>, at 2013-04-21T19:39:39Z

skype: avoid fake MBERS buddy in groupchats

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