Remove useless comparison
[pidgin-git.git] / libpurple / protocols / gg / search.c
blobebafe74e463aeba4b75246941b0364e00b9bfc1c
1 /**
2 * @file search.c
4 * purple
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
24 #include <libgadu.h>
26 #include "gg-utils.h"
27 #include "search.h"
30 /* GGPSearchForm *ggp_search_form_new() {{{ */
31 GGPSearchForm *ggp_search_form_new(GGPSearchType st)
33 GGPSearchForm *form;
35 form = g_new0(GGPSearchForm, 1);
37 form->search_type = st;
38 form->window = NULL;
39 form->user_data = NULL;
40 form->seq = 0;
41 form->page_number = 0;
42 form->page_size = 0;
44 form->uin = NULL;
45 form->lastname = NULL;
46 form->firstname = NULL;
47 form->nickname = NULL;
48 form->city = NULL;
49 form->birthyear = NULL;
50 form->gender = NULL;
51 form->active = NULL;
53 return form;
55 /* }}} */
57 /* void ggp_search_form_destroy(GGPSearchForm *form) {{{ */
58 void ggp_search_form_destroy(GGPSearchForm *form)
60 g_return_if_fail(form != NULL);
62 form->window = NULL;
63 form->user_data = NULL;
64 form->seq = 0;
65 form->page_number = 0;
66 form->page_size = 0;
68 g_free(form->uin);
69 g_free(form->lastname);
70 g_free(form->firstname);
71 g_free(form->nickname);
72 g_free(form->city);
73 g_free(form->birthyear);
74 g_free(form->gender);
75 g_free(form->active);
76 g_free(form);
78 /* }}} */
80 /* void ggp_search_add(GGPSearches *searches, guint32 seq, GGPSearchForm *form) {{{ */
81 void ggp_search_add(GGPSearches *searches, guint32 seq, GGPSearchForm *form)
83 guint32 *tmp;
85 g_return_if_fail(searches != NULL);
86 g_return_if_fail(form != NULL);
88 tmp = g_new0(guint32, 1);
89 *tmp = seq;
90 form->seq = seq;
92 g_hash_table_insert(searches, tmp, form);
94 /* }}} */
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);
103 /* }}} */
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);
112 /* }}} */
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,
120 g_free, NULL);
122 return searches;
124 /* }}} */
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);
133 /* }}} */
135 /* guint32 ggp_search_start(PurpleConnection *gc, GGPSearchForm *form) {{{ */
136 guint32 ggp_search_start(PurpleConnection *gc, GGPSearchForm *form)
138 GGPInfo *info = gc->proto_data;
139 gg_pubdir50_t req;
140 guint seq, offset;
141 gchar *tmp;
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");
148 return 0;
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);
154 } else {
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);
196 g_free(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);
201 return 0;
204 purple_debug_info("gg", "search sequence number: %d\n", seq);
205 gg_pubdir50_free(req);
207 return seq;
209 /* }}} */
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)
214 char *tmp;
216 tmp = g_strdup(gg_pubdir50_get(res, num, field));
218 return (tmp == NULL) ? g_strdup("") : tmp;
220 /* }}} */
223 /* vim: set ts=8 sts=0 sw=8 noet: */