res_pjsip res_pjsip_mwi: Misc fixes and cleanups.
[asterisk/asterisk.git] / res / res_hep.c
index 474e15d..e79f2b6 100644 (file)
@@ -37,7 +37,6 @@
  */
 
 /*** MODULEINFO
-       <defaultenabled>no</defaultenabled>
        <support_level>extended</support_level>
  ***/
 
                                                </enumlist>
                                        </description>
                                </configOption>
+                               <configOption name="uuid_type" default="call-id">
+                                       <synopsis>The preferred type of UUID to pass to Homer.</synopsis>
+                                       <description>
+                                               <enumlist>
+                                                       <enum name="call-id"><para>Use the PJSIP Call-Id</para></enum>
+                                                       <enum name="channel"><para>Use the Asterisk channel name</para></enum>
+                                               </enumlist>
+                                       </description>
+                               </configOption>
                                <configOption name="capture_address" default="192.168.1.1:9061">
                                        <synopsis>The address and port of the Homer server to send packets to.</synopsis>
                                </configOption>
@@ -77,7 +85,7 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+ASTERISK_REGISTER_FILE()
 
 #include "asterisk/module.h"
 #include "asterisk/astobj2.h"
@@ -232,6 +240,7 @@ struct hep_generic {
 struct hepv3_global_config {
        unsigned int enabled;                    /*!< Whether or not sending is enabled */
        unsigned int capture_id;                 /*!< Capture ID for this agent */
+       enum hep_uuid_type uuid_type;            /*!< The preferred type of the UUID */
        AST_DECLARE_STRING_FIELDS(
                AST_STRING_FIELD(capture_address);   /*!< Address to send to */
                AST_STRING_FIELD(capture_password);  /*!< Password for Homer server */
@@ -330,6 +339,25 @@ static void *module_config_alloc(void)
        return config;
 }
 
+/*! \brief Handler for the uuid_type attribute */
+static int uuid_type_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+       struct hepv3_global_config *global_config = obj;
+
+       if (strcasecmp(var->name, "uuid_type")) {
+               return -1;
+       }
+
+       if (!strcasecmp(var->value, "channel")) {
+               global_config->uuid_type = HEP_UUID_TYPE_CHANNEL;
+       } else if (!strcasecmp(var->value, "call-id")) {
+               global_config->uuid_type = HEP_UUID_TYPE_CALL_ID;
+       } else {
+               return -1;
+       }
+       return 0;
+}
+
 /*! \brief HEPv3 run-time data destructor */
 static void hepv3_data_dtor(void *obj)
 {
@@ -377,6 +405,25 @@ static void capture_info_dtor(void *obj)
        ast_free(info->payload);
 }
 
+enum hep_uuid_type hepv3_get_uuid_type(void)
+{
+       RAII_VAR(struct module_config *, config, ao2_global_obj_ref(global_config), ao2_cleanup);
+
+       if (!config) {
+               /* Well, that's unfortunate. Return something. */
+               return HEP_UUID_TYPE_CALL_ID;
+       }
+
+       return config->general->uuid_type;
+}
+
+int hepv3_is_loaded(void)
+{
+       RAII_VAR(struct module_config *, config, ao2_global_obj_ref(global_config), ao2_cleanup);
+
+       return (config != NULL) ? 1 : 0;
+}
+
 struct hepv3_capture_info *hepv3_create_capture_info(const void *payload, size_t len)
 {
        struct hepv3_capture_info *info;
@@ -533,6 +580,7 @@ int hepv3_send_packet(struct hepv3_capture_info *capture_info)
        int res;
 
        if (!config || !config->general->enabled) {
+               ao2_ref(capture_info, -1);
                return 0;
        }
 
@@ -561,6 +609,7 @@ static void hepv3_config_post_apply(void)
        }
 
        ao2_global_obj_replace_unref(global_data, data);
+       ao2_ref(data, -1);
 }
 
 /*!
@@ -606,6 +655,7 @@ static int load_module(void)
        aco_option_register(&cfg_info, "capture_address", ACO_EXACT, global_options, DEFAULT_HEP_SERVER, OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_address));
        aco_option_register(&cfg_info, "capture_password", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_password));
        aco_option_register(&cfg_info, "capture_id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));
+       aco_option_register_custom(&cfg_info, "uuid_type", ACO_EXACT, global_options, "call-id", uuid_type_handler, 0);
 
        if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
                goto error;
@@ -619,8 +669,9 @@ error:
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "HEPv3 API",
+       .support_level = AST_MODULE_SUPPORT_EXTENDED,
        .load = load_module,
        .unload = unload_module,
        .reload = reload_module,
        .load_pri = AST_MODPRI_APP_DEPEND,
-       );
+);