xmlChar* recipient = xmlGetProp( root, BAD_CAST "to");
xmlChar* subject = xmlGetProp( root, BAD_CAST "subject");
xmlChar* thread = xmlGetProp( root, BAD_CAST "thread" );
- xmlChar* router_from = xmlGetProp( root, BAD_CAST "router_from" );
- xmlChar* router_to = xmlGetProp( root, BAD_CAST "router_to" );
- xmlChar* router_class = xmlGetProp( root, BAD_CAST "router_class" );
- xmlChar* broadcast = xmlGetProp( root, BAD_CAST "broadcast" );
- xmlChar* osrf_xid = xmlGetProp( root, BAD_CAST "osrf_xid" );
-
- if( osrf_xid ) {
- message_set_osrf_xid( new_msg, (char*) osrf_xid);
- xmlFree(osrf_xid);
- }
-
- if( router_from ) {
- new_msg->sender = strdup((const char*)router_from);
- } else {
- if( sender ) {
- new_msg->sender = strdup((const char*)sender);
- xmlFree(sender);
- }
+ xmlChar* router_from = NULL;
+ xmlChar* router_to = NULL;
+ xmlChar* router_class = NULL;
+ xmlChar* router_command = NULL;
+ xmlChar* broadcast = NULL;
+ xmlChar* osrf_xid = NULL;
+
+ if( sender ) {
+ new_msg->sender = strdup((const char*)sender);
+ xmlFree(sender);
}
if( recipient ) {
xmlFree(thread);
}
- if(router_from) {
- new_msg->router_from = strdup((const char*)router_from);
- xmlFree(router_from);
- }
-
- if(router_to) {
- new_msg->router_to = strdup((const char*)router_to);
- xmlFree(router_to);
- }
-
- if(router_class) {
- new_msg->router_class = strdup((const char*)router_class);
- xmlFree(router_class);
- }
-
- if(broadcast) {
- if(strcmp((const char*) broadcast,"0") )
- new_msg->broadcast = 1;
- xmlFree(broadcast);
- }
-
- /* Within the message element, find the child nodes for "thread", "subject", and */
- /* "body". Extract their textual content into the corresponding members. */
+ /* Within the message element, find the child nodes for "thread", "subject" */
+ /* "body", and "opensrf". Extract their textual content into the corresponding members. */
xmlNodePtr search_node = root->children;
while( search_node != NULL ) {
new_msg->subject = strdup( (const char*) search_node->children->content );
}
+ if( ! strcmp( (const char*) search_node->name, "opensrf" ) ) {
+ router_from = xmlGetProp( search_node, BAD_CAST "router_from" );
+ router_to = xmlGetProp( search_node, BAD_CAST "router_to" );
+ router_class = xmlGetProp( search_node, BAD_CAST "router_class" );
+ router_command = xmlGetProp( search_node, BAD_CAST "router_command" );
+ broadcast = xmlGetProp( search_node, BAD_CAST "broadcast" );
+ osrf_xid = xmlGetProp( search_node, BAD_CAST "osrf_xid" );
+
+ if( osrf_xid ) {
+ message_set_osrf_xid( new_msg, (char*) osrf_xid);
+ xmlFree(osrf_xid);
+ }
+
+ if( router_from ) {
+ if (new_msg->sender) {
+ // Sender value applied above. Clear it and
+ // use the router value instead.
+ free(new_msg->sender);
+ }
+
+ new_msg->sender = strdup((const char*)router_from);
+ new_msg->router_from = strdup((const char*)router_from);
+ xmlFree(router_from);
+ }
+
+ if(router_to) {
+ new_msg->router_to = strdup((const char*)router_to);
+ xmlFree(router_to);
+ }
+
+ if(router_class) {
+ new_msg->router_class = strdup((const char*)router_class);
+ xmlFree(router_class);
+ }
+
+ if(router_command) {
+ new_msg->router_command = strdup((const char*)router_command);
+ xmlFree(router_command);
+ }
+
+ if(broadcast) {
+ if(strcmp((const char*) broadcast,"0") )
+ new_msg->broadcast = 1;
+ xmlFree(broadcast);
+ }
+ }
+
if( ! strcmp( (const char*) search_node->name, "body" ) ) {
if( search_node->children && search_node->children->content )
new_msg->body = strdup((const char*) search_node->children->content );
xmlNodePtr message_node;
xmlNodePtr body_node;
xmlNodePtr thread_node;
+ xmlNodePtr opensrf_node;
xmlNodePtr subject_node;
xmlNodePtr error_node;
/* set from and to */
xmlNewProp( message_node, BAD_CAST "to", BAD_CAST msg->recipient );
xmlNewProp( message_node, BAD_CAST "from", BAD_CAST msg->sender );
- xmlNewProp( message_node, BAD_CAST "router_from", BAD_CAST msg->router_from );
- xmlNewProp( message_node, BAD_CAST "router_to", BAD_CAST msg->router_to );
- xmlNewProp( message_node, BAD_CAST "router_class", BAD_CAST msg->router_class );
- xmlNewProp( message_node, BAD_CAST "router_command", BAD_CAST msg->router_command );
- xmlNewProp( message_node, BAD_CAST "osrf_xid", BAD_CAST msg->osrf_xid );
-
- if( msg->broadcast )
- xmlNewProp( message_node, BAD_CAST "broadcast", BAD_CAST "1" );
+
+ /* set from and to on a new node, also */
+ opensrf_node = xmlNewChild(message_node, NULL, (xmlChar*) "opensrf", NULL );
+ xmlNewProp( opensrf_node, BAD_CAST "router_from", BAD_CAST msg->router_from );
+ xmlNewProp( opensrf_node, BAD_CAST "router_to", BAD_CAST msg->router_to );
+ xmlNewProp( opensrf_node, BAD_CAST "router_class", BAD_CAST msg->router_class );
+ xmlNewProp( opensrf_node, BAD_CAST "router_command", BAD_CAST msg->router_command );
+ xmlNewProp( opensrf_node, BAD_CAST "osrf_xid", BAD_CAST msg->osrf_xid );
+
+ xmlAddChild(message_node, opensrf_node);
+
+ if( msg->broadcast ) {
+ xmlNewProp( opensrf_node, BAD_CAST "broadcast", BAD_CAST "1" );
+ }
/* Now add nodes where appropriate */
char* body = msg->body;
ses->state_machine->in_message = 1;
buffer_add( ses->from_buffer, get_xml_attr( atts, "from" ) );
buffer_add( ses->recipient_buffer, get_xml_attr( atts, "to" ) );
- buffer_add( ses->router_from_buffer, get_xml_attr( atts, "router_from" ) );
- buffer_add( ses->osrf_xid_buffer, get_xml_attr( atts, "osrf_xid" ) );
- buffer_add( ses->router_to_buffer, get_xml_attr( atts, "router_to" ) );
- buffer_add( ses->router_class_buffer, get_xml_attr( atts, "router_class" ) );
- buffer_add( ses->router_command_buffer, get_xml_attr( atts, "router_command" ) );
- const char* broadcast = get_xml_attr( atts, "broadcast" );
- if( broadcast )
- ses->router_broadcast = atoi( broadcast );
return;
}
if( ses->state_machine->in_message ) {
+ if( strcmp( (char*) name, "opensrf" ) == 0 ) {
+ buffer_add( ses->router_from_buffer, get_xml_attr( atts, "router_from" ) );
+ buffer_add( ses->osrf_xid_buffer, get_xml_attr( atts, "osrf_xid" ) );
+ buffer_add( ses->router_to_buffer, get_xml_attr( atts, "router_to" ) );
+ buffer_add( ses->router_class_buffer, get_xml_attr( atts, "router_class" ) );
+ buffer_add( ses->router_command_buffer, get_xml_attr( atts, "router_command" ) );
+ const char* broadcast = get_xml_attr( atts, "broadcast" );
+ if( broadcast )
+ ses->router_broadcast = atoi( broadcast );
+
+ return;
+ }
+
if( strcmp( (char*) name, "body" ) == 0 ) {
ses->state_machine->in_message_body = 1;
return;
START_TEST(test_transport_message_new_message_from_xml_populated)
const char* xml_jabber_msg =
- "<message from=\"sender\" to=\"receiver\" router_from=\"routerfrom\" router_to=\"routerto\" router_class=\"class\" broadcast=\"1\" osrf_xid=\"xid\"><thread>thread_value</thread><subject>subject_value</subject><body>body_value</body></message>";
+ "<message from=\"sender\" to=\"receiver\"><opensrf router_from=\"routerfrom\" router_to=\"routerto\" router_class=\"class\" broadcast=\"1\" osrf_xid=\"xid\"/><thread>thread_value</thread><subject>subject_value</subject><body>body_value</body></message>";
transport_message *my_msg = new_message_from_xml(xml_jabber_msg);
fail_if(my_msg == NULL, "new_message_from_xml failed to create a transport_message");
"message_prepare_xml should return 1 upon success");
fail_if(a_message->msg_xml == NULL,
"message_prepare_xml should store the returned xml in msg->msg_xml");
- fail_unless(strcmp(a_message->msg_xml, "<message to=\"recipient\" from=\"sender\" router_from=\"routerfrom\" router_to=\"routerto\" router_class=\"routerclass\" router_command=\"routercommand\" osrf_xid=\"osrfxid\" broadcast=\"1\"><error type=\"errortype\" code=\"123\"/><thread>thread</thread><subject>subject</subject><body>body</body></message>") == 0,
+
+ fail_unless(strcmp(a_message->msg_xml, "<message to=\"recipient\" from=\"sender\"><error type=\"errortype\" code=\"123\"/><opensrf router_from=\"routerfrom\" router_to=\"routerto\" router_class=\"routerclass\" router_command=\"routercommand\" osrf_xid=\"osrfxid\" broadcast=\"1\"/><thread>thread</thread><subject>subject</subject><body>body</body></message>") == 0,
"message_prepare_xml should store the correct xml in msg->msg_xml");
END_TEST