Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pjsip/include/pjsip-simple/presence.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,25 @@ PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf2(char *body, unsigned body_len,
pjsip_pres_status *status);


/**
* This is a utility function to create DIALOG-INFO message body from PJSIP
* presence status.
*
* @param pool The pool to allocate memory for the message body.
* @param status Presence status to be converted into DIALOG-INFO
* message body.
* @param entity The entity ID, which normally is equal to the
* presentity ID publishing this presence info.
* @param p_body Pointer to receive the SIP message body.
*
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pjsip_pres_create_dialog_info(pj_pool_t* pool,
const pjsip_pres_status* status,
const pj_str_t* entity,
pjsip_msg_body** p_body);



/**
* @}
Expand Down
40 changes: 25 additions & 15 deletions pjsip/src/pjsip-simple/dialog_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ static void xml_init_node(pj_pool_t *pool, pj_xml_node *node,
{
pj_list_init(&node->attr_head);
pj_list_init(&node->node_head);
node->name = *name;

if (name) node->name = *name;
else node->name.ptr=NULL, node->name.slen=0;

if (value) pj_strdup(pool, &node->content, value);
else node->content.ptr=NULL, node->content.slen=0;
}
Expand All @@ -68,12 +71,12 @@ static pj_xml_attr* xml_create_attr(pj_pool_t *pool, pj_str_t *name,
PJ_DEF(void) pjsip_dlg_info_remote_construct(pj_pool_t *pool,
pjsip_dlg_info_remote *remote)
{
pj_xml_node *node;
//pj_xml_node *node;

xml_init_node(pool, remote, &REMOTE, NULL);
node = PJ_POOL_ALLOC_T(pool, pj_xml_node);
xml_init_node(pool, node, NULL, NULL);
pj_xml_add_node(remote, node);
//node = PJ_POOL_ALLOC_T(pool, pj_xml_node);
//xml_init_node(pool, node, NULL, NULL);
//pj_xml_add_node(remote, node);
}

PJ_DEF(const pj_str_t *)
Expand Down Expand Up @@ -176,12 +179,12 @@ pjsip_dlg_info_remote_set_target_uri(pj_pool_t *pool,
PJ_DEF(void) pjsip_dlg_info_local_construct(pj_pool_t *pool,
pjsip_dlg_info_local *local)
{
pj_xml_node *node;
//pj_xml_node *node;

xml_init_node(pool, local, &LOCAL, NULL);
node = PJ_POOL_ALLOC_T(pool, pj_xml_node);
xml_init_node(pool, node, NULL, NULL);
pj_xml_add_node(local, node);
//node = PJ_POOL_ALLOC_T(pool, pj_xml_node);
//xml_init_node(pool, node, &EMPTY_STRING, &EMPTY_STRING);
//pj_xml_add_node(local, node);
}

PJ_DEF(const pj_str_t *)
Expand Down Expand Up @@ -290,8 +293,12 @@ pjsip_dlg_info_dialog_construct(pj_pool_t *pool,
pjsip_dlg_info_remote *remote;

xml_init_node(pool, dialog, &DIALOG, NULL);
attr = xml_create_attr(pool, &ID, id);
pj_xml_add_attr(dialog, attr);

if (id) {
attr = xml_create_attr(pool, &ID, id);
pj_xml_add_attr(dialog, attr);
}

local = PJ_POOL_ALLOC_T(pool, pjsip_dlg_info_local);
pjsip_dlg_info_local_construct(pool, local);
pj_xml_add_node(dialog, local);
Expand Down Expand Up @@ -516,20 +523,23 @@ pjsip_dlg_info_dialog_info_construct(pj_pool_t *pool,
{
pj_xml_attr *attr;
pjsip_dlg_info_dialog *dialog;
pj_xml_node* node;

xml_init_node(pool, dialog_info, &DIALOG_INFO, NULL);
attr = xml_create_attr(pool, &VERSION, version);
pj_xml_add_attr(dialog_info, attr);

attr = xml_create_attr(pool, &STATE, state);
pj_xml_add_attr(dialog_info, attr);

attr = xml_create_attr(pool, &ENTITY, entity);
pj_xml_add_attr(dialog_info, attr);

dialog = PJ_POOL_ALLOC_T(pool, pjsip_dlg_info_dialog);
pjsip_dlg_info_local_construct(pool, dialog);
pjsip_dlg_info_dialog_construct(pool, dialog, NULL);
pj_xml_add_node(dialog_info, dialog);

node = PJ_POOL_ALLOC_T(pool, pj_xml_node);
xml_init_node(pool, node, &STATE, state);
pj_xml_add_node(dialog, node);

}

PJ_DEF(const pj_str_t *)
Expand Down
16 changes: 16 additions & 0 deletions pjsip/src/pjsip-simple/presence.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef enum content_type_e
CONTENT_TYPE_NONE,
CONTENT_TYPE_PIDF,
CONTENT_TYPE_XPIDF,
CONTENT_TYPE_DIALOG_INFO,
} content_type_e;

/*
Expand Down Expand Up @@ -133,11 +134,13 @@ static pjsip_evsub_user pres_user =
*/
static const pj_str_t STR_EVENT = { "Event", 5 };
static const pj_str_t STR_PRESENCE = { "presence", 8 };
static const pj_str_t STR_DIALOG = { "dialog", 6 };
static const pj_str_t STR_APPLICATION = { "application", 11 };
static const pj_str_t STR_PIDF_XML = { "pidf+xml", 8};
static const pj_str_t STR_XPIDF_XML = { "xpidf+xml", 9};
static const pj_str_t STR_APP_PIDF_XML = { "application/pidf+xml", 20 };
static const pj_str_t STR_APP_XPIDF_XML = { "application/xpidf+xml", 21 };
static const pj_str_t STR_APP_DIALOG_INFO_XML = { "application/dialog-info+xml", 27 };


