PJ_DEF(pj_status_t) pjxpidf_set_status(pjxpidf_pres *pres, pj_bool_t online_status) { pj_xml_node *atom; pj_xml_node *addr; pj_xml_node *status; pj_xml_attr *attr; atom = pj_xml_find_node(pres, &STR_ATOM); if (!atom) { pj_assert(0); return -1; } addr = pj_xml_find_node(atom, &STR_ADDRESS); if (!addr) { pj_assert(0); return -1; } status = pj_xml_find_node(addr, &STR_STATUS); if (!status) { pj_assert(0); return -1; } attr = pj_xml_find_attr(status, &STR_STATUS, NULL); if (!attr) { pj_assert(0); return -1; } attr->value = ( online_status ? STR_OPEN : STR_CLOSED ); return 0; }
PJ_DEF(pj_bool_t) pjxpidf_get_status(pjxpidf_pres *pres) { pj_xml_node *atom; pj_xml_node *addr; pj_xml_node *status; pj_xml_attr *attr; atom = pj_xml_find_node(pres, &STR_ATOM); if (!atom) { pj_assert(0); return PJ_FALSE; } addr = pj_xml_find_node(atom, &STR_ADDRESS); if (!addr) { pj_assert(0); return PJ_FALSE; } status = pj_xml_find_node(addr, &STR_STATUS); if (!status) { pj_assert(0); return PJ_FALSE; } attr = pj_xml_find_attr(status, &STR_STATUS, NULL); if (!attr) { pj_assert(0); return PJ_FALSE; } return pj_stricmp(&attr->value, &STR_OPEN)==0 ? PJ_TRUE : PJ_FALSE; }
PJ_DEF(pj_status_t) pjsip_iscomposing_parse( pj_pool_t *pool, char *msg, pj_size_t len, pj_bool_t *p_is_composing, pj_str_t **p_last_active, pj_str_t **p_content_type, int *p_refresh ) { pj_xml_node *doc, *node; /* Set defaults: */ if (p_is_composing) *p_is_composing = PJ_FALSE; if (p_last_active) *p_last_active = NULL; if (p_content_type) *p_content_type = NULL; /* Parse XML */ doc = pj_xml_parse( pool, msg, len); if (!doc) return PJLIB_UTIL_EINXML; /* Root document must be "isComposing" */ if (pj_stricmp(&doc->name, &STR_ISCOMPOSING) != 0) return PJSIP_SIMPLE_EBADISCOMPOSE; /* Get the status. */ if (p_is_composing) { node = pj_xml_find_node(doc, &STR_STATE); if (node == NULL) return PJSIP_SIMPLE_EBADISCOMPOSE; *p_is_composing = (pj_stricmp(&node->content, &STR_ACTIVE)==0); } /* Get last active. */ if (p_last_active) { node = pj_xml_find_node(doc, &STR_LASTACTIVE); if (node) *p_last_active = &node->content; } /* Get content type */ if (p_content_type) { node = pj_xml_find_node(doc, &STR_CONTENTTYPE); if (node) *p_content_type = &node->content; } /* Get refresh */ if (p_refresh) { node = pj_xml_find_node(doc, &STR_REFRESH); if (node) *p_refresh = pj_strtoul(&node->content); } return PJ_SUCCESS; }
PJ_DECL(const pj_str_t *) pjdialog_info_local_get_identity(const pjdialog_info_local *local) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)local, &IDENTITY); if (!node) return &EMPTY_STRING; return &node->content; }
PJ_DEF(pj_bool_t) pjpidf_status_is_basic_open(const pjpidf_status *st) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)st, &BASIC); if (!node) return PJ_FALSE; return pj_stricmp(&node->content, &OPEN)==0; }
PJ_DECL(pjdialog_info_remote*) pjdialog_info_dialog_get_remote(pjdialog_info_dialog *dialog) { pjdialog_info_remote *remote = (pjdialog_info_remote*)pj_xml_find_node(dialog, &REMOTE); if(remote) return remote; return NULL; }
PJ_DECL(const pj_str_t*) pjdialog_info_dialog_get_duration(pjdialog_info_dialog *dialog) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)dialog, &DURATION); if (!node) return &EMPTY_STRING; return &node->content; }
PJ_DEF(const pj_str_t *) pjdialog_info_remote_get_identity(const pjdialog_info_remote *remote) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)remote, &IDENTITY); if (!node) return &EMPTY_STRING; return &node->content; }
PJ_DEF(const pj_str_t*) pjpidf_tuple_get_contact(const pjpidf_tuple *t) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)t, &CONTACT); if (!node) return &EMPTY_STRING; return &node->content; }
PJ_DECL(pjdialog_info_local*) pjdialog_info_dialog_get_local(pjdialog_info_dialog *dialog) { pjdialog_info_local *local = (pjdialog_info_local*)pj_xml_find_node(dialog, &LOCAL); if (local) return local; return NULL; }
PJ_DEF(pjxpidf_pres*) pjxpidf_parse(pj_pool_t *pool, char *text, pj_size_t len) { pjxpidf_pres *pres; pj_xml_node *node; pres = pj_xml_parse(pool, text, len); if (!pres) return NULL; /* Validate <presence> */ if (pj_stricmp(&pres->name, &STR_PRESENCE) != 0) return NULL; /* Validate <presentity> */ node = pj_xml_find_node(pres, &STR_PRESENTITY); if (node == NULL) return NULL; if (pj_xml_find_attr(node, &STR_URI, NULL) == NULL) return NULL; /* Validate <atom> */ node = pj_xml_find_node(pres, &STR_ATOM); if (node == NULL) return NULL; if (pj_xml_find_attr(node, &STR_ATOMID, NULL) == NULL && pj_xml_find_attr(node, &STR_ID, NULL) == NULL) { return NULL; } /* Address */ node = pj_xml_find_node(node, &STR_ADDRESS); if (node == NULL) return NULL; if (pj_xml_find_attr(node, &STR_URI, NULL) == NULL) return NULL; /* Status */ node = pj_xml_find_node(node, &STR_STATUS); if (node == NULL) return NULL; if (pj_xml_find_attr(node, &STR_STATUS, NULL) == NULL) return NULL; return pres; }
PJ_DECL(const pj_str_t*) pjdialog_info_dialog_get_state_code(pjdialog_info_dialog *dialog) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)dialog, &STATE); pj_assert(node); const pj_xml_attr *attr = pj_xml_find_attr((pj_xml_node*)node, &CODE, NULL); if (attr) return &attr->value; return &EMPTY_STRING; }
PJ_DEF(pj_status_t) pjxpidf_set_uri(pj_pool_t *pool, pjxpidf_pres *pres, const pj_str_t *uri) { pj_xml_node *presentity; pj_xml_node *atom; pj_xml_node *addr; pj_xml_attr *attr; pj_str_t dup_uri; presentity = pj_xml_find_node(pres, &STR_PRESENTITY); if (!presentity) { pj_assert(0); return -1; } atom = pj_xml_find_node(pres, &STR_ATOM); if (!atom) { pj_assert(0); return -1; } addr = pj_xml_find_node(atom, &STR_ADDRESS); if (!addr) { pj_assert(0); return -1; } /* Set uri in presentity */ attr = pj_xml_find_attr(presentity, &STR_URI, NULL); if (!attr) { pj_assert(0); return -1; } pj_strdup(pool, &dup_uri, uri); attr->value = dup_uri; /* Set uri in address. */ attr = pj_xml_find_attr(addr, &STR_URI, NULL); if (!attr) { pj_assert(0); return -1; } attr->value = dup_uri; return 0; }
PJ_DEF(void) pjpidf_tuple_set_timestamp_np(pj_pool_t *pool, pjpidf_tuple *t, pj_str_t *ts) { pj_xml_node *node = pj_xml_find_node(t, &TIMESTAMP); if (!node) { node = PJ_POOL_ALLOC_T(pool, pj_xml_node); xml_init_node(pool, node, &TIMESTAMP, ts); } else { node->content = *ts; } }
PJ_DECL(const pj_str_t *) pjdialog_info_local_get_identity_display(const pjdialog_info_local *local) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)local, &IDENTITY); pj_xml_attr *attr; if (!node) return &EMPTY_STRING; attr = pj_xml_find_attr(node, &DISPLAY, NULL); if (!attr) return &EMPTY_STRING; return &attr->value; }
PJ_DECL(const pj_str_t *) pjdialog_info_local_get_target_uri(const pjdialog_info_local *local) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)local, &TARGET); pj_xml_attr *attr; if (!node) return &EMPTY_STRING; attr = pj_xml_find_attr(node, &URI, NULL); if (!attr) return &EMPTY_STRING; return &attr->value; }
PJ_DEF(const pj_str_t*) pjpidf_tuple_get_contact_prio(const pjpidf_tuple *t) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)t, &CONTACT); pj_xml_attr *attr; if (!node) return &EMPTY_STRING; attr = pj_xml_find_attr(node, &PRIORITY, NULL); if (!attr) return &EMPTY_STRING; return &attr->value; }
PJ_DEF(void) pjpidf_tuple_set_contact(pj_pool_t *pool, pjpidf_tuple *t, const pj_str_t *contact) { pj_xml_node *node = pj_xml_find_node(t, &CONTACT); if (!node) { node = PJ_POOL_ALLOC_T(pool, pj_xml_node); xml_init_node(pool, node, &CONTACT, contact); pj_xml_add_node(t, node); } else { pj_strdup(pool, &node->content, contact); } }
PJ_DECL(void) pjdialog_info_local_add_identity(pj_pool_t *pool, pjdialog_info_local *local, const pj_str_t *identity) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)local, &IDENTITY); if (!node) { node = PJ_POOL_ALLOC_T(pool, pj_xml_node); xml_init_node(pool, node, &IDENTITY, identity); pj_xml_add_node(local, node); } else { pj_strdup(pool, &node->content, identity); } }
PJ_DECL(void) pjdialog_info_dialog_set_state(pj_pool_t *pool, pjdialog_info_dialog *dialog, const pj_str_t *state) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)dialog, &STATE); if (!node) { node = PJ_POOL_ALLOC_T(pool, pj_xml_node); xml_init_node(pool, node, &STATE, state); pj_xml_add_node(dialog, node); } else { pj_strdup(pool, &node->content, state); } }
PJ_DECL(void) pjdialog_info_dialog_set_duration(pj_pool_t *pool, pjdialog_info_dialog *dialog, const pj_str_t *duration) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)dialog, &DURATION); if (!node) { node = PJ_POOL_ALLOC_T(pool, pj_xml_node); xml_init_node(pool, node, &DURATION, duration); pj_xml_add_node(dialog, node); } else { pj_strdup(pool, &node->content, duration); } }
PJ_DEF(pj_str_t*) pjxpidf_get_uri(pjxpidf_pres *pres) { pj_xml_node *presentity; pj_xml_attr *attr; presentity = pj_xml_find_node(pres, &STR_PRESENTITY); if (!presentity) return &STR_EMPTY_STRING; attr = pj_xml_find_attr(presentity, &STR_URI, NULL); if (!attr) return &STR_EMPTY_STRING; return &attr->value; }
PJ_DECL(void) pjdialog_info_dialog_set_state_code(pj_pool_t *pool, pjdialog_info_dialog *dialog, const pj_str_t *state_code) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)dialog, &STATE); pj_assert(node); pj_xml_attr *attr = pj_xml_find_attr(node, &CODE, NULL); if (!attr) { attr = xml_create_attr(pool, &CODE, state_code); pj_xml_add_attr(node, attr); } else pj_strdup(pool, &attr->value, state_code); }
PJ_DEF(void) pjpidf_tuple_set_contact_prio(pj_pool_t *pool, pjpidf_tuple *t, const pj_str_t *prio) { pj_xml_node *node = pj_xml_find_node(t, &CONTACT); pj_xml_attr *attr; if (!node) { node = PJ_POOL_ALLOC_T(pool, pj_xml_node); xml_init_node(pool, node, &CONTACT, NULL); pj_xml_add_node(t, node); } attr = pj_xml_find_attr(node, &PRIORITY, NULL); if (!attr) { attr = xml_create_attr(pool, &PRIORITY, prio); pj_xml_add_attr(node, attr); } else { pj_strdup(pool, &attr->value, prio); } }
PJ_DECL(void) pjdialog_info_local_set_identity_display(pj_pool_t *pool, pjdialog_info_local *local, const pj_str_t *identity_display) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)local, &IDENTITY); pj_xml_attr *attr; if (!node) { node = PJ_POOL_ALLOC_T(pool, pj_xml_node); xml_init_node(pool, node, &IDENTITY, NULL); pj_xml_add_node(local, node); } attr = pj_xml_find_attr(node, &DISPLAY, NULL); if (!attr) { attr = xml_create_attr(pool, &DISPLAY, identity_display); pj_xml_add_attr(node, attr); } else { pj_strdup(pool, &attr->value, identity_display); } }
PJ_DECL(void) pjdialog_info_local_set_target_uri(pj_pool_t *pool, pjdialog_info_local *local, const pj_str_t * target_uri) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)local, &TARGET); pj_xml_attr *attr; if (!node) { node = PJ_POOL_ALLOC_T(pool, pj_xml_node); xml_init_node(pool, node, &TARGET, NULL); pj_xml_add_node(local, node); } attr = pj_xml_find_attr(node, &URI, NULL); if (!attr) { attr = xml_create_attr(pool, &URI, target_uri); pj_xml_add_attr(node, attr); } else { pj_strdup(pool, &attr->value, target_uri); } }
PJ_DEF(void) pjpidf_status_set_basic_open(pjpidf_status *st, pj_bool_t open) { pj_xml_node *node = pj_xml_find_node(st, &BASIC); pj_assert(node != NULL); node->content = open ? OPEN : CLOSED; }
PJ_DEF(pj_bool_t) pjpidf_status_is_basic_open(const pjpidf_status *st) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)st, &BASIC); pj_assert(node != NULL); return pj_stricmp(&node->content, &OPEN)==0; }
PJ_DEF(const pj_str_t*) pjpidf_tuple_get_timestamp(const pjpidf_tuple *t) { pj_xml_node *node = pj_xml_find_node((pj_xml_node*)t, &TIMESTAMP); return node ? &node->content : &EMPTY_STRING; }
PJ_DEF(pjpidf_note*) pjpidf_tuple_get_first_note(pjpidf_tuple *t) { return pj_xml_find_node(t, &NOTE); }