NCCI Perl Documentation                               Encode(3)

 

 

 

NAME

     Encode.pl - Perl routines to encode and decode binary

     strings

 

SYNOPSIS

         # Access to modules (see the NOTES section for setup)

         BEGIN {

             ...

             push (@INC, "../sys/csbase/lib");

         }

 

         require 'Encode.pl';

 

         # Read any data from the requesting form and then

         # pick up the parameters for this script (from form

         # data or specified on the URL).

 

         my (%in) = &Encode::ReadParse;

 

         # Fetch the CGI parameter "FIELD".

 

         my ($fieldValue) = $in{"FIELD"};

 

 

DESCRIPTION

     This Perl5 library implements set of routines which encode

     and decode binary strings using a very limited subset of

     ASCII characters.  These can be used to encode strings for

     use on the HTTP protocol.

 

     Functions

 

     enc ($arg)

         Encode an arbitrary binary string into a VERY limited

         set of characters.

 

         The output has only the characters: % + - . a-z A-Z 0-9

         This routine is useful for encoding many strings which

         can have embedded characters which are 'meta-characters'

         in some 'larger context':

 

          - Passing a string as an http URL, a Cookie, or a

            Location: reference.

 

          - Inserting a string into a data file which uses

            some 'delimeter' character such as TAB or @.

 

          - Passing a string on a command line (through a

            shell) to another executable.

 

         The following transformations are done:

 

 

 

 

19/Mar/01       Last change: perl 5.004, patch 01               1

 

 

 

 

 

 

NCCI Perl Documentation                               Encode(3)

 

 

 

             Input        Output

 

             a-z A-Z 0-9  No change in these characters

             - .          No change in these characters

             (space)      +

             all other    %HH where HH is 2 upper case

                                   characters 0-9, A-F

 

 

     dec ($arg)

         Decode a string into an arbirary binary string. This

         routine undoes the work of &Encode::enc as well as the

         encodings done by all known web browsers.

 

         Plus characters are converted to spaces. Also, embedded

         %HH hexidecimal 'macros' which are converted into their

         equivalent binary representation.

 

     encodeHtml ($arg)

         Encode an arbitrary string for output to HTML.

         Basically, we remove anything which might be interpreted

         as a meta-character by the browser.  For example,

         encodeHtml () maps "<" onto "&lt;"

 

     encodeNonPrinting ($arg)

         Encode the non-printable characters in an arbitrary

         string.  Only characters between space (%20) and ~ (%7F)

         are considered OK.

 

     sanitizeFileName ($arg)

         Make the argument a valid file name on this system.

         "Dangerous" characters are encoded and the length is

         TRUNCATED to the max file name length for this system.

 

         How long can a filename be? Good question!

 

         I'd have expected the limits.h file on any Unix system

         to have this number, but SunOS 5.4 just refers you to

         pathconf().  So ... I tried some file creations of

         ordinary files and came up with 120 characters.

 

WARNING

     None

 

SEE ALSO

     G(3), GBasic(3)

 

NOTES

     This module has not yet been set up for "installation" in

     your local Perl. We currently use a set of conventions for

     access to this module, until the install procedures are

     developed:

 

 

 

19/Mar/01       Last change: perl 5.004, patch 01               2

 

 

 

 

 

 

NCCI Perl Documentation                               Encode(3)

 

 

 

     - The source code lives on development and production hosts

     in the directory /Volumes/app/cs/csbase/lib.

 

     - By convention, a project maintains perl scripts in

     subdirectories of some top-level directory, which we will

     call $TOP.

 

     - By convention, projects establish a $TOP/sys directory

     which contains a symbolic link from csbase to

     /Volummes/app/cs/csbase.

 

     - To get access to the modules, you typically include a

     BEGIN of the form:

 

         BEGIN {

             ...

             push (@INC, "../sys/csbase/lib");

         }

 

 

AUTHOR

     Clint Goss <clint@goss.com>, Feb 1997