Wed, 27 Jun 2012 02:35:26 +0200
Gadu-Gadu: utils refactoring, (partially) fix new account registration
| 11414 | 1 | /** |
| 2 | * @file search.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 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32261
diff
changeset
|
26 | #include "gg.h" |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32261
diff
changeset
|
27 | #include "utils.h" |
| 11414 | 28 | #include "search.h" |
| 29 | ||
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32261
diff
changeset
|
30 | #include <debug.h> |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32261
diff
changeset
|
31 | |
| 13641 | 32 | |
| 11414 | 33 | /* GGPSearchForm *ggp_search_form_new() {{{ */ |
| 13641 | 34 | GGPSearchForm *ggp_search_form_new(GGPSearchType st) |
| 11414 | 35 | { |
| 36 | GGPSearchForm *form; | |
| 37 | ||
| 38 | form = g_new0(GGPSearchForm, 1); | |
| 13641 | 39 | |
| 40 | form->search_type = st; | |
| 41 | form->window = NULL; | |
| 42 | form->user_data = NULL; | |
| 43 | form->seq = 0; | |
|
31879
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
44 | form->page_number = 0; |
|
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
45 | form->page_size = 0; |
| 13641 | 46 | |
| 11414 | 47 | form->uin = NULL; |
| 48 | form->lastname = NULL; | |
| 49 | form->firstname = NULL; | |
| 50 | form->nickname = NULL; | |
| 51 | form->city = NULL; | |
| 52 | form->birthyear = NULL; | |
| 53 | form->gender = NULL; | |
| 54 | form->active = NULL; | |
| 55 | ||
| 56 | return form; | |
| 57 | } | |
| 58 | /* }}} */ | |
| 59 | ||
| 13641 | 60 | /* void ggp_search_form_destroy(GGPSearchForm *form) {{{ */ |
| 61 | void ggp_search_form_destroy(GGPSearchForm *form) | |
| 62 | { | |
| 63 | g_return_if_fail(form != NULL); | |
| 64 | ||
| 65 | form->window = NULL; | |
| 66 | form->user_data = NULL; | |
| 67 | form->seq = 0; | |
|
31879
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
68 | form->page_number = 0; |
|
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
69 | form->page_size = 0; |
| 13641 | 70 | |
| 71 | g_free(form->uin); | |
| 72 | g_free(form->lastname); | |
| 73 | g_free(form->firstname); | |
| 74 | g_free(form->nickname); | |
| 75 | g_free(form->city); | |
| 76 | g_free(form->birthyear); | |
| 77 | g_free(form->gender); | |
| 78 | g_free(form->active); | |
| 79 | g_free(form); | |
| 80 | } | |
| 81 | /* }}} */ | |
| 82 | ||
| 83 | /* void ggp_search_add(GGPSearches *searches, guint32 seq, GGPSearchForm *form) {{{ */ | |
| 84 | void ggp_search_add(GGPSearches *searches, guint32 seq, GGPSearchForm *form) | |
| 85 | { | |
| 86 | guint32 *tmp; | |
| 87 | ||
| 88 | g_return_if_fail(searches != NULL); | |
| 89 | g_return_if_fail(form != NULL); | |
| 90 | ||
| 91 | tmp = g_new0(guint32, 1); | |
| 92 | *tmp = seq; | |
| 93 | form->seq = seq; | |
| 94 | ||
| 95 | g_hash_table_insert(searches, tmp, form); | |
| 96 | } | |
| 97 | /* }}} */ | |
| 98 | ||
| 99 | /* void ggp_search_remove(GGPSearches *searches, guint32 seq) {{{ */ | |
| 100 | void ggp_search_remove(GGPSearches *searches, guint32 seq) | |
| 101 | { | |
| 102 | g_return_if_fail(searches != NULL); | |
| 103 | ||
| 104 | g_hash_table_remove(searches, &seq); | |
| 105 | } | |
| 106 | /* }}} */ | |
| 107 | ||
| 108 | /* GGPSearchForm *ggp_search_get(GGPSearches *searches, seq) {{{ */ | |
| 109 | GGPSearchForm *ggp_search_get(GGPSearches *searches, guint32 seq) | |
| 110 | { | |
| 111 | g_return_val_if_fail(searches != NULL, NULL); | |
| 112 | ||
| 113 | return g_hash_table_lookup(searches, &seq); | |
| 114 | } | |
| 115 | /* }}} */ | |
| 116 | ||
| 117 | /* GGPSearches *ggp_search_new() {{{ */ | |
| 118 | GGPSearches *ggp_search_new(void) | |
| 119 | { | |
| 120 | GGPSearches *searches; | |
| 121 | ||
| 122 | searches = g_hash_table_new_full(g_int_hash, g_int_equal, | |
| 123 | g_free, NULL); | |
| 124 | ||
| 125 | return searches; | |
| 126 | } | |
| 127 | /* }}} */ | |
| 128 | ||
| 129 | /* void ggp_search_destroy(GGPSearches *searches) {{{ */ | |
| 130 | void ggp_search_destroy(GGPSearches *searches) | |
| 131 | { | |
| 132 | g_return_if_fail(searches != NULL); | |
| 133 | ||
| 134 | g_hash_table_destroy(searches); | |
| 135 | } | |
| 136 | /* }}} */ | |
| 137 | ||
| 15884 | 138 | /* guint32 ggp_search_start(PurpleConnection *gc, GGPSearchForm *form) {{{ */ |
| 139 | guint32 ggp_search_start(PurpleConnection *gc, GGPSearchForm *form) | |
| 11414 | 140 | { |
|
32261
bd956558346e
Convert gg prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
31879
diff
changeset
|
141 | GGPInfo *info = purple_connection_get_protocol_data(gc); |
| 11414 | 142 | gg_pubdir50_t req; |
|
31879
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
143 | guint seq, offset; |
| 11414 | 144 | |
| 15884 | 145 | purple_debug_info("gg", "It's time to perform a search...\n"); |
| 11414 | 146 | |
| 147 | if ((req = gg_pubdir50_new(GG_PUBDIR50_SEARCH)) == NULL) { | |
| 15884 | 148 | purple_debug_error("gg", |
| 12007 | 149 | "ggp_bmenu_show_details: Unable to create req variable.\n"); |
| 13641 | 150 | return 0; |
| 11414 | 151 | } |
| 152 | ||
| 153 | if (form->uin != NULL) { | |
| 15884 | 154 | purple_debug_info("gg", " uin: %s\n", form->uin); |
| 11414 | 155 | gg_pubdir50_add(req, GG_PUBDIR50_UIN, form->uin); |
| 156 | } else { | |
| 157 | if (form->lastname != NULL) { | |
| 15884 | 158 | purple_debug_info("gg", " lastname: %s\n", form->lastname); |
| 11414 | 159 | gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, form->lastname); |
| 160 | } | |
| 161 | ||
| 162 | if (form->firstname != NULL) { | |
| 15884 | 163 | purple_debug_info("gg", " firstname: %s\n", form->firstname); |
| 11414 | 164 | gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, form->firstname); |
| 165 | } | |
| 166 | ||
| 167 | if (form->nickname != NULL) { | |
| 15884 | 168 | purple_debug_info("gg", " nickname: %s\n", form->nickname); |
| 11414 | 169 | gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, form->nickname); |
| 170 | } | |
| 171 | ||
| 172 | if (form->city != NULL) { | |
| 15884 | 173 | purple_debug_info("gg", " city: %s\n", form->city); |
| 11414 | 174 | gg_pubdir50_add(req, GG_PUBDIR50_CITY, form->city); |
| 175 | } | |
| 176 | ||
| 177 | if (form->birthyear != NULL) { | |
| 15884 | 178 | purple_debug_info("gg", " birthyear: %s\n", form->birthyear); |
| 11414 | 179 | gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, form->birthyear); |
| 180 | } | |
| 181 | ||
| 182 | if (form->gender != NULL) { | |
| 15884 | 183 | purple_debug_info("gg", " gender: %s\n", form->gender); |
| 11414 | 184 | gg_pubdir50_add(req, GG_PUBDIR50_GENDER, form->gender); |
| 185 | } | |
| 186 | ||
| 187 | if (form->active != NULL) { | |
| 15884 | 188 | purple_debug_info("gg", " active: %s\n", form->active); |
| 11414 | 189 | gg_pubdir50_add(req, GG_PUBDIR50_ACTIVE, form->active); |
| 190 | } | |
| 191 | } | |
| 192 | ||
|
31879
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
193 | offset = form->page_size * form->page_number; |
|
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
194 | purple_debug_info("gg", "page number: %u, page size: %u, offset: %u\n", |
|
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
195 | form->page_number, form->page_size, offset); |
|
6c34fd3b36f4
Fixed searching for buddies in Gadu-Gadu public directory. Fixes #5242
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
30164
diff
changeset
|
196 | gg_pubdir50_add(req, GG_PUBDIR50_START, g_strdup_printf("%u", offset)); |
| 11414 | 197 | |
| 13641 | 198 | if ((seq = gg_pubdir50(info->session, req)) == 0) { |
| 15884 | 199 | purple_debug_warning("gg", "ggp_bmenu_show_details: Search failed.\n"); |
| 13641 | 200 | return 0; |
| 11414 | 201 | } |
| 202 | ||
| 15884 | 203 | purple_debug_info("gg", "search sequence number: %d\n", seq); |
| 11414 | 204 | gg_pubdir50_free(req); |
| 13641 | 205 | |
| 206 | return seq; | |
| 11414 | 207 | } |
| 208 | /* }}} */ | |
| 209 | ||
| 210 | /* char *ggp_search_get_result(gg_pubdir50_t res, int num, const char *field) {{{ */ | |
| 211 | char *ggp_search_get_result(gg_pubdir50_t res, int num, const char *field) | |
| 212 | { | |
| 213 | char *tmp; | |
| 214 | ||
|
30164
8d3219753e5e
gg: For protocol 8.0+, the server sends this in UTF-8 now. Closes #11775.
Krzysztof Klinikowski <kkszysiu@gmail.com>
parents:
19859
diff
changeset
|
215 | tmp = g_strdup(gg_pubdir50_get(res, num, field)); |
| 11414 | 216 | |
| 217 | return (tmp == NULL) ? g_strdup("") : tmp; | |
| 218 | } | |
| 219 | /* }}} */ | |
| 220 | ||
| 221 | ||
| 12007 | 222 | /* vim: set ts=8 sts=0 sw=8 noet: */ |