13870
|
1 /**
|
|
2 * The QQ2003C protocol plugin
|
|
3 *
|
|
4 * for gaim
|
|
5 *
|
|
6 * Copyright (C) 2004 Puzzlebird
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22
|
|
23 // START OF FILE
|
|
24 /*****************************************************************************/
|
|
25 #include "debug.h" // gaim_debug
|
|
26 #include "conversation.h" // GaimConversation
|
|
27
|
|
28 #include "utils.h" // QQ_NAME_PREFIX, gaim_name_to_uid
|
|
29 #include "group_find.h"
|
|
30 #include "group_network.h" // group_packet
|
|
31 #include "qq.h" // qq_data
|
|
32
|
|
33 /*****************************************************************************/
|
|
34 // find a chat member's valid gaim_name of its nickname and chat room channel
|
|
35 gchar *qq_group_find_member_by_channel_and_nickname(GaimConnection * gc, gint channel, const gchar * who) {
|
|
36 qq_group *group;
|
|
37 qq_buddy *member;
|
|
38 GList *list;
|
|
39
|
|
40 g_return_val_if_fail(gc != NULL && who != NULL, NULL);
|
|
41
|
|
42 // if it starts with QQ_NAME_PREFIX, we think it is valid name already
|
|
43 // otherwise we think it is nickname and try to find the matching gaim_name
|
|
44 if (g_str_has_prefix(who, QQ_NAME_PREFIX) && gaim_name_to_uid(who) > 0)
|
|
45 return (gchar *) who;
|
|
46
|
|
47 group = qq_group_find_by_channel(gc, channel);
|
|
48 g_return_val_if_fail(group != NULL, NULL);
|
|
49
|
|
50 list = group->members;
|
|
51 member = NULL;
|
|
52 while (list != NULL) {
|
|
53 member = (qq_buddy *) list->data;
|
|
54 if (member->nickname != NULL && !g_ascii_strcasecmp(member->nickname, who))
|
|
55 break;
|
|
56 list = list->next;
|
|
57 } // while list
|
|
58
|
|
59 return (member == NULL) ? NULL : uid_to_gaim_name(member->uid);
|
|
60
|
|
61 } // qq_group_find_member_by_channel_and_nickname
|
|
62
|
|
63 /*****************************************************************************/
|
|
64 // find the internal_group_id by the reply packet sequence
|
|
65 // return TRUE if we have a record of it, return FALSE if not
|
|
66 gboolean qq_group_find_internal_group_id_by_seq(GaimConnection * gc, guint16 seq, guint32 * internal_group_id) {
|
|
67 GList *list;
|
|
68 qq_data *qd;
|
|
69 group_packet *p;
|
|
70
|
|
71 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && internal_group_id != NULL, FALSE);
|
|
72 qd = (qq_data *) gc->proto_data;
|
|
73
|
|
74 list = qd->group_packets;
|
|
75 while (list != NULL) {
|
|
76 p = (group_packet *) (list->data);
|
|
77 if (p->send_seq == seq) { // found and remove
|
|
78 *internal_group_id = p->internal_group_id;
|
|
79 qd->group_packets = g_list_remove(qd->group_packets, p);
|
|
80 g_free(p);
|
|
81 return TRUE;
|
|
82 } // if
|
|
83 list = list->next;
|
|
84 } // while
|
|
85
|
|
86 return FALSE;
|
|
87 } // qq_group_find_internal_group_id_by_seq
|
|
88
|
|
89 /*****************************************************************************/
|
|
90 // find a qq_buddy by uid, called by qq_im.c
|
|
91 qq_buddy *qq_group_find_member_by_uid(qq_group * group, guint32 uid)
|
|
92 {
|
|
93 GList *list;
|
|
94 qq_buddy *member;
|
|
95 g_return_val_if_fail(group != NULL && uid > 0, NULL);
|
|
96
|
|
97 list = group->members;
|
|
98 while (list != NULL) {
|
|
99 member = (qq_buddy *) list->data;
|
|
100 if (member->uid == uid)
|
|
101 return member;
|
|
102 else
|
|
103 list = list->next;
|
|
104 } // while list
|
|
105
|
|
106 return NULL;
|
|
107 } // qq_group_find_member_by_uid
|
|
108
|
|
109 /*****************************************************************************/
|
|
110 // remove a qq_buddy by uid, called by qq_group_opt.c
|
|
111 void qq_group_remove_member_by_uid(qq_group * group, guint32 uid)
|
|
112 {
|
|
113 GList *list;
|
|
114 qq_buddy *member;
|
|
115 g_return_if_fail(group != NULL && uid > 0);
|
|
116
|
|
117 list = group->members;
|
|
118 while (list != NULL) {
|
|
119 member = (qq_buddy *) list->data;
|
|
120 if (member->uid == uid) {
|
|
121 group->members = g_list_remove(group->members, member);
|
|
122 return;
|
|
123 } else
|
|
124 list = list->next;
|
|
125 } // while list
|
|
126
|
|
127 } // qq_group_remove_member_by_uid
|
|
128
|
|
129 /*****************************************************************************/
|
|
130 qq_buddy *qq_group_find_or_add_member(GaimConnection * gc, qq_group * group, guint32 member_uid) {
|
|
131 qq_buddy *member, *q_bud;
|
|
132 GaimBuddy *buddy;
|
|
133 g_return_val_if_fail(gc != NULL && group != NULL && member_uid > 0, NULL);
|
|
134
|
|
135 member = qq_group_find_member_by_uid(group, member_uid);
|
|
136 if (member == NULL) { // first appear during my session
|
|
137 member = g_new0(qq_buddy, 1);
|
|
138 member->uid = member_uid;
|
|
139 buddy = gaim_find_buddy(gaim_connection_get_account(gc), uid_to_gaim_name(member_uid));
|
|
140 if (buddy != NULL) {
|
|
141 q_bud = (qq_buddy *) buddy->proto_data;
|
|
142 if (q_bud != NULL)
|
|
143 member->nickname = g_strdup(q_bud->nickname);
|
|
144 else if (buddy->alias != NULL)
|
|
145 member->nickname = g_strdup(buddy->alias);
|
|
146 } // if buddy != NULL
|
|
147 group->members = g_list_append(group->members, member);
|
|
148 } // if member
|
|
149
|
|
150 return member;
|
|
151 } // qq_group_find_or_add_member
|
|
152
|
|
153 /*****************************************************************************/
|
|
154 // find a qq_group by chatroom channel
|
|
155 qq_group *qq_group_find_by_channel(GaimConnection * gc, gint channel)
|
|
156 {
|
|
157 GaimConversation *conv;
|
|
158 qq_data *qd;
|
|
159 qq_group *group;
|
|
160 GList *list;
|
|
161
|
|
162 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL);
|
|
163 qd = (qq_data *) gc->proto_data;
|
|
164
|
|
165 conv = gaim_find_chat(gc, channel);
|
|
166 g_return_val_if_fail(conv != NULL, NULL);
|
|
167
|
|
168 list = qd->groups;
|
|
169 group = NULL;
|
|
170 while (list != NULL) {
|
|
171 group = (qq_group *) list->data;
|
|
172 if (!g_ascii_strcasecmp(gaim_conversation_get_name(conv), group->group_name_utf8))
|
|
173 break;
|
|
174 list = list->next;
|
|
175 } // while list
|
|
176
|
|
177 return group;
|
|
178
|
|
179 } // qq_group_find_by_name
|
|
180
|
|
181 /*****************************************************************************/
|
|
182 // find a qq_group by internal_group_id
|
|
183 qq_group *qq_group_find_by_internal_group_id(GaimConnection * gc, guint32 internal_group_id) {
|
|
184
|
|
185 GList *list;
|
|
186 qq_group *group;
|
|
187 qq_data *qd;
|
|
188
|
|
189 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && internal_group_id > 0, NULL);
|
|
190
|
|
191 qd = (qq_data *) gc->proto_data;
|
|
192 if (qd->groups == NULL)
|
|
193 return NULL;
|
|
194
|
|
195 list = qd->groups;
|
|
196 while (list != NULL) {
|
|
197 group = (qq_group *) list->data;
|
|
198 if (group->internal_group_id == internal_group_id)
|
|
199 return group;
|
|
200 list = list->next;
|
|
201 } // while
|
|
202
|
|
203 return NULL;
|
|
204 } // qq_group_find_by_internal_group_id
|
|
205
|
|
206 /*****************************************************************************/
|
|
207 // END OF FILE
|