[svn-commits] mmichelson: branch mmichelson/subscription_abstraction r416418 - /team/mmiche...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Jun 16 13:55:59 CDT 2014
Author: mmichelson
Date: Mon Jun 16 13:55:53 2014
New Revision: 416418
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416418
Log:
Fill in stubs in res_pjsip_pubsub
Modified:
team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c
team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c?view=diff&rev=416418&r1=416417&r2=416418
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c Mon Jun 16 13:55:53 2014
@@ -663,10 +663,6 @@
static int mwi_initial_subscription(struct ast_sip_subscription *sip_sub)
{
- /* It's not obvious here, but the reference(s) to this subscription,
- * once this function exits, is held by the stasis subscription(s)
- * created in mwi_stasis_subscription_alloc()
- */
const char *resource = ast_sip_subscription_get_resource_name(sip_sub);
struct mwi_subscription *sub;
struct ast_sip_endpoint *endpoint = ast_sip_subscription_get_endpoint(sip_sub);
Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c?view=diff&rev=416418&r1=416417&r2=416418
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c Mon Jun 16 13:55:53 2014
@@ -307,6 +307,8 @@
AST_LIST_ENTRY(ast_sip_subscription) next;
/*! List of child subscriptions */
AST_LIST_HEAD_NOLOCK(,ast_sip_subscription) children;
+ /*! Name of resource being subscribed to */
+ char resource[0];
};
static const char *sip_subscription_roles_map[] = {
@@ -764,13 +766,20 @@
static struct ast_sip_subscription *notifier_create_subscription(const struct ast_sip_subscription_handler *handler,
struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
{
- struct ast_sip_subscription *sub = ao2_alloc(sizeof(*sub), subscription_destructor);
+ struct ast_sip_subscription *sub;
pjsip_dialog *dlg;
struct subscription_persistence *persistence;
-
+ size_t resource_size;
+ pjsip_sip_uri *request_uri;
+
+ request_uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
+ resource_size = pj_strlen(&request_uri->user) + 1;
+
+ sub = ao2_alloc(sizeof(*sub) + resource_size, subscription_destructor);
if (!sub) {
return NULL;
}
+ ast_copy_pj_str(sub->resource, &request_uri->user, resource_size);
sub->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
if (!sub->datastores) {
ao2_ref(sub, -1);
@@ -822,7 +831,7 @@
struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,
struct ast_sip_endpoint *endpoint, const char *resource)
{
- struct ast_sip_subscription *sub = ao2_alloc(sizeof(*sub), subscription_destructor);
+ struct ast_sip_subscription *sub = ao2_alloc(sizeof(*sub) + strlen(resource) + 1, subscription_destructor);
pjsip_dialog *dlg;
struct ast_sip_contact *contact;
pj_str_t event;
@@ -830,6 +839,7 @@
if (!sub) {
return NULL;
}
+ strcpy(sub->resource, resource); /* Safe */
sub->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
if (!sub->datastores) {
ao2_ref(sub, -1);
@@ -890,39 +900,7 @@
return sub->serializer;
}
-int ast_sip_subscription_notify(struct ast_sip_subscription *sub, void *notify_data)
-{
- /* XXX STUB */
- return 0;
-}
-
-void ast_sip_subscription_get_local_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
-{
- /* XXX STUB */
-}
-
-void ast_sip_subscription_get_remote_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
-{
- /* XXX STUB */
-}
-
-const char *ast_sip_subscription_get_resource_name(struct ast_sip_subscription *sub)
-{
- /* XXX STUB */
- return NULL;
-}
-
-int ast_sip_subscription_accept(struct ast_sip_subscription *sub, pjsip_rx_data *rdata, int response)
-{
- /* If this is a persistence recreation the subscription has already been accepted */
- if (ast_sip_mod_data_get(rdata->endpt_info.mod_data, pubsub_module.id, MOD_DATA_PERSISTENCE)) {
- return 0;
- }
-
- return pjsip_evsub_accept(sip_subscription_get_evsub(sub), rdata, response, NULL) == PJ_SUCCESS ? 0 : -1;
-}
-
-int ast_sip_subscription_send_request(struct ast_sip_subscription *sub, pjsip_tx_data *tdata)
+static int sip_subscription_send_request(struct ast_sip_subscription *sub, pjsip_tx_data *tdata)
{
struct ast_sip_endpoint *endpoint = ast_sip_subscription_get_endpoint(sub);
int res;
@@ -942,6 +920,72 @@
ao2_cleanup(endpoint);
return res;
+}
+
+int ast_sip_subscription_notify(struct ast_sip_subscription *sub, void *notify_data)
+{
+ struct ast_sip_body body = {
+ .type = ast_sip_subscription_get_body_type(sub),
+ .subtype = ast_sip_subscription_get_body_subtype(sub),
+ };
+ struct ast_str *body_text = ast_str_create(64);
+ pjsip_evsub *evsub = sip_subscription_get_evsub(sub);
+ pjsip_tx_data *tdata;
+
+ if (!body_text) {
+ return -1;
+ }
+
+ if (ast_sip_pubsub_generate_body_content(body.type, body.subtype, notify_data, &body_text)) {
+ ast_free(body_text);
+ return -1;
+ }
+
+ body.body_text = ast_str_buffer(body_text);
+
+ if (pjsip_evsub_notify(evsub, pjsip_evsub_get_state(evsub), NULL, NULL, &tdata) != PJ_SUCCESS) {
+ ast_free(body_text);
+ return -1;
+ }
+ if (ast_sip_add_body(tdata, &body)) {
+ ast_free(body_text);
+ pjsip_tx_data_dec_ref(tdata);
+ return -1;
+ }
+ if (sip_subscription_send_request(sub, tdata)) {
+ ast_free(body_text);
+ pjsip_tx_data_dec_ref(tdata);
+ return -1;
+ }
+
+ return 0;
+}
+
+void ast_sip_subscription_get_local_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
+{
+ pjsip_dialog *dlg = sip_subscription_get_dlg(sub);
+ ast_copy_pj_str(buf, &dlg->local.info_str, size);
+}
+
+void ast_sip_subscription_get_remote_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
+{
+ pjsip_dialog *dlg = sip_subscription_get_dlg(sub);
+ ast_copy_pj_str(buf, &dlg->remote.info_str, size);
+}
+
+const char *ast_sip_subscription_get_resource_name(struct ast_sip_subscription *sub)
+{
+ return sub->resource;
+}
+
+int ast_sip_subscription_accept(struct ast_sip_subscription *sub, pjsip_rx_data *rdata, int response)
+{
+ /* If this is a persistence recreation the subscription has already been accepted */
+ if (ast_sip_mod_data_get(rdata->endpt_info.mod_data, pubsub_module.id, MOD_DATA_PERSISTENCE)) {
+ return 0;
+ }
+
+ return pjsip_evsub_accept(sip_subscription_get_evsub(sub), rdata, response, NULL) == PJ_SUCCESS ? 0 : -1;
}
static void subscription_datastore_destroy(void *obj)
More information about the svn-commits
mailing list