clean up presence function

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13164 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-04-27 15:52:34 +00:00
parent e58f6afa6f
commit b51345932c
1 changed files with 22 additions and 6 deletions

View File

@ -1094,20 +1094,28 @@ SWITCH_STANDARD_API(strftime_api_function)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
#define PRESENCE_USAGE "[in|out] <user> <rpid> <message>"
SWITCH_STANDARD_API(presence_api_function) SWITCH_STANDARD_API(presence_api_function)
{ {
switch_event_t *event; switch_event_t *event;
char *lbuf, *argv[4]; char *lbuf, *argv[4];
int argc = 0; int argc = 0;
switch_event_types_t type = SWITCH_EVENT_PRESENCE_IN; switch_event_types_t type = SWITCH_EVENT_PRESENCE_IN;
int need = 4;
if (!switch_strlen_zero(cmd) && (lbuf = strdup(cmd)) if (!switch_strlen_zero(cmd) && (lbuf = strdup(cmd))
&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) > 0) { && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) > 0) {
if (!strcasecmp(argv[0], "out")) { if (!strcasecmp(argv[0], "out")) {
type = SWITCH_EVENT_PRESENCE_OUT; type = SWITCH_EVENT_PRESENCE_OUT;
} else if (argc != 4) { need = 2;
stream->write_function(stream, "Invalid"); } else if (strcasecmp(argv[0], "in")) {
return SWITCH_STATUS_SUCCESS; goto error;
}
if (argc != need) {
goto error;
} }
if (switch_event_create(&event, type) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, type) == SWITCH_STATUS_SUCCESS) {
@ -1119,14 +1127,22 @@ SWITCH_STANDARD_API(presence_api_function)
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", argv[3]); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", argv[3]);
} }
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
switch_event_fire(&event); switch_event_fire(&event);
} }
stream->write_function(stream, "Event Sent"); stream->write_function(stream, "Event Sent");
switch_safe_free(lbuf); switch_safe_free(lbuf);
} else { } else {
stream->write_function(stream, "Invalid"); goto error;
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
error:
stream->write_function(stream, "Invalid: presence %s", PRESENCE_USAGE);
return SWITCH_STATUS_SUCCESS;
} }
SWITCH_STANDARD_API(chat_api_function) SWITCH_STANDARD_API(chat_api_function)
@ -2599,7 +2615,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SWITCH_ADD_API(api_interface, "strepoch", "Convert a date string into epoch time", strepoch_api_function, "<string>"); SWITCH_ADD_API(api_interface, "strepoch", "Convert a date string into epoch time", strepoch_api_function, "<string>");
SWITCH_ADD_API(api_interface, "chat", "chat", chat_api_function, "<proto>|<from>|<to>|<message>|[<content-type>]"); SWITCH_ADD_API(api_interface, "chat", "chat", chat_api_function, "<proto>|<from>|<to>|<message>|[<content-type>]");
SWITCH_ADD_API(api_interface, "strftime", "strftime", strftime_api_function, "<format_string>"); SWITCH_ADD_API(api_interface, "strftime", "strftime", strftime_api_function, "<format_string>");
SWITCH_ADD_API(api_interface, "presence", "presence", presence_api_function, "<user> <rpid> <message>"); SWITCH_ADD_API(api_interface, "presence", "presence", presence_api_function, PRESENCE_USAGE);
SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number", SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number",
SAF_SUPPORT_NOMEDIA); SAF_SUPPORT_NOMEDIA);