[Freeswitch-svn] [commit] r11495 - freeswitch/trunk/src/mod/event_handlers/mod_erlang_event
FreeSWITCH SVN
andrew at freeswitch.org
Mon Jan 26 15:31:40 PST 2009
Author: andrew
Date: Mon Jan 26 17:31:40 2009
New Revision: 11495
Log:
Allow the event encoding strategy to be configurable; choices are string or binary
Modified:
freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/ei_helpers.c
freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/erlang_event.conf.xml
freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c
freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/ei_helpers.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/ei_helpers.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/ei_helpers.c Mon Jan 26 17:31:40 2009
@@ -41,18 +41,19 @@
* */
#define put8(s,n) do { \
- (s)[0] = (char)((n) & 0xff); \
- (s) += 1; \
+ (s)[0] = (char)((n) & 0xff); \
+ (s) += 1; \
} while (0)
#define put32be(s,n) do { \
- (s)[0] = ((n) >> 24) & 0xff; \
- (s)[1] = ((n) >> 16) & 0xff; \
- (s)[2] = ((n) >> 8) & 0xff; \
- (s)[3] = (n) & 0xff; \
- (s) += 4; \
+ (s)[0] = ((n) >> 24) & 0xff; \
+ (s)[1] = ((n) >> 16) & 0xff; \
+ (s)[2] = ((n) >> 8) & 0xff; \
+ (s)[3] = (n) & 0xff; \
+ (s) += 4; \
} while (0)
+
void ei_link(listener_t *listener, erlang_pid *from, erlang_pid *to) {
char msgbuf[2048];
char *s;
@@ -92,21 +93,21 @@
ei_x_encode_list_header(ebuf, i+1);
if (uuid) {
- ei_x_encode_string(ebuf, switch_event_get_header(event, "unique-id"));
+ _ei_x_encode_string(ebuf, switch_event_get_header(event, "unique-id"));
} else {
ei_x_encode_atom(ebuf, "undefined");
}
for (hp = event->headers; hp; hp = hp->next) {
ei_x_encode_tuple_header(ebuf, 2);
- ei_x_encode_string(ebuf, hp->name);
- ei_x_encode_string(ebuf, hp->value);
+ _ei_x_encode_string(ebuf, hp->name);
+ _ei_x_encode_string(ebuf, hp->value);
}
if (event->body) {
ei_x_encode_tuple_header(ebuf, 2);
- ei_x_encode_string(ebuf, "body");
- ei_x_encode_string(ebuf, event->body);
+ _ei_x_encode_string(ebuf, "body");
+ _ei_x_encode_string(ebuf, event->body);
}
ei_x_encode_empty_list(ebuf);
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/erlang_event.conf.xml
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/erlang_event.conf.xml (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/erlang_event.conf.xml Mon Jan 26 17:31:40 2009
@@ -3,7 +3,10 @@
<param name="listen-ip" value="127.0.0.1"/>
<param name="listen-port" value="8031"/>
<param name="cookie" value="ClueCon"/>
- <param name="shortname" value="true"/>
- <!--<param name="apply-inbound-acl" value="lan"/>-->
+ <param name="shortname" value="true"/>
+ <!-- in additon to cookie, optionally restrict by ACL -->
+ <!--<param name="apply-inbound-acl" value="lan"/>-->
+ <!-- alternative is "binary" -->
+ <!--<param name="encoding" value="string"/>-->
</settings>
</configuration>
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c Mon Jan 26 17:31:40 2009
@@ -101,8 +101,8 @@
else
ei_x_encode_atom(&ebuf, "bgerror");
- ei_x_encode_string(&ebuf, acs->uuid_str);
- ei_x_encode_string(&ebuf, reply);
+ _ei_x_encode_string(&ebuf, acs->uuid_str);
+ _ei_x_encode_string(&ebuf, reply);
switch_mutex_lock(acs->listener->sock_mutex);
ei_send(acs->listener->sockfd, &acs->pid, ebuf.buff, ebuf.index);
@@ -129,7 +129,7 @@
ei_x_encode_atom(&rbuf, "error");
}
- ei_x_encode_string(&rbuf, reply);
+ _ei_x_encode_string(&rbuf, reply);
switch_mutex_lock(acs->listener->sock_mutex);
@@ -360,7 +360,7 @@
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "ok");
- ei_x_encode_string(rbuf, acs->uuid_str);
+ _ei_x_encode_string(rbuf, acs->uuid_str);
}
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c Mon Jan 26 17:31:40 2009
@@ -380,10 +380,10 @@
ei_x_encode_tuple_header(&buf, 7);
ei_x_encode_atom(&buf, "fetch");
ei_x_encode_atom(&buf, sectionstr);
- ei_x_encode_string(&buf, tag_name ? tag_name : "undefined");
- ei_x_encode_string(&buf, key_name ? key_name : "undefined");
- ei_x_encode_string(&buf, key_value ? key_value : "undefined");
- ei_x_encode_string(&buf, uuid_str);
+ _ei_x_encode_string(&buf, tag_name ? tag_name : "undefined");
+ _ei_x_encode_string(&buf, key_name ? key_name : "undefined");
+ _ei_x_encode_string(&buf, key_value ? key_value : "undefined");
+ _ei_x_encode_string(&buf, uuid_str);
ei_encode_switch_event_headers(&buf, params);
/*switch_core_hash_insert(ptr->reply_hash, uuid_str, );*/
@@ -840,6 +840,7 @@
memset(&prefs, 0, sizeof(prefs));
prefs.shortname = SWITCH_TRUE;
+ prefs.encoding = ERLANG_STRING;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
@@ -859,6 +860,14 @@
set_pref_nodename(val);
} else if (!strcmp(var, "shortname")) {
prefs.shortname = switch_true(val);
+ } else if (!strcmp(var, "encoding")) {
+ if (!strcasecmp(val, "string")) {
+ prefs.encoding = ERLANG_STRING;
+ } else if (!strcasecmp(val, "binary")) {
+ prefs.encoding = ERLANG_BINARY;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid encoding strategy '%s' specified\n", val);
+ }
} else if (!strcasecmp(var, "apply-inbound-acl")) {
if (prefs.acl_count < MAX_ACL) {
prefs.acl[prefs.acl_count++] = strdup(val);
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h Mon Jan 26 17:31:40 2009
@@ -44,6 +44,11 @@
ERLANG_REG_PROCESS
} process_type;
+typedef enum {
+ ERLANG_STRING = 0,
+ ERLANG_BINARY
+} erlang_encoding_t;
+
struct erlang_process {
process_type type;
char *reg_name;
@@ -163,6 +168,7 @@
char *acl[MAX_ACL];
uint32_t acl_count;
uint32_t id;
+ erlang_encoding_t encoding;
};
typedef struct prefs_struct prefs_t;
@@ -197,6 +203,16 @@
switch_status_t initialise_ei(struct ei_cnode_s *ec);
#define ei_encode_switch_event(_b, _e) ei_encode_switch_event_tag(_b, _e, "event")
+/* crazy macro for toggling encoding type */
+#define _ei_x_encode_string(buf, string) switch (prefs.encoding) { \
+ case ERLANG_BINARY: \
+ ei_x_encode_binary(buf, string, strlen(string)); \
+ break; \
+ default: \
+ ei_x_encode_string(buf, string); \
+ break; \
+}
+
/* mod_erlang_event.c */
session_elem_t* attach_call_to_registered_process(listener_t* listener, char* reg_name, switch_core_session_t *session);
session_elem_t* attach_call_to_spawned_process(listener_t* listener, char *module, char *function, switch_core_session_t *session);
More information about the Freeswitch-svn
mailing list