[asterisk-commits] mmichelson: branch group/CCSS r240223 - in /team/group/CCSS: channels/ includ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jan 14 14:00:21 CST 2010
Author: mmichelson
Date: Thu Jan 14 14:00:18 2010
New Revision: 240223
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=240223
Log:
Commit some progress towards XML parsing of SIP PUBLISH requests.
My focus is going elsewhere for a while, since Richard has found
some glaring problems with some elements of the CC core. Off to
work on those!
Modified:
team/group/CCSS/channels/chan_sip.c
team/group/CCSS/include/asterisk/xml.h
team/group/CCSS/main/xml.c
Modified: team/group/CCSS/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_sip.c?view=diff&rev=240223&r1=240222&r2=240223
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Thu Jan 14 14:00:18 2010
@@ -15358,7 +15358,7 @@
struct sip_request *req;
char *colon;
char *decoded_uri;
-
+
req = oreq;
if (!req)
req = &p->initreq;
@@ -23793,8 +23793,8 @@
struct ast_xml_node *presence_node = ast_xml_get_root(doc);
struct ast_xml_node *child_nodes;
struct ast_xml_node *node_iterator;
+ struct ast_xml_ns *ns;
const char *entity;
- const char *namespace;
if (!presence_node) {
ast_log(LOG_WARNING, "Unable to retrieve root node of the XML document\n");
@@ -23818,18 +23818,14 @@
/* We're not interested in what the entity is, just that it exists */
ast_xml_free_attr(entity);
- if (!(namespace = ast_xml_get_attribute(presence_node, "xmlns"))) {
- ast_log(LOG_WARNING, "Presence element of PIDF document has no 'xmlns' attribute\n");
+ if (!(ns = ast_xml_find_namespace(doc, presence_node, NULL))) {
+ ast_log(LOG_WARNING, "Couldn't find default namespace...\n");
return FALSE;
}
- if (strcmp(namespace, "urn:ietf:params:xml:ns:pidf")) {
- ast_log(LOG_WARNING, "Improper XML namespace in PIDF document\n");
- ast_xml_free_attr(namespace);
- return FALSE;
- }
-
- ast_xml_free_attr(namespace);
+ /* XXX Need to add code here to make sure the namespace is valid and to free it once we're done
+ * with it
+ */
if (!(child_nodes = ast_xml_node_get_children(presence_node))) {
ast_log(LOG_WARNING, "PIDF document has no elements as children of 'presence'. Invalid\n");
@@ -23851,6 +23847,7 @@
continue;
}
if (pidf_validate_tuple(node_iterator) == FALSE) {
+ ast_log(LOG_NOTICE, "Unable to validate tuple\n");
return FALSE;
}
}
@@ -23926,8 +23923,11 @@
struct ast_xml_doc *pidf_doc;
const char *basic_status;
struct ast_xml_node *presence_node;
+ struct ast_xml_node *presence_children;
struct ast_xml_node *tuple_node;
+ struct ast_xml_node *tuple_children;
struct ast_xml_node *status_node;
+ struct ast_xml_node *status_children;
struct ast_xml_node *basic_node;
if (!agent) {
@@ -23943,6 +23943,8 @@
ao2_ref(agent, -1);
return -1;
}
+
+ ast_log(LOG_NOTICE, "PIDF document is valid!\n");
/* It's important to note that the PIDF validation routine has no knowledge
* of what we specifically want in this instance. A valid PIDF document could
@@ -23951,30 +23953,48 @@
* insufficient for our needs in this situation
*/
presence_node = ast_xml_get_root(pidf_doc);
- tuple_node = ast_xml_find_element(presence_node, "tuple", NULL, NULL);
-
- if (!tuple_node) {
+ if (!(presence_children = ast_xml_node_get_children(presence_node))) {
+ ast_log(LOG_WARNING, "No tuples within presence element.\n");
transmit_response(pvt, "400 Bad Request", req);
ast_xml_close(pidf_doc);
ao2_ref(agent, -1);
return -1;
}
- status_node = ast_xml_find_element(tuple_node, "status", NULL, NULL);
- /* We already made sure that the tuple has a status node when we validated the PIDF
- * document earlier.
- */
- basic_node = ast_xml_find_element(status_node, "basic", NULL, NULL);
- if (!basic_node) {
+ if (!(tuple_node = ast_xml_find_element(presence_children, "tuple", NULL, NULL))) {
+ ast_log(LOG_NOTICE, "Couldn't find tuple node?\n");
transmit_response(pvt, "400 Bad Request", req);
ast_xml_close(pidf_doc);
ao2_ref(agent, -1);
return -1;
}
+ /* We already made sure that the tuple has a status node when we validated the PIDF
+ * document earlier. So there's no need to enclose this operation in an if statement.
+ */
+ tuple_children = ast_xml_node_get_children(tuple_node);
+ status_node = ast_xml_find_element(tuple_children, "status", NULL, NULL);
+
+ if (!(status_children = ast_xml_node_get_children(status_node))) {
+ ast_log(LOG_WARNING, "No basic elements within status element.\n");
+ transmit_response(pvt, "400 Bad Request", req);
+ ast_xml_close(pidf_doc);
+ ao2_ref(agent, -1);
+ return -1;
+ }
+
+ if (!(basic_node = ast_xml_find_element(status_children, "basic", NULL, NULL))) {
+ ast_log(LOG_WARNING, "Couldn't find basic node?\n");
+ transmit_response(pvt, "400 Bad Request", req);
+ ast_xml_close(pidf_doc);
+ ao2_ref(agent, -1);
+ return -1;
+ }
+
basic_status = ast_xml_get_text(basic_node);
if (ast_strlen_zero(basic_status)) {
+ ast_log(LOG_NOTICE, "NOthing in basic node?\n");
transmit_response(pvt, "400 Bad Request", req);
ast_xml_free_text(basic_status);
ast_xml_close(pidf_doc);
@@ -23989,6 +24009,7 @@
agent_pvt->is_available = FALSE;
ast_cc_agent_caller_busy(agent->core_id, "Received PUBLISH stating SIP caller is busy");
} else {
+ ast_log(LOG_NOTICE, "BS basic content?\n");
transmit_response(pvt, "400 Bad Request", req);
}
Modified: team/group/CCSS/include/asterisk/xml.h
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/include/asterisk/xml.h?view=diff&rev=240223&r1=240222&r2=240223
==============================================================================
--- team/group/CCSS/include/asterisk/xml.h (original)
+++ team/group/CCSS/include/asterisk/xml.h Thu Jan 14 14:00:18 2010
@@ -98,6 +98,7 @@
* \retval The node on success.
*/
struct ast_xml_node *ast_xml_find_element(struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue);
+struct ast_xml_ns *ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name);
/*! \brief Get an element content string.
* \param node Node from where to get the string.
Modified: team/group/CCSS/main/xml.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/xml.c?view=diff&rev=240223&r1=240222&r2=240223
==============================================================================
--- team/group/CCSS/main/xml.c (original)
+++ team/group/CCSS/main/xml.c Thu Jan 14 14:00:18 2010
@@ -23,6 +23,7 @@
#include "asterisk.h"
#include "asterisk/xml.h"
+#include "asterisk/logger.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -183,6 +184,11 @@
return NULL;
}
+struct ast_xml_ns *ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name) {
+ xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name);
+ return (struct ast_xml_ns *) ns;
+}
+
const char *ast_xml_get_text(struct ast_xml_node *node)
{
if (!node) {
More information about the asterisk-commits
mailing list