1 package OpenSRF::Transport::SlimJabber::XMPPMessage;
2 use strict; use warnings;
3 use OpenSRF::Utils::Logger qw/$logger/;
4 use OpenSRF::EX qw/:try/;
5 use strict; use warnings;
8 use constant JABBER_MESSAGE =>
9 "<message to='%s' from='%s>".
10 "<opensrf router_command='%s' router_class='%s' osrf_xid='%s'/>".
11 "<thread>%s</thread><body>%s</body></message>";
16 my $self = bless({}, $class);
19 $self->parse_xml($args{xml});
22 $self->{to} = $args{to} || '';
23 $self->{from} = $args{from} || '';
24 $self->{thread} = $args{thread} || '';
25 $self->{body} = $args{body} || '';
26 $self->{osrf_xid} = $args{osrf_xid} || '';
27 $self->{router_command} = $args{router_command} || '';
28 $self->{router_class} = $args{router_class} || '';
36 $self->{to} = $to if defined $to;
40 my($self, $from) = @_;
41 $self->{from} = $from if defined $from;
45 my($self, $thread) = @_;
46 $self->{thread} = $thread if defined $thread;
47 return $self->{thread};
50 my($self, $body) = @_;
51 $self->{body} = $body if defined $body;
55 my($self, $status) = @_;
56 $self->{status} = $status if defined $status;
57 return $self->{status};
60 my($self, $type) = @_;
61 $self->{type} = $type if defined $type;
65 my($self, $err_type) = @_;
66 $self->{err_type} = $err_type if defined $err_type;
67 return $self->{err_type};
70 my($self, $err_code) = @_;
71 $self->{err_code} = $err_code if defined $err_code;
72 return $self->{err_code};
75 my($self, $osrf_xid) = @_;
76 $self->{osrf_xid} = $osrf_xid if defined $osrf_xid;
77 return $self->{osrf_xid};
80 my($self, $router_command) = @_;
81 $self->{router_command} = $router_command if defined $router_command;
82 return $self->{router_command};
85 my($self, $router_class) = @_;
86 $self->{router_class} = $router_class if defined $router_class;
87 return $self->{router_class};
94 my $body = $self->{body};
95 $body =~ s/&/&/sog;
96 $body =~ s/</</sog;
97 $body =~ s/>/>/sog;
103 $self->{router_command},
104 $self->{router_class},
112 my($self, $xml) = @_;
116 $doc = XML::LibXML->new->parse_string($xml);
119 $logger->error("Error parsing message xml: $xml --- $err");
123 my $root = $doc->documentElement;
124 my $osrf_node = $root->findnodes('/opensrf')->shift;
126 $self->{body} = $root->findnodes('/message/body').'';
127 $self->{thread} = $root->findnodes('/message/thread').'';
129 $self->{from} = $osrf_node->getAttribute('router_from');
130 $self->{from} = $root->getAttribute('from') unless $self->{from};
132 $self->{to} = $root->getAttribute('to');
134 $self->{type} = $osrf_node->getAttribute('type');
135 $self->{osrf_xid} = $osrf_node->getAttribute('osrf_xid');