1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
############################################################################### |
############################################################################### |
3 |
# Copyright 2006 BITart Gerd Knops, All rights reserved. |
# Meteor |
4 |
|
# An HTTP server for the 2.0 web |
5 |
|
# Copyright (c) 2006 contributing authors |
6 |
# |
# |
7 |
# Project : Meteor |
# The Meteor daemon |
|
# File : meteord |
|
|
# Author : Gerd Knops gerti@BITart.com |
|
8 |
# |
# |
9 |
############################################################################### |
# Main program should call Meteor::Config::setCommandLineParameters(@ARGV),. |
10 |
# |
# Afterwards anybody can access $::CONF{<parameterName>}, where |
11 |
# History: |
# <parameterName> is any valid parameter (except 'Help') listed in the |
12 |
# 060821 Creation of file |
# @DEFAULTS array below. |
13 |
# |
# |
14 |
############################################################################### |
############################################################################### |
15 |
# |
# |
16 |
# Description: |
# This program is free software; you can redistribute it and/or modify it |
17 |
# The Meteor daemon |
# under the terms of the GNU General Public License as published by the Free |
18 |
|
# Software Foundation; either version 2 of the License, or (at your option) |
19 |
|
# any later version. |
20 |
# |
# |
21 |
# $Id:$ |
# This program is distributed in the hope that it will be useful, but WITHOUT |
22 |
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
23 |
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
24 |
|
# more details. |
25 |
# |
# |
26 |
############################################################################### |
# You should have received a copy of the GNU General Public License along |
27 |
|
# with this program; if not, write to the Free Software Foundation, Inc., |
28 |
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
29 |
# |
# |
30 |
# DISCLAIMER |
# For more information visit www.meteorserver.org |
|
# |
|
|
# BITart and Gerd Knops make no warranties, representations or commitments |
|
|
# with regard to the contents of this software. BITart and Gerd Knops |
|
|
# specifically disclaim any and all warranties, whether express, implied or |
|
|
# statutory, including, but not limited to, any warranty of merchantability |
|
|
# or fitness for a particular purpose, and non-infringement. Under no |
|
|
# circumstances will BITart or Gerd Knops be liable for loss of data, |
|
|
# special, incidental or consequential damages out of the use of this |
|
|
# software, even if those damages were foreseeable, or BITart or Gerd Knops |
|
|
# was informed of their potential. |
|
31 |
# |
# |
32 |
############################################################################### |
############################################################################### |
33 |
|
|
34 |
|
############################################################################### |
35 |
|
# meterod version |
36 |
|
################################################################################ |
37 |
|
|
38 |
|
$::VERSION='1.05.06'; |
39 |
|
$::RELEASE_DATE='not yet released'; |
40 |
|
|
41 |
|
############################################################################### |
42 |
# Configuration |
# Configuration |
43 |
############################################################################### |
############################################################################### |
44 |
|
|
45 |
use strict; |
use strict; |
46 |
|
|
47 |
|
use Socket; |
48 |
|
|
49 |
use Meteor::Syslog; |
use Meteor::Syslog; |
50 |
|
|
51 |
use Meteor::Socket; |
use Meteor::Socket; |
65 |
our $AGE_CHECK_INTERVALL=60; |
our $AGE_CHECK_INTERVALL=60; |
66 |
|
|
67 |
our $MAX_EXIT_DELAY=120; |
our $MAX_EXIT_DELAY=120; |
68 |
|
|
69 |
|
our $UDP_MAX_MESSAGE_SIZE=8192; |
70 |
|
|
71 |
############################################################################### |
############################################################################### |
72 |
# Main |
# Main |
73 |
############################################################################### |
############################################################################### |
74 |
|
|
75 |
# |
# |
76 |
|
# Record startup time |
77 |
|
# |
78 |
|
$::STARTUP_TIME=time; |
79 |
|
$::STARTUP_TIME+=0; # avoid warning |
80 |
|
|
81 |
|
# |
82 |
# Program name |
# Program name |
83 |
# |
# |
84 |
$::PGM=$0; |
$::PGM=$0; |
106 |
{ |
{ |
107 |
$0="$::PGM daemon"; |
$0="$::PGM daemon"; |
108 |
|
|
109 |
unless($::CONF{'Debug'}) |
my $facility=$::CONF{'SyslogFacility'} || $Meteor::Syslog::DEFAULT_FACILITY; |
110 |
|
|
111 |
|
unless($::CONF{'Debug'} || $facility eq 'none') |
112 |
{ |
{ |
113 |
# close standard file descriptors |
# close standard file descriptors |
114 |
close(STDIN); |
close(STDIN); |
131 |
} |
} |
132 |
else |
else |
133 |
{ |
{ |
134 |
print "$::PGM PID: $$\n"; |
&::syslog('info',"PID\t%s",$$); |
135 |
} |
} |
136 |
} |
} |
137 |
|
|
164 |
); |
); |
165 |
my $subscriberServerFN=$subscriberServer->fileno(); |
my $subscriberServerFN=$subscriberServer->fileno(); |
166 |
|
|
167 |
|
my $udpServer=undef; |
168 |
|
my $udpPort=$::CONF{'UDPPort'}; |
169 |
|
my $udpServerFN=undef; |
170 |
|
if($udpPort && $udpPort>0) |
171 |
|
{ |
172 |
|
$udpServer=Meteor::Socket->newUDPServer( |
173 |
|
$udpPort, |
174 |
|
$::CONF{'UDPIP'} |
175 |
|
); |
176 |
|
$udpServerFN=$udpServer->fileno(); |
177 |
|
} |
178 |
|
|
179 |
my $serverVector=''; |
my $serverVector=''; |
180 |
vec($serverVector,$controlServerFN,1)=1; |
vec($serverVector,$controlServerFN,1)=1; |
181 |
vec($serverVector,$subscriberServerFN,1)=1; |
vec($serverVector,$subscriberServerFN,1)=1; |
182 |
|
vec($serverVector,$udpServerFN,1)=1 if(defined($udpServerFN)); |
183 |
|
|
184 |
my $lastAgeCheck=time; |
my $lastAgeCheck=time; |
185 |
|
|
198 |
my $rVec=$serverVector; |
my $rVec=$serverVector; |
199 |
my $wVec=''; |
my $wVec=''; |
200 |
my $eVec=''; |
my $eVec=''; |
201 |
|
|
202 |
my $rout; |
my $rout; |
203 |
my $wout; |
my $wout; |
204 |
my $eout; |
my $eout; |
205 |
|
|
206 |
Meteor::Connection->addAllHandleBits(\$rVec,\$wVec,\$eVec); |
Meteor::Connection->addAllHandleBits(\$rVec,\$wVec,\$eVec); |
207 |
|
|
208 |
my $timeout=$MAIN_LOOP_TIMEOUT; |
my $timeout=$MAIN_LOOP_TIMEOUT; |
227 |
{ |
{ |
228 |
Meteor::Subscriber->newFromServer($subscriberServer); |
Meteor::Subscriber->newFromServer($subscriberServer); |
229 |
} |
} |
230 |
|
if(defined($udpServerFN) && vec($rout,$udpServerFN,1)) |
231 |
|
{ |
232 |
|
&handleUPD($udpServer); |
233 |
|
} |
234 |
|
|
235 |
Meteor::Connection->checkAllHandleBits($rout,$wout,$eout); |
Meteor::Connection->checkAllHandleBits($rout,$wout,$eout); |
236 |
} |
} |
351 |
|
|
352 |
&::syslog('emerg',"$::PGM loop exited"); |
&::syslog('emerg',"$::PGM loop exited"); |
353 |
|
|
354 |
|
############################################################################### |
355 |
|
# Subroutines |
356 |
|
############################################################################### |
357 |
|
sub handleUPD { |
358 |
|
$udpServer=shift; |
359 |
|
|
360 |
|
my $line; |
361 |
|
my $hispaddr=recv($udpServer->{'handle'},$line,$::UDP_MAX_MESSAGE_SIZE,0); |
362 |
|
|
363 |
|
&::syslog('debug',"udp message received: %s",$line); |
364 |
|
|
365 |
|
return unless($line=~s/^(\S+)\s//); |
366 |
|
|
367 |
|
my $cmd=$1; |
368 |
|
|
369 |
|
if($cmd eq 'ADDMESSAGE') |
370 |
|
{ |
371 |
|
return unless($line=~s/^(\S+)\s//); |
372 |
|
|
373 |
|
my $channelName=$1; |
374 |
|
my $channel=Meteor::Channel->channelWithName($channelName); |
375 |
|
my $msg=$channel->addMessage($line); |
376 |
|
my $msgID=$msg->id(); |
377 |
|
&::syslog('debug',"udp: new message added, ID %s",$msgID); |
378 |
|
} |
379 |
|
} |
380 |
|
|
381 |
1; |
1; |
382 |
############################################################################EOF |
############################################################################EOF |