/*
Expand Down Expand Up @@ -273,6 +276,10 @@ PJ_DEF(pj_status_t) pjsip_pres_create_uas( pjsip_dialog *dlg,
return PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_BAD_REQUEST);
}
if (pj_stricmp(&event->event_type, &STR_PRESENCE) != 0) {
}
else if (pj_stricmp(&event->event_type, &STR_DIALOG) != 0) {
}
else {
return PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_BAD_EVENT);
}

Expand All @@ -289,6 +296,10 @@ PJ_DEF(pj_status_t) pjsip_pres_create_uas( pjsip_dialog *dlg,
if (pj_stricmp(&accept->values[i], &STR_APP_XPIDF_XML)==0) {
content_type = CONTENT_TYPE_XPIDF;
break;
} else
if (pj_stricmp(&accept->values[i], &STR_APP_DIALOG_INFO_XML) == 0) {
content_type = CONTENT_TYPE_DIALOG_INFO;
break;
}
}

Expand Down Expand Up @@ -499,6 +510,11 @@ static pj_status_t pres_create_msg_body( pjsip_pres *pres,
return pjsip_pres_create_xpidf(tdata->pool, &pres->status,
&entity, &tdata->msg->body);

} else if (pres->content_type == CONTENT_TYPE_DIALOG_INFO) {

return pjsip_pres_create_dialog_info(tdata->pool, &pres->status,
&entity, &tdata->msg->body);

} else {
return PJSIP_SIMPLE_EBADCONTENT;
}
Expand Down
55 changes: 54 additions & 1 deletion pjsip/src/pjsip-simple/presence_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <pj/os.h>
#include <pj/pool.h>
#include <pj/string.h>
#include <pjsip-simple/dialog_info.h>


#define THIS_FILE "presence_body.c"
Expand All @@ -33,7 +34,14 @@
static const pj_str_t STR_APPLICATION = { "application", 11 };
static const pj_str_t STR_PIDF_XML = { "pidf+xml", 8 };
static const pj_str_t STR_XPIDF_XML = { "xpidf+xml", 9 };

static const pj_str_t STR_DIALOG_INFO_XML = { "dialog-info+xml", 15 };
//static pj_str_t STR_TRYING = { "trying", 6 };
//static pj_str_t STR_PROCEEDING = { "proceeding", 10 };
//static pj_str_t STR_EARLY = { "early", 5 };
static pj_str_t STR_CONFIRMED = { "confirmed", 9 };
static pj_str_t STR_TERMINATED = { "terminated", 10 };
static pj_str_t STR_VERSION = { "1.0", 3 };
static pj_str_t STR_EMPTY_STRING = { NULL, 0 };



Expand Down Expand Up @@ -294,3 +302,48 @@ PJ_DEF(pj_status_t) pjsip_pres_parse_xpidf2(char *body, unsigned body_len,
}


/*
* This is a utility function to create DIALOG-INFO message body from PJSIP
* presence status (pjsip_pres_status).
*/
PJ_DEF(pj_status_t) pjsip_pres_create_dialog_info(pj_pool_t* pool,
const pjsip_pres_status* status,
const pj_str_t* entity,
pjsip_msg_body** p_body)
{
pjsip_dlg_info_dialog* dlginfo;
pjsip_msg_body* body;

pjrpid_element rpid = status->info[0].rpid;
pj_bool_t basic_open = status->info[0].basic_open;

const pj_str_t* state;

if (basic_open) {
if (rpid.activity == PJRPID_ACTIVITY_BUSY) {
state = &STR_CONFIRMED;
}
else {
state = &STR_TERMINATED;
}
}
else {
//pjsip_dlg_info_dialog_set_state(pool, dlginfo, &STR_TERMINATED);
state = &STR_TERMINATED;
}

/* Create DIALOG-INFO document. */
dlginfo = pjsip_dlg_info_create(pool, &STR_VERSION, state, entity);

body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body);
body->data = dlginfo;
body->content_type.type = STR_APPLICATION;
body->content_type.subtype = STR_DIALOG_INFO_XML;
body->print_body = &pres_print_body;
body->clone_data = &xml_clone_data;

*p_body = body;

return PJ_SUCCESS;
}

Loading