GO 46 !


RD Dreams

MacDizzy

DBS

YADBS

SourceForge

SIX

Rally.co.in

Rossi Files

Open Solaris

Meebo

Crash.net

MotoGP

Beginning of End

Elving's blog

Sandeep's page

Sun Forums

Air Cooled RD

MindStorms

LEGO-Robotics

Track Guide

Track Forum

M's blogs

BikesZone

Kawasaki Triples

PhRack

Metallica

Distance Running

RD Shop

SMX - Solaris Minix

Elephant Story

WD40

Dan's M/C Site

Tunnel Rats

Gatorade

Orkut

Free Science

Spiderman McBride

Racing a Fiat

Forsyth

BSM Archives

Bugatti Veyron

RNR Racing

Perl and NSAPI

Whew after a nightmarish ride through perlembed, perlglut, perlapi, perlcall blah blah, have managed to add perl support to the scripting plugin. So now, Perl code, in the form of subroutines, can be embedded in between < perl >...< / perl> tags, and those subroutines can be called from inside the scripting code. For example, here is the simple authentication script rewritten to use perl functionality:


#############################################
#                                           #        
# A simple authentication script using perl #
#                                           #        
#############################################

<perl>
use MIME::Base64;

@authlist = ("honda:CBR600", "yamaha:yzfR1", "suzuki:giXXXer", "kawasaki:NinJa");

sub checkuserpass()
{
        my ($af) = @_;

        if (!$af)
        {
                return 0;
        }

        $af = substr($af, 6);
        $af =  decode_base64($af);

        foreach $var (@authlist)
        {
                if ($af == $var)
                {
                        return 1;
                }
        }
        return 0;
}
</perl>

ret = checkuserpass($rq.headers.authorization)

if $ret == 1
then
        req proceed
fi

rq.srvhdrs.status = "401 Unauthorized!!!!"
rq.srvhdrs.WWW-authenticate = "basic realm=\"test\""

req aborted

But now, this inserts a perl dependency - to run the scripting plugin, one would need to have perl installed and configured such that:

- dynamic loading is turned on
- threading is enabled
- libperl.so is present in the perl install

Each of the above can be specified while building perl from source.

Besides, the "start" script of the Proxy/Web server should be modified to pick up libperl.so. In my case, i had the following changes:

...
...
#set LD_LIBRARY_PATH
PERLPATH=/workspace/user/tools/perl/install/lib/5.8.8/sun4-solaris-thread-multi/CORE/
LD_LIBRARY_PATH=/usr/lib/lwp:${SERVER_LIBPATH}:${LD_LIBRARY_PATH}:${MPS_LIB_DIRS}:${PERLPATH};
export LD_LIBRARY_PATH
...
...

Also, as you can see, my perl version is 5.8.8.

In a way this is a bit sad - all those commands i spent so much time to add, all those is rendered unnecessary now, because everything and much much more exists in perl.

The way it works right now, perl code have no "direct" access to nsapi data or internals. But we can construct any type, or amount, of functionality by writing perl subroutines, and then pass nsapi data to them, through, and back.

Comments [0]




Trackback URL: http://blogs.sun.com/motor/entry/perl_and_nsapi
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed