[rt-commit] r303 - rt/branches/rt-3.1/bin
root at fsck.com
root at fsck.com
Sun Dec 14 23:32:22 EST 2003
Author: root
Date: 2003-12-12 19:30:00 -0500 (Fri, 12 Dec 2003)
New Revision: 303
Modified:
rt/branches/rt-3.1/bin/standalone_httpd.in
Log:
a bit of refactoring for the standalone httpd
Modified: rt/branches/rt-3.1/bin/standalone_httpd.in
===================================================================
--- rt/branches/rt-3.1/bin/standalone_httpd.in 2003-12-12 08:45:44 UTC (rev 302)
+++ rt/branches/rt-3.1/bin/standalone_httpd.in 2003-12-13 00:30:00 UTC (rev 303)
@@ -2,91 +2,111 @@
use strict;
+require ('@RT_BIN_PATH@/webmux.pl');
+
use lib( "@LOCAL_LIB_PATH@", "@RT_LIB_PATH@");
-use RT;
-RT::LoadConfig();
-use CGI qw(-private_tempfiles); #bring this in before mason, to make sure we
- #set private_tempfiles
-use HTML::Mason::CGIHandler;
-use HTML::Mason; # brings in subpackages: Parser, Interp, etc.
-
-use RT::Tickets;
-use RT::Transactions;
-use RT::Users;
-use RT::CurrentUser;
-use RT::Templates;
-use RT::Queues;
-use RT::ScripActions;
-use RT::ScripConditions;
-use RT::Scrips;
-use RT::Groups;
-use RT::GroupMembers;
-use RT::CustomFields;
-use RT::CustomFieldValues;
-use RT::TicketCustomFieldValues;
-
-use RT::Interface::Web;
-use MIME::Entity;
-use Text::Wrapper;
-use CGI::Cookie;
-use Time::ParseDate;
-use HTML::Entities;
-
use Socket;
RT::Init();
my $port = 4711;
+my $h = &RT::Interface::Web::NewCGIHandler(@RT::MasonParameters);
main_loop($port);
sub main_loop {
my $port = shift;
my $tcp = getprotobyname('tcp');
- socket( Server, PF_INET, SOCK_STREAM, $tcp ) or die "socket: $!";
- setsockopt( Server, SOL_SOCKET, SO_REUSEADDR, pack( "l", 1 ) )
+
+ socket( HTTPDaemon, PF_INET, SOCK_STREAM, $tcp ) or die "socket: $!";
+ setsockopt( HTTPDaemon, SOL_SOCKET, SO_REUSEADDR, pack( "l", 1 ) )
or warn "setsockopt: $!";
- bind( Server, sockaddr_in( $port, INADDR_ANY ) ) or die "bind: $!";
- listen( Server, SOMAXCONN ) or die "listen: $!";
- $RT::Logger->info("server started on port $port");
+ bind( HTTPDaemon, sockaddr_in( $port, INADDR_ANY ) ) or die "bind: $!";
+ listen( HTTPDaemon, SOMAXCONN ) or die "listen: $!";
- CONNECT:
+ print("You can connect to your RT server at http://localhost:$port/\n");
- RT::Init();
- my $h = &RT::Interface::Web::NewCGIHandler(@RT::MasonParameters);
+ while (1) {
- for ( ; accept( Client, Server ) ; close Client ) {
+ for ( ; accept( Remote, HTTPDaemon ); close Remote ) {
- *STDIN = *Client;
- *STDOUT = *Client;
+ *STDIN = *Remote;
+ *STDOUT = *Remote;
- my $remote_sockaddr = getpeername(STDIN);
- my ( undef, $iaddr ) = sockaddr_in($remote_sockaddr);
- my $peername = gethostbyaddr( $iaddr, AF_INET ) || "localhost";
- my $peeraddr = inet_ntoa($iaddr) || "127.0.0.1";
+ my $remote_sockaddr = getpeername(STDIN);
+ my ( undef, $iaddr ) = sockaddr_in($remote_sockaddr);
+ my $peername = gethostbyaddr( $iaddr, AF_INET ) || "localhost";
+ my $peeraddr = inet_ntoa($iaddr) || "127.0.0.1";
- my $local_sockaddr = getsockname(STDIN);
- my ( undef, $localiaddr ) = sockaddr_in($local_sockaddr);
- my $localname = gethostbyaddr( $localiaddr, AF_INET ) || "localhost";
- my $localaddr = inet_ntoa($iaddr) || "127.0.0.1";
+ my $local_sockaddr = getsockname(STDIN);
+ my ( undef, $localiaddr ) = sockaddr_in($local_sockaddr);
+ my $localname = gethostbyaddr( $localiaddr, AF_INET )
+ || "localhost";
+ my $localaddr = inet_ntoa($localiaddr) || "127.0.0.1";
- chomp( $_ = <STDIN> );
- my ( $method, $url, $proto, undef ) = split;
+ chomp( $_ = <STDIN> );
+ my ( $method, $request_uri, $proto, undef ) = split;
- $url =~ s#\\#/#g;
- $RT::Logger->info("<- $peername: $_");
- my ( $file, undef, $arglist ) =
- ( $url =~ /([^?]*)(\?(.*))?/ ); # split at ?
- my $file_escaped = $file;
- $file =~ s/%([\dA-Fa-f]{2})/chr(hex($1))/eg; # %20 -> space
+ $request_uri =~ s#\\#/#g;
+ $RT::Logger->info("<- $peername: $_");
+ my ( $file, undef, $query_string ) =
+ ( $request_uri =~ /([^?]*)(\?(.*))?/ ); # split at ?
+ $file =~
+ s/%([\dA-Fa-f]{2})/chr(hex($1))/eg; # decode url-escaped entities
- if ( $method !~ /^(GET|POST|HEAD)$/ ) {
- next CONNECT;
+ last if ( $method !~ /^(GET|POST|HEAD)$/ );
+
+ build_cgi_env( method => $method,
+ query_string => $query_string,
+ path => $file,
+ method => $method,
+ port => $port,
+ peername => $peername,
+ peeraddr => $peeraddr,
+ localname => $localname,
+ request_uri => $request_uri );
+
+ RT::ConnectToDatabase();
+ my $cgi = CGI->new();
+
+ print "HTTP/1.0 200 OK\n"; # probably OK by now
+
+ if ( ( !$h->interp->comp_exists( $cgi->path_info ) )
+ && ($h->interp->comp_exists( $cgi->path_info . "/index.html" ) )
+ ) {
+ $cgi->path_info( $cgi->path_info . "/index.html" );
+ }
+
+ eval { $h->handle_cgi_object($cgi); };
+ $RT::Logger->crit($@) if ($@);
+
+ if ( $RT::Handle->TransactionDepth ) {
+ $RT::Handle->ForceRollback;
+ $RT::Logger->crit( "Transaction not committed. Usually indicates a software fault. Data loss may have occurred");
+ }
+
}
- my @env_vars = qw(USER_AGENT CONTENT_LENGTH CONTENT_TYPE);
- foreach my $var (@env_vars) {
+ }
+
+}
+
+
+
+sub build_cgi_env {
+ my %args = ( query_string => '',
+ path => '',
+ port => undef,
+ protocol => undef,
+ localname => undef,
+ method => undef,
+ remote_name => undef,
+
+
+ @_);
+
+ foreach my $var qw(USER_AGENT CONTENT_LENGTH CONTENT_TYPE) {
delete $ENV{$var};
}
while (<STDIN>) {
@@ -98,40 +118,18 @@
last if (/^$/);
}
- print "HTTP/1.0 200 OK\n"; # probably OK by now
- $ENV{SERVER_PROTOCOL} = $proto;
- $ENV{SERVER_PORT} = $port;
- $ENV{SERVER_NAME} = $localname;
- $ENV{SERVER_URL} = "http://$localname:$port/";
- $ENV{PATH_INFO} = $file;
- $ENV{SCRIPT_FILENAME} = "file";
- $ENV{REQUEST_URI} = $url;
- $ENV{REQUEST_METHOD} = $method;
- $ENV{REMOTE_ADDR} = $peeraddr;
- $ENV{REMOTE_HOST} = $peername;
- $ENV{QUERY_STRING} = $arglist ||'';
+ $ENV{SERVER_PROTOCOL} = $args{protocol};
+ $ENV{SERVER_PORT} = $args{port};
+ $ENV{SERVER_NAME} = $args{'localname'};
+ $ENV{SERVER_URL} = "http://".$args{'localname'}.":".$args{'port'}."/";
+ $ENV{PATH_INFO} = $args{'path'};
+ $ENV{REQUEST_URI} = $args{'request_uri'};
+ $ENV{REQUEST_METHOD} = $args{method};
+ $ENV{REMOTE_ADDR} = $args{'peeraddr'};
+ $ENV{REMOTE_HOST} = $args{'peername'};
+ $ENV{QUERY_STRING} = $args{'query_string'};
$ENV{SERVER_SOFTWARE} = "rt-standalone/$RT::VERSION";
- RT::ConnectToDatabase();
-
CGI::initialize_globals();
- my $cgi = CGI->new();
-
- if ( ( !$h->interp->comp_exists( $cgi->path_info ) )
- && ( $h->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) {
- $cgi->path_info( $cgi->path_info . "/index.html" );
- }
-
- eval { $h->handle_cgi_object($cgi); };
- $RT::Logger->crit($@) if ($@);
-
- if ( $RT::Handle->TransactionDepth ) {
- $RT::Handle->ForceRollback;
- $RT::Logger->crit( "Transaction not committed. Usually indicates a software fault. Data loss may have occurred");
- }
-
- }
- next CONNECT;
-
-}
+}
More information about the Rt-commit
mailing list