[svn-commits] mmichelson: branch mmichelson/trunk-digiumphones r361325 - /team/mmichelson/t...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Apr 5 15:14:31 CDT 2012
Author: mmichelson
Date: Thu Apr 5 15:14:27 2012
New Revision: 361325
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=361325
Log:
Add CLI functions to func_presencestate.
The idea here is to bring presence state in line with
the facilities offered by its device state counterpart.
This adds two CLI commands.
"presencestate list" lists all current CustomPresence
entities.
"presencestate change" changes the presence state of
a CustomPresence entity.
Modified:
team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c
Modified: team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c?view=diff&rev=361325&r1=361324&r2=361325
==============================================================================
--- team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c (original)
+++ team/mmichelson/trunk-digiumphones/funcs/func_presencestate.c Thu Apr 5 15:14:27 2012
@@ -272,6 +272,145 @@
.write = presence_write,
};
+static char *handle_cli_presencestate_list(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ast_db_entry *db_entry, *db_tree;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "presencestate list";
+ e->usage =
+ "Usage: presencestate list\n"
+ " List all custom presence states that have been set by using\n"
+ " the PRESENCE_STATE dialplan function.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != e->args)
+ return CLI_SHOWUSAGE;
+
+ ast_cli(a->fd, "\n"
+ "---------------------------------------------------------------------\n"
+ "--- Custom Presence States ------------------------------------------\n"
+ "---------------------------------------------------------------------\n"
+ "---\n");
+
+ db_entry = db_tree = ast_db_gettree(astdb_family, NULL);
+ for (; db_entry; db_entry = db_entry->next) {
+ const char *object_name = strrchr(db_entry->key, '/') + 1;
+ char state_info[1024];
+ int state;
+ char *subtype;
+ char *message;
+ char *options;
+
+ ast_copy_string(state_info, db_entry->data, sizeof(state_info));
+ parse_data(state_info, &state, &subtype, &message, &options);
+
+ if (object_name <= (const char *) 1)
+ continue;
+ ast_cli(a->fd, "--- Name: 'CustomPresence:%s'\n"
+ " --- State: '%s'\n"
+ " --- Subtype: '%s'\n"
+ " --- Message: '%s'\n"
+ " --- Base64 Encoded: '%s'\n"
+ "---\n",
+ object_name,
+ ast_presence_state2str(state),
+ subtype,
+ message,
+ AST_CLI_YESNO(strchr(options, 'e')));
+ }
+ ast_db_freetree(db_tree);
+ db_tree = NULL;
+
+ ast_cli(a->fd,
+ "---------------------------------------------------------------------\n"
+ "---------------------------------------------------------------------\n"
+ "\n");
+
+ return CLI_SUCCESS;
+}
+
+static char *handle_cli_presencestate_change(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ size_t len;
+ const char *dev, *state, *full_dev;
+ int state_val;
+ char *message;
+ char *subtype;
+ char *options;
+ char *args;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "presencestate change";
+ e->usage =
+ "Usage: presencestate change <entity> <state>\n"
+ " Change a custom presence to a new state.\n"
+ " The possible values for the state are:\n"
+ "NOT_SET | UNAVAILABLE | AVAILABLE | AWAY | XA | CHAT | DND\n"
+ "\n"
+ "Examples:\n"
+ " presencestate change CustomPresence:mystate1 AWAY\n"
+ " presencestate change CustomPresence:mystate1 AVAILABLE\n"
+ " \n";
+ return NULL;
+ case CLI_GENERATE:
+ {
+ static const char * const cmds[] = { "NOT_SET", "UNAVAILABLE", "AVAILABLE", "AWAY",
+ "XA", "CHAT", "DND", NULL };
+
+ if (a->pos == e->args + 1)
+ return ast_cli_complete(a->word, cmds, a->n);
+
+ return NULL;
+ }
+ }
+
+ if (a->argc != e->args + 2) {
+ return CLI_SHOWUSAGE;
+ }
+
+ len = strlen("CustomPresence:");
+ full_dev = dev = a->argv[e->args];
+ state = a->argv[e->args + 1];
+
+ if (strncasecmp(dev, "CustomPresence:", len)) {
+ ast_cli(a->fd, "The presencestate command can only be used to set 'CustomPresence:' presence state!\n");
+ return CLI_FAILURE;
+ }
+
+ dev += len;
+ if (ast_strlen_zero(dev)) {
+ return CLI_SHOWUSAGE;
+ }
+
+ args = ast_strdupa(state);
+ if (parse_data(args, &state_val, &subtype, &message, &options)) {
+ return CLI_SHOWUSAGE;
+ }
+
+ if (state_val == AST_PRESENCE_NOT_SET) {
+ return CLI_SHOWUSAGE;
+ }
+
+ ast_cli(a->fd, "Changing %s to %s\n", dev, args);
+
+ ast_db_put(astdb_family, dev, state);
+
+ ast_presence_state_changed(full_dev);
+
+ return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_funcpresencestate[] = {
+ AST_CLI_DEFINE(handle_cli_presencestate_list, "List currently know custom presence states"),
+ AST_CLI_DEFINE(handle_cli_presencestate_change, "Change a custom presence state"),
+};
+
#ifdef TEST_FRAMEWORK
struct test_string {
@@ -565,6 +704,7 @@
res |= ast_custom_function_unregister(&presence_function);
res |= ast_presence_state_prov_del("CustomPresence");
+ res |= ast_cli_unregister_multiple(cli_funcpresencestate, ARRAY_LEN(cli_funcpresencestate));
#ifdef TEST_FRAMEWORK
AST_TEST_UNREGISTER(test_valid_parse_data);
AST_TEST_UNREGISTER(test_invalid_parse_data);
@@ -579,6 +719,7 @@
res |= ast_custom_function_register(&presence_function);
res |= ast_presence_state_prov_add("CustomPresence", custom_presence_callback);
+ res |= ast_cli_register_multiple(cli_funcpresencestate, ARRAY_LEN(cli_funcpresencestate));
#ifdef TEST_FRAMEWORK
AST_TEST_REGISTER(test_valid_parse_data);
AST_TEST_REGISTER(test_invalid_parse_data);
More information about the svn-commits
mailing list