mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-06 02:22:56 +00:00
Allow the event encoding strategy to be configurable; choices are string or binary
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11495 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
9c83e491e0
commit
462db06bb7
@ -53,6 +53,7 @@
|
|||||||
(s) += 4; \
|
(s) += 4; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
void ei_link(listener_t *listener, erlang_pid *from, erlang_pid *to) {
|
void ei_link(listener_t *listener, erlang_pid *from, erlang_pid *to) {
|
||||||
char msgbuf[2048];
|
char msgbuf[2048];
|
||||||
char *s;
|
char *s;
|
||||||
@ -92,21 +93,21 @@ void ei_encode_switch_event_headers(ei_x_buff *ebuf, switch_event_t *event)
|
|||||||
ei_x_encode_list_header(ebuf, i+1);
|
ei_x_encode_list_header(ebuf, i+1);
|
||||||
|
|
||||||
if (uuid) {
|
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 {
|
} else {
|
||||||
ei_x_encode_atom(ebuf, "undefined");
|
ei_x_encode_atom(ebuf, "undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (hp = event->headers; hp; hp = hp->next) {
|
for (hp = event->headers; hp; hp = hp->next) {
|
||||||
ei_x_encode_tuple_header(ebuf, 2);
|
ei_x_encode_tuple_header(ebuf, 2);
|
||||||
ei_x_encode_string(ebuf, hp->name);
|
_ei_x_encode_string(ebuf, hp->name);
|
||||||
ei_x_encode_string(ebuf, hp->value);
|
_ei_x_encode_string(ebuf, hp->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->body) {
|
if (event->body) {
|
||||||
ei_x_encode_tuple_header(ebuf, 2);
|
ei_x_encode_tuple_header(ebuf, 2);
|
||||||
ei_x_encode_string(ebuf, "body");
|
_ei_x_encode_string(ebuf, "body");
|
||||||
ei_x_encode_string(ebuf, event->body);
|
_ei_x_encode_string(ebuf, event->body);
|
||||||
}
|
}
|
||||||
|
|
||||||
ei_x_encode_empty_list(ebuf);
|
ei_x_encode_empty_list(ebuf);
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
<param name="listen-port" value="8031"/>
|
<param name="listen-port" value="8031"/>
|
||||||
<param name="cookie" value="ClueCon"/>
|
<param name="cookie" value="ClueCon"/>
|
||||||
<param name="shortname" value="true"/>
|
<param name="shortname" value="true"/>
|
||||||
|
<!-- in additon to cookie, optionally restrict by ACL -->
|
||||||
<!--<param name="apply-inbound-acl" value="lan"/>-->
|
<!--<param name="apply-inbound-acl" value="lan"/>-->
|
||||||
|
<!-- alternative is "binary" -->
|
||||||
|
<!--<param name="encoding" value="string"/>-->
|
||||||
</settings>
|
</settings>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -101,8 +101,8 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
|
|||||||
else
|
else
|
||||||
ei_x_encode_atom(&ebuf, "bgerror");
|
ei_x_encode_atom(&ebuf, "bgerror");
|
||||||
|
|
||||||
ei_x_encode_string(&ebuf, acs->uuid_str);
|
_ei_x_encode_string(&ebuf, acs->uuid_str);
|
||||||
ei_x_encode_string(&ebuf, reply);
|
_ei_x_encode_string(&ebuf, reply);
|
||||||
|
|
||||||
switch_mutex_lock(acs->listener->sock_mutex);
|
switch_mutex_lock(acs->listener->sock_mutex);
|
||||||
ei_send(acs->listener->sockfd, &acs->pid, ebuf.buff, ebuf.index);
|
ei_send(acs->listener->sockfd, &acs->pid, ebuf.buff, ebuf.index);
|
||||||
@ -129,7 +129,7 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
|
|||||||
ei_x_encode_atom(&rbuf, "error");
|
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);
|
switch_mutex_lock(acs->listener->sock_mutex);
|
||||||
@ -360,7 +360,7 @@ static switch_status_t handle_msg_bgapi(listener_t *listener, erlang_msg *msg, i
|
|||||||
|
|
||||||
ei_x_encode_tuple_header(rbuf, 2);
|
ei_x_encode_tuple_header(rbuf, 2);
|
||||||
ei_x_encode_atom(rbuf, "ok");
|
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;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -380,10 +380,10 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c
|
|||||||
ei_x_encode_tuple_header(&buf, 7);
|
ei_x_encode_tuple_header(&buf, 7);
|
||||||
ei_x_encode_atom(&buf, "fetch");
|
ei_x_encode_atom(&buf, "fetch");
|
||||||
ei_x_encode_atom(&buf, sectionstr);
|
ei_x_encode_atom(&buf, sectionstr);
|
||||||
ei_x_encode_string(&buf, tag_name ? tag_name : "undefined");
|
_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_name ? key_name : "undefined");
|
||||||
ei_x_encode_string(&buf, key_value ? key_value : "undefined");
|
_ei_x_encode_string(&buf, key_value ? key_value : "undefined");
|
||||||
ei_x_encode_string(&buf, uuid_str);
|
_ei_x_encode_string(&buf, uuid_str);
|
||||||
ei_encode_switch_event_headers(&buf, params);
|
ei_encode_switch_event_headers(&buf, params);
|
||||||
|
|
||||||
/*switch_core_hash_insert(ptr->reply_hash, uuid_str, );*/
|
/*switch_core_hash_insert(ptr->reply_hash, uuid_str, );*/
|
||||||
@ -840,6 +840,7 @@ static int config(void)
|
|||||||
memset(&prefs, 0, sizeof(prefs));
|
memset(&prefs, 0, sizeof(prefs));
|
||||||
|
|
||||||
prefs.shortname = SWITCH_TRUE;
|
prefs.shortname = SWITCH_TRUE;
|
||||||
|
prefs.encoding = ERLANG_STRING;
|
||||||
|
|
||||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
|
||||||
@ -859,6 +860,14 @@ static int config(void)
|
|||||||
set_pref_nodename(val);
|
set_pref_nodename(val);
|
||||||
} else if (!strcmp(var, "shortname")) {
|
} else if (!strcmp(var, "shortname")) {
|
||||||
prefs.shortname = switch_true(val);
|
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")) {
|
} else if (!strcasecmp(var, "apply-inbound-acl")) {
|
||||||
if (prefs.acl_count < MAX_ACL) {
|
if (prefs.acl_count < MAX_ACL) {
|
||||||
prefs.acl[prefs.acl_count++] = strdup(val);
|
prefs.acl[prefs.acl_count++] = strdup(val);
|
||||||
|
@ -44,6 +44,11 @@ typedef enum {
|
|||||||
ERLANG_REG_PROCESS
|
ERLANG_REG_PROCESS
|
||||||
} process_type;
|
} process_type;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ERLANG_STRING = 0,
|
||||||
|
ERLANG_BINARY
|
||||||
|
} erlang_encoding_t;
|
||||||
|
|
||||||
struct erlang_process {
|
struct erlang_process {
|
||||||
process_type type;
|
process_type type;
|
||||||
char *reg_name;
|
char *reg_name;
|
||||||
@ -163,6 +168,7 @@ struct prefs_struct {
|
|||||||
char *acl[MAX_ACL];
|
char *acl[MAX_ACL];
|
||||||
uint32_t acl_count;
|
uint32_t acl_count;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
erlang_encoding_t encoding;
|
||||||
};
|
};
|
||||||
typedef struct prefs_struct prefs_t;
|
typedef struct prefs_struct prefs_t;
|
||||||
|
|
||||||
@ -197,6 +203,16 @@ int ei_compare_pids(erlang_pid *pid1, erlang_pid *pid2);
|
|||||||
switch_status_t initialise_ei(struct ei_cnode_s *ec);
|
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")
|
#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 */
|
/* 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_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);
|
session_elem_t* attach_call_to_spawned_process(listener_t* listener, char *module, char *function, switch_core_session_t *session);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user