sr_module.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* $Id$
  2. *
  3. * modules/plugin strtuctures declarations
  4. *
  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. #ifndef sr_module_h
  30. #define sr_module_h
  31. #include "parser/msg_parser.h" /* for sip_msg */
  32. typedef struct module_exports* (*module_register)();
  33. typedef int (*cmd_function)(struct sip_msg*, char*, char*);
  34. typedef int (*fixup_function)(void** param, int param_no);
  35. typedef int (*response_function)(struct sip_msg*);
  36. typedef void (*onbreak_function)(struct sip_msg*);
  37. typedef void (*destroy_function)();
  38. typedef int (*init_function)(void);
  39. typedef int (*child_init_function)(int rank);
  40. typedef enum {
  41. STR_PARAM, /* String parameter type */
  42. INT_PARAM, /* Integer parameter type */
  43. } modparam_t; /* Allowed types of parameters */
  44. struct module_exports{
  45. char* name; /* null terminated module name */
  46. char** cmd_names; /* cmd names registered by this modules */
  47. cmd_function* cmd_pointers; /* pointers to the corresponding
  48. functions */
  49. int* param_no; /* number of parameters used
  50. by the function */
  51. fixup_function* fixup_pointers; /* pointers to functions called to "fix"
  52. the params, e.g: precompile a re */
  53. int cmd_no; /* number of registered commands
  54. (size of cmd_{names,pointers} */
  55. char** param_names; /* parameter names registered by this modules */
  56. modparam_t* param_types; /* Type of parameters */
  57. void** param_pointers; /* Pointers to the corresponding memory locations */
  58. int par_no; /* number of registered parameters */
  59. init_function init_f; /* Initilization function */
  60. response_function response_f; /* function used for responses,
  61. returns yes or no; can be null */
  62. destroy_function destroy_f; /* function called when the module should
  63. be "destroyed", e.g: on ser exit;
  64. can be null */
  65. onbreak_function onbreak_f;
  66. child_init_function init_child_f; /* function called by all processes
  67. after the fork */
  68. };
  69. struct sr_module{
  70. char* path;
  71. void* handle;
  72. struct module_exports* exports;
  73. struct sr_module* next;
  74. };
  75. struct sr_module* modules; /* global module list*/
  76. int register_builtin_modules();
  77. int register_module(struct module_exports*, char*, void*);
  78. int load_module(char* path);
  79. cmd_function find_export(char* name, int param_no);
  80. struct sr_module* find_module(void *f, int* r);
  81. void destroy_modules();
  82. int init_child(int rank);
  83. int init_modules(void);
  84. /*
  85. * Find a parameter with given type and return it's
  86. * address in memory
  87. * If there is no such parameter, NULL is returned
  88. */
  89. void* find_param_export(char* mod, char* name, modparam_t type);
  90. /* modules function prototypes:
  91. * struct module_exports* mod_register(); (type module_register)
  92. * int foo_cmd(struct sip_msg* msg, char* param);
  93. * - returns >0 if ok , <0 on error, 0 to stop processing (==DROP)
  94. * int response_f(struct sip_msg* msg)
  95. * - returns >0 if ok, 0 to drop message
  96. */
  97. #endif