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 $conf = OpenSRF::Utils::Config->current;
36 my $domains = $conf->bootstrap->domains;
38 my $username = $conf->bootstrap->username;
39 my $password = $conf->bootstrap->passwd;
40 my $port = $conf->bootstrap->port;
41 my $host = $domains->[0]; # XXX for now...
42 my $resource = $app . '_listener_at_' . $conf->env->hostname;
44 my $router_name = $conf->bootstrap->router_name;
45 # no router, only one listener running..
46 if(!$router_name) { $resource = $app; }
48 OpenSRF::Utils::Logger->transport("Inbound as $username, $password, $resource, $host, $port\n", INTERNAL );
50 my $self = __PACKAGE__->SUPER::new(
51 username => $username,
52 resource => $resource,
53 password => $password,
60 my $client = OpenSRF::Utils::SettingsClient->new();
61 my $f = $client->config_value("dirs", "sock");
62 $unix_sock = join( "/", $f,
63 $client->config_value("apps", $app, "unix_config", "unix_sock" ));
64 bless( $self, $class );
75 my $routers = $self->{routers}; #store for destroy
76 my $router_name = $self->{router_name};
78 unless($router_name and $routers) {
83 for my $router (@$routers) {
84 push @targets, "$router_name\@$router/router";
87 for my $router (@targets) {
88 if($self->tcp_connected()) {
89 $self->send( to => $router, body => "registering",
90 router_command => "unregister" , router_class => $self->{app} );
102 my $conf = OpenSRF::Utils::Config->current;
103 my $router_name = $conf->bootstrap->router_name;
104 my $routers = $conf->bootstrap->domains;
106 $self->{routers} = $routers; #store for destroy
107 $self->{router_name} = $router_name;
109 if($router_name and $routers) {
112 for my $router (@$routers) {
113 push @targets, "$router_name\@$router/router";
116 for my $router (@targets) {
117 $logger->transport( $self->{app} . " connecting to router $router", INFO );
118 $self->send( to => $router,
119 body => "registering", router_command => "register" , router_class => $self->{app} );
121 $logger->transport( $self->{app} . " :routers connected", INFO );
125 $logger->transport("Bypassing routers...", INFO);
129 } catch OpenSRF::EX::Config with {
130 $logger->transport( $self->{app} . ": No routers defined" , WARN );
137 $logger->transport( $self->{app} . " going into listen loop", INFO );
140 my $sock = $self->unix_sock();
141 my $o = $self->process( -1 );
143 if( ! defined( $o ) ) {
144 throw OpenSRF::EX::Jabber( "Listen Loop failed at 'process()'" );
147 my $socket = IO::Socket::UNIX->new( Peer => $sock );
148 throw OpenSRF::EX::Socket( "Unable to connect to UnixServer: socket-file: $sock \n :=> $! " )
149 unless ($socket->connected);
155 throw OpenSRF::EX::Socket( "How did we get here?!?!" );