14192
|
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 #include "conversation.h"
|
|
24 #include "debug.h"
|
|
25 #include "util.h"
|
|
26
|
|
27 #include "group_find.h"
|
|
28 #include "group_network.h"
|
|
29 #include "qq.h"
|
|
30 #include "utils.h"
|
|
31
|
|
32 /* find a chat member's valid gaim_name of its nickname and chat room channel */
|
|
33 gchar *qq_group_find_member_by_channel_and_nickname(GaimConnection *gc, gint channel, const gchar *who)
|
|
34 {
|
|
35 qq_group *group;
|
|
36 qq_buddy *member;
|
|
37 GList *list;
|
|
38
|
|
39 g_return_val_if_fail(gc != NULL && who != NULL, NULL);
|
|
40
|
|
41 /* if it starts with QQ_NAME_PREFIX, we think it is valid name already
|
|
42 * otherwise we think it is nickname and try to find the matching gaim_name */
|
|
43 if (gaim_str_has_prefix(who, QQ_NAME_PREFIX) && gaim_name_to_uid(who) > 0)
|
|
44 return (gchar *) who;
|
|
45
|
|
46 group = qq_group_find_by_channel(gc, channel);
|
|
47 g_return_val_if_fail(group != NULL, NULL);
|
|
48
|
|
49 list = group->members;
|
|
50 member = NULL;
|
|
51 while (list != NULL) {
|
|
52 member = (qq_buddy *) list->data;
|
|
53 if (member->nickname != NULL && !g_ascii_strcasecmp(member->nickname, who))
|
|
54 break;
|
|
55 list = list->next;
|
|
56 }
|
|
57
|
|
58 return (member == NULL) ? NULL : uid_to_gaim_name(member->uid);
|
|
59 }
|
|
60
|
|
61 /* find the internal_group_id by the reply packet sequence
|
|
62 * return TRUE if we have a record of it, return FALSE if not */
|
|
63 gboolean qq_group_find_internal_group_id_by_seq(GaimConnection *gc, guint16 seq, guint32 *internal_group_id)
|
|
64 {
|
|
65 GList *list;
|
|
66 qq_data *qd;
|
|
67 group_packet *p;
|
|
68
|
|
69 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && internal_group_id != NULL, FALSE);
|
|
70 qd = (qq_data *) gc->proto_data;
|
|
71
|
|
72 list = qd->group_packets;
|
|
73 while (list != NULL) {
|
|
74 p = (group_packet *) (list->data);
|
|
75 if (p->send_seq == seq) { /* found and remove */
|
|
76 *internal_group_id = p->internal_group_id;
|
|
77 qd->group_packets = g_list_remove(qd->group_packets, p);
|
|
78 g_free(p);
|
|
79 return TRUE;
|
|
80 }
|
|
81 list = list->next;
|
|
82 }
|
|
83
|
|
84 return FALSE;
|
|
85 }
|
|
86
|
|
87 /* find a qq_buddy by uid, called by qq_im.c */
|
|
88 qq_buddy *qq_group_find_member_by_uid(qq_group *group, guint32 uid)
|
|
89 {
|
|
90 GList *list;
|
|
91 qq_buddy *member;
|
|
92 g_return_val_if_fail(group != NULL && uid > 0, NULL);
|
|
93
|
|
94 list = group->members;
|
|
95 while (list != NULL) {
|
|
96 member = (qq_buddy *) list->data;
|
|
97 if (member->uid == uid)
|
|
98 return member;
|
|
99 else
|
|
100 list = list->next;
|
|
101 }
|
|
102
|
|
103 return NULL;
|
|
104 }
|
|
105
|
|
106 /* remove a qq_buddy by uid, called by qq_group_opt.c */
|
|
107 void qq_group_remove_member_by_uid(qq_group *group, guint32 uid)
|
|
108 {
|
|
109 GList *list;
|
|
110 qq_buddy *member;
|
|
111 g_return_if_fail(group != NULL && uid > 0);
|
|
112
|
|
113 list = group->members;
|
|
114 while (list != NULL) {
|
|
115 member = (qq_buddy *) list->data;
|
|
116 if (member->uid == uid) {
|
|
117 group->members = g_list_remove(group->members, member);
|
|
118 return;
|
|
119 } else {
|
|
120 list = list->next;
|
|
121 }
|
|
122 }
|
|
123 }
|
|
124
|
|
125 qq_buddy *qq_group_find_or_add_member(GaimConnection *gc, qq_group *group, guint32 member_uid)
|
|
126 {
|
|
127 qq_buddy *member, *q_bud;
|
|
128 GaimBuddy *buddy;
|
|
129 g_return_val_if_fail(gc != NULL && group != NULL && member_uid > 0, NULL);
|
|
130
|
|
131 member = qq_group_find_member_by_uid(group, member_uid);
|
|
132 if (member == NULL) { /* first appear during my session */
|
|
133 member = g_new0(qq_buddy, 1);
|
|
134 member->uid = member_uid;
|
|
135 buddy = gaim_find_buddy(gaim_connection_get_account(gc), uid_to_gaim_name(member_uid));
|
|
136 if (buddy != NULL) {
|
|
137 q_bud = (qq_buddy *) buddy->proto_data;
|
|
138 if (q_bud != NULL)
|
|
139 member->nickname = g_strdup(q_bud->nickname);
|
|
140 else if (buddy->alias != NULL)
|
|
141 member->nickname = g_strdup(buddy->alias);
|
|
142 }
|
|
143 group->members = g_list_append(group->members, member);
|
|
144 }
|
|
145
|
|
146 return member;
|
|
147 }
|
|
148
|
|
149 /* find a qq_group by chatroom channel */
|
|
150 qq_group *qq_group_find_by_channel(GaimConnection *gc, gint channel)
|
|
151 {
|
|
152 GaimConversation *conv;
|
|
153 qq_data *qd;
|
|
154 qq_group *group;
|
|
155 GList *list;
|
|
156
|
|
157 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL);
|
|
158 qd = (qq_data *) gc->proto_data;
|
|
159
|
|
160 conv = gaim_find_chat(gc, channel);
|
|
161 g_return_val_if_fail(conv != NULL, NULL);
|
|
162
|
|
163 list = qd->groups;
|
|
164 group = NULL;
|
|
165 while (list != NULL) {
|
|
166 group = (qq_group *) list->data;
|
|
167 if (!g_ascii_strcasecmp(gaim_conversation_get_name(conv), group->group_name_utf8))
|
|
168 break;
|
|
169 list = list->next;
|
|
170 }
|
|
171
|
|
172 return group;
|
|
173 }
|
|
174
|
|
175 /* find a qq_group by internal_group_id */
|
|
176 qq_group *qq_group_find_by_internal_group_id(GaimConnection *gc, guint32 internal_group_id)
|
|
177 {
|
|
178 GList *list;
|
|
179 qq_group *group;
|
|
180 qq_data *qd;
|
|
181
|
|
182 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && internal_group_id > 0, NULL);
|
|
183
|
|
184 qd = (qq_data *) gc->proto_data;
|
|
185 if (qd->groups == NULL)
|
|
186 return NULL;
|
|
187
|
|
188 list = qd->groups;
|
|
189 while (list != NULL) {
|
|
190 group = (qq_group *) list->data;
|
|
191 if (group->internal_group_id == internal_group_id)
|
|
192 return group;
|
|
193 list = list->next;
|
|
194 }
|
|
195
|
|
196 return NULL;
|
|
197 }
|