From 4ce2cebee506e94f1765e9240e2b35143c5ebe85 Mon Sep 17 00:00:00 2001 From: MelwareDE Date: Tue, 2 Nov 2010 15:44:36 +0000 Subject: [PATCH] Add 'chat manage' for management of chat conferences. Add first command 'remove'. To be reworked to support full range of commands. --- chan_capi_chat.c | 40 +++++++++++++++++++++++++++++ chan_capi_chat.h | 1 + chan_capi_cli.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/chan_capi_chat.c b/chan_capi_chat.c index 3446d58..479ade6 100644 --- a/chan_capi_chat.c +++ b/chan_capi_chat.c @@ -1117,3 +1117,43 @@ int pbx_capi_chat_mute(struct ast_channel *c, char *param) return -1; } +/* + CLI interface + */ +int pbx_capi_chat_remove_user(const char* roomName, const char* memberName) +{ + struct capichat_s *room; + unsigned int roomnumber; + int ret = -1; + + cc_mutex_lock(&chat_lock); + + for (room = chat_list; room != 0; room = room->next) { + if (strcmp(room->name, roomName) == 0) { + roomnumber = room->number; + break; + } + } + if (room != 0) { + for (room = chat_list; room != 0; room = room->next) { + if ((roomnumber == room->number) && (room->i != 0)) { + struct ast_channel *c = room->i->owner; + if (c == 0) { + c = room->i->used; + } + if (c != 0) { + if (strcmp (memberName, c->name) == 0) { + room->info |= PBX_CHAT_MEMBER_INFO_REMOVE; + ret = 0; + } + } + } + } + } + + cc_mutex_unlock(&chat_lock); + + return ret; +} + + diff --git a/chan_capi_chat.h b/chan_capi_chat.h index 50f0ae9..6106919 100644 --- a/chan_capi_chat.h +++ b/chan_capi_chat.h @@ -26,5 +26,6 @@ extern int pbxcli_capi_chatinfo(int fd, int argc, char *argv[]); extern int pbx_capi_chat_command (struct ast_channel *c, char *param); extern int pbx_capi_chat_mute(struct ast_channel *c, char *param); extern int pbx_capi_chat_play(struct ast_channel *c, char *param); +int pbx_capi_chat_remove_user(const char* room, const char* name); #endif diff --git a/chan_capi_cli.c b/chan_capi_cli.c index 916cf86..4db4733 100644 --- a/chan_capi_cli.c +++ b/chan_capi_cli.c @@ -65,6 +65,10 @@ static char show_exec_usage[] = "Usage: " CC_MESSAGE_NAME " info\n" " Exec chancapi command on selected interface (exec interface command parameters).\n"; +static char show_chat_manage_usage[] = +"Usage: " CC_MESSAGE_NAME " chat manage\n" +" Manage chat conference (chat manage room member command parameters).\n"; + #ifndef CC_AST_HAS_VERSION_1_6 static #endif @@ -81,6 +85,7 @@ char chatinfo_usage[] = #define CC_CLI_TEXT_CHATINFO "Show " CC_MESSAGE_BIGNAME " chat info" #define CC_CLI_TEXT_SHOW_RESOURCES "Show used resources" #define CC_CLI_TEXT_EXEC_CAPICOMMAND "Exec command" +#define CC_CLI_TEXT_CHAT_MANAGE "Manager chat conference" /* * helper functions to convert conf value to string @@ -642,6 +647,66 @@ static int pbxcli_capi_exec_capicommand(int fd, int argc, char *argv[]) #endif } +/* + * exec capi command + */ +#ifdef CC_AST_HAS_VERSION_1_6 +static char *pbxcli_capi_chat_manage_capicommand(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +#else +static int pbxcli_capi_chat_manage_capicommand(int fd, int argc, char *argv[]) +#endif +{ + int required_args = 6; + int provided_args; + const char* roomName = NULL; + const char* memberName = NULL; + const char* chatCommand = NULL; + const char* commandParameters = NULL; +#ifdef CC_AST_HAS_VERSION_1_6 + const char * const *cli_argv; +#else + char * const *cli_argv; +#endif + int ret = -1; + +#ifdef CC_AST_HAS_VERSION_1_6 + if (cmd == CLI_INIT) { + e->command = CC_MESSAGE_NAME " chat manage"; + e->usage = show_chat_manage_usage; + return NULL; + } else if (cmd == CLI_GENERATE) { + return NULL; + } + provided_args = a->argc; + cli_argv = a->argv; + if (provided_args < required_args) { + return CLI_SHOWUSAGE; + } +#else + provided_args = argc; + cli_argv = argv; + if (provided_args < required_args) { + return RESULT_SHOWUSAGE; + } +#endif + + roomName = cli_argv[3]; + memberName = cli_argv[4]; + chatCommand = cli_argv[5]; + if (provided_args > required_args) + commandParameters = cli_argv[6]; + + if (strcmp(chatCommand, "remove") == 0) { + ret = pbx_capi_chat_remove_user (roomName, memberName); + } + +#ifdef CC_AST_HAS_VERSION_1_6 + return ((ret == 0) ? CLI_SUCCESS : CLI_FAILURE); +#else + return ((ret == 0) ? RESULT_SUCCESS : RESULT_FAILURE); +#endif +} + /* * define commands */ @@ -659,6 +724,7 @@ static struct ast_cli_entry cc_cli_cmd[] = { #endif AST_CLI_DEFINE(pbxcli_capi_show_resources, CC_CLI_TEXT_SHOW_RESOURCES), AST_CLI_DEFINE(pbxcli_capi_exec_capicommand, CC_CLI_TEXT_EXEC_CAPICOMMAND), + AST_CLI_DEFINE(pbxcli_capi_chat_manage_capicommand, CC_CLI_TEXT_CHAT_MANAGE), }; #else static struct ast_cli_entry cli_info = @@ -683,6 +749,7 @@ static struct ast_cli_entry cli_show_resources = { { CC_MESSAGE_NAME, "show", "resources", NULL }, pbxcli_capi_show_resources, CC_CLI_TEXT_SHOW_RESOURCES, show_resources_usage }; static struct ast_cli_entry cli_exec_capicommand = { { CC_MESSAGE_NAME, "exec", NULL }, pbxcli_capi_exec_capicommand, CC_CLI_TEXT_EXEC_CAPICOMMAND, show_exec_usage }; + { { CC_MESSAGE_NAME, "chat", "manage" NULL }, pbxcli_capi_chat_manage_capicommand, CC_CLI_TEXT_EXEC_CAPICOMMAND, show_chat_manage_usage }; #endif