Perl Basics
Introduction to Perl
FAQ's
CGI
Regular Expressions

PC Overview
Cool Stuff
My Modules
Success Stories
Links
Perl in the News
Logos

PC Internals
About
Contact
Handy Logos
What's new

XML RPC Samples

See also
P-friendly

[ home ] - [ search ] - [ sitemap ]


up
#!/usr/bin/perl -w
use strict;
$| = 1;

use RPC::XML::Client;
require "xmlrpcutil_inc.pl";

&main();

#########################
sub main() {
#########################
	my $cli = RPC::XML::Client->new('https://reto.provisioning.extlab.sunrise.ch/OpenLDAP_iso.php');

	my $request;
	$request = RPC::XML::request->new('LookupCustomer',
		RPC::XML::struct->new(
			'mode'   => RPC::XML::string->new("interactive"),
			'source' => RPC::XML::string->new("openLDAP"),
			'lookup' => RPC::XML::string->new('AdminProfile'),
			'cn'     => RPC::XML::string->new('foo@example.org'),
		)
	);

	my $response = $cli->simple_request($request);


	if (!$response) {
		print "$RPC::XML::ERROR \n"; # No response
	}
	else {
		print "SunriseStatusCode: ",
			 $response->{'SunriseStatusCode'}, "\n"; # 001000... ist okay
		my $hash_ref = &prepareResponse($response);
		foreach (sort keys %$hash_ref) {
			print "- $_ \t= [\"", $hash_ref->{$_}, "\"]\n";
		}
	}
}


xmlrpcutil_inc.pl

my $response;

#######################################################
sub prepareResponse ($) {
#######################################################
	$response = $_[0];
	my %hash = ();
	foreach my $key (sort keys %$response) {
		my $dumpArr = 0;
		my @array = $response->{$key};
		foreach (@array) {
			if (ref $_ eq 'ARRAY') {
				foreach (@{$_}) {
					if (ref $_ eq 'ARRAY') {
						my $arr_ref = &dumpArray($key);
						$dumpArr = 1;
						my $i = 0;
						foreach (@{$arr_ref}) {
							$hash{"$key\.$i"} = $_;
							$i++;
						}
					}
					else {
						$hash{$key} = $_;
					}
				}
			}
			else {
				$hash{$key} = $_;
			}
		}
	}
	\%hash;
}

sub dumpArray ($) {
	# print "Dumping Array \"$_[0]\"\n";
	my @array = ();
	foreach (@{$response->{$_[0]}}) {
		foreach (@{$_}) {
			push(@array, $_);
		}
	}
	\@array;
}

1;
home - feedback - search

$Id: foo.htm,v 1.10 2004/03/11 17:50:01 reto Exp $
© 1998-2004 reto :)