Changeset 89d6845


Ignore:
Timestamp:
2011-01-02T02:32:38Z (13 years ago)
Author:
Miklos Vajna <vmiklos@…>
Branches:
master
Children:
54ca269
Parents:
8b8d1bed
Message:

Parse the user list of each group

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skype/skype.c

    r8b8d1bed r89d6845  
    22 *  skype.c - Skype plugin for BitlBee
    33 *
    4  *  Copyright (c) 2007, 2008, 2009, 2010 by Miklos Vajna <vmiklos@frugalware.org>
     4 *  Copyright (c) 2007, 2008, 2009, 2010, 2011 by Miklos Vajna <vmiklos@frugalware.org>
    55 *
    66 *  This program is free software; you can redistribute it and/or modify
     
    108108        /* If this is just an update of an already received message. */
    109109        int is_edit;
     110        /* List of struct skype_group* */
     111        GList *groups;
    110112};
    111113
     
    119121        /* This is also used for call IDs for simplicity */
    120122        char *handle;
     123};
     124
     125struct skype_group {
     126        int id;
     127        char *name;
     128        GList *users;
    121129};
    122130
     
    736744}
    737745
     746static struct skype_group *skype_group_by_id(struct im_connection *ic, int id) {
     747        struct skype_data *sd = ic->proto_data;
     748        int i;
     749
     750        for (i = 0; i < g_list_length(sd->groups); i++) {
     751                struct skype_group *sg = (struct skype_group *)g_list_nth_data(sd->groups, i);
     752
     753                if (sg->id == id)
     754                        return sg;
     755        }
     756        return NULL;
     757}
     758
     759static void skype_group_free(struct skype_group* sg, gboolean usersonly) {
     760        int i;
     761       
     762        for (i = 0; i < g_list_length(sg->users); i++) {
     763                char *user = g_list_nth_data(sg->users, i);
     764                g_free(user);
     765        }
     766        sg->users = NULL;
     767        if (usersonly)
     768                return;
     769        g_free(sg->name);
     770        g_free(sg);
     771}
     772
     773static void skype_parse_group(struct im_connection *ic, char *line)
     774{
     775        struct skype_data *sd = ic->proto_data;
     776        char *id = strchr(line, ' ');
     777
     778        if (!++id)
     779                return;
     780
     781        char *info = strchr(id, ' ');
     782
     783        if (!info)
     784                return;
     785        *info = '\0';
     786        info++;
     787
     788        if (!strncmp(info, "DISPLAYNAME ", 12)) {
     789                info += 12;
     790
     791                /* Name given for a group ID: try to update it or insert a new
     792                 * one if not found */
     793                struct skype_group *sg = skype_group_by_id(ic, atoi(id));
     794                if (sg) {
     795                        g_free(sg->name);
     796                        sg->name = g_strdup(info);
     797                } else {
     798                        sg = g_new0(struct skype_group, 1);
     799                        sg->id = atoi(id);
     800                        sg->name = g_strdup(info);
     801                        sd->groups = g_list_append(sd->groups, sg);
     802                }
     803        } else if (!strncmp(info, "USERS ", 6)) {
     804                struct skype_group *sg = skype_group_by_id(ic, atoi(id));
     805
     806                if (sg) {
     807                        char **i;
     808                        char **users = g_strsplit(info + 6, ", ", 0);
     809
     810                        skype_group_free(sg, TRUE);
     811                        i = users;
     812                        while (*i) {
     813                                sg->users = g_list_append(sg->users, g_strdup(*i));
     814                                i++;
     815                        }
     816                        g_strfreev(users);
     817                } else
     818                        log_message(LOGLVL_ERROR, "No skype group with id %s. That's probably a bug.", id);
     819        }
     820}
     821
    738822static void skype_parse_chat(struct im_connection *ic, char *line)
    739823{
     
    893977                { "FILETRANSFER ", skype_parse_filetransfer },
    894978                { "CHAT ", skype_parse_chat },
     979                { "GROUP ", skype_parse_group },
    895980                { "PASSWORD ", skype_parse_password },
    896981                { "PROFILE PSTN_BALANCE ", skype_parse_profile },
     
    10071092{
    10081093        struct skype_data *sd = ic->proto_data;
     1094        int i;
    10091095
    10101096        skype_printf(ic, "SET USERSTATUS OFFLINE\n");
    10111097
     1098        for (i = 0; i < g_list_length(sd->groups); i++) {
     1099                struct skype_group *sg = (struct skype_group *)g_list_nth_data(sd->groups, i);
     1100                skype_group_free(sg, FALSE);
     1101        }
    10121102        g_free(sd->username);
    10131103        g_free(sd->handle);
Note: See TracChangeset for help on using the changeset viewer.