6 * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
28 #include "buddylist.h"
38 /* void ggp_buddylist_send(PurpleConnection *gc) {{{ */
39 void ggp_buddylist_send(PurpleConnection
*gc
)
41 GGPInfo
*info
= gc
->proto_data
;
42 PurpleAccount
*account
= purple_connection_get_account(gc
);
49 buddies
= purple_find_buddies(account
, NULL
);
51 size
= g_slist_length(buddies
);
52 userlist
= g_new(uin_t
, size
);
53 types
= g_new(gchar
, size
);
55 for (buddies
= purple_find_buddies(account
, NULL
); buddies
;
56 buddies
= g_slist_delete_link(buddies
, buddies
), ++i
)
58 PurpleBuddy
*buddy
= buddies
->data
;
59 const gchar
*name
= purple_buddy_get_name(buddy
);
61 userlist
[i
] = ggp_str_to_uin(name
);
62 types
[i
] = GG_USER_NORMAL
;
63 purple_debug_info("gg", "ggp_buddylist_send: adding %d\n",
67 ret
= gg_notify_ex(info
->session
, userlist
, types
, size
);
68 purple_debug_info("gg", "send: ret=%d; size=%d\n", ret
, size
);
77 /* void ggp_buddylist_load(PurpleConnection *gc, char *buddylist) {{{ */
78 void ggp_buddylist_load(PurpleConnection
*gc
, char *buddylist
)
84 char *utf8buddylist
= charset_convert(buddylist
, "CP1250", "UTF-8");
86 /* Don't limit the number of records in a buddylist. */
87 users_tbl
= g_strsplit(utf8buddylist
, "\r\n", -1);
89 for (i
= 0; users_tbl
[i
] != NULL
; i
++) {
91 gchar
*name
, *show
, *g
;
93 if (strlen(users_tbl
[i
]) == 0)
96 data_tbl
= g_strsplit(users_tbl
[i
], ";", 8);
97 if (ggp_array_size(data_tbl
) < 8) {
98 purple_debug_warning("gg",
99 "Something is wrong on line %d of the buddylist. Skipping.\n",
104 show
= data_tbl
[F_NICKNAME
];
105 name
= data_tbl
[F_UIN
];
106 if ('\0' == *name
|| !atol(name
)) {
107 purple_debug_warning("gg",
108 "Identifier on line %d of the buddylist is not a number. Skipping.\n",
117 purple_debug_info("gg", "got buddy: name=%s; show=%s\n", name
, show
);
119 if (purple_find_buddy(purple_connection_get_account(gc
), name
)) {
120 g_strfreev(data_tbl
);
124 g
= g_strdup("Gadu-Gadu");
126 if ('\0' != data_tbl
[F_GROUP
]) {
127 /* XXX: Probably buddy should be added to all the groups. */
128 /* Hard limit to at most 50 groups */
129 gchar
**group_tbl
= g_strsplit(data_tbl
[F_GROUP
], ",", 50);
130 if (ggp_array_size(group_tbl
) > 0) {
132 g
= g_strdup(group_tbl
[0]);
134 g_strfreev(group_tbl
);
137 buddy
= purple_buddy_new(purple_connection_get_account(gc
), name
,
138 strlen(show
) ? show
: NULL
);
140 if (!(group
= purple_find_group(g
))) {
141 group
= purple_group_new(g
);
142 purple_blist_add_group(group
, NULL
);
145 purple_blist_add_buddy(buddy
, NULL
, group
, NULL
);
148 g_strfreev(data_tbl
);
150 g_strfreev(users_tbl
);
151 g_free(utf8buddylist
);
153 ggp_buddylist_send(gc
);
157 /* char *ggp_buddylist_dump(PurpleAccount *account) {{{ */
158 char *ggp_buddylist_dump(PurpleAccount
*account
)
161 GString
*buddylist
= g_string_sized_new(1024);
164 for (buddies
= purple_find_buddies(account
, NULL
); buddies
;
165 buddies
= g_slist_delete_link(buddies
, buddies
)) {
166 PurpleBuddy
*buddy
= buddies
->data
;
167 PurpleGroup
*group
= purple_buddy_get_group(buddy
);
168 const char *bname
= purple_buddy_get_name(buddy
);
169 const char *gname
= purple_group_get_name(group
);
170 const char *alias
= purple_buddy_get_alias(buddy
);
175 g_string_append_printf(buddylist
,
176 "%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
177 alias
, alias
, alias
, alias
,
178 "", gname
, bname
, "", "");
181 ptr
= charset_convert(buddylist
->str
, "UTF-8", "CP1250");
182 g_string_free(buddylist
, TRUE
);
188 /* vim: set ts=8 sts=0 sw=8 noet: */