parse_param.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * $Id$
  3. *
  4. * Generic Parameter Parser
  5. *
  6. * Copyright (C) 2001-2003 Fhg Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. *
  29. * History:
  30. * -------
  31. * 2003-03-24 Created by janakj
  32. * 2003-04-07 shm duplication support (janakj)
  33. * 2003-04-07 URI class added (janakj)
  34. */
  35. #ifndef PARSE_PARAM_H
  36. #define PARSE_PARAM_H
  37. #include <stdio.h>
  38. /*
  39. * Supported types of parameters
  40. */
  41. typedef enum ptype {
  42. P_OTHER = 0, /* Unknown parameter */
  43. P_Q, /* Contact: q parameter */
  44. P_EXPIRES, /* Contact: expires parameter */
  45. P_METHOD, /* Contact: method parameter */
  46. P_TRANSPORT, /* URI: transport parameter */
  47. P_LR, /* URI: lr parameter */
  48. P_R2, /* URI: r2 parameter (ser specific) */
  49. P_MADDR /* URI: maddr parameter */
  50. } ptype_t;
  51. /*
  52. * Class of parameters
  53. */
  54. typedef enum pclass {
  55. CLASS_ANY = 0, /* Any parameters, well-known hooks will be not used */
  56. CLASS_CONTACT, /* Contact parameters */
  57. CLASS_URI /* URI parameters */
  58. } pclass_t;
  59. /*
  60. * Structure representing a parameter
  61. */
  62. typedef struct param {
  63. ptype_t type; /* Type of the parameter */
  64. str name; /* Parameter name */
  65. str body; /* Parameter body */
  66. int len; /* Total lenght of the parameter including = and quotes */
  67. struct param* next; /* Next parameter in the list */
  68. } param_t;
  69. /*
  70. * Hooks to well known parameters for contact class of parameters
  71. */
  72. struct contact_hooks {
  73. struct param* expires; /* expires parameter */
  74. struct param* q; /* q parameter */
  75. struct param* method; /* method parameter */
  76. };
  77. /*
  78. * Hooks to well known parameter for URI class of parameters
  79. */
  80. struct uri_hooks {
  81. struct param* transport; /* transport parameter */
  82. struct param* lr; /* lr parameter */
  83. struct param* r2; /* r2 parameter */
  84. struct param* maddr; /* maddr parameter */
  85. };
  86. /*
  87. * Union of hooks structures for all classes
  88. */
  89. typedef union param_hooks {
  90. struct contact_hooks contact; /* Contact hooks */
  91. struct uri_hooks uri; /* URI hooks */
  92. } param_hooks_t;
  93. /*
  94. * Parse parameters
  95. * _s is string containing parameters
  96. * _c is class of parameters
  97. * _h is pointer to structure that will be filled with pointer to well known parameters
  98. * linked list of parsed parameters will be stored in
  99. * the variable _p is pointing to
  100. * The function returns 0 on success and negative number
  101. * on an error
  102. */
  103. int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p);
  104. /*
  105. * Free linked list of parameters
  106. */
  107. void free_params(param_t* _p);
  108. /*
  109. * Free linked list of parameters from shared memory
  110. */
  111. void shm_free_params(param_t* _p);
  112. /*
  113. * Print linked list of parameters, just for debugging
  114. */
  115. void print_params(FILE* _o, param_t* _p);
  116. /*
  117. * Duplicate linked list of parameters
  118. */
  119. int duplicate_params(param_t** _n, param_t* _p);
  120. /*
  121. * Duplicate linked list of parameters
  122. */
  123. int shm_duplicate_params(param_t** _n, param_t* _p);
  124. #endif /* PARSE_PARAM_H */