[OpenSRF-GIT] OpenSRF branch master updated. 9682d15475485522812ac73ac10e283d11176f7e
Evergreen Git
git at git.evergreen-ils.org
Fri Sep 21 11:27:54 EDT 2018
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenSRF".
The branch, master has been updated
via 9682d15475485522812ac73ac10e283d11176f7e (commit)
via 744f0d1f2775bd5c51bfbf47d4d89a29001aafcf (commit)
via b44fb8675a3b9983d3d3c1f2586006520b6f7281 (commit)
from 265aa9f8cc12472b347e34a62a8f2655dfb1c51b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9682d15475485522812ac73ac10e283d11176f7e
Author: Bill Erickson <berickxx at gmail.com>
Date: Thu Sep 20 18:04:09 2018 -0400
LP#1703411 XMPP opensrf element make check repairs
Update the transport_message unit tests to check for the new <opensrf/>
element for relaying custom commands.
Signed-off-by: Bill Erickson <berickxx at gmail.com>
Signed-off-by: Jason Stephenson <jason at sigio.com>
Signed-off-by: Mike Rylander <mrylander at gmail.com>
diff --git a/tests/check_transport_message.c b/tests/check_transport_message.c
index 293ba5d..4ecbfd3 100644
--- a/tests/check_transport_message.c
+++ b/tests/check_transport_message.c
@@ -111,7 +111,7 @@ END_TEST
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");
@@ -199,7 +199,8 @@ START_TEST(test_transport_message_prepare_xml)
"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
commit 744f0d1f2775bd5c51bfbf47d4d89a29001aafcf
Author: Bill Erickson <berickxx at gmail.com>
Date: Wed Sep 19 15:34:49 2018 -0400
LP#1703411 XMPP opensrf sub-element repairs
* Message template typo repair -- missing "'"
* XPath repair on path to opensrf sub-element for Perl
* Move 'type' attribute get/set back up to the <message> for Perl.
* Clean up code duplication in the C message building libs.
* Squash a centuries-old memory leak where xmlFree(sender) was only
called if a router_from was not supplied.
Signed-off-by: Bill Erickson <berickxx at gmail.com>
Signed-off-by: Jason Stephenson <jason at sigio.com>
Signed-off-by: Mike Rylander <mrylander at gmail.com>
diff --git a/src/libopensrf/transport_message.c b/src/libopensrf/transport_message.c
index f95debc..332b622 100644
--- a/src/libopensrf/transport_message.c
+++ b/src/libopensrf/transport_message.c
@@ -120,25 +120,16 @@ transport_message* new_message_from_xml( const char* msg_xml ) {
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* router_command = xmlGetProp( root, BAD_CAST "router_command" );
- 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 ) {
@@ -156,34 +147,8 @@ transport_message* new_message_from_xml( const char* msg_xml ) {
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(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);
- }
-
- /* 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 ) {
@@ -211,15 +176,13 @@ transport_message* new_message_from_xml( const char* msg_xml ) {
}
if( router_from ) {
- new_msg->sender = strdup((const char*)router_from);
- } else {
- if( sender ) {
- new_msg->sender = strdup((const char*)sender);
- xmlFree(sender);
+ if (new_msg->sender) {
+ // Sender value applied above. Clear it and
+ // use the router value instead.
+ free(new_msg->sender);
}
- }
- if(router_from) {
+ new_msg->sender = strdup((const char*)router_from);
new_msg->router_from = strdup((const char*)router_from);
xmlFree(router_from);
}
diff --git a/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPMessage.pm b/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPMessage.pm
index 44e2040..0fc4124 100644
--- a/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPMessage.pm
+++ b/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPMessage.pm
@@ -6,7 +6,7 @@ use strict; use warnings;
use XML::LibXML;
use constant JABBER_MESSAGE =>
- "<message to='%s' from='%s>".
+ "<message to='%s' from='%s'>".
"<opensrf router_command='%s' router_class='%s' osrf_xid='%s'/>".
"<thread>%s</thread><body>%s</body></message>";
@@ -121,7 +121,7 @@ sub parse_xml {
throw $err if $err;
my $root = $doc->documentElement;
- my $osrf_node = $root->findnodes('/opensrf')->shift;
+ my $osrf_node = $root->findnodes('/message/opensrf')->shift;
$self->{body} = $root->findnodes('/message/body').'';
$self->{thread} = $root->findnodes('/message/thread').'';
@@ -131,7 +131,7 @@ sub parse_xml {
$self->{to} = $root->getAttribute('to');
- $self->{type} = $osrf_node->getAttribute('type');
+ $self->{type} = $root->getAttribute('type');
$self->{osrf_xid} = $osrf_node->getAttribute('osrf_xid');
}
diff --git a/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm b/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm
index 737cf96..0a84ae1 100644
--- a/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm
+++ b/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm
@@ -307,14 +307,14 @@ sub start_element {
my $msg = $self->{message};
$msg->{to} = $attrs{'to'};
$msg->{from} = $attrs{from};
+ $msg->{type} = $attrs{type};
} elsif($name eq 'opensrf') {
# These will be authoritative if they exist
my $msg = $self->{message};
- $msg->{from} = $attrs{router_from};
+ $msg->{from} = $attrs{router_from} if $attrs{router_from};
$msg->{osrf_xid} = $attrs{'osrf_xid'};
- $msg->{type} = $attrs{type};
} elsif($name eq 'body') {
$self->{xml_state} = IN_BODY;
commit b44fb8675a3b9983d3d3c1f2586006520b6f7281
Author: Mike Rylander <mrylander at gmail.com>
Date: Tue Aug 28 14:32:02 2018 -0400
LP#1703411: Move OpenSRF XMPP attrs to subelement
Modern versions of Ejabberd strip custom XML attributes which appear
outside of custom elements. To support OpenSRF's custom router and
osrf_xid commands, move these attributes into a new custom XML element
<opensrf>.
Signed-off-by: Mike Rylander <mrylander at gmail.com>
Signed-off-by: Bill Erickson <berickxx at gmail.com>
Signed-off-by: Jason Stephenson <jason at sigio.com>
diff --git a/src/java/org/opensrf/net/xmpp/XMPPReader.java b/src/java/org/opensrf/net/xmpp/XMPPReader.java
index 406298a..cd620a6 100644
--- a/src/java/org/opensrf/net/xmpp/XMPPReader.java
+++ b/src/java/org/opensrf/net/xmpp/XMPPReader.java
@@ -248,6 +248,14 @@ public class XMPPReader implements Runnable {
return;
}
+ if("opensrf".equals(name)) {
+ /** add a special case for the opensrf "router_from" attribute */
+ String rf = reader.getAttributeValue(null, "router_from");
+ if( rf != null )
+ msgFrom = rf;
+ return;
+ }
+
if("body".equals(name)) {
xmlState = XMLState.IN_BODY;
return;
diff --git a/src/libopensrf/transport_message.c b/src/libopensrf/transport_message.c
index dfe83d1..f95debc 100644
--- a/src/libopensrf/transport_message.c
+++ b/src/libopensrf/transport_message.c
@@ -123,6 +123,7 @@ transport_message* new_message_from_xml( const char* msg_xml ) {
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* router_command = xmlGetProp( root, BAD_CAST "router_command" );
xmlChar* broadcast = xmlGetProp( root, BAD_CAST "broadcast" );
xmlChar* osrf_xid = xmlGetProp( root, BAD_CAST "osrf_xid" );
@@ -170,6 +171,11 @@ transport_message* new_message_from_xml( const char* msg_xml ) {
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;
@@ -191,6 +197,55 @@ transport_message* new_message_from_xml( const char* msg_xml ) {
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 ) {
+ new_msg->sender = strdup((const char*)router_from);
+ } else {
+ if( sender ) {
+ new_msg->sender = strdup((const char*)sender);
+ xmlFree(sender);
+ }
+ }
+
+ 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(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 );
@@ -317,6 +372,7 @@ int message_prepare_xml( transport_message* msg ) {
xmlNodePtr message_node;
xmlNodePtr body_node;
xmlNodePtr thread_node;
+ xmlNodePtr opensrf_node;
xmlNodePtr subject_node;
xmlNodePtr error_node;
@@ -340,14 +396,20 @@ int message_prepare_xml( transport_message* msg ) {
/* 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;
diff --git a/src/libopensrf/transport_session.c b/src/libopensrf/transport_session.c
index 4d2f7f6..7ea15d5 100644
--- a/src/libopensrf/transport_session.c
+++ b/src/libopensrf/transport_session.c
@@ -573,20 +573,25 @@ static void startElementHandler(
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;
diff --git a/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPMessage.pm b/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPMessage.pm
index 9bd5328..44e2040 100644
--- a/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPMessage.pm
+++ b/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPMessage.pm
@@ -6,7 +6,8 @@ use strict; use warnings;
use XML::LibXML;
use constant JABBER_MESSAGE =>
- "<message to='%s' from='%s' router_command='%s' router_class='%s' osrf_xid='%s'>".
+ "<message to='%s' from='%s>".
+ "<opensrf router_command='%s' router_class='%s' osrf_xid='%s'/>".
"<thread>%s</thread><body>%s</body></message>";
sub new {
@@ -120,14 +121,18 @@ sub parse_xml {
throw $err if $err;
my $root = $doc->documentElement;
+ my $osrf_node = $root->findnodes('/opensrf')->shift;
$self->{body} = $root->findnodes('/message/body').'';
$self->{thread} = $root->findnodes('/message/thread').'';
- $self->{from} = $root->getAttribute('router_from');
+
+ $self->{from} = $osrf_node->getAttribute('router_from');
$self->{from} = $root->getAttribute('from') unless $self->{from};
+
$self->{to} = $root->getAttribute('to');
- $self->{type} = $root->getAttribute('type');
- $self->{osrf_xid} = $root->getAttribute('osrf_xid');
+
+ $self->{type} = $osrf_node->getAttribute('type');
+ $self->{osrf_xid} = $osrf_node->getAttribute('osrf_xid');
}
diff --git a/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm b/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm
index 9e15ecd..737cf96 100644
--- a/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm
+++ b/src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm
@@ -306,8 +306,13 @@ sub start_element {
my $msg = $self->{message};
$msg->{to} = $attrs{'to'};
- $msg->{from} = $attrs{router_from} if $attrs{router_from};
- $msg->{from} = $attrs{from} unless $msg->{from};
+ $msg->{from} = $attrs{from};
+
+ } elsif($name eq 'opensrf') {
+
+ # These will be authoritative if they exist
+ my $msg = $self->{message};
+ $msg->{from} = $attrs{router_from};
$msg->{osrf_xid} = $attrs{'osrf_xid'};
$msg->{type} = $attrs{type};
-----------------------------------------------------------------------
Summary of changes:
src/java/org/opensrf/net/xmpp/XMPPReader.java | 8 ++
src/libopensrf/transport_message.c | 123 ++++++++++++--------
src/libopensrf/transport_session.c | 21 ++--
.../OpenSRF/Transport/SlimJabber/XMPPMessage.pm | 11 ++-
.../lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm | 9 +-
tests/check_transport_message.c | 5 +-
6 files changed, 113 insertions(+), 64 deletions(-)
hooks/post-receive
--
OpenSRF
More information about the opensrf-commits
mailing list