home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / RUNIMAGE / DELPHI30 / SOURCE / RTL / WIN / NSAPI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-03  |  99.9 KB  |  2,961 lines

  1. {****************************************************************************}
  2. {*                                                                           }
  3. {*  Copyright (c) 1997  Borland International                                }
  4. {*                                                                           }
  5. {*  This module contains  the structure definitions and prototypes for the   }
  6. {*  Netscape Internet Server API (NSAPI)                                     }
  7. {*                                                                           }
  8. {****************************************************************************}
  9.  
  10. unit NSApi;
  11.  
  12. {$WEAKPACKAGEUNIT}
  13.  
  14. interface
  15.  
  16. uses Windows, WinSock;
  17.  
  18. {*****************************************************************************}
  19. {* From version.h                                                             }
  20. {*****************************************************************************}
  21. {
  22.  
  23.   This file is included from both C source and the NT installation compiler.
  24.   Because of that, no ifdefs are allowed, and strings must be simple strings
  25.   (not concatenated).
  26.  
  27.   Because macros called PERSONAL_VERSION and ENTERPRISE_VERSION already
  28.   exist, the PRODUCT_VERSION define has _DEF appended.
  29. }
  30.  
  31. const
  32.   PROXY_VERSION_DEF = '2.0b4';
  33.   PROXY_VERSION_STRING = 'Netscape-Proxy/2.0b4';
  34.  
  35.   ADMSERV_VERSION_DEF = '2.0';
  36.   ADMSERV_VERSION_STRING = 'Netscape-Administrator/2.0';
  37.  
  38.   PERSONAL_VERSION_DEF = '2.0b4';
  39.   PERSONAL_VERSION_STRING = 'Netscape-FastTrack/2.0b4';
  40.  
  41.   CATALOG_VERSION_DEF = '1.0b2';
  42.   CATALOG_VERSION_STRING = 'Netscape-Catalog/1.0b2';
  43.  
  44.   RDS_VERSION_DEF = '1.0b2';
  45.   RDS_VERSION_STRING = 'Netscape-RDS/1.0b2';
  46.  
  47.   ENTERPRISE_VERSION_DEF = '2.0b4';
  48.   ENTERPRISE_VERSION_STRING = 'Netscape-Enterprise/2.0b4';
  49.  
  50.   NEWS_VERSION_STRING = 'Netscape 1.1';
  51.  
  52.   BATMAN_VERSION_DEF = '1.0a1';
  53.   BATMAN_VERSION_STRING = 'Batman/1.0a1';
  54.  
  55. {*****************************************************************************}
  56. {* From systems.h                                                             }
  57. {*****************************************************************************}
  58. {
  59.   Lists of defines for systems
  60.   This sets what general flavor the system is (UNIX, etc.),
  61.   and defines what extra functions your particular system needs.
  62. }
  63.  
  64.   DAEMON_LISTEN_SIZE = 100;
  65.  
  66. function strcasecmp(s1, s2: PChar): Integer; cdecl;
  67. function strncasecmp(s1, s2: PChar; n: Integer): Integer; cdecl;
  68. function util_strcasecmp(s1, s2: PChar): Integer; cdecl;
  69. function util_strncasecmp(s1, s2: PChar; n: Integer): Integer; cdecl;
  70.  
  71. type
  72.   PASSWD = Pointer;
  73.   PPASSWD = ^PASSWD;
  74.   TCAddr = PChar; {caddr_t}
  75.   caddr_t = TCAddr;
  76.   TAtRestart = procedure (Data: Pointer) cdecl;
  77.   TMagnusAtRestart = TAtRestart;
  78.   TDaemonAtRestart = TAtRestart;
  79.  
  80. {*****************************************************************************}
  81. {* From netsite.h                                                             }
  82. {*****************************************************************************}
  83. {
  84.    Standard defs for NetSite servers.
  85. }
  86.  
  87. const
  88.   {* Used in some places as a length limit on error messages *}
  89.   MAGNUS_ERROR_LEN = 8192;
  90.  
  91.   {* Carraige return and line feed *}
  92.   CR = 13;
  93.   LF = 10;
  94.   ENDLINE = #13#10;
  95.  
  96.   {* -------------------------- System version on NT------------------------- *}
  97.  
  98.   {* Encode the server version as a number to be able to provide inexpensive
  99.    * dynamic checks on server version - this isn't added in yet. *}
  100.  
  101.   ENTERPRISE_VERSION = 1;
  102.   PERSONAL_VERSION = 2;
  103.   CATALOG_VERSION = 3;
  104.   RDS_VERSION = 4;
  105.  
  106. {* Return server version *}
  107. function system_version: PChar; cdecl;
  108. function MAGNUS_VERSION_STRING: PChar; cdecl;
  109.  
  110. function server_fasttrack: Boolean;
  111. function server_enterprise: Boolean;
  112.  
  113. {* Set server's version dynamically *}
  114. procedure system_version_set(ptr: PChar); cdecl;
  115.  
  116. {* -------------------------- Memory allocation --------------------------- *}
  117.  
  118.  
  119. {*
  120.    Depending on the system, memory allocated via these macros may come from
  121.    an arena. If these functions are called from within an Init function, they
  122.    will be allocated from permanent storage. Otherwise, they will be freed
  123.    when the current request is finished.
  124. *}
  125.  
  126. function MALLOC(size: Integer): Pointer; cdecl;
  127. function system_malloc(size: Integer): Pointer; cdecl;
  128.  
  129. function CALLOC(size: Integer): Pointer; cdecl;
  130. function system_calloc(size: Integer): Pointer; cdecl;
  131.  
  132. function REALLOC(ptr: Pointer; size: Integer): Pointer; cdecl;
  133. function system_realloc(ptr: Pointer; size: Integer): Pointer; cdecl;
  134.  
  135. procedure FREE(ptr: Pointer); cdecl;
  136. procedure system_free(ptr: Pointer); cdecl;
  137.  
  138. function STRDUP(ptr: PChar): PChar; cdecl;
  139. function system_strdup(ptr: PChar): PChar; cdecl;
  140.  
  141. {*
  142.    These macros always provide permanent storage, for use in global variables
  143.    and such. They are checked at runtime to prevent them from returning NULL.
  144. *}
  145.  
  146. function PERM_MALLOC(size: Integer): Pointer; cdecl;
  147. function system_malloc_perm(size: Integer): Pointer; cdecl;
  148.  
  149. function PERM_CALLOC(size: Integer): Pointer; cdecl;
  150. function system_calloc_perm(size: Integer): Pointer; cdecl;
  151.  
  152. function PERM_REALLOC(ptr: Pointer; size: Integer): Pointer; cdecl;
  153. function system_realloc_perm(ptr: Pointer; size: Integer): Pointer; cdecl;
  154.  
  155. procedure PERM_FREE(ptr: Pointer); cdecl;
  156. procedure system_free_perm(ptr: Pointer); cdecl;
  157.  
  158. function PERM_STRDUP(ptr: PChar): PChar; cdecl;
  159. function system_strdup_perm(ptr: PChar): PChar; cdecl;
  160.  
  161. {* Not sure where to put this. *}
  162. procedure magnus_atrestart(fn: TMagnusAtRestart; data: Pointer); cdecl;
  163.  
  164. {*****************************************************************************}
  165. {* From pool.h                                                                }
  166. {*****************************************************************************}
  167. {
  168.   Module for handling memory allocations.
  169.  
  170.   Notes:
  171.   This module is used instead of the NSPR prarena module because the prarenas
  172.   did not fit as cleanly into the existing server.
  173. }
  174.  
  175. type
  176.   pool_handle_t = Pointer;
  177.   TPoolHandle = pool_handle_t;
  178.   PPoolHandle = ^TPoolHandle;
  179.  
  180. { pool_create
  181.   Function to create a new pool.
  182.   Returns non-NULL on success, NULL on failure.
  183. }
  184. function pool_create: PPoolHandle; cdecl;
  185.  
  186. { pool_destroy
  187.   Frees all memory associated with a pool and destroys the pool.
  188. }
  189. procedure pool_destroy(pool_handle: PPoolHandle); cdecl;
  190.  
  191. { pool_enabled
  192.   Check if the pools are enabled and a pool is currently set
  193.   for this thread.  Return 1 if enabled, 0 if not enabled.
  194. }
  195. function pool_enabled: BOOL; cdecl;
  196. function pool_malloc(pool_handle: PPoolHandle; size: Integer): Pointer; cdecl;
  197. procedure pool_free(pool_handle: PPoolHandle; ptr: Pointer); cdecl;
  198. function pool_calloc(pool_handle: PPoolHandle; nelem, elsize: Integer): Pointer; cdecl;
  199. function pool_realloc(pool_handle: PPoolHandle; ptr: Pointer; size: Integer): Pointer; cdecl;
  200. function pool_strdup(pool_handle: PPoolHandle; orig_str: PChar): PChar; cdecl;
  201.  
  202. {*****************************************************************************}
  203. {* From sem.h                                                                 }
  204. {*****************************************************************************}
  205. {
  206.   Attempt to provide multi-process semaphores across platforms
  207. }
  208.  
  209. type
  210.   Semaphore = THandle;
  211.  
  212. const
  213.   SEM_ERROR    = 0;
  214.   {* That oughta hold them (I hope) *}
  215.   SEM_MAXVALUE = 32767;
  216.  
  217. {
  218.   sem_init creates a semaphore using the given name and unique
  219.   identification number. filename should be a file accessible to the
  220.   process. Returns SEM_ERROR on error.
  221. }
  222. function sem_init(name: PChar; Number: Integer): Semaphore; cdecl;
  223.  
  224. {
  225.   sem_terminate de-allocates the given semaphore.
  226. }
  227. procedure sem_terminate(id: Semaphore); cdecl;
  228.  
  229. {
  230.   sem_grab attempts to gain exclusive access to the given semaphore. If
  231.   it can't get it, the caller will block. Returns -1 on error.
  232. }
  233. function sem_grab(id: Semaphore): Integer; cdecl;
  234. function sem_tgrab(id: Semaphore): Integer; cdecl;
  235.  
  236. {
  237.   sem_release releases this process's exclusive control over the given
  238.   semaphore. Returns -1 on error.
  239. }
  240. function sem_release(id: Semaphore): Integer; cdecl;
  241.  
  242. {*****************************************************************************}
  243. {* From crit.h                                                                }
  244. {*****************************************************************************}
  245. {
  246.   Critical section abstraction. Used in threaded servers to protect
  247.   areas where two threads can interfere with each other.
  248.  
  249.   Condvars are condition variables that are used for thread-thread
  250.   synchronization.
  251. }
  252.  
  253. type
  254.   CRITICAL = Pointer;
  255.  
  256. {
  257.   crit_init creates and returns a new critical section variable. At the
  258.   time of creation no one has entered it.
  259. }
  260. function crit_init: CRITICAL; cdecl;
  261.  
  262. {
  263.   crit_enter enters a critical section. If someone is already in the
  264.   section, the calling thread is blocked until that thread exits.
  265. }
  266. procedure crit_enter(id: CRITICAL); cdecl;
  267.  
  268. {
  269.   crit_exit exits a critical section. If another thread is blocked waiting
  270.   to enter, it will be unblocked and given ownership of the section.
  271. }
  272. procedure crit_exit(id: CRITICAL); cdecl;
  273.  
  274. {
  275.   crit_terminate removes a previously allocated critical section variable.
  276. }
  277. procedure crit_terminate(id: CRITICAL); cdecl;
  278.  
  279. type
  280.   CONDVAR = Pointer;
  281.  
  282. {
  283.   condvar_init initializes and returns a new condition variable. You
  284.   must provide a critical section to be associated with this condition
  285.   variable.
  286. }
  287. function condvar_init(id: CRITICAL): CONDVAR; cdecl;
  288.  
  289. {
  290.   condvar_wait blocks on the given condition variable. The calling thread
  291.   will be blocked until another thread calls condvar_notify on this variable.
  292.   The caller must have entered the critical section associated with this
  293.   condition variable prior to waiting for it.
  294. }
  295. procedure condvar_wait(cv: CONDVAR); cdecl;
  296.  
  297. {
  298.   condvar_notify awakens any threads blocked on the given condition
  299.   variable. The caller must have entered the critical section associated
  300.   with this variable first.
  301. }
  302. procedure condvar_notify(cv: CONDVAR); cdecl;
  303.  
  304. {
  305.   condvar_terminate frees the given previously allocated condition variable
  306. }
  307. procedure condvar_terminate(cv: CONDVAR); cdecl;
  308.  
  309. {*****************************************************************************}
  310. {* From file.h                                                                }
  311. {*****************************************************************************}
  312. {
  313.   system specific functions for reading/writing files
  314. }
  315.  
  316. {
  317.   I cheat: These are set up such that system_read can be a macro for read
  318.   under UNIX. IO_OKAY is anything positive.
  319. }
  320.  
  321. const
  322.   IO_OKAY = 1;
  323.   IO_ERROR = -1;
  324.   IO_EOF = 0;
  325.  
  326. {* -------------------------- File related defs --------------------------- *}
  327.  
  328. {* The disk page size on this machine. *}
  329.   FILE_BUFFERSIZE = 4096;
  330.  
  331. {
  332.   The fd data type for this system.
  333. }
  334.  
  335. type
  336.   SYS_FILE = ^TFile;
  337.   TFile = record
  338.     fh: THandle;
  339.     fname: PChar;
  340.     flsem: Semaphore;
  341.   end;
  342.   file_s = TFile;
  343.  
  344. const
  345.   SYS_ERROR_FD = nil;
  346.   SYS_STDERR = nil;
  347.  
  348. type
  349.   pid_t = THandle;
  350.   TPid = pid_t;
  351.  
  352. const
  353.   ERROR_PIPE = ERROR_BROKEN_PIPE or ERROR_BAD_PIPE or ERROR_PIPE_BUSY or
  354.     ERROR_PIPE_LISTENING or ERROR_PIPE_NOT_CONNECTED;
  355.  
  356. procedure CONVERT_TO_PRINTABLE_FORMAT(Filename: PChar);
  357. procedure CONVERT_TO_NATIVE_FS(Filename: PChar);
  358.  
  359. {!!! uses errno from C RTL }
  360. { #define rtfile_notfound() ((errno == ENOENT) || (errno == ESRCH)) }
  361.  
  362. const
  363.   FILE_PATHSEP = '/';
  364.   FILE_PARENT  = '..\';
  365.  
  366. function system_chdir(Path: PChar): BOOL; stdcall;
  367.  
  368. {
  369.   Wrapper for stat system call
  370. }
  371. type
  372.   PStat = ^TStat;
  373.   TStat = record
  374.     st_dev: Word;
  375.     st_ino: Word;
  376.     st_mode: Word;
  377.     st_nlink: SmallInt;
  378.     st_uid: SmallInt;
  379.     st_gid: SmallInt;
  380.     st_rdev: Word;
  381.     st_size: Longint;
  382.     st_atime: Longint;
  383.     st_mtime: Longint;
  384.     st_ctime: Longint;
  385.   end;
  386.   Stat = TStat;
  387.  
  388. function system_stat(name: PChar; var finfo: TStat): Integer; cdecl;
  389.  
  390. {
  391.   Wrapper for rename system call
  392. }
  393. function system_rename(old, new: PChar): BOOL;
  394.  
  395. {
  396.   Wrapper to remove file
  397. }
  398. function system_unlink(path: PChar): BOOL;
  399.  
  400. {
  401.   system_fread reads sz bytes from fd into to buf, return number of bytes
  402.   read, or IO_EOF if EOF, or IO_ERROR if error.
  403. }
  404. function system_fread(fd: SYS_FILE; buf: Pointer; sz: Integer): Integer; cdecl;
  405. function system_pread(fd: SYS_FILE; buf: Pointer; sz: Integer): Integer; cdecl;
  406.  
  407. {
  408.   system_fopenRO opens a given file for reading only
  409.   system_fopenWA opens a given file for writing, appending new output
  410. }
  411. function system_fopenRO(path: PChar): SYS_FILE; cdecl;
  412. function system_fopenWA(path: PChar): SYS_FILE; cdecl;
  413. function system_fopenRW(path: PChar): SYS_FILE; cdecl;
  414. function system_fopenWT(path: PChar): SYS_FILE; cdecl;
  415.  
  416. {
  417.   system_fclose closes the file fd
  418. }
  419. procedure system_fclose(fd: SYS_FILE); cdecl;
  420.  
  421. {
  422.   This call stops core dumps in a portable way. Returns -1 on error.
  423. }
  424. function system_nocoredumps: Integer; cdecl;
  425.  
  426. function system_winsockerr: PChar; cdecl;
  427. function system_winerr: PChar; cdecl;
  428. function system_lseek(fd: SYS_FILE; off: Longint; wh: Longint): Longint;
  429.  
  430. {
  431.   system_write writes sz bytes from buf to fd. The handler function should
  432.   handle partial writes and anything else like that. Returns IO_*
  433. }
  434. function system_fwrite(fd: SYS_FILE; buf: Pointer; sz: Integer): Integer; cdecl;
  435.  
  436. {
  437.   system_fwrite_atomic locks the given fd before writing to it. This avoids
  438.   interference between simultaneous writes. Returns IO_*
  439. }
  440. function system_fwrite_atomic(fd: SYS_FILE; buf: Pointer; sz: Integer): Integer; cdecl;
  441.  
  442. {
  443.   system_errmsg returns the last error that occured while processing file
  444.   descriptor fd. fd does not have to be specified (if the error is a global
  445.   such as in UNIX systems). PPS: Rob is a halfwit. This parameter is useless.
  446. }
  447. function file_notfound: Integer; cdecl;
  448. function system_errmsg: PChar; cdecl; {system_errmsg_fn}
  449. function system_errmsg_fn: PChar; cdecl;
  450.  
  451. {
  452.   flock locks a file against interference from other processes
  453.   ulock unlocks it.
  454. }
  455. function system_initlock(fd: SYS_FILE): Integer; cdecl;
  456. function system_flock(fd: SYS_FILE): Integer;
  457. function system_ulock(fd: SYS_FILE): Integer;
  458.  
  459. {
  460.   setinherit sets whether the file descriptor fd can be inherited by child
  461.   processes. A non-zero value means they can. Return of -1 means error.
  462. }
  463. function file_setinherit(fd: SYS_FILE; value: Integer): Integer; cdecl;
  464.  
  465. {
  466.   unix2local converts a unix-style pathname to a local one
  467. }
  468. procedure file_unix2local(path, p2: PChar); cdecl;
  469.  
  470. {* -------------------------- Dir related defs ---------------------------- *}
  471.  
  472.  
  473. type
  474.   PDirEnt = ^TDirEnt;
  475.   TDirEnt = packed record
  476.     d_name: PChar;
  477.   end;
  478.   dirent_s = TDirEnt;
  479.  
  480.   PDir = ^TDir;
  481.   TDir = record
  482.     dp: THandle;
  483.     fdata: TWin32FindData;
  484.     de: dirent_s;
  485.   end;
  486.   dir_s = TDir;
  487.  
  488.   SYS_DIR = PDir;
  489.   SYS_DIRENT = TDir;
  490.  
  491. function dir_open(path: PChar): SYS_DIR; cdecl;
  492. function dir_read(ds: SYS_DIR): PDirEnt; cdecl;
  493. procedure dir_close(ds: SYS_DIR); cdecl;
  494. function dir_create(Path: PChar): Integer;
  495. function dir_remove(Path: PChar): Integer;
  496.  
  497. {
  498.   create a directory and any of its parents
  499. }
  500. function dir_create_all(dir: PChar): Integer; cdecl;
  501.  
  502. {
  503.   Thread-safe variants of localtime and gmtime
  504. }
  505. type
  506.   tm = record
  507.     tm_sec: Integer;
  508.     tm_min: Integer;
  509.     tm_hour: Integer;
  510.     tm_mday: Integer;
  511.     tm_mon: Integer;
  512.     tm_year: Integer;
  513.     tm_wday: Integer;
  514.     tm_yday: Integer;
  515.     tm_isdst: Integer;
  516.   end;
  517.   ptm = ^tm;
  518.  
  519. {!!! need conversion }
  520. {function system_localtime(curtime: Longint) localtime(curtime)
  521. function system_gmtime(curtime: Longint) gmtime(curtime) }
  522.  
  523. {*****************************************************************************}
  524. {* From pblock.h                                                              }
  525. {*****************************************************************************}
  526. {
  527.   pblock.h: Header for Parameter Block handling functions
  528.  
  529.   A parameter block is a set of name=value pairs which are generally used
  530.   as parameters, but can be anything. They are kept in a hash table for
  531.   reasonable speed, but if you are doing any intensive modification or
  532.   access of them you should probably make a local copy of each parameter
  533.   while working.
  534.  
  535.   When creating a pblock, you specify the hash table size for that pblock.
  536.   You should set this size larger if you know that many items will be in
  537.   that pblock, and smaller if only a few will be used or if speed is not
  538.   a concern.
  539.  
  540.   The hashing function is very simple right now, and only looks at the
  541.   first character of name.
  542.  
  543. }
  544.  
  545. {* ------------------------------ Structures ------------------------------ *}
  546.  
  547.  
  548. type
  549.   PPbParam = ^TPbParam;
  550.   TPbParam = record
  551.     name: PChar;
  552.     value: PChar;
  553.   end;
  554.   pb_param = TPbParam;
  555.  
  556.   PPbEntry = ^TPbEntry;
  557.   TPbEntry = record
  558.     param: PPbParam;
  559.     next: PPbEntry;
  560.   end;
  561.   pb_entry = TPbEntry;
  562.   PPPbEntry = ^PPbEntry;
  563.  
  564.   PPblock = ^TPblock;
  565.   TPblock = record
  566.     hsize: Integer;
  567.     ht: PPPbEntry;
  568.   end;
  569.   pblock = TPblock;
  570.  
  571.   TPCharArray = array[0..MaxInt div 16 - 1] of PChar;
  572.   PPCharArray = ^TPCharArray;
  573.  
  574. {* ------------------------------ Prototypes ------------------------------ *}
  575.  
  576.  
  577. {
  578.   param_create creates a parameter with the given name and value. If name
  579.   and value are non-NULL, they are copied and placed into the new pb_param
  580.   struct.
  581. }
  582. function param_create(name, value: PChar): PPbParam; cdecl;
  583.  
  584. {
  585.   param_free frees a given parameter if it's non-NULL, and returns 1 if
  586.   p was non-NULL, and 0 if p was NULL.
  587.  
  588.   Useful for error checking pblock_remove.
  589. }
  590. function param_free(pp: PPbParam): Integer; cdecl;
  591.  
  592. {
  593.   pblock_create creates a new pblock with hash table size n.
  594.  
  595.   It returns the newly allocated pblock.
  596. }
  597. function pblock_create(n: Integer): PPblock; cdecl;
  598.  
  599. {
  600.   pblock_free frees the given pblock and any entries inside it.
  601.  
  602.   If you want to save anything in a pblock, remove its entities with
  603.   pblock_remove first and save the pointers you get.
  604. }
  605. procedure pblock_free(pb: PPblock); cdecl;
  606.  
  607. {
  608.   pblock_find finds the entry with the given name in pblock pb.
  609.  
  610.   If it is successful, it returns the param block. If not, it returns NULL.
  611. }
  612. function pblock_find(name: PChar; pb: PPblock): PPbParam;
  613.  
  614. {
  615.   pblock_findval finds the entry with the given name in pblock pb, and
  616.   returns its value, otherwise returns NULL.
  617. }
  618. function pblock_findval(name: PChar; pb: PPblock): PChar; cdecl;
  619.  
  620. {
  621.   pblock_remove behaves exactly like pblock_find, but removes the given
  622.   entry from pb.
  623. }
  624. function pblock_remove(name: PChar; pb: PPblock): PPbParam;
  625.  
  626. {
  627.   pblock_nvinsert creates a new parameter with the given name and value
  628.   and inserts it into pblock pb. The name and value in the parameter are
  629.   also newly allocated. Returns the pb_param it allocated (in case you
  630.   need it).
  631.  
  632.   pblock_nninsert inserts a numerical value.
  633. }
  634. function pblock_nvinsert(name, value: PChar; pb: PPblock): PPbParam; cdecl;
  635. function pblock_nninsert(name: PChar; value: Integer; pb: PPblock): PPbParam; cdecl;
  636.  
  637. {
  638.   pblock_pinsert inserts a pb_param into a pblock.
  639. }
  640. procedure pblock_pinsert(pp: PPbParam; pb: PPblock); cdecl;
  641.  
  642. {
  643.   pblock_str2pblock scans the given string str for parameter pairs
  644.   name=value, or name="value". Any \ must be followed by a literal
  645.   character. If a string value is found, with no unescaped = signs, it
  646.   will be added with the name 1, 2, 3, etc. depending on whether it was
  647.   first, second, third, etc. in the stream (zero doesn't count).
  648.  
  649.   Returns the number of parameters added to the table, or -1 upon error.
  650. }
  651. function pblock_str2pblock(str: PChar; pb: PPblock): Integer; cdecl;
  652.  
  653. {
  654.   pblock_pblock2str places all of the parameters in the given pblock
  655.   into the given string (NULL if it needs creation). It will re-allocate
  656.   more space for the string. Each parameter is separated by a space and of
  657.   the form name="value"
  658. }
  659. function pblock_pblock2str(pb: PPblock; str: PChar): PChar; cdecl;
  660.  
  661. {
  662.   pblock_copy copies the entries in the given source pblock to the
  663.   destination one. The entries are newly allocated so that the original
  664.   pblock may be freed or the new one changed without affecting the other.
  665. }
  666. procedure pblock_copy(src, dst: PPblock); cdecl;
  667.  
  668. {
  669.   pblock_dup creates a new pblock and copies the given source pblock
  670.   into it.  The entries are newly allocated so that the original pblock
  671.   may be freed or the new one changed without affecting the other.
  672. }
  673. function pblock_dup(src: PPblock): PPblock; cdecl;
  674.  
  675. {
  676.   pblock_pb2env copies the given pblock into the given environment, with
  677.   one new env entry for each name/value pair in the pblock.
  678. }
  679. function pblock_pb2env(pb: PPblock; env: PPCharArray): PPCharArray;
  680.  
  681. {* --------------------------- Internal things ---------------------------- *}
  682. function _pblock_fr(name: PChar; pb: PPblock; remove: BOOL): PPbParam; cdecl;
  683.  
  684. {*****************************************************************************}
  685. {* From net.h                                                                 }
  686. {*****************************************************************************}
  687. {
  688.   system specific networking definitions
  689. }
  690.  
  691. const
  692. {* This should be a user-given parameter later *}
  693.   NET_BUFFERSIZE = 8192;
  694. {* So should this. *}
  695.   NET_READ_TIMEOUT = 120;
  696.   NET_WRITE_TIMEOUT = 300;
  697.   NET_INFINITE_TIMEOUT = 0;
  698.   NET_ZERO_TIMEOUT = -1;
  699.  
  700.   SSL_HANDSHAKE_TIMEOUT = 300;
  701.  
  702. {* ------------------------------ Data types ------------------------------ *}
  703. type
  704.   SYS_NETFD = Integer;
  705.  
  706. const
  707.   SYS_NET_ERRORFD = (-1);
  708.  
  709. {* -------------------------------- Global -------------------------------- *}
  710.  
  711. {!!!
  712. extern int net_enabledns;
  713. extern int net_listenqsize;
  714.  
  715.  
  716. int net_accept_init(int port);
  717. void net_accept_terminate(void);
  718. void net_accept_enter(void);
  719. int net_accept_tenter(void);
  720. void net_accept_exit(void);
  721. void net_accept_texit(void);
  722. }
  723.  
  724. {* ------------------------------ Prototypes ------------------------------ *}
  725.  
  726.  
  727. function net_socket(domain, nettype, protocol: Integer): SYS_NETFD; cdecl;
  728. function net_getsockopt(s: SYS_NETFD; level, optname: Integer; optval: Pointer;
  729.   var optlen: Integer): Integer; cdecl;
  730. function net_setsockopt(s: SYS_NETFD; level, optname: Integer; optval: Pointer;
  731.   optlen: Integer): Integer; cdecl;
  732. function net_listen(s: SYS_NETFD; backlog: Integer): Integer; cdecl;
  733. function net_create_listener(ipaddr: PChar; port: Integer): SYS_NETFD; cdecl;
  734. function net_select(nfds: Integer; r, w, e: PFDSet; timeout: PTimeVal): Integer; cdecl;
  735. function net_connect(s: SYS_NETFD; sockaddr: Pointer; namelen: Integer): Integer; cdecl;
  736. function net_ioctl(s: SYS_NETFD; tag: Integer; result: Pointer): Integer; cdecl;
  737. function net_getpeername(s: SYS_NETFD; var name: TSockAddr; var namelen: Integer): Integer; cdecl;
  738. function net_close(s: SYS_NETFD): Integer; cdecl;
  739. function net_bind(s: SYS_NETFD; var name: TSockAddr; namelen: Integer): Integer; cdecl;
  740. function net_accept(s: SYS_NETFD; addr: PSockAddr; addrlen: PInteger): SYS_NETFD; cdecl;
  741. function net_read(sd: SYS_NETFD; buf: PChar; sz, timeout: Integer): Integer; cdecl;
  742. function net_write(sd: SYS_NETFD; buf: PChar; sz: Integer): Integer; cdecl;
  743. {!!! what is iovec???? }
  744. // function _net_writev(sd: SYS_NETFD; struct iovec *iov, int iovlen);
  745.  
  746. {
  747.   net_isalive checks to see if the given sd is still connected to a remote
  748.   host. It returns 0 if the socket is no longer connected, or 1 if it is
  749.   still there. The remote host will not see any side effects.
  750. }
  751. function net_isalive(sd: SYS_NETFD): BOOL; cdecl;
  752.  
  753. {!!! what is iovec???
  754. int _net_simulated_writev(SYS_NETFD sd, struct iovec *iov, int iovlen);
  755. NSAPI_PUBLIC extern int
  756. (*net_writev)(SYS_NETFD sd, struct iovec *iov, int iovlen);
  757. }
  758.  
  759. {
  760.   net_ip2host transforms the given textual IP number into a FQDN. If it
  761.   can't find a FQDN, it will return what it can get. Otherwise, NULL.
  762.  
  763.   verify is whether or not the function should verify the hostname it
  764.   gets. This takes an extra query but is safer for use in access control.
  765. }
  766. function net_ip2host(ip: PChar; verify: BOOL): PChar; cdecl;
  767.  
  768. {*****************************************************************************}
  769. {* From buffer.h                                                              }
  770. {*****************************************************************************}
  771. {
  772.   For performing buffered I/O on a file or socket descriptor.
  773.  
  774.   This is an abstraction to allow I/O to be performed regardless of the
  775.   current system. That way, an integer file descriptor can be used under
  776.   UNIX but a stdio FILE structure could be used on systems which don't
  777.   support that or don't support it as efficiently.
  778.  
  779.   Two abstractions are defined: A file buffer, and a network buffer. A
  780.   distinction is made so that mmap() can be used on files (but is not
  781.   required). Also, the file buffer takes a file name as the object to
  782.   open instead of a file descriptor. A lot of the network buffering
  783.   is almost an exact duplicate of the non-mmap file buffering.
  784.  
  785.   If an error occurs, system-independent means to obtain an error string
  786.   are also provided. However, if the underlying system is UNIX the error
  787.   may not be accurate in a threaded environment.
  788. }
  789.  
  790. {* ------------------------------ Structures ------------------------------ *}
  791.  
  792. type
  793.   PFileBuffer = ^TFileBuffer;
  794.   TFileBuffer = record
  795.     fd: SYS_FILE;
  796.     fdmap: THandle;
  797.     fp: PChar;
  798.     len: Integer;
  799.     inbuf: PChar;   // for buffer_grab
  800.     cursize: Integer;
  801.     pos: Integer;
  802.     errmsg: PChar;
  803.   end;
  804.   filebuffer = TFileBuffer;
  805.   filebuf = filebuffer;
  806.  
  807.   PNetBuf = ^TNetBuf;
  808.   TNetBuf = record
  809.     sd: SYS_NETFD;
  810.     pos,
  811.     cursize,
  812.     maxsize,
  813.     rdtimeout: Integer;
  814.     address: array[0..63] of Char;
  815.     inbuf: PChar;
  816.     errmsg: PChar;
  817.   end;
  818.   netbuf = TNetBuf;
  819.  
  820.  
  821. {* -------------------------------- Macros -------------------------------- *}
  822.  
  823. {
  824.   netbuf_getc gets a character from the given network buffer and returns
  825.   it. (as an integer).
  826.  
  827.   It will return (int) IO_ERROR for an error and (int) IO_EOF for
  828.   an error condition or EOF respectively.
  829. }
  830. function netbuf_getc(b: PNetBuf): Integer;
  831. function filebuf_getc(b: PFileBuffer): Integer;
  832. function pipebuf_getc(b: PFileBuffer): Integer;
  833.  
  834. {
  835.   buffer_error returns the last error that occurred with buffer. Don't use
  836.   this unless you know an error occurred. Independent of network/file type.
  837. }
  838. //!!! #define buffer_error(b) ((b)->errmsg)
  839.  
  840. {* ------------------------------ Prototypes ------------------------------ *}
  841.  
  842.  
  843. {
  844.   buffer_open opens a new buffer reading the specified file, with an I/O
  845.   buffer of size sz, and returns a new buffer structure which will hold
  846.   the data.
  847.  
  848.   If FILE_UNIX_MMAP is defined, this may return NULL. If it does, check
  849.   system_errmsg to get a message about the error.
  850. }
  851.  
  852. function filebuf_open(fd: SYS_FILE; sz: Integer): PFileBuffer; cdecl;
  853. function netbuf_open(sd: SYS_NETFD; sz: Integer): PNetBuf; cdecl;
  854.  
  855. {
  856.   filebuf_create is a convenience function if the file is already open
  857.   or mmap'd.  It creates a new filebuf for use with the mmap'd file.
  858.   If mmap_ptr is NULL, or MMAP is not supported on this system, it
  859.   creates a buffer with buffer size bufsz.
  860. }
  861.  
  862. function filebuf_create(fd: SYS_FILE; mmap_ptr: caddr_t; mmap_len,
  863.   bufsz: Integer): PFileBuffer; cdecl;
  864.  
  865. {
  866.   filebuf_close_buffer is provided to cleanup a filebuf without closing
  867.   the underlying file.  If clean_mmap is 1, and the file is memory mapped,
  868.   the file will be unmapped.  If clean_mmap is 0, the file will not
  869.   be unmapped.
  870. }
  871. procedure filebuf_close_buffer(buf: PFileBuffer; clean_mmap: BOOL); cdecl;
  872.  
  873. {
  874.   filebuf_open_nostat is a convenience function for mmap() buffer opens,
  875.   if you happen to have the stat structure already.
  876. }
  877. function filebuf_open_nostat(fd: SYS_FILE; sz: Integer; var finfo: TStat): PFileBuffer; cdecl;
  878. function pipebuf_open(fd: SYS_FILE; sz: Integer; var finfo: TStat): PFileBuffer; cdecl;
  879.  
  880. {
  881.   buffer_next loads size more bytes into the given buffer and returns the
  882.   first one, or BUFFER_EOF on EOF and BUFFER_ERROR on error.
  883. }
  884. function filebuf_next(buf: PFileBuffer; advance: Integer): Integer; cdecl;
  885. function netbuf_next(buf: PNetBuf; advance: Integer): Integer; cdecl;
  886. function pipebuf_next(buf: PFileBuffer; advance: Integer): Integer; cdecl;
  887.  
  888. {
  889.   buffer_close deallocates a buffer and closes its associated files
  890.   (does not close a network socket).
  891. }
  892. procedure filebuf_close(buf: PFileBuffer); cdecl;
  893. procedure netbuf_close(buf: PNetBuf); cdecl;
  894. procedure pipebuf_close(buf: PFileBuffer); cdecl;
  895.  
  896. {
  897.   buffer_grab will set the buffer's inbuf array to an array of sz bytes
  898.   from the buffer's associated object. It returns the number of bytes
  899.   actually read (between 1 and sz). It returns IO_EOF upon EOF or IO_ERROR
  900.   upon error. The cursize entry of the structure will reflect the size
  901.   of the iobuf array.
  902.  
  903.   The buffer will take care of allocation and deallocation of this array.
  904. }
  905. function filebuf_grab(buf: PFileBuffer; sz: Integer): Integer; cdecl;
  906. function netbuf_grab(buf: PNetBuf; sz: Integer): Integer; cdecl;
  907. function pipebuf_grab(buf: PFileBuffer; sz: Integer): Integer; cdecl;
  908.  
  909. {
  910.   netbuf_buf2sd will send n bytes from the (probably previously read)
  911.   buffer and send them to sd. If sd is -1, they are discarded. If n is
  912.   -1, it will continue until EOF is recieved. Returns IO_ERROR on error
  913.   and the number of bytes sent any other time.
  914. }
  915. function netbuf_buf2sd(buf: PNetBuf; sd: SYS_NETFD; len: Integer): Integer; cdecl;
  916.  
  917. {
  918.   filebuf_buf2sd assumes that nothing has been read from the filebuf,
  919.   and just sends the file out to the given socket. Returns IO_ERROR on error
  920.   and the number of bytes sent otherwise.
  921.  
  922.   Does not currently support you having read from the buffer previously. This
  923.   can be changed transparently.
  924. }
  925. function filebuf_buf2sd(buf: PFileBuffer; sd: SYS_NETFD): Integer; cdecl;
  926.  
  927. {
  928.   NT pipe version of filebuf_buf2sd.
  929. }
  930. function pipebuf_buf2sd(buf: PFileBuffer; sd: SYS_NETFD; len: Integer): Integer; cdecl;
  931.  
  932. {
  933.   NT pipe version of netbuf_buf2sd.
  934. }
  935. function pipebuf_netbuf2sd(buf: PNetBuf; sd: SYS_FILE; len: Integer): Integer; cdecl;
  936.  
  937. {*****************************************************************************}
  938. {* From session.h                                                             }
  939. {*****************************************************************************}
  940. {
  941.   Deals with virtual sessions
  942.  
  943.   A session is the time between when a client connects and when it
  944.   disconnects. Several requests may be handled in one session.
  945. }
  946.  
  947. {* ------------------------------ Structures ------------------------------ *}
  948.  
  949. const
  950.   SESSION_HASHSIZE = 5;
  951.  
  952. type
  953.   PSession = ^TSession;
  954.   TSession = record
  955.     {* Client-specific information *}
  956.     client: PPblock;
  957.     csd: SYS_NETFD;
  958.     inbuf: PNetBuf;
  959.     csd_open: Integer;
  960.     iaddr: TInAddr;
  961.     pool: PPoolHandle;
  962.     clauth: Pointer;   {* ACL client authentication information *}
  963.   end;
  964.   Session = TSession;
  965.  
  966. {* ------------------------------ Prototypes ------------------------------ *}
  967.  
  968. {
  969.   session_create creates a new request structure for the client with the
  970.   given socket descriptor and sockaddr.
  971. }
  972. function session_create(csd: SYS_NETFD; sac: PSockAddrIn): PSession; cdecl;
  973.  
  974. {
  975.   session_free frees the given session
  976. }
  977. procedure session_free(sn: PSession);
  978.  
  979. {
  980.   session_dns returns the DNS hostname of the client of this session,
  981.   and inserts it into the client pblock. Returns NULL if unavailable.
  982. }
  983. function session_dns(sn: PSession): PChar;
  984.  
  985. {
  986.   session_maxdns looks up a hostname from an IP address, and then verifies
  987.   that the host is really who they claim to be.
  988. }
  989. function session_maxdns(sn: PSession): PChar;
  990.  
  991. function session_dns_lookup(sn: PSession; verify: BOOL): PChar; cdecl;
  992.  
  993. {*****************************************************************************}
  994. {* From cinfo.h                                                               }
  995. {*****************************************************************************}
  996. {
  997.   Content Information for a file, i.e. its type, etc.
  998. }
  999.  
  1000. {* ------------------------------ Constants ------------------------------- *}
  1001.  
  1002. {
  1003.   This will be the first string in the file, followed by x.x version
  1004.   where x is an integer.
  1005.  
  1006.   Updated due to trendy name change
  1007. }
  1008. const
  1009.   MCC_MT_MAGIC = '#--Mosaic Communications Corporation MIME Information';
  1010.   MCC_MT_MAGIC_LEN = 53;
  1011.   NCC_MT_MAGIC = '#--Netscape Communications Corporation MIME Information';
  1012.   NCC_MT_MAGIC_LEN = 55;
  1013.  
  1014. {* The character which separates extensions with cinfo_find *}
  1015.  
  1016.   CINFO_SEPARATOR = '.';
  1017.  
  1018. {* The maximum length of a line in this file *}
  1019.  
  1020.   CINFO_MAX_LEN = 1024;
  1021.  
  1022. {* The hash table size for that function *}
  1023.   CINFO_HASHSIZE = 27;
  1024.  
  1025. {* The hash function for the database. Hashed on extension. *}
  1026. function CINFO_HASH(s: PChar): Char;
  1027.  
  1028. {* ------------------------------ Structures ------------------------------ *}
  1029. {
  1030.   The ContentInfo structure.
  1031.  
  1032.   Currently, we support the following attributes:
  1033.  
  1034.   1. Type: This identifies what kind of data is in the file.
  1035.   2. Encoding: Identifies any compression or otherwise content-independent
  1036.      transformation which has been applied to the file (uuencode, etc.)
  1037.   3. Language: Identifies the language a text document is in.
  1038.   4. Description: A text string describing the file.
  1039.   5. Viewer: The program to use to view the file.
  1040.  
  1041.   Multiple items are separated with a comma, e.g.
  1042.   encoding="x-gzip, x-uuencode"
  1043. }
  1044.  
  1045. type
  1046.   PCInfo = ^TCInfo;
  1047.   TCInfo = record
  1048.     ctype: PChar;
  1049.     encoding: PChar;
  1050.     language: PChar;
  1051.   end;
  1052.   cinfo = TCInfo;
  1053.  
  1054. {* ------------------------------ Prototypes ------------------------------ *}
  1055.  
  1056. {
  1057.   cinfo_init initializes the content info system. Call this before
  1058.   cinfo_merge.
  1059. }
  1060. procedure cinfo_init; cdecl;
  1061.  
  1062. {
  1063.   cinfo_terminate frees the database for shutdown.
  1064. }
  1065. procedure cinfo_terminate; cdecl;
  1066.  
  1067. {
  1068.   cinfo_merge merges the contents of the given filename with the current
  1069.   cinfo database. It returns NULL upon success and a string (which you
  1070.   must deallocate) upon error.
  1071. }
  1072. function cinfo_merge(fn: PChar): PChar; cdecl;
  1073.  
  1074. {
  1075.   cinfo_find finds any content information for the given uri. The file name
  1076.   is the string following the last / in the uri. Multiple extensions are
  1077.   separated by CINFO_SEPARATOR. You may pass in a filename instead of uri.
  1078.  
  1079.   Returns a newly allocated cinfo structure with the information it
  1080.   finds. The elements of this structure are coming right out of the types
  1081.   database and so if you change it or want to keep it around for long you
  1082.   should strdup it. You should free only the structure itself when finished
  1083.   with it.
  1084.  
  1085.   If there is no information for any one of the extensions it
  1086.   finds, it will ignore that extension. If it cannot find information for
  1087.   any of the extensions, it will return NULL.
  1088. }
  1089. function cinfo_find(uri: PChar): PCInfo; cdecl;
  1090.  
  1091. {
  1092.   cinfo_lookup finds the information about the given content-type, and
  1093.   returns a cinfo structure so you can look up description and icon.
  1094. }
  1095. function cinfo_lookup(ctype: PChar): PCInfo; cdecl;
  1096.  
  1097. {
  1098.   cinfo_dump_database dumps the current database to the given file desc.
  1099. }
  1100. {!!! requires C RTL _iobuf or FILE }
  1101. // NSAPI_PUBLIC void cinfo_dump_database(FILE *dump);
  1102.  
  1103. {*****************************************************************************}
  1104. {* From ereport.h                                                             }
  1105. {*****************************************************************************}
  1106. {
  1107.   Records transactions, reports errors to administrators, etc.
  1108. }
  1109.  
  1110. {* ------------------------------ Constants ------------------------------- *}
  1111.  
  1112. const
  1113. {
  1114.   The maximum length of an error message. NOT RUN-TIME CHECKED
  1115. }
  1116.   MAX_ERROR_LEN = 8192;
  1117.  
  1118. {* A warning is a minor mishap, such as a 404 being issued. *}
  1119.   LOG_WARN = 0;
  1120.  
  1121. {
  1122.   A misconfig is when there is a syntax error or permission violation in
  1123.   a config. file.
  1124. }
  1125.   LOG_MISCONFIG = 1;
  1126.  
  1127. {
  1128.   Security warnings are issued when authentication fails, or a host is
  1129.   given a 403 return code.
  1130. }
  1131.   LOG_SECURITY = 2;
  1132.  
  1133. {
  1134.   A failure is when a request could not be fulfilled due to an internal
  1135.   problem, such as a CGI script exiting prematurely, or a filesystem
  1136.   permissions problem.
  1137. }
  1138.   LOG_FAILURE = 3;
  1139.  
  1140. {
  1141.   A catastrophe is a fatal server error such as running out of
  1142.   memory or processes, or a system call failing, or even a server crash.
  1143.   The server child cannot recover from a catastrophe.
  1144. }
  1145.   LOG_CATASTROPHE = 4;
  1146.  
  1147. {
  1148.   Informational message, of no concern.
  1149. }
  1150.   LOG_INFORM = 5;
  1151.  
  1152. {
  1153.   The time format to use in the error log
  1154. }
  1155.   ERR_TIMEFMT = '[%d/%b/%Y:%H:%M:%S]';
  1156.  
  1157.  
  1158. {* The fd you will get if you are reporting errors to SYSLOG *}
  1159.  
  1160.   ERRORS_TO_SYSLOG = -1;
  1161.  
  1162. {* ------------------------------ Prototypes ------------------------------ *}
  1163.  
  1164. {
  1165.   ereport logs an error of the given degree and formats the arguments with
  1166.   the printf() style fmt. Returns whether the log was successful. Records
  1167.   the current date.
  1168. }
  1169. {!!! require C/C++ varargs support !!!}
  1170. //NSAPI_PUBLIC int ereport(int degree, char *fmt, ...);
  1171.  
  1172. {
  1173.   ereport_init initializes the error logging subsystem and opens the static
  1174.   file descriptors. It returns NULL upon success and an error string upon
  1175.   error. If a userpw is given, the logs will be chowned to that user.
  1176.  
  1177.   email is the address of a person to mail upon catastrophic error. It
  1178.   can be NULL if no e-mail is desired. ereport_init will not duplicate
  1179.   its own copy of this string; you must make sure it stays around and free
  1180.   it when you shut down the server.
  1181. }
  1182. function ereport_init(err_fn, email: PChar; var pw: PASSWD): PChar; cdecl;
  1183.  
  1184. {
  1185.   log_terminate closes the error and common log file descriptors.
  1186. }
  1187. procedure ereport_terminate; cdecl;
  1188.  
  1189. {* For restarts *}
  1190. function ereport_getfd: SYS_FILE; cdecl;
  1191.  
  1192. {*****************************************************************************}
  1193. {* From shexp.h                                                               }
  1194. {*****************************************************************************}
  1195. {
  1196.   Defines and prototypes for shell exp. match routines
  1197.  
  1198.  
  1199.   This routine will match a string with a shell expression. The expressions
  1200.   accepted are based loosely on the expressions accepted by zsh.
  1201.  
  1202.   o * matches anything
  1203.   o ? matches one character
  1204.   o \ will escape a special character
  1205.   o $ matches the end of the string
  1206.   o [abc] matches one occurence of a, b, or c. The only character that needs
  1207.           to be escaped in this is ], all others are not special.
  1208.   o [a-z] matches any character between a and z
  1209.   o [^az] matches any character except a or z
  1210.   o ~ followed by another shell expression will remove any pattern
  1211.       matching the shell expression from the match list
  1212.   o (foo|bar) will match either the substring foo, or the substring bar.
  1213.               These can be shell expressions as well.
  1214.  
  1215.   The public interface to these routines is documented below.
  1216. }
  1217.  
  1218. {* --------------------------- Public routines ---------------------------- *}
  1219.  
  1220. {
  1221.   shexp_valid takes a shell expression exp as input. It returns:
  1222.  
  1223.    NON_SXP      if exp is a standard string
  1224.    INVALID_SXP  if exp is a shell expression, but invalid
  1225.    VALID_SXP    if exp is a valid shell expression
  1226. }
  1227.  
  1228. const
  1229.    NON_SXP = -1;
  1230.    INVALID_SXP = -2;
  1231.    VALID_SXP = 1;
  1232.  
  1233. {* and generic shexp/regexp versions *}
  1234.    NON_WILDPAT     = NON_SXP;
  1235.    INVALID_WILDPAT = INVALID_SXP;
  1236.    VALID_WILDPAT   = VALID_SXP;
  1237.  
  1238. {* and regexp versions *}
  1239.    NON_REGEXP      = NON_SXP;
  1240.    INVALID_REGEXP  = INVALID_SXP;
  1241.    VALID_REGEXP    = VALID_SXP;
  1242.  
  1243. function shexp_valid(exp: PChar): Integer; cdecl;
  1244.  
  1245. {
  1246.   shexp_match
  1247.  
  1248.   Takes a prevalidated shell expression exp, and a string str.
  1249.  
  1250.   Returns 0 on match and 1 on non-match.
  1251. }
  1252. function shexp_match(str, exp: PChar): Integer; cdecl;
  1253.  
  1254. {
  1255.   shexp_cmp
  1256.  
  1257.   Same as above, but validates the exp first. 0 on match, 1 on non-match,
  1258.   -1 on invalid exp. shexp_casecmp does the same thing but is case
  1259.   insensitive.
  1260. }
  1261. function shexp_cmp(str, exp: PChar): Integer; cdecl;
  1262. function shexp_casecmp(str, exp: PChar): Integer; cdecl;
  1263.  
  1264. {*****************************************************************************}
  1265. {* From shmem.h                                                               }
  1266. {*****************************************************************************}
  1267. {
  1268.   Portable abstraction for memory shared among a server's workers
  1269. }
  1270.  
  1271. {* --------------------------- Data structures ---------------------------- *}
  1272.  
  1273. type
  1274.   PShMem = ^TShMem;
  1275.   TShMem = record
  1276.     data: Pointer;   {* the data *}
  1277.     fdmap: THandle;
  1278.     size: Integer;   {* the maximum length of the data *}
  1279.     name: PChar;     {* internal use: filename to unlink if exposed *}
  1280.     fd: SYS_FILE;    {* internal use: file descriptor for region *}
  1281.   end;
  1282.   shmem_s = TShMem;
  1283.  
  1284. {* ------------------------------ Prototypes ------------------------------ *}
  1285.  
  1286. {
  1287.   shmem_alloc allocates a region of shared memory of the given size, using
  1288.   the given name to avoid conflicts between multiple regions within the
  1289.   program. The region will not be automatically grown if its boundaries
  1290.   are over-run, use shmem_realloc for that.
  1291.  
  1292.   If expose is non-zero and the underlying system supports it, the
  1293.   file used to create the shared region will be visible to other processes
  1294.   running on the system.
  1295.  
  1296.   name should be unique to the program which calls this routine, otherwise
  1297.   conflicts will arise.
  1298.  
  1299.   Returns a new shared memory region, with the data element being a
  1300.   pointer to the shared memory. This function must be called before any
  1301.   daemon workers are spawned, in order for the handle to the shared region
  1302.   to be inherited by the children.
  1303.  
  1304.   Because of the requirement that the region must be inherited by the
  1305.   children, the region cannot be re-allocated with a larger size when
  1306.   necessary.
  1307. }
  1308. function shmem_alloc(name: PChar; size: Integer; expose: BOOL): PShMem; cdecl;
  1309.  
  1310. {
  1311.   shmem_free de-allocates the specified region of shared memory.
  1312. }
  1313. procedure shmem_free(region: PShMem); cdecl;
  1314.  
  1315. {*****************************************************************************}
  1316. {* From systhr.h                                                              }
  1317. {*****************************************************************************}
  1318. {
  1319.   Abstracted threading mechanisms
  1320. }
  1321.  
  1322. type
  1323.   SYS_THREAD = Pointer;
  1324.   TSysThreadFunc = procedure (Arg: Pointer) cdecl;
  1325.  
  1326. const
  1327.   SYS_THREAD_ERROR = nil;
  1328.   SYSTHREAD_DEFAULT_PRIORITY = 16;
  1329.  
  1330. {
  1331.   systhread_start creates a thread with the given priority, will allocate
  1332.   a stack of stksz bytes, and calls fn with arg as its argument. stksz
  1333.   of zero will allocate a default stack size.
  1334.  
  1335.   Returns a new SYS_THREAD pointer on success, SYS_THREAD_ERROR on failure.
  1336.   XXX Priorities are system dependent
  1337. }
  1338. function systhread_start(prio, stksz: Integer; fn: TSysThreadFunc; arg: Pointer): SYS_THREAD; cdecl;
  1339.  
  1340. {
  1341.   systhread_current returns a pointer to the current thread.
  1342. }
  1343. function systhread_current: SYS_THREAD;
  1344.  
  1345. {
  1346.   systhread_yield yields the processor to another thread
  1347. }
  1348. procedure systhread_yield; cdecl;
  1349.  
  1350. {
  1351.   systhread_attach makes an existing thread an NSPR thread.
  1352. }
  1353. function systhread_attach: SYS_THREAD; cdecl;
  1354.  
  1355. {
  1356.   systhread_terminate terminates the thread that is passed in.
  1357. }
  1358. procedure systhread_terminate(thr: SYS_THREAD);
  1359.  
  1360. {
  1361.   systhread_sleep puts the calling thread to sleep for the given number
  1362.   of milliseconds.
  1363. }
  1364. procedure systhread_sleep(milliseconds: Integer); cdecl;
  1365.  
  1366. {
  1367.   systhread_init initializes the threading system. name is a name for the
  1368.   program for debugging.
  1369. }
  1370. procedure systhread_init(name: PChar); cdecl;
  1371.  
  1372. {
  1373.   systhread_timerset starts or re-sets the interrupt timer for a thread
  1374.   system. This should be considered a suggestion as most systems don't allow
  1375.   the timer interval to be changed.
  1376. }
  1377. procedure systhread_timerset(usec: Integer); cdecl;
  1378.  
  1379. {
  1380.   newkey allocates a new integer id for thread-private data. Use this
  1381.   key to identify a variable which you want to appear differently
  1382.   between threads, and then use setdata to associate a value with this
  1383.   key for each thread.
  1384. }
  1385. function systhread_newkey: Integer; cdecl;
  1386.  
  1387. {
  1388.   Get data that has been previously associated with key in this thread.
  1389.   Returns NULL if setkey has not been called with this key by this
  1390.   thread previously, or the data that was previously used with setkey
  1391.   by this thread with this key.
  1392. }
  1393. function systhread_getdata(key: Integer): Pointer; cdecl;
  1394.  
  1395. {
  1396.   Associate data with the given key number in this thread.
  1397. }
  1398. procedure systhread_setdata(key: Integer; data: Pointer); cdecl;
  1399.  
  1400. {*****************************************************************************}
  1401. {* From daemon.h                                                              }
  1402. {*****************************************************************************}
  1403. {
  1404.   Things related to the accepting connections
  1405. }
  1406.  
  1407. {* ------------------------------- Defines -------------------------------- *}
  1408.  
  1409. // NSAPI_PUBLIC void child_exit(int status);
  1410.  
  1411. const
  1412. {* Codes for child_status *}
  1413.   CHILD_EMPTY_SLOT = $fe;
  1414.   CHILD_AWAIT_CONNECT = $ff;
  1415.   CHILD_PROCESSING = $00;
  1416.   CHILD_READING = $01;
  1417.   CHILD_WRITING = $02;
  1418.   CHILD_RESOLVING = $03;
  1419. {* Need completors to handle async IO *}
  1420.   CHILD_DONE_PROCESSING = $14;
  1421.   CHILD_DONE_READING = $15;
  1422.   CHILD_DONE_WRITING = $16;
  1423.   CHILD_DONE_RESOLVING = $17;
  1424.  
  1425.   MAX_IP_DOMAINS = 256;
  1426.  
  1427. type
  1428.   PMultipleDomains = ^TMultipleDomains;
  1429.   TMultipleDomains = record
  1430.     address: PChar;
  1431.     docroot: PChar;
  1432.     sd: SYS_NETFD;
  1433.     threads: Integer;
  1434.     AddressNumber: Integer;
  1435.   end;
  1436.   multiple_domains = TMultipleDomains;
  1437.  
  1438.   TChildCallback = procedure (sn: PSession) cdecl;
  1439.   TRotateCallback = procedure cdecl;
  1440.   TRCBack = procedure (Param: Integer) cdecl;
  1441.  
  1442.   PDaemon = ^TDaemon;
  1443.   TDaemon = record
  1444.     ipstr: PChar;
  1445.     port: Integer;
  1446.     child_callback: TChildCallback;
  1447.     rotate_callback: TRotateCallback;
  1448.     servid: PChar;
  1449.     domains: PMultipleDomains;
  1450.     rcback: TRCBack;
  1451.     maxprocs: Integer;
  1452.     minprocs: Integer;
  1453.     proclife: Integer;
  1454.     maxthreads: Integer;
  1455.     minthreads: Integer;
  1456. {$ifdef NET_SSL}
  1457.     char *secure_keyfn;
  1458.     char *secure_certfn;
  1459.     int secure_auth;
  1460.     int secure_session_timeout;
  1461.     long ssl3_secure_session_timeout;
  1462.     int security;
  1463.     int ssl3;
  1464.     int ssl2;
  1465. {$endif}
  1466.   end;
  1467.   daemon_s = TDaemon;
  1468.  
  1469. {* ------------------------------ Prototypes ------------------------------ *}
  1470.  
  1471. {
  1472.   daemon_run accepts whether or not it should detach from its parent process,
  1473.   and a daemon structure as its arguments. The daemon structure contains
  1474.   a port number, a root directory to chroot to (can be NULL), a filename to
  1475.   log the daemon pid to (can be NULL). daemon_run never returns.
  1476.  
  1477.   child_callback is a function which will be called every time a new
  1478.   connection is recieved. Session is a new session ID.
  1479.  
  1480.   rcback is a function which is a restart function: When SIGHUP is received,
  1481.   this function will be called. You may give SIG_DFL if you don't want to
  1482.   support restarting. The rcback will be passed SIGHUP.
  1483.  
  1484.   pw is the passwd entry to run the daemon as. If the effective user id is
  1485.   root, daemon_run will try to set its uid and gid to the user pointed
  1486.   to by this structure. You may pass NULL.
  1487. }
  1488. procedure _ntdaemon_run(Param: Pointer); cdecl;
  1489.  
  1490. {
  1491.   daemon_atrestart registers a function to be called fn, with the given
  1492.   void pointer as an argument, when the server is restarted.
  1493. }
  1494. procedure daemon_atrestart(fn: TDaemonAtRestart; data: Pointer); cdecl;
  1495.  
  1496. {
  1497.   fork is a wrapper for the system's fork function. This closes the listen
  1498.   socket for the mob. This also makes sure that a threaded daemon only gets
  1499.   the calling thread and not all of them.
  1500. }
  1501. function child_fork: pid_t;
  1502.  
  1503. {* servssl_init is in base/servssl.c *}
  1504. {$ifdef NET_SSL}
  1505. procedure servssl_init(keyfn, certfn: PChar; stimeout: Integer; ssl3timeout: Longint;
  1506.   servid: PChar); cdecl;
  1507. {$endif NET_SSL}
  1508.  
  1509. {*****************************************************************************}
  1510. {* From util.h                                                                }
  1511. {*****************************************************************************}
  1512. {
  1513.   A hodge podge of utility functions and standard functions which
  1514.   are unavailable on certain systems
  1515. }
  1516.  
  1517. {* ------------------------------ Prototypes ------------------------------ *}
  1518.  
  1519.  
  1520. {
  1521.   getline scans in buf until it finds a LF or CRLF, storing the string in
  1522.   l. It will terminate the string and return:
  1523.  
  1524.    0 when done, with the scanned line (minus CR or LF) in l
  1525.    1 upon EOF, with the scanned line (minus CR or LF) in l
  1526.   -1 on error with the error description in l (uses lineno for information)
  1527. }
  1528. function util_getline(buf: PFileBuffer; lineno, maxlen: Integer; l: PChar): Integer; cdecl;
  1529.  
  1530. {
  1531.   env_create creates a new environment with the given env, with n new
  1532.   entries, and places the current position that you should add your
  1533.   entries with at pos.
  1534.  
  1535.   If env is NULL, it will allocate a new one. If not, it will reallocate
  1536.   that one.
  1537. }
  1538. function util_env_create(env: PPCharArray; n: Integer; var pos: Integer): PPCharArray; cdecl;
  1539.  
  1540. {
  1541.   util_env_str allocates a string from the given name and value and
  1542.   returns it. It does not check for things like = signs in name.
  1543. }
  1544. function util_env_str(name, value: PChar): PChar; cdecl;
  1545.  
  1546. {
  1547.   env_replace replaces the occurrence of the given variable with the
  1548.   value you give.
  1549. }
  1550. procedure util_env_replace(env: PPCharArray; name, value: PChar); cdecl;
  1551.  
  1552. {
  1553.   util_env_free frees an environment.
  1554. }
  1555. procedure util_env_free(env: PPCharArray); cdecl;
  1556.  
  1557. {
  1558.   util_env_copy copies an env
  1559. }
  1560. function util_env_copy(src, dst: PPCharArray): PPCharArray; cdecl;
  1561.  
  1562. {
  1563.   util_env_find looks through env for the named string. Returns the
  1564.   corresponding value if the named string is found, or NULL if not.
  1565. }
  1566. function util_env_find(env: PPCharArray; name: PChar): PChar; cdecl;
  1567.  
  1568. {
  1569.   hostname gets the local hostname. Returns NULL if it can't find a FQDN.
  1570.   You are free to realloc or free this string.
  1571. }
  1572. function util_hostname: PChar; cdecl;
  1573.  
  1574. {
  1575.   chdir2path changes the current directory to the one that the file
  1576.   path is in. path should point to a file. Caveat: path must be a writable
  1577.   string. It won't get modified permanently.
  1578. }
  1579. function util_chdir2path(path: PChar): Integer;
  1580.  
  1581. {
  1582.   is_mozilla checks if the given user-agent is mozilla, of at least
  1583.   the given major and minor revisions. These are strings to avoid
  1584.   ambiguities like 1.56 > 1.5
  1585. }
  1586. function util_is_mozilla(ua, major, minor: PChar): BOOL; cdecl;
  1587.  
  1588. {
  1589.   is_url will return 1 if the given string seems to be a URL, or will
  1590.   return 0 otherwise.
  1591.  
  1592.   Because of stupid news URLs, this will return 1 if the string has
  1593.   all alphabetic characters up to the first colon and will not check for
  1594.   the double slash.
  1595. }
  1596. function util_is_url(url: PChar): BOOL; cdecl;
  1597.  
  1598. {
  1599.   util_later_than checks the date in the string ims, and if that date is
  1600.   later than or equal to the one in the tm struct lms, then it returns 1.
  1601.  
  1602.   util_time_equal is above, but checks for exact equality.
  1603.  
  1604.   Handles RFC 822, 850, and ctime formats.
  1605. }
  1606.  
  1607. function util_later_than(var lms: tm; ims: PChar): BOOL; cdecl;
  1608. function util_time_equal(var lms: tm; ims: PChar): BOOL; cdecl;
  1609.  
  1610. {
  1611.   util_str_time_equal checks the character-string dates are equal.
  1612.   Supports rfc1123 and rfc850 formats.  t1 must be rfc1123
  1613.   Returns 0 if equal, -1 otherwise
  1614. }
  1615. function util_str_time_equal(t1, t2: PChar): Integer; cdecl;
  1616.  
  1617. {
  1618.   util_uri_is_evil returns 1 if a URL has ../ or // in it.
  1619. }
  1620. function util_uri_is_evil(t: PChar): BOOL; cdecl;
  1621.  
  1622. {
  1623.   util_uri_parse gets rid of /../, /./, and //.
  1624.  
  1625.   Assumes that either the string starts with a /, or the string will
  1626.   not .. right off of its beginning.  As such, ../foo.gif will
  1627.   not be changed, although /../foo.gif will become /foo.gif.
  1628. }
  1629. procedure util_uri_parse(uri: PChar); cdecl;
  1630.  
  1631. {
  1632.   util_uri_unescape unescapes the given URI in place (% conversions only).
  1633. }
  1634. procedure util_uri_unescape(s: PChar); cdecl;
  1635.  
  1636. {
  1637.   util_uri_escape escapes any nasty chars in s and copies the string into d.
  1638.   If d is NULL, it will allocate and return a properly sized string.
  1639.   Warning: does not check bounds on a given d.
  1640.  
  1641.   util_url_escape does the same thing but does it for a url, i.e. ?:+ is
  1642.   not escaped.
  1643. }
  1644. function util_uri_escape(d, s: PChar): PChar; cdecl;
  1645. function util_url_escape(d, s: PChar): PChar; cdecl;
  1646.  
  1647. {
  1648.   util_sh_escape places a \ in front of any shell-special characters.
  1649.   Returns a newly-allocated copy of the string.
  1650. }
  1651. function util_sh_escape(s: PChar): PChar cdecl;
  1652.  
  1653. {
  1654.   util_mime_separator generates a new MIME separator into the given buffer.
  1655.   The buffer should be more than 4 + 3*10 + 1 bytes long. A CRLF is prepended
  1656.   to the beginning of the string, along with two dashes. The string is null
  1657.   terminated, with no CRLF. The intent is that you create your content-type
  1658.   header by accessing &sep[4], and afterwards print sep followed by CRLF
  1659.   for message boundaries.
  1660.  
  1661.   Returns the length of the string.
  1662. }
  1663. function util_mime_separator(sep: PChar): Integer;
  1664.  
  1665. {
  1666.   util_itoa converts the given integer to a string into a.
  1667. }
  1668. function util_itoa(i: Integer; a: PChar): Integer;
  1669.  
  1670. {
  1671.   util_vsprintf and util_sprintf are simplified clones of the System V
  1672.   vsprintf and sprintf routines.
  1673.  
  1674.   Returns the number of characters printed. Only handles %d and %s,
  1675.   does not handle any width or precision.
  1676. }
  1677. {!!! requires vararg support !!!
  1678. #include <stdarg.h>
  1679.  
  1680. NSAPI_PUBLIC int util_vsprintf(char *s, register char *fmt, va_list args);
  1681. NSAPI_PUBLIC int util_sprintf(char *s, char *fmt, ...);
  1682.  
  1683. /* These routines perform bounds checks. */
  1684. NSAPI_PUBLIC int util_vsnprintf(char *s, int n, register char *fmt,
  1685.                                 va_list args);
  1686. NSAPI_PUBLIC int util_snprintf(char *s, int n, char *fmt, ...);
  1687. }
  1688.  
  1689. { util_delete_directory()
  1690.   This routine deletes all the files in a directory.  If delete_directory is
  1691.   TRUE it will also delete the directory itself.
  1692. }
  1693. procedure util_delete_directory(FileName: PChar; delete_directory: BOOL); cdecl;
  1694.  
  1695. { util_strftime()
  1696.   Thread safe version of strftime.
  1697.   No bounds checking is done s.  t must be a valid tm structure.
  1698. }
  1699. function util_strftime(s: PChar; format: PChar; var t: tm): Integer; cdecl;
  1700.  
  1701. {*****************************************************************************}
  1702. {* From object.h                                                              }
  1703. {*****************************************************************************}
  1704. {
  1705.   Handle httpd objects
  1706.  
  1707.   Manages information about a document from config. files. Called mainly
  1708.   by objset.c.
  1709.  
  1710.   This module does not assume anything about the directives being parsed.
  1711.   That is handled by objset.c.
  1712.  
  1713.   This module requires the pblock module from the base library.
  1714. }
  1715.  
  1716. {* ------------------------------ Structures ------------------------------ *}
  1717.  
  1718. {
  1719.   Hierarchy of httpd_object
  1720.  
  1721.   An object contains dtables.
  1722.  
  1723.   Each dtable is a table of directives that were entered of a certain type.
  1724.   There is one dtable for each unique type of directive.
  1725.  
  1726.   Each dtable contains an array of directives, each of which is equivalent
  1727.   to one directive that occurred in a config. file.
  1728.  
  1729.   It is up to the caller to determine how many dtables will be allocated
  1730.   and to keep track of which of their directive types maps to which dtable
  1731.   number.
  1732. }
  1733.  
  1734. type
  1735. {
  1736.   directive is a structure containing the protection and parameters to an
  1737.   instance of a directive within an httpd_object.
  1738.  
  1739.   param is the parameters, client is the protection.
  1740. }
  1741.   PDirective = ^TDirective;
  1742.   TDirective = record
  1743.     param: PPblock;
  1744.     client: PPblock;
  1745.   end;
  1746.   directive = TDirective;
  1747.  
  1748. {
  1749.   dtable is a structure for creating tables of directives
  1750. }
  1751.   PDtable = ^TDtable;
  1752.   TDtable = record
  1753.     ni: Integer;
  1754.     inst: PDirective;
  1755.   end;
  1756.   dtable = TDtable;
  1757.  
  1758. {
  1759.   The httpd_object structure.
  1760.  
  1761.   The name pblock array contains the names for this object, such as its
  1762.   virtual location, its physical location, or its identifier.
  1763.  
  1764.   tmpl contains any templates allocated to this object.
  1765. }
  1766.   PHttpdObject = ^THttpdObject;
  1767.   THttpdObject = record
  1768.     name: PPblock;
  1769.     nd: Integer;
  1770.     dt: PDtable;
  1771.   end;
  1772.   httpd_object = THttpdObject;
  1773.  
  1774. {* ------------------------------ Prototypes ------------------------------ *}
  1775.  
  1776. {
  1777.   object_create will create a new object and return a pointer to it.
  1778.   It will allocate space for nd directive types and set name accordingly.
  1779. }
  1780. function object_create(nd: Integer; name: PPblock): PHttpdObject; cdecl;
  1781.  
  1782. {
  1783.   object_free will free an object and any data associated with it.
  1784. }
  1785. procedure object_free(obj: PHttpdObject); cdecl;
  1786.  
  1787. {
  1788.   object_add_directive will add a new directive to the dtable for
  1789.   the directive class at position dc.
  1790. }
  1791. procedure object_add_directive(dc: Integer; p: PPblock; c: PPblock;
  1792.   obj: PHttpdObject); cdecl;
  1793.  
  1794. {
  1795.   Executes the directive specified by inst within the context of the
  1796.   given session and request structures. Returns what the executed function
  1797.   returned (one of the REQ_* codes defined in req.h).
  1798.  
  1799.   This prototype uses void * for Request * in order to avoid including
  1800.   all of req.h.
  1801. }
  1802. function object_execute(inst: PDirective; sn: PSession; rq: Pointer): Integer; cdecl;
  1803.  
  1804. {*****************************************************************************}
  1805. {* From objset.h                                                              }
  1806. {*****************************************************************************}
  1807. {
  1808.   Handles object sets
  1809.  
  1810.   Each object is produced by reading a config file of some form. See the
  1811.   server documentation for descriptions of the directives that are
  1812.   recognized, what they do, and how they are parsed.
  1813.  
  1814.   This module requires the pblock and buffer modules from the base library.
  1815. }
  1816.  
  1817. {* ------------------------------ Constants ------------------------------- *}
  1818.  
  1819. const
  1820. {
  1821.   The default number of objects to leave room for in an object set,
  1822.   and the number of new entries by which to increase the size when that
  1823.   room is filled.
  1824. }
  1825.   OBJSET_INCSIZE = 8;
  1826.  
  1827. {
  1828.   When parsing config. files, httpd will put a limit on how long
  1829.   the parameters to a directive can be (in characters).
  1830.  
  1831.   Currently set to 10 lines (80 chars/line).
  1832. }
  1833.   MAX_DIRECTIVE_LEN = 800;
  1834.  
  1835. {
  1836.   The size of the hash tables that store a directive's parameters
  1837. }
  1838.   PARAMETER_HASH_SIZE = 3;
  1839.  
  1840. {* ------------------------------ Structures ------------------------------ *}
  1841.  
  1842. {
  1843.   httpd_objset is a container for a bunch of objects. obj is a
  1844.   NULL-terminated array of objects. pos points to the entry after the last
  1845.   one in the array. You should not mess with pos, but can read it to find
  1846.   the last entry.
  1847.  
  1848.   The initfns array is a NULL-terminated array of the Init functions
  1849.   associated with this object set. If there are no Init functions associated
  1850.   with this object set, initfns can be NULL. Each pblock specifies the
  1851.   parameters which are passed to the function when it's executed.
  1852. }
  1853.  
  1854. type
  1855.   PHttpdObjSet = ^THttpdObjSet;
  1856.   THttpdObjSet = record
  1857.     pos: Integer;
  1858.     obj: ^PHttpdObject;
  1859.     initfns: ^PPblock;
  1860.   end;
  1861.   httpd_objset = THttpdObjSet;
  1862.  
  1863. {* ------------------------------ Prototypes ------------------------------ *}
  1864.  
  1865.  
  1866. {
  1867.   objset_scan_buffer will scan through buffer, looking for object
  1868.   configuration information, and adding them to the object set os if it
  1869.   finds any. If os is NULL it will allocate a new object set.
  1870.  
  1871.   If any error occurs (syntax error, premature EOF) this function will
  1872.   free os, print an error message into errstr, and return NULL.
  1873.   This is because a config. file error is viewed as a catastrophic error
  1874.   from which httpd should not try to recover. If httpd were to continue
  1875.   after an error, it would not behave as the admin. expected and he/she
  1876.   may not notice until it's too late.
  1877.  
  1878.   Upon EOF the file will not be closed.
  1879. }
  1880. function objset_scan_buffer(buf: PFileBuffer; errstr: PChar;
  1881.   os: PHttpdObjSet): PHttpdObjSet; cdecl;
  1882.  
  1883. {
  1884.   objset_create creates a new object set and returns a pointer to it.
  1885. }
  1886. function objset_create: PHttpdObjSet; cdecl;
  1887.  
  1888. {
  1889.   objset_free will free an object set, any associated objects, and any
  1890.   associated Init functions.
  1891. }
  1892. procedure objset_free(os: PHttpdObjSet); cdecl;
  1893.  
  1894. {
  1895.   objset_free_setonly frees only the object set, and not the associated
  1896.   objects or init functions.
  1897. }
  1898. procedure objset_free_setonly(os: PHttpdObjSet); cdecl;
  1899.  
  1900. {
  1901.   objset_new_object will add a new object to objset with the specified
  1902.   name. It returns a pointer to the new object (which may be anywhere in
  1903.   the objset).
  1904. }
  1905. function objset_new_object(name: PPblock; os: PHttpdObjSet): PHttpdObjSet; cdecl;
  1906.  
  1907. {
  1908.   objset_add_object will add the existing object to os.
  1909. }
  1910. procedure objset_add_object(obj: PHttpdObject; os: PHttpdObjSet); cdecl;
  1911.  
  1912. {
  1913.   objset_add_init will add the initialization function specified by
  1914.   initfn to the given object set. Modifies os->initfns.
  1915. }
  1916. procedure objset_add_init(initfn: PPblock; os: PHttpdObjSet); cdecl;
  1917.  
  1918. {
  1919.   objset_findbyname will find the object in objset having the given name,
  1920.   and return the object if found, and NULL otherwise.
  1921.   ign is a set of objects to ignore.
  1922. }
  1923. function objset_findbyname(name: PChar; ign, os: PHttpdObjSet): PHttpdObject; cdecl;
  1924.  
  1925. {
  1926.   objset_findbyppath will find the object in objset having the given
  1927.   partial path entry. Returns object if found, NULL otherwise.
  1928.   ign is a set of objects to ignore.
  1929. }
  1930. function objset_findbyppath(ppath: Pchar; ign, os: PHttpdObjSet): PHttpdObject; cdecl;
  1931.  
  1932. {
  1933.   objset_copydirs takes a given objset and copies all of the
  1934.   directive in directive set <dir> into a new objset, dst_os.  If
  1935.   dst_os is NULL, it creates a new objset.
  1936.   The newly created objset only has one object in it.
  1937. }
  1938. function objset_copydirs(dst_os, os: PHttpdObjSet; dir: Integer): PHttpdObjSet; cdecl;
  1939.  
  1940. {* Read the registry configuration parameters into memory *}
  1941. function objset_scan_registry(errstr: PChar; os: PHttpdObjSet;
  1942.   product_key: PChar): PHttpdObjSet; cdecl;
  1943.  
  1944. {* Recursively scan the object key *}
  1945.  
  1946. procedure ProcessObject(nos: PHttpdObjSet; hObjectKey: HKEY; Obj: PChar;
  1947.   ObjectIndex: DWORD); cdecl;
  1948.  
  1949. {* Recursively scan the client key *}
  1950.  
  1951. function ProcessClient(cobj: PHttpdObject; hObjectKey: HKEY; Client: PChar;
  1952.   ObjectIndex: DWORD): BOOL; cdecl;
  1953.  
  1954. {* Recursively scan the directive key *}
  1955.  
  1956. function ProcessDirective(cobj: PHttpdObject; param, client: PPblock;
  1957.   hObjectKey: HKEY; Directive: PChar; ObjectIndex, DirectiveIndex: DWORD;
  1958.   var clrefs: DWORD; IsObject: BOOL): BOOL; cdecl;
  1959.  
  1960. {* Recursively scan the function key *}
  1961.  
  1962. function ProcessFunction(var param: PPblock; hDirectiveKey: HKEY; Func: PChar;
  1963.   ObjectIndex, DirectiveIndex, FunctionIndex: DWORD): BOOL; cdecl;
  1964.  
  1965. {* Verify the name value pair *}
  1966.  
  1967. function _ntverify_parameter(str: PChar): Integer; cdecl;
  1968.  
  1969. {* Enter name value pair into pblock *}
  1970. function ntpblock_str2pblock(ParameterIndex: Integer; name, value: PChar;
  1971.   namelength, valuelength: Integer; pb: PPblock): Integer; cdecl;
  1972.  
  1973. {* Get name value pair from a pblock entry *}
  1974. function ntpblock_pblock2str(p: PPbEntry; var ParameterName,
  1975.     ParameterValue: PChar): Integer; cdecl;
  1976.  
  1977. {* Given a key and its parent, delete the key recursively *}
  1978. function ClearConfigurationParameters(hParentKey: HKEY; CompleteKeyName,
  1979.   KeyName: PChar): BOOL; cdecl;
  1980.  
  1981. { Look at the hidden file in the server's directory structure to
  1982.   figure out the name of this server }
  1983. function GetProductKey: PChar; cdecl;
  1984.  
  1985. {*****************************************************************************}
  1986. {* From conf.h                                                                }
  1987. {*****************************************************************************}
  1988. {
  1989.   conf.h: Deals with the server configuration file.
  1990.  
  1991.   Object configuration is an entirely different matter. This deals with
  1992.   things like what port the server runs on, how many children it spawns,
  1993.   and other server-related issues. Information related configuration is
  1994.   handled by the object conf.
  1995. }
  1996.  
  1997. {* ------------------------------ Constants ------------------------------- *}
  1998.  
  1999. const
  2000. {* The longest line in the configuration file *}
  2001.   CONF_MAXLEN = 16384;
  2002.   DEFAULT_PORT = 80;
  2003.   DEFAULT_POOL_MAX = 50;
  2004.  
  2005. {* ------------------------------- Globals -------------------------------- *}
  2006.  
  2007. {
  2008.   These server parameters are made global because they really don't
  2009.   belong anywhere else.
  2010. }
  2011.  
  2012. {* These can't be macros because they're used in daemon.h. */
  2013. extern char *pidfn;
  2014. extern int port;
  2015. extern char *chr;
  2016.  
  2017. #ifdef NET_SSL
  2018. extern char *secure_keyfn;
  2019. extern char *secure_certfn;
  2020. extern int secure_auth;
  2021. #endif}
  2022.  
  2023. type
  2024.   PConfGlobalVars = ^TConfGlobalVars;
  2025.   TConfGlobalVars = record
  2026.     {* What port we listen to *}
  2027.     Vport: Integer;
  2028.     {* What address to bind to *}
  2029.     Vaddr: PChar;
  2030.     {* User to run as *}
  2031.     Vuserpw: PPASSWD;
  2032.     {* Directory to chroot to *}
  2033.     Vchr: PChar;
  2034.     {* Where to log our pid to *}
  2035.     Vpidfn: PChar;
  2036.     {* The maximum number of processes to keep in the pool *}
  2037.     Vpool_max: Integer;
  2038.     {* The minimum number of processes to keep in the pool *}
  2039.     Vpool_min: Integer;
  2040.     {* The maximum number of requests each process should handle. -1=default *}
  2041.     Vpool_life: Integer;
  2042.     {* For multiprocess UNIX servers, the maximum threads per process *}
  2043.     Vpool_maxthreads: Integer;
  2044.     {* For multiprocess UNIX servers, the minimum threads per process *}
  2045.     Vpool_minthreads: Integer;
  2046. {$ifdef NET_SSL}
  2047.     Vsecure_keyfn: PChar;
  2048.     Vsecure_certfn: PChar;
  2049.     Vsecurity_active: Integer;
  2050.     Vssl3_active: Integer;
  2051.     Vssl2_active: Integer;
  2052.     Vsecure_auth: Integer;
  2053.     Vsecurity_session_timeout: Integer;
  2054.     Vssl3_session_timeout: Longint;
  2055. {$endif} {* NET_SSL *}
  2056.     {* The server's hostname as should be reported in self-ref URLs *}
  2057.     Vserver_hostname: PChar;
  2058.     {* The main object from which all are derived *}
  2059.     Vroot_object: PChar;
  2060.     {* The object set the administrator has asked us to load *}
  2061.     Vstd_os: PHttpdObjSet;
  2062.     {* The root of ACL data structures *}
  2063.     Vacl_root: Pointer;
  2064.     {* The main error log, where all errors are logged *}
  2065.     Vmaster_error_log: PChar;
  2066.     {* The server root ( in which the server sits while executing ) *}
  2067.     Vserver_root: PChar;
  2068.     {* This server's id *}
  2069.     Vserver_id: PChar;
  2070.   end;
  2071.   conf_global_vars_s = TConfGlobalVars;
  2072.  
  2073. function userpw: PPASSWD;
  2074. function pool_max: Integer;
  2075. function pool_min: Integer;
  2076. function pool_life: Integer;
  2077. function pool_maxthreads: Integer;
  2078. function pool_minthreads: Integer;
  2079. function server_hostname: PChar;
  2080. function root_object: PChar;
  2081. function std_os: PHttpdObjSet;
  2082. function acl_root: Pointer;
  2083. function master_error_log: PChar;
  2084. function server_root: PChar;
  2085. function server_id: PChar;
  2086.  
  2087. {* ------------------------------ Prototypes ------------------------------ *}
  2088.  
  2089. {
  2090.   conf_init reads the given configuration file and sets any non-default
  2091.   parameters to their given setting.
  2092. }
  2093. function conf_init(cfn: PChar): PChar; cdecl;
  2094.  
  2095. {
  2096.   conf_terminate frees any data the conf routines may be holding.
  2097. }
  2098. procedure conf_terminate; cdecl;
  2099.  
  2100. {
  2101.   Get a structure with the global variables for this server.
  2102. }
  2103. function conf_getglobals: PConfGlobalVars; cdecl;
  2104.  
  2105. {
  2106.   conf_vars2daemon transfers these globals to a daemon structure
  2107. }
  2108. procedure conf_vars2daemon(d: PDaemon); cdecl;
  2109.  
  2110. function GetDomainAddresses(ErrMsg: PChar): BOOL; cdecl;
  2111.  
  2112. {*****************************************************************************}
  2113. {* From req.h                                                                 }
  2114. {*****************************************************************************}
  2115. {
  2116.   Request-specific data structures and functions
  2117. }
  2118.  
  2119. {* ------------------------------ Constants ------------------------------- *}
  2120.  
  2121. const
  2122.   REQ_HASHSIZE = 10;
  2123.   REQ_MAX_LINE = 4096;
  2124.  
  2125. {
  2126.   The REQ_ return codes. These codes are used to determine what the server
  2127.   should do after a particular module completes its task.
  2128.  
  2129.   Func type functions return these as do many internal functions.
  2130. }
  2131.  
  2132. {* The function performed its task, proceed with the request *}
  2133.   REQ_PROCEED = 0;
  2134. {* The entire request should be aborted: An error occurred *}
  2135.   REQ_ABORTED = -1;
  2136. {* The function performed no task, but proceed anyway. *}
  2137.   REQ_NOACTION = -2;
  2138. {* Tear down the session and exit *}
  2139.   REQ_EXIT = -3;
  2140. {* Restart the entire request-response process *}
  2141.   REQ_RESTART = -4;
  2142.  
  2143.  
  2144. {* ------------------------------ Structures ------------------------------ *}
  2145.  
  2146.  
  2147. type
  2148.   PRequest = ^TRequest;
  2149.   TRequest = record
  2150.     {* Server working variables *}
  2151.     vars: PPblock;
  2152.     {* The method, URI, and protocol revision of this request *}
  2153.     reqpb: PPblock;
  2154.     {* Protocol specific headers *}
  2155.     loadhdrs: Integer;
  2156.     headers: PPblock;
  2157.     {* Server's response headers *}
  2158.     senthdrs: Integer;
  2159.     srvhdrs: PPblock;
  2160.     {* The object set constructed to fulfill this request *}
  2161.     os: PHttpdObjSet;
  2162.     {* Array of objects that were created from .nsconfig files *}
  2163.     tmpos: PHttpdObjSet;
  2164.     {* The stat last returned by request_stat_path *}
  2165.     statpath: PChar;
  2166.     staterr: PChar;
  2167.     finfo: PStat;
  2168.     {* access control state *}
  2169.     aclstate: Integer;    {* ACL decision state *}
  2170.     acldirno: Integer;    {* deciding ACL directive number *}
  2171.     aclname: PChar;        {* name of deciding ACL *}
  2172.     aclpb: PPblock;     {* parameter block for ACL PathCheck *}
  2173.     request_is_cacheable: BOOL;   {* default TRUE *}
  2174.     directive_is_cacheable: BOOL; {* default FALSE *}
  2175.  
  2176.     cached_headers: PChar;
  2177.     cached_headers_len: Integer;  {* length of the valid headers *}
  2178.     cached_date_header: PChar;
  2179.   end;
  2180.   Request = TRequest;
  2181.  
  2182. {* ------------------------------ Prototypes ------------------------------ *}
  2183.  
  2184. {
  2185.   request_create creates a new request structure.
  2186. }
  2187. function request_create: PRequest; cdecl;
  2188.  
  2189. {
  2190.   request_free destroys a request structure.
  2191. }
  2192. procedure request_free(req: PRequest); cdecl;
  2193.  
  2194. {
  2195.   Restarts a request for a given URI internally. If rq is non-NULL, the
  2196.   function will keep the old request's headers and protocol, but with a new
  2197.   URI and method of GET. If the previous method was HEAD, this is preserved.
  2198.   Any other method becomes GET. You may assume that if you give it a request
  2199.   structure that it will use the same structure.
  2200.  
  2201.   Once you have this new Request, you must then do what you want with
  2202.   it (e.g. send the object back, perform uri2path translation, etc.)
  2203. }
  2204. function request_restart_internal(uri: PChar; rq: PRequest): PRequest; cdecl;
  2205.  
  2206. {
  2207.   request_header finds the named header depending on the requesting
  2208.   protocol. If possible, it will not load headers until the first is
  2209.   requested. You have to watch out because this can return REQ_ABORTED.
  2210. }
  2211. function request_header(name: PChar; value: PPCharArray; sn: PSession;
  2212.   rq: PRequest): Integer; cdecl;
  2213.  
  2214. {
  2215.   request_loadheaders just makes sure the headers have been loaded.
  2216. }
  2217. function request_loadheaders(sn: PSession; rq: PRequest): Integer;
  2218.  
  2219. {
  2220.   request_stat_path tries to stat path. If path is NULL, it will look in
  2221.   the vars pblock for "path". If the stat is successful, it returns the stat
  2222.   structure. If not, returns NULL and leaves a message in rq->staterr. If a
  2223.   previous call to this function was successful, and path is the same, the
  2224.   function will simply return the previously found value.
  2225.  
  2226.   User functions should not free this structure.
  2227. }
  2228. function request_stat_path(path: PChar; rq: PRequest): PStat; cdecl;
  2229.  
  2230. {
  2231.   request_handle handles one request from the session's inbuf.
  2232. }
  2233. procedure request_handle(sn: PSession); cdecl;
  2234.  
  2235. {
  2236.   request_translate_uri performs virtual to physical mapping on
  2237.   a specified URI during a specified session.
  2238. }
  2239. function request_translate_uri(uri: PChar; sn: PSession): PChar; cdecl;
  2240.  
  2241.  
  2242. (* XXXrobm temporary compatibility */
  2243. #define request_uri2path servact_uri2path
  2244. #define request_pathchecks servact_pathchecks
  2245. #define request_fileinfo servact_fileinfo
  2246. #define request_service servact_service
  2247.  
  2248. #define request_handle_processed servact_handle_processed
  2249. #define request_translate_uri servact_translate_uri
  2250. #define request_finderror servact_finderror *)
  2251.  
  2252. {*****************************************************************************}
  2253. {* From http.h                                                                }
  2254. {*****************************************************************************}
  2255. {
  2256.   Deals with HTTP-related issues
  2257. }
  2258.  
  2259. {* ------------------------------ Constants ------------------------------- *}
  2260.  
  2261. const
  2262.   HTTP_DATE_LEN = 128;
  2263.   HTTP_DATE_FMT = '%A, %d-%b-%y %H:%M:%S GMT';
  2264.  
  2265. { Number of seconds to allow a second request to come over a persistent
  2266.   connection, zero to disable *}
  2267.   HTTP_DEFAULT_KEEPALIVE_TIMEOUT = 15;
  2268.  
  2269. {* The maximum number of RFC-822 headers we'll allow *}
  2270. {* This would be smaller if a certain browser wasn't so damn stupid. *}
  2271.   HTTP_MAX_HEADERS = 200;
  2272.  
  2273. {* HTTP status codes *}
  2274.   PROTOCOL_OK = 200;
  2275.   PROTOCOL_CREATED = 201;
  2276.   PROTOCOL_NO_RESPONSE = 204;
  2277.   PROTOCOL_PARTIAL_CONTENT = 206;
  2278.   PROTOCOL_REDIRECT = 302;
  2279.   PROTOCOL_NOT_MODIFIED = 304;
  2280.   PROTOCOL_BAD_REQUEST = 400;
  2281.   PROTOCOL_UNAUTHORIZED = 401;
  2282.   PROTOCOL_FORBIDDEN = 403;
  2283.   PROTOCOL_NOT_FOUND = 404;
  2284.   PROTOCOL_PROXY_UNAUTHORIZED = 407;
  2285.   PROTOCOL_SERVER_ERROR = 500;
  2286.   PROTOCOL_NOT_IMPLEMENTED = 501;
  2287.  
  2288. {$ifdef NET_SSL}
  2289.   HTTPS_PORT = 443;
  2290.   HTTPS_URL = 'https';
  2291. {$endif}
  2292.   HTTP_PORT = 80;
  2293.   HTTP_URL = 'http';
  2294.  
  2295. {* -------------------------- http_scan_headers --------------------------- *}
  2296.  
  2297. {
  2298.   gets the first line of an HTTP request
  2299. }
  2300. function protocol_find_request(buf: PNetBuf; sn: PSession; var reply: Integer): PRequest; cdecl;
  2301. function http_find_request(buf: PNetBuf; sn: PSession; var reply: Integer): PRequest; cdecl;
  2302.  
  2303. {
  2304.   parses the first line of an HTTP request
  2305. }
  2306. function protocol_parse_request(t: PChar; rq: PRequest; sn: PSession): Integer; cdecl;
  2307. function http_parse_request(t: PChar; rq: PRequest; sn: PSession): Integer; cdecl;
  2308.  
  2309. {
  2310.   Scans HTTP headers from the given netbuf, and places them in headers.
  2311.   If netbuf is NULL, the session's inbuf is used.
  2312.  
  2313.   Folded lines are joined and the linefeed removed (but not the whitespace).
  2314.   If there are any repeat headers they are joined and the two field bodies
  2315.   separated by a comma and space.
  2316.  
  2317.   t should be a string of length REQ_MAX_LINE. This is a convenience to
  2318.   req.c so that we don't use too much runtime stack.
  2319.  
  2320.   Session is an optional parameter. Use NULL if you wish. It's used for
  2321.   error logs.
  2322. }
  2323. function protocol_scan_headers(sn: PSession; buf: PNetBuf; t: PChar;
  2324.   headers: PPblock): Integer; cdecl;
  2325. function http_scan_headers(sn: PSession; buf: PNetBuf; t: PChar;
  2326.   headers: PPblock): Integer; cdecl;
  2327.  
  2328. {
  2329.   Starts the HTTP response. If HTTP/0.9, does nothing. If 1.0, sends header.
  2330.   If this returns REQ_NOACTION, the method was head and no body should be
  2331.   sent. Otherwise, it will return REQ_PROCEED.
  2332. }
  2333. function protocol_start_response(sn: PSession; rq: PRequest): Integer; cdecl;
  2334. function http_start_response(sn: PSession; rq: PRequest): Integer; cdecl;
  2335.  
  2336. {
  2337.   http_hdrs2env takes the entries from the given pblock and converts them
  2338.   to an environment.
  2339.  
  2340.   Each name entry will be made uppercase, prefixed with HTTP_ and any
  2341.   occurrence of - will be converted to _.
  2342. }
  2343. function http_hdrs2env(pb: PPblock): PPCharArray; cdecl;
  2344.  
  2345. {
  2346.   http_status sets status to the code n, with reason string r. If r is
  2347.   NULL, the server will attempt to find one for the given status code.
  2348.   If it finds none, it will give "Because I felt like it."
  2349. }
  2350. procedure protocol_status(sn: PSession; rq: PRequest; n: Integer; r: PChar); cdecl;
  2351. procedure http_status(sn: PSession; rq: PRequest; n: Integer; r: PChar); cdecl;
  2352.  
  2353. {
  2354.   http_set_finfo sets content-length and last-modified
  2355. }
  2356. function protocol_set_finfo(sn: PSession; rq: PRequest; var finfo: TStat): Integer; cdecl;
  2357. function http_set_finfo(sn: PSession; rq: PRequest; var finfo: TStat): Integer; cdecl;
  2358.  
  2359. {
  2360.   Takes the given pblock and prints headers into the given buffer at
  2361.   position pos. Returns the buffer, reallocated if needed. Modifies pos.
  2362. }
  2363. function http_dump822(pb: PPblock; t: PChar; var pos: Integer; tsz: Integer): Pchar; cdecl;
  2364.  
  2365. {
  2366.   Finishes a request. For HTTP, this just closes the socket.
  2367. }
  2368. procedure protocol_finish_request(sn: PSession; rq: PRequest); cdecl;
  2369. procedure http_finish_request(sn: PSession; rq: PRequest); cdecl;
  2370.  
  2371. {
  2372.   http_handle_session processes each request generated by Session
  2373. }
  2374. procedure protocol_handle_session(sn: PSession); cdecl;
  2375. procedure http_handle_session(sn: PSession); cdecl;
  2376.  
  2377. {
  2378.   http_uri2url takes the give URI prefix and URI suffix and creates a
  2379.   newly-allocated full URL from them of the form
  2380.   http://(server):(port)(prefix)(suffix)
  2381.  
  2382.   If you want either prefix or suffix to be skipped, use "" instead of NULL.
  2383.  
  2384.   Normally, the server hostname is taken from the ServerName parameter in
  2385.   magnus.conf. The newer function http_uri2url_dynamic should be used when
  2386.   a Session and Request structure are available, to ensure that the browser
  2387.   gets redirected to the exact host they were originally referencing.
  2388. }
  2389. function protocol_uri2url(prefix, suffix: PChar): PChar; cdecl;
  2390. function protocol_uri2url_dynamic(prefix, suffix: PChar; sn: PSession;
  2391.   rq: PRequest): PChar; cdecl;
  2392. function http_uri2url(prefix, suffix: PChar): PChar; cdecl;
  2393. function http_uri2url_dynamic(prefix, suffix: PChar; sn: PSession;
  2394.   rq: PRequest): PChar; cdecl;
  2395.  
  2396. {
  2397.   http_set_keepalive_timeout sets the number of seconds to wait for a new
  2398.   request to come from a persistent connection. Returns nothing. Intended
  2399.   to be called at server startup only.
  2400.  
  2401.   Specifying a timeout of zero will disable persistent connections and allow
  2402.   browsers to request only one file per connection.
  2403. }
  2404. procedure protocol_set_keepalive_timeout(secs: Integer); cdecl;
  2405. procedure http_set_keepalive_timeout(secs: Integer); cdecl;
  2406.  
  2407. {*****************************************************************************}
  2408. {* From func.h                                                                }
  2409. {*****************************************************************************}
  2410. {
  2411.   func.h: Handles the function hash table
  2412.  
  2413.   httpd uses a table of internal functions hashed by a name string such that
  2414.   users can reference specific functions from the configuration files.
  2415.  
  2416.   Any function referenced by configuration files will be passed a
  2417.   parameter, a Request structure. The functions do not return anything.
  2418. }
  2419.  
  2420. {* -------------------------- Structure and Type -------------------------- *}
  2421.  
  2422.  
  2423. {
  2424.   FuncPtr is a pointer to our kind of functions
  2425. }
  2426.  
  2427. type
  2428.   TFunction = function (pb: PPblock; sn: PSession; rq: PRequest): Integer cdecl;
  2429.  
  2430. {
  2431.   FuncStruct is a structure used in the static declaration of the
  2432.   functions. This static declaration is parsed into a hash table at
  2433.   startup. You should initialize the next entry to NULL.
  2434. }
  2435.  
  2436.   PFuncStruct = ^TFuncStruct;
  2437.   TFuncStruct = record
  2438.     name: PChar;
  2439.     func: TFunction;
  2440.     next: PFuncStruct;
  2441.   end;
  2442.  
  2443. {* --------------------------- Hash definitions --------------------------- *}
  2444.  
  2445. {
  2446.   This is a primitive hash function. Once more is known about the names of
  2447.   the functions, this will be optimized.
  2448. }
  2449. const
  2450.   NUM_HASH = 20;
  2451.  
  2452. // #define FUNC_HASH(s) (s[0] % NUM_HASH)
  2453.  
  2454. {* ------------------------------ Prototypes ------------------------------ *}
  2455.  
  2456. {
  2457.   func_init reads the static FuncStruct arrays and creates the global
  2458.   function table from them.
  2459.  
  2460.   func_init will only read from the static arrays defined in func.c.
  2461. }
  2462. procedure func_init; cdecl;
  2463.  
  2464. {
  2465.   func_find returns a pointer to the function named name, or NULL if none
  2466.   exists.
  2467. }
  2468. function func_find(name: PChar): TFunction; cdecl;
  2469.  
  2470. {
  2471.   func_exec will try to execute the function whose name is the "fn" entry
  2472.   in the given pblock. If name is not found, it will log a misconfig of
  2473.   missing fn parameter. If it can't find it, it will log that. In these
  2474.   cases it will return REQ_ABORTED. Otherwise, it will return what the
  2475.   function being executed returns.
  2476. }
  2477. function func_exec(pb: PPblock; sn: PSession; rq: PRequest): Integer; cdecl;
  2478.  
  2479. {
  2480.   func_insert dynamically inserts a named function into the server's
  2481.   table of functions. Returns the FuncStruct it keeps in internal
  2482.   databases, because on server restart you are responsible for freeing
  2483.   (or not) its contents.
  2484. }
  2485. function func_insert(name: PChar; fn: TFunction): PFuncStruct;
  2486.  
  2487. function NSstr2String(nsStr: PChar): string;
  2488.  
  2489. implementation
  2490.  
  2491. uses SysUtils;
  2492.  
  2493. const
  2494.   nshttp = 'ns-httpd20.dll';
  2495.  
  2496. function server_fasttrack: Boolean;
  2497. begin
  2498.   Result := StrComp(MAGNUS_VERSION_STRING, PERSONAL_VERSION_STRING) = 0;
  2499. end;
  2500.  
  2501. function server_enterprise: Boolean;
  2502. begin
  2503.   Result := StrComp(MAGNUS_VERSION_STRING, ENTERPRISE_VERSION_STRING) = 0;
  2504. end;
  2505.  
  2506. procedure CONVERT_TO_PRINTABLE_FORMAT(Filename: PChar);
  2507. var
  2508.   S: PChar;
  2509. begin
  2510.   if Filename = nil then
  2511.   begin
  2512.     S := FileName;
  2513.     while S^ <> #0 do
  2514.     begin
  2515.       if S^ = '\' then
  2516.         S^ := '/';
  2517.       Inc(S);
  2518.     end;
  2519.   end;
  2520. end;
  2521.  
  2522. procedure CONVERT_TO_NATIVE_FS(Filename: PChar);
  2523. var
  2524.   S: PChar;
  2525. begin
  2526.   if Filename = nil then
  2527.   begin
  2528.     S := FileName;
  2529.     while S^ <> #0 do
  2530.     begin
  2531.       if S^ = '/' then
  2532.         S^ := '\';
  2533.       Inc(S);
  2534.     end;
  2535.   end;
  2536. end;
  2537.  
  2538. function system_rename(old, new: PChar): BOOL;
  2539. begin
  2540.   Result := MoveFile(old, new);
  2541. end;
  2542.  
  2543. function system_unlink(path: PChar): BOOL;
  2544. begin
  2545.   Result := DeleteFile(path);
  2546. end;
  2547.  
  2548. function system_lseek(fd: SYS_FILE; off: Longint; wh: Longint): Longint;
  2549. begin
  2550.   Result := SetFilePointer(fd.fh, Off, nil, wh);
  2551. end;
  2552.  
  2553. function system_flock(fd: SYS_FILE): Integer;
  2554. begin
  2555.   Result := sem_grab(fd.flsem);
  2556. end;
  2557.  
  2558. function system_ulock(fd: SYS_FILE): Integer;
  2559. begin
  2560.   Result := sem_release(fd.flsem);
  2561. end;
  2562.  
  2563. function dir_create(Path: PChar): Integer;
  2564. begin
  2565.   if CreateDirectory(Path, nil) then
  2566.     Result := 0
  2567.   else Result := -1;
  2568. end;
  2569.  
  2570. function dir_remove(Path: PChar): Integer;
  2571. begin
  2572.   if RemoveDirectory(Path) then
  2573.     Result := 0
  2574.   else Result := -1;
  2575. end;
  2576.  
  2577. function pblock_find(name: PChar; pb: PPblock): PPbParam;
  2578. begin
  2579.   Result := _pblock_fr(name,pb,False);
  2580. end;
  2581.  
  2582. function pblock_remove(name: PChar; pb: PPblock): PPbParam;
  2583. begin
  2584.   Result := _pblock_fr(name,pb,True);
  2585. end;
  2586.  
  2587. function netbuf_getc(b: PNetBuf): Integer;
  2588. begin
  2589.   with b^ do
  2590.     if pos <> cursize then
  2591.     begin
  2592.       Result := Integer(Byte(inbuf[pos]));
  2593.       Inc(pos);
  2594.     end else Result := netbuf_next(b, 1);
  2595. end;
  2596.  
  2597. function filebuf_getc(b: PFileBuffer): Integer;
  2598. begin
  2599.   with b^ do
  2600.     if pos = len then
  2601.       Result := IO_EOF
  2602.     else
  2603.     begin
  2604.       Result := Integer(Byte(fp[pos]));
  2605.       Inc(pos);
  2606.     end;
  2607. end;
  2608.  
  2609. function pipebuf_getc(b: PFileBuffer): Integer;
  2610. begin
  2611.   with b^ do
  2612.     if pos <> cursize then
  2613.     begin
  2614.       Result := Integer(Byte(inbuf[pos]));
  2615.       Inc(pos);
  2616.     end else Result := pipebuf_next(b, 1);
  2617. end;
  2618.  
  2619. function session_dns(sn: PSession): PChar;
  2620. begin
  2621.   Result := session_dns_lookup(sn, False);
  2622. end;
  2623.  
  2624. function session_maxdns(sn: PSession): PChar;
  2625. begin
  2626.   Result := session_dns_lookup(sn, True);
  2627. end;
  2628.  
  2629. function CINFO_HASH(s: PChar): Char;
  2630. begin
  2631.   if IsCharAlpha(s[0]) then
  2632.     Result := Char(Byte(CharLower(PChar(s[0]))) - Ord('a'))
  2633.   else Result := #26;
  2634. end;
  2635.  
  2636. function request_loadheaders(sn: PSession; rq: PRequest): Integer;
  2637. begin
  2638.   Result := REQ_PROCEED;
  2639. end;
  2640.  
  2641. function userpw: PPASSWD;
  2642. begin
  2643.   Result := conf_getglobals.Vuserpw;
  2644. end;
  2645.  
  2646. function pool_max: Integer;
  2647. begin
  2648.   Result := conf_getglobals.Vpool_max;
  2649. end;
  2650.  
  2651. function pool_min: Integer;
  2652. begin
  2653.   Result := conf_getglobals.Vpool_min;
  2654. end;
  2655.  
  2656. function pool_life: Integer;
  2657. begin
  2658.   Result := conf_getglobals.Vpool_life;
  2659. end;
  2660.  
  2661. function pool_maxthreads: Integer;
  2662. begin
  2663.   Result := conf_getglobals.Vpool_maxthreads;
  2664. end;
  2665.  
  2666. function pool_minthreads: Integer;
  2667. begin
  2668.   Result := conf_getglobals.Vpool_minthreads;
  2669. end;
  2670.  
  2671.  
  2672. function server_hostname: PChar;
  2673. begin
  2674.   Result := conf_getglobals.Vserver_hostname;
  2675. end;
  2676.  
  2677. function root_object: PChar;
  2678. begin
  2679.   Result := conf_getglobals.Vroot_object;
  2680. end;
  2681.  
  2682. function std_os: PHttpdObjSet;
  2683. begin
  2684.   Result := conf_getglobals.Vstd_os;
  2685. end;
  2686.  
  2687. function acl_root: Pointer;
  2688. begin
  2689.   Result := conf_getglobals.Vacl_root;
  2690. end;
  2691.  
  2692. function master_error_log: PChar;
  2693. begin
  2694.   Result := conf_getglobals.Vmaster_error_log;
  2695. end;
  2696.  
  2697. function server_root: PChar;
  2698. begin
  2699.   Result := conf_getglobals.Vserver_root;
  2700. end;
  2701.  
  2702. function server_id: PChar;
  2703. begin
  2704.   Result := conf_getglobals.Vserver_id;
  2705. end;
  2706.  
  2707. function NSstr2String(nsStr: PChar): string;
  2708. begin
  2709.   Result := nsStr;
  2710.   system_free(nsStr);
  2711. end;
  2712.  
  2713. { imports }
  2714.  
  2715. function strcasecmp; external nshttp name 'strcasecmp';
  2716. function strncasecmp; external nshttp name 'strncasecmp';
  2717. function util_strcasecmp; external nshttp name 'util_strcasecmp';
  2718. function util_strncasecmp; external nshttp name 'util_strncasecmp';
  2719. function system_version; external nshttp name 'system_version';
  2720. function MAGNUS_VERSION_STRING; external nshttp name 'MAGNUS_VERSION_STRING';
  2721. procedure system_version_set; external nshttp name 'system_version_set';
  2722. function MALLOC; external nshttp name 'system_malloc';
  2723. function system_malloc; external nshttp name 'system_malloc';
  2724. function CALLOC; external nshttp name 'system_calloc';
  2725. function system_calloc; external nshttp name 'system_calloc';
  2726. function REALLOC; external nshttp name 'system_realloc';
  2727. function system_realloc; external nshttp name 'system_realloc';
  2728. procedure FREE; external nshttp name 'system_free';
  2729. procedure system_free; external nshttp name 'system_free';
  2730. function STRDUP; external nshttp name 'system_strdup';
  2731. function system_strdup; external nshttp name 'system_strdup';
  2732. function PERM_MALLOC; external nshttp name 'system_malloc_perm';
  2733. function system_malloc_perm; external nshttp name 'system_malloc_perm';
  2734. function PERM_CALLOC; external nshttp name 'system_calloc_perm';
  2735. function system_calloc_perm; external nshttp name 'system_calloc_perm';
  2736. function PERM_REALLOC; external nshttp name 'system_realloc_perm';
  2737. function system_realloc_perm; external nshttp name 'system_realloc_perm';
  2738. procedure PERM_FREE; external nshttp name 'system_free_perm';
  2739. procedure system_free_perm; external nshttp name 'system_free_perm';
  2740. function PERM_STRDUP; external nshttp name 'system_strdup_perm';
  2741. function system_strdup_perm; external nshttp name 'system_strdup_perm';
  2742. procedure magnus_atrestart; external nshttp name 'magnus_atrestart';
  2743. function pool_create; external nshttp name 'pool_create';
  2744. procedure pool_destroy; external nshttp name 'pool_destroy';
  2745. function pool_enabled; external nshttp name 'pool_enabled';
  2746. function pool_malloc; external nshttp name 'pool_malloc';
  2747. procedure pool_free; external nshttp name 'pool_free';
  2748. function pool_calloc; external nshttp name 'pool_calloc';
  2749. function pool_realloc; external nshttp name 'pool_realloc';
  2750. function pool_strdup; external nshttp name 'pool_strdup';
  2751. function sem_init; external nshttp name 'sem_init';
  2752. procedure sem_terminate; external nshttp name 'sem_terminate';
  2753. function sem_grab; external nshttp name 'sem_grab';
  2754. function sem_tgrab; external nshttp name 'sem_tgrab';
  2755. function sem_release; external nshttp name 'sem_release';
  2756. function crit_init; external nshttp name 'crit_init';
  2757. procedure crit_enter; external nshttp name 'crit_enter';
  2758. procedure crit_exit; external nshttp name 'crit_exit';
  2759. procedure crit_terminate; external nshttp name 'crit_terminate';
  2760. function condvar_init; external nshttp name 'condvar_init';
  2761. procedure condvar_wait; external nshttp name 'condvar_wait';
  2762. procedure condvar_notify; external nshttp name 'condvar_notify';
  2763. procedure condvar_terminate; external nshttp name 'condvar_terminate';
  2764. function system_chdir; external 'kernel32.dll' name 'SetCurrentDirectory';
  2765. function system_stat; external nshttp name 'system_stat';
  2766. function system_fread; external nshttp name 'system_fread';
  2767. function system_pread; external nshttp name 'system_pread';
  2768. function system_fopenRO; external nshttp name 'system_fopenRO';
  2769. function system_fopenWA; external nshttp name 'system_fopenWA';
  2770. function system_fopenRW; external nshttp name 'system_fopenRW';
  2771. function system_fopenWT; external nshttp name 'system_fopenWT';
  2772. procedure system_fclose; external nshttp name 'system_fclose';
  2773. function system_nocoredumps; external nshttp name 'system_nocoredumps';
  2774. function system_winsockerr; external nshttp name 'system_winsockerr';
  2775. function system_winerr; external nshttp name 'system_winerr';
  2776. function system_fwrite; external nshttp name 'system_fwrite';
  2777. function system_fwrite_atomic; external nshttp name 'system_fwrite_atomic';
  2778. function file_notfound; external nshttp name 'file_notfound';
  2779. function system_errmsg; external nshttp name 'system_errmsg_fn';
  2780. function system_errmsg_fn; external nshttp name 'system_errmsg_fn';
  2781. function system_initlock; external nshttp name 'system_initlock';
  2782. function file_setinherit; external nshttp name 'file_setinherit';
  2783. procedure file_unix2local; external nshttp name 'file_unix2local';
  2784. function dir_open; external nshttp name 'dir_open';
  2785. function dir_read; external nshttp name 'dir_read';
  2786. procedure dir_close; external nshttp name 'dir_close';
  2787. function dir_create_all; external nshttp name 'dir_create_all';
  2788. function param_create; external nshttp name 'param_create';
  2789. function param_free; external nshttp name 'param_free';
  2790. function pblock_create; external nshttp name 'pblock_create';
  2791. procedure pblock_free; external nshttp name 'pblock_free';
  2792. function pblock_findval; external nshttp name 'pblock_findval';
  2793. function pblock_nvinsert; external nshttp name 'pblock_nvinsert';
  2794. function pblock_nninsert; external nshttp name 'pblock_nninsert';
  2795. procedure pblock_pinsert; external nshttp name 'pblock_pinsert';
  2796. function pblock_str2pblock; external nshttp name 'pblock_str2pblock';
  2797. function pblock_pblock2str; external nshttp name 'pblock_pblock2str';
  2798. procedure pblock_copy; external nshttp name 'pblock_copy';
  2799. function pblock_dup; external nshttp name 'pblock_dup';
  2800. function pblock_pb2env; external nshttp name 'pblock_pb2env';
  2801. function _pblock_fr; external nshttp name '_pblock_fr';
  2802. function net_socket; external nshttp name 'net_socket';
  2803. function net_getsockopt; external nshttp name 'net_getsockopt';
  2804. function net_setsockopt; external nshttp name 'net_setsockopt';
  2805. function net_listen; external nshttp name 'net_listen';
  2806. function net_create_listener; external nshttp name 'net_create_listener';
  2807. function net_select; external nshttp name 'net_select';
  2808. function net_connect; external nshttp name 'net_connect';
  2809. function net_ioctl; external nshttp name 'net_ioctl';
  2810. function net_getpeername; external nshttp name 'net_getpeername';
  2811. function net_close; external nshttp name 'net_close';
  2812. function net_bind; external nshttp name 'net_bind';
  2813. function net_accept; external nshttp name 'net_accept';
  2814. function net_read; external nshttp name 'net_read';
  2815. function net_write; external nshttp name 'net_write';
  2816. function net_isalive; external nshttp name 'net_isalive';
  2817. function net_ip2host; external nshttp name 'net_ip2host';
  2818. function filebuf_open; external nshttp name 'filebuf_open';
  2819. function netbuf_open; external nshttp name 'netbuf_open';
  2820. function filebuf_create; external nshttp name 'filebuf_create';
  2821. procedure filebuf_close_buffer; external nshttp name 'filebuf_close_buffer';
  2822. function filebuf_open_nostat; external nshttp name 'filebuf_open_nostat';
  2823. function pipebuf_open; external nshttp name 'pipebuf_open';
  2824. function filebuf_next; external nshttp name 'filebuf_next';
  2825. function netbuf_next; external nshttp name 'netbuf_next';
  2826. function pipebuf_next; external nshttp name 'pipebuf_next';
  2827. procedure filebuf_close; external nshttp name 'filebuf_close';
  2828. procedure netbuf_close; external nshttp name 'netbuf_close';
  2829. procedure pipebuf_close; external nshttp name 'pipebuf_close';
  2830. function filebuf_grab; external nshttp name 'filebuf_grab';
  2831. function netbuf_grab; external nshttp name 'netbuf_grab';
  2832. function pipebuf_grab; external nshttp name 'pipebuf_grab';
  2833. function netbuf_buf2sd; external nshttp name 'netbuf_buf2sd';
  2834. function filebuf_buf2sd; external nshttp name 'filebuf_buf2sd';
  2835. function pipebuf_buf2sd; external nshttp name 'pipebuf_buf2sd';
  2836. function pipebuf_netbuf2sd; external nshttp name 'pipebuf_netbuf2sd';
  2837. function session_create; external nshttp name 'session_create';
  2838. procedure session_free; external nshttp name 'session_free';
  2839. function session_dns_lookup; external nshttp name 'session_dns_lookup';
  2840. procedure cinfo_init; external nshttp name 'cinfo_init';
  2841. procedure cinfo_terminate; external nshttp name 'cinfo_terminate';
  2842. function cinfo_merge; external nshttp name 'cinfo_merge';
  2843. function cinfo_find; external nshttp name 'cinfo_find';
  2844. function cinfo_lookup; external nshttp name 'cinfo_lookup';
  2845. function ereport_init; external nshttp name 'ereport_init';
  2846. procedure ereport_terminate; external nshttp name 'ereport_terminate';
  2847. function ereport_getfd; external nshttp name 'ereport_getfd';
  2848. function shexp_valid; external nshttp name 'shexp_valid';
  2849. function shexp_match; external nshttp name 'shexp_match';
  2850. function shexp_cmp; external nshttp name 'shexp_cmp';
  2851. function shexp_casecmp; external nshttp name 'shexp_casecmp';
  2852. function shmem_alloc; external nshttp name 'shmem_alloc';
  2853. procedure shmem_free; external nshttp name 'shmem_free';
  2854. function systhread_start; external nshttp name 'systhread_start';
  2855. function systhread_current; external nshttp name 'systhread_current';
  2856. procedure systhread_yield; external nshttp name 'systhread_yield';
  2857. function systhread_attach; external nshttp name 'systhread_attach';
  2858. procedure systhread_terminate; external nshttp name 'systhread_terminate';
  2859. procedure systhread_sleep; external nshttp name 'systhread_sleep';
  2860. procedure systhread_init; external nshttp name 'systhread_init';
  2861. procedure systhread_timerset; external nshttp name 'systhread_timerset';
  2862. function systhread_newkey; external nshttp name 'systhread_newkey';
  2863. function systhread_getdata; external nshttp name 'systhread_getdata';
  2864. procedure systhread_setdata; external nshttp name 'systhread_setdata';
  2865. procedure _ntdaemon_run; external nshttp name '_ntdaemon_run';
  2866. procedure daemon_atrestart; external nshttp name 'daemon_atrestart';
  2867. function child_fork; external nshttp name 'child_fork';
  2868. {$ifdef NET_SSL}
  2869. procedure servssl_init; external nshttp name 'servssl_init';
  2870. {$endif NET_SSL}
  2871. function util_getline; external nshttp name 'util_getline';
  2872. function util_env_create; external nshttp name 'util_env_create';
  2873. function util_env_str; external nshttp name 'util_env_str';
  2874. procedure util_env_replace; external nshttp name 'util_env_replace';
  2875. procedure util_env_free; external nshttp name 'util_env_free';
  2876. function util_env_copy; external nshttp name 'util_env_copy';
  2877. function util_env_find; external nshttp name 'util_env_find';
  2878. function util_hostname; external nshttp name 'util_hostname';
  2879. function util_chdir2path; external nshttp name 'util_chdir2path';
  2880. function util_is_mozilla; external nshttp name 'util_is_mozilla';
  2881. function util_is_url; external nshttp name 'util_is_url';
  2882. function util_later_than; external nshttp name 'util_later_than';
  2883. function util_time_equal; external nshttp name 'util_time_equal';
  2884. function util_str_time_equal; external nshttp name 'util_str_time_equal';
  2885. function util_uri_is_evil; external nshttp name 'util_uri_is_evil';
  2886. procedure util_uri_parse; external nshttp name 'util_uri_parse';
  2887. procedure util_uri_unescape; external nshttp name 'util_uri_unescape';
  2888. function util_uri_escape; external nshttp name 'util_uri_escape';
  2889. function util_url_escape; external nshttp name 'util_url_escape';
  2890. function util_sh_escape; external nshttp name 'util_sh_escape';
  2891. function util_mime_separator; external nshttp name 'util_mime_separator';
  2892. function util_itoa; external nshttp name 'util_itoa';
  2893. procedure util_delete_directory; external nshttp name 'util_delete_directory';
  2894. function util_strftime; external nshttp name 'util_strftime';
  2895. function object_create; external nshttp name 'object_create';
  2896. procedure object_free; external nshttp name 'object_free';
  2897. procedure object_add_directive; external nshttp name 'object_add_directive';
  2898. function object_execute; external nshttp name 'object_execute';
  2899. function objset_scan_buffer; external nshttp name 'objset_scan_buffer';
  2900. function objset_create; external nshttp name 'objset_create';
  2901. procedure objset_free; external nshttp name 'objset_free';
  2902. procedure objset_free_setonly; external nshttp name 'objset_free_setonly';
  2903. function objset_new_object; external nshttp name 'objset_new_object';
  2904. procedure objset_add_object; external nshttp name 'objset_add_object';
  2905. procedure objset_add_init; external nshttp name 'objset_add_init';
  2906. function objset_findbyname; external nshttp name 'objset_findbyname';
  2907. function objset_findbyppath; external nshttp name 'objset_findbyppath';
  2908. function objset_copydirs; external nshttp name 'objset_copydirs';
  2909. function objset_scan_registry; external nshttp name 'objset_scan_registry';
  2910. procedure ProcessObject; external nshttp name 'ProcessObject';
  2911. function ProcessClient; external nshttp name 'ProcessClient';
  2912. function ProcessDirective; external nshttp name 'ProcessDirective';
  2913. function ProcessFunction; external nshttp name 'ProcessFunction';
  2914. function _ntverify_parameter; external nshttp name '_ntverify_parameter';
  2915. function ntpblock_str2pblock; external nshttp name 'ntpblock_str2pblock';
  2916. function ntpblock_pblock2str; external nshttp name 'ntpblock_pblock2str';
  2917. function ClearConfigurationParameters; external nshttp name 'ClearConfigurationParameters';
  2918. function GetProductKey; external nshttp name 'GetProductKey';
  2919. function conf_init; external nshttp name 'conf_init';
  2920. procedure conf_terminate; external nshttp name 'conf_terminate';
  2921. function conf_getglobals; external nshttp name 'conf_getglobals';
  2922. procedure conf_vars2daemon; external nshttp name 'conf_vars2daemon';
  2923. function GetDomainAddresses; external nshttp name 'GetDomainAddresses';
  2924. function request_create; external nshttp name 'request_create';
  2925. procedure request_free; external nshttp name 'request_free';
  2926. function request_restart_internal; external nshttp name 'request_restart_internal';
  2927. function request_header; external nshttp name 'request_header';
  2928. function request_stat_path; external nshttp name 'request_stat_path';
  2929. procedure request_handle; external nshttp name 'request_handle';
  2930. function request_translate_uri; external nshttp name 'servact_translate_uri';
  2931. function protocol_find_request; external nshttp name 'http_find_request';
  2932. function http_find_request; external nshttp name 'http_find_request';
  2933. function protocol_parse_request; external nshttp name 'http_parse_request';
  2934. function http_parse_request; external nshttp name 'http_parse_request';
  2935. function protocol_scan_headers; external nshttp name 'http_scan_headers';
  2936. function http_scan_headers; external nshttp name 'http_scan_headers';
  2937. function protocol_start_response; external nshttp name 'http_start_response';
  2938. function http_start_response; external nshttp name 'http_start_response';
  2939. function http_hdrs2env; external nshttp name 'http_hdrs2env';
  2940. procedure protocol_status; external nshttp name 'http_status';
  2941. procedure http_status; external nshttp name 'http_status';
  2942. function protocol_set_finfo; external nshttp name 'http_set_finfo';
  2943. function http_set_finfo; external nshttp name 'http_set_finfo';
  2944. function http_dump822; external nshttp name 'http_dump822';
  2945. procedure protocol_finish_request; external nshttp name 'http_finish_request';
  2946. procedure http_finish_request; external nshttp name 'http_finish_request';
  2947. procedure protocol_handle_session; external nshttp name 'http_handle_session';
  2948. procedure http_handle_session; external nshttp name 'http_handle_session';
  2949. function protocol_uri2url; external nshttp name 'http_uri2url';
  2950. function protocol_uri2url_dynamic; external nshttp name 'http_uri2url_dynamic';
  2951. function http_uri2url; external nshttp name 'http_uri2url';
  2952. function http_uri2url_dynamic; external nshttp name 'http_uri2url_dynamic';
  2953. procedure protocol_set_keepalive_timeout; external nshttp name 'http_set_keepalive_timeout';
  2954. procedure http_set_keepalive_timeout; external nshttp name 'http_set_keepalive_timeout';
  2955. procedure func_init; external nshttp name 'func_init';
  2956. function func_find; external nshttp name 'func_find';
  2957. function func_exec; external nshttp name 'func_exec';
  2958. function func_insert; external nshttp name 'func_insert';
  2959.  
  2960. end.
  2961.