/[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 26 by andrew.betts, Mon Jun 25 10:37:57 2007 UTC revision 45 by knops.gerd, Mon Feb 4 19:02:49 2008 UTC
# Line 60  package Meteor::Config; Line 60  package Meteor::Config;
60  'Name of index file to serve when a directory is requested from the static file web server',  'Name of index file to serve when a directory is requested from the static file web server',
61          DirectoryIndex  => 'index.html',          DirectoryIndex  => 'index.html',
62    
 'Header to be served with static documents. ~server~ and ~status~ will be replaced by the appropriate values',  
         DocumentHeaderTemplate                  => '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',  
   
63  '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)',
64          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                  => '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',
65    
66    'Template for each line in channelinfo',
67    
68            ChannelInfoTemplate             => '~name~ ~messageCount~\r\n',
69    
70  'Print out this help message',  'Print out this help message',
71          Help                                    => '',          Help                                    => '',
72    
# Line 87  package Meteor::Config; Line 88  package Meteor::Config;
88  '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 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.',
89          PingInterval                    => 5,          PingInterval                    => 5,
90    
91    'Persistence of a connection. Note: some modes have this hardcoded!',
92    
93            Persist                                 => 0,
94    
95  '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',
96          PingMessage                             => '<script>p(-1,"");</script>\r\n',          PingMessage                             => '<script>p(-1,"");</script>\r\n',
97    
# Line 113  package Meteor::Config; Line 118  package Meteor::Config;
118          our %CommandLine=();          our %CommandLine=();
119          our %Defaults=();          our %Defaults=();
120          our %ExtraKeys=();          our %ExtraKeys=();
121            our %Modes=();
122                    
123          for(my $i=0;$i<scalar(@DEFAULTS);$i+=3)          for(my $i=0;$i<scalar(@DEFAULTS);$i+=3)
124          {          {
# Line 140  sub updateConfig { Line 146  sub updateConfig {
146          }          }
147          push(@keys,keys %ExtraKeys);          push(@keys,keys %ExtraKeys);
148                    
149          foreach my $key (@keys)          
150          {                        foreach my $mode ('',keys %Modes)
151                  if(exists($CommandLine{$key}))          {
152                  {                  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}))  
153                  {                  {
154                          print STDERR "Default" if($debug);                          my $foundValue=0;
155                          $::CONF{$key}=$Defaults{$key};                          my $key=$baseKey.$mode;
156                  }                          
157                                            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')  
158                          {                          {
159                                  ' ';                                  print STDERR "CmdLine" if($debug);
160                                    $::CONF{$key}=$CommandLine{$key};
161                                    $foundValue=1;
162                          }                          }
163                          elsif($1 eq 't')                          elsif(exists($ConfigFileData{$key}))
164                          {                          {
165                                  "\t";                                  print STDERR "CnfFile" if($debug);
166                                    $::CONF{$key}=$ConfigFileData{$key};
167                                    $foundValue=1;
168                          }                          }
169                          else                          elsif(exists($Defaults{$key}))
170                          {                          {
171                                  $1;                                  print STDERR "Default" if($debug);
172                                    $::CONF{$key}=$Defaults{$key};
173                                    $foundValue=1;
174                          }                          }
175                  /gex;                          
176                            next unless($foundValue);
177                            
178                            print STDERR "\t$key\t$::CONF{$key}\n" if($debug);
179                            
180                            # Take care of escapes
181                            $::CONF{$key}=~s/\\(.)/
182                                    if($1 eq 'r')
183                                    {
184                                            "\r";
185                                    }
186                                    elsif($1 eq 'n')
187                                    {
188                                            "\n";
189                                    }
190                                    elsif($1 eq 's')
191                                    {
192                                            ' ';
193                                    }
194                                    elsif($1 eq 't')
195                                    {
196                                            "\t";
197                                    }
198                                    else
199                                    {
200                                            $1;
201                                    }
202                            /gex;
203                    }
204          }          }
           
205          print STDERR '-'x79 ."\n" if($debug);          print STDERR '-'x79 ."\n" if($debug);
206  }  }
207    
# Line 201  sub valueForKey { Line 218  sub valueForKey {
218  sub setCommandLineParameters {  sub setCommandLineParameters {
219          my $class=shift;          my $class=shift;
220                    
221            #
222            # Quick check if we should show the version, if so ignore everything else
223            # Accept -v, -version, and everything in between
224            #
225            foreach my $p (@_)
226            {
227                    if(index($p,'-v')==0 && index('-version',$p)==0)
228                    {
229                            print "$::PGM $::VERSION\n";
230                            exit(0);
231                    }
232            }
233            
234          while(my $cnt=scalar(@_))          while(my $cnt=scalar(@_))
235          {          {
236                  my $k=shift(@_);                  my $k=shift(@_);
# Line 208  sub setCommandLineParameters { Line 238  sub setCommandLineParameters {
238                                    
239                  $k='Debug' if($k eq 'd');                  $k='Debug' if($k eq 'd');
240                                    
241                    my $mode='';
242                    
243                    if($k=~s/(\..+)$//)
244                    {
245                            $mode=$1;
246                            $Modes{$mode}=1;
247                    }
248                    
249                  my $key=undef;                  my $key=undef;
250                  my $kl=length($k);                  my $kl=length($k);
251                  my $kOrig=$k;                  my $kOrig=$k;
# Line 252  sub setCommandLineParameters { Line 290  sub setCommandLineParameters {
290                                    
291                  #print "$kOrig: $key\n";                  #print "$kOrig: $key\n";
292                                    
293                  $CommandLine{$key}=1;                  $CommandLine{"$key$mode"}=1;
294                                    
295                  if($cnt>1 && $_[0]!~/^\-(?!\-)/)                  if($cnt>1 && $_[0]!~/^\-(?!\-)/)
296                  {                  {
297                          my $param=shift;                          my $param=shift;
298                          $param=~s/^\-\-/\-/;                          $param=~s/^\-\-/\-/;
299                          $CommandLine{$key}=$param;                          $CommandLine{"$key$mode"}=$param;
300                  }                  }
301          }          }
302                    
# Line 275  sub readConfig { Line 313  sub readConfig {
313          my $path=$class->valueForKey('ConfigFileLocation');          my $path=$class->valueForKey('ConfigFileLocation');
314          return unless(defined($path) && -f $path);          return unless(defined($path) && -f $path);
315                    
316            my $mode='';
317            
318          open(CONFIG,"$path") or &usage("Config file '$path' for read: $!\n");          open(CONFIG,"$path") or &usage("Config file '$path' for read: $!\n");
319          while(<CONFIG>)          while(<CONFIG>)
320          {          {
# Line 283  sub readConfig { Line 323  sub readConfig {
323                                    
324                  s/[\r\n]*$//;                  s/[\r\n]*$//;
325                                    
326                    if(/^\s*\[\s*([^\]\s]+)\s*\]\s*$/)
327                    {
328                            $Modes{".$1"}=1;
329                            next;
330                    }
331                    
332                  unless(/^(\S+)\s*(.*)/)                  unless(/^(\S+)\s*(.*)/)
333                  {                  {
334                          &usage("Invalid configuration file parameter line '$_'");                          &usage("Invalid configuration file parameter line '$_'");
# Line 300  sub readConfig { Line 346  sub readConfig {
346                  {                  {
347                          unless(exists($Defaults{$key}))                          unless(exists($Defaults{$key}))
348                          {                          {
349                                  &usage("Unknown configuration file parameter name '$key'");                                  &usage("Unknown configuration file parameter name '$key$mode'");
350                          }                          }
351                          if($key eq 'ConfigFileLocation')                          if($key eq 'ConfigFileLocation')
352                          {                          {
# Line 310  sub readConfig { Line 356  sub readConfig {
356                                    
357                  $val=~s/^--/-/;                  $val=~s/^--/-/;
358                                    
359                  $ConfigFileData{$key}=$val;                  $ConfigFileData{"$key$mode"}=$val;
360          }          }
361          close(CONFIG);          close(CONFIG);
362  }  }
# Line 330  EOT Line 376  EOT
376                    
377                  print STDERR <<"EOT";                  print STDERR <<"EOT";
378    
379  Meteor server v1.0 (release date: 1 Dec 2006)  Meteor server v$::VERSION (release date: $::RELEASE_DATE)
380  Licensed under the terms of the GNU General Public Licence (2.0)  Licensed under the terms of the GNU General Public Licence (2.0)
381    
382  Usage:  Usage:

Legend:
Removed from v.26  
changed lines
  Added in v.45

  ViewVC Help
Powered by ViewVC 1.1.26