creating an alfs app

Bryan Dumm bdumm at bobby.bcpub.com
Thu Feb 1 21:20:57 PST 2001


I've been playing with David's alfs app idea and trying to 
make it do something useful like xmlrpc. Well amazingly enough
this is very simple to do, and I hope most people understand the
basics by the end of this email.... Then again, it might blow 
by most people.... :)

Ok some of you may have read the previous email I sent about building
xmlrpc clients...

http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto.html

Well this combines the frontend and the alfs app which uses the alfs backend..

Ok let's start with the client first...


use Frontier::Client;
 
$url = 'http://domain.com:8000';
  
$server = Frontier::Client->new( url => $url );
$profile = "my_alfs_profile";
 
$result = $server->call('process_profile', $profile);


now Frontier::Client is a perl module you can d/l @ 

http://bitsko.slc.ut.us/~ken/xml-rpc/

or use cpan to search for Frontier modules...

amazingly enough this is all the frontend has to do besides package 
up the profile xml... Now in other languages/frontends it might be a
little different to implement the xmlrpc client, but there are plenty
of such examples @ http://www.xmlrpc.org

Ok now we have this frontend that knows how to send these xmlrpc messages
with an alfs profile. Now what happens on the other end?

use Frontier::Daemon;

Frontier::Daemon->new(LocalPort => 8000, 
	methods => {
            	'process_profile' => \&process_profile,
	});

sub process_profile {
#this is what is handed off to process_profile when the daemon 
#is called upon/
my $profile = shift;

#all this below is normal alfs app stuff....

my $tag_handler = new ALFS::TagHandler( debug_def  => 'no',
				        tagdir_def => '/path/to/tag_handlers'                            
				      );

my $twig = new XML::Twig( CharHandler => \&ALFS::Support::char_handler );
$twig->parse($profile);

my @elements = $twig->root->children;

foreach my $elt (@elements) {
  my $gi = $elt->gi;
  $tag_handler->$gi($elt); # here the handler gets called
}


}


and amazingly enough thats all there is to it. You can add in 
authentication, or authorization methods, send it over a ssl port, etc.etc.
Even make up new methods like say authenticate_client and then in
process_profile you have to have to the right "token" or whatever. 

When you set up your alfs app, you just run it like a daemon and fork the 
process off into the background..... The frontend could be anything 
that could send an xmlrpc message to port 8000 to this domain.com

Make sense to anyone? Or am I all alone? :)

Bryan





More information about the alfs-discuss mailing list