libpurple/protocols/gg/lib/pubdir50.c

changeset 31826
0f6ab56fbf9d
parent 31609
d67fbc90b28a
child 32438
dc8991868906
child 35617
c9069e0e3c36
equal deleted inserted replaced
31825:92996c775af3 31826:0f6ab56fbf9d
29 #include <stdlib.h> 29 #include <stdlib.h>
30 #include <string.h> 30 #include <string.h>
31 #include <time.h> 31 #include <time.h>
32 32
33 #include "libgadu.h" 33 #include "libgadu.h"
34 #include "libgadu-config.h"
34 #include "libgadu-internal.h" 35 #include "libgadu-internal.h"
35 #include "encoding.h" 36 #include "encoding.h"
36 37
37 /** 38 /**
38 * Tworzy nowe zapytanie katalogu publicznego. 39 * Tworzy nowe zapytanie katalogu publicznego.
92 free(req->entries[i].value); 93 free(req->entries[i].value);
93 req->entries[i].value = dupvalue; 94 req->entries[i].value = dupvalue;
94 95
95 return 0; 96 return 0;
96 } 97 }
97 98
98 if (!(dupfield = strdup(field))) { 99 if (!(dupfield = strdup(field))) {
99 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_add_n() out of memory\n"); 100 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_add_n() out of memory\n");
100 free(dupvalue); 101 free(dupvalue);
101 return -1; 102 return -1;
102 } 103 }
147 * \ingroup pubdir50 148 * \ingroup pubdir50
148 */ 149 */
149 int gg_pubdir50_seq_set(gg_pubdir50_t req, uint32_t seq) 150 int gg_pubdir50_seq_set(gg_pubdir50_t req, uint32_t seq)
150 { 151 {
151 gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_seq_set(%p, %d);\n", req, seq); 152 gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_seq_set(%p, %d);\n", req, seq);
152 153
153 if (!req) { 154 if (!req) {
154 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_seq_set() invalid arguments\n"); 155 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_seq_set() invalid arguments\n");
155 errno = EFAULT; 156 errno = EFAULT;
156 return -1; 157 return -1;
157 } 158 }
172 { 173 {
173 int i; 174 int i;
174 175
175 if (!s) 176 if (!s)
176 return; 177 return;
177 178
178 for (i = 0; i < s->entries_count; i++) { 179 for (i = 0; i < s->entries_count; i++) {
179 free(s->entries[i].field); 180 free(s->entries[i].field);
180 free(s->entries[i].value); 181 free(s->entries[i].value);
181 } 182 }
182 183
200 uint32_t res; 201 uint32_t res;
201 char *buf, *p; 202 char *buf, *p;
202 struct gg_pubdir50_request *r; 203 struct gg_pubdir50_request *r;
203 204
204 gg_debug_session(sess, GG_DEBUG_FUNCTION, "** gg_pubdir50(%p, %p);\n", sess, req); 205 gg_debug_session(sess, GG_DEBUG_FUNCTION, "** gg_pubdir50(%p, %p);\n", sess, req);
205 206
206 if (!sess || !req) { 207 if (!sess || !req) {
207 gg_debug_session(sess, GG_DEBUG_MISC, "// gg_pubdir50() invalid arguments\n"); 208 gg_debug_session(sess, GG_DEBUG_MISC, "// gg_pubdir50() invalid arguments\n");
208 errno = EFAULT; 209 errno = EFAULT;
209 return 0; 210 return 0;
210 } 211 }
217 218
218 for (i = 0; i < req->entries_count; i++) { 219 for (i = 0; i < req->entries_count; i++) {
219 /* wyszukiwanie bierze tylko pierwszy wpis */ 220 /* wyszukiwanie bierze tylko pierwszy wpis */
220 if (req->entries[i].num) 221 if (req->entries[i].num)
221 continue; 222 continue;
222 223
223 if (sess->encoding == GG_ENCODING_CP1250) { 224 if (sess->encoding == GG_ENCODING_CP1250) {
224 size += strlen(req->entries[i].field) + 1; 225 size += strlen(req->entries[i].field) + 1;
225 size += strlen(req->entries[i].value) + 1; 226 size += strlen(req->entries[i].value) + 1;
226 } else { 227 } else {
227 char *tmp; 228 char *tmp;
325 { 326 {
326 const char *end = packet + length, *p; 327 const char *end = packet + length, *p;
327 struct gg_pubdir50_reply *r = (struct gg_pubdir50_reply*) packet; 328 struct gg_pubdir50_reply *r = (struct gg_pubdir50_reply*) packet;
328 gg_pubdir50_t res; 329 gg_pubdir50_t res;
329 int num = 0; 330 int num = 0;
330 331
331 gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_handle_reply_sess(%p, %p, %p, %d);\n", sess, e, packet, length); 332 gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_handle_reply_sess(%p, %p, %p, %d);\n", sess, e, packet, length);
332 333
333 if (!sess || !e || !packet) { 334 if (!sess || !e || !packet) {
334 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_handle_reply() invalid arguments\n"); 335 gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_handle_reply() invalid arguments\n");
335 errno = EFAULT; 336 errno = EFAULT;
382 num++; 383 num++;
383 field++; 384 field++;
384 } 385 }
385 386
386 value = NULL; 387 value = NULL;
387 388
388 for (p = field; p < end; p++) { 389 for (p = field; p < end; p++) {
389 /* jeśli mamy koniec tekstu... */ 390 /* jeśli mamy koniec tekstu... */
390 if (!*p) { 391 if (!*p) {
391 /* ...i jeszcze nie mieliśmy wartości pola to 392 /* ...i jeszcze nie mieliśmy wartości pola to
392 * wiemy, że po tym zerze jest wartość... */ 393 * wiemy, że po tym zerze jest wartość... */
397 * wartości i możemy wychodzić 398 * wartości i możemy wychodzić
398 * grzecznie z pętli */ 399 * grzecznie z pętli */
399 break; 400 break;
400 } 401 }
401 } 402 }
402 403
403 /* sprawdźmy, czy pole nie wychodzi poza pakiet, żeby nie 404 /* sprawdźmy, czy pole nie wychodzi poza pakiet, żeby nie
404 * mieć segfaultów, jeśli serwer przestanie zakańczać pakietów 405 * mieć segfaultów, jeśli serwer przestanie zakańczać pakietów
405 * przez \0 */ 406 * przez \0 */
406 407
407 if (p == end) { 408 if (p == end) {
434 } 435 }
435 436
436 free(tmp); 437 free(tmp);
437 } 438 }
438 } 439 }
439 } 440 }
440 441
441 res->count = num + 1; 442 res->count = num + 1;
442 443
443 return 0; 444 return 0;
444 445
445 failure: 446 failure:
446 gg_pubdir50_free(res); 447 gg_pubdir50_free(res);
447 return -1; 448 return -1;

mercurial