[asterisk-commits] mmichelson: branch mmichelson/rls-rlmi r418256 - /team/mmichelson/rls-rlmi/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jul 9 16:45:12 CDT 2014
Author: mmichelson
Date: Wed Jul 9 16:45:08 2014
New Revision: 418256
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418256
Log:
Doing a bit of refactoring.
This isn't anything major, but it cleans up the production
of multipart bodies a bit, so it makes me happier.
Modified:
team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c
Modified: team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c?view=diff&rev=418256&r1=418255&r2=418256
==============================================================================
--- team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c Wed Jul 9 16:45:08 2014
@@ -1488,22 +1488,23 @@
AST_VECTOR(body_part_list, struct body_part *);
-static pj_xml_node *build_rlmi_body(pj_pool_t *pool, struct ast_sip_subscription *sub,
+static pjsip_multipart_part *build_rlmi_body(pj_pool_t *pool, struct ast_sip_subscription *sub,
struct body_part_list *body_parts, int full_state)
{
+ static const pj_str_t rlmi_type = { "application", 11 };
+ static const pj_str_t rlmi_subtype = { "rlmi+xml", 8 };
pj_xml_node *rlmi;
pj_xml_node *name;
+ pj_str_t rlmi_text;
+ pjsip_multipart_part *rlmi_part;
char version_str[32];
char uri[PJSIP_MAX_URL_SIZE];
+ char rlmi_str[2048] = { 0,};
int i;
rlmi = ast_sip_presence_xml_create_node(pool, NULL, "list");
ast_sip_presence_xml_create_attr(pool, rlmi, "xmlns", "urn:ietf:params:xml:ns:rlmi");
- /* XXX This works for the top-level list, but any sub lists will
- * have an incorrect URI. Probably should come up with a scheme
- * like list_name at host for this URI.
- */
ast_sip_subscription_get_local_uri(sub, uri, sizeof(uri));
ast_sip_presence_xml_create_attr(pool, rlmi, "uri", uri);
@@ -1520,20 +1521,31 @@
add_rlmi_resource(pool, rlmi, part->cid, part->resource, part->uri, part->state);
}
- return rlmi;
+ pj_xml_print(rlmi, rlmi_str, sizeof(rlmi_str) - 1, PJ_TRUE);
+ pj_cstr(&rlmi_text, rlmi_str);
+
+ rlmi_part = pjsip_multipart_create_part(pool);
+ rlmi_part->body = pjsip_msg_body_create(pool, &rlmi_type, &rlmi_subtype, &rlmi_text);
+
+ return rlmi_part;
}
static pjsip_msg_body *generate_notify_body(pj_pool_t *pool, struct ast_sip_subscription *root,
int force_full_state);
+static void free_body_part(struct body_part *part)
+{
+ ast_free((char *) part->cid);
+ ast_free(part);
+}
+
static void free_body_parts(struct body_part_list *parts)
{
int i;
for (i = 0; i < AST_VECTOR_SIZE(parts); ++i) {
struct body_part *part = AST_VECTOR_GET(parts, i);
- ast_free((char *) part->cid);
- ast_free(part);
+ free_body_part(part);
}
AST_VECTOR_FREE(parts);
@@ -1561,59 +1573,57 @@
return bp;
}
+static void build_body_part(pj_pool_t *pool, struct ast_sip_subscription *sub,
+ struct body_part_list *parts, int use_full_state)
+{
+ static const pj_str_t cid_name = { "Content-ID", 10 };
+ struct body_part *bp;
+ pjsip_generic_string_hdr *cid;
+ pjsip_msg_body *body;
+ pj_str_t cid_value;
+
+ bp = allocate_body_part(pool, sub);
+ if (!bp) {
+ return;
+ }
+
+ body = generate_notify_body(pool, sub, use_full_state);
+ if (!body) {
+ /* Partial state was requested and the resource has not changed state */
+ free_body_part(bp);
+ return;
+ }
+
+ bp->part = pjsip_multipart_create_part(pool);
+ bp->part->body = body;
+
+ pj_cstr(&cid_value, bp->cid);
+ cid = pjsip_generic_string_hdr_create(pool, &cid_name, &cid_value);
+ pj_list_insert_before(&bp->part->hdr, cid);
+
+ AST_VECTOR_APPEND(parts, bp);
+}
+
static pjsip_msg_body *generate_list_body(pj_pool_t *pool, struct ast_sip_subscription *sub,
int force_full_state)
{
int i;
- pj_xml_node *rlmi;
- char rlmi_str[2048] = { 0,};
+ pjsip_multipart_part *rlmi_part;
pjsip_msg_body *multipart;
- pjsip_media_type media_type = {
- .type = { "multipart", 9 },
- .subtype = { "related", 7 },
- };
- pjsip_multipart_part *rlmi_part;
- static const pj_str_t rlmi_type = { "application", 11};
- static const pj_str_t rlmi_subtype = {"rlmi+xml", 8};
- pj_str_t rlmi_text;
+ pjsip_media_type media_type;
struct body_part_list body_parts;
int use_full_state = force_full_state ? 1 : sub->full_state;
AST_VECTOR_INIT(&body_parts, AST_VECTOR_SIZE(&sub->children));
+ pjsip_media_type_init2(&media_type, "multipart", "related");
multipart = pjsip_multipart_create(pool, &media_type, NULL);
for (i = 0; i < AST_VECTOR_SIZE(&sub->children); ++i) {
- /* XXX This should probably be factored into a function */
- struct ast_sip_subscription *child = AST_VECTOR_GET(&sub->children, i);
- struct body_part *bp = allocate_body_part(pool, child);
- pjsip_generic_string_hdr *cid;
- static const pj_str_t cid_name = { "Content-ID", 10 };
- pjsip_msg_body *body;
- pj_str_t cid_value;
-
- body = generate_notify_body(pool, child, use_full_state);
- if (!body) {
- /* Partial state was requested and the resource has not changed state */
- continue;
- }
-
- bp->part = pjsip_multipart_create_part(pool);
- bp->part->body = body;
-
- pj_cstr(&cid_value, bp->cid);
- cid = pjsip_generic_string_hdr_create(pool, &cid_name, &cid_value);
- pj_list_insert_before(&bp->part->hdr, cid);
-
- AST_VECTOR_APPEND(&body_parts, bp);
+ build_body_part(pool, AST_VECTOR_GET(&sub->children, i), &body_parts, use_full_state);
}
- rlmi = build_rlmi_body(pool, sub, &body_parts, use_full_state);
- pj_xml_print(rlmi, rlmi_str, sizeof(rlmi_str) - 1, PJ_TRUE);
- pj_cstr(&rlmi_text, rlmi_str);
-
- rlmi_part = pjsip_multipart_create_part(pool);
- rlmi_part->body = pjsip_msg_body_create(pool, &rlmi_type, &rlmi_subtype, &rlmi_text);
+ rlmi_part = build_rlmi_body(pool, sub, &body_parts, use_full_state);
pjsip_multipart_add_part(pool, multipart, rlmi_part);
for (i = 0; i < AST_VECTOR_SIZE(&body_parts); ++i) {
More information about the asterisk-commits
mailing list