00001 /* 00002 * $Id: parse_param.h 5299 2008-12-04 18:12:33Z 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 Generic Parameter Parser 00026 * \ingroup parser 00027 */ 00028 00029 #ifndef PARSE_PARAM_H 00030 #define PARSE_PARAM_H 00031 00032 #include <stdio.h> 00033 00034 00035 /*! 00036 * Supported types of parameters 00037 */ 00038 typedef enum ptype { 00039 P_OTHER = 0, /*!< Unknown parameter */ 00040 P_Q, /*!< Contact: q parameter */ 00041 P_EXPIRES, /*!< Contact: expires parameter */ 00042 P_METHODS, /*!< Contact: methods parameter (RFC 3840) */ 00043 P_RECEIVED, /*!< Contact: received parameter */ 00044 P_TRANSPORT, /*!< URI: transport parameter */ 00045 P_LR, /*!< URI: lr parameter */ 00046 P_R2, /*!< URI: r2 parameter (ser specific) */ 00047 P_MADDR, /*!< URI: maddr parameter */ 00048 P_TTL, /*!< URI: ttl parameter */ 00049 P_DSTIP, /*!< URI: dstip parameter */ 00050 P_DSTPORT, /*!< URi: dstport parameter */ 00051 } ptype_t; 00052 00053 00054 /*! 00055 * Class of parameters 00056 */ 00057 typedef enum pclass { 00058 CLASS_ANY = 0, /*!< Any parameters, well-known hooks will be not used */ 00059 CLASS_CONTACT, /*!< Contact parameters */ 00060 CLASS_URI /*!< URI parameters */ 00061 } pclass_t; 00062 00063 00064 /*! 00065 * Structure representing a parameter 00066 */ 00067 typedef struct param { 00068 ptype_t type; /*!< Type of the parameter */ 00069 str name; /*!< Parameter name */ 00070 str body; /*!< Parameter body */ 00071 int len; /*!< Total length of the parameter including = and quotes */ 00072 struct param* next; /*!< Next parameter in the list */ 00073 } param_t; 00074 00075 00076 /*! 00077 * Hooks to well known parameters for contact class of parameters 00078 */ 00079 struct contact_hooks { 00080 struct param* expires; /*!< expires parameter */ 00081 struct param* q; /*!< q parameter */ 00082 struct param* methods; /*!< methods parameter (RFC 3840) */ 00083 struct param* received; /*!< received parameter */ 00084 }; 00085 00086 00087 /*! 00088 * Hooks to well known parameter for URI class of parameters 00089 */ 00090 struct uri_hooks { 00091 struct param* transport; /*!< transport parameter */ 00092 struct param* lr; /*!< lr parameter */ 00093 struct param* r2; /*!< r2 parameter */ 00094 struct param* maddr; /*!< maddr parameter */ 00095 struct param* ttl; /*!< ttl parameter */ 00096 struct param* dstip; /*!< Destination IP */ 00097 struct param* dstport; /*!< Destination port */ 00098 }; 00099 00100 00101 /*! 00102 * Union of hooks structures for all classes 00103 */ 00104 typedef union param_hooks { 00105 struct contact_hooks contact; /*!< Contact hooks */ 00106 struct uri_hooks uri; /*!< URI hooks */ 00107 } param_hooks_t; 00108 00109 00110 /*! 00111 * \brief Parse parameters 00112 * \param _s string containing parameters, it will be updated to point behind the parameters 00113 * \param _c class of parameters 00114 * \param _h structure that will be filled with pointer to well known parameters 00115 * \param _p linked list of parsed parameters will be stored in the variable _p is pointing to 00116 * \return 0 on success and negative number on an error 00117 */ 00118 int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p); 00119 00120 00121 /* 00122 * Free linked list of parameters in pkg_mem 00123 */ 00124 void free_params(param_t* _p); 00125 00126 00127 /* 00128 * Free linked list of parameters from shm_mem 00129 */ 00130 void shm_free_params(param_t* _p); 00131 00132 00133 /* 00134 * Print linked list of parameters, just for debugging 00135 */ 00136 void print_params(FILE* _o, param_t* _p); 00137 00138 00139 /* 00140 * Duplicate linked list of parameters in pkg_mem 00141 */ 00142 int duplicate_params(param_t** _n, param_t* _p); 00143 00144 00145 /* 00146 * Duplicate linked list of parameters in shm_mem 00147 */ 00148 int shm_duplicate_params(param_t** _n, param_t* _p); 00149 00150 00151 #endif /* PARSE_PARAM_H */
1.5.6