cel.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2008 - 2009, Digium, Inc.
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*!
  17. * \file
  18. * \brief Call Event Logging API
  19. *
  20. * \todo TODO: There some event types that have been defined here, but are not
  21. * yet used anywhere in the code. It would be really awesome if someone
  22. * went through and had Asterisk generate these events where it is
  23. * appropriate to do so. The defined, but unused events are:
  24. * CONF_ENTER, CONF_EXIT, CONF_START, CONF_END, 3WAY_START, 3WAY_END,
  25. * TRANSFER, and HOOKFLASH.
  26. */
  27. #ifndef __AST_CEL_H__
  28. #define __AST_CEL_H__
  29. #if defined(__cplusplus) || defined(c_plusplus)
  30. extern "C" {
  31. #endif
  32. #include "asterisk/event.h"
  33. /*!
  34. * \brief CEL event types
  35. */
  36. enum ast_cel_event_type {
  37. AST_CEL_INVALID_VALUE = -1,
  38. AST_CEL_ALL = 0,
  39. /*! \brief channel birth */
  40. AST_CEL_CHANNEL_START = 1,
  41. /*! \brief channel end */
  42. AST_CEL_CHANNEL_END = 2,
  43. /*! \brief hangup terminates connection */
  44. AST_CEL_HANGUP = 3,
  45. /*! \brief A ringing phone is answered */
  46. AST_CEL_ANSWER = 4,
  47. /*! \brief an app starts */
  48. AST_CEL_APP_START = 5,
  49. /*! \brief an app ends */
  50. AST_CEL_APP_END = 6,
  51. /*! \brief channel enters a bridge */
  52. AST_CEL_BRIDGE_ENTER = 7,
  53. /*! \brief channel exits a bridge */
  54. AST_CEL_BRIDGE_EXIT = 8,
  55. /*! \brief a channel is parked */
  56. AST_CEL_PARK_START = 9,
  57. /*! \brief channel out of the park */
  58. AST_CEL_PARK_END = 10,
  59. /*! \brief a transfer occurs */
  60. AST_CEL_BLINDTRANSFER = 11,
  61. /*! \brief a transfer occurs */
  62. AST_CEL_ATTENDEDTRANSFER = 12,
  63. /*! \brief a user-defined event, the event name field should be set */
  64. AST_CEL_USER_DEFINED = 13,
  65. /*! \brief the last channel with the given linkedid is retired */
  66. AST_CEL_LINKEDID_END = 14,
  67. /*! \brief a directed pickup was performed on this channel */
  68. AST_CEL_PICKUP = 15,
  69. /*! \brief this call was forwarded somewhere else */
  70. AST_CEL_FORWARD = 16,
  71. /*! \brief A local channel optimization occurred */
  72. AST_CEL_LOCAL_OPTIMIZE = 17,
  73. };
  74. /*!
  75. * \brief Check to see if CEL is enabled
  76. *
  77. * \since 1.8
  78. *
  79. * \retval zero not enabled
  80. * \retval non-zero enabled
  81. */
  82. unsigned int ast_cel_check_enabled(void);
  83. /*!
  84. * \brief Get the name of a CEL event type
  85. *
  86. * \param type the type to get the name of
  87. *
  88. * \since 1.8
  89. *
  90. * \return the string representation of the type
  91. */
  92. const char *ast_cel_get_type_name(enum ast_cel_event_type type);
  93. /*!
  94. * \brief Get the event type from a string
  95. *
  96. * \param name the event type name as a string
  97. *
  98. * \since 1.8
  99. *
  100. * \return the ast_cel_event_type given by the string
  101. */
  102. enum ast_cel_event_type ast_cel_str_to_event_type(const char *name);
  103. /*!
  104. * \brief Create a fake channel from data in a CEL event
  105. *
  106. * \note
  107. * This function creates a fake channel containing the
  108. * serialized channel data in the given cel event. It should be
  109. * released with ast_channel_unref() but could be released with
  110. * ast_channel_release().
  111. *
  112. * \param event the CEL event
  113. *
  114. * \since 1.8
  115. *
  116. * \return a channel with the data filled in, or NULL on error
  117. *
  118. * \todo This function is \b very expensive, especially given that some CEL backends
  119. * use it on \b every CEL event. This function really needs to go away at
  120. * some point.
  121. */
  122. struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event *event);
  123. /*!
  124. * \brief Helper struct for getting the fields out of a CEL event
  125. */
  126. struct ast_cel_event_record {
  127. /*!
  128. * \brief struct ABI version
  129. * \note This \b must be incremented when the struct changes.
  130. */
  131. #define AST_CEL_EVENT_RECORD_VERSION 2
  132. /*!
  133. * \brief struct ABI version
  134. * \note This \b must stay as the first member.
  135. */
  136. uint32_t version;
  137. enum ast_cel_event_type event_type;
  138. struct timeval event_time;
  139. const char *event_name;
  140. const char *user_defined_name;
  141. const char *caller_id_name;
  142. const char *caller_id_num;
  143. const char *caller_id_ani;
  144. const char *caller_id_rdnis;
  145. const char *caller_id_dnid;
  146. const char *extension;
  147. const char *context;
  148. const char *channel_name;
  149. const char *application_name;
  150. const char *application_data;
  151. const char *account_code;
  152. const char *peer_account;
  153. const char *unique_id;
  154. const char *linked_id;
  155. uint amaflag;
  156. const char *user_field;
  157. const char *peer;
  158. const char *extra;
  159. };
  160. /*!
  161. * \brief Fill in an ast_cel_event_record from a CEL event
  162. *
  163. * \param[in] event the CEL event
  164. * \param[out] r the ast_cel_event_record to fill in
  165. *
  166. * \since 1.8
  167. *
  168. * \retval 0 success
  169. * \retval non-zero failure
  170. */
  171. int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r);
  172. /*!
  173. * \brief Publish a CEL event
  174. * \since 12
  175. *
  176. * \param chan This is the primary channel associated with this channel event.
  177. * \param event_type This is the type of call event being reported.
  178. * \param blob This contains any additional parameters that need to be conveyed for this event.
  179. */
  180. void ast_cel_publish_event(struct ast_channel *chan,
  181. enum ast_cel_event_type event_type,
  182. struct ast_json *blob);
  183. /*!
  184. * \brief Get the CEL topic
  185. *
  186. * \retval The CEL topic
  187. * \retval NULL if not allocated
  188. */
  189. struct stasis_topic *ast_cel_topic(void);
  190. /*! \brief A structure to hold CEL global configuration options */
  191. struct ast_cel_general_config {
  192. AST_DECLARE_STRING_FIELDS(
  193. AST_STRING_FIELD(date_format); /*!< The desired date format for logging */
  194. );
  195. int enable; /*!< Whether CEL is enabled */
  196. int64_t events; /*!< The events to be logged */
  197. /*! The apps for which to log app start and end events. This is
  198. * ast_str_container_alloc()ed and filled with ao2-allocated
  199. * char* which are all-lowercase application names. */
  200. struct ao2_container *apps;
  201. };
  202. /*!
  203. * \brief Allocate a CEL configuration object
  204. *
  205. * \retval NULL on error
  206. * \retval The new CEL configuration object
  207. */
  208. void *ast_cel_general_config_alloc(void);
  209. /*!
  210. * \since 12
  211. * \brief Obtain the current CEL configuration
  212. *
  213. * The configuration is a ref counted object. The caller of this function must
  214. * decrement the ref count when finished with the configuration.
  215. *
  216. * \retval NULL on error
  217. * \retval The current CEL configuration
  218. */
  219. struct ast_cel_general_config *ast_cel_get_config(void);
  220. /*!
  221. * \since 12
  222. * \brief Set the current CEL configuration
  223. *
  224. * \param config The new CEL configuration
  225. */
  226. void ast_cel_set_config(struct ast_cel_general_config *config);
  227. struct ast_channel_snapshot;
  228. /*!
  229. * \brief Allocate and populate a CEL event structure
  230. *
  231. * \param snapshot An ast_channel_snapshot of the primary channel associated
  232. * with this channel event.
  233. * \param event_type The type of call event being reported.
  234. * \param userdefevname Custom name for the call event. (optional)
  235. * \param extra An event-specific opaque JSON blob to be rendered and placed
  236. * in the "CEL_EXTRA" information element of the call event. (optional)
  237. * \param peer_str A list of comma-separated peer channel names. (optional)
  238. *
  239. * \since 12
  240. *
  241. * \retval The created ast_event structure
  242. * \retval NULL on failure
  243. */
  244. struct ast_event *ast_cel_create_event(struct ast_channel_snapshot *snapshot,
  245. enum ast_cel_event_type event_type, const char *userdefevname,
  246. struct ast_json *extra, const char *peer_str);
  247. /*!
  248. * \brief CEL backend callback
  249. */
  250. /*typedef int (*ast_cel_backend_cb)(struct ast_cel_event_record *cel);*/
  251. typedef void (*ast_cel_backend_cb)(struct ast_event *event);
  252. /*!
  253. * \brief Register a CEL backend
  254. *
  255. * \param name Name of backend to register
  256. * \param backend_callback Callback to register
  257. *
  258. * \retval zero on success
  259. * \retval non-zero on failure
  260. * \since 12
  261. */
  262. int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback);
  263. /*!
  264. * \brief Unregister a CEL backend
  265. *
  266. * \param name Name of backend to unregister
  267. *
  268. * \retval zero on success
  269. * \retval non-zero on failure
  270. * \since 12
  271. */
  272. int ast_cel_backend_unregister(const char *name);
  273. #if defined(__cplusplus) || defined(c_plusplus)
  274. }
  275. #endif
  276. #endif /* __AST_CEL_H__ */