MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / parse_accept_hdr

Function parse_accept_hdr

parser/parse_content.c:482–553  ·  view source on GitHub ↗

returns: > 0 ok * = 0 hdr not found * = -1 error */

Source from the content-addressed store, hash-verified

480 * = 0 hdr not found
481 * = -1 error */
482int parse_accept_hdr( struct sip_msg *msg )
483{
484 static unsigned int mimes[MAX_MIMES_NR];
485 int nr_mimes;
486 unsigned int mime;
487 char *end;
488 char *ret;
489
490 /* is the header already found? */
491 if ( msg->accept==0 ) {
492 /* if not, found it */
493 if ( parse_headers(msg, HDR_ACCEPT_F, 0)==-1)
494 goto error;
495 if ( msg->accept==0 ) {
496 LM_DBG("missing Accept header\n");
497 return 0;
498 }
499 }
500
501 /* maybe the header is already parsed! */
502 if ( msg->accept->parsed!=0)
503 return 1;
504
505 /* it seams we have to parse it! :-( */
506 ret = msg->accept->body.s;
507 end = ret + msg->accept->body.len;
508 nr_mimes = 0;
509 while (1){
510 ret = decode_mime_type(ret, end , &mime, NULL);
511 if (ret==0)
512 goto parse_error;
513 /* a new mime was found -> put it into array */
514 if (nr_mimes==MAX_MIMES_NR) {
515 LM_ERR("accept hdr contains more than"
516 " %d mime type -> buffer overflow!!\n",MAX_MIMES_NR);
517 goto error;
518 }
519 mimes[nr_mimes++] = mime;
520 /* is another mime following? */
521 if (ret==end )
522 break;
523 /* parse the mime separator ',' */
524 if (*ret!=',' || ret+1==end) {
525 LM_ERR("parse error between mimes at "
526 "char <%x> (offset=%d) in <%.*s>!\n",
527 *ret, (int)(ret-msg->accept->body.s),
528 msg->accept->body.len, msg->accept->body.s);
529 goto parse_error;
530 }
531 /* skip the ',' */
532 ret++;
533 }
534
535 /* copy and link the mime buffer into the message */
536 msg->accept->parsed = (void*)pkg_malloc((nr_mimes+1)*sizeof(int));
537 if (msg->accept->parsed==0) {
538 LM_ERR("no more pkg memory\n");
539 goto error;

Callers 1

cpl_process_registerFunction · 0.85

Calls 3

decode_mime_typeFunction · 0.85
set_err_infoFunction · 0.85
set_err_replyFunction · 0.85

Tested by

no test coverage detected