Changeset c35bf7a


Ignore:
Timestamp:
2009-01-07T01:29:22Z (15 years ago)
Author:
Miklos Vajna <vmiklos@…>
Branches:
master
Children:
2709f4c
Parents:
e200daf
Message:

introduce skype_parse_chat()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skype/skype.c

    re200daf rc35bf7a  
    693693}
    694694
     695static void skype_parse_chat(struct im_connection *ic, char *line)
     696{
     697        struct skype_data *sd = ic->proto_data;
     698        char buf[1024];
     699        char *id = strchr(line, ' ');
     700
     701        if (++id) {
     702                struct groupchat *gc;
     703                char *info = strchr(id, ' ');
     704
     705                if (!info)
     706                        return;
     707                *info = '\0';
     708                info++;
     709                /* Remove fake chat if we created one in skype_chat_with() */
     710                gc = skype_chat_by_name(ic, "");
     711                if (gc)
     712                        imcb_chat_free(gc);
     713                if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) {
     714                        imcb_chat_new(ic, id);
     715                        g_snprintf(buf, 1024, "GET CHAT %s ADDER\n", id);
     716                        skype_write(ic, buf);
     717                        g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id);
     718                        skype_write(ic, buf);
     719                } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) {
     720                        gc = imcb_chat_new(ic, id);
     721                        /* According to the docs this
     722                         * is necessary. However it
     723                         * does not seem the situation
     724                         * and it would open an extra
     725                         * window on our client, so
     726                         * just leave it out. */
     727                        /*g_snprintf(buf, 1024, "OPEN CHAT %s\n", id);
     728                          skype_write(ic, buf);*/
     729                        g_snprintf(buf, 1024, "%s@skype.com", sd->groupchat_with);
     730                        imcb_chat_add_buddy(gc, buf);
     731                        imcb_chat_add_buddy(gc, sd->username);
     732                        g_free(sd->groupchat_with);
     733                        sd->groupchat_with = NULL;
     734                        g_snprintf(buf, 1024, "GET CHAT %s ADDER\n", id);
     735                        skype_write(ic, buf);
     736                        g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id);
     737                        skype_write(ic, buf);
     738                } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) {
     739                        gc = skype_chat_by_name(ic, id);
     740                        if (gc)
     741                                gc->data = (void *)FALSE;
     742                } else if (!strncmp(info, "ADDER ", 6)) {
     743                        info += 6;
     744                        g_free(sd->adder);
     745                        sd->adder = g_strdup_printf("%s@skype.com", info);
     746                } else if (!strncmp(info, "TOPIC ", 6)) {
     747                        info += 6;
     748                        gc = skype_chat_by_name(ic, id);
     749                        if (gc && (sd->adder || sd->topic_wait)) {
     750                                if (sd->topic_wait) {
     751                                        sd->adder = g_strdup(sd->username);
     752                                        sd->topic_wait = 0;
     753                                }
     754                                imcb_chat_topic(gc, sd->adder, info, 0);
     755                                g_free(sd->adder);
     756                                sd->adder = NULL;
     757                        }
     758                } else if (!strncmp(info, "ACTIVEMEMBERS ", 14)) {
     759                        info += 14;
     760                        gc = skype_chat_by_name(ic, id);
     761                        /* Hack! We set ->data to TRUE
     762                         * while we're on the channel
     763                         * so that we won't rejoin
     764                         * after a /part. */
     765                        if (gc && !gc->data) {
     766                                char **members = g_strsplit(info, " ", 0);
     767                                int i;
     768                                for (i = 0; members[i]; i++) {
     769                                        if (!strcmp(members[i], sd->username))
     770                                                continue;
     771                                        g_snprintf(buf, 1024, "%s@skype.com", members[i]);
     772                                        if (!g_list_find_custom(gc->in_room, buf, (GCompareFunc)strcmp))
     773                                                imcb_chat_add_buddy(gc, buf);
     774                                }
     775                                imcb_chat_add_buddy(gc, sd->username);
     776                                g_strfreev(members);
     777                        }
     778                }
     779        }
     780}
     781
    695782static gboolean skype_read_callback(gpointer data, gint fd,
    696783                                    b_input_condition cond)
     
    726813                        else if (!strncmp(line, "FILETRANSFER ", 13))
    727814                                skype_parse_filetransfer(ic, line);
    728                         else if (!strncmp(line, "CHAT ", 5)) {
    729                                 char *id = strchr(line, ' ');
    730                                 if (++id) {
    731                                         char *info = strchr(id, ' ');
    732                                         if (info)
    733                                                 *info = '\0';
    734                                         info++;
    735                                         /* Remove fake chat if we created one in skype_chat_with() */
    736                                         struct groupchat *gc = skype_chat_by_name(ic, "");
    737                                         if (gc)
    738                                                 imcb_chat_free(gc);
    739                                         if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) {
    740                                                 imcb_chat_new(ic, id);
    741                                                 g_snprintf(buf, 1024, "GET CHAT %s ADDER\n", id);
    742                                                 skype_write(ic, buf);
    743                                                 g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id);
    744                                                 skype_write(ic, buf);
    745                                         } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) {
    746                                                 gc = imcb_chat_new(ic, id);
    747                                                 /* According to the docs this
    748                                                  * is necessary. However it
    749                                                  * does not seem the situation
    750                                                  * and it would open an extra
    751                                                  * window on our client, so
    752                                                  * just leave it out. */
    753                                                 /*g_snprintf(buf, 1024, "OPEN CHAT %s\n", id);
    754                                                 skype_write(ic, buf);*/
    755                                                 g_snprintf(buf, 1024, "%s@skype.com", sd->groupchat_with);
    756                                                 imcb_chat_add_buddy(gc, buf);
    757                                                 imcb_chat_add_buddy(gc, sd->username);
    758                                                 g_free(sd->groupchat_with);
    759                                                 sd->groupchat_with = NULL;
    760                                                 g_snprintf(buf, 1024, "GET CHAT %s ADDER\n", id);
    761                                                 skype_write(ic, buf);
    762                                                 g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id);
    763                                                 skype_write(ic, buf);
    764                                         } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) {
    765                                                 gc = skype_chat_by_name(ic, id);
    766                                                 if (gc)
    767                                                         gc->data = (void *)FALSE;
    768                                         } else if (!strncmp(info, "ADDER ", 6)) {
    769                                                 info += 6;
    770                                                 g_free(sd->adder);
    771                                                 sd->adder = g_strdup_printf("%s@skype.com", info);
    772                                         } else if (!strncmp(info, "TOPIC ", 6)) {
    773                                                 info += 6;
    774                                                 gc = skype_chat_by_name(ic, id);
    775                                                 if (gc && (sd->adder || sd->topic_wait)) {
    776                                                         if (sd->topic_wait) {
    777                                                                 sd->adder = g_strdup(sd->username);
    778                                                                 sd->topic_wait = 0;
    779                                                         }
    780                                                         imcb_chat_topic(gc, sd->adder, info, 0);
    781                                                         g_free(sd->adder);
    782                                                         sd->adder = NULL;
    783                                                 }
    784                                         } else if (!strncmp(info, "ACTIVEMEMBERS ", 14)) {
    785                                                 info += 14;
    786                                                 gc = skype_chat_by_name(ic, id);
    787                                                 /* Hack! We set ->data to TRUE
    788                                                  * while we're on the channel
    789                                                  * so that we won't rejoin
    790                                                  * after a /part. */
    791                                                 if (gc && !gc->data) {
    792                                                         char **members = g_strsplit(info, " ", 0);
    793                                                         int i;
    794                                                         for (i = 0; members[i]; i++) {
    795                                                                 if (!strcmp(members[i], sd->username))
    796                                                                         continue;
    797                                                                 g_snprintf(buf, 1024, "%s@skype.com", members[i]);
    798                                                                 if (!g_list_find_custom(gc->in_room, buf, (GCompareFunc)strcmp))
    799                                                                         imcb_chat_add_buddy(gc, buf);
    800                                                         }
    801                                                         imcb_chat_add_buddy(gc, sd->username);
    802                                                         g_strfreev(members);
    803                                                 }
    804                                         }
    805                                 }
    806                         } else if (!strncmp(line, "PASSWORD ", 9)) {
     815                        else if (!strncmp(line, "CHAT ", 5))
     816                                skype_parse_chat(ic, line);
     817                        else if (!strncmp(line, "PASSWORD ", 9)) {
    807818                                if (!strncmp(line+9, "OK", 2))
    808819                                        imcb_connected(ic);
Note: See TracChangeset for help on using the changeset viewer.