root/tags/5.4.pre05/wxis_src/xis.c

Revision 1, 35.5 kB (checked in by heitor.barbieri, 4 years ago)

Criação do svn para Cisis.

Line 
1/* ------------------------------------------------------------------- XIS.C */
2
3/* /////////////////////////////////////////////////////////////////////////
4
5   [ Version 0.6 ]
6   03.Mar.1999 - XML Isis Script.
7
8   [ Version 0.7 ]
9   22.Mar.1999 - "programPath": To find files in the same path of the program.
10
11   [ Version 0.8 ]
12   29.Mar.1999 - "cpl_Load": Check close element couple;
13   30.Mar.1999 - "efc_split_lines_char": CR/LF problem;
14   31.Mar.1999 - "exePrint": check command parameter presence.
15
16   [ Version 0.8a ]
17   05.Apr.1999 - "exeFieldOcc": Get specific occurrence.
18
19   [ Version 0.9 ]
20   12.Apr.1999 - "main": Check license after xisArgRead and xisCgi;
21   13.Apr.1999 - "path_source": Set environment variable;
22   14.Apr.1999 - "ATVALUE_PREFIX": substitute for ATVALUE_PFXTAG;
23   14.Apr.1999 - "PATH_WXIS": substitute for PATH_SOURCE;
24   14.Apr.1999 - "exeCgiTable": allowing CGI prefix tag.
25
26   [ Version 0.9a ]
27   15.Apr.1999 - "exeCall": previous index is set with the caller index.
28
29   [ Version 0.9b ]
30   15.Apr.1999 - "exePft": htmlpft convertion;
31
32   [ Version 0.9c ]
33   16.Apr.1999 - "exeScopeClose": parameter scopeVar -> localScopeVar;
34   16.Apr.1999 - "efc_split_lines_char": avoid empty buffer memory fault;
35   16.Apr.1999 - "exeTaskFullInvertion": internal key sort format and length;
36   16.Apr.1999 - "PRECISE_GETNEW": GetNew argument value, useful for appending new records.
37
38   [ Version 0.9d ]
39   26.Apr.1999 - "exeLoop": accepts <parm name=task>...</parm>;
40   27.Apr.1999 - "ELEMENT_RETURN": exit from current function;
41   28.Apr.1999 - "ELEMENT_DISPL": synonymous for ELEMENT_DISPLAY;
42   04.May.1999 - "exeTaskInvertedLoad": need iflind.
43
44   [ Version 0.9e ]
45   11.May.1999 - "cib62.c": b53_writx/b53_seek, fixed;
46   12.May.1999 - "cib51.c, cib62.c": "$" search fixed.
47
48   [ Version 0.9f ]
49   20.May.1999 - "svdifload": mfnread--, first LE2 missing key fixed.
50
51   [ Version 0.9g ]
52   26.May.1999 - "exeTaskDo": exePos() sets Isis_Current value;
53   28.May.1999 - "exeLock": expired lock need to change the lock id field;
54   31.May.1999 - "exeExpire": gap time <= expire value returns not expired;
55   31.May.1999 - "ATVALUE_RESET": ifupdat, ifload -reset flag;
56   31.May.1999 - "PRECISE_WNOUNLOCK": write but not unlock (keep locked);
57   31.May.1999 - "exeTaskUpdate": PRECISE_LOCK, PRECISE_STATUS don't propagate.
58
59   [ Version 1.0 ]
60   08.Jun.1999 - "cplToken": XML instructions as comments <? ... ?> and <! ... >;
61   15.Jun.1999 - "xisLicense": license checks the new version expire limit date;
62   16.Jun.1999 - "RLINE": sequential import type;
63   16.Jun.1999 - "exeTaskFullInvertion": fast, fix extract, mastersort via field and fix inverted load;
64   17.Jun.1999 - "exePft": allows format syntax check;
65   17.Jun.1999 - "exeFieldTransf": import and export actions with tag list, respect previous attribute;
66   29.Jun.1999 - "exeParm": allows fst syntax check;
67   29.Jun.1999 - "exeParm": buffer size attribute value;
68   06.Jul.1999 - "exeFieldTransf": if (keep) { ... while (isdigit(*(p+1))) p++; };
69   13.Jul.1999 - "PRECISE_ITEMS": PRECISE_ITENS spelling mistake;
70   15.Jul.1999 - "xisArgRead": call xisCgi for all in file parameters;
71   30.Jul.1999 - "exeTaskList": interprets "from=" and "to=" parameters;
72   04.Aug.1999 - "exeExtract": efc_free(lnk1p) and efc_free(lnk2p);
73   23.Sep.1999 - "exeCgiSubfld": avoid empty value;
74   27.Sep.1999 - "exeFieldSplit": attribute type=list.
75
76   [ Version 1.1 ]
77   28.Sep.1999 - "xisLicense": use REMOTE_ADDR and REMOTE_HOST instead of SERVER_NAME;
78   28.Sep.1999 - "exeFieldDir": attribute type=delete.
79
80   [ Version 1.2 ]
81   26.Oct.1999 - "exeCopyFile": copy file functionality;
82   04.Nov.1999 - "exeTaskMfnrange": the Isis_Status can handle the RCLOCK;
83   12.Nov.1999 - "exeFileTemp": temporary file can be at CI_TEMPDIR directory;
84   17.Nov.1999 - "exeTaskSearch": dbxtmpnm() instead of tmpnam();
85   13.Dec.1999 - "exeHtmlPft": entity must remain untouched;
86   07.Jan.2000 - "cifm3.c": date(DATEONLY) and date(DATETIME) bug.
87
88   [ Version 4.0 ]
89   07.Jan.2000 - WXIS will be first released as WWWISIS version 4.0;
90   22.Feb.2000 - "ELEMENT_INCLUDE": the include functionality;
91   23.Feb.2000 - "xisFileContent": first try is the original file name;
92   23.Feb.2000 - "xisFileContent": not found message is the original file name;
93   28.Feb.2000 - "exeJump": jump to a label inside a <include> element;
94   09.Mar.2000 - Compiled save;
95   10.Mar.2000 - Compiled run;
96   13.Mar.2000 - Avoid trace over compiled instruction;
97   20.Mar.2000 - "xisLicense": remoteAddr,remoteHost use cgi_getenv instead of getenv;
98   08.Jun.2000 - "xisLicense": allows script name based lincense;
99   26.Jun.2000 - "exeExport": export direct to the standard output export;
100   13.Jul.2000 - "exeExport": export ISO forcing CRLF;
101   14.Ago.2000 - "stwTable": PARM_STW correct load;
102   25.Ago.2000 - "exeCmd/ELEMENT_TRACE": activate/deactivate dbxtrace & Cia;
103   08.Sep.2000 - "arglist.c/arg_lines": avoid memory invasion;
104   08.Sep.2000 - "exeExtractSave": allow in-place field add via FST;
105   26.Sep.2000 - "cirec.c/mstsetup": avoid fatal("mstsetup/ALLOMAXV/.xrf");
106   27.Nov.2000 - "PARM_PREFIX_HTMLPFT/PARM_SUFFIX_HTMLPFT": to be different from the hl prefix and suffix;
107    27.Nov.2000 - "exeFile/ATVALUE_DELETE" uses the cipar file name translation;
108
109   [ Version 4.1 ]
110    27.Nov.2000 - "<include>" accepts compiled script;
111    28.Nov.2000 - 'tag="first line"': allows to specify the tag via a format for the <field> element;
112
113   [ Version 4.2 ]
114    20.Dez.2000 - "cib7": New search engine;
115    30.Jan.2001 - "PARM_POSTTAG": accepts tag list;
116    15.Feb.2001 - "exeField": check action= attribute presence.
117
118   [ Version 4.3 ]
119    23.Feb.2001 - "<isisxml>": generate XML data;
120    28.Feb.2001 - "cib7p": moved from global to SEARCH_VAR to allow multiple search;
121    13.Mar.2001 - "exeSearchCisisPropagateQualifier": iah style feature.
122
123   [ Version 5.0 ]
124   14.Mar.2001 - WXIS with the b7 search will be released as WWWISIS version 5.0;
125   25.Mar.2001 - ISISXML_STYLE_EDIT;
126   05.Apr.2001 - <parm name="log">: on task search;
127   05.Apr.2001 - <field action="define" tag="1098">Isis_SetNumber</field>: on task search;
128   27.Apr.2001 - "cixml.c" module;
129
130   [ Version 5.1 ]
131   03.May.2001 - "xisVar.argList[ARG_SCRIPT].text = getenv("PATH_TRANSLATED")";
132   22.Jun.2001 - "cib72.c": if (tmp) - 29 quoted search key error;
133   21.Sep.2001 - "cib71.c": b7_cib7_delete implemented.
134
135   [ Version 5.2 ]
136   03.Oct.2001 - "cib72.c/b7_run": FREE(vtrmp[b7itrm]);
137   29.Nov.2001 - "exePft()": set isisxml_style before isisxml_load;
138   05.Dec.2001 - "cixmlLoad": new parameter: default_style;
139   18.Mar.2002 - "xisFileContent": not found message is "IsisScript".
140
141   [ Version 5.3 ]
142   07.Aug.2002 - "cib72.c": if (tmp) - 29 quoted search key error; (AGAIN in CISIS)
143   07.Aug.2002 - "cisis 4.1r1": #define CIFFI 0.
144
145   [ Version 5.4 ]
146   11.Feb.2003 - "cib72.c": (G), (F) and related operators OK.
147   14.Feb.2003 - "cisis 4.2r0": #define CIFFI 0.
148   27.Feb.2003 - "cib72.c": b7_pfx - if ( aspas )...
149
150   [ Version 6.0 ]
151   07.Aug.2002 - "cisis 4.1r1": #define CIFFI 1.
152   14.Feb.2003 - "cisis 4.2r0": #define CIFFI 1.
153   27.May.2003 - "cisis 4.3a": record update with FFI (linux)
154
155   [ Version 7.0 ]
156   02.Sep.2003 - "LICENSED_VERSION": may be compiled without license
157
158   [ Version 7.0a ]
159   02.Feb.2006 - iso/marc import and export
160
161   [ Version 7.1 ]
162   02.Feb.2007 - from now wxis will not be compiled with license.
163                 CIFII and isis compilation will have the same version number.
164                 the release date is generated automatically
165
166   [ Version 7.1a ]
167   20.Mar.2007 - temporary search files are not longer created.
168
169   [ Version 7.1b ]
170   16.May.2007 - .iso export marc bug fixed
171
172   [ Version 7.1c ]
173   19.Jul.2007 - the release date can not be generated automatically
174
175   [ Version 7.1d ]
176   26.Oct.2007 - security issue - now wxis check if the isis script file
177                 name ends with *.xis or *.xis
178   ///////////////////////////////////////////////////////////////////////// */
179
180/* ----------------------------------------------------------- C HEADER FILE */
181#include <time.h>
182#include <stdio.h>
183#include <string.h>
184/* #include <mem.h> */
185/* ------------------------------------------------------------- HEADER FILE */
186#include "../cisis.h"
187#include "../cirun.h"
188#include "easyfc.h"
189#include "arglist.h"
190#include "cgilist.h"
191#include "freqlist.h"
192#include "xis_comp.h"
193#include "xis_exec.h"
194#include "hide.h"
195/* #include "chronometer.h" */
196/* ------------------------------------------------------------------ define */
197
198#define LICENSED_VERSION    0
199#define XIS_VERSION         "?XML IsisScript WWWISIS 7.1d"  /* xis version */
200#define XIS_RELEASE_DATE     __DATE__ /*"20080925"*/
201
202#define XIS_LICENSE         "wxis.lic"  /* xis license file */
203#define XIS_LICDATE         20030525L   /* xis license date */
204#define XIS_LICTIME         10000L      /* xis license time (one year) */
205#define XIS_LICMIN          19990600L   /* xis license smaller date */
206#define XIS_COMPILED_EXT    ".xic"      /* xis compiled file extension */
207#define MAX_IN_ARGV         512         /* limit of arguments */
208
209#ifndef XIS_SERVER
210#define GEN_MAIN 1
211#define XIS_ERR(x,y,z)  exit(xisError(x,y))
212#define XIS_ERR2(x,y,z) xisError(x,y)
213#else
214#define GEN_MAIN 0
215#define XIS_ERR(x,y,z)  return xisServerError(x,y,z)
216#define XIS_ERR2(x,y,z) xisServerError(x,y,z)
217#endif /* XIS_SERVER */
218
219OUT_BUFFER *outBuff;
220int firstTime = 0;
221
222/* ------------------------------------------------------------- enumeration */
223typedef enum {
224   XIS_ERROR_OK,
225   XIS_ERROR_ALLOC,
226   XIS_ERROR_ARGS,
227   XIS_ERROR_CGI,
228   XIS_ERROR_COMPILED,
229   XIS_ERROR_COMPILER,
230   XIS_ERROR_EXECUTION,
231   XIS_ERROR_FATAL,
232   XIS_ERROR_FILE,
233   XIS_ERROR_MISSING,
234   XIS_ERROR_LICENSE,
235   XIS_ERROR_QTT
236} XIS_ERROR;                    /* error */
237
238typedef enum {
239   ARG_ARGS,
240   ARG_COMPILE,
241   ARG_HELLO,
242   ARG_IN,
243   ARG_SCRIPT,
244   ARG_SOURCE,
245   ARG_WHAT,
246   ARG_LIST_QTT
247} ARG_LIST;                 /* argument */
248
249typedef enum {
250   LICERROR_OK,
251   LICERROR_FILE,
252   LICERROR_INVALID,
253   LICERROR_EXPIRED,
254   LICERROR_UNAUTHO,
255   LICERROR_MISSING,
256   LICERROR_LIST_QTT
257} LICERROR_LIST;           /* license error */
258/* --------------------------------------------------------------- structure */
259typedef struct {
260   char            *programPath;
261   STRUCT_ARGUMENT argList[ARG_LIST_QTT];
262   EFC_ERROR       error;
263   CGI_PARAM       *cgiList;
264   char            *licenseText;
265   char            *pathTranslated;
266   char            *script;
267   CPL_STRUCT      xisProgram;
268} XIS_VAR;                     /* variables */
269/* ------------------------------------------------------------------ global */
270char *xisVersion = XIS_VERSION;                 /* xis version */
271char *xisLicenseFile = XIS_LICENSE;             /* xis license file */
272char path_source[PATH_NAME_LEN+1];              /* PATH_SOURCE putenv */
273
274/* ============================================================ xisErrorText */
275char *xisErrorText(XIS_ERROR errorCode)     /* XIS error code */
276{
277
278    /* Return corresponding error text */
279   switch (errorCode) {
280   case XIS_ERROR_OK:           return "no error";
281   case XIS_ERROR_ALLOC:        return "memory allocation";
282   case XIS_ERROR_ARGS:         return "argument";
283   case XIS_ERROR_CGI:          return "cgi parameter";
284   case XIS_ERROR_COMPILED: return "compiled";
285   case XIS_ERROR_COMPILER: return "compiler";
286   case XIS_ERROR_EXECUTION:    return "execution";
287   case XIS_ERROR_FATAL:        return "fatal";
288   case XIS_ERROR_FILE:         return "file";
289   case XIS_ERROR_MISSING:      return "missing";
290   case XIS_ERROR_LICENSE:      return "license";
291   } /* switch */
292
293    /* Return undefined error code message */
294   return "undefined message";
295
296} /* xisErrorText */
297
298/* ========================================================== xisErrorDetail */
299char *xisErrorDetail(EFC_ERROR *error,          /* error structure */
300                     XIS_ERROR errorCode)       /* XIS error code */
301{
302
303    /* Return corresponding error text */
304   switch (errorCode) {
305   case XIS_ERROR_OK:           return "success";
306   case XIS_ERROR_ALLOC:        return "not enough";
307   case XIS_ERROR_ARGS:
308   case XIS_ERROR_CGI:
309   case XIS_ERROR_FILE:
310    switch (error->code) {
311    case FILE_ERROR_SIZE:
312    case -FILE_ERROR_SIZE:  return "file size";
313    case FILE_ERROR_OPEN:
314    case -FILE_ERROR_OPEN:  return "file open";
315    case FILE_ERROR_ALLOC:
316    case -FILE_ERROR_ALLOC: return "memory allocation";
317    case FILE_ERROR_READ:
318    case -FILE_ERROR_READ:  return "file read";
319    case ARG_ERROR_MAX:
320    case -ARG_ERROR_MAX:        sprintf(error->info,"%d",MAX_IN_ARGV);
321                                    return "argument limit exceeded";
322      } /* switch */
323      break;
324   case XIS_ERROR_COMPILED:
325    switch (error->code) {
326    case CPL_ERROR_READ:                return "read";
327      } /* switch */
328      break;
329   case XIS_ERROR_COMPILER:
330    switch (error->code) {
331    case CPL_ERROR_ALLOC:           return "memory allocation";
332    case CPL_ERROR_INVALID:         return "invalid identifier";
333    case CPL_ERROR_MISSING:         return "missing";
334    case CPL_ERROR_PATHNAMELEN: return "path name lenght";
335    case CPL_ERROR_NOTFOUND:        return "file not found";
336    case CPL_ERROR_FILE:                return "file";
337    case CPL_ERROR_WRITE:           return "write";
338      } /* switch */
339      break;
340   case XIS_ERROR_EXECUTION:
341    switch (error->code) {
342    case EXE_ERROR_ACTAB:   return "actab";
343    case EXE_ERROR_ALLOC:   return "memory allocation";
344    case EXE_ERROR_EXTRACT: return "extract";
345    case EXE_ERROR_FIELD:   return "field";
346    case EXE_ERROR_FILE:        return "file";
347    case EXE_ERROR_FORMAT:  return "format syntax";
348    case EXE_ERROR_FST:     return "fst";
349    case EXE_ERROR_IMPORT:  return "import";
350    case EXE_ERROR_INVALID: return "invalid value";
351    case EXE_ERROR_MAXNREC: return "record index overflow";
352    case EXE_ERROR_MAXNTRM: return "term index overflow";
353    case EXE_ERROR_MISSING: return "missing";
354    case EXE_ERROR_MSRT:        return "master sort";
355    case EXE_ERROR_PROC:        return "proc";
356    case EXE_ERROR_RETURN:  return "return";
357    case EXE_ERROR_SORT:        return "sort";
358    case EXE_ERROR_STW:     return "stop word";
359    case EXE_ERROR_SEARCH:  return "search";
360        case EXE_ERROR_TARGET:  return "label not found (same scope)";
361    case EXE_ERROR_UCTAB:   return "uctab";
362    case EXE_ERROR_UNDEFINED:
363                                    return "undefined instruction";
364      } /* switch */
365      break;
366   case XIS_ERROR_FATAL:        return "unavoidable";
367   case XIS_ERROR_MISSING:      return "parameter";
368   case XIS_ERROR_LICENSE:      return "unauthorized";
369   } /* switch */
370
371    /* Return undefined error code message */
372    sprintf(error->info,"%d/%d",errorCode,error->code);
373    return "undefined message";
374
375} /* xisErrorDetail */
376
377/* ================================================================ xisError */
378XIS_ERROR xisError(EFC_ERROR *error,        /* error structure */
379                   XIS_ERROR errorCode)     /* WIS error code */
380{
381   char *text;         /* error message text */
382   char *detail;        /* error message detail */
383
384    /* Return exit command code, without any message */
385    if (errorCode == XIS_ERROR_EXECUTION && error->code == EXE_ERROR_EXIT)
386        return atoi(error->info);
387
388    /* Prepare message */
389    text = xisErrorText(errorCode);
390    detail = xisErrorDetail(error,errorCode);
391
392    /* Show XIS error line */
393   printf("\nWXIS|%s error|%s|%s|\n",text,detail,error->info);
394
395    /* Return error code */
396   return errorCode;
397
398} /* xisError */
399
400#ifdef XIS_SERVER
401/* ========================================================== xisServerError */
402XIS_ERROR xisServerError(EFC_ERROR *error,          /* error structure */
403                         XIS_ERROR errorCode,       /* WIS error code */
404                         XIS_VAR *xisVar)
405{
406    char *text;         /* error message text */
407    char *detail;       /* error message detail */
408    char mess[256];
409
410    /* Return exit command code, without any message */
411    if (errorCode == XIS_ERROR_EXECUTION && error->code == EXE_ERROR_EXIT)
412      return atoi(error->info);
413
414    /* Prepare message */
415    text = xisErrorText(errorCode);
416    detail = xisErrorDetail(error,errorCode);
417
418    /* Show XIS error line */
419    sprintf(mess, "\nWXIS_SERVER|%s error|%s|%s|\n",text,detail,error->info);
420    writeBuff(mess, outBuff, 0);
421
422    /* Return error code */
423   return errorCode;
424
425} /* xisError */
426#endif /* XIS_SERVER */
427
428/* ============================================================== wwwi_fatal */
429#ifdef XIS_SERVER
430void wwwi_fatal(char *fatal_msg) {
431    printf("FATRAP flag should be on.\n");
432    exit(1);
433}
434#else
435void wwwi_fatal(char *fatal_msg)
436{
437    EFC_ERROR err;
438
439    /* Set fatal message */
440   efc_error(&err,fatal_errcod,fatal_msg);
441
442    /* Show message, exit with error code */
443    exit(xisError(&err,XIS_ERROR_FATAL));
444
445} /* wwwi_fatal */
446#endif
447
448/* ========================================================== xisFileContent */
449char *xisFileContent(XIS_VAR *xisVar,   /* XIS variables */
450                     char *fileName)    /* file name */
451{
452    char *p;                        /* file content buffer pointer */
453    char pathName[PATH_NAME_LEN+1]; /* auxiliary file name complement */
454
455   /* [4.1] Get file content, try with the original file name */
456   p = efc_std_filecontent(&(xisVar->error),fileName);
457    xisVar->xisProgram.pathSource = "";
458    if (p) return p;
459
460   /* Get file content, try with the program path */
461    sprintf(pathName,"%s%s",xisVar->programPath,fileName);
462   p = efc_std_filecontent(&(xisVar->error),pathName);
463    xisVar->xisProgram.pathSource = xisVar->programPath;
464    if (p) return p;
465
466   /* If file not found, try with the CGI path translated */
467   if (!p && xisVar->error.code == -FILE_ERROR_OPEN) {
468        if (strlen(xisVar->pathTranslated) + strlen(fileName) > PATH_NAME_LEN)
469            fatal("PATH_NAME_LEN");
470        sprintf(pathName,"%s%s",xisVar->pathTranslated,fileName);
471        p = efc_std_filecontent(&(xisVar->error),pathName);
472    xisVar->xisProgram.pathSource = xisVar->pathTranslated;
473    }
474
475   /* If error, exit */
476   if (!p) {
477    efc_error(&(xisVar->error),FILE_ERROR_OPEN,"Isis_Script");//fileName);
478    XIS_ERR2(&(xisVar->error),XIS_ERROR_FILE, xisVar);
479   }
480
481   /* Return allocated buffer */
482   return p;
483
484} /* xisFileContent */
485
486/* ========================================================== xisLicenseInfo */
487void xisLicenseInfo(void)
488{
489    time_t tim = time(NULL);
490    struct tm *now = localtime(&tim);
491
492    printf("\nWXIS release date: %s\n",  XIS_RELEASE_DATE);
493}
494
495/* =========================================================== xisArgInstant */
496void xisArgInstant(XIS_VAR *xisVar)     /* XIS variables */
497{
498
499    /* Interpret instant parameters */
500   if (xisVar->argList[ARG_HELLO].text) {
501    printf("Content-type: text/plain\n\n%s",cicopyr(xisVersion));
502      xisLicenseInfo();
503   }
504   if (xisVar->argList[ARG_WHAT].text) {
505    printf("%s",cicopyr(xisVersion));
506      xisLicenseInfo();
507   }
508
509} /* xisArgInstant */
510
511/* ================================================================== xisRun */
512XIS_ERROR xisRun(XIS_VAR *xisVar)   /* XIS variables */
513{
514   XIS_ERROR errorCode = XIS_ERROR_OK;     /* XIS error code */
515   CPL_CMD_LIST cmdList;                   /* sub-command list */
516   int len;
517   char * ext;
518
519    /* Get script parameter */
520    if (xisVar->argList[ARG_SCRIPT].text) {
521
522        /* Check if the script file ends with .xis/.xic for security reasons */
523      len = strlen(xisVar->argList[ARG_SCRIPT].text);
524      ext = xisVar->argList[ARG_SCRIPT].text + (len - 1);
525
526      while ((len >= 5) && (ext == ' ')) {
527        *ext-- = 0;
528         len--;
529      }
530      if (len < 5) { /* x.xis */
531                        efc_free(xisVar->programPath); xisVar->programPath = NULL;// Code Guard
532         XIS_ERR(&(xisVar->error),efc_error(&(xisVar->error),XIS_ERROR_MISSING,"IsisScript expected"), xisVar);
533      }
534      ext = xisVar->argList[ARG_SCRIPT].text + (len - 4);
535#if UNIX
536      if (!((strcasecmp(ext, ".xis") == 0) || (strcasecmp(ext, ".xic") == 0))) {
537#else /* UNIX */
538      if (!((stricmp(ext, ".xis") == 0) || (stricmp(ext, ".xic") == 0))) {
539#endif /* UNUX */
540                        efc_free(xisVar->programPath); xisVar->programPath = NULL;// Code Guard
541         XIS_ERR(&(xisVar->error),efc_error(&(xisVar->error),XIS_ERROR_MISSING,"IsisScript expected"), xisVar);
542      }
543
544        /* Not compiled */
545      if (!cplIsCompiled(&(xisVar->xisProgram),xisVar->argList[ARG_SCRIPT].text)) {
546        /* Get script file content, set xisVar->xisProgram.pathSource */
547        xisVar->script = xisFileContent(xisVar,xisVar->argList[ARG_SCRIPT].text);
548        if (!xisVar->script) {   // MUDAR !!!
549            return XIS_ERROR_MISSING;
550            //XIS_ERR(&(xisVar->error),efc_error(&(xisVar->error),XIS_ERROR_MISSING,xisVar->argList[ARG_SCRIPT].id), xisVar);
551        }
552
553        /* Load program instructions */
554        xisVar->xisProgram.printSource = (BOOLEAN)xisVar->argList[ARG_SOURCE].num;
555        if (cplCompile(xisVar->script,&(xisVar->xisProgram))) {
556            errorCode = XIS_ERR2(&(xisVar->xisProgram.error),XIS_ERROR_COMPILER, xisVar);
557        }
558
559        /* Compiled */
560        } else {
561
562                /* Load compiled instructions */
563         if (cplLoadCompiled(xisVar->argList[ARG_SCRIPT].text,&(xisVar->xisProgram),&(xisVar->xisProgram.cmd),&cmdList)) {
564                errorCode = XIS_ERR2(&(xisVar->xisProgram.error),XIS_ERROR_COMPILER, xisVar);
565         }
566      }
567
568    /* No script parameter present */
569    } else {
570        efc_free(xisVar->programPath); xisVar->programPath = NULL;// Code Guard
571        XIS_ERR(&(xisVar->error),efc_error(&(xisVar->error),XIS_ERROR_MISSING,xisVar->argList[ARG_SCRIPT].id), xisVar);
572   }
573
574    /* No error */
575   if (!errorCode) {
576
577    /* Write compiled instructions required  */
578    if (xisVar->argList[ARG_COMPILE].text) {
579
580        /* Save compiled */
581        if (cplSaveCompiled(&(xisVar->xisProgram),xisVar->argList[ARG_COMPILE].text)) {
582            errorCode = XIS_ERR2(&(xisVar->xisProgram.error),XIS_ERROR_COMPILER, xisVar);
583        }
584
585    /* Normal run */
586      } else {
587        /* Execute program */
588        if (exeRun(&(xisVar->xisProgram),xisVar->cgiList, outBuff)) {
589            errorCode = XIS_ERR2(&(xisVar->xisProgram.error),XIS_ERROR_EXECUTION, xisVar);
590        }
591      }
592   }
593
594   /* Garbage collector */
595   cplFree(xisVar->xisProgram.cmd);
596
597   /* Return error code */
598    return errorCode;
599
600} /* xisRun */
601
602/* ============================================================== xisArgShow */
603void xisArgShow(XIS_VAR *xisVar,        /* XIS variables */
604                     int argc,              /* quantity of arguments */
605                     char *argv[])          /* array of arguments */
606{
607   int argI;        /* argument loop index */
608
609    /* Check show flag */
610    if (!xisVar->argList[ARG_ARGS].text) return;
611
612    /* Show argument list title */
613    printf("\n[%s]\n",argv[0]);
614
615    /* Show all arguments */
616    for (argI = 1; argI < argc; argI++)
617        printf("%3d) %s\n",argI,argv[argI]);
618
619} /* xisArgShow */
620
621/* ================================================================== xisCgi */
622XIS_ERROR xisCgi(XIS_VAR *xisVar,   /* XIS variables */
623                 int argc,          /* quantity of arguments */
624                 char *argv[])      /* array of arguments */
625{
626   CGI_PARAM *cgiHead = NULL;       /* cgi parameter header */
627   CGI_PARAM *cgiAux = NULL;        /* auxiliary cgi parameter pointer */
628   int argI;                        /* argument loop index */
629   char *cgiCouple;                 /* cgi couple parameter name=value */
630
631    /* Get CGI parameter list */
632   if (!xisVar->cgiList) {
633       xisVar->cgiList = cgi_read(&(xisVar->error));
634       if (xisVar->error.code) return XIS_ERROR_CGI;
635   }
636
637    /* Get arguments as CGI parameter */
638   for (argI = 1; argI < argc; argI++) {
639      cgiCouple = strdup(argv[argI]);
640      if (!cgiCouple) XIS_ERR(&(xisVar->error),XIS_ERROR_ALLOC, xisVar);
641      cgiAux = cgi_newparam(&(xisVar->error),cgiAux,cgiCouple);
642      if (!cgiAux) XIS_ERR(&(xisVar->error),XIS_ERROR_ALLOC, xisVar);
643      if (!cgiHead) cgiHead = cgiAux;
644   }
645
646    /* Join the two list */
647   if (xisVar->cgiList) {
648       for (cgiAux = xisVar->cgiList; cgiAux->next; cgiAux = cgiAux->next);
649       cgiAux->next = cgiHead;
650   } else xisVar->cgiList = cgiHead;
651
652    /* Return no error */
653   return XIS_ERROR_OK;
654
655} /* xisCgi */
656
657/* ============================================================== xisArgRead */
658int xisArgRead(XIS_VAR *xisVar, /* XIS variables */
659               int argc,        /* quantity of arguments */
660               char *argv[])    /* arrray of arguments */
661{
662   char *inArgV[MAX_IN_ARGV];    /* in arguments array */
663   int inArgC;                          /* in arguments quantity */
664   int argI;                            /* arguments list index */
665
666    /* Access command line arguments */
667    arg_read(xisVar->argList,ARG_LIST_QTT,argv,1,argc);
668
669    /* Set instant arguments */
670   xisArgInstant(xisVar);
671
672    /* Show arguments */
673    xisArgShow(xisVar,argc,argv);
674
675    /* Loop while infile argument present */
676    while (xisVar->argList[ARG_IN].text) {
677
678        /* Set argument list title */
679        inArgV[0] = xisVar->argList[ARG_IN].text;
680
681        /* Split infile, generate argument list, on error return -ARG_ERROR_LIST */
682        inArgC = arg_in(inArgV,1,MAX_IN_ARGV,xisVar->argList[ARG_IN].text);
683       if (inArgC < 0) return efc_error(&(xisVar->error),inArgC,xisVar->argList[ARG_IN].text);
684        xisVar->argList[ARG_IN].text = NULL;
685
686        /* Access infile arguments */
687        arg_read(xisVar->argList,ARG_LIST_QTT,inArgV,0,inArgC);
688
689        /* Store CGI parameters, on error exit */
690        if (xisCgi(xisVar,inArgC,inArgV))
691            XIS_ERR(&(xisVar->error),XIS_ERROR_CGI, xisVar);
692
693        /* Show valid arguments */
694       xisArgInstant(xisVar);
695
696        /* Show infile arguments */
697        xisArgShow(xisVar,inArgC,inArgV);
698
699   } /* while */
700
701    /* Show valid arguments */
702    if (xisVar->argList[ARG_ARGS].text) {
703        printf("\n[Isis Script]\n");
704        for (argI = 0; argI < ARG_LIST_QTT; argI++)
705        if (xisVar->argList[argI].text) {
706            printf("  %s",xisVar->argList[argI].id);
707             if (xisVar->argList[argI].id_type != ARG_TYPE_BOOLEAN)
708                printf("=%s",xisVar->argList[argI].text);
709            printf("\n");
710         }
711   }
712
713    /* Return no error */
714   return 0;
715
716} /* xisArgRead */
717
718/* ============================================================== xisArgLoad */
719void xisArgLoad(XIS_VAR *xisVar)        /* XIS variables */
720{
721
722    /* Load all arguments */
723    arg_load(&(xisVar->argList[ARG_ARGS]),      "args",         ARG_TYPE_BOOLEAN);
724    arg_load(&(xisVar->argList[ARG_COMPILE]),   "compile",      ARG_TYPE_TEXT);
725    arg_load(&(xisVar->argList[ARG_HELLO]),     "hello",        ARG_TYPE_BOOLEAN);
726    arg_load(&(xisVar->argList[ARG_IN]),        "in",           ARG_TYPE_TEXT);
727    arg_load(&(xisVar->argList[ARG_SCRIPT]),    "IsisScript",   ARG_TYPE_TEXT);
728    arg_load(&(xisVar->argList[ARG_SOURCE]),    "+source",      ARG_TYPE_BOOLEAN);
729    arg_load(&(xisVar->argList[ARG_WHAT]),      "what",         ARG_TYPE_BOOLEAN);
730
731} /* xisArgLoad */
732
733/* ======================================================== xisGetIsisScript */
734char *xisGetIsisScript(CGI_PARAM *cgip) /* cgi list item */
735{
736    char *p;            /* auxiliary loop pointer */
737   int pos;         /* auxiliary loop string position */
738
739    /* Find IsisScript */
740   for (; cgip; cgip = cgip->next) {
741        if (strcmp("IsisScript",cgip->name) == 0) {
742        p = cgip->value;
743         pos = strlen(cgip->value);
744        for (p += pos; pos; p--, pos--) {
745                if (*p == '\\' || *p == '/') {
746                p++;
747                break;
748            }
749         }
750        return p;
751      }
752   } /* for */
753
754   /* parameter IsisScript not found */
755   return NULL;
756
757} /* xisGetIsisScript */
758
759#if LICENSED_VERSION
760/* ============================================================== xisLicense */
761#define LICENSE_TYPE_POS    21      /* 19993112 174009 5 365x */
762                                            /* 012345678901234567890x */
763LICERROR_LIST xisLicense(XIS_VAR *xisVar,       /* XIS variables */
764                                 char *fileName)        /* license file name */
765{
766   char licenseType;                        /* license type */
767   char *p;                                 /* file content buffer */
768   char *remoteAddr;                        /* remote address */
769   char *remoteHost;                        /* remote host */
770   char *localAddr = "127.0.0.1";   /* authorized local address */
771   char *localHost = "localhost";   /* authorized local host */
772    EFC_SPLIT_LINES table;              /* split line structure */
773   long line;                               /* line index */
774   long licenseDate;                /* authorized license date */
775   LICERROR_LIST licensed = LICERROR_UNAUTHO;   /* licensed flag */
776
777   /* 1.1 */
778    /* Check remote address or host */
779   remoteAddr = cgi_getenv("REMOTE_ADDR");
780   remoteHost = cgi_getenv("REMOTE_HOST");
781    if (strcmp(remoteAddr,localAddr) == 0) return LICERROR_OK;
782    if (strcmp(remoteAddr,localHost) == 0) return LICERROR_OK;
783    if (strcmp(remoteHost,localAddr) == 0) return LICERROR_OK;
784    if (strcmp(remoteHost,localHost) == 0) return LICERROR_OK;
785
786    /* Check local server name */
787/* 1.0
788    if (strcmp(xisVar->licenseText,"localhost") == 0) return LICERROR_OK;
789    if (strcmp(xisVar->licenseText,"127.0.0.1") == 0) return LICERROR_OK;
790*/
791
792    /* Get license file content */
793   p = xisFileContent(xisVar,fileName);
794   if (!*p) return LICERROR_FILE;
795
796   /* Split lines */
797    efc_split_lines(&table,p);
798
799   /* Check license time */
800   hide_expose(table.list[0].text);
801   licenseDate = atol(table.list[0].text);
802   if (licenseDate < XIS_LICMIN) {
803    licensed = LICERROR_INVALID;
804   } else {
805        if (XIS_LICDATE > licenseDate + XIS_LICTIME) {
806        licensed = LICERROR_EXPIRED;
807        }
808   }
809
810   /* 08.Jun.2000 begin ]
811   /* get the license type,
812        2 types: 1 by server name
813                2 by script name (IsisScript)
814      to set the comparison text */
815
816   /* lincese type is the first character after the standard time */
817    licenseType = table.list[0].text[LICENSE_TYPE_POS];
818
819   /* if license type is '\0' means the original standard type */
820   if (licenseType == 's') {
821    xisVar->licenseText = xisGetIsisScript(xisVar->cgiList);
822   }
823
824    /* check mandatory arguments */
825   if (!xisVar->licenseText) licensed = LICERROR_MISSING;
826   /* 08.Jun.2000 end ]
827
828    /* if OK, check server names */
829    if (licensed == LICERROR_UNAUTHO) {
830
831       /* Loop all lines */
832    for (line = 1L; line < table.qtt; line++) {
833
834        /* Check licensed servers */
835          hide_expose(table.list[line].text);
836        if (strcmp(xisVar->licenseText,table.list[line].text) == 0) {
837           licensed = LICERROR_OK;
838            break;
839          }
840
841    } /* for */
842
843   }
844
845   /* Garbage collector */
846    efc_split_lines_free(&table);
847
848   /* Return licensed flag */
849   return licensed;
850
851} /* xisLicense */
852#endif
853
854/* ================================================================ xisStart */
855void xisStart(XIS_VAR *xisVar,  /* XIS variables */
856              char *argv0)      /* program itself */
857{
858    int auxLength;                       /* auxiliary length */
859    char *p;                             /* auxiliary string buffer pointer */
860
861    /* Set program path */
862    xisVar->programPath = strdup(argv0);
863    auxLength = strlen(xisVar->programPath);
864    for (p = xisVar->programPath+auxLength; auxLength; p--,auxLength--) {
865        if (*p == '\\' || *p == '/') {
866            p++;
867            break;
868        }
869    } /* for */
870    *p = '\0';
871
872    /* Set environment variable */
873    sprintf(path_source,"PATH_WXIS=%s",xisVar->programPath);
874    putenv(path_source);
875
876    /* Call CISIS setup functions */
877    if (firstTime) {
878        dbxinit();
879        recinit();
880        trminit();
881        firstTime = 0;
882    }
883    ifupd_wrnmsg = 0;
884
885    /* Setup XIS variables*/
886    xisVar->licenseText = getenv("SERVER_NAME");
887    xisVar->pathTranslated = cgi_getenv("PATH_TRANSLATED");
888
889    /* Setup compiler variables*/
890    xisVar->xisProgram.compiledExt = XIS_COMPILED_EXT;
891
892} /* xisStart */
893
894/* ================================================================= xisFree */
895void xisFree(XIS_VAR *xisVar)       /* XIS variables */
896{
897
898    /* Garbage collector */
899   efc_free(xisVar->programPath);
900#ifndef XIS_SERVER
901   efc_free(xisVar->script);
902#else
903    //efc_delete_buffer();
904#endif
905   cgi_free(xisVar->cgiList);
906
907} /* xisFree */
908
909/* ================================================================ mainFunc */
910int mainFunc(int argc,       /* quantity of arguments */
911             char *argv[],   /* array of arguments */
912             char *envv[],   /* array of environment variables */
913             OUT_BUFFER *out)   /* server output buffer */
914{
915    XIS_VAR xisVar;                 /* XIS variables */
916    XIS_ERROR errorCode;            /* XIS error code */
917    LICERROR_LIST licenseError;     /* license error return code */
918    CGI_PARAM *cgiAux;              /* auxiliary cgi parameter pointer */
919
920/*
921{
922int i;
923printf("Content-type: text/plain\n\n");
924for (i = 0; i < argc; i++) {
925    printf("argv[%d]: %s\n",i,argv[i]);
926}
927for (i = 0; envv[i]; i++) {
928    printf("env[%d]: %s\n",i,envv[i]);
929}
930}
931exit(0);
932*/
933
934    //chrono_start();
935
936    outBuff = out;
937
938#define AIX     0
939#if AIX
940    /* 1.2 avoid AIX behaviour [fatal: dbxopen/fd=0] */
941    int fdAux;
942    fdAux = open(argv[0],0);
943#endif
944
945    /* Start variables */
946    memset(&xisVar,0x00,sizeof(XIS_VAR));
947    xisStart(&xisVar,argv[0]);
948
949    /* Store arguments, on error exit */
950    xisArgLoad(&xisVar);
951    if (xisArgRead(&xisVar,argc,argv) < 0)
952        XIS_ERR(&(xisVar.error),XIS_ERROR_ARGS, &xisVar);
953
954    /* Store CGI parameters, on error exit */
955    if (xisCgi(&xisVar,argc,argv))
956        XIS_ERR(&(xisVar.error),XIS_ERROR_CGI, &xisVar);
957
958    /* Licensed server name */
959    if (xisVar.licenseText) {
960#if LICENSED_VERSION
961        licenseError = xisLicense(&xisVar,xisLicenseFile);
962#else
963        licenseError = LICERROR_OK;
964#endif
965        switch (licenseError) {
966            case LICERROR_OK :
967                break;
968            case LICERROR_FILE :
969                XIS_ERR(&(xisVar.error),efc_error(&(xisVar.error),XIS_ERROR_LICENSE,xisLicenseFile), &xisVar);
970            case LICERROR_INVALID :
971                XIS_ERR(&(xisVar.error),efc_error(&(xisVar.error),XIS_ERROR_LICENSE,"invalid license"), &xisVar);
972            case LICERROR_EXPIRED :
973                XIS_ERR(&(xisVar.error),efc_error(&(xisVar.error),XIS_ERROR_LICENSE,"new release"), &xisVar);
974            case LICERROR_UNAUTHO :
975                XIS_ERR(&(xisVar.error),efc_error(&(xisVar.error),XIS_ERROR_LICENSE,xisVar.licenseText), &xisVar);
976            case LICERROR_MISSING :
977                XIS_ERR(&(xisVar.error),efc_error(&(xisVar.error),XIS_ERROR_LICENSE,"server name/script name"), &xisVar);
978        } /* switch */
979    }
980
981    /* Find script parameter */
982    for (cgiAux = xisVar.cgiList; cgiAux; cgiAux = cgiAux->next) {
983        if (strcmp(cgiAux->name,xisVar.argList[ARG_SCRIPT].id) == 0) {
984            xisVar.argList[ARG_SCRIPT].text = cgiAux->value;
985            break;
986        }
987    }
988
989    /* The WXIS is called by the server via the .xis/.xic configuration */
990    if ( !xisVar.argList[ARG_SCRIPT].text ) {
991        xisVar.argList[ARG_SCRIPT].text = getenv("PATH_TRANSLATED");
992    }
993
994    /* Run script */
995    errorCode = xisRun(&xisVar);
996
997    /* Garbage collector */
998    xisFree(&xisVar);
999
1000
1001    //chrono_stop("mainFunc");
1002
1003    /* Return error code */
1004    return errorCode;
1005} /* mainFunc */
1006
1007
1008/* ==================================================================== main */
1009#if GEN_MAIN
1010int main(int argc,       /* quantity of arguments */
1011         char *argv[],   /* arrray of arguments */
1012         char *envv[])   /* arrray of environment variables */
1013{
1014    int errorCode =  0;
1015
1016    //chrono_init("chrono_wxis.txt");
1017
1018    mainFunc(argc, argv, envv, NULL);
1019
1020    //chrono_end();
1021
1022    /* Return error code */
1023    exit(errorCode);
1024
1025    return 0;
1026}
1027#endif /* GEN_MAIN */
Note: See TracBrowser for help on using the browser.