comparison libpurple/protocols/gg/lib/pubdir50.c @ 32094:380f530c3f86

merged from im.pidgin.pidgin
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 07 Jun 2011 13:42:47 +0900
parents 8b9e9c61d061 3a90a59ddea2
children 4a34689eeb33
comparison
equal deleted inserted replaced
31933:6b3bc0947068 32094:380f530c3f86
30 #include <string.h> 30 #include <string.h>
31 #include <time.h> 31 #include <time.h>
32 #include <glib.h> 32 #include <glib.h>
33 33
34 #include "libgadu.h" 34 #include "libgadu.h"
35 #include "libgadu-config.h"
35 #include "libgadu-internal.h" 36 #include "libgadu-internal.h"
36 #include "encoding.h" 37 #include "encoding.h"
37 38
38 /** 39 /**
39 * Tworzy nowe zapytanie katalogu publicznego. 40 * Tworzy nowe zapytanie katalogu publicznego.
93 free(req->entries[i].value); 94 free(req->entries[i].value);
94 req->entries[i].value = dupvalue; 95 req->entries[i].value = dupvalue;
95 96
96 return 0; 97 return 0;
97 } 98 }
98 99
99 if (!(dupfield = strdup(field))) { 100 if (!(dupfield = strdup(field))) {
100 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_add_n() out of memory\n"); 101 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_add_n() out of memory\n");
101 free(dupvalue); 102 free(dupvalue);
102 return -1; 103 return -1;
103 } 104 }
148 * \ingroup pubdir50 149 * \ingroup pubdir50
149 */ 150 */
150 int gg_pubdir50_seq_set(gg_pubdir50_t req, uint32_t seq) 151 int gg_pubdir50_seq_set(gg_pubdir50_t req, uint32_t seq)
151 { 152 {
152 gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_seq_set(%p, %d);\n", req, seq); 153 gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_seq_set(%p, %d);\n", req, seq);
153 154
154 if (!req) { 155 if (!req) {
155 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_seq_set() invalid arguments\n"); 156 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_seq_set() invalid arguments\n");
156 errno = EFAULT; 157 errno = EFAULT;
157 return -1; 158 return -1;
158 } 159 }
173 { 174 {
174 int i; 175 int i;
175 176
176 if (!s) 177 if (!s)
177 return; 178 return;
178 179
179 for (i = 0; i < s->entries_count; i++) { 180 for (i = 0; i < s->entries_count; i++) {
180 free(s->entries[i].field); 181 free(s->entries[i].field);
181 free(s->entries[i].value); 182 free(s->entries[i].value);
182 } 183 }
183 184
201 uint32_t res; 202 uint32_t res;
202 char *buf, *p; 203 char *buf, *p;
203 struct gg_pubdir50_request *r; 204 struct gg_pubdir50_request *r;
204 205
205 gg_debug_session(sess, GG_DEBUG_FUNCTION, "** gg_pubdir50(%p, %p);\n", sess, req); 206 gg_debug_session(sess, GG_DEBUG_FUNCTION, "** gg_pubdir50(%p, %p);\n", sess, req);
206 207
207 if (!sess || !req) { 208 if (!sess || !req) {
208 gg_debug_session(sess, GG_DEBUG_MISC, "// gg_pubdir50() invalid arguments\n"); 209 gg_debug_session(sess, GG_DEBUG_MISC, "// gg_pubdir50() invalid arguments\n");
209 errno = EFAULT; 210 errno = EFAULT;
210 return 0; 211 return 0;
211 } 212 }
218 219
219 for (i = 0; i < req->entries_count; i++) { 220 for (i = 0; i < req->entries_count; i++) {
220 /* wyszukiwanie bierze tylko pierwszy wpis */ 221 /* wyszukiwanie bierze tylko pierwszy wpis */
221 if (req->entries[i].num) 222 if (req->entries[i].num)
222 continue; 223 continue;
223 224
224 if (sess->encoding == GG_ENCODING_CP1250) { 225 if (sess->encoding == GG_ENCODING_CP1250) {
225 size += strlen(req->entries[i].field) + 1; 226 size += strlen(req->entries[i].field) + 1;
226 size += strlen(req->entries[i].value) + 1; 227 size += strlen(req->entries[i].value) + 1;
227 } else { 228 } else {
228 char *tmp; 229 char *tmp;
326 { 327 {
327 const char *end = packet + length, *p; 328 const char *end = packet + length, *p;
328 struct gg_pubdir50_reply *r = (struct gg_pubdir50_reply*) packet; 329 struct gg_pubdir50_reply *r = (struct gg_pubdir50_reply*) packet;
329 gg_pubdir50_t res; 330 gg_pubdir50_t res;
330 int num = 0; 331 int num = 0;
331 332
332 gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_handle_reply_sess(%p, %p, %p, %d);\n", sess, e, packet, length); 333 gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_handle_reply_sess(%p, %p, %p, %d);\n", sess, e, packet, length);
333 334
334 if (!sess || !e || !packet) { 335 if (!sess || !e || !packet) {
335 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_handle_reply() invalid arguments\n"); 336 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_handle_reply() invalid arguments\n");
336 errno = EFAULT; 337 errno = EFAULT;
383 num++; 384 num++;
384 field++; 385 field++;
385 } 386 }
386 387
387 value = NULL; 388 value = NULL;
388 389
389 for (p = field; p < end; p++) { 390 for (p = field; p < end; p++) {
390 /* jeśli mamy koniec tekstu... */ 391 /* jeśli mamy koniec tekstu... */
391 if (!*p) { 392 if (!*p) {
392 /* ...i jeszcze nie mieliśmy wartości pola to 393 /* ...i jeszcze nie mieliśmy wartości pola to
393 * wiemy, że po tym zerze jest wartość... */ 394 * wiemy, że po tym zerze jest wartość... */
398 * wartości i możemy wychodzić 399 * wartości i możemy wychodzić
399 * grzecznie z pętli */ 400 * grzecznie z pętli */
400 break; 401 break;
401 } 402 }
402 } 403 }
403 404
404 /* sprawdźmy, czy pole nie wychodzi poza pakiet, żeby nie 405 /* sprawdźmy, czy pole nie wychodzi poza pakiet, żeby nie
405 * mieć segfaultów, jeśli serwer przestanie zakańczać pakietów 406 * mieć segfaultów, jeśli serwer przestanie zakańczać pakietów
406 * przez \0 */ 407 * przez \0 */
407 408
408 if (p == end) { 409 if (p == end) {
435 } 436 }
436 437
437 free(tmp); 438 free(tmp);
438 } 439 }
439 } 440 }
440 } 441 }
441 442
442 res->count = num + 1; 443 res->count = num + 1;
443 444
444 return 0; 445 return 0;
445 446
446 failure: 447 failure:
447 gg_pubdir50_free(res); 448 gg_pubdir50_free(res);
448 return -1; 449 return -1;