]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_amqp] Events subclass support 1996/head
authoragree <ahrongreenberg@gmail.com>
Tue, 21 Mar 2023 16:16:01 +0000 (12:16 -0400)
committeragree <ahrongreenberg@gmail.com>
Tue, 21 Mar 2023 16:16:01 +0000 (12:16 -0400)
src/mod/event_handlers/mod_amqp/mod_amqp.h
src/mod/event_handlers/mod_amqp/mod_amqp_producer.c

index 0717876040d2740b7e5adee27758b242f182a200..f5c63780a47aa93fe22d7961adaf731e6ef72fc0 100644 (file)
@@ -87,6 +87,11 @@ typedef struct mod_amqp_keypart_s {
   int size;
 } mod_amqp_keypart_t;
 
+typedef struct {
+  switch_event_types_t id;
+  char* subclass;
+} mod_amqp_events_t;
+
 typedef struct {
   char *name;
 
@@ -103,7 +108,7 @@ typedef struct {
   /* Array to store the possible event subscriptions */
   int event_subscriptions;
   switch_event_node_t *event_nodes[SWITCH_EVENT_ALL];
-  switch_event_types_t event_ids[SWITCH_EVENT_ALL];
+  mod_amqp_events_t events[SWITCH_EVENT_ALL];
   switch_event_node_t *eventNode;
 
 
index d7741d3f414929b8fd5170351025ddbf860d6dc4..303927285eeb55a967d4e828b7e842e947a578a1 100644 (file)
@@ -186,7 +186,8 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
        profile->name = switch_core_strdup(profile->pool, name);
        profile->running = 1;
        memset(profile->format_fields, 0, (MAX_ROUTING_KEY_FORMAT_FIELDS + 1) * sizeof(mod_amqp_keypart_t));
-       profile->event_ids[0] = SWITCH_EVENT_ALL;
+       profile->events[0].id = SWITCH_EVENT_ALL;
+       profile->events[0].subclass = SWITCH_EVENT_SUBCLASS_ANY;
        profile->event_subscriptions = 1;
        profile->conn_root   = NULL;
        profile->conn_active = NULL;
@@ -269,7 +270,14 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Found %d subscriptions\n", profile->event_subscriptions);
 
                                for (arg = 0; arg < profile->event_subscriptions; arg++) {
-                                       if (switch_name_event(argv[arg], &(profile->event_ids[arg])) != SWITCH_STATUS_SUCCESS) {
+                                       char *subclass = SWITCH_EVENT_SUBCLASS_ANY;
+                                       if ((subclass = strchr(argv[arg], '^'))) {
+                                               *subclass++ = '\0';
+                                       }
+
+                                       if (switch_name_event(argv[arg], &(profile->events[arg].id)) == SWITCH_STATUS_SUCCESS) {
+                                               profile->events[arg].subclass = subclass;
+                                       } else {
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The switch event %s was not recognised.\n", argv[arg]);
                                        }
                                }
@@ -344,13 +352,13 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
        /* Subscribe events */
        for (i = 0; i < profile->event_subscriptions; i++) {
                if (switch_event_bind_removable("AMQP",
-                                                                               profile->event_ids[i],
-                                                                               SWITCH_EVENT_SUBCLASS_ANY,
+                                                                               profile->events[i].id,
+                                                                               profile->events[i].subclass,
                                                                                mod_amqp_producer_event_handler,
                                                                                profile,
                                                                                &(profile->event_nodes[i])) != SWITCH_STATUS_SUCCESS) {
 
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to event handler %d!\n",(int)profile->event_ids[i]);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to event handler %d!\n",(int)profile->events[i].id);
                        goto err;
                }
        }