Ticket #576: Added user data in pjsua account and buddy
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2162 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c
index 892d63c..a234964 100644
--- a/pjsip/src/pjsua-lib/pjsua_acc.c
+++ b/pjsip/src/pjsua-lib/pjsua_acc.c
@@ -159,7 +159,6 @@
sip_reg_uri = NULL;
}
-
/* Save the user and domain part. These will be used when finding an
* account for incoming requests.
*/
@@ -386,6 +385,39 @@
/*
+ * Set arbitrary data to be associated with the account.
+ */
+PJ_DEF(pj_status_t) pjsua_acc_set_user_data(pjsua_acc_id acc_id,
+ void *user_data)
+{
+ PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc),
+ PJ_EINVAL);
+ PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
+
+ PJSUA_LOCK();
+
+ pjsua_var.acc[acc_id].cfg.user_data = user_data;
+
+ PJSUA_UNLOCK();
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Retrieve arbitrary data associated with the account.
+ */
+PJ_DEF(void*) pjsua_acc_get_user_data(pjsua_acc_id acc_id)
+{
+ PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc),
+ NULL);
+ PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, NULL);
+
+ return pjsua_var.acc[acc_id].cfg.user_data;
+}
+
+
+/*
* Delete account.
*/
PJ_DEF(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id)
diff --git a/pjsip/src/pjsua-lib/pjsua_pres.c b/pjsip/src/pjsua-lib/pjsua_pres.c
index 1bf2309..04632f4 100644
--- a/pjsip/src/pjsua-lib/pjsua_pres.c
+++ b/pjsip/src/pjsua-lib/pjsua_pres.c
@@ -70,6 +70,31 @@
/*
+ * Find buddy.
+ */
+PJ_DEF(pjsua_buddy_id) pjsua_buddy_find(const pj_str_t *uri_str)
+{
+ pj_str_t input;
+ pj_pool_t *pool;
+ pjsip_uri *uri;
+ pjsua_buddy_id buddy_id;
+
+ pool = pjsua_pool_create("buddyfind", 512, 512);
+ pj_strdup_with_null(pool, &input, uri_str);
+
+ uri = pjsip_parse_uri(pool, input.ptr, input.slen, 0);
+ if (!uri)
+ buddy_id = PJSUA_INVALID_ID;
+ else
+ buddy_id = pjsua_find_buddy(uri);
+
+ pj_pool_release(pool);
+
+ return buddy_id;
+}
+
+
+/*
* Check if buddy ID is valid.
*/
PJ_DEF(pj_bool_t) pjsua_buddy_is_valid(pjsua_buddy_id buddy_id)
@@ -190,6 +215,46 @@
return PJ_SUCCESS;
}
+/*
+ * Set the user data associated with the buddy object.
+ */
+PJ_DEF(pj_status_t) pjsua_buddy_set_user_data( pjsua_buddy_id buddy_id,
+ void *user_data)
+{
+ PJ_ASSERT_RETURN(buddy_id>=0 &&
+ buddy_id<(int)PJ_ARRAY_SIZE(pjsua_var.buddy),
+ PJ_EINVAL);
+
+ PJSUA_LOCK();
+
+ pjsua_var.buddy[buddy_id].user_data = user_data;
+
+ PJSUA_UNLOCK();
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Get the user data associated with the budy object.
+ */
+PJ_DEF(void*) pjsua_buddy_get_user_data(pjsua_buddy_id buddy_id)
+{
+ void *user_data;
+
+ PJ_ASSERT_RETURN(buddy_id>=0 &&
+ buddy_id<(int)PJ_ARRAY_SIZE(pjsua_var.buddy),
+ NULL);
+
+ PJSUA_LOCK();
+
+ user_data = pjsua_var.buddy[buddy_id].user_data;
+
+ PJSUA_UNLOCK();
+
+ return user_data;
+}
+
/*
* Reset buddy descriptor.
@@ -289,6 +354,9 @@
if (pjsua_var.buddy[index].port == 0)
pjsua_var.buddy[index].port = 5060;
+ /* Save user data */
+ pjsua_var.buddy[index].user_data = (void*)cfg->user_data;
+
if (p_buddy_id)
*p_buddy_id = index;