提交 4114c1d5 authored 作者: Luis Azedo's avatar Luis Azedo

FS-7806 FS-7803 #resolve

added new properties to amqp configuration
fixed - enable_fallback_format_fields usage, only worked on first event
added amqp_util_encode to fix routing key
上级 6813d664
...@@ -50,10 +50,12 @@ ...@@ -50,10 +50,12 @@
/* If you change MAX_ROUTING_KEY_FORMAT_FIELDS then you must change the implementation of makeRoutingKey where it formats the routing key using sprintf */ /* If you change MAX_ROUTING_KEY_FORMAT_FIELDS then you must change the implementation of makeRoutingKey where it formats the routing key using sprintf */
#define MAX_ROUTING_KEY_FORMAT_FIELDS 10 #define MAX_ROUTING_KEY_FORMAT_FIELDS 10
#define MAX_ROUTING_KEY_FORMAT_FALLBACK_FIELDS 5
#define MAX_AMQP_ROUTING_KEY_LENGTH 255 #define MAX_AMQP_ROUTING_KEY_LENGTH 255
#define TIME_STATS_TO_AGGREGATE 1024 #define TIME_STATS_TO_AGGREGATE 1024
#define MOD_AMQP_DEBUG_TIMING 0 #define MOD_AMQP_DEBUG_TIMING 0
#define MOD_AMQP_DEFAULT_CONTENT_TYPE "text/json"
typedef struct { typedef struct {
...@@ -74,12 +76,23 @@ typedef struct mod_amqp_connection_s { ...@@ -74,12 +76,23 @@ typedef struct mod_amqp_connection_s {
struct mod_amqp_connection_s *next; struct mod_amqp_connection_s *next;
} mod_amqp_connection_t; } mod_amqp_connection_t;
typedef struct mod_amqp_keypart_s {
char *name[MAX_ROUTING_KEY_FORMAT_FALLBACK_FIELDS];
int size;
} mod_amqp_keypart_t;
typedef struct { typedef struct {
char *name; char *name;
char *exchange; char *exchange;
char *exchange_type; char *exchange_type;
char *format_fields[MAX_ROUTING_KEY_FORMAT_FIELDS+1]; int exchange_durable;
int exchange_auto_delete;
int delivery_mode;
int delivery_timestamp;
char *content_type;
mod_amqp_keypart_t format_fields[MAX_ROUTING_KEY_FORMAT_FIELDS+1];
/* Array to store the possible event subscriptions */ /* Array to store the possible event subscriptions */
int event_subscriptions; int event_subscriptions;
...@@ -158,11 +171,12 @@ void * SWITCH_THREAD_FUNC mod_amqp_command_thread(switch_thread_t *thread, void ...@@ -158,11 +171,12 @@ void * SWITCH_THREAD_FUNC mod_amqp_command_thread(switch_thread_t *thread, void
/* producer */ /* producer */
void mod_amqp_producer_event_handler(switch_event_t* evt); void mod_amqp_producer_event_handler(switch_event_t* evt);
switch_status_t mod_amqp_producer_routing_key(mod_amqp_producer_profile_t *profile, char routingKey[MAX_AMQP_ROUTING_KEY_LENGTH], switch_status_t mod_amqp_producer_routing_key(mod_amqp_producer_profile_t *profile, char routingKey[MAX_AMQP_ROUTING_KEY_LENGTH],
switch_event_t* evt, char* routingKeyEventHeaderNames[]); switch_event_t* evt, mod_amqp_keypart_t routingKeyEventHeaderNames[]);
switch_status_t mod_amqp_producer_destroy(mod_amqp_producer_profile_t **profile); switch_status_t mod_amqp_producer_destroy(mod_amqp_producer_profile_t **profile);
switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg); switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg);
void * SWITCH_THREAD_FUNC mod_amqp_producer_thread(switch_thread_t *thread, void *data); void * SWITCH_THREAD_FUNC mod_amqp_producer_thread(switch_thread_t *thread, void *data);
char *amqp_util_encode(char *key, char *dest);
#endif /* MOD_AMQP_H */ #endif /* MOD_AMQP_H */
...@@ -148,6 +148,42 @@ switch_status_t mod_amqp_do_config(switch_bool_t reload) ...@@ -148,6 +148,42 @@ switch_status_t mod_amqp_do_config(switch_bool_t reload)
} }
#define KEY_SAFE(C) ((C >= 'a' && C <= 'z') || \
(C >= 'A' && C <= 'Z') || \
(C >= '0' && C <= '9') || \
(C == '-' || C == '~' || C == '_'))
#define HI4(C) (C>>4)
#define LO4(C) (C & 0x0F)
#define hexint(C) (C < 10?('0' + C):('A'+ C - 10))
char *amqp_util_encode(char *key, char *dest) {
char *p, *end;
if ((strlen(key) == 1) && (key[0] == '#' || key[0] == '*')) {
*dest++ = key[0];
*dest = '\0';
return dest;
}
for (p = key, end = key + strlen(key); p < end; p++) {
if (KEY_SAFE(*p)) {
*dest++ = *p;
} else if (*p == '.') {
memcpy(dest, "%2E", 3);
dest += 3;
} else if (*p == ' ') {
*dest++ = '+';
} else {
*dest++ = '%';
sprintf(dest, "%c%c", hexint(HI4(*p)), hexint(LO4(*p)));
dest += 2;
}
}
*dest = '\0';
return dest;
}
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论