[SimBot-commits] CVS: simbot/plugins httpd.pl,NONE,1.1
Status: Abandoned
Brought to you by:
kstange
|
From: Pete P. <fou...@us...> - 2005-07-27 02:02:48
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9282/plugins Added Files: httpd.pl Log Message: Beginnings of the HTTPD plugin. No, it doesn't do anything useful yet. --- NEW FILE: httpd.pl --- # SimBot HTTPD plugin # # Copyright (C) 2005 Pete Pearson # # This program is free software; you can redistribute and/or modify it # under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package SimBot::plugin::httpd; use warnings; use strict; use POE; use POE::Component::Server::HTTP; use constant WEB_PORT => 8090; our %pages; POE::Component::Server::HTTP->new( Alias => 'simbot_plugin_httpd', Port => WEB_PORT, ContentHandler => { '/' => \&index_handler, }, Headers => { Server => 'SimBot', }, ); sub index_handler { # build and display a index of what is available my ($request, $response) = @_; &SimBot::debug(3, 'httpd: handling request for ' . $request->uri . "\n"); my $requested_page = $request->uri; $requested_page =~ s|^http://(.*?)/|/|; if(defined $pages{$requested_page}) { my $handler = $pages{$requested_page}->{'handler'}; &$handler($request, $response); return; } my $msg = &page_header('SimBot'); $msg .= "<ul>\n"; foreach my $url (keys %pages) { my $title = $pages{$url}->{'title'}; $msg .= qq(<li><a href="$url">$title</a>\n); } $msg .= "</ul>\n"; $response->code(RC_OK); $response->push_header("Content-Type", "text/html"); $response->content($msg); } sub page_header { my ($title) = @_; return <<EOT; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <link rel="generator" href="http://simbot.sf.net/" /> <title>$title</title> </head> <body> EOT } sub add_page { my ($url, $title, $handler) = @_; &SimBot::debug(3, "httpd: adding page $url\n"); $pages{$url} = { 'title' => $title, 'handler' => $handler, }; } sub messup_httpd { &add_page('/test', 'Goes nowhere, does nothing!', sub {}); } &SimBot::plugin_register( plugin_id => 'httpd', event_plugin_load => \&messup_httpd, ); |