summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-07-21 18:12:51 +0000
committerBenny Prijono <bennylp@teluu.com>2008-07-21 18:12:51 +0000
commitd96688e27a0e7d8c06ac3e399718a217daf6994e (patch)
tree3cbc487e7d28cf7d64f354aaeab6a4fb3967c606
parent76dabd42483b801576cfaa1f0d907e11dbf32c40 (diff)
Ticket #576: Added user data in pjsua account and buddy
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2162 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsua-lib/pjsua.h69
-rw-r--r--pjsip/include/pjsua-lib/pjsua_internal.h1
-rw-r--r--pjsip/src/pjsua-lib/pjsua_acc.c34
-rw-r--r--pjsip/src/pjsua-lib/pjsua_pres.c68
4 files changed, 171 insertions, 1 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index 326f5306..0d6322ea 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -2000,6 +2000,13 @@ PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id,
typedef struct pjsua_acc_config
{
/**
+ * Arbitrary user data to be associated with the newly created account.
+ * Application may set this later with #pjsua_acc_set_user_data() and
+ * retrieve it with #pjsua_acc_get_user_data().
+ */
+ void *user_data;
+
+ /**
* Account priority, which is used to control the order of matching
* incoming/outgoing requests. The higher the number means the higher
* the priority is, and the account will be matched first.
@@ -2396,6 +2403,29 @@ PJ_DECL(pj_status_t) pjsua_acc_add_local(pjsua_transport_id tid,
pjsua_acc_id *p_acc_id);
/**
+ * Set arbitrary data to be associated with the account.
+ *
+ * @param acc_id The account ID.
+ * @param user_data User/application data.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_user_data(pjsua_acc_id acc_id,
+ void *user_data);
+
+
+/**
+ * Retrieve arbitrary data associated with the account.
+ *
+ * @param acc_id The account ID.
+ *
+ * @return The user data. In the case where the account ID is
+ * not valid, NULL is returned.
+ */
+PJ_DECL(void*) pjsua_acc_get_user_data(pjsua_acc_id acc_id);
+
+
+/**
* Delete an account. This will unregister the account from the SIP server,
* if necessary, and terminate server side presence subscriptions associated
* with this account.
@@ -3359,6 +3389,12 @@ typedef struct pjsua_buddy_config
*/
pj_bool_t subscribe;
+ /**
+ * Specify arbitrary application data to be associated with with
+ * the buddy object.
+ */
+ void *user_data;
+
} pjsua_buddy_config;
@@ -3518,6 +3554,16 @@ PJ_DECL(pj_status_t) pjsua_enum_buddies(pjsua_buddy_id ids[],
unsigned *count);
/**
+ * Find the buddy ID with the specified URI.
+ *
+ * @param uri The buddy URI.
+ *
+ * @return The buddy ID, or PJSUA_INVALID_ID if not found.
+ */
+PJ_DECL(pjsua_buddy_id) pjsua_buddy_find(const pj_str_t *uri);
+
+
+/**
* Get detailed buddy info.
*
* @param buddy_id The buddy identification.
@@ -3535,6 +3581,29 @@ PJ_DECL(pj_status_t) pjsua_buddy_get_info(pjsua_buddy_id buddy_id,
pjsua_buddy_info *info);
/**
+ * Set the user data associated with the buddy object.
+ *
+ * @param buddy_id The buddy identification.
+ * @param user_data Arbitrary application data to be associated with
+ * the buddy object.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_buddy_set_user_data(pjsua_buddy_id buddy_id,
+ void *user_data);
+
+
+/**
+ * Get the user data associated with the budy object.
+ *
+ * @param buddy_id The buddy identification.
+ *
+ * @return The application data.
+ */
+PJ_DECL(void*) pjsua_buddy_get_user_data(pjsua_buddy_id buddy_id);
+
+
+/**
* Add new buddy to the buddy list. If presence subscription is enabled
* for this buddy, this function will also start the presence subscription
* session immediately.
diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h
index 7245469c..7e913969 100644
--- a/pjsip/include/pjsua-lib/pjsua_internal.h
+++ b/pjsip/include/pjsua-lib/pjsua_internal.h
@@ -164,6 +164,7 @@ typedef struct pjsua_buddy
{
pj_pool_t *pool; /**< Pool for this buddy. */
unsigned index; /**< Buddy index. */
+ void *user_data; /**< Application data. */
pj_str_t uri; /**< Buddy URI. */
pj_str_t contact; /**< Contact learned from subscrp. */
pj_str_t name; /**< Buddy name. */
diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c
index 892d63c4..a234964c 100644
--- a/pjsip/src/pjsua-lib/pjsua_acc.c
+++ b/pjsip/src/pjsua-lib/pjsua_acc.c
@@ -159,7 +159,6 @@ static pj_status_t initialize_acc(unsigned acc_id)
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 @@ PJ_DEF(pj_status_t) pjsua_acc_add_local( pjsua_transport_id tid,
/*
+ * 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 1bf23098..04632f41 100644
--- a/pjsip/src/pjsua-lib/pjsua_pres.c
+++ b/pjsip/src/pjsua-lib/pjsua_pres.c
@@ -70,6 +70,31 @@ PJ_DEF(unsigned) pjsua_get_buddy_count(void)
/*
+ * 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 @@ PJ_DEF(pj_status_t) pjsua_buddy_get_info( pjsua_buddy_id buddy_id,
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 @@ PJ_DEF(pj_status_t) pjsua_buddy_add( const pjsua_buddy_config *cfg,
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;