Sun, 01 Feb 2009 08:25:57 +0000
Move some MSN message handlers from switchboard to general msg.c.
References #7676.
| 11414 | 1 | /** |
| 2 | * @file buddylist.c | |
| 3 | * | |
| 15884 | 4 | * purple |
| 11414 | 5 | * |
| 6 | * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us> | |
| 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 11414 | 21 | */ |
| 22 | ||
| 23 | ||
| 13318 | 24 | #include <libgadu.h> |
| 11414 | 25 | |
| 26 | #include "gg.h" | |
|
13627
44233a1064f9
[gaim-migrate @ 16013]
Evan Schoenberg <evands@pidgin.im>
parents:
13318
diff
changeset
|
27 | #include "gg-utils.h" |
| 11414 | 28 | #include "buddylist.h" |
| 29 | ||
|
20199
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
30 | #define F_FIRSTNAME 0 |
|
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
31 | #define F_LASTNAME 1 |
|
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
32 | /* #define F_ 2 */ |
|
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
33 | #define F_NICKNAME 3 |
|
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
34 | #define F_PHONE 4 |
|
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
35 | #define F_GROUP 5 |
|
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
36 | #define F_UIN 6 |
| 11414 | 37 | |
| 15884 | 38 | /* void ggp_buddylist_send(PurpleConnection *gc) {{{ */ |
| 39 | void ggp_buddylist_send(PurpleConnection *gc) | |
| 11414 | 40 | { |
| 41 | GGPInfo *info = gc->proto_data; | |
| 15884 | 42 | PurpleAccount *account = purple_connection_get_account(gc); |
| 11414 | 43 | |
| 15884 | 44 | PurpleBuddyList *blist; |
| 45 | PurpleBlistNode *gnode, *cnode, *bnode; | |
| 46 | PurpleBuddy *buddy; | |
| 11414 | 47 | uin_t *userlist = NULL; |
| 48 | gchar *types = NULL; | |
|
25287
fab49163239d
Fix a connection timeout that occurs with empty Gadu-Gadu buddy lists.
Martin Rosinski <martin@zone-mr.net>
parents:
24826
diff
changeset
|
49 | int size = 0, ret = 0; |
| 12007 | 50 | |
| 15884 | 51 | if ((blist = purple_get_blist()) == NULL) |
| 12007 | 52 | return; |
| 11414 | 53 | |
| 12007 | 54 | for (gnode = blist->root; gnode != NULL; gnode = gnode->next) { |
| 15884 | 55 | if (!PURPLE_BLIST_NODE_IS_GROUP(gnode)) |
| 12007 | 56 | continue; |
| 57 | ||
| 58 | for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) { | |
| 15884 | 59 | if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) |
| 11414 | 60 | continue; |
| 12007 | 61 | |
| 62 | for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { | |
| 15884 | 63 | if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) |
| 11414 | 64 | continue; |
| 12007 | 65 | |
| 15884 | 66 | buddy = (PurpleBuddy *)bnode; |
| 12007 | 67 | |
| 68 | if (buddy->account != account) | |
| 69 | continue; | |
| 11414 | 70 | |
| 12007 | 71 | size++; |
| 72 | userlist = (uin_t *) g_renew(uin_t, userlist, size); | |
| 73 | types = (gchar *) g_renew(gchar, types, size); | |
| 74 | userlist[size - 1] = ggp_str_to_uin(buddy->name); | |
| 75 | types[size - 1] = GG_USER_NORMAL; | |
| 15884 | 76 | purple_debug_info("gg", "ggp_buddylist_send: adding %d\n", |
| 12007 | 77 | userlist[size - 1]); |
| 11414 | 78 | } |
| 79 | } | |
| 80 | } | |
| 81 | ||
|
25287
fab49163239d
Fix a connection timeout that occurs with empty Gadu-Gadu buddy lists.
Martin Rosinski <martin@zone-mr.net>
parents:
24826
diff
changeset
|
82 | ret = gg_notify_ex(info->session, userlist, types, size); |
|
fab49163239d
Fix a connection timeout that occurs with empty Gadu-Gadu buddy lists.
Martin Rosinski <martin@zone-mr.net>
parents:
24826
diff
changeset
|
83 | purple_debug_info("gg", "send: ret=%d; size=%d\n", ret, size); |
|
fab49163239d
Fix a connection timeout that occurs with empty Gadu-Gadu buddy lists.
Martin Rosinski <martin@zone-mr.net>
parents:
24826
diff
changeset
|
84 | |
| 11414 | 85 | if (userlist) { |
| 86 | g_free(userlist); | |
| 87 | g_free(types); | |
| 88 | } | |
| 89 | } | |
| 90 | /* }}} */ | |
| 91 | ||
| 15884 | 92 | /* void ggp_buddylist_load(PurpleConnection *gc, char *buddylist) {{{ */ |
| 93 | void ggp_buddylist_load(PurpleConnection *gc, char *buddylist) | |
| 11414 | 94 | { |
| 15884 | 95 | PurpleBuddy *buddy; |
| 96 | PurpleGroup *group; | |
| 11414 | 97 | gchar **users_tbl; |
| 98 | int i; | |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
99 | char *utf8buddylist = charset_convert(buddylist, "CP1250", "UTF-8"); |
| 11414 | 100 | |
|
20199
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
101 | /* Don't limit the number of records in a buddylist. */ |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
102 | users_tbl = g_strsplit(utf8buddylist, "\r\n", -1); |
| 11414 | 103 | |
| 104 | for (i = 0; users_tbl[i] != NULL; i++) { | |
| 105 | gchar **data_tbl; | |
| 106 | gchar *name, *show, *g; | |
| 107 | ||
| 108 | if (strlen(users_tbl[i]) == 0) | |
| 109 | continue; | |
| 110 | ||
| 111 | data_tbl = g_strsplit(users_tbl[i], ";", 8); | |
| 15288 | 112 | if (ggp_array_size(data_tbl) < 8) { |
| 15884 | 113 | purple_debug_warning("gg", |
| 15288 | 114 | "Something is wrong on line %d of the buddylist. Skipping.\n", |
| 115 | i + 1); | |
| 116 | continue; | |
| 117 | } | |
| 11414 | 118 | |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
119 | show = data_tbl[F_NICKNAME]; |
|
20199
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
120 | name = data_tbl[F_UIN]; |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
121 | if ('\0' == *name || !atol(name)) { |
| 15884 | 122 | purple_debug_warning("gg", |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
123 | "Identifier on line %d of the buddylist is not a number. Skipping.\n", |
| 14925 | 124 | i + 1); |
| 125 | continue; | |
| 126 | } | |
| 127 | ||
| 15288 | 128 | if ('\0' == *show) { |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
129 | show = name; |
| 14925 | 130 | } |
| 11414 | 131 | |
|
20199
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
132 | purple_debug_info("gg", "got buddy: name=%s; show=%s\n", name, show); |
| 11414 | 133 | |
| 15884 | 134 | if (purple_find_buddy(purple_connection_get_account(gc), name)) { |
| 11414 | 135 | g_strfreev(data_tbl); |
| 136 | continue; | |
| 137 | } | |
| 138 | ||
| 139 | g = g_strdup("Gadu-Gadu"); | |
| 140 | ||
|
20199
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
141 | if ('\0' != data_tbl[F_GROUP]) { |
| 15288 | 142 | /* XXX: Probably buddy should be added to all the groups. */ |
| 11414 | 143 | /* Hard limit to at most 50 groups */ |
|
20199
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
144 | gchar **group_tbl = g_strsplit(data_tbl[F_GROUP], ",", 50); |
| 15288 | 145 | if (ggp_array_size(group_tbl) > 0) { |
| 11414 | 146 | g_free(g); |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
147 | g = g_strdup(group_tbl[0]); |
| 11414 | 148 | } |
| 149 | g_strfreev(group_tbl); | |
| 150 | } | |
| 151 | ||
| 15884 | 152 | buddy = purple_buddy_new(purple_connection_get_account(gc), name, |
|
20199
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
153 | strlen(show) ? show : NULL); |
| 12007 | 154 | |
| 15884 | 155 | if (!(group = purple_find_group(g))) { |
| 156 | group = purple_group_new(g); | |
| 157 | purple_blist_add_group(group, NULL); | |
| 11414 | 158 | } |
| 159 | ||
| 15884 | 160 | purple_blist_add_buddy(buddy, NULL, group, NULL); |
| 11414 | 161 | g_free(g); |
| 162 | ||
| 163 | g_strfreev(data_tbl); | |
| 164 | } | |
| 165 | g_strfreev(users_tbl); | |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
166 | g_free(utf8buddylist); |
| 11414 | 167 | |
| 168 | ggp_buddylist_send(gc); | |
| 169 | } | |
| 170 | /* }}} */ | |
| 171 | ||
| 15884 | 172 | /* void ggp_buddylist_offline(PurpleConnection *gc) {{{ */ |
| 173 | void ggp_buddylist_offline(PurpleConnection *gc) | |
| 11414 | 174 | { |
| 15884 | 175 | PurpleAccount *account = purple_connection_get_account(gc); |
| 176 | PurpleBuddyList *blist; | |
| 177 | PurpleBlistNode *gnode, *cnode, *bnode; | |
| 178 | PurpleBuddy *buddy; | |
| 11414 | 179 | |
| 15884 | 180 | if ((blist = purple_get_blist()) == NULL) |
| 12007 | 181 | return; |
| 182 | ||
| 183 | for (gnode = blist->root; gnode != NULL; gnode = gnode->next) { | |
| 15884 | 184 | if (!PURPLE_BLIST_NODE_IS_GROUP(gnode)) |
| 12007 | 185 | continue; |
| 186 | ||
| 187 | for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) { | |
| 15884 | 188 | if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) |
| 11414 | 189 | continue; |
| 12007 | 190 | |
| 191 | for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { | |
| 15884 | 192 | if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) |
| 11414 | 193 | continue; |
| 12007 | 194 | |
| 15884 | 195 | buddy = (PurpleBuddy *)bnode; |
| 11414 | 196 | |
| 12007 | 197 | if (buddy->account != account) |
| 198 | continue; | |
| 11414 | 199 | |
| 15884 | 200 | purple_prpl_got_user_status( |
|
20199
f417c49285e9
applied changes from 45b8a011cd84e0e69d7ac5a6fb84f55cdb0809cb
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
201 | account, buddy->name, "offline", NULL); |
| 11414 | 202 | |
| 15884 | 203 | purple_debug_info("gg", |
| 12007 | 204 | "ggp_buddylist_offline: gone: %s\n", |
| 205 | buddy->name); | |
| 11414 | 206 | } |
| 207 | } | |
| 208 | } | |
| 209 | } | |
| 210 | /* }}} */ | |
| 211 | ||
| 15884 | 212 | /* char *ggp_buddylist_dump(PurpleAccount *account) {{{ */ |
| 213 | char *ggp_buddylist_dump(PurpleAccount *account) | |
| 11414 | 214 | { |
| 15884 | 215 | PurpleBuddyList *blist; |
| 216 | PurpleBlistNode *gnode, *cnode, *bnode; | |
| 217 | PurpleGroup *group; | |
| 218 | PurpleBuddy *buddy; | |
|
25295
2fa5deedaefd
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
Daniel Atallah <datallah@pidgin.im>
parents:
25287
diff
changeset
|
219 | GString *buddylist; |
| 11414 | 220 | char *ptr; |
| 221 | ||
| 15884 | 222 | if ((blist = purple_get_blist()) == NULL) |
| 11414 | 223 | return NULL; |
| 224 | ||
|
25295
2fa5deedaefd
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
Daniel Atallah <datallah@pidgin.im>
parents:
25287
diff
changeset
|
225 | buddylist = g_string_sized_new(1024); |
|
2fa5deedaefd
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
Daniel Atallah <datallah@pidgin.im>
parents:
25287
diff
changeset
|
226 | |
| 11414 | 227 | for (gnode = blist->root; gnode != NULL; gnode = gnode->next) { |
| 15884 | 228 | if (!PURPLE_BLIST_NODE_IS_GROUP(gnode)) |
| 11414 | 229 | continue; |
| 230 | ||
| 15884 | 231 | group = (PurpleGroup *)gnode; |
| 11414 | 232 | |
| 233 | for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) { | |
| 15884 | 234 | if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) |
| 11414 | 235 | continue; |
| 236 | ||
| 237 | for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { | |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
238 | gchar *name, *alias, *gname; |
| 11414 | 239 | |
| 15884 | 240 | if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) |
| 11414 | 241 | continue; |
| 242 | ||
| 15884 | 243 | buddy = (PurpleBuddy *)bnode; |
| 11414 | 244 | if (buddy->account != account) |
| 245 | continue; | |
| 246 | ||
| 247 | name = buddy->name; | |
| 12007 | 248 | alias = buddy->alias ? buddy->alias : buddy->name; |
| 11414 | 249 | gname = group->name; |
| 250 | ||
|
25295
2fa5deedaefd
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
Daniel Atallah <datallah@pidgin.im>
parents:
25287
diff
changeset
|
251 | g_string_append_printf(buddylist, |
|
2fa5deedaefd
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
Daniel Atallah <datallah@pidgin.im>
parents:
25287
diff
changeset
|
252 | "%s;%s;%s;%s;%s;%s;%s;%s%s\r\n", |
|
2fa5deedaefd
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
Daniel Atallah <datallah@pidgin.im>
parents:
25287
diff
changeset
|
253 | alias, alias, alias, alias, |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
254 | "", gname, name, "", ""); |
| 11414 | 255 | } |
| 256 | } | |
| 257 | } | |
| 258 | ||
|
25295
2fa5deedaefd
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
Daniel Atallah <datallah@pidgin.im>
parents:
25287
diff
changeset
|
259 | ptr = charset_convert(buddylist->str, "UTF-8", "CP1250"); |
|
2fa5deedaefd
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
Daniel Atallah <datallah@pidgin.im>
parents:
25287
diff
changeset
|
260 | g_string_free(buddylist, TRUE); |
|
24826
1ce0a7a3ab84
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
Adam Strzelecki <ono@java.pl>
parents:
20199
diff
changeset
|
261 | return ptr; |
| 11414 | 262 | } |
| 263 | /* }}} */ | |
| 264 | ||
| 265 | ||
| 12007 | 266 | /* vim: set ts=8 sts=0 sw=8 noet: */ |