Frontier::Daemon - receive Frontier XML RPC requests


Frontier-RPC documentation Contained in the Frontier-RPC distribution.

Index


Code Index:

NAME

Top

Frontier::Daemon - receive Frontier XML RPC requests

SYNOPSIS

Top

 use Frontier::Daemon;

 Frontier::Daemon->new(methods => {
     'rpcName' => \&sub_name,
        ...
     });

DESCRIPTION

Top

Frontier::Daemon is an HTTP/1.1 server that listens on a socket for incoming requests containing Frontier XML RPC2 method calls. Frontier::Daemon is a subclass of HTTP::Daemon, which is a subclass of IO::Socket::INET.

Frontier::Daemon takes a `methods' parameter, a hash that maps an incoming RPC method name to reference to a subroutine.

Frontier::Daemon takes a `use_objects' parameter that if set to a non-zero value will convert incoming <int>, <i4>, <float>, and <string> values to objects instead of scalars. See int(), float(), and string() in Frontier::RPC2 for more details.

SEE ALSO

Top

perl(1), HTTP::Daemon(3), IO::Socket::INET(3), Frontier::RPC2(3)

<http://www.scripting.com/frontier5/xml/code/rpc.html>

AUTHOR

Top

Ken MacLeod <ken@bitsko.slc.ut.us>


Frontier-RPC documentation Contained in the Frontier-RPC distribution.

#
# Copyright (C) 1998 Ken MacLeod
# Frontier::Daemon is free software; you can redistribute it
# and/or modify it under the same terms as Perl itself.
#
# $Id: Daemon.pm,v 1.5 2001/10/03 01:30:54 kmacleod Exp $
#

# NOTE: see Net::pRPC for a Perl RPC implementation

###
### NOTE: $self is inherited from HTTP::Daemon and the weird access
### comes from there (`${*$self}').
###

use strict;

package Frontier::Daemon;
use vars qw{@ISA};

@ISA = qw{HTTP::Daemon};

use Frontier::RPC2;
use HTTP::Daemon;
use HTTP::Status;

sub new {
    my $class = shift; my %args = @_;
    my $self = $class->SUPER::new(%args);
    return undef unless $self;

    ${*$self}{'methods'} = $args{'methods'};
    ${*$self}{'decode'} = new Frontier::RPC2 'use_objects' => $args{'use_objects'};
    ${*$self}{'response'} = new HTTP::Response 200;
    ${*$self}{'response'}->header('Content-Type' => 'text/xml');

    my $conn;
    while ($conn = $self->accept) {
	my $rq = $conn->get_request;
	if ($rq) {
	    if ($rq->method eq 'POST' && $rq->url->path eq '/RPC2') {
                ${*$self}{'response'}->content(${*$self}{'decode'}->serve($rq->content, ${*$self}{'methods'}));
                $conn->send_response(${*$self}{'response'});
	    } else {
		$conn->send_error(RC_FORBIDDEN);
	    }
	}
        $conn->close;
	$conn = undef;		# close connection
    }

    return $self;
}

1;