summaryrefslogtreecommitdiff
path: root/main/presencestate.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2015-06-08 09:44:04 -0500
committerKevin Harwell <kharwell@digium.com>2015-06-08 09:44:04 -0500
commit53c1126090733d8d4e6ee06e2ef92dc98bb0f374 (patch)
treef9597ec0362307ee798469749c1d9d2aeff53e22 /main/presencestate.c
parent8785d0ccbfa1959d1ba6be8769e9d5356f3fef32 (diff)
AMI: Escape string values.
So this issue is a bit complicated. Since it is possible to pass values to AMI that contain a '\r\n' (or other similar sequences) these values need to be escaped. One way to solve this is to escape the values and then pass the escaped values to the AMI variable parameter string building function. However, this puts the onus on the pre-build function to escape all string values. This potentially requires a fair amount of changes along with a lot of string allocations/freeing for all values. Surely there is a way to push this complexity down a level into the string building function itself? This of course is possible, but ends up requiring a way to distinguish between strings that need to be escaped and those that don't. The best way to handle this is by introducing a new format specifier in the format string. For instance a %s (no escape) and %S (escape). However, that is a bit weird and unexpected. So faced with those possibilities this patch implements a limited version of the first option. Instead of attempting to escape all string values this patch only escapes those values that make sense. This approach limits the number of changes and doesn't suffer from the odd format specifier problem. ASTERISK-24934 #close Reported by: warren smith Change-Id: Ib55a5b84fe0481b0f2caaaab68c566f392c0aac0
Diffstat (limited to 'main/presencestate.c')
-rw-r--r--main/presencestate.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/main/presencestate.c b/main/presencestate.c
index 399613e39..3be2ebeed 100644
--- a/main/presencestate.c
+++ b/main/presencestate.c
@@ -522,14 +522,23 @@ int ast_presence_state_engine_init(void)
static struct ast_manager_event_blob *presence_state_to_ami(struct stasis_message *msg)
{
struct ast_presence_state_message *presence_state = stasis_message_data(msg);
+ struct ast_manager_event_blob *res;
- return ast_manager_event_blob_create(EVENT_FLAG_CALL, "PresenceStateChange",
+ char *subtype = ast_escape_c_alloc(presence_state->subtype);
+ char *message = ast_escape_c_alloc(presence_state->message);
+
+ res = ast_manager_event_blob_create(EVENT_FLAG_CALL, "PresenceStateChange",
"Presentity: %s\r\n"
"Status: %s\r\n"
"Subtype: %s\r\n"
"Message: %s\r\n",
presence_state->provider,
ast_presence_state2str(presence_state->state),
- presence_state->subtype,
- presence_state->message);
+ subtype ?: "",
+ message ?: "");
+
+ ast_free(subtype);
+ ast_free(message);
+
+ return res;
}