libpurple/protocols/gg/lib/pubdir50.c

changeset 35630
8e5d0d726b09
parent 35620
fb20cfee648a
parent 35627
fd11790cc4d6
child 37181
06b74c255e95
equal deleted inserted replaced
35629:5aecb81f23ab 35630:8e5d0d726b09
94 free(req->entries[i].value); 94 free(req->entries[i].value);
95 req->entries[i].value = dupvalue; 95 req->entries[i].value = dupvalue;
96 96
97 return 0; 97 return 0;
98 } 98 }
99 99
100 if (!(dupfield = strdup(field))) { 100 if (!(dupfield = strdup(field))) {
101 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");
102 free(dupvalue); 102 free(dupvalue);
103 return -1; 103 return -1;
104 } 104 }
149 * \ingroup pubdir50 149 * \ingroup pubdir50
150 */ 150 */
151 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)
152 { 152 {
153 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);
154 154
155 if (!req) { 155 if (!req) {
156 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");
157 errno = EFAULT; 157 errno = EFAULT;
158 return -1; 158 return -1;
159 } 159 }
174 { 174 {
175 int i; 175 int i;
176 176
177 if (!s) 177 if (!s)
178 return; 178 return;
179 179
180 for (i = 0; i < s->entries_count; i++) { 180 for (i = 0; i < s->entries_count; i++) {
181 free(s->entries[i].field); 181 free(s->entries[i].field);
182 free(s->entries[i].value); 182 free(s->entries[i].value);
183 } 183 }
184 184
202 uint32_t res; 202 uint32_t res;
203 char *buf, *p; 203 char *buf, *p;
204 struct gg_pubdir50_request *r; 204 struct gg_pubdir50_request *r;
205 205
206 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);
207 207
208 if (!sess || !req) { 208 if (!sess || !req) {
209 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");
210 errno = EFAULT; 210 errno = EFAULT;
211 return 0; 211 return 0;
212 } 212 }
219 219
220 for (i = 0; i < req->entries_count; i++) { 220 for (i = 0; i < req->entries_count; i++) {
221 /* wyszukiwanie bierze tylko pierwszy wpis */ 221 /* wyszukiwanie bierze tylko pierwszy wpis */
222 if (req->entries[i].num) 222 if (req->entries[i].num)
223 continue; 223 continue;
224 224
225 if (sess->encoding == GG_ENCODING_CP1250) { 225 if (sess->encoding == GG_ENCODING_CP1250) {
226 size += strlen(req->entries[i].field) + 1; 226 size += strlen(req->entries[i].field) + 1;
227 size += strlen(req->entries[i].value) + 1; 227 size += strlen(req->entries[i].value) + 1;
228 } else { 228 } else {
229 char *tmp; 229 char *tmp;
327 { 327 {
328 const char *end = packet + length, *p; 328 const char *end = packet + length, *p;
329 const struct gg_pubdir50_reply *r = (const struct gg_pubdir50_reply*) packet; 329 const struct gg_pubdir50_reply *r = (const struct gg_pubdir50_reply*) packet;
330 gg_pubdir50_t res; 330 gg_pubdir50_t res;
331 int num = 0; 331 int num = 0;
332 332
333 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);
334 334
335 if (!sess || !e || !packet) { 335 if (!sess || !e || !packet) {
336 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");
337 errno = EFAULT; 337 errno = EFAULT;
384 num++; 384 num++;
385 field++; 385 field++;
386 } 386 }
387 387
388 value = NULL; 388 value = NULL;
389 389
390 for (p = field; p < end; p++) { 390 for (p = field; p < end; p++) {
391 /* jeśli mamy koniec tekstu... */ 391 /* jeśli mamy koniec tekstu... */
392 if (!*p) { 392 if (!*p) {
393 /* ...i jeszcze nie mieliśmy wartości pola to 393 /* ...i jeszcze nie mieliśmy wartości pola to
394 * wiemy, że po tym zerze jest wartość... */ 394 * wiemy, że po tym zerze jest wartość... */
399 * wartości i możemy wychodzić 399 * wartości i możemy wychodzić
400 * grzecznie z pętli */ 400 * grzecznie z pętli */
401 break; 401 break;
402 } 402 }
403 } 403 }
404 404
405 /* sprawdźmy, czy pole nie wychodzi poza pakiet, żeby nie 405 /* sprawdźmy, czy pole nie wychodzi poza pakiet, żeby nie
406 * mieć segfaultów, jeśli serwer przestanie zakańczać pakietów 406 * mieć segfaultów, jeśli serwer przestanie zakańczać pakietów
407 * przez \0 */ 407 * przez \0 */
408 408
409 if (p == end) { 409 if (p == end) {
436 } 436 }
437 437
438 free(tmp); 438 free(tmp);
439 } 439 }
440 } 440 }
441 } 441 }
442 442
443 res->count = num + 1; 443 res->count = num + 1;
444 444
445 return 0; 445 return 0;
446 446
447 failure: 447 failure:
448 gg_pubdir50_free(res); 448 gg_pubdir50_free(res);
449 return -1; 449 return -1;

mercurial