[svn-commits] mmichelson: branch mmichelson/subscription_abstraction r416752 - /team/mmiche...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Jun 19 15:22:47 CDT 2014
Author: mmichelson
Date: Thu Jun 19 15:22:44 2014
New Revision: 416752
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416752
Log:
Address Matt's comments on reviewboard:
* Add doxygen for the real/virtual enum
* Add URI scheme checking for PUBLISH and SUBSCRIBE requests.
I also made changes to use a PJSIP macro to check if a SIP response was
in a certain class.
Modified:
team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
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=416752&r1=416751&r2=416752
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c Thu Jun 19 15:22:44 2014
@@ -273,8 +273,27 @@
struct ast_sip_subscription *parent;
};
+/*!
+ * \brief Discriminator between real and virtual subscriptions
+ */
enum sip_subscription_type {
+ /*!
+ * \brief a "real" subscription.
+ *
+ * Real subscriptions are at the root of a tree of subscriptions.
+ * A real subscription has a corresponding SIP subscription in the
+ * PJSIP stack.
+ */
SIP_SUBSCRIPTION_REAL,
+ /*!
+ * \brief a "virtual" subscription.
+ *
+ * Virtual subscriptions are the descendents of real subscriptions
+ * in a tree of subscriptions. Virtual subscriptions do not have
+ * a corresponding SIP subscription in the PJSIP stack. Instead,
+ * when a state change happens on a virtual subscription, the
+ * state change is indicated to the virtual subscription's parent.
+ */
SIP_SUBSCRIPTION_VIRTUAL,
};
@@ -547,7 +566,7 @@
pubsub_module.id, MOD_DATA_PERSISTENCE, persistence);
resp = handler->notifier->new_subscribe(endpoint, resource);
- if (resp >= 200 && resp < 300) {
+ if (!PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {
sub = notifier_create_subscription(handler, endpoint, &rdata, resource, generator);
sub->persistence = ao2_bump(persistence);
subscription_persistence_update(sub, &rdata);
@@ -1299,7 +1318,8 @@
struct ast_sip_subscription *sub;
struct ast_sip_pubsub_body_generator *generator;
char *resource;
- struct pjsip_sip_uri *request_uri;
+ pjsip_uri *request_uri;
+ pjsip_sip_uri *request_uri_sip;
size_t resource_size;
int resp;
@@ -1312,10 +1332,21 @@
return PJ_TRUE;
}
- request_uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
- resource_size = pj_strlen(&request_uri->user) + 1;
+ request_uri = rdata->msg_info.msg->line.req.uri;
+
+ if (!PJSIP_URI_SCHEME_IS_SIP(request_uri) && !PJSIP_URI_SCHEME_IS_SIPS(request_uri)) {
+ char uri_str[PJSIP_MAX_URL_SIZE];
+
+ pjsip_uri_print(PJSIP_URI_IN_REQ_URI, request_uri, uri_str, sizeof(uri_str));
+ ast_log(LOG_WARNING, "Request URI '%s' is not a sip: or sips: URI.\n", uri_str);
+ pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 416, NULL, NULL, NULL);
+ return PJ_TRUE;
+ }
+
+ request_uri_sip = pjsip_uri_get_uri(request_uri);
+ resource_size = pj_strlen(&request_uri_sip->user) + 1;
resource = alloca(resource_size);
- ast_copy_pj_str(resource, &request_uri->user, resource_size);
+ ast_copy_pj_str(resource, &request_uri_sip->user, resource_size);
expires_header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, rdata->msg_info.msg->hdr.next);
@@ -1347,7 +1378,7 @@
}
resp = handler->notifier->new_subscribe(endpoint, resource);
- if (resp < 200 || resp >= 300) {
+ if (!PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, resp, NULL, NULL, NULL);
return PJ_TRUE;
}
@@ -1360,7 +1391,7 @@
subscription_persistence_update(sub, rdata);
sip_subscription_accept(sub, rdata, resp);
if (handler->notifier->notify_required(sub, AST_SIP_SUBSCRIPTION_NOTIFY_REASON_STARTED)) {
- pjsip_evsub_terminate(sip_subscription_get_evsub, PJ_TRUE);
+ pjsip_evsub_terminate(sip_subscription_get_evsub(sub), PJ_TRUE);
}
}
@@ -1494,13 +1525,25 @@
struct ast_sip_publication *publication;
char *resource;
size_t resource_size;
- pjsip_sip_uri *request_uri;
+ pjsip_uri *request_uri;
+ pjsip_sip_uri *request_uri_sip;
int resp;
- request_uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
- resource_size = pj_strlen(&request_uri->user) + 1;
+ request_uri = rdata->msg_info.msg->line.req.uri;
+
+ if (!PJSIP_URI_SCHEME_IS_SIP(request_uri) && !PJSIP_URI_SCHEME_IS_SIPS(request_uri)) {
+ char uri_str[PJSIP_MAX_URL_SIZE];
+
+ pjsip_uri_print(PJSIP_URI_IN_REQ_URI, request_uri, uri_str, sizeof(uri_str));
+ ast_log(LOG_WARNING, "Request URI '%s' is not a sip: or sips: URI.\n", uri_str);
+ pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 416, NULL, NULL, NULL);
+ return NULL;
+ }
+
+ request_uri_sip = pjsip_uri_get_uri(request_uri);
+ resource_size = pj_strlen(&request_uri_sip->user) + 1;
resource = alloca(resource_size);
- ast_copy_pj_str(resource, &request_uri->user, resource_size);
+ ast_copy_pj_str(resource, &request_uri_sip->user, resource_size);
resp = handler->new_publication(endpoint, resource);
More information about the svn-commits
mailing list