cleanup and documentation updates
[webpac] / openisis / tcl / tspr.c
diff --git a/openisis/tcl/tspr.c b/openisis/tcl/tspr.c
deleted file mode 100644 (file)
index 6f8b229..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
-       openisis - an open implementation of the CDS/ISIS database
-       Version 0.8.x (patchlevel see file Version)
-       Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
-
-       This library is free software; you can redistribute it and/or
-       modify it under the terms of the GNU Lesser General Public
-       License as published by the Free Software Foundation; either
-       version 2.1 of the License, or (at your option) any later version.
-
-       This library is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-       Lesser General Public License for more details.
-
-       You should have received a copy of the GNU Lesser General Public
-       License along with this library; if not, write to the Free Software
-       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-       see README for more information
-EOH */
-
-/*
-       $Id: tspr.c,v 1.7 2003/06/06 10:35:38 mawag Exp $
-       OpenIsis TSP runner
-       must be binary in order to use with #! lines
-*/
-
-
-#include <stdlib.h> /* getenv */
-#include <unistd.h> /* read/write */
-
-#include "openisis.h"
-#include "openisistcl.h"
-
-#define CL_MAX 512*1024
-
-static int opc;
-static const char **opv;
-
-
-static int urldec ( OpenIsisRec **preq, const char *q, int l )
-{
-       OpenIsisRec *req = *preq;
-       const char *e = q + (0 <= l ? l : (l = strlen(q)));
-
-       while ( q < e && *q ) {
-               char *v, *p;
-               int tag, len;
-               /* assume numeric tags */
-               len = openIsisA2il( q, e-q, &tag );
-               if ( !len && opc ) {
-                       int i = opc;
-                       while ( i-- ) {
-                               int cmplen = strlen(opv[i]);
-                               if ( cmplen > e-q-1 )
-                                       cmplen = e-q-1;
-                               if ( !memcmp( opv[i], q, cmplen ) && '=' == q[cmplen] ) {
-                                       tag = i+1;
-                                       len = cmplen;
-                                       break;
-                               }
-                       }
-               }
-               q += len;
-               if ( '=' != *q || 0 >= tag ) {
-                       openIsisSMsg( OPENISIS_LOG_ERROR, "bad param %d '%.32s'", tag, q );
-                       return 1;
-               }
-               q++;
-               OPENISIS_RADD( req, tag, 0, e-q, !0 );
-               if ( ! req )
-                       return 3;
-               p = v = (char*)req->field[req->len-1].val;
-               for (;;p++,q++) {
-                       switch (*q) {
-                       case '+': *p = ' '; continue;
-                       default: *p = *q; continue;
-                       case '%': /* dehex 2 */
-                               *p = 0;
-                               q++;
-                               if ( '0' <= *q && *q <= '9' )
-                                       *p += *q - '0';
-                               else if ( 'A' <= *q && *q <= 'F' )
-                                       *p += *q - 'A' + 10;
-                               else if ( 'a' <= *q && *q <= 'f' )
-                                       *p += *q - 'a' + 10;
-                               else
-                                       return 2; /* carp bad hex */
-                               *p <<= 4;
-                               q++;
-                               if ( '0' <= *q && *q <= '9' )
-                                       *p += *q - '0';
-                               else if ( 'A' <= *q && *q <= 'F' )
-                                       *p += *q - 'A' + 10;
-                               else if ( 'a' <= *q && *q <= 'f' )
-                                       *p += *q - 'a' + 10;
-                               else
-                                       return 2;
-                               continue;
-                       case '&':
-                               q++;
-                       case 0:
-                               break;
-                       }
-                       /* hit proper end */
-                       req->used += req->field[req->len-1].len = p - v;
-                       break;
-               }
-       } /* while q */
-       *preq = req;
-       return 0;
-}
-
-
-
-#ifdef ORATCL
-extern int Oratcl_Init ( Tcl_Interp *ip );
-#endif
-#ifdef PGTCL
-extern int Pgtcl_Init ( Tcl_Interp *ip );
-#endif
-
-
-static int appinit ( Tcl_Interp *interp )
-{
-       if ( TCL_OK != Tcl_Init( interp )
-               /* done in new session
-               || TCL_OK != OpenisisTcl_Init( interp )
-               */
-#ifdef ORATCL
-               || TCL_OK != Oratcl_Init( interp )
-#endif
-#ifdef PGTCL
-               || TCL_OK != Pgtcl_Init( interp )
-#endif
-       )
-               return TCL_ERROR;
-       return TCL_OK;
-}
-
-static char prelude[] = "Content-Type: text/html\r\n\r\n";
-static char code[] = "package require openIsis 0.8\nopenIsis::Tspr $tsp";
-
-int main ( int argc, const char **argv )
-{
-       OpenIsisRec *req = 0;
-       int sid, rid, ret;
-       const char *q;
-       Tcl_Interp *interp;
-
-       if ( 2 > argc )
-               return 42;
-       opc = argc-2;
-       opv = argv+1;
-       openIsisCOpen(0);
-
-       /* Tcl_Main( argc, argv, appinit ); */
-       Tcl_FindExecutable(argv[0]); /* adds ../lib to auto_path */
-       interp = Tcl_CreateInterp();
-       appinit( interp );
-       if ( (q = getenv("SCRIPT_NAME")) )
-               OPENISIS_RADDS( req, -10, q, !0 );
-       if ( (q = getenv("PATH_INFO")) )
-               OPENISIS_RADDS( req, -11, q, !0 );
-       if ( (q = getenv("REMOTE_USER")) )
-               OPENISIS_RADDS( req, -12, q, !0 );
-       /* URL-decode env(QUERY_STRING) into request record */
-       if ( (q = getenv("QUERY_STRING")) && (ret = urldec( &req, q, -1 )) ) 
-               return ret;
-       if ( (q = getenv("CONTENT_LENGTH")) && *q ) {
-               char buf[CL_MAX+1];
-               int l = openIsisA2i( q, -1 );
-               if ( l > CL_MAX )
-                       return 4;
-               if ( !(q = getenv("CONTENT_TYPE"))
-                       || strcmp("application/x-www-form-urlencoded", q)
-               )
-                       return 5;
-               if ( l != read( 0, buf, l ) )
-                       return 6;
-               buf[l] = 0;
-               if ( (ret = urldec( &req, buf, l )) )
-                       return ret;
-       }
-       sid = openIsisTclNewSession( interp );
-       rid = openIsisTclCreateRecCmd( sid, "request", 0, 0 );
-
-       Tcl_SetVar( interp, "tsp", (char*)argv[argc-1], 0 );
-       write( 1, prelude, sizeof(prelude)-1 );
-       if ( openIsisTclEval( sid, 1, &rid, &req, code ) ) {
-               const char *errorInfo
-                       = Tcl_GetVar( interp, "errorInfo", TCL_GLOBAL_ONLY );
-               openIsisSMsg( OPENISIS_LOG_ERROR, "error in tsp\n%s",
-                       errorInfo ? errorInfo : "-" );
-               return 3;
-       }
-       return 0;
-}