parse_allow.c

Go to the documentation of this file.
00001 /*
00002  * $Id: parse_allow.c 4720 2008-08-23 10:56:15Z henningw $
00003  *
00004  * Copyright (c) 2004 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  * History:
00023  * -------
00024  * 2006-03-02  parse_allow() parses and cumulates all ALLOW headers (bogdan)
00025  */
00026 
00027 /*!
00028  * \file
00029  * \brief SIP message parser
00030  * \ingroup parser
00031  */
00032 
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include "../dprint.h"
00036 #include "../mem/mem.h"
00037 #include "parse_allow.h"
00038 #include "parse_methods.h"
00039 #include "msg_parser.h"
00040 
00041 
00042 /*!
00043  * \brief This method is used to parse all Allow HF body.
00044  * \param msg sip msg
00045  * \return 0 on success,-1 on failure.
00046  */
00047 int parse_allow(struct sip_msg *msg)
00048 {
00049    unsigned int allow;
00050    struct hdr_field  *hdr;
00051    struct allow_body *ab = 0;
00052 
00053    /* maybe the header is already parsed! */
00054    if (msg->allow && msg->allow->parsed)
00055       return 0;
00056 
00057    /* parse to the end in order to get all ALLOW headers */
00058    if (parse_headers(msg,HDR_EOH_F,0)==-1 || !msg->allow)
00059       return -1;
00060 
00061    /* bad luck! :-( - we have to parse them */
00062    allow = 0;
00063    for( hdr=msg->allow ; hdr ; hdr=hdr->sibling) {
00064       if (hdr->parsed) {
00065          allow |= ((struct allow_body*)hdr->parsed)->allow;
00066          continue;
00067       }
00068 
00069       ab = (struct allow_body*)pkg_malloc(sizeof(struct allow_body));
00070       if (ab == 0) {
00071          LM_ERR("out of pkg_memory\n");
00072          return -1;
00073       }
00074 
00075       if (parse_methods(&(hdr->body), &(ab->allow))!=0) {
00076          LM_ERR("bad allow body header\n"); 
00077          goto error;
00078       }
00079       ab->allow_all = 0;
00080       hdr->parsed = (void*)ab;
00081       allow |= ab->allow;
00082    }
00083 
00084    ((struct allow_body*)msg->allow->parsed)->allow_all = allow;
00085    return 0;
00086 
00087 error:
00088    if(ab!=0)
00089       pkg_free(ab);
00090    return -1;
00091 }
00092 

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