G:/ScriptBasic/source/hookers.c

Go to the documentation of this file.
00001 /* hookers.c
00002 
00003 --GNU LGPL
00004 This library is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU Lesser General Public
00006 License as published by the Free Software Foundation; either
00007 version 2.1 of the License, or (at your option) any later version.
00008 
00009 This library is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 Lesser General Public License for more details.
00013 
00014 You should have received a copy of the GNU Lesser General Public
00015 License along with this library; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 TO_HEADER:
00019 
00020 #include "filesys.h"
00021 
00022 typedef struct _ExecuteObject *pExecuteObject;
00023 #define PEXECUTEOBJECT 1
00024 
00025 typedef struct _HookFunctions {
00026 
00027   void *hook_pointer;//this can freely be used by a module that alters some of the hook functions
00028 
00029 #define HOOK_FILE_ACCESS(X) (pEo->pHookers->HOOK_file_access(pEo,(X)))
00030   int (*HOOK_file_access)(pExecuteObject, char *);
00031 
00032 #define HOOK_FOPEN(X,Y) (pEo->pHookers->HOOK_fopen(pEo,(X),(Y)))
00033   FILE *(*HOOK_fopen)(pExecuteObject, char *, char *);
00034 
00035 #define HOOK_FCLOSE(X) (pEo->pHookers->HOOK_fclose(pEo,(X)))
00036   void (*HOOK_fclose)(pExecuteObject, FILE *);
00037 
00038 #define HOOK_SIZE(X) (pEo->pHookers->HOOK_size(pEo,(X)))
00039   long (*HOOK_size)(pExecuteObject, char *);
00040 
00041 #define HOOK_TIME_ACCESSED(X) (pEo->pHookers->HOOK_time_accessed(pEo,(X)))
00042   long (*HOOK_time_accessed)(pExecuteObject, char *);
00043 
00044 #define HOOK_TIME_MODIFIED(X) (pEo->pHookers->HOOK_time_modified(pEo,(X)))
00045   long (*HOOK_time_modified)(pExecuteObject, char *);
00046 
00047 #define HOOK_TIME_CREATED(X) (pEo->pHookers->HOOK_time_created(pEo,(X)))
00048   long (*HOOK_time_created)(pExecuteObject, char *);
00049 
00050 #define HOOK_ISDIR(X) (pEo->pHookers->HOOK_isdir(pEo,(X)))
00051   int (*HOOK_isdir)(pExecuteObject, char *);
00052 
00053 #define HOOK_ISREG(X) (pEo->pHookers->HOOK_isreg(pEo,(X)))
00054   int (*HOOK_isreg)(pExecuteObject, char *);
00055 
00056 #define HOOK_EXISTS(X) (pEo->pHookers->HOOK_exists(pEo,(X)))
00057   int (*HOOK_exists)(pExecuteObject, char *);
00058 
00059 #define HOOK_TRUNCATE(X,Y) (pEo->pHookers->HOOK_truncate(pEo,(X),(Y)))
00060   int (*HOOK_truncate)(pExecuteObject, FILE *, long);
00061 
00062 #define HOOK_FGETC(X) (pEo->pHookers->HOOK_fgetc(pEo,(X)))
00063   int (*HOOK_fgetc)(pExecuteObject, FILE *);
00064 
00065 #define HOOK_FERROR(X) (pEo->pHookers->HOOK_ferror(pEo,(X)))
00066   int (*HOOK_ferror)(pExecuteObject, FILE *);
00067 
00068 #define HOOK_FREAD(X,Y,Z,W) (pEo->pHookers->HOOK_fread(pEo,(X),(Y),(Z),(W)))
00069   int (*HOOK_fread)(pExecuteObject, char *, int, int, FILE *);
00070 
00071 #define HOOK_SETMODE(X,Y) (pEo->pHookers->HOOK_setmode(pEo,(X),(Y)))
00072   void (*HOOK_setmode)(pExecuteObject,FILE *, int);
00073 
00074 #define HOOK_BINMODE(X) (pEo->pHookers->HOOK_binmode(pEo,(X)))
00075   void (*HOOK_binmode)(pExecuteObject,FILE *);
00076 
00077 #define HOOK_TEXTMODE(X) (pEo->pHookers->HOOK_textmode(pEo,(X)))
00078   void (*HOOK_textmode)(pExecuteObject,FILE *);
00079 
00080 #define HOOK_FWRITE(X,Y,Z,W) (pEo->pHookers->HOOK_fwrite(pEo,(X),(Y),(Z),(W)))
00081   int (*HOOK_fwrite)(pExecuteObject, char *, int, int, FILE *);
00082 
00083 #define HOOK_PUTC(X,Y) (pEo->pHookers->HOOK_fputc(pEo,(X),(Y)))
00084   int (*HOOK_fputc)(pExecuteObject, int, FILE *);
00085 
00086 #define HOOK_FLOCK(X,Y) (pEo->pHookers->HOOK_flock(pEo,(X),(Y)))
00087   int (*HOOK_flock)(pExecuteObject, FILE *, int);
00088 
00089 #define HOOK_LOCK(X,Y,Z,W) (pEo->pHookers->HOOK_lock(pEo,(X),(Y),(Z),(W)))
00090   int (*HOOK_lock)(pExecuteObject, FILE *, int, long, long);
00091 
00092 #define HOOK_FEOF(X) (pEo->pHookers->HOOK_feof(pEo,(X)))
00093   int (*HOOK_feof)(pExecuteObject, FILE *);
00094 
00095 #define HOOK_MKDIR(X) (pEo->pHookers->HOOK_mkdir(pEo,(X)))
00096   int (*HOOK_mkdir)(pExecuteObject, char *);
00097 
00098 #define HOOK_RMDIR(X) (pEo->pHookers->HOOK_rmdir(pEo,(X)))
00099   int (*HOOK_rmdir)(pExecuteObject, char *);
00100 
00101 #define HOOK_REMOVE(X) (pEo->pHookers->HOOK_remove(pEo,(X)))
00102   int (*HOOK_remove)(pExecuteObject, char *);
00103 
00104 #define HOOK_DELTREE(X) (pEo->pHookers->HOOK_deltree(pEo,(X)))
00105   int (*HOOK_deltree)(pExecuteObject, char *);
00106 
00107 #define HOOK_MAKEDIRECTORY(X) (pEo->pHookers->HOOK_MakeDirectory(pEo,(X)))
00108   int (*HOOK_MakeDirectory)(pExecuteObject, char *);
00109 
00110 #define HOOK_OPENDIR(X,Y) (pEo->pHookers->HOOK_opendir(pEo,(X),(Y)))
00111   DIR *(*HOOK_opendir)(pExecuteObject, char *, tDIR *);
00112 
00113 #define HOOK_READDIR(X) (pEo->pHookers->HOOK_readdir(pEo,(X)))
00114   struct dirent *(*HOOK_readdir)(pExecuteObject, DIR *);
00115 
00116 #define HOOK_CLOSEDIR(X) (pEo->pHookers->HOOK_closedir(pEo,(X)))
00117   void (*HOOK_closedir)(pExecuteObject, DIR *);
00118 
00119 #define HOOK_SLEEP(X) (pEo->pHookers->HOOK_sleep(pEo,(X)))
00120   void (*HOOK_sleep)(pExecuteObject, long);
00121 
00122 #define HOOK_CURDIR(X,Y) (pEo->pHookers->HOOK_curdir(pEo,(X),(Y)))
00123   int (*HOOK_curdir)(pExecuteObject, char *, unsigned long);
00124 
00125 #define HOOK_CHDIR(X) (pEo->pHookers->HOOK_chdir(pEo,(X)))
00126   int (*HOOK_chdir)(pExecuteObject, char *);
00127 
00128 #define HOOK_CHOWN(X,Y) (pEo->pHookers->HOOK_chown(pEo,(X),(Y)))
00129   int (*HOOK_chown)(pExecuteObject, char *, char *);
00130 
00131 #define HOOK_SETCREATETIME(X,Y) (pEo->pHookers->HOOK_SetCreateTime(pEo,(X),(Y)))
00132   int (*HOOK_SetCreateTime)(pExecuteObject, char *, long);
00133 
00134 #define HOOK_SETMODIFYTIME(X,Y) (pEo->pHookers->HOOK_SetModifyTime(pEo,(X),(Y)))
00135   int (*HOOK_SetModifyTime)(pExecuteObject, char *, long);
00136 
00137 #define HOOK_SETACCESSTIME(X,Y) (pEo->pHookers->HOOK_SetAccessTime(pEo,(X),(Y)))
00138   int (*HOOK_SetAccessTime)(pExecuteObject, char *, long);
00139 
00140   int (*HOOK_ExecBefore)(pExecuteObject);
00141   int (*HOOK_ExecAfter)(pExecuteObject);
00142   int (*HOOK_ExecCall)(pExecuteObject);
00143   int (*HOOK_ExecReturn)(pExecuteObject);
00144 
00145 #define HOOK_GETHOSTNAME(X,Y) (pEo->pHookers->HOOK_gethostname(pEo,(X),(Y)))
00146   int (*HOOK_gethostname)(pExecuteObject, char *, long);
00147 #define HOOK_GETHOST(X,Y) (pEo->pHookers->HOOK_gethost(pEo,(X),(Y)))
00148   int (*HOOK_gethost)(pExecuteObject, char *, struct hostent *);
00149 #define HOOK_TCPCONNECT(X,Y) (pEo->pHookers->HOOK_tcpconnect(pEo,(X),(Y)))
00150   int (*HOOK_tcpconnect)(pExecuteObject, SOCKET *, char *);
00151 #define HOOK_TCPSEND(X,Y,Z,W) (pEo->pHookers->HOOK_tcpsend(pEo,(X),(Y),(Z),(W)))
00152   int (*HOOK_tcpsend)(pExecuteObject, SOCKET, char *, long, int);
00153 #define HOOK_TCPRECV(X,Y,Z,W) (pEo->pHookers->HOOK_tcprecv(pEo,(X),(Y),(Z),(W)))
00154   int (*HOOK_tcprecv)(pExecuteObject, SOCKET, char *, long, int);
00155 #define HOOK_TCPCLOSE(X) (pEo->pHookers->HOOK_tcpclose(pEo,(X)))
00156   int (*HOOK_tcpclose)(pExecuteObject, SOCKET);
00157 
00158   int (*HOOK_killproc)(pExecuteObject, long);
00159 #define HOOK_KILLPROC(X) (pEo->pHookers->HOOK_killproc(pEo,(X)))
00160   int (*HOOK_getowner)(pExecuteObject, char *, char *, long);
00161 #define HOOK_GETOWNER(X,Y,Z) (pEo->pHookers->HOOK_getowner(pEo,(X),(Y),(Z)))
00162   char *(*HOOK_fcrypt)(pExecuteObject, char *, char *, char *);
00163 #define HOOK_FCRYPT(X,Y,Z) (pEo->pHookers->HOOK_fcrypt(pEo,(X),(Y),(Z)))
00164   long (*HOOK_CreateProcess)(pExecuteObject, char *);
00165 #define HOOK_CREATEPROCESS(X) (pEo->pHookers->HOOK_CreateProcess(pEo,(X)))
00166 
00167   int (*HOOK_CallScribaFunction)(pExecuteObject,
00168                                  unsigned long,
00169                                  pFixSizeMemoryObject *,
00170                                  unsigned long,
00171                                  pFixSizeMemoryObject *);
00172 #define HOOK_CALLSCRIBAFUNCTION(X,Y,Z,W) (pEo->pHookers->HOOK_CallScribaFunction(pEo,(X),(Y),(Z),(W)))
00173 
00174   long (*HOOK_CreateProcessEx)(pExecuteObject,
00175                               char *,
00176                               long,
00177                               unsigned long *,
00178                               unsigned long *);
00179 #define HOOK_CREATEPROCESSEX(P,TO,PID,EXIT) (pEo->pHookers->HOOK_CreateProcessEx(pEo,(P),(TO),(PID),(EXIT)))
00180 
00181   int (*HOOK_waitpid)(pExecuteObject, long, unsigned long *);
00182 #define HOOK_WAITPID(X,Y) (pEo->pHookers->HOOK_waitpid(pEo,(X),(Y)))
00183   } HookFunctions
00184 #ifndef PHOOKFUNCTIONS  
00185   , *pHookFunctions
00186 #endif
00187   ;
00188 
00189 */
00190 #include <stdio.h>
00191 
00192 #include "basext.h"
00193 #include "sym.h"
00194 #include "errcodes.h"
00195 #include "report.h"
00196 #include "lexer.h"
00197 #include "expression.h"
00198 #include "builder.h"
00199 #include "memory.h"
00200 #include "syntax.h"
00201 #include "execute.h"
00202 #include "myalloc.h"
00203 #include "dynlolib.h"
00204 #include "hookers.h"
00205 
00206 /*POD
00207 
00208 This file contains the hook functions that are called by the commands whenever
00209 a command wants to access the operating system functions. The hook functions
00210 implemented here are transparent, they call the operating system. However these hook
00211 functions are called via the HookFunctions function pointer table and external modules
00212 may alter this table supplying their own hook functions.
00213 
00214 There are some hook functions, which do not exist by default. In this case the hook functions table
00215 points to T<NULL>. These functions, if defined are called by ScriptBasic at certain points of execution.
00216 For example the function T<HOOK_ExecBefore> is called each time before executing a command in case
00217 an external module defines the function altering the hook function table.
00218 
00219 The hook functions have the same arguments as the original function preceeded by the
00220 pointer to the execution object T<pExecuteObject pEo>. For example the function T<fopen> has two arguments
00221 to T<char *>, and therefore HOOK_fopen has three. The first should point to T<pEo> and the second and third should
00222 point to 
00223 
00224 CUT*/
00225 
00226 /*POD
00227 =H hook_Init
00228 
00229 This function allocates a hook function table and fills the
00230 function pointers to point to the original transparent hook functions.
00231 
00232 /*FUNCTION*/
00233 int hook_Init(pExecuteObject pEo,
00234               pHookFunctions *pHookers
00235   ){
00236 /*noverbatim
00237 CUT*/
00238   *pHookers = alloc_Alloc(sizeof(HookFunctions),pEo->pMemorySegment);
00239   if( *pHookers == NULL )return COMMAND_ERROR_MEMORY_LOW;
00240 #define SET(x) (*pHookers)->HOOK_##x = hook_##x
00241 
00242   (*pHookers)->hook_pointer = NULL;
00243 
00244   SET(file_access);
00245 
00246   SET(fopen);
00247   SET(fclose);
00248   SET(size);
00249   SET(time_accessed);
00250   SET(time_modified);
00251   SET(time_created);
00252   SET(isdir);
00253   SET(isreg);
00254   SET(exists);
00255   SET(truncate);
00256   SET(fgetc);
00257   SET(ferror);
00258   SET(fread);
00259   SET(setmode);
00260   SET(binmode);
00261   SET(textmode);
00262   SET(fwrite);
00263   SET(fputc);
00264   SET(flock);
00265   SET(lock);
00266   SET(feof);
00267   SET(mkdir);
00268   SET(rmdir);
00269   SET(remove);
00270   SET(deltree);
00271   SET(MakeDirectory);
00272   SET(opendir);
00273   SET(readdir);
00274   SET(closedir);
00275   SET(sleep);
00276   SET(curdir);
00277   SET(chdir);
00278   SET(chown);
00279   SET(SetCreateTime);
00280   SET(SetModifyTime);
00281   SET(SetAccessTime);
00282   SET(gethostname);
00283   SET(gethost);
00284   SET(tcpconnect);
00285   SET(tcpsend);
00286   SET(tcprecv);
00287   SET(tcpclose);
00288   SET(killproc);
00289   SET(getowner);
00290   SET(fcrypt);
00291   SET(CreateProcess);
00292   SET(CreateProcessEx);
00293   SET(CallScribaFunction);
00294   SET(waitpid);
00295 
00296   (*pHookers)->HOOK_ExecBefore = NULL; /* called before executing a command       */
00297   (*pHookers)->HOOK_ExecAfter  = NULL; /* called after executing a command        */
00298   (*pHookers)->HOOK_ExecCall   = NULL; /* executed when calling a function        */
00299   (*pHookers)->HOOK_ExecReturn = NULL; /* executed when returning from a function */
00300 
00301   return COMMAND_ERROR_SUCCESS;
00302   }
00303 
00304 /*POD
00305 =H hook_file_access
00306 @c  file_access
00307 
00308 This function gets a file name as an argument and return an integer code that tells
00309 the caller if the program is allowed to read, write or both read and write to the file.
00310 The default implementation just dumbly answers that the program is allowed both read
00311 and write. This function is called by each other hook functions that access a file via the
00312 file name. If a module wants to restrict the basic code to access files based on the file
00313 name the module does not need to alter all hook functions that access files via file name.
00314 
00315 The module has to write its own T<file_access> hook function instead, alter the hook function table
00316 to point to the module's function and all file accessing functions will ask the module's
00317 hook function if the code may access the file.
00318 
00319 The argument T<pszFileName> is the name of the file that the ScriptBasic program
00320 want to do something. The actual T<file_access> hook function should decide if the
00321 basic program is
00322 
00323 =itemize
00324 =item 0 not allowed to access the file
00325 =item 1 allowed to read the file
00326 =item 2 allowed to write the file (modify)
00327 =item 3 allowed to read and write the file
00328 =noitemize
00329 
00330 The default implementation of this function just
00331 allows the program to do anything. Any extension module may
00332 have its own implementation and restrict the basic program to
00333 certain files.
00334 
00335 /*FUNCTION*/
00336 int hook_file_access(pExecuteObject pEo,
00337                      char *pszFileName
00338   ){
00339 /*noverbatim
00340 CUT*/
00341   return 3;
00342   }
00343 
00344 /*POD
00345 =H hook_fopen
00346 @c  fopen
00347 /*FUNCTION*/
00348 FILE *hook_fopen(pExecuteObject pEo,
00349                  char *pszFileName,
00350                  char *pszOpenMode
00351   ){
00352 /*noverbatim
00353 CUT*/
00354   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00355 
00356   if( iAccessPermission == 0 )return NULL;
00357   if( (iAccessPermission&1 && *pszOpenMode == 'r') ||
00358       (iAccessPermission&2 && ( *pszOpenMode == 'w' || *pszOpenMode == 'a' )) )
00359     return file_fopen(pszFileName,pszOpenMode);
00360   return NULL;
00361   }
00362 
00363 /*POD
00364 =H hook_fclose
00365 @c  fclose
00366 /*FUNCTION*/
00367 void hook_fclose(pExecuteObject pEo,
00368                   FILE *fp
00369   ){
00370 /*noverbatim
00371 CUT*/
00372   file_fclose(fp);
00373   }
00374 
00375 /*POD
00376 =H hook_size
00377 @c  size
00378 /*FUNCTION*/
00379 long hook_size(pExecuteObject pEo,
00380                char *pszFileName
00381   ){
00382 /*noverbatim
00383 CUT*/
00384   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00385   if( !(iAccessPermission&1) )return -1;
00386   return file_size(pszFileName);
00387   }
00388 
00389 /*POD
00390 =H hook_time_accessed
00391 @c  time_accessed
00392 
00393 /*FUNCTION*/
00394 long hook_time_accessed(pExecuteObject pEo,
00395                         char *pszFileName
00396   ){
00397 /*noverbatim
00398 CUT*/
00399   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00400   if( !(iAccessPermission&1) )return 0;
00401 
00402   return file_time_accessed(pszFileName);
00403   }
00404 
00405 /*POD
00406 =H hook_time_modified
00407 @c  time_modified
00408 
00409 /*FUNCTION*/
00410 long hook_time_modified(pExecuteObject pEo,
00411                         char *pszFileName
00412   ){
00413 /*noverbatim
00414 CUT*/
00415   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00416   if( !(iAccessPermission&1) )return 0;
00417 
00418   return file_time_modified(pszFileName);
00419   }
00420 
00421 /*POD
00422 =H hook_time_created
00423 @c  time_created
00424 
00425 /*FUNCTION*/
00426 long hook_time_created(pExecuteObject pEo,
00427                         char *pszFileName
00428   ){
00429 /*noverbatim
00430 CUT*/
00431   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00432   if( !(iAccessPermission&1) )return 0;
00433 
00434   return file_time_created(pszFileName);
00435   }
00436 
00437 /*POD
00438 =H hook_isdir
00439 @c  isdir
00440 
00441 /*FUNCTION*/
00442 int hook_isdir(pExecuteObject pEo,
00443                char *pszFileName
00444   ){
00445 /*noverbatim
00446 CUT*/
00447   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00448   if( !(iAccessPermission&1) )return 0;
00449 
00450   return file_isdir(pszFileName);
00451   }
00452 
00453 /*POD
00454 =H hook_isreg
00455 @c  isreg
00456 
00457 /*FUNCTION*/
00458 int hook_isreg(pExecuteObject pEo,
00459                char *pszFileName
00460   ){
00461 /*noverbatim
00462 CUT*/
00463   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00464   if( !(iAccessPermission&1) )return 0;
00465 
00466   return file_isreg(pszFileName);
00467   }
00468 
00469 /*POD
00470 =H hook_fileexists
00471 @c  fileexists
00472 
00473 /*FUNCTION*/
00474 int hook_exists(pExecuteObject pEo,
00475                 char *pszFileName
00476   ){
00477 /*noverbatim
00478 CUT*/
00479   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00480   if( !(iAccessPermission&1) )return 0;
00481 
00482   return file_exists(pszFileName);
00483   }
00484 
00485 /*POD
00486 =H hook_truncate
00487 @c  truncate
00488 /*FUNCTION*/
00489 int hook_truncate(pExecuteObject pEo,
00490                   FILE *fp,
00491                   long lNewFileSize
00492   ){
00493 /*noverbatim
00494 CUT*/
00495   return file_truncate(fp,lNewFileSize);
00496   }
00497 
00498 /*POD
00499 =H hook_fgetc
00500 @c  fgetc
00501 /*FUNCTION*/
00502 int hook_fgetc(pExecuteObject pEo,
00503                FILE *fp
00504   ){
00505 /*noverbatim
00506 CUT*/
00507   return file_fgetc(fp);
00508   }
00509 
00510 /*POD
00511 =H hook_ferror
00512 @c  ferror
00513 /*FUNCTION*/
00514 int hook_ferror(pExecuteObject pEo,
00515                FILE *fp
00516   ){
00517 /*noverbatim
00518 CUT*/
00519   return file_ferror(fp);
00520   }
00521 
00522 /*POD
00523 =H hook_fread
00524 @c  fread
00525 /*FUNCTION*/
00526 int hook_fread(pExecuteObject pEo,
00527                char *buf,
00528                int size,
00529                int count,
00530                FILE *fp
00531   ){
00532 /*noverbatim
00533 CUT*/
00534   return file_fread(buf,size,count,fp);
00535   }
00536 
00537 /*POD
00538 =H hook_setmode
00539 @c  Set the mode of a file stream to binary or to ASCII
00540 
00541 /*FUNCTION*/
00542 void hook_setmode(pExecuteObject pEo,
00543                   FILE *fp,
00544                   int mode
00545   ){
00546 /*noverbatim
00547 CUT*/
00548   file_setmode(fp,mode);
00549   return;
00550   }
00551 
00552 /*POD
00553 =H hook_binmode
00554 @c  Set a file stream to binary mode
00555 /*FUNCTION*/
00556 void hook_binmode(pExecuteObject pEo,
00557                   FILE *fp
00558   ){
00559 /*noverbatim
00560 CUT*/
00561   file_binmode(fp);
00562   return;
00563   }
00564 
00565 /*POD
00566 =H hook_textmode
00567 @c  Set a file stream to text mode
00568 /*FUNCTION*/
00569 void hook_textmode(pExecuteObject pEo,
00570                    FILE *fp
00571   ){
00572 /*noverbatim
00573 CUT*/
00574   file_textmode(fp);
00575   return;
00576   }
00577 
00578 /*POD
00579 =H hook_fwrite
00580 @c  fwrite
00581 /*FUNCTION*/
00582 int hook_fwrite(pExecuteObject pEo,
00583                char *buf,
00584                int size,
00585                int count,
00586                FILE *fp
00587   ){
00588 /*noverbatim
00589 CUT*/
00590   return file_fwrite(buf,size,count,fp);
00591   }
00592 
00593 /*POD
00594 =H hook_fputc
00595 @c  fputc
00596 
00597 /*FUNCTION*/
00598 int hook_fputc(pExecuteObject pEo,
00599                int c,
00600                FILE *fp
00601   ){
00602 /*noverbatim
00603 CUT*/
00604   return file_fputc(c,fp);
00605   }
00606 
00607 /*POD
00608 =H hook_flock
00609 @c  flock
00610 
00611 /*FUNCTION*/
00612 int hook_flock(pExecuteObject pEo,
00613                FILE *fp,
00614                int iLockType
00615   ){
00616 /*noverbatim
00617 CUT*/
00618   return file_flock(fp,iLockType);
00619   }
00620 
00621 /*POD
00622 =H hook_lock
00623 @c  lock
00624 
00625 /*FUNCTION*/
00626 int hook_lock(pExecuteObject pEo,
00627               FILE *fp,
00628               int iLockType,
00629               long lStart,
00630               long lLength
00631   ){
00632   return file_lock(fp,iLockType,lStart,lLength);
00633 /*noverbatim
00634 CUT*/
00635   }
00636 
00637 /*POD
00638 =H hook_feof
00639 @c  feof
00640 
00641 /*FUNCTION*/
00642 int hook_feof(pExecuteObject pEo,
00643               FILE *fp
00644   ){
00645 /*noverbatim
00646 CUT*/
00647   return file_feof(fp);
00648   }
00649 
00650 /*POD
00651 =H hook_mkdir
00652 @c  mkdir
00653 
00654 /*FUNCTION*/
00655 int hook_mkdir(pExecuteObject pEo,
00656                char *pszDirectoryName
00657   ){
00658 /*noverbatim
00659 CUT*/
00660   return file_mkdir(pszDirectoryName);
00661   }
00662 
00663 /*POD
00664 =H hook_rmdir
00665 @c  rmdir
00666 
00667 /*FUNCTION*/
00668 int hook_rmdir(pExecuteObject pEo,
00669                char *pszDirectoryName
00670   ){
00671 /*noverbatim
00672 CUT*/
00673   return file_rmdir(pszDirectoryName);
00674   }
00675 
00676 /*POD
00677 =H hook_remove
00678 @c  remove
00679 
00680 /*FUNCTION*/
00681 int hook_remove(pExecuteObject pEo,
00682                 char *pszFileName
00683   ){
00684 /*noverbatim
00685 CUT*/
00686   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00687   if( !(iAccessPermission&1) )return -1;
00688 
00689   return file_remove(pszFileName);
00690   }
00691 
00692 /*POD
00693 =H hook_deltree
00694 @c  deltree
00695 
00696 /*FUNCTION*/
00697 int hook_deltree(pExecuteObject pEo,
00698                  char *pszDirectoryName
00699   ){
00700 /*noverbatim
00701 CUT*/
00702   int iAccessPermission = HOOK_FILE_ACCESS(pszDirectoryName);
00703   if( !(iAccessPermission&1) )return -1;
00704 
00705   return file_deltree(pszDirectoryName);
00706   }
00707 
00708 /*POD
00709 =H hook_MakeDirectory
00710 @c  MakeDirectory
00711 
00712 /*FUNCTION*/
00713 int hook_MakeDirectory(pExecuteObject pEo,
00714                        char *pszDirectoryName
00715   ){
00716 /*noverbatim
00717 CUT*/
00718   int iAccessPermission = HOOK_FILE_ACCESS(pszDirectoryName);
00719   if( !(iAccessPermission&1) )return -1;
00720 
00721   return file_MakeDirectory(pszDirectoryName);
00722   }
00723 
00724 /*POD
00725 =H hook_opendir
00726 @c  opendir
00727 
00728 /*FUNCTION*/
00729 DIR *hook_opendir(pExecuteObject pEo,
00730                   char *pszDirectoryName,
00731                   tDIR *pDirectory
00732   ){
00733 /*noverbatim
00734 CUT*/
00735   return file_opendir(pszDirectoryName,pDirectory);
00736   }
00737 
00738 /*POD
00739 =H hook_readdir
00740 @c  readdir
00741 
00742 /*FUNCTION*/
00743 struct dirent *hook_readdir(pExecuteObject pEo,
00744                             DIR *pDirectory
00745   ){
00746 /*noverbatim
00747 CUT*/
00748   return file_readdir(pDirectory);
00749   }
00750 
00751 /*POD
00752 =H hook_closedir
00753 @c  closedir
00754 
00755 /*FUNCTION*/
00756 void hook_closedir(pExecuteObject pEo,
00757                    DIR *pDirectory
00758   ){
00759 /*noverbatim
00760 CUT*/
00761 
00762   file_closedir(pDirectory);
00763   }
00764 
00765 /*POD
00766 =H hook_sleep
00767 @c  sleep
00768 
00769 /*FUNCTION*/
00770 void hook_sleep(pExecuteObject pEo,
00771                 long lSeconds
00772   ){
00773 /*noverbatim
00774 CUT*/
00775   sys_sleep(lSeconds);
00776   }
00777 
00778 /*POD
00779 =H hook_curdir
00780 @c  curdir
00781 
00782 /*FUNCTION*/
00783 int hook_curdir(pExecuteObject pEo,
00784                 char *Buffer,
00785                 unsigned long cbBuffer
00786   ){
00787 /*noverbatim
00788 CUT*/
00789   return file_curdir(Buffer,cbBuffer);
00790   }
00791 
00792 /*POD
00793 =H hook_chdir
00794 @c  chdir
00795 
00796 /*FUNCTION*/
00797 int hook_chdir(pExecuteObject pEo,
00798                char *Buffer
00799   ){
00800 /*noverbatim
00801 CUT*/
00802   return file_chdir(Buffer);
00803   }
00804 
00805 /*POD
00806 =H hook_chown
00807 @c  chown
00808 
00809 /*FUNCTION*/
00810 int hook_chown(pExecuteObject pEo,
00811                char *pszFileName,
00812                char *pszOwner
00813   ){
00814 /*noverbatim
00815 CUT*/
00816   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00817   if( !(iAccessPermission&1) )return COMMAND_ERROR_CHOWN_SET_OWNER;
00818 
00819   return file_chown(pszFileName,pszOwner);
00820   }
00821 
00822 /*POD
00823 =H hook_SetCreateTime
00824 @c  SetCreateTime
00825 
00826 /*FUNCTION*/
00827 int hook_SetCreateTime(pExecuteObject pEo,
00828                        char *pszFileName,
00829                        long lTime
00830   ){
00831 /*noverbatim
00832 CUT*/
00833   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00834   if( !(iAccessPermission&1) )return COMMAND_ERROR_CREATIME_FAIL;
00835 
00836   return file_SetCreateTime(pszFileName,lTime);
00837   }
00838 
00839 /*POD
00840 =H hook_SetModifyTime
00841 @c  SetModifyTime
00842 
00843 /*FUNCTION*/
00844 int hook_SetModifyTime(pExecuteObject pEo,
00845                        char *pszFileName,
00846                        long lTime
00847   ){
00848 /*noverbatim
00849 CUT*/
00850   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00851   if( !(iAccessPermission&1) )return COMMAND_ERROR_MODTIME_FAIL;
00852 
00853   return file_SetModifyTime(pszFileName,lTime);
00854   }
00855 
00856 /*POD
00857 =H hook_SetAccessTime
00858 @c  SetAccessTime
00859 
00860 /*FUNCTION*/
00861 int hook_SetAccessTime(pExecuteObject pEo,
00862                        char *pszFileName,
00863                        long lTime
00864   ){
00865 /*noverbatim
00866 CUT*/
00867   int iAccessPermission = HOOK_FILE_ACCESS(pszFileName);
00868   if( !(iAccessPermission&1) )return COMMAND_ERROR_ACCTIM_FAIL;
00869 
00870   return file_SetAccessTime(pszFileName,lTime);
00871   }
00872 
00873 /*POD
00874 =H hook_gethostname
00875 @c  gethostname
00876 
00877 /*FUNCTION*/
00878 int hook_gethostname(pExecuteObject pEo,
00879                      char *pszBuffer,
00880                      long cbBuffer
00881   ){
00882 /*noverbatim
00883 CUT*/
00884   return file_gethostname(pszBuffer,cbBuffer);
00885   }
00886 
00887 /*POD
00888 =H hook_gethost
00889 @c  gethost
00890 /*FUNCTION*/
00891 int hook_gethost(pExecuteObject pEo,
00892                  char *pszBuffer,
00893                  struct hostent *pHost
00894   ){
00895 /*noverbatim
00896 CUT*/
00897   return file_gethost(pszBuffer,pHost);
00898   }
00899 
00900 /*POD
00901 =H hook_tcpconnect
00902 @c  tcpconnect
00903 /*FUNCTION*/
00904 int hook_tcpconnect(pExecuteObject pEo,
00905                     SOCKET *sClient,
00906                     char *pszRemoteSocket
00907   ){
00908 /*noverbatim
00909 CUT*/
00910   return file_tcpconnect(sClient,pszRemoteSocket);
00911   }
00912 
00913 /*POD
00914 =H hook_tcpsend
00915 @c  tcpsend
00916 /*FUNCTION*/
00917 int hook_tcpsend(pExecuteObject pEo,
00918                  SOCKET sClient,
00919                  char *pszBuffer,
00920                  long cbBuffer,
00921                  int iFlags
00922   ){
00923 /*noverbatim
00924 CUT*/
00925   return file_tcpsend(sClient,pszBuffer,cbBuffer,iFlags);
00926   }
00927 
00928 /*POD
00929 =H hook_tcprecv
00930 @c  tcprecv
00931 /*FUNCTION*/
00932 int hook_tcprecv(pExecuteObject pEo,
00933                  SOCKET sClient,
00934                  char *pszBuffer,
00935                  long cbBuffer,
00936                  int iFlags
00937   ){
00938 /*noverbatim
00939 CUT*/
00940   return file_tcprecv(sClient,pszBuffer,cbBuffer,iFlags);
00941   }
00942 
00943 /*POD
00944 =H hook_tcpclose
00945 @c  tcpclose
00946 /*FUNCTION*/
00947 int hook_tcpclose(pExecuteObject pEo,
00948                   SOCKET sClient
00949   ){
00950 /*noverbatim
00951 CUT*/
00952   return file_tcpclose(sClient);
00953   }
00954 
00955 /*POD
00956 =H hook_killproc
00957 @c  killproc
00958 /*FUNCTION*/
00959 int hook_killproc(pExecuteObject pEo,
00960                   long pid
00961   ){
00962 /*noverbatim
00963 CUT*/
00964   return file_killproc(pid);
00965   }
00966 
00967 /*POD
00968 =H hook_getowner
00969 @c  getowner
00970 /*FUNCTION*/
00971 int hook_getowner(pExecuteObject pEo,
00972                   char *pszFileName,
00973                   char *pszOwnerBuffer,
00974                   long cbOwnerBuffer
00975  ){
00976 /*noverbatim
00977 CUT*/
00978   return file_getowner(pszFileName,pszOwnerBuffer,cbOwnerBuffer);
00979   }
00980 
00981 /*POD
00982 =H hook_fcrypt
00983 @c  fcrypt
00984 /*FUNCTION*/
00985 char *hook_fcrypt(pExecuteObject pEo,
00986                   char *buf,
00987                   char *salt,
00988                   char *buff
00989   ){
00990 /*noverbatim
00991 CUT*/
00992   return file_fcrypt(buf,salt,buff);
00993   }
00994 
00995 /*POD
00996 =H hook_CreateProcess
00997 @c  CreateProcess
00998 /*FUNCTION*/
00999 long hook_CreateProcess(pExecuteObject pEo,
01000                          char *pszCommandLine
01001   ){
01002 /*noverbatim
01003 CUT*/
01004   return file_CreateProcess(pszCommandLine);
01005   }
01006 
01007 /*POD
01008 =H hook_CreateProcessEx
01009 @c  CreateProcessEx
01010 /*FUNCTION*/
01011 long hook_CreateProcessEx(pExecuteObject pEo,
01012                           char *pszCommandLine,
01013                           long lTimeOut,
01014                           unsigned long *plPid,
01015                           unsigned long *plExitCode
01016   ){
01017 /*noverbatim
01018 CUT*/
01019   return file_CreateProcessEx(pszCommandLine,lTimeOut,plPid,plExitCode);
01020   }
01021 
01022 /*POD
01023 =H hook_waitpid
01024 @c  waitpid
01025 /*FUNCTION*/
01026 int hook_waitpid(pExecuteObject pEo,
01027                  long pid,
01028                  unsigned long *plExitCode
01029   ){
01030 /*noverbatim
01031 CUT*/
01032   return file_waitpid(pid,plExitCode);
01033   }
01034 
01035 /*POD
01036 =H hook_CallScribaFunction
01037 @c  Start to execute a scriba function
01038 
01039 This is a hook function that performs its operation itself without
01040 calling underlying T<file_> function. This function is called
01041 by external modules whenever the external module wants to execute
01042 certain ScriptBasic function.
01043 
01044 The external module has to know the entry point of the ScriptBasic
01045 function.
01046 
01047 /*FUNCTION*/
01048 int hook_CallScribaFunction(pExecuteObject pEo,
01049                             unsigned long lStartNode,
01050                             pFixSizeMemoryObject *pArgument,
01051                             unsigned long NumberOfPassedArguments,
01052                             pFixSizeMemoryObject *pFunctionResult
01053   ){
01054 /*noverbatim
01055 CUT*/
01056 
01057   int iError;
01058   unsigned long SaveProgramCounter,SaveStepCounter;
01059   unsigned long SavefErrorGoto,SaveErrorGoto,SaveErrorResume;
01060   pFixSizeMemoryObject SaveLocalVariablesPointer;
01061   pFixSizeMemoryObject SaveFunctionResultPointer;
01062   MortalList _ThisCommandMortals=NULL;
01063   pMortalList _pThisCommandMortals = &_ThisCommandMortals;
01064   unsigned long _ActualNode=pEo->ProgramCounter;
01065   int iErrorCode;
01066   NODE nItem;
01067   unsigned long i;
01068   unsigned long NumberOfArguments;
01069   long Opcode;
01070 
01071 
01072   SaveLocalVariablesPointer = pEo->LocalVariables;
01073   SaveProgramCounter = pEo->ProgramCounter;
01074   pEo->ProgramCounter = lStartNode;
01075   if( pEo->ProgramCounter == 0 )return EXE_ERROR_USERFUN_UNDEFINED;
01076 
01077   SaveFunctionResultPointer = pEo->pFunctionResult;
01078   pEo->pFunctionResult = NULL;
01079   SaveStepCounter = pEo->lStepCounter;
01080   pEo->lStepCounter = 0;
01081   SaveErrorGoto = pEo->ErrorGoto;
01082   pEo->ErrorGoto = 0;
01083   SaveErrorResume = pEo->ErrorResume;
01084   pEo->ErrorResume = 0;
01085   SavefErrorGoto = pEo->fErrorGoto;
01086   pEo->fErrorGoto = ONERROR_NOTHING;
01087 
01088   nItem = pEo->CommandArray[pEo->ProgramCounter-1].Parameter.NodeList.actualm ;
01089   Opcode = pEo->CommandArray[nItem-1].OpCode;
01090   pEo->cLocalVariables = pEo->CommandArray[nItem-1].Parameter.CommandArgument.Argument.lLongValue;
01091   nItem = pEo->CommandArray[nItem-1].Parameter.CommandArgument.next;
01092   NumberOfArguments = pEo->CommandArray[nItem-1].Parameter.CommandArgument.Argument.lLongValue;
01093   nItem = pEo->CommandArray[nItem-1].Parameter.CommandArgument.next;
01094   nItem = pEo->CommandArray[nItem-1].Parameter.CommandArgument.Argument.lLongValue;
01095 
01096   if( pEo->cLocalVariables ){
01097     pEo->LocalVariables = memory_NewArray(pEo->pMo,1,pEo->cLocalVariables);
01098     if( pEo->LocalVariables == NULL )return COMMAND_ERROR_MEMORY_LOW;
01099     }else pEo->LocalVariables = NULL; /* it should have been null anyway */
01100 
01101   for( i=0 ; pArgument && i < NumberOfPassedArguments && i < NumberOfArguments ; i++ ){
01102      pEo->LocalVariables->Value.aValue[i]
01103         = memory_DupVar(pEo->pMo,
01104                         pArgument[i],
01105                         _pThisCommandMortals,
01106                         &iError);
01107      if( iError )return iError;
01108      }
01109   while( i < (unsigned)pEo->cLocalVariables ){
01110      pEo->LocalVariables->Value.aValue[i] = NULL;
01111      i++;
01112      }
01113 
01114   /* and finally we start to execute the function when executing the next command */
01115   pEo->lFunctionLevel++;
01116   /* some macros need this label */
01117 // _FunctionFinishLabel: ;
01118   pEo->ProgramCounter = pEo->CommandArray[pEo->ProgramCounter-1].Parameter.NodeList.rest;
01119   execute_Execute_r(pEo,&iErrorCode);
01120 
01121   /* restore variables */
01122 
01123   pEo->lStepCounter = SaveStepCounter;
01124   if( pEo->LocalVariables )/* this is null if the function did not have arguments and no local variables */
01125     memory_ReleaseVariable(pEo->pMo,pEo->LocalVariables);
01126   pEo->ProgramCounter = SaveProgramCounter;
01127   pEo->LocalVariables = SaveLocalVariablesPointer;
01128   (*pFunctionResult) = pEo->pFunctionResult;
01129   pEo->pFunctionResult = SaveFunctionResultPointer;
01130 
01131   pEo->ErrorGoto = SaveErrorGoto;
01132   pEo->fErrorGoto = SavefErrorGoto;
01133   pEo->ErrorResume = SaveErrorResume;
01134   return iErrorCode;
01135   }

Generated on Sun Mar 12 23:56:30 2006 for ScriptBasic by  doxygen 1.4.6-NO