mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-13 10:37:42 +00:00
xmppmas
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@196 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
549d9ca93a
commit
32273a0c3f
9
conf/xmpp_event.conf
Normal file
9
conf/xmpp_event.conf
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[settings]
|
||||||
|
|
||||||
|
debug => 0
|
||||||
|
|
||||||
|
#jid => somebody@jabber.org
|
||||||
|
#passwd => pass
|
||||||
|
#target_jid => somebodyelse@jabber.org
|
||||||
|
|
||||||
|
|
@ -54,6 +54,7 @@ struct switch_event {
|
|||||||
char *owner;
|
char *owner;
|
||||||
switch_event_subclass *subclass;
|
switch_event_subclass *subclass;
|
||||||
struct switch_event_header *headers;
|
struct switch_event_header *headers;
|
||||||
|
char *body;
|
||||||
void *bind_user_data;
|
void *bind_user_data;
|
||||||
void *event_user_data;
|
void *event_user_data;
|
||||||
struct switch_event *next;
|
struct switch_event *next;
|
||||||
@ -83,6 +84,7 @@ SWITCH_DECLARE(char *) switch_event_name(switch_event_t event);
|
|||||||
SWITCH_DECLARE(switch_status) switch_event_reserve_subclass_detailed(char *owner, char *subclass_name);
|
SWITCH_DECLARE(switch_status) switch_event_reserve_subclass_detailed(char *owner, char *subclass_name);
|
||||||
SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *buf, size_t buflen, char *fmt, ...);
|
SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *buf, size_t buflen, char *fmt, ...);
|
||||||
SWITCH_DECLARE(switch_status) switch_event_running(void);
|
SWITCH_DECLARE(switch_status) switch_event_running(void);
|
||||||
|
SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *fmt, ...);
|
||||||
|
|
||||||
#define switch_event_reserve_subclass(subclass_name) switch_event_reserve_subclass_detailed(__FILE__, subclass_name)
|
#define switch_event_reserve_subclass(subclass_name) switch_event_reserve_subclass_detailed(__FILE__, subclass_name)
|
||||||
#define switch_event_create(event, id) switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)
|
#define switch_event_create(event, id) switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)
|
||||||
|
@ -125,6 +125,7 @@ typedef enum {
|
|||||||
SWITCH_EVENT_CUSTOM,
|
SWITCH_EVENT_CUSTOM,
|
||||||
SWITCH_EVENT_CHANNEL_STATE,
|
SWITCH_EVENT_CHANNEL_STATE,
|
||||||
SWITCH_EVENT_CHANNEL_ANSWER,
|
SWITCH_EVENT_CHANNEL_ANSWER,
|
||||||
|
SWITCH_EVENT_API,
|
||||||
SWITCH_EVENT_LOG,
|
SWITCH_EVENT_LOG,
|
||||||
SWITCH_EVENT_INBOUND_CHAN,
|
SWITCH_EVENT_INBOUND_CHAN,
|
||||||
SWITCH_EVENT_OUTBOUND_CHAN,
|
SWITCH_EVENT_OUTBOUND_CHAN,
|
||||||
|
@ -204,6 +204,50 @@ int on_stream (struct session *sess, int type, iks *node)
|
|||||||
return IKS_OK;
|
return IKS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int on_msg (void *user_data, ikspak *pak)
|
||||||
|
{
|
||||||
|
switch_api_interface *api;
|
||||||
|
char *cmd = iks_find_cdata (pak->x, "body");
|
||||||
|
char *arg = NULL;
|
||||||
|
switch_event *event;
|
||||||
|
char retbuf[512] = "";
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if ((p = strchr(cmd, '\r'))) {
|
||||||
|
*p++ = '\0';
|
||||||
|
} else if ((p = strchr(cmd, '\n'))) {
|
||||||
|
*p++ = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((arg = strchr(cmd, ' '))) {
|
||||||
|
*arg++ = '\0';
|
||||||
|
}
|
||||||
|
if (arg && (p = strchr(arg, '\r'))) {
|
||||||
|
*p++ = '\0';
|
||||||
|
} else if ((p = strchr(cmd, '\n'))) {
|
||||||
|
*p++ = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((api = loadable_module_get_api_interface(cmd))) {
|
||||||
|
api->function(arg, retbuf, sizeof(retbuf));
|
||||||
|
} else {
|
||||||
|
snprintf(retbuf, sizeof(retbuf), "INVALID COMMAND [%s]", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (switch_event_create(&event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
if (cmd) {
|
||||||
|
switch_event_add_header(event, "re_command", cmd);
|
||||||
|
}
|
||||||
|
if (arg) {
|
||||||
|
switch_event_add_header(event, "re_command_arg", arg);
|
||||||
|
}
|
||||||
|
switch_event_add_body(event, retbuf);
|
||||||
|
switch_event_fire(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int on_error (void *user_data, ikspak *pak)
|
int on_error (void *user_data, ikspak *pak)
|
||||||
{
|
{
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "authorization failed\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "authorization failed\n");
|
||||||
@ -221,6 +265,11 @@ void j_setup_filter (struct session *sess)
|
|||||||
{
|
{
|
||||||
if (my_filter) iks_filter_delete (my_filter);
|
if (my_filter) iks_filter_delete (my_filter);
|
||||||
my_filter = iks_filter_new ();
|
my_filter = iks_filter_new ();
|
||||||
|
iks_filter_add_rule (my_filter, on_msg, 0,
|
||||||
|
IKS_RULE_TYPE, IKS_PAK_MESSAGE,
|
||||||
|
IKS_RULE_SUBTYPE, IKS_TYPE_CHAT,
|
||||||
|
IKS_RULE_FROM, globals.target_jid,
|
||||||
|
IKS_RULE_DONE);
|
||||||
iks_filter_add_rule (my_filter, (iksFilterHook *) on_result, sess,
|
iks_filter_add_rule (my_filter, (iksFilterHook *) on_result, sess,
|
||||||
IKS_RULE_TYPE, IKS_PAK_IQ,
|
IKS_RULE_TYPE, IKS_PAK_IQ,
|
||||||
IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,
|
IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,
|
||||||
|
@ -57,9 +57,7 @@ char *arg = NULL;
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((arg = strchr(cmd, ' '))) {
|
|
||||||
*arg++ = '\0';
|
|
||||||
}
|
|
||||||
if ((api = loadable_module_get_api_interface(cmd))) {
|
if ((api = loadable_module_get_api_interface(cmd))) {
|
||||||
char retbuf[512] = "";
|
char retbuf[512] = "";
|
||||||
api->function(arg, retbuf, sizeof(retbuf));
|
api->function(arg, retbuf, sizeof(retbuf));
|
||||||
|
@ -90,6 +90,7 @@ static char *EVENT_NAMES[] = {
|
|||||||
"CUSTOM",
|
"CUSTOM",
|
||||||
"CHANNEL_STATE",
|
"CHANNEL_STATE",
|
||||||
"CHANNEL_ANSWER",
|
"CHANNEL_ANSWER",
|
||||||
|
"API",
|
||||||
"LOG",
|
"LOG",
|
||||||
"INBOUND_CHAN",
|
"INBOUND_CHAN",
|
||||||
"OUTBOUND_CHAN",
|
"OUTBOUND_CHAN",
|
||||||
@ -367,6 +368,28 @@ SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, char
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *fmt, ...)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
char data[2048];
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(data, sizeof(data), fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (ret == -1) {
|
||||||
|
return SWITCH_STATUS_MEMERR;
|
||||||
|
} else {
|
||||||
|
event->body = DUP(data);
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ret >= 0) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(void) switch_event_destroy(switch_event **event)
|
SWITCH_DECLARE(void) switch_event_destroy(switch_event **event)
|
||||||
{
|
{
|
||||||
#ifdef MALLOC_EVENTS
|
#ifdef MALLOC_EVENTS
|
||||||
@ -423,7 +446,7 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
|
|||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
switch_event_header *hp;
|
switch_event_header *hp;
|
||||||
char *data = NULL;
|
char *data = NULL, *body = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -450,13 +473,29 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
|
|||||||
for (hp = event->headers; hp; hp = hp->next) {
|
for (hp = event->headers; hp; hp = hp->next) {
|
||||||
snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value);
|
snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value);
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
snprintf(buf+len, buflen-len, "Content-Length: %d\n\n%s", (int)strlen(data), data);
|
body = data;
|
||||||
free(data);
|
} else if (event->body) {
|
||||||
|
body = event->body;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body) {
|
||||||
|
int blen = (int)strlen(body);
|
||||||
|
if (blen) {
|
||||||
|
snprintf(buf+len, buflen-len, "Content-Length: %d\n\n%s", blen, body);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buf+len, buflen-len, "\n");
|
snprintf(buf+len, buflen-len, "\n");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
snprintf(buf+len, buflen-len, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user