| 1 /** |
|
| 2 * @file search.c |
|
| 3 * |
|
| 4 * gaim |
|
| 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 |
|
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 21 */ |
|
| 22 |
|
| 23 |
|
| 24 #include <libgadu.h> |
|
| 25 |
|
| 26 #include "gg-utils.h" |
|
| 27 #include "search.h" |
|
| 28 |
|
| 29 |
|
| 30 /* GGPSearchForm *ggp_search_form_new() {{{ */ |
|
| 31 GGPSearchForm *ggp_search_form_new(GGPSearchType st) |
|
| 32 { |
|
| 33 GGPSearchForm *form; |
|
| 34 |
|
| 35 form = g_new0(GGPSearchForm, 1); |
|
| 36 |
|
| 37 form->search_type = st; |
|
| 38 form->window = NULL; |
|
| 39 form->user_data = NULL; |
|
| 40 form->seq = 0; |
|
| 41 |
|
| 42 form->uin = NULL; |
|
| 43 form->lastname = NULL; |
|
| 44 form->firstname = NULL; |
|
| 45 form->nickname = NULL; |
|
| 46 form->city = NULL; |
|
| 47 form->birthyear = NULL; |
|
| 48 form->gender = NULL; |
|
| 49 form->active = NULL; |
|
| 50 form->offset = NULL; |
|
| 51 form->last_uin = NULL; |
|
| 52 |
|
| 53 return form; |
|
| 54 } |
|
| 55 /* }}} */ |
|
| 56 |
|
| 57 /* void ggp_search_form_destroy(GGPSearchForm *form) {{{ */ |
|
| 58 void ggp_search_form_destroy(GGPSearchForm *form) |
|
| 59 { |
|
| 60 g_return_if_fail(form != NULL); |
|
| 61 |
|
| 62 form->window = NULL; |
|
| 63 form->user_data = NULL; |
|
| 64 form->seq = 0; |
|
| 65 |
|
| 66 g_free(form->uin); |
|
| 67 g_free(form->lastname); |
|
| 68 g_free(form->firstname); |
|
| 69 g_free(form->nickname); |
|
| 70 g_free(form->city); |
|
| 71 g_free(form->birthyear); |
|
| 72 g_free(form->gender); |
|
| 73 g_free(form->active); |
|
| 74 g_free(form->offset); |
|
| 75 g_free(form->last_uin); |
|
| 76 g_free(form); |
|
| 77 } |
|
| 78 /* }}} */ |
|
| 79 |
|
| 80 /* void ggp_search_add(GGPSearches *searches, guint32 seq, GGPSearchForm *form) {{{ */ |
|
| 81 void ggp_search_add(GGPSearches *searches, guint32 seq, GGPSearchForm *form) |
|
| 82 { |
|
| 83 guint32 *tmp; |
|
| 84 |
|
| 85 g_return_if_fail(searches != NULL); |
|
| 86 g_return_if_fail(form != NULL); |
|
| 87 |
|
| 88 tmp = g_new0(guint32, 1); |
|
| 89 *tmp = seq; |
|
| 90 form->seq = seq; |
|
| 91 |
|
| 92 g_hash_table_insert(searches, tmp, form); |
|
| 93 } |
|
| 94 /* }}} */ |
|
| 95 |
|
| 96 /* void ggp_search_remove(GGPSearches *searches, guint32 seq) {{{ */ |
|
| 97 void ggp_search_remove(GGPSearches *searches, guint32 seq) |
|
| 98 { |
|
| 99 g_return_if_fail(searches != NULL); |
|
| 100 |
|
| 101 g_hash_table_remove(searches, &seq); |
|
| 102 } |
|
| 103 /* }}} */ |
|
| 104 |
|
| 105 /* GGPSearchForm *ggp_search_get(GGPSearches *searches, seq) {{{ */ |
|
| 106 GGPSearchForm *ggp_search_get(GGPSearches *searches, guint32 seq) |
|
| 107 { |
|
| 108 g_return_val_if_fail(searches != NULL, NULL); |
|
| 109 |
|
| 110 return g_hash_table_lookup(searches, &seq); |
|
| 111 } |
|
| 112 /* }}} */ |
|
| 113 |
|
| 114 /* GGPSearches *ggp_search_new() {{{ */ |
|
| 115 GGPSearches *ggp_search_new(void) |
|
| 116 { |
|
| 117 GGPSearches *searches; |
|
| 118 |
|
| 119 searches = g_hash_table_new_full(g_int_hash, g_int_equal, |
|
| 120 g_free, NULL); |
|
| 121 |
|
| 122 return searches; |
|
| 123 } |
|
| 124 /* }}} */ |
|
| 125 |
|
| 126 /* void ggp_search_destroy(GGPSearches *searches) {{{ */ |
|
| 127 void ggp_search_destroy(GGPSearches *searches) |
|
| 128 { |
|
| 129 g_return_if_fail(searches != NULL); |
|
| 130 |
|
| 131 g_hash_table_destroy(searches); |
|
| 132 } |
|
| 133 /* }}} */ |
|
| 134 |
|
| 135 /* guint32 ggp_search_start(GaimConnection *gc, GGPSearchForm *form) {{{ */ |
|
| 136 guint32 ggp_search_start(GaimConnection *gc, GGPSearchForm *form) |
|
| 137 { |
|
| 138 GGPInfo *info = gc->proto_data; |
|
| 139 gg_pubdir50_t req; |
|
| 140 guint seq; |
|
| 141 |
|
| 142 gaim_debug_info("gg", "It's time to perform a search...\n"); |
|
| 143 |
|
| 144 if ((req = gg_pubdir50_new(GG_PUBDIR50_SEARCH)) == NULL) { |
|
| 145 gaim_debug_error("gg", |
|
| 146 "ggp_bmenu_show_details: Unable to create req variable.\n"); |
|
| 147 return 0; |
|
| 148 } |
|
| 149 |
|
| 150 if (form->uin != NULL) { |
|
| 151 gaim_debug_info("gg", " uin: %s\n", form->uin); |
|
| 152 gg_pubdir50_add(req, GG_PUBDIR50_UIN, form->uin); |
|
| 153 } else { |
|
| 154 if (form->lastname != NULL) { |
|
| 155 gaim_debug_info("gg", " lastname: %s\n", form->lastname); |
|
| 156 gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, form->lastname); |
|
| 157 } |
|
| 158 |
|
| 159 if (form->firstname != NULL) { |
|
| 160 gaim_debug_info("gg", " firstname: %s\n", form->firstname); |
|
| 161 gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, form->firstname); |
|
| 162 } |
|
| 163 |
|
| 164 if (form->nickname != NULL) { |
|
| 165 gaim_debug_info("gg", " nickname: %s\n", form->nickname); |
|
| 166 gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, form->nickname); |
|
| 167 } |
|
| 168 |
|
| 169 if (form->city != NULL) { |
|
| 170 gaim_debug_info("gg", " city: %s\n", form->city); |
|
| 171 gg_pubdir50_add(req, GG_PUBDIR50_CITY, form->city); |
|
| 172 } |
|
| 173 |
|
| 174 if (form->birthyear != NULL) { |
|
| 175 gaim_debug_info("gg", " birthyear: %s\n", form->birthyear); |
|
| 176 gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, form->birthyear); |
|
| 177 } |
|
| 178 |
|
| 179 if (form->gender != NULL) { |
|
| 180 gaim_debug_info("gg", " gender: %s\n", form->gender); |
|
| 181 gg_pubdir50_add(req, GG_PUBDIR50_GENDER, form->gender); |
|
| 182 } |
|
| 183 |
|
| 184 if (form->active != NULL) { |
|
| 185 gaim_debug_info("gg", " active: %s\n", form->active); |
|
| 186 gg_pubdir50_add(req, GG_PUBDIR50_ACTIVE, form->active); |
|
| 187 } |
|
| 188 } |
|
| 189 |
|
| 190 gaim_debug_info("gg", "offset: %s\n", form->offset); |
|
| 191 gg_pubdir50_add(req, GG_PUBDIR50_START, g_strdup(form->offset)); |
|
| 192 |
|
| 193 if ((seq = gg_pubdir50(info->session, req)) == 0) { |
|
| 194 gaim_debug_warning("gg", "ggp_bmenu_show_details: Search failed.\n"); |
|
| 195 return 0; |
|
| 196 } |
|
| 197 |
|
| 198 gaim_debug_info("gg", "search sequence number: %d\n", seq); |
|
| 199 gg_pubdir50_free(req); |
|
| 200 |
|
| 201 return seq; |
|
| 202 } |
|
| 203 /* }}} */ |
|
| 204 |
|
| 205 /* char *ggp_search_get_result(gg_pubdir50_t res, int num, const char *field) {{{ */ |
|
| 206 char *ggp_search_get_result(gg_pubdir50_t res, int num, const char *field) |
|
| 207 { |
|
| 208 char *tmp; |
|
| 209 |
|
| 210 tmp = charset_convert(gg_pubdir50_get(res, num, field), "CP1250", "UTF-8"); |
|
| 211 |
|
| 212 return (tmp == NULL) ? g_strdup("") : tmp; |
|
| 213 } |
|
| 214 /* }}} */ |
|
| 215 |
|
| 216 |
|
| 217 /* vim: set ts=8 sts=0 sw=8 noet: */ |
|