esl_event.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * Copyright (c) 2007-2014, Anthony Minessale II
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of the original author; nor the names of any contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  25. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #ifndef ESL_EVENT_H
  34. #define ESL_EVENT_H
  35. #include <esl.h>
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif /* defined(__cplusplus) */
  39. typedef enum {
  40. ESL_STACK_BOTTOM,
  41. ESL_STACK_TOP,
  42. ESL_STACK_PUSH,
  43. ESL_STACK_UNSHIFT
  44. } esl_stack_t;
  45. typedef enum {
  46. ESL_EVENT_CUSTOM,
  47. ESL_EVENT_CLONE,
  48. ESL_EVENT_CHANNEL_CREATE,
  49. ESL_EVENT_CHANNEL_DESTROY,
  50. ESL_EVENT_CHANNEL_STATE,
  51. ESL_EVENT_CHANNEL_CALLSTATE,
  52. ESL_EVENT_CHANNEL_ANSWER,
  53. ESL_EVENT_CHANNEL_HANGUP,
  54. ESL_EVENT_CHANNEL_HANGUP_COMPLETE,
  55. ESL_EVENT_CHANNEL_EXECUTE,
  56. ESL_EVENT_CHANNEL_EXECUTE_COMPLETE,
  57. ESL_EVENT_CHANNEL_HOLD,
  58. ESL_EVENT_CHANNEL_UNHOLD,
  59. ESL_EVENT_CHANNEL_BRIDGE,
  60. ESL_EVENT_CHANNEL_UNBRIDGE,
  61. ESL_EVENT_CHANNEL_PROGRESS,
  62. ESL_EVENT_CHANNEL_PROGRESS_MEDIA,
  63. ESL_EVENT_CHANNEL_OUTGOING,
  64. ESL_EVENT_CHANNEL_PARK,
  65. ESL_EVENT_CHANNEL_UNPARK,
  66. ESL_EVENT_CHANNEL_APPLICATION,
  67. ESL_EVENT_CHANNEL_ORIGINATE,
  68. ESL_EVENT_CHANNEL_UUID,
  69. ESL_EVENT_API,
  70. ESL_EVENT_LOG,
  71. ESL_EVENT_INBOUND_CHAN,
  72. ESL_EVENT_OUTBOUND_CHAN,
  73. ESL_EVENT_STARTUP,
  74. ESL_EVENT_SHUTDOWN,
  75. ESL_EVENT_PUBLISH,
  76. ESL_EVENT_UNPUBLISH,
  77. ESL_EVENT_TALK,
  78. ESL_EVENT_NOTALK,
  79. ESL_EVENT_SESSION_CRASH,
  80. ESL_EVENT_MODULE_LOAD,
  81. ESL_EVENT_MODULE_UNLOAD,
  82. ESL_EVENT_DTMF,
  83. ESL_EVENT_MESSAGE,
  84. ESL_EVENT_PRESENCE_IN,
  85. ESL_EVENT_NOTIFY_IN,
  86. ESL_EVENT_PRESENCE_OUT,
  87. ESL_EVENT_PRESENCE_PROBE,
  88. ESL_EVENT_MESSAGE_WAITING,
  89. ESL_EVENT_MESSAGE_QUERY,
  90. ESL_EVENT_ROSTER,
  91. ESL_EVENT_CODEC,
  92. ESL_EVENT_BACKGROUND_JOB,
  93. ESL_EVENT_DETECTED_SPEECH,
  94. ESL_EVENT_DETECTED_TONE,
  95. ESL_EVENT_PRIVATE_COMMAND,
  96. ESL_EVENT_HEARTBEAT,
  97. ESL_EVENT_TRAP,
  98. ESL_EVENT_ADD_SCHEDULE,
  99. ESL_EVENT_DEL_SCHEDULE,
  100. ESL_EVENT_EXE_SCHEDULE,
  101. ESL_EVENT_RE_SCHEDULE,
  102. ESL_EVENT_RELOADXML,
  103. ESL_EVENT_NOTIFY,
  104. ESL_EVENT_PHONE_FEATURE,
  105. ESL_EVENT_PHONE_FEATURE_SUBSCRIBE,
  106. ESL_EVENT_SEND_MESSAGE,
  107. ESL_EVENT_RECV_MESSAGE,
  108. ESL_EVENT_REQUEST_PARAMS,
  109. ESL_EVENT_CHANNEL_DATA,
  110. ESL_EVENT_GENERAL,
  111. ESL_EVENT_COMMAND,
  112. ESL_EVENT_SESSION_HEARTBEAT,
  113. ESL_EVENT_CLIENT_DISCONNECTED,
  114. ESL_EVENT_SERVER_DISCONNECTED,
  115. ESL_EVENT_SEND_INFO,
  116. ESL_EVENT_RECV_INFO,
  117. ESL_EVENT_RECV_RTCP_MESSAGE,
  118. ESL_EVENT_CALL_SECURE,
  119. ESL_EVENT_NAT,
  120. ESL_EVENT_RECORD_START,
  121. ESL_EVENT_RECORD_STOP,
  122. ESL_EVENT_PLAYBACK_START,
  123. ESL_EVENT_PLAYBACK_STOP,
  124. ESL_EVENT_CALL_UPDATE,
  125. ESL_EVENT_FAILURE,
  126. ESL_EVENT_SOCKET_DATA,
  127. ESL_EVENT_MEDIA_BUG_START,
  128. ESL_EVENT_MEDIA_BUG_STOP,
  129. ESL_EVENT_CONFERENCE_DATA_QUERY,
  130. ESL_EVENT_CONFERENCE_DATA,
  131. ESL_EVENT_CALL_SETUP_REQ,
  132. ESL_EVENT_CALL_SETUP_RESULT,
  133. ESL_EVENT_CALL_DETAIL,
  134. ESL_EVENT_DEVICE_STATE,
  135. ESL_EVENT_ALL
  136. } esl_event_types_t;
  137. typedef enum {
  138. ESL_PRIORITY_NORMAL,
  139. ESL_PRIORITY_LOW,
  140. ESL_PRIORITY_HIGH
  141. } esl_priority_t;
  142. /*! \brief An event Header */
  143. struct esl_event_header {
  144. /*! the header name */
  145. char *name;
  146. /*! the header value */
  147. char *value;
  148. /*! array space */
  149. char **array;
  150. /*! array index */
  151. int idx;
  152. /*! hash of the header name */
  153. unsigned long hash;
  154. struct esl_event_header *next;
  155. };
  156. /*! \brief Representation of an event */
  157. struct esl_event {
  158. /*! the event id (descriptor) */
  159. esl_event_types_t event_id;
  160. /*! the priority of the event */
  161. esl_priority_t priority;
  162. /*! the owner of the event */
  163. char *owner;
  164. /*! the subclass of the event */
  165. char *subclass_name;
  166. /*! the event headers */
  167. esl_event_header_t *headers;
  168. /*! the event headers tail pointer */
  169. esl_event_header_t *last_header;
  170. /*! the body of the event */
  171. char *body;
  172. /*! user data from the subclass provider */
  173. void *bind_user_data;
  174. /*! user data from the event sender */
  175. void *event_user_data;
  176. /*! unique key */
  177. unsigned long key;
  178. struct esl_event *next;
  179. int flags;
  180. };
  181. typedef enum {
  182. ESL_EF_UNIQ_HEADERS = (1 << 0)
  183. } esl_event_flag_t;
  184. #define ESL_EVENT_SUBCLASS_ANY NULL
  185. /*!
  186. \brief Create an event
  187. \param event a NULL pointer on which to create the event
  188. \param event_id the event id enumeration of the desired event
  189. \param subclass_name the subclass name for custom event (only valid when event_id is ESL_EVENT_CUSTOM)
  190. \return ESL_SUCCESS on success
  191. */
  192. ESL_DECLARE(esl_status_t) esl_event_create_subclass(esl_event_t **event, esl_event_types_t event_id, const char *subclass_name);
  193. /*!
  194. \brief Set the priority of an event
  195. \param event the event to set the priority on
  196. \param priority the event priority
  197. \return ESL_SUCCESS
  198. */
  199. ESL_DECLARE(esl_status_t) esl_event_set_priority(esl_event_t *event, esl_priority_t priority);
  200. /*!
  201. \brief Retrieve a header value from an event
  202. \param event the event to read the header from
  203. \param header_name the name of the header to read
  204. \return the value of the requested header
  205. */
  206. ESL_DECLARE(esl_event_header_t *) esl_event_get_header_ptr(esl_event_t *event, const char *header_name);
  207. ESL_DECLARE(char *) esl_event_get_header_idx(esl_event_t *event, const char *header_name, int idx);
  208. #define esl_event_get_header(_e, _h) esl_event_get_header_idx(_e, _h, -1)
  209. /*!
  210. \brief Retrieve the body value from an event
  211. \param event the event to read the body from
  212. \return the value of the body or NULL
  213. */
  214. ESL_DECLARE(char *)esl_event_get_body(esl_event_t *event);
  215. /*!
  216. \brief Add a header to an event
  217. \param event the event to add the header to
  218. \param stack the stack sense (stack it on the top or on the bottom)
  219. \param header_name the name of the header to add
  220. \param fmt the value of the header (varargs see standard sprintf family)
  221. \return ESL_SUCCESS if the header was added
  222. */
  223. ESL_DECLARE(esl_status_t) esl_event_add_header(esl_event_t *event, esl_stack_t stack,
  224. const char *header_name, const char *fmt, ...); //PRINTF_FUNCTION(4, 5);
  225. ESL_DECLARE(int) esl_event_add_array(esl_event_t *event, const char *var, const char *val);
  226. /*!
  227. \brief Add a string header to an event
  228. \param event the event to add the header to
  229. \param stack the stack sense (stack it on the top or on the bottom)
  230. \param header_name the name of the header to add
  231. \param data the value of the header
  232. \return ESL_SUCCESS if the header was added
  233. */
  234. ESL_DECLARE(esl_status_t) esl_event_add_header_string(esl_event_t *event, esl_stack_t stack, const char *header_name, const char *data);
  235. ESL_DECLARE(esl_status_t) esl_event_del_header_val(esl_event_t *event, const char *header_name, const char *var);
  236. #define esl_event_del_header(_e, _h) esl_event_del_header_val(_e, _h, NULL)
  237. /*!
  238. \brief Destroy an event
  239. \param event pointer to the pointer to event to destroy
  240. */
  241. ESL_DECLARE(void) esl_event_destroy(esl_event_t **event);
  242. #define esl_event_safe_destroy(_event) if (_event) esl_event_destroy(_event)
  243. /*!
  244. \brief Duplicate an event
  245. \param event a NULL pointer on which to duplicate the event
  246. \param todup an event to duplicate
  247. \return ESL_SUCCESS if the event was duplicated
  248. */
  249. ESL_DECLARE(esl_status_t) esl_event_dup(esl_event_t **event, esl_event_t *todup);
  250. ESL_DECLARE(void) esl_event_merge(esl_event_t *event, esl_event_t *tomerge);
  251. /*!
  252. \brief Render the name of an event id enumeration
  253. \param event the event id to render the name of
  254. \return the rendered name
  255. */
  256. ESL_DECLARE(const char *)esl_event_name(esl_event_types_t event);
  257. /*!
  258. \brief return the event id that matches a given event name
  259. \param name the name of the event
  260. \param type the event id to return
  261. \return ESL_SUCCESS if there was a match
  262. */
  263. ESL_DECLARE(esl_status_t) esl_name_event(const char *name, esl_event_types_t *type);
  264. /*!
  265. \brief Render a string representation of an event sutable for printing or network transport
  266. \param event the event to render
  267. \param str a string pointer to point at the allocated data
  268. \param encode url encode the headers
  269. \return ESL_SUCCESS if the operation was successful
  270. \note you must free the resulting string when you are finished with it
  271. */
  272. ESL_DECLARE(esl_status_t) esl_event_serialize(esl_event_t *event, char **str, esl_bool_t encode);
  273. ESL_DECLARE(esl_status_t) esl_event_serialize_json(esl_event_t *event, char **str);
  274. ESL_DECLARE(esl_status_t) esl_event_create_json(esl_event_t **event, const char *json);
  275. /*!
  276. \brief Add a body to an event
  277. \param event the event to add to body to
  278. \param fmt optional body of the event (varargs see standard sprintf family)
  279. \return ESL_SUCCESS if the body was added to the event
  280. \note the body parameter can be shadowed by the esl_event_reserve_subclass_detailed function
  281. */
  282. ESL_DECLARE(esl_status_t) esl_event_add_body(esl_event_t *event, const char *fmt, ...);
  283. ESL_DECLARE(esl_status_t) esl_event_set_body(esl_event_t *event, const char *body);
  284. /*!
  285. \brief Create a new event assuming it will not be custom event and therefore hiding the unused parameters
  286. \param event a NULL pointer on which to create the event
  287. \param id the event id enumeration of the desired event
  288. \return ESL_SUCCESS on success
  289. */
  290. #define esl_event_create(event, id) esl_event_create_subclass(event, id, ESL_EVENT_SUBCLASS_ANY)
  291. ESL_DECLARE(const char *)esl_priority_name(esl_priority_t priority);
  292. ///\}
  293. #ifdef __cplusplus
  294. }
  295. #endif /* defined(__cplusplus) */
  296. #endif /* defined(ESL_EVENT_H) */
  297. /* For Emacs:
  298. * Local Variables:
  299. * mode:c
  300. * indent-tabs-mode:t
  301. * tab-width:4
  302. * c-basic-offset:4
  303. * End:
  304. * For VIM:
  305. * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
  306. */