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' router_command='%s' router_class='%s' osrf_xid='%s'>".
10 "<thread>%s</thread><body>%s</body></message>";
15 my $self = bless({}, $class);
18 $self->parse_xml($args{xml});
21 $self->{to} = $args{to} || '';
22 $self->{from} = $args{from} || '';
23 $self->{thread} = $args{thread} || '';
24 $self->{body} = $args{body} || '';
25 $self->{osrf_xid} = $args{osrf_xid} || '';
26 $self->{router_command} = $args{router_command} || '';
27 $self->{router_class} = $args{router_class} || '';
35 $self->{to} = $to if defined $to;
39 my($self, $from) = @_;
40 $self->{from} = $from if defined $from;
44 my($self, $thread) = @_;
45 $self->{thread} = $thread if defined $thread;
46 return $self->{thread};
49 my($self, $body) = @_;
50 $self->{body} = $body if defined $body;
54 my($self, $status) = @_;
55 $self->{status} = $status if defined $status;
56 return $self->{status};
59 my($self, $type) = @_;
60 $self->{type} = $type if defined $type;
64 my($self, $err_type) = @_;
65 $self->{err_type} = $err_type if defined $err_type;
66 return $self->{err_type};
69 my($self, $err_code) = @_;
70 $self->{err_code} = $err_code if defined $err_code;
71 return $self->{err_code};
74 my($self, $osrf_xid) = @_;
75 $self->{osrf_xid} = $osrf_xid if defined $osrf_xid;
76 return $self->{osrf_xid};
79 my($self, $router_command) = @_;
80 $self->{router_command} = $router_command if defined $router_command;
81 return $self->{router_command};
84 my($self, $router_class) = @_;
85 $self->{router_class} = $router_class if defined $router_class;
86 return $self->{router_class};
93 my $body = $self->{body};
94 $body =~ s/&/&/sog;
95 $body =~ s/</</sog;
96 $body =~ s/>/>/sog;
102 $self->{router_command},
103 $self->{router_class},
111 my($self, $xml) = @_;
115 $doc = XML::LibXML->new->parse_string($xml);
118 $logger->error("Error parsing message xml: $xml --- $err");
122 my $root = $doc->documentElement;
124 $self->{body} = $root->findnodes('/message/body').'';
125 $self->{thread} = $root->findnodes('/message/thread').'';
126 $self->{from} = $root->getAttribute('router_from');
127 $self->{from} = $root->getAttribute('from') unless $self->{from};
128 $self->{to} = $root->getAttribute('to');
129 $self->{type} = $root->getAttribute('type');
130 $self->{osrf_xid} = $root->getAttribute('osrf_xid');