/[meteor]/trunk/Meteor/Config.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 /trunk/Meteor/Config.pm

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

revision 32 by andrew.betts, Thu Dec 20 21:24:24 2007 UTC revision 50 by andrew.betts, Wed Feb 27 13:55:35 2008 UTC
# Line 42  package Meteor::Config; Line 42  package Meteor::Config;
42          use strict;          use strict;
43                    
44          our @DEFAULTS=(          our @DEFAULTS=(
45    'Template for each line in channelinfo',
46            ChannelInfoTemplate             => '<script>ch("~name~", ~lastMsgID~);</script>\r\n',
47    
48  'Configuration file location on disk (if any)',  'Configuration file location on disk (if any)',
49          ConfigFileLocation              => '/etc/meteord.conf',          ConfigFileLocation              => '/etc/meteord.conf',
50    
# Line 61  package Meteor::Config; Line 64  package Meteor::Config;
64          DirectoryIndex  => 'index.html',          DirectoryIndex  => 'index.html',
65    
66  'Header template, ~server~, ~servertime~ and ~status~ will be replaced by the appropriate values.  **NOTE**: It is possible to define more than one HeaderTemplate by appending a number at the end, for example *HeaderTemplate42*. Clients can request a specific header to be used by adding the parameter template=<number> to their GET request. If *HeaderTemplate<number>* is not found, the system will use the default HeaderTemplate (no number)',  'Header template, ~server~, ~servertime~ and ~status~ will be replaced by the appropriate values.  **NOTE**: It is possible to define more than one HeaderTemplate by appending a number at the end, for example *HeaderTemplate42*. Clients can request a specific header to be used by adding the parameter template=<number> to their GET request. If *HeaderTemplate<number>* is not found, the system will use the default HeaderTemplate (no number)',
67          HeaderTemplate                  => 'HTTP/1.1 ~status~\r\nServer: ~server~\r\nContent-Type: text/html; charset=utf-8\r\nPragma: no-cache\r\nCache-Control: no-cache, no-store, must-revalidate\r\nExpires: Thu, 1 Jan 1970 00:00:00 GMT\r\n\r\n<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">\r\n<meta http-equiv="Cache-Control" content="no-store">\r\n<meta http-equiv="Cache-Control" content="no-cache">\r\n<meta http-equiv="Pragma" content="no-cache">\r\n<meta http-equiv="Expires" content="Thu, 1 Jan 1970 00:00:00 GMT">\r\n<script type="text/javascript">\r\nwindow.onError = null;\r\nvar domainparts = document.domain.split(".");\r\ndocument.domain = domainparts[domainparts.length-2]+"."+domainparts[domainparts.length-1];\r\nparent.Meteor.register(this);\r\n</script>\r\n</head>\r\n<body onload="try { parent.Meteor.reset(this) } catch (e) {}">\r\n',          HeaderTemplate                  => 'HeaderTemplate HTTP/1.1 ~status~\r\nServer: ~server~\r\nContent-Type: text/html; charset=utf-8\r\nPragma: no-cache\r\nCache-Control: no-cache, no-store, must-revalidate\r\nExpires: Thu, 1 Jan 1970 00:00:00 GMT\r\n\r\n',
68    
69  'Print out this help message',  'Print out this help message',
70          Help                                    => '',          Help                                    => '',
71    
72    'Format to use for timestamps in syslog: unix or human',
73            LogTimeFormat                   => 'human',
74    
75  'Maximum age of a message in seconds',  'Maximum age of a message in seconds',
76          MaxMessageAge                   => 7200,          MaxMessageAge                   => 7200,
77    
# Line 81  package Meteor::Config; Line 87  package Meteor::Config;
87  'Message template, ~text~, ~id~, ~channel~ and ~timestamp~ will be replaced by the appropriate values',  'Message template, ~text~, ~id~, ~channel~ and ~timestamp~ will be replaced by the appropriate values',
88          MessageTemplate                 => '<script>p(~id~,"~channel~","~text~");</script>\r\n',          MessageTemplate                 => '<script>p(~id~,"~channel~","~text~");</script>\r\n',
89    
90  'Interval at which PingMessage is sent to all persistent and identified subscriber connections (ie those including id=someuniqueidentifier in their request, and not specifying persist=0). Must be at least 3 if set higher than zero. Set to zero to disable.',  'Interval at which PingMessage is sent to all persistent subscriber connections. Must be at least 3 if set higher than zero. Set to zero to disable.',
91          PingInterval                    => 5,          PingInterval                    => 5,
92    
93    'Persistence of a connection.',
94            Persist                                 => 0,
95    
96  'Message to be sent to all persistent and identified subscriber connections (see above) every PingInterval seconds',  'Message to be sent to all persistent and identified subscriber connections (see above) every PingInterval seconds',
97          PingMessage                             => '<script>p(-1,"");</script>\r\n',          PingMessage                             => '<script>p(-1,"");</script>\r\n',
98    
# Line 99  package Meteor::Config; Line 108  package Meteor::Config;
108  'An absolute filesystem path, to be used as the document root for Meteor\'s static file web server. If left empty, no documents will be served.',  'An absolute filesystem path, to be used as the document root for Meteor\'s static file web server. If left empty, no documents will be served.',
109          SubscriberDocumentRoot  => '/usr/local/meteor/public_html',          SubscriberDocumentRoot  => '/usr/local/meteor/public_html',
110    
111  'Since Meteor is capable of serving static pages from a document root as well as streaming events to subscribers, this paramter is used to specify the URI at which the event server can be reached. If set to the root, Meteor will lose the ability to serve static pages.',  'Since Meteor is capable of serving static pages from a document root as well as streaming events to subscribers, this parameter is used to specify the URI at which the event server can be reached. If set to the root, Meteor will lose the ability to serve static pages.',
112          SubscriberDynamicPageAddress    => '/push',          SubscriberDynamicPageAddress    => '/push',
113    
114  'The syslog facility to use',  'The syslog facility to use',
115          SyslogFacility                  => 'daemon',          SyslogFacility                  => 'daemon',
116            
117    'IP address for udp server (leave empty for all local addresses)',
118            UDPIP                                   => '',
119            
120    'Port number for udp connections, set to 0 to disable',
121            UDPPort                                 => 0,
122    
123          );          );
124                    
125          our %ConfigFileData=();          our %ConfigFileData=();
126          our %CommandLine=();          our %CommandLine=();
127          our %Defaults=();          our %Defaults=();
128          our %ExtraKeys=();          our %Modes=();
129                    
130          for(my $i=0;$i<scalar(@DEFAULTS);$i+=3)          for(my $i=0;$i<scalar(@DEFAULTS);$i+=3)
131          {          {
# Line 126  sub updateConfig { Line 142  sub updateConfig {
142                    
143          my $debug=$class->valueForKey('Debug');          my $debug=$class->valueForKey('Debug');
144                    
145          print STDERR '-'x79 ."\nParamters:\nSource \tName and Value\n".'-'x79 ."\n" if($debug);          print STDERR '-'x79 ."\nMeteor server v$::VERSION (release date: $::RELEASE_DATE)\r\nLicensed under the terms of the GNU General Public Licence (2.0)\n".'-'x79 ."\n" if($debug);
146                    
147          my @keys=();          my @keys=();
148                    
# Line 135  sub updateConfig { Line 151  sub updateConfig {
151                  next if($DEFAULTS[$i+1] eq 'Help');                  next if($DEFAULTS[$i+1] eq 'Help');
152                  push(@keys,$DEFAULTS[$i+1]);                  push(@keys,$DEFAULTS[$i+1]);
153          }          }
         push(@keys,keys %ExtraKeys);  
154                    
155          foreach my $key (@keys)          foreach my $mode ('',keys %Modes)
156          {                        {
157                  if(exists($CommandLine{$key}))                  print STDERR ($mode) ? "\r\n$mode:\r\n" : "\r\nDefaults:\r\n" if($debug);
158                  {                  foreach my $baseKey (@keys)
                         print STDERR "CmdLine" if($debug);  
                         $::CONF{$key}=$CommandLine{$key};  
                 }  
                 elsif(exists($ConfigFileData{$key}))  
                 {  
                         print STDERR "CnfFile" if($debug);  
                         $::CONF{$key}=$ConfigFileData{$key};  
                 }  
                 elsif(exists($Defaults{$key}))  
159                  {                  {
160                          print STDERR "Default" if($debug);                          my $foundValue=0;
161                          $::CONF{$key}=$Defaults{$key};                          my $key=$baseKey.$mode;
162                  }                          
163                                            if(exists($CommandLine{$key}))
                 print STDERR "\t$key\t$::CONF{$key}\n" if($debug);  
                   
                 # Take care of escapes  
                 $::CONF{$key}=~s/\\(.)/  
                         if($1 eq 'r')  
                         {  
                                 "\r";  
                         }  
                         elsif($1 eq 'n')  
                         {  
                                 "\n";  
                         }  
                         elsif($1 eq 's')  
164                          {                          {
165                                  ' ';                                  print STDERR "CmdLine" if($debug);
166                                    $::CONF{$key}=$CommandLine{$key};
167                                    $foundValue=1;
168                          }                          }
169                          elsif($1 eq 't')                          elsif(exists($ConfigFileData{$key}))
170                          {                          {
171                                  "\t";                                  print STDERR "CnfFile" if($debug);
172                                    $::CONF{$key}=$ConfigFileData{$key};
173                                    $foundValue=1;
174                          }                          }
175                          else                          elsif(exists($Defaults{$key}))
176                          {                          {
177                                  $1;                                  print STDERR "Default" if($debug);
178                                    $::CONF{$key}=$Defaults{$key};
179                                    $foundValue=1;
180                          }                          }
181                  /gex;                          
182                            next unless($foundValue);
183                            
184                            print STDERR "\t$baseKey\t$::CONF{$key}\n" if($debug);
185                            
186                            # Take care of escapes
187                            $::CONF{$key}=~s/\\(.)/
188                                    if($1 eq 'r') {
189                                            "\r";
190                                    } elsif($1 eq 'n') {
191                                            "\n";
192                                    } elsif($1 eq 's') {
193                                            ' ';
194                                    } elsif($1 eq 't') {
195                                            "\t";
196                                    } elsif($1 eq '0') {
197                                            "\0";
198                                    } else {
199                                            $1;
200                                    }
201                            /gex;
202                    }
203          }          }
           
204          print STDERR '-'x79 ."\n" if($debug);          print STDERR '-'x79 ."\n" if($debug);
205  }  }
206    
# Line 198  sub valueForKey { Line 217  sub valueForKey {
217  sub setCommandLineParameters {  sub setCommandLineParameters {
218          my $class=shift;          my $class=shift;
219                    
220            #
221            # Quick check if we should show the version, if so ignore everything else
222            # Accept -v, -version, and everything in between
223            #
224            foreach my $p (@_)
225            {
226                    if(index($p,'-v')==0 && index('-version',$p)==0)
227                    {
228                            print "$::PGM $::VERSION\n";
229                            exit(0);
230                    }
231            }
232            
233          while(my $cnt=scalar(@_))          while(my $cnt=scalar(@_))
234          {          {
235                  my $k=shift(@_);                  my $k=shift(@_);
# Line 205  sub setCommandLineParameters { Line 237  sub setCommandLineParameters {
237                                    
238                  $k='Debug' if($k eq 'd');                  $k='Debug' if($k eq 'd');
239                                    
240                    my $mode='';
241                    
242                    if($k=~s/(\.(.+))$//)
243                    {
244                            $mode=$2;
245                            $Modes{$mode}=1;
246                    }
247                    
248                  my $key=undef;                  my $key=undef;
249                  my $kl=length($k);                  my $kl=length($k);
250                  my $kOrig=$k;                  my $kOrig=$k;
# Line 236  sub setCommandLineParameters { Line 276  sub setCommandLineParameters {
276                                  $key=$p;                                  $key=$p;
277                          }                          }
278                  }                  }
                   
                 if($k=~/^HeaderTemplate(\d+)$/i)  
                 {  
                         $key="HeaderTemplate$1";  
                         $ExtraKeys{$key}=1;  
                 }  
279                                                    
280                  &usage("Unknown parameter name '$kOrig'") unless(defined($key));                  &usage("Unknown parameter name '$kOrig'") unless(defined($key));
281                                    
# Line 249  sub setCommandLineParameters { Line 283  sub setCommandLineParameters {
283                                    
284                  #print "$kOrig: $key\n";                  #print "$kOrig: $key\n";
285                                    
286                  $CommandLine{$key}=1;                  $CommandLine{"$key$mode"}=1;
287                                    
288                  if($cnt>1 && $_[0]!~/^\-(?!\-)/)                  if($cnt>1 && $_[0]!~/^\-(?!\-)/)
289                  {                  {
290                          my $param=shift;                          my $param=shift;
291                          $param=~s/^\-\-/\-/;                          $param=~s/^\-\-/\-/;
292                          $CommandLine{$key}=$param;                          $CommandLine{"$key$mode"}=$param;
293                  }                  }
294          }          }
295                    
# Line 272  sub readConfig { Line 306  sub readConfig {
306          my $path=$class->valueForKey('ConfigFileLocation');          my $path=$class->valueForKey('ConfigFileLocation');
307          return unless(defined($path) && -f $path);          return unless(defined($path) && -f $path);
308                    
309            my $mode='';
310            
311          open(CONFIG,"$path") or &usage("Config file '$path' for read: $!\n");          open(CONFIG,"$path") or &usage("Config file '$path' for read: $!\n");
312          while(<CONFIG>)          while(<CONFIG>)
313          {          {
# Line 280  sub readConfig { Line 316  sub readConfig {
316                                    
317                  s/[\r\n]*$//;                  s/[\r\n]*$//;
318                                    
319                    if(/^\s*\[\s*([^\]\s]+)\s*\]\s*$/)
320                    {
321                            $Modes{$1}=1;
322                            $mode = $1;
323                            next;
324                    }
325                    
326                  unless(/^(\S+)\s*(.*)/)                  unless(/^(\S+)\s*(.*)/)
327                  {                  {
328                          &usage("Invalid configuration file parameter line '$_'");                          &usage("Invalid configuration file parameter line '$_'");
# Line 289  sub readConfig { Line 332  sub readConfig {
332                  my $val=$2;                  my $val=$2;
333                  $val='' unless(defined($val));                  $val='' unless(defined($val));
334                                    
335                  if($key=~/^HeaderTemplate\d+$/)                  unless(exists($Defaults{$key}))
336                  {                  {
337                          $ExtraKeys{$key}=1;                          &usage("Unknown configuration file parameter name '$key$mode'");
338                  }                  }
339                  else                  if($key eq 'ConfigFileLocation')
340                  {                  {
341                          unless(exists($Defaults{$key}))                          &usage("'ConfigFileLocation' parameter not allowed in configuration file!");
                         {  
                                 &usage("Unknown configuration file parameter name '$key'");  
                         }  
                         if($key eq 'ConfigFileLocation')  
                         {  
                                 &usage("'ConfigFileLocation' parameter not allowed in configuration file!");  
                         }  
342                  }                  }
343                                    
344                  $val=~s/^--/-/;                  $val=~s/^--/-/;
345                                    
346                  $ConfigFileData{$key}=$val;                  $ConfigFileData{"$key$mode"}=$val;
347          }          }
348          close(CONFIG);          close(CONFIG);
349  }  }
# Line 319  sub usage { Line 355  sub usage {
355                  print STDERR <<"EOT";                  print STDERR <<"EOT";
356  $msg;  $msg;
357  For further help type $::PGM -help  For further help type $::PGM -help
358  or consult docs at http://www.meteorserver.org/  or consult docs at http://meteorserver.org/
359  EOT  EOT
360    
361          } else {          } else {
# Line 327  EOT Line 363  EOT
363                    
364                  print STDERR <<"EOT";                  print STDERR <<"EOT";
365    
366  Meteor server v1.0 (release date: 1 Dec 2006)  Meteor server v$::VERSION (release date: $::RELEASE_DATE)
367  Licensed under the terms of the GNU General Public Licence (2.0)  Licensed under the terms of the GNU General Public Licence (2.0)
368    
369  Usage:  Usage:
# Line 351  configuration file. The default location Line 387  configuration file. The default location
387          $Defaults{'ConfigFileLocation'}          $Defaults{'ConfigFileLocation'}
388    
389  For more information and complete documentation, see the Meteor  For more information and complete documentation, see the Meteor
390  website at http://www.meteorserver.org/  website at http://meteorserver.org/
391  EOT  EOT
392    
393          }          }

Legend:
Removed from v.32  
changed lines
  Added in v.50

  ViewVC Help
Powered by ViewVC 1.1.26