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
30 /* GGPSearchForm *ggp_search_form_new() {{{ */
31 GGPSearchForm
*ggp_search_form_new(GGPSearchType st
)
35 form
= g_new0(GGPSearchForm
, 1);
37 form
->search_type
= st
;
39 form
->user_data
= NULL
;
41 form
->page_number
= 0;
45 form
->lastname
= NULL
;
46 form
->firstname
= NULL
;
47 form
->nickname
= NULL
;
49 form
->birthyear
= NULL
;
57 /* void ggp_search_form_destroy(GGPSearchForm *form) {{{ */
58 void ggp_search_form_destroy(GGPSearchForm
*form
)
60 g_return_if_fail(form
!= NULL
);
63 form
->user_data
= NULL
;
65 form
->page_number
= 0;
69 g_free(form
->lastname
);
70 g_free(form
->firstname
);
71 g_free(form
->nickname
);
73 g_free(form
->birthyear
);
80 /* void ggp_search_add(GGPSearches *searches, guint32 seq, GGPSearchForm *form) {{{ */
81 void ggp_search_add(GGPSearches
*searches
, guint32 seq
, GGPSearchForm
*form
)
85 g_return_if_fail(searches
!= NULL
);
86 g_return_if_fail(form
!= NULL
);
88 tmp
= g_new0(guint32
, 1);
92 g_hash_table_insert(searches
, tmp
, form
);
96 /* void ggp_search_remove(GGPSearches *searches, guint32 seq) {{{ */
97 void ggp_search_remove(GGPSearches
*searches
, guint32 seq
)
99 g_return_if_fail(searches
!= NULL
);
101 g_hash_table_remove(searches
, &seq
);
105 /* GGPSearchForm *ggp_search_get(GGPSearches *searches, seq) {{{ */
106 GGPSearchForm
*ggp_search_get(GGPSearches
*searches
, guint32 seq
)
108 g_return_val_if_fail(searches
!= NULL
, NULL
);
110 return g_hash_table_lookup(searches
, &seq
);
114 /* GGPSearches *ggp_search_new() {{{ */
115 GGPSearches
*ggp_search_new(void)
117 GGPSearches
*searches
;
119 searches
= g_hash_table_new_full(g_int_hash
, g_int_equal
,
126 /* void ggp_search_destroy(GGPSearches *searches) {{{ */
127 void ggp_search_destroy(GGPSearches
*searches
)
129 g_return_if_fail(searches
!= NULL
);
131 g_hash_table_destroy(searches
);
135 /* guint32 ggp_search_start(PurpleConnection *gc, GGPSearchForm *form) {{{ */
136 guint32
ggp_search_start(PurpleConnection
*gc
, GGPSearchForm
*form
)
138 GGPInfo
*info
= gc
->proto_data
;
143 purple_debug_info("gg", "It's time to perform a search...\n");
145 if ((req
= gg_pubdir50_new(GG_PUBDIR50_SEARCH
)) == NULL
) {
146 purple_debug_error("gg",
147 "ggp_bmenu_show_details: Unable to create req variable.\n");
151 if (form
->uin
!= NULL
) {
152 purple_debug_info("gg", " uin: %s\n", form
->uin
);
153 gg_pubdir50_add(req
, GG_PUBDIR50_UIN
, form
->uin
);
155 if (form
->lastname
!= NULL
) {
156 purple_debug_info("gg", " lastname: %s\n", form
->lastname
);
157 gg_pubdir50_add(req
, GG_PUBDIR50_LASTNAME
, form
->lastname
);
160 if (form
->firstname
!= NULL
) {
161 purple_debug_info("gg", " firstname: %s\n", form
->firstname
);
162 gg_pubdir50_add(req
, GG_PUBDIR50_FIRSTNAME
, form
->firstname
);
165 if (form
->nickname
!= NULL
) {
166 purple_debug_info("gg", " nickname: %s\n", form
->nickname
);
167 gg_pubdir50_add(req
, GG_PUBDIR50_NICKNAME
, form
->nickname
);
170 if (form
->city
!= NULL
) {
171 purple_debug_info("gg", " city: %s\n", form
->city
);
172 gg_pubdir50_add(req
, GG_PUBDIR50_CITY
, form
->city
);
175 if (form
->birthyear
!= NULL
) {
176 purple_debug_info("gg", " birthyear: %s\n", form
->birthyear
);
177 gg_pubdir50_add(req
, GG_PUBDIR50_BIRTHYEAR
, form
->birthyear
);
180 if (form
->gender
!= NULL
) {
181 purple_debug_info("gg", " gender: %s\n", form
->gender
);
182 gg_pubdir50_add(req
, GG_PUBDIR50_GENDER
, form
->gender
);
185 if (form
->active
!= NULL
) {
186 purple_debug_info("gg", " active: %s\n", form
->active
);
187 gg_pubdir50_add(req
, GG_PUBDIR50_ACTIVE
, form
->active
);
191 offset
= form
->page_size
* form
->page_number
;
192 purple_debug_info("gg", "page number: %u, page size: %u, offset: %u\n",
193 form
->page_number
, form
->page_size
, offset
);
194 tmp
= g_strdup_printf("%u", offset
);
195 gg_pubdir50_add(req
, GG_PUBDIR50_START
, tmp
);
198 if ((seq
= gg_pubdir50(info
->session
, req
)) == 0) {
199 purple_debug_warning("gg", "ggp_bmenu_show_details: Search failed.\n");
200 gg_pubdir50_free(req
);
204 purple_debug_info("gg", "search sequence number: %d\n", seq
);
205 gg_pubdir50_free(req
);
211 /* char *ggp_search_get_result(gg_pubdir50_t res, int num, const char *field) {{{ */
212 char *ggp_search_get_result(gg_pubdir50_t res
, int num
, const char *field
)
216 tmp
= g_strdup(gg_pubdir50_get(res
, num
, field
));
218 return (tmp
== NULL
) ? g_strdup("") : tmp
;
223 /* vim: set ts=8 sts=0 sw=8 noet: */