parse_pai.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Juha Heinanen
00003  *
00004  * This file is part of Kamailio, a free SIP server.
00005  *
00006  * Kamailio is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * Kamailio is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License 
00017  * along with this program; if not, write to the Free Software 
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*!
00022  * \file
00023  * \brief P-Asserted-Identity header parser
00024  * \ingroup parser
00025  */
00026 
00027 #include "parse_from.h"
00028 #include "parse_to.h"
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include "../dprint.h"
00032 #include "msg_parser.h"
00033 #include "../ut.h"
00034 #include "../mem/mem.h"
00035 
00036 /*!
00037  * This method is used to parse P-Asserted-Identity header (RFC 3325).
00038  *
00039  * Currently only one name-addr / addr-spec is supported in the header
00040  * and it must contain a sip or sips URI.
00041  * \param msg sip msg
00042  * \return 0 on success, -1 on failure.
00043  */
00044 int parse_pai_header( struct sip_msg *msg )
00045 {
00046    struct to_body* pai_b;
00047 
00048    if ( !msg->pai && (parse_headers(msg, HDR_PAI_F,0)==-1 || !msg->pai)) {
00049       goto error;
00050    }
00051 
00052    /* maybe the header is already parsed! */
00053    if (msg->pai->parsed)
00054       return 0;
00055  
00056    /* bad luck! :-( - we have to parse it */
00057    /* first, get some memory */
00058    pai_b = pkg_malloc(sizeof(struct to_body));
00059    if (pai_b == 0) {
00060       LM_ERR("out of pkg_memory\n");
00061       goto error;
00062    }
00063  
00064    /* now parse it!! */
00065    memset(pai_b, 0, sizeof(struct to_body));
00066    parse_to(msg->pai->body.s, msg->pai->body.s + msg->pai->body.len+1, pai_b);
00067    if (pai_b->error == PARSE_ERROR) {
00068       LM_ERR("bad P-Asserted-Identity header\n");
00069       pkg_free(pai_b);
00070       goto error;
00071    }
00072    msg->pai->parsed = pai_b;
00073  
00074    return 0;
00075 error:
00076    return -1;
00077 }

Generated on Thu May 24 00:00:28 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6