106 char *subtype =
NULL;
108 int base64encode = 0;
125 ast_log(
LOG_WARNING,
"PRESENCE_STATE reading requires both presence provider and presence field arguments. \n");
152 }
else if (!strcasecmp(
args.field,
"value")) {
171 state_str =
strsep(&data,
",");
184 if (!(*subtype =
strsep(&data,
","))) {
189 if (!(*message =
strsep(&data,
","))) {
194 if (!(*options =
strsep(&data,
","))) {
209 size_t len = strlen(
"CustomPresence:");
215 if (strncasecmp(data,
"CustomPresence:", len)) {
216 ast_log(
LOG_WARNING,
"The PRESENCE_STATE function can only set CustomPresence: presence providers.\n");
225 if (
parse_data(args, &state, &subtype, &message, &options)) {
232 if (strchr(options,
'e')) {
234 char decoded_subtype[256] = { 0, };
235 char decoded_message[256] = { 0, };
237 ast_base64decode((
unsigned char *) decoded_subtype, subtype,
sizeof(decoded_subtype) -1);
238 ast_base64decode((
unsigned char *) decoded_message, message,
sizeof(decoded_message) -1);
260 if (
parse_data(buf, &state, &_subtype, &_message, &_options)) {
264 if ((strchr(_options,
'e'))) {
270 memset(tmp, 0,
sizeof(tmp));
278 memset(tmp, 0,
sizeof(tmp));
290 .
name =
"PRESENCE_STATE",
301 e->
command =
"presencestate list";
303 "Usage: presencestate list\n" 304 " List all custom presence states that have been set by using\n" 305 " the PRESENCE_STATE dialplan function.\n";
316 "---------------------------------------------------------------------\n" 317 "--- Custom Presence States ------------------------------------------\n" 318 "---------------------------------------------------------------------\n" 323 ast_cli(a->
fd,
"No custom presence states defined\n");
326 for (; db_entry; db_entry = db_entry->
next) {
327 const char *object_name = strrchr(db_entry->
key,
'/') + 1;
328 char state_info[1301];
335 if (
parse_data(state_info, &state, &subtype, &message, &options)) {
340 if (object_name <= (
const char *) 1) {
343 ast_cli(a->
fd,
"--- Name: 'CustomPresence:%s'\n" 345 " --- Subtype: '%s'\n" 346 " --- Message: '%s'\n" 347 " --- Base64 Encoded: '%s'\n" 359 "---------------------------------------------------------------------\n" 360 "---------------------------------------------------------------------\n" 369 const char *dev, *
state, *full_dev;
378 e->
command =
"presencestate change";
380 "Usage: presencestate change <entity> <state>[,<subtype>[,message[,options]]]\n" 381 " Change a custom presence to a new state.\n" 382 " The possible values for the state are:\n" 383 "NOT_SET | UNAVAILABLE | AVAILABLE | AWAY | XA | CHAT | DND\n" 384 "Optionally, a custom subtype and message may be provided, along with any options\n" 385 "accepted by func_presencestate. If the subtype or message provided contain spaces,\n" 386 "be sure to enclose the data in quotation marks (\"\")\n" 389 " presencestate change CustomPresence:mystate1 AWAY\n" 390 " presencestate change CustomPresence:mystate1 AVAILABLE\n" 391 " presencestate change CustomPresence:mystate1 \"Away,upstairs,eating lunch\"\n" 396 static const char *
const cmds[] = {
"NOT_SET",
"UNAVAILABLE",
"AVAILABLE",
"AWAY",
397 "XA",
"CHAT",
"DND",
NULL };
411 len = strlen(
"CustomPresence:");
415 if (strncasecmp(dev,
"CustomPresence:", len)) {
416 ast_cli(a->
fd,
"The presencestate command can only be used to set 'CustomPresence:' presence state!\n");
426 if (
parse_data(args, &state_val, &subtype, &message, &options)) {
434 ast_cli(a->
fd,
"Changing %s to %s\n", dev, args);
448 #ifdef TEST_FRAMEWORK 519 {
"away,down the hall",
526 {
"away,down the hall,Quarterly financial meeting",
529 "Quarterly financial meeting",
533 {
"away,,Quarterly financial meeting",
536 "Quarterly financial meeting",
547 {
"away,down the hall,,e",
554 {
"away,down the hall,Quarterly financial meeting,e",
557 "Quarterly financial meeting",
561 {
"away,,Quarterly financial meeting,e",
564 "Quarterly financial meeting",
572 info->name =
"parse_valid_presence_data";
573 info->category =
"/funcs/func_presence/";
574 info->summary =
"PRESENCESTATE parsing test";
576 "Ensure that parsing function accepts proper values, and gives proper outputs";
589 parse_result =
parse_data(parse_string, &state, &subtype, &message, &options);
590 if (parse_result == -1) {
595 if (tests[i].
outputs.value != state ||
596 strcmp(tests[i].
outputs.subtype, subtype) ||
597 strcmp(tests[i].
outputs.message, message) ||
598 strcmp(tests[i].
outputs.options, options)) {
630 info->name =
"parse_invalid_presence_data";
631 info->category =
"/funcs/func_presence/";
632 info->summary =
"PRESENCESTATE parsing test";
634 "Ensure that parsing function rejects improper values";
647 parse_result =
parse_data(parse_string, &state, &subtype, &message, &options);
648 if (parse_result == 0) {
660 #define PRES_STATE "away" 661 #define PRES_SUBTYPE "down the hall" 662 #define PRES_MESSAGE "Quarterly financial meeting" 707 char *out_state,
size_t out_state_size,
708 char *out_subtype,
size_t out_subtype_size,
709 char *out_message,
size_t out_message_size)
720 snprintf(pres,
sizeof(pres),
"%s,%s,%s", state, subtype, message);
722 snprintf(pres,
sizeof(pres),
"%s,%s,%s,%s", state, subtype, message, options);
725 if (
presence_write(
NULL,
"PRESENCESTATE",
"CustomPresence:TestPresenceStateChange", pres)) {
733 ast_copy_string(out_subtype, cb_data->presence_state->subtype, out_subtype_size);
734 ast_copy_string(out_message, cb_data->presence_state->message, out_message_size);
737 ast_db_del(
"CustomPresence",
"TestPresenceStateChange");
745 char out_subtype[32];
746 char out_message[32];
750 info->name =
"test_presence_state_change";
751 info->category =
"/funcs/func_presence/";
752 info->summary =
"presence state change subscription";
754 "Ensure that presence state changes are communicated to subscribers";
761 out_state,
sizeof(out_state),
762 out_subtype,
sizeof(out_subtype),
783 char out_subtype[32];
784 char out_message[32];
785 char encoded_subtype[64];
786 char encoded_message[64];
790 info->name =
"test_presence_state_base64_encode";
791 info->category =
"/funcs/func_presence/";
792 info->summary =
"presence state base64 encoding";
794 "Ensure that base64-encoded presence state is stored base64-encoded but\n" 795 "is presented to consumers decoded.";
805 out_state,
sizeof(out_state),
806 out_subtype,
sizeof(out_subtype),
812 strcmp(out_subtype, PRES_SUBTYPE) ||
813 strcmp(out_message, PRES_MESSAGE)) {
816 PRES_SUBTYPE, out_subtype,
817 PRES_MESSAGE, out_message);
833 #ifdef TEST_FRAMEWORK 850 for (; db_entry; db_entry = db_entry->
next) {
851 const char *dev_name = strrchr(db_entry->
key,
'/') + 1;
855 if (dev_name <= (
const char *) 1) {
869 #ifdef TEST_FRAMEWORK
static struct ast_custom_function presence_function
enum sip_cc_notify_state state
static struct test_cb_data * test_cb_data_alloc(void)
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
int ast_sem_destroy(struct ast_sem *sem)
Destroy a semaphore.
Asterisk main include file. File version handling, generic pbx functions.
struct ast_presence_state_message * presence_state
static const char astdb_family[]
static int parse_data(char *data, enum ast_presence_state *state, char **subtype, char **message, char **options)
int ast_presence_state_changed_literal(enum ast_presence_state state, const char *subtype, const char *message, const char *presence_provider)
Notify the world that a presence provider state changed.
AST_TEST_DEFINE(test_valid_parse_data)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
enum ast_presence_state ast_presence_state_val(const char *val)
Convert presence state from text to integer value.
int ast_sem_post(struct ast_sem *sem)
Increments the semaphore, unblocking a waiter if necessary.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
descriptor for a cli entry.
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
#define AST_TEST_REGISTER(cb)
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
enum ast_presence_state ast_presence_state_nocache(const char *presence_provider, char **subtype, char **message)
Asks a presence state provider for the current presence state, bypassing the event cache...
Stasis message payload representing a presence state update.
#define ast_strdup(str)
A wrapper for strdup()
void ast_cli(int fd, const char *fmt,...)
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int args
This gets set in ast_cli_register()
#define ast_strlen_zero(foo)
static enum ast_presence_state custom_presence_callback(const char *data, char **subtype, char **message)
char * ast_cli_complete(const char *word, const char *const choices[], int pos)
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
struct ast_db_entry * next
General Asterisk PBX channel definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_test_status_update(a, b, c...)
static char * handle_cli_presencestate_list(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Data structure associated with a custom dialplan function.
static void test_sub(struct ast_event *event)
int ast_presence_state_prov_add(const char *label, ast_presence_state_prov_cb_type callback)
Add presence state provider.
#define ao2_ref(o, delta)
#define ast_strdupa(s)
duplicate a string in memory from the stack
static enum ast_test_result_state presence_change_common(struct ast_test *test, const char *state, const char *subtype, const char *message, const char *options, char *out_state, size_t out_state_size, char *out_subtype, size_t out_subtype_size, char *out_message, size_t out_message_size)
A set of macros to manage forward-linked lists.
Core PBX routines and definitions.
int ast_sem_wait(struct ast_sem *sem)
Decrements the semaphore.
#define stasis_subscribe(topic, callback, data)
Presence state management.
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define AST_TEST_UNREGISTER(cb)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int presence_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
struct test_string::@215 outputs
static int load_module(void)
static void parse(struct mgcp_request *req)
static int presence_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
#define ast_calloc(num, len)
A wrapper for calloc()
int ast_sem_init(struct ast_sem *sem, int pshared, unsigned int value)
Initialize a semaphore.
int ast_presence_state_prov_del(const char *label)
Remove presence state provider.
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
char * strsep(char **str, const char *delims)
Standard Command Line Interface.
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
struct stasis_message_type * ast_presence_state_message_type(void)
Get presence state message type.
static int unload_module(void)
struct stasis_forward * sub
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
static char * handle_cli_presencestate_change(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define AST_CLI_YESNO(x)
Return Yes or No depending on the argument.
int ast_presence_state_changed(enum ast_presence_state state, const char *subtype, const char *message, const char *fmt,...)
Notify the world that a presence provider state changed.
struct stasis_topic * ast_presence_state_topic_all(void)
Get presence state topic.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static void test_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Persistant data storage (akin to *doze registry)
static struct prometheus_metrics_provider provider
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.
#define AST_APP_ARG(name)
Define an application argument.
static struct ast_cli_entry cli_funcpresencestate[]
static void test_cb_data_destroy(struct test_cb_data *cb_data)