Mercurial > pidgin.yaz
annotate src/protocols/qq/group_find.c @ 14115:8ea1929c4c69
[gaim-migrate @ 16749]
Fix a bunch of warnings that I caused.
Sorry, I should have compiled before committing.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 14 Aug 2006 07:27:41 +0000 |
parents | 44e1bf83dadf |
children |
rev | line source |
---|---|
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 | |
14021 | 23 #include "conversation.h" |
24 #include "debug.h" | |
14055
44e1bf83dadf
[gaim-migrate @ 16668]
Richard Laager <rlaager@wiktel.com>
parents:
14021
diff
changeset
|
25 #include "util.h" |
13870 | 26 |
27 #include "group_find.h" | |
14021 | 28 #include "group_network.h" |
29 #include "qq.h" | |
30 #include "utils.h" | |
13870 | 31 |
14021 | 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 { | |
13870 | 35 qq_group *group; |
36 qq_buddy *member; | |
37 GList *list; | |
38 | |
39 g_return_val_if_fail(gc != NULL && who != NULL, NULL); | |
40 | |
14021 | 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 */ | |
14055
44e1bf83dadf
[gaim-migrate @ 16668]
Richard Laager <rlaager@wiktel.com>
parents:
14021
diff
changeset
|
43 if (gaim_str_has_prefix(who, QQ_NAME_PREFIX) && gaim_name_to_uid(who) > 0) |
13870 | 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; | |
14021 | 56 } |
13870 | 57 |
58 return (member == NULL) ? NULL : uid_to_gaim_name(member->uid); | |
14021 | 59 } |
13870 | 60 |
14021 | 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 { | |
13870 | 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); | |
14021 | 75 if (p->send_seq == seq) { /* found and remove */ |
13870 | 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; | |
14021 | 80 } |
13870 | 81 list = list->next; |
14021 | 82 } |
13870 | 83 |
84 return FALSE; | |
14021 | 85 } |
13870 | 86 |
14021 | 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) | |
13870 | 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; | |
14021 | 101 } |
13870 | 102 |
103 return NULL; | |
14021 | 104 } |
13870 | 105 |
14021 | 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) | |
13870 | 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; | |
14021 | 119 } else { |
13870 | 120 list = list->next; |
14021 | 121 } |
122 } | |
123 } | |
13870 | 124 |
14021 | 125 qq_buddy *qq_group_find_or_add_member(GaimConnection *gc, qq_group *group, guint32 member_uid) |
126 { | |
13870 | 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); | |
14021 | 132 if (member == NULL) { /* first appear during my session */ |
13870 | 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); | |
14021 | 142 } |
13870 | 143 group->members = g_list_append(group->members, member); |
14021 | 144 } |
13870 | 145 |
146 return member; | |
14021 | 147 } |
13870 | 148 |
14021 | 149 /* find a qq_group by chatroom channel */ |
150 qq_group *qq_group_find_by_channel(GaimConnection *gc, gint channel) | |
13870 | 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; | |
14021 | 170 } |
13870 | 171 |
172 return group; | |
14021 | 173 } |
13870 | 174 |
14021 | 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 { | |
13870 | 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; | |
14021 | 194 } |
13870 | 195 |
196 return NULL; | |
14021 | 197 } |