root/trunk/lib/DJabberd/Connection/ClientIn.pm @ 63

Revision 63, 3.3 kB (checked in by bradfitz, 4 years ago)

unbreak SSL

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1package DJabberd::Connection::ClientIn;
2use strict;
3use base 'DJabberd::Connection';
4
5use fields (
6            'requested_roster',  # bool: if user has requested their roster,
7            );
8
9sub set_requested_roster {
10    my ($self, $val) = @_;
11    $self->{requested_roster} = $val;
12}
13
14sub requested_roster {
15    my $self = shift;
16    return $self->{requested_roster};
17}
18
19sub on_stream_start {
20    my DJabberd::Connection $self = shift;
21    my $ss = shift;
22    # FIXME: bitch if we're starting a stream when we already have one, and we aren't
23    # expeting a new stream to start (like after SSL or SASL)
24    $self->start_stream_back($ss,
25                             namespace  => 'jabber:client');
26}
27
28sub is_server { 0 }
29
30sub on_stanza_received {
31    my ($self, $node) = @_;
32
33    my %class = (
34                 "{jabber:client}iq"       => 'DJabberd::IQ',
35                 "{jabber:client}message"  => 'DJabberd::Message',
36                 "{jabber:client}presence" => 'DJabberd::Presence',
37                 "{urn:ietf:params:xml:ns:xmpp-tls}starttls"  => 'DJabberd::Stanza::StartTLS',
38                 );
39    my $class = $class{$node->element} or
40        return $self->stream_error("unsupported-stanza-type");
41
42    # same variable as $node, but down(specific)-classed.
43    my $stanza = $class->new($node);
44
45    $self->run_hook_chain(phase => "filter_incoming_client",
46                          args  => [ $stanza ],
47                          methods => {
48                              reject => sub { },  # just stops the chain
49                          },
50                          fallback => sub {
51                              $self->filter_incoming_client_builtin($stanza);
52                          });
53}
54
55sub is_authenticated_jid {
56    my ($self, $jid) = @_;
57    return $jid->eq($self->bound_jid);
58}
59
60sub filter_incoming_client_builtin {
61    my ($self, $stanza) = @_;
62
63    # <invalid-from/> -- the JID or hostname provided in a 'from'
64    # address does not match an authorized JID or validated domain
65    # negotiated between servers via SASL or dialback, or between a
66    #  client and a server via authentication and resource binding.
67    #{=clientin-invalid-from}
68    my $from = $stanza->from_jid;
69
70    if ($from && ! $self->is_authenticated_jid($from)) {
71        # make sure it is from them, if they care to tell us who they are.
72        # (otherwise further processing should assume it's them anyway)
73        return $self->stream_error('invalid-from');
74    }
75
76    # if no from, we set our own
77    if (! $from) {
78        my $bj = $self->bound_jid;
79        $stanza->set_from($bj->as_string) if $bj;
80    }
81
82    $self->run_hook_chain(phase => "switch_incoming_client",
83                          args  => [ $stanza ],
84                          methods => {
85                              process => sub { $stanza->process($self) },
86                              deliver => sub { $stanza->deliver($self) },
87                          },
88                          fallback => sub {
89                              $self->switch_incoming_client_builtin($stanza);
90                          });
91}
92
93sub switch_incoming_client_builtin {
94    my ($self, $stanza) = @_;
95
96    my $to = $stanza->to_jid;
97    if (!$to
98        || ($to && $self->vhost->uses_jid($to)) ) {
99        $stanza->process($self);
100        return;
101    }
102
103    $stanza->deliver($self);
104}
105
1061;
Note: See TracBrowser for help on using the browser.