1 package OpenSRF::Transport::SlimJabber::Inbound;
2 use strict;use warnings;
3 use base qw/OpenSRF::Transport::SlimJabber::Client/;
4 use OpenSRF::EX qw(:try);
5 use OpenSRF::Utils::Logger qw(:level);
6 use OpenSRF::Utils::SettingsClient;
7 use OpenSRF::Utils::Config;
9 my $logger = "OpenSRF::Utils::Logger";
13 This is the jabber connection where all incoming client requests will be accepted.
14 This connection takes the data, passes it off to the system then returns to take
15 more data. Connection params are all taken from the config file and the values
16 retreived are based on the $app name passed into new().
18 This service should be loaded at system startup.
22 # XXX This will be overhauled to connect as a component instead of as
23 # a user. all in good time, though.
27 sub unix_sock { return $unix_sock; }
31 my( $class, $app ) = @_;
32 $class = ref( $class ) || $class;
35 my $client = OpenSRF::Utils::SettingsClient->new();
37 my $transport_info = $client->config_value(
38 "apps", $app, "transport_hosts", "transport_host" );
40 if( !ref($transport_info) eq "ARRAY" ) {
41 $transport_info = [$transport_info];
45 # XXX for now, we just try the first host...
47 my $username = $transport_info->[0]->{username};
48 my $password = $transport_info->[0]->{password};
49 my $resource = 'system';
50 my $host = $transport_info->[0]->{host};
51 my $port = $transport_info->[0]->{port};
53 if (defined $client->config_value("router_targets")) {
54 my $h = OpenSRF::Utils::Config->current->env->hostname;
55 $resource .= "_$h" . "_$$";
58 OpenSRF::Utils::Logger->transport("Inbound as $username, $password, $resource, $host, $port\n", INTERNAL );
60 my $self = __PACKAGE__->SUPER::new(
61 username => $username,
62 resource => $resource,
63 password => $password,
70 my $f = $client->config_value("dirs", "sock");
71 $unix_sock = join( "/", $f,
72 $client->config_value("apps", $app, "unix_config", "unix_sock" ));
73 bless( $self, $class );
84 my $client = OpenSRF::Utils::SettingsClient->new();
88 $routers = $client->config_value("router_targets","router_target");
89 $logger->transport( $self->{app} . " connecting to router $routers", INFO );
91 if (defined $routers) {
92 if( !ref($routers) || !(ref($routers) eq "ARRAY") ) {
93 $routers = [$routers];
97 for my $router (@$routers) {
98 $logger->transport( $self->{app} . " connecting to router $router", INFO );
99 $self->send( to => $router,
100 body => "registering", router_command => "register" , router_class => $self->{app} );
102 $logger->transport( $self->{app} . " :routers connected", INFO );
105 } catch OpenSRF::EX::Config with {
106 $logger->transport( $self->{app} . ": No routers defined" , WARN );
113 $logger->transport( $self->{app} . " going into listen loop", INFO );
115 my $sock = $self->unix_sock();
116 my $socket = IO::Socket::UNIX->new( Peer => $sock );
118 throw OpenSRF::EX::Socket( "Unable to connect to UnixServer: socket-file: $sock \n :=> $! " )
119 unless ($socket->connected);
121 my $o = $self->process( -1 );
123 if( ! defined( $o ) ) {
124 throw OpenSRF::EX::Jabber( "Listen Loop failed at 'process()'" );
132 throw OpenSRF::EX::Socket( "How did we get here?!?!" );