parse_sipifmatch.c

Go to the documentation of this file.
00001 /*
00002  * $Id: parse_sipifmatch.c 4720 2008-08-23 10:56:15Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
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 Parse Sipifmatch HF body
00026  * \ingroup parser
00027  */
00028 
00029 #include <string.h>
00030 
00031 #include "parse_sipifmatch.h"
00032 #include "../dprint.h"
00033 #include "parse_def.h"
00034 #include "../mem/mem.h"
00035 #include "../trim.h"
00036 
00037 static inline char* skip_token(char* _b, int _l)
00038 {
00039         int i = 0;
00040 
00041         for(i = 0; i < _l; i++) {
00042                 switch(_b[i]) {
00043                 case ' ':
00044                 case '\r':
00045                 case '\n':
00046                 case '\t':
00047                 case ';':
00048                         return _b + i;
00049                 }
00050         }
00051 
00052         return _b + _l;
00053 }
00054 
00055 
00056 int
00057 etag_parser(char *_s, int _l, str *_e)
00058 {
00059         char* end;
00060 
00061         _e->s = _s;
00062         _e->len = _l;
00063 
00064         trim_leading(_e);
00065 
00066         if (_e->len == 0) {
00067                 LM_ERR("empty body\n");
00068                 return -1;
00069         }
00070 
00071         end = skip_token(_e->s, _e->len);
00072         _e->len = end - _e->s;
00073 
00074    return 0;
00075 }
00076 
00077 
00078 int
00079 parse_sipifmatch(struct hdr_field* _h)
00080 {
00081    str *e;
00082 
00083    LM_DBG("called\n");
00084 
00085         if (_h->parsed != 0) {
00086                 return 0;
00087         }
00088 
00089         e = (str*)pkg_malloc(sizeof(str));
00090         if (e == 0) {
00091                 LM_ERR("no pkg memory left\n");
00092                 return -1;
00093         }
00094 
00095         memset(e, 0, sizeof(str));
00096 
00097         if (etag_parser(_h->body.s, _h->body.len, e) < 0) {
00098                 LM_ERR("error in tag_parser\n");
00099                 pkg_free(e);
00100                 return -2;
00101         }
00102 
00103         _h->parsed = (void*)e;
00104         return 0;
00105 }
00106 
00107 
00108 void free_sipifmatch(str** _e)
00109 {
00110    if (*_e)
00111       pkg_free(*_e);
00112    *_e = 0;
00113 }

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