parse_refer_to.c

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

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