/[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 42 by knops.gerd, Sun Feb 3 23:10:24 2008 UTC revision 49 by knops.gerd, Mon Feb 4 22:30:35 2008 UTC
# Line 63  package Meteor::Config; Line 63  package Meteor::Config;
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~ ~lastMsgID~\r\n',
69    
70  'Print out this help message',  'Print out this help message',
71          Help                                    => '',          Help                                    => '',
72    
# Line 84  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 104  package Meteor::Config; Line 112  package Meteor::Config;
112    
113  'The syslog facility to use',  'The syslog facility to use',
114          SyslogFacility                  => 'daemon',          SyslogFacility                  => 'daemon',
115            
116    'IP address for udp server (leave empty for all local addresses)',
117            UDPIP                                   => '',
118            
119    'Port number for udp connections, set to 0 to disable',
120            UDPPort                                 => 0,
121    
122          );          );
123                    
124          our %ConfigFileData=();          our %ConfigFileData=();
125          our %CommandLine=();          our %CommandLine=();
126          our %Defaults=();          our %Defaults=();
127          our %ExtraKeys=();          our %Modes=();
128                    
129          for(my $i=0;$i<scalar(@DEFAULTS);$i+=3)          for(my $i=0;$i<scalar(@DEFAULTS);$i+=3)
130          {          {
# Line 135  sub updateConfig { Line 150  sub updateConfig {
150                  next if($DEFAULTS[$i+1] eq 'Help');                  next if($DEFAULTS[$i+1] eq 'Help');
151                  push(@keys,$DEFAULTS[$i+1]);                  push(@keys,$DEFAULTS[$i+1]);
152          }          }
         push(@keys,keys %ExtraKeys);  
153                    
154          foreach my $key (@keys)          foreach my $mode ('',keys %Modes)
155          {                        {
156                  if(exists($CommandLine{$key}))                  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}))  
157                  {                  {
158                          print STDERR "Default" if($debug);                          my $foundValue=0;
159                          $::CONF{$key}=$Defaults{$key};                          my $key=$baseKey.$mode;
160                  }                          
161                                            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')  
162                          {                          {
163                                  ' ';                                  print STDERR "CmdLine" if($debug);
164                                    $::CONF{$key}=$CommandLine{$key};
165                                    $foundValue=1;
166                          }                          }
167                          elsif($1 eq 't')                          elsif(exists($ConfigFileData{$key}))
168                          {                          {
169                                  "\t";                                  print STDERR "CnfFile" if($debug);
170                                    $::CONF{$key}=$ConfigFileData{$key};
171                                    $foundValue=1;
172                          }                          }
173                          else                          elsif(exists($Defaults{$key}))
174                          {                          {
175                                  $1;                                  print STDERR "Default" if($debug);
176                                    $::CONF{$key}=$Defaults{$key};
177                                    $foundValue=1;
178                          }                          }
179                  /gex;                          
180                            next unless($foundValue);
181                            
182                            print STDERR "\t$key\t$::CONF{$key}\n" if($debug);
183                            
184                            # Take care of escapes
185                            $::CONF{$key}=~s/\\(.)/
186                                    if($1 eq 'r')
187                                    {
188                                            "\r";
189                                    }
190                                    elsif($1 eq 'n')
191                                    {
192                                            "\n";
193                                    }
194                                    elsif($1 eq 's')
195                                    {
196                                            ' ';
197                                    }
198                                    elsif($1 eq 't')
199                                    {
200                                            "\t";
201                                    }
202                                    else
203                                    {
204                                            $1;
205                                    }
206                            /gex;
207                    }
208          }          }
           
209          print STDERR '-'x79 ."\n" if($debug);          print STDERR '-'x79 ."\n" if($debug);
210  }  }
211    
# Line 218  sub setCommandLineParameters { Line 242  sub setCommandLineParameters {
242                                    
243                  $k='Debug' if($k eq 'd');                  $k='Debug' if($k eq 'd');
244                                    
245                    my $mode='';
246                    
247                    if($k=~s/(\..+)$//)
248                    {
249                            $mode=$1;
250                            $Modes{$mode}=1;
251                    }
252                    
253                  my $key=undef;                  my $key=undef;
254                  my $kl=length($k);                  my $kl=length($k);
255                  my $kOrig=$k;                  my $kOrig=$k;
# Line 249  sub setCommandLineParameters { Line 281  sub setCommandLineParameters {
281                                  $key=$p;                                  $key=$p;
282                          }                          }
283                  }                  }
                   
                 if($k=~/^HeaderTemplate(\d+)$/i)  
                 {  
                         $key="HeaderTemplate$1";  
                         $ExtraKeys{$key}=1;  
                 }  
284                                                    
285                  &usage("Unknown parameter name '$kOrig'") unless(defined($key));                  &usage("Unknown parameter name '$kOrig'") unless(defined($key));
286                                    
# Line 262  sub setCommandLineParameters { Line 288  sub setCommandLineParameters {
288                                    
289                  #print "$kOrig: $key\n";                  #print "$kOrig: $key\n";
290                                    
291                  $CommandLine{$key}=1;                  $CommandLine{"$key$mode"}=1;
292                                    
293                  if($cnt>1 && $_[0]!~/^\-(?!\-)/)                  if($cnt>1 && $_[0]!~/^\-(?!\-)/)
294                  {                  {
295                          my $param=shift;                          my $param=shift;
296                          $param=~s/^\-\-/\-/;                          $param=~s/^\-\-/\-/;
297                          $CommandLine{$key}=$param;                          $CommandLine{"$key$mode"}=$param;
298                  }                  }
299          }          }
300                    
# Line 285  sub readConfig { Line 311  sub readConfig {
311          my $path=$class->valueForKey('ConfigFileLocation');          my $path=$class->valueForKey('ConfigFileLocation');
312          return unless(defined($path) && -f $path);          return unless(defined($path) && -f $path);
313                    
314            my $mode='';
315            
316          open(CONFIG,"$path") or &usage("Config file '$path' for read: $!\n");          open(CONFIG,"$path") or &usage("Config file '$path' for read: $!\n");
317          while(<CONFIG>)          while(<CONFIG>)
318          {          {
# Line 293  sub readConfig { Line 321  sub readConfig {
321                                    
322                  s/[\r\n]*$//;                  s/[\r\n]*$//;
323                                    
324                    if(/^\s*\[\s*([^\]\s]+)\s*\]\s*$/)
325                    {
326                            $Modes{".$1"}=1;
327                            next;
328                    }
329                    
330                  unless(/^(\S+)\s*(.*)/)                  unless(/^(\S+)\s*(.*)/)
331                  {                  {
332                          &usage("Invalid configuration file parameter line '$_'");                          &usage("Invalid configuration file parameter line '$_'");
# Line 302  sub readConfig { Line 336  sub readConfig {
336                  my $val=$2;                  my $val=$2;
337                  $val='' unless(defined($val));                  $val='' unless(defined($val));
338                                    
339                  if($key=~/^HeaderTemplate\d+$/)                  unless(exists($Defaults{$key}))
340                  {                  {
341                          $ExtraKeys{$key}=1;                          &usage("Unknown configuration file parameter name '$key$mode'");
342                  }                  }
343                  else                  if($key eq 'ConfigFileLocation')
344                  {                  {
345                          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!");  
                         }  
346                  }                  }
347                                    
348                  $val=~s/^--/-/;                  $val=~s/^--/-/;
349                                    
350                  $ConfigFileData{$key}=$val;                  $ConfigFileData{"$key$mode"}=$val;
351          }          }
352          close(CONFIG);          close(CONFIG);
353  }  }
# Line 340  EOT Line 367  EOT
367                    
368                  print STDERR <<"EOT";                  print STDERR <<"EOT";
369    
370  Meteor server v1.0 (release date: 1 Dec 2006)  Meteor server v$::VERSION (release date: $::RELEASE_DATE)
371  Licensed under the terms of the GNU General Public Licence (2.0)  Licensed under the terms of the GNU General Public Licence (2.0)
372    
373  Usage:  Usage:

Legend:
Removed from v.42  
changed lines
  Added in v.49

  ViewVC Help
Powered by ViewVC 1.1.26