Net::EPP::Protocol - Low-level functions useful for both EPP clients and


Net-EPP documentation Contained in the Net-EPP distribution.

Index


Code Index:

NAME

Top

Net::EPP::Protocol - Low-level functions useful for both EPP clients and servers.

SYNOPSIS

Top

	#!/usr/bin/perl
	use Net::EPP::Protocol;
	use IO::Socket;
	use strict;

	# create a socket:

	my $socket = IO::Socket::INET->new( ... );

	# send a frame down the socket:

	Net::EPP::Protocol->send_frame($socket, $xml);

	# get a frame from the socket:

	my $xml = Net::EPP::Protocol->get_frame($socket);

DESCRIPTION

Top

EPP is the Extensible Provisioning Protocol. EPP (defined in RFC 4930) is an application layer client-server protocol for the provisioning and management of objects stored in a shared central repository. Specified in XML, the protocol defines generic object management operations and an extensible framework that maps protocol operations to objects. As of writing, its only well-developed application is the provisioning of Internet domain names, hosts, and related contact details.

This module implements functions that are common to both EPP clients and servers that implement the TCP transport as defined in RFC 4934. The main consumer of this module is currently Net::EPP::Client.

METHODS

Top

	my $xml = Net::EPP::Protocol->get_frame($socket);

This method reads a frame from the socket and returns a scalar containing the XML. $socket must be an IO::Handle or one of its subclasses (ie IO::Socket::*).

If the transmission fails for whatever reason, this method will croak(), so be sure to enclose it in an eval().

	Net::EPP::Protocol->send_frame($socket, $xml);

This method prepares an RFC 4934 compliant EPP frame and transmits it to the remote peer. $socket must be an IO::Handle or one of its subclasses (ie IO::Socket::*).

If the transmission fails for whatever reason, this method will croak(), so be sure to enclose it in an eval(). Otherwise, it will return a true value.

	my $frame = Net::EPP::Protocol->prep_frame($xml);

This method returns the XML frame in "wire format" with the protocol header prepended to it. The return value can be printed directly to an open socket, for example:

	print STDOUT Net::EPP::Protocol->prep_frame($frame->toString);

AUTHOR

Top

CentralNic Ltd (http://www.centralnic.com/).

COPYRIGHT

Top

SEE ALSO

Top

* Net::EPP::Client
* RFCs 4930 and RFC 4934, available from http://www.ietf.org/.
* The CentralNic EPP site at http://www.centralnic.com/resellers/epp.

Net-EPP documentation Contained in the Net-EPP distribution.
# Copyright (c) 2011 CentralNic Ltd. All rights reserved. This program is
# free software; you can redistribute it and/or modify it under the same
# terms as Perl itself.
package Net::EPP::Protocol;
use bytes;
use Carp;
use strict;

sub get_frame {
	my ($class, $fh) = @_;

	my $hdr;
	if (!defined($fh->read($hdr, 4))) {
		croak("Got a bad frame length from peer - connection closed?");

	} else {
		my $length = (unpack('N', $hdr) - 4);
		if ($length < 0) {
			croak("Got a bad frame length from peer - connection closed?");

		} elsif (0 == $length) {
			croak('Frame length is zero');

		} else {
			my $xml = '';
			my $buffer;
			while (length($xml) < $length) {
				$buffer = '';
				$fh->read($buffer, ($length - length($xml)));
				last if (length($buffer) == 0); # in case the socket has closed
				$xml .= $buffer;
			}

			return $xml;

		}
	}
}

sub send_frame {
	my ($class, $fh, $xml) = @_;
	$fh->print($class->prep_frame($xml));
	$fh->flush;
	return 1;
}

sub prep_frame {
	my ($class, $xml) = @_;
	return pack('N', length($xml) + 4).$xml;
}

1;