--- googlecode.com/svn/trunk/Meteor/Config.pm 2006/12/14 16:29:42 11 +++ googlecode.com/svn/trunk/Meteor/Config.pm 2008/03/02 22:18:59 57 @@ -42,6 +42,9 @@ use strict; our @DEFAULTS=( +'Template for each line in channelinfo', + ChannelInfoTemplate => '\r\n', + 'Configuration file location on disk (if any)', ConfigFileLocation => '/etc/meteord.conf', @@ -60,15 +63,15 @@ 'Name of index file to serve when a directory is requested from the static file web server', DirectoryIndex => 'index.html', -'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\n\r\n', - -'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= to their GET request. If *HeaderTemplate* is not found, the system will use the default HeaderTemplate (no number)', - 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\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n', +'Header template, ~server~, ~servertime~ and ~status~ will be replaced by the appropriate values.', + 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', 'Print out this help message', Help => '', +'Format to use for timestamps in syslog: unix or human', + LogTimeFormat => 'human', + 'Maximum age of a message in seconds', MaxMessageAge => 7200, @@ -81,13 +84,16 @@ 'Maximum duration in seconds for a subscriber connection to exist before forcing a it to close. Note that the server checks for expired connections in 60 second intervals, so small changes to this value will not have much of an effect. Use 0 to disable', MaxTime => 0, -'Message template, ~text~, ~id~ and ~timestamp~ will be replaced by the appropriate values', - MessageTemplate => '\r\n', +'Message template, ~text~, ~id~, ~channel~ and ~timestamp~ will be replaced by the appropriate values', + MessageTemplate => '\r\n', -'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.', PingInterval => 5, -'Message to be sent to all persistent and identified subscriber connections (see above) every PingInterval seconds', +'Persistence of a connection.', + Persist => 0, + +'Message to be sent to all persistent subscriber connections (see above) every PingInterval seconds', PingMessage => '\r\n', 'IP address for subscriber server (leave empty for all local addresses)', @@ -102,17 +108,24 @@ '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.', SubscriberDocumentRoot => '/usr/local/meteor/public_html', -'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.', SubscriberDynamicPageAddress => '/push', 'The syslog facility to use', SyslogFacility => 'daemon', + +'IP address for udp server (leave empty for all local addresses)', + UDPIP => '', + +'Port number for udp connections, set to 0 to disable', + UDPPort => 0, + ); our %ConfigFileData=(); our %CommandLine=(); our %Defaults=(); - our %ExtraKeys=(); + our %Modes=(); for(my $i=0;$ivalueForKey('Debug'); - 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); my @keys=(); @@ -138,53 +151,56 @@ next if($DEFAULTS[$i+1] eq 'Help'); push(@keys,$DEFAULTS[$i+1]); } - push(@keys,keys %ExtraKeys); - foreach my $key (@keys) - { - if(exists($CommandLine{$key})) - { - 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})) + foreach my $mode ('',keys %Modes) + { + print STDERR ($mode) ? "\r\n$mode:\r\n" : "\r\nDefaults:\r\n" if($debug); + foreach my $baseKey (@keys) { - print STDERR "Default" if($debug); - $::CONF{$key}=$Defaults{$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') + my $foundValue=0; + my $key=$baseKey.$mode; + + if(exists($CommandLine{$key})) { - ' '; + print STDERR "CmdLine" if($debug); + $::CONF{$key}=$CommandLine{$key}; + $foundValue=1; } - elsif($1 eq 't') + elsif(exists($ConfigFileData{$key})) { - "\t"; + print STDERR "CnfFile" if($debug); + $::CONF{$key}=$ConfigFileData{$key}; + $foundValue=1; } - else + elsif(exists($Defaults{$key})) { - $1; + print STDERR "Default" if($debug); + $::CONF{$key}=$Defaults{$key}; + $foundValue=1; } - /gex; + + next unless($foundValue); + + print STDERR "\t$baseKey\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') { + ' '; + } elsif($1 eq 't') { + "\t"; + } elsif($1 eq '0') { + "\0"; + } else { + $1; + } + /gex; + } } - print STDERR '-'x79 ."\n" if($debug); } @@ -201,6 +217,19 @@ sub setCommandLineParameters { my $class=shift; + # + # Quick check if we should show the version, if so ignore everything else + # Accept -v, -version, and everything in between + # + foreach my $p (@_) + { + if(index($p,'-v')==0 && index('-version',$p)==0) + { + print "$::PGM $::VERSION\n"; + exit(0); + } + } + while(my $cnt=scalar(@_)) { my $k=shift(@_); @@ -208,6 +237,14 @@ $k='Debug' if($k eq 'd'); + my $mode=''; + + if($k=~s/(\.(.+))$//) + { + $mode=$2; + $Modes{$mode}=1; + } + my $key=undef; my $kl=length($k); my $kOrig=$k; @@ -239,12 +276,6 @@ $key=$p; } } - - if($k=~/^HeaderTemplate(\d+)$/i) - { - $key="HeaderTemplate$1"; - $ExtraKeys{$key}=1; - } &usage("Unknown parameter name '$kOrig'") unless(defined($key)); @@ -252,13 +283,13 @@ #print "$kOrig: $key\n"; - $CommandLine{$key}=1; + $CommandLine{"$key$mode"}=1; if($cnt>1 && $_[0]!~/^\-(?!\-)/) { my $param=shift; $param=~s/^\-\-/\-/; - $CommandLine{$key}=$param; + $CommandLine{"$key$mode"}=$param; } } @@ -275,6 +306,8 @@ my $path=$class->valueForKey('ConfigFileLocation'); return unless(defined($path) && -f $path); + my $mode=''; + open(CONFIG,"$path") or &usage("Config file '$path' for read: $!\n"); while() { @@ -283,6 +316,13 @@ s/[\r\n]*$//; + if(/^\s*\[\s*([^\]\s]+)\s*\]\s*$/) + { + $Modes{$1}=1; + $mode = $1; + next; + } + unless(/^(\S+)\s*(.*)/) { &usage("Invalid configuration file parameter line '$_'"); @@ -292,25 +332,18 @@ my $val=$2; $val='' unless(defined($val)); - if($key=~/^HeaderTemplate\d+$/) + unless(exists($Defaults{$key})) { - $ExtraKeys{$key}=1; + &usage("Unknown configuration file parameter name '$key$mode'"); } - else + if($key eq 'ConfigFileLocation') { - unless(exists($Defaults{$key})) - { - &usage("Unknown configuration file parameter name '$key'"); - } - if($key eq 'ConfigFileLocation') - { - &usage("'ConfigFileLocation' parameter not allowed in configuration file!"); - } + &usage("'ConfigFileLocation' parameter not allowed in configuration file!"); } $val=~s/^--/-/; - $ConfigFileData{$key}=$val; + $ConfigFileData{"$key$mode"}=$val; } close(CONFIG); } @@ -322,7 +355,7 @@ print STDERR <<"EOT"; $msg; For further help type $::PGM -help -or consult docs at http://www.meteorserver.org/ +or consult docs at http://meteorserver.org/ EOT } else { @@ -330,7 +363,7 @@ print STDERR <<"EOT"; -Meteor server v1.0 (release date: 1 Dec 2006) +Meteor server v$::VERSION (release date: $::RELEASE_DATE) Licensed under the terms of the GNU General Public Licence (2.0) Usage: @@ -354,7 +387,7 @@ $Defaults{'ConfigFileLocation'} For more information and complete documentation, see the Meteor -website at http://www.meteorserver.org/ +website at http://meteorserver.org/ EOT }