git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@196 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2005-12-23 02:24:56 +00:00
parent 549d9ca93a
commit 32273a0c3f
6 changed files with 104 additions and 6 deletions

9
conf/xmpp_event.conf Normal file
View File

@ -0,0 +1,9 @@
[settings]
debug => 0
#jid => somebody@jabber.org
#passwd => pass
#target_jid => somebodyelse@jabber.org

View File

@ -54,6 +54,7 @@ struct switch_event {
char *owner;
switch_event_subclass *subclass;
struct switch_event_header *headers;
char *body;
void *bind_user_data;
void *event_user_data;
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_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_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_create(event, id) switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)

View File

@ -125,6 +125,7 @@ typedef enum {
SWITCH_EVENT_CUSTOM,
SWITCH_EVENT_CHANNEL_STATE,
SWITCH_EVENT_CHANNEL_ANSWER,
SWITCH_EVENT_API,
SWITCH_EVENT_LOG,
SWITCH_EVENT_INBOUND_CHAN,
SWITCH_EVENT_OUTBOUND_CHAN,

View File

@ -204,6 +204,50 @@ int on_stream (struct session *sess, int type, iks *node)
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)
{
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);
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_RULE_TYPE, IKS_PAK_IQ,
IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,

View File

@ -57,9 +57,7 @@ char *arg = NULL;
return 1;
}
if ((arg = strchr(cmd, ' '))) {
*arg++ = '\0';
}
if ((api = loadable_module_get_api_interface(cmd))) {
char retbuf[512] = "";
api->function(arg, retbuf, sizeof(retbuf));

View File

@ -90,6 +90,7 @@ static char *EVENT_NAMES[] = {
"CUSTOM",
"CHANNEL_STATE",
"CHANNEL_ANSWER",
"API",
"LOG",
"INBOUND_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)
{
#ifdef MALLOC_EVENTS
@ -423,7 +446,7 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
{
size_t len;
switch_event_header *hp;
char *data = NULL;
char *data = NULL, *body = NULL;
int ret = 0;
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) {
snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value);
len = strlen(buf);
}
if (data) {
snprintf(buf+len, buflen-len, "Content-Length: %d\n\n%s", (int)strlen(data), data);
free(data);
body = 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 {
snprintf(buf+len, buflen-len, "\n");
}
} else {
snprintf(buf+len, buflen-len, "\n");
}
if (data) {
free(data);
}
return SWITCH_STATUS_SUCCESS;
}