Changeset 5669
- Timestamp:
- Oct 3, 2017 9:35:36 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua2/siptypes.cpp
r5207 r5669 364 364 void SipHeader::fromPj(const pjsip_hdr *hdr) throw(Error) 365 365 { 366 char buf[256]; 367 368 int len = pjsip_hdr_print_on((void*)hdr, buf, sizeof(buf)-1); 369 if (len <= 0) 366 char *buf = NULL; 367 int len = 0; 368 unsigned buf_size = 256>>1; 369 370 /* Print header to a 256 bytes buffer first. 371 * If buffer is not sufficient, try 512, 1024, soon 372 * until > PJSIP_MAX_PKT_LEN 373 */ 374 do { 375 buf_size <<= 1; 376 buf = (char*)malloc(buf_size); 377 if (!buf) 378 PJSUA2_RAISE_ERROR(PJ_ENOMEM); 379 380 len = pjsip_hdr_print_on((void*)hdr, buf, buf_size-1); 381 if (len < 0) 382 free(buf); 383 384 } while ((buf_size < PJSIP_MAX_PKT_LEN) && (len < 0)); 385 386 if (len < 0) 370 387 PJSUA2_RAISE_ERROR(PJ_ETOOSMALL); 388 371 389 buf[len] = '\0'; 372 390 373 391 char *pos = strchr(buf, ':'); 374 if (!pos) 392 if (!pos) { 393 free(buf); 375 394 PJSUA2_RAISE_ERROR(PJSIP_EINVALIDHDR); 395 } 376 396 377 397 // Trim white space after header name … … 385 405 hName = string(buf, end_name); 386 406 hValue = string(start_val); 407 free(buf); 387 408 } 388 409
Note: See TracChangeset
for help on using the changeset viewer.