parse_param.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Generic Parameter Parser
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. * History:
  28. * -------
  29. * 2003-03-24 Created by janakj
  30. * 2003-04-07 shm duplication support (janakj)
  31. * 2003-04-07 URI class added (janakj)
  32. */
  33. /*! \file
  34. * \brief Parser :: Generic Parameter Parser
  35. *
  36. * \ingroup parser
  37. */
  38. #ifndef PARSE_PARAM_H
  39. #define PARSE_PARAM_H
  40. #include <stdio.h>
  41. #include "../str.h"
  42. /*! \brief
  43. * Supported types of parameters
  44. */
  45. typedef enum ptype {
  46. P_OTHER = 0, /*!< Unknown parameter */
  47. P_Q, /*!< Contact: q parameter */
  48. P_EXPIRES, /*!< Contact: expires parameter */
  49. P_METHODS, /*!< Contact: methods parameter */
  50. P_RECEIVED, /*!< Contact: received parameter */
  51. P_TRANSPORT, /*!< URI: transport parameter */
  52. P_LR, /*!< URI: lr parameter */
  53. P_R2, /*!< URI: r2 parameter (ser specific) */
  54. P_MADDR, /*!< URI: maddr parameter */
  55. P_TTL, /*!< URI: ttl parameter */
  56. P_DSTIP, /*!< URI: dstip parameter */
  57. P_DSTPORT, /*!< URi: dstport parameter */
  58. P_INSTANCE, /*!< Contact: sip.instance parameter */
  59. P_REG_ID, /*!< Contact: reg-id parameter */
  60. P_FTAG, /*!< URI: ftag parameter */
  61. P_CALL_ID, /*!< Dialog event package: call-id */
  62. P_FROM_TAG, /*!< Dialog event package: from-tag */
  63. P_TO_TAG, /*!< Dialog event package: to-tag */
  64. P_ISD, /*!< Dialog event package: include-session-description */
  65. P_SLA, /*!< Dialog event package: sla */
  66. P_MA, /*!< Dialog event package: ma */
  67. P_OB /*!< Contact|URI: ob parameter */
  68. } ptype_t;
  69. /*! \brief
  70. * Class of parameters
  71. */
  72. typedef enum pclass {
  73. CLASS_ANY = 0, /*!< Any parameters, well-known hooks will be not used */
  74. CLASS_CONTACT, /*!< Contact parameters */
  75. CLASS_URI, /*!< URI parameters */
  76. CLASS_EVENT_DIALOG /*!< Event dialog parameters */
  77. } pclass_t;
  78. /*! \brief
  79. * Structure representing a parameter
  80. */
  81. typedef struct param {
  82. ptype_t type; /*!< Type of the parameter */
  83. str name; /*!< Parameter name */
  84. str body; /*!< Parameter body */
  85. int len; /*!< Total length of the parameter including = and quotes */
  86. struct param* next; /*!< Next parameter in the list */
  87. } param_t;
  88. /*! \brief
  89. * Hooks to well known parameters for contact class of parameters
  90. */
  91. struct contact_hooks {
  92. struct param* expires; /*!< expires parameter */
  93. struct param* q; /*!< q parameter */
  94. struct param* methods; /*!< methods parameter */
  95. struct param* received; /*!< received parameter */
  96. struct param* instance; /*!< sip.instance parameter */
  97. struct param* reg_id; /*!< reg-id parameter */
  98. struct param* ob; /*!< ob parameter */
  99. };
  100. /*! \brief
  101. * Hooks to well known parameter for URI class of parameters
  102. */
  103. struct uri_hooks {
  104. struct param* transport; /*!< transport parameter */
  105. struct param* lr; /*!< lr parameter */
  106. struct param* r2; /*!< r2 parameter */
  107. struct param* maddr; /*!< maddr parameter */
  108. struct param* ttl; /*!< ttl parameter */
  109. struct param* dstip; /*!< Destination IP */
  110. struct param* dstport; /*!< Destination port */
  111. struct param* ftag; /*!< From tag in the original request */
  112. struct param* ob; /*!< ob parameter */
  113. };
  114. struct event_dialog_hooks {
  115. struct param* call_id;
  116. struct param* from_tag;
  117. struct param* to_tag;
  118. struct param* include_session_description;
  119. struct param* sla;
  120. struct param* ma;
  121. };
  122. /*! \brief
  123. * Union of hooks structures for all classes
  124. */
  125. typedef union param_hooks {
  126. struct contact_hooks contact; /*!< Contact hooks */
  127. struct uri_hooks uri; /*!< URI hooks */
  128. struct event_dialog_hooks event_dialog;
  129. } param_hooks_t;
  130. /*! \brief
  131. * Only parse one parameter
  132. * @return:
  133. * t: out parameter
  134. * -1: on error
  135. * 0: success, but expect a next paramter
  136. * 1: success and exepect no more parameters
  137. */
  138. extern inline int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t);
  139. /*! \brief
  140. * Parse parameters
  141. * \param _s is string containing parameters
  142. * \param _c is class of parameters
  143. * \param _h is pointer to structure that will be filled with pointer to well known parameters
  144. * linked list of parsed parameters will be stored in the variable _p is pointing to
  145. * \return The function returns 0 on success and negative number
  146. * on an error
  147. */
  148. int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p);
  149. /*! \brief
  150. * Parse parameters
  151. * \param _s is string containing parameters
  152. * \param _c is class of parameters
  153. * \param _h is pointer to structure that will be filled with pointer to well known parameters
  154. * linked list of parsed parameters will be stored in the variable _p is pointing to
  155. * \param separator single character separator
  156. * \return The function returns 0 on success and negative number
  157. * on an error
  158. */
  159. int parse_params2(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p,
  160. char separator);
  161. /*! \brief
  162. * Free linked list of parameters
  163. */
  164. void free_params(param_t* _p);
  165. /*! \brief
  166. * Free linked list of parameters from shared memory
  167. */
  168. void shm_free_params(param_t* _p);
  169. /*! \brief
  170. * Print linked list of parameters, just for debugging
  171. */
  172. void print_params(FILE* _o, param_t* _p);
  173. /*! \brief
  174. * Duplicate linked list of parameters
  175. */
  176. int duplicate_params(param_t** _n, param_t* _p);
  177. /*! \brief
  178. * Duplicate linked list of parameters
  179. */
  180. int shm_duplicate_params(param_t** _n, param_t* _p);
  181. #endif /* PARSE_PARAM_H */