/[meteor]/googlecode.com/svn/trunk/Meteor/Controller.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /googlecode.com/svn/trunk/Meteor/Controller.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by andrew.betts, Mon Nov 20 17:59:30 2006 UTC revision 9 by andrew.betts, Fri Dec 8 16:52:58 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2  ###############################################################################  ###############################################################################
3  #   Meteor  #   Meteor
4  #   An HTTP server for the 2.0 web  #   An HTTP server for the 2.0 web
5  #   Copyright (c) 2006 contributing authors  #   Copyright (c) 2006 contributing authors
6  #  #
7  #   Subscriber.pm  #   Subscriber.pm
8  #  #
9  #       Description:  #       Description:
10  #       A Meteor Controller  #       A Meteor Controller
11  #  #
12  ###############################################################################  ###############################################################################
13  #  #
14  #   This program is free software; you can redistribute it and/or modify it  #   This program is free software; you can redistribute it and/or modify it
15  #   under the terms of the GNU General Public License as published by the Free  #   under the terms of the GNU General Public License as published by the Free
16  #   Software Foundation; either version 2 of the License, or (at your option)  #   Software Foundation; either version 2 of the License, or (at your option)
17  #   any later version.  #   any later version.
18  #  #
19  #   This program is distributed in the hope that it will be useful, but WITHOUT  #   This program is distributed in the hope that it will be useful, but WITHOUT
20  #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or  #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  #   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for  #   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22  #   more details.  #   more details.
23  #  #
24  #   You should have received a copy of the GNU General Public License along  #   You should have received a copy of the GNU General Public License along
25  #   with this program; if not, write to the Free Software Foundation, Inc.,  #   with this program; if not, write to the Free Software Foundation, Inc.,
26  #   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  #   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27  #  #
28  #   For more information visit www.meteorserver.org  #   For more information visit www.meteorserver.org
29  #  #
30  ###############################################################################  ###############################################################################
31    
32  package Meteor::Controller;  package Meteor::Controller;
33  ###############################################################################  ###############################################################################
34  # Configuration  # Configuration
35  ###############################################################################  ###############################################################################
36                    
37          use strict;          use strict;
38                    
39          use Meteor::Connection;          use Meteor::Connection;
40          use Meteor::Channel;          use Meteor::Channel;
41                    
42          @Meteor::Controller::ISA=qw(Meteor::Connection);          @Meteor::Controller::ISA=qw(Meteor::Connection);
43    
44  ###############################################################################  ###############################################################################
45  # Instance methods  # Instance methods
46  ###############################################################################  ###############################################################################
47  sub processLine {  sub processLine {
48          my $self=shift;          my $self=shift;
49          my $line=shift;          my $line=shift;
50                    
51          # ADDMESSAGE channel1 Message text          # ADDMESSAGE channel1 Message text
52          # < OK          # < OK
53          # ADDMESSAGE          # ADDMESSAGE
54          # < ERR Invalid command syntax          # < ERR Invalid command syntax
55          # COUNTSUBSCRIBERS channel1          # COUNTSUBSCRIBERS channel1
56          # < OK 344          # < OK 344
57                    
58          unless($line=~s/^(ADDMESSAGE|COUNTSUBSCRIBERS|LISTCHANNELS|QUIT)//)          unless($line=~s/^(ADDMESSAGE|COUNTSUBSCRIBERS|LISTCHANNELS|QUIT)//)
59          {          {
60                  $self->write("ERR Invalid command syntax$::CRLF");                  $self->write("ERR Invalid command syntax$::CRLF");
61                                    
62                  return;                  return;
63          }          }
64                    
65          my $cmd=$1;          my $cmd=$1;
66                    
67          if($cmd eq 'ADDMESSAGE')          if($cmd eq 'ADDMESSAGE')
68          {          {
69                  unless($line=~s/^\s+(\S+)\s//)                  unless($line=~s/^\s+(\S+)\s//)
70                  {                  {
71                          $self->write("ERR Invalid command syntax$::CRLF");                          $self->write("ERR Invalid command syntax$::CRLF");
72    
73                          return;                          return;
74                  }                  }
75                                    
76                  my $channelName=$1;                  my $channelName=$1;
77                  my $channel=Meteor::Channel->channelWithName($channelName);                  my $channel=Meteor::Channel->channelWithName($channelName);
78                  $channel->addMessage($line);                  $channel->addMessage($line);
79                  $self->write("OK$::CRLF");                  $self->write("OK$::CRLF");
80          }          }
81          elsif($cmd eq 'COUNTSUBSCRIBERS')          elsif($cmd eq 'COUNTSUBSCRIBERS')
82          {          {
83                  unless($line=~s/^\s+(\S+)$//)                  unless($line=~s/^\s+(\S+)$//)
84                  {                  {
85                          $self->write("ERR Invalid command syntax$::CRLF");                          $self->write("ERR Invalid command syntax$::CRLF");
86    
87                          return;                          return;
88                  }                  }
89                                    
90                  my $channelName=$1;                  my $channelName=$1;
91                  my $numSubscribers=0;                  my $numSubscribers=0;
92                  my $channel=Meteor::Channel->channelWithName($channelName,1);                  my $channel=Meteor::Channel->channelWithName($channelName,1);
93                  $numSubscribers=$channel->subscriberCount() if($channel);                  $numSubscribers=$channel->subscriberCount() if($channel);
94                                    
95                  $self->write("OK $numSubscribers$::CRLF");                  $self->write("OK $numSubscribers$::CRLF");
96          }          }
97          elsif($cmd eq 'LISTCHANNELS')          elsif($cmd eq 'LISTCHANNELS')
98          {          {
99                  unless($line eq '')                  unless($line eq '')
100                  {                  {
101                          $self->write("ERR Invalid command syntax$::CRLF");                          $self->write("ERR Invalid command syntax$::CRLF");
102    
103                          return;                          return;
104                  }                  }
105                                    
106                  my $txt="OK$::CRLF".Meteor::Channel->listChannels()."--EOT--$::CRLF";                  my $txt="OK$::CRLF".Meteor::Channel->listChannels()."--EOT--$::CRLF";
107                                    
108                  $self->write($txt);                  $self->write($txt);
109          }          }
110          elsif($cmd eq 'QUIT')          elsif($cmd eq 'QUIT')
111          {          {
112                  unless($line eq '')                  unless($line eq '')
113                  {                  {
114                          $self->write("ERR Invalid command syntax$::CRLF");                          $self->write("ERR Invalid command syntax$::CRLF");
115    
116                          return;                          return;
117                  }                  }
118                                    
119                  $self->write("OK$::CRLF");                  $self->write("OK$::CRLF");
120                  $self->close(1);                  $self->close(1);
121          }          }
122          else          else
123          {          {
124                  # Should never get here                  # Should never get here
125                  die("Unknown command '$cmd'");                  die("Unknown command '$cmd'");
126          }          }
127  }  }
128    
129  sub close {  sub close {
130          my $self=shift;          my $self=shift;
131          my $noShutdownMsg=shift;          my $noShutdownMsg=shift;
132                    
133          unless($noShutdownMsg || $self->{'remoteClosed'})          unless($noShutdownMsg || $self->{'remoteClosed'})
134          {          {
135                  my $msg=$::CONF{'ControllerShutdownMsg'};                  my $msg=$::CONF{'ControllerShutdownMsg'};
136                  if(defined($msg) && $msg ne '')                  if(defined($msg) && $msg ne '')
137                  {                  {
138                          $self->write($msg);                          $self->write($msg);
139                  }                  }
140          }          }
141                    
142          $self->SUPER::close();          $self->SUPER::close();
143  }  }
144    
145  1;  1;
146  ############################################################################EOF  ############################################################################EOF

Legend:
Removed from v.8  
changed lines
  Added in v.9

  ViewVC Help
Powered by ViewVC 1.1.26