package FS::SelfService;
-use 5.006;
use strict;
-use warnings;
+use vars qw($VERSION @ISA @EXPORT_OK $socket %autoload );
+use Exporter;
+use Socket;
+use FileHandle;
+#use IO::Handle;
+use IO::Select;
+use Storable qw(nstore_fd fd_retrieve);
+
+$VERSION = '0.03';
+
+@ISA = qw( Exporter );
+
+$socket = "/usr/local/freeside/selfservice_socket";
+
+#maybe should ask ClientAPI for this list
+%autoload = (
+ 'passwd' => 'passwd/passwd',
+ 'chfn' => 'passwd/passwd',
+ 'chsh' => 'passwd/passwd',
+ 'login' => 'MyAccount/login',
+ 'customer_info' => 'MyAccount/customer_info',
+ 'invoice' => 'MyAccount/invoice',
+ 'cancel' => 'MyAccount/cancel',
+ 'payment_info' => 'MyAccount/payment_info',
+ 'process_payment' => 'MyAccount/process_payment',
+ 'signup_info' => 'Signup/signup_info',
+ 'new_customer' => 'Signup/new_customer',
+);
+@EXPORT_OK = keys %autoload;
-require Exporter;
+$ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin';
+$ENV{'SHELL'} = '/bin/sh';
+$ENV{'IFS'} = " \t\n";
+$ENV{'CDPATH'} = '';
+$ENV{'ENV'} = '';
+$ENV{'BASH_ENV'} = '';
-our @ISA = qw(Exporter);
+my $freeside_uid = scalar(getpwnam('freeside'));
+die "not running as the freeside user\n" if $> != $freeside_uid;
-# Items to export into callers namespace by default. Note: do not export
-# names by default without a very good reason. Use EXPORT_OK instead.
-# Do not simply export all your public functions/methods/constants.
+=head1 NAME
-# This allows declaration use FS::SelfService ':all';
-# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
-# will save memory.
-our %EXPORT_TAGS = ( 'all' => [ qw(
-
-) ] );
+FS::SelfService - Freeside self-service API
-our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
+=head1 SYNOPSIS
-our @EXPORT = qw(
-
-);
-our $VERSION = '0.01';
+=head1 DESCRIPTION
+Use this API to implement your own client "self-service" module.
-# Preloaded methods go here.
+If you just want to customize the look of the existing "self-service" module,
+see XXXX instead.
-1;
-__END__
-# Below is stub documentation for your module. You better edit it!
+=head1 FUNCTIONS
-=head1 NAME
+=over 4
-FS::SelfService - Perl extension for blah blah blah
+=item passwd
-=head1 SYNOPSIS
+Returns the empty value on success, or an error message on errors.
- use FS::SelfService;
- blah blah blah
+=cut
-=head1 DESCRIPTION
+foreach my $autoload ( keys %autoload ) {
+
+ my $eval =
+ "sub $autoload { ". '
+ my $param;
+ if ( ref($_[0]) ) {
+ $param = shift;
+ } else {
+ $param = { @_ };
+ }
+
+ $param->{_packet} = \''. $autoload{$autoload}. '\';
+
+ simple_packet($param);
+ }';
-Stub documentation for FS::SelfService, created by h2xs. It looks like the
-author of the extension was negligent enough to leave the stub
-unedited.
+ eval $eval;
+ die $@ if $@;
-Blah blah blah.
+}
-=head2 EXPORT
+sub simple_packet {
+ my $packet = shift;
+ socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
+ connect(SOCK, sockaddr_un($socket)) or die "connect: $!";
+ nstore_fd($packet, \*SOCK) or die "can't send packet: $!";
+ SOCK->flush;
-None by default.
+ #shoudl trap: Magic number checking on storable file failed at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/fd_retrieve.al) line 337, at /usr/local/share/perl/5.6.1/FS/SelfService.pm line 71
+ #block until there is a message on socket
+# my $w = new IO::Select;
+# $w->add(\*SOCK);
+# my @wait = $w->can_read;
+ my $return = fd_retrieve(\*SOCK) or die "error reading result: $!";
+ die $return->{'_error'} if defined $return->{_error} && $return->{_error};
-=head1 AUTHOR
+ $return;
+}
-A. U. Thor, E<lt>a.u.thor@a.galaxy.far.far.awayE<gt>
+=back
+
+=head1 BUGS
=head1 SEE ALSO
-L<perl>.
+L<freeside-selfservice-clientd>, L<freeside-selfservice-server>
=cut
+
+1;
+