summaryrefslogtreecommitdiff
path: root/res/res_pjsip/pjsip_options.c
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2015-11-30 21:19:18 -0700
committerGeorge Joseph <george.joseph@fairview5.com>2015-12-02 19:37:09 -0700
commitbd265a90be0f372ce71301ce358e92cdf2a5434d (patch)
tree6e4d137adda0a5aa9909d8164ffb94e509e871ad /res/res_pjsip/pjsip_options.c
parentb5281b74e0572e9ca574098937765647bf2e953a (diff)
res_pjsip: Update logging to show contact->uri in messages
An earlier commit changed the id of dynamic contacts to contain a hash instead of the uri. This patch updates status change logging to show the aor/uri instead of the id. This required adding the aor id to contact and contact_status and adding uri to contact_status. The aor id gets added to contact and contact_status in their allocators and the uri gets added to contact_status in pjsip_options when the contact_status is created or updated. ASTERISK-25598 #close Reported-by: George Joseph Tested-by: George Joseph Change-Id: I56cbec1d2ddbe8461367dd8b6da8a6f47f6fe511
Diffstat (limited to 'res/res_pjsip/pjsip_options.c')
-rw-r--r--res/res_pjsip/pjsip_options.c63
1 files changed, 45 insertions, 18 deletions
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index d55a99587..6762b754e 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -42,7 +42,6 @@ static const char *status_map [] = {
[UNKNOWN] = "Unknown",
[CREATED] = "Created",
[REMOVED] = "Removed",
-
};
static const char *short_status_map [] = {
@@ -65,18 +64,45 @@ const char *ast_sip_get_contact_short_status_label(const enum ast_sip_contact_st
/*!
* \internal
+ * \brief Destroy a ast_sip_contact_status object.
+ */
+static void contact_status_destroy(void * obj)
+{
+ struct ast_sip_contact_status *status = obj;
+
+ ast_string_field_free_memory(status);
+}
+
+/*!
+ * \internal
* \brief Create a ast_sip_contact_status object.
*/
static void *contact_status_alloc(const char *name)
{
- struct ast_sip_contact_status *status = ast_sorcery_generic_alloc(sizeof(*status), NULL);
+ struct ast_sip_contact_status *status = ast_sorcery_generic_alloc(sizeof(*status), contact_status_destroy);
+ char *id = ast_strdupa(name);
+ char *aor = id;
+ char *aor_separator = NULL;
if (!status) {
ast_log(LOG_ERROR, "Unable to allocate ast_sip_contact_status\n");
return NULL;
}
- status->status = UNKNOWN;
+ if (ast_string_field_init(status, 256)) {
+ ast_log(LOG_ERROR, "Unable to allocate ast_sip_contact_status stringfields\n");
+ ao2_cleanup(status);
+ return NULL;
+ }
+
+ /* Dynamic contacts are delimited with ";@" and static ones with "@@" */
+ if ((aor_separator = strstr(id, ";@")) || (aor_separator = strstr(id, "@@"))) {
+ *aor_separator = '\0';
+ }
+ ast_assert(aor_separator != NULL);
+
+ ast_string_field_set(status, aor, aor);
+ status->status = CREATED;
return status;
}
@@ -98,12 +124,12 @@ struct ast_sip_contact_status *ast_res_pjsip_find_or_create_contact_status(const
status = ast_sorcery_alloc(ast_sip_get_sorcery(), CONTACT_STATUS,
ast_sorcery_object_get_id(contact));
if (!status) {
- ast_log(LOG_ERROR, "Unable to create ast_sip_contact_status for contact %s\n",
- contact->uri);
+ ast_log(LOG_ERROR, "Unable to create ast_sip_contact_status for contact %s/%s\n",
+ contact->aor, contact->uri);
return NULL;
}
- status->status = UNKNOWN;
+ ast_string_field_set(status, uri, contact->uri);
status->rtt_start = ast_tv(0, 0);
status->rtt = 0;
@@ -127,8 +153,8 @@ struct ast_sip_contact_status *ast_res_pjsip_find_or_create_contact_status(const
static void update_contact_status(const struct ast_sip_contact *contact,
enum ast_sip_contact_status_type value)
{
- struct ast_sip_contact_status *status;
- struct ast_sip_contact_status *update;
+ RAII_VAR(struct ast_sip_contact_status *, status, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_sip_contact_status *, update, NULL, ao2_cleanup);
status = ast_res_pjsip_find_or_create_contact_status(contact);
if (!status) {
@@ -145,6 +171,7 @@ static void update_contact_status(const struct ast_sip_contact *contact,
return;
}
+ ast_string_field_set(update, uri, contact->uri);
update->last_status = status->status;
update->status = value;
if (update->last_status != update->status) {
@@ -175,9 +202,6 @@ static void update_contact_status(const struct ast_sip_contact *contact,
ast_log(LOG_ERROR, "Unable to update ast_sip_contact_status for contact %s\n",
contact->uri);
}
-
- ao2_ref(status, -1);
- ao2_ref(update, -1);
}
/*!
@@ -187,8 +211,8 @@ static void update_contact_status(const struct ast_sip_contact *contact,
*/
static void init_start_time(const struct ast_sip_contact *contact)
{
- struct ast_sip_contact_status *status;
- struct ast_sip_contact_status *update;
+ RAII_VAR(struct ast_sip_contact_status *, status, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_sip_contact_status *, update, NULL, ao2_cleanup);
status = ast_res_pjsip_find_or_create_contact_status(contact);
if (!status) {
@@ -205,6 +229,7 @@ static void init_start_time(const struct ast_sip_contact *contact)
return;
}
+ ast_string_field_set(status, uri, contact->uri);
update->status = status->status;
update->last_status = status->last_status;
update->rtt = status->rtt;
@@ -214,9 +239,6 @@ static void init_start_time(const struct ast_sip_contact *contact)
ast_log(LOG_ERROR, "Unable to update ast_sip_contact_status for contact %s\n",
contact->uri);
}
-
- ao2_ref(status, -1);
- ao2_ref(update, -1);
}
/*!
@@ -993,6 +1015,9 @@ static int rtt_start_to_str(const void *obj, const intptr_t *args, char **buf)
return 0;
}
+static char status_value_unknown[2];
+static char status_value_created[2];
+
int ast_sip_initialize_sorcery_qualify(void)
{
struct ast_sorcery *sorcery = ast_sip_get_sorcery();
@@ -1006,10 +1031,12 @@ int ast_sip_initialize_sorcery_qualify(void)
return -1;
}
+ snprintf(status_value_unknown, sizeof(status_value_unknown), "%u", UNKNOWN);
ast_sorcery_object_field_register_nodoc(sorcery, CONTACT_STATUS, "last_status",
- "0", OPT_UINT_T, 1, FLDSET(struct ast_sip_contact_status, last_status));
+ status_value_unknown, OPT_UINT_T, 1, FLDSET(struct ast_sip_contact_status, last_status));
+ snprintf(status_value_created, sizeof(status_value_created), "%u", CREATED);
ast_sorcery_object_field_register_nodoc(sorcery, CONTACT_STATUS, "status",
- "0", OPT_UINT_T, 1, FLDSET(struct ast_sip_contact_status, status));
+ status_value_created, OPT_UINT_T, 1, FLDSET(struct ast_sip_contact_status, status));
ast_sorcery_object_field_register_custom_nodoc(sorcery, CONTACT_STATUS, "rtt_start",
"0.0", rtt_start_handler, rtt_start_to_str, NULL, 0, 0);
ast_sorcery_object_field_register_nodoc(sorcery, CONTACT_STATUS, "rtt",