[asterisk-commits] mmichelson: branch mmichelson/rls-rlmi r418326 - /team/mmichelson/rls-rlmi/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 10 11:11:43 CDT 2014
Author: mmichelson
Date: Thu Jul 10 11:11:37 2014
New Revision: 418326
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418326
Log:
Add a Content-ID header to the RLMI body part.
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=418326&r1=418325&r2=418326
==============================================================================
--- team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c Thu Jul 10 11:11:37 2014
@@ -1474,14 +1474,21 @@
return res;
}
-static void add_rlmi_resource(pj_pool_t *pool, pj_xml_node *rlmi, const char *cid,
+static void add_rlmi_resource(pj_pool_t *pool, pj_xml_node *rlmi, const pjsip_generic_string_hdr *cid,
const char *resource_name, const pjsip_sip_uri *resource_uri, pjsip_evsub_state state)
{
+ static pj_str_t cid_name = { "cid", 3 };
pj_xml_node *resource;
pj_xml_node *name;
pj_xml_node *instance;
+ pj_xml_attr *cid_attr;
char id[AST_UUID_STR_LEN];
char uri[PJSIP_MAX_URL_SIZE];
+
+ pj_str_t cid_stripped = {
+ .ptr = cid->hvalue.ptr + 1,
+ .slen = cid->hvalue.slen - 2,
+ };
resource = ast_sip_presence_xml_create_node(pool, rlmi, "resource");
name = ast_sip_presence_xml_create_node(pool, resource, "name");
@@ -1496,11 +1503,12 @@
ast_sip_presence_xml_create_attr(pool, instance, "id", id);
ast_sip_presence_xml_create_attr(pool, instance, "state",
state == PJSIP_EVSUB_STATE_TERMINATED ? "terminated" : "active");
- ast_sip_presence_xml_create_attr(pool, instance, "cid", ast_strip_quoted(ast_strdupa(cid), "<", ">"));
+ cid_attr = pj_xml_attr_new(pool, &cid_name, &cid_stripped);
+ pj_xml_add_attr(instance, cid_attr);
}
struct body_part {
- char *cid;
+ pjsip_generic_string_hdr *cid;
const char *resource;
pjsip_sip_uri *uri;
pjsip_evsub_state state;
@@ -1508,6 +1516,25 @@
};
AST_VECTOR(body_part_list, struct body_part *);
+
+static pjsip_generic_string_hdr *generate_content_id_hdr(pj_pool_t *pool,
+ const struct ast_sip_subscription *sub)
+{
+ static const pj_str_t cid_name = { "Content-ID", 10 };
+ pjsip_generic_string_hdr *cid;
+ char id[AST_UUID_STR_LEN];
+ size_t alloc_size;
+ pj_str_t cid_value;
+
+ alloc_size = sizeof(id) + pj_strlen(&sub->uri->host) + 3;
+ cid_value.ptr = pj_pool_alloc(pool, alloc_size);
+ cid_value.slen = sprintf(cid_value.ptr, "<%s@%.*s>",
+ ast_uuid_generate_str(id, sizeof(id)),
+ (int) pj_strlen(&sub->uri->host), pj_strbuf(&sub->uri->host));
+ cid = pjsip_generic_string_hdr_create(pool, &cid_name, &cid_value);
+
+ return cid;
+}
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)
@@ -1521,6 +1548,7 @@
char version_str[32];
char uri[PJSIP_MAX_URL_SIZE];
char rlmi_str[2048] = { 0,};
+ pjsip_generic_string_hdr *cid;
int i;
rlmi = ast_sip_presence_xml_create_node(pool, NULL, "list");
@@ -1548,6 +1576,9 @@
rlmi_part = pjsip_multipart_create_part(pool);
rlmi_part->body = pjsip_msg_body_create(pool, &rlmi_type, &rlmi_subtype, &rlmi_text);
+ cid = generate_content_id_hdr(pool, sub);
+ pj_list_insert_before(&rlmi_part->hdr, cid);
+
return rlmi_part;
}
@@ -1556,7 +1587,6 @@
static void free_body_part(struct body_part *part)
{
- ast_free(part->cid);
ast_free(part);
}
@@ -1575,20 +1605,13 @@
static struct body_part *allocate_body_part(pj_pool_t *pool, const struct ast_sip_subscription *sub)
{
struct body_part *bp;
- char id[AST_UUID_STR_LEN];
bp = ast_calloc(1, sizeof(*bp));
if (!bp) {
return NULL;
}
- ast_asprintf(&bp->cid, "<%s@%.*s>", ast_uuid_generate_str(id, sizeof(id)),
- (int) pj_strlen(&sub->uri->host), pj_strbuf(&sub->uri->host));
- if (!bp->cid) {
- ast_free(bp);
- return NULL;
- }
-
+ bp->cid = generate_content_id_hdr(pool, sub);
bp->resource = sub->resource;
bp->state = sub->subscription_state;
bp->uri = sub->uri;
@@ -1599,11 +1622,8 @@
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) {
@@ -1619,10 +1639,7 @@
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);
+ pj_list_insert_before(&bp->part->hdr, bp->cid);
AST_VECTOR_APPEND(parts, bp);
}
More information about the asterisk-commits
mailing list