home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / nsfast / root.10 / usr / ns-home / nsapi / include / frame / func.h / func.h
Encoding:
C/C++ Source or Header  |  1998-08-19  |  2.9 KB  |  115 lines

  1. /*
  2.  * Copyright (c) 1994, 1995.  Netscape Communications Corporation.  All
  3.  * rights reserved.
  4.  * 
  5.  * Use of this software is governed by the terms of the license agreement for
  6.  * the Netscape FastTrack or Netscape Enterprise Server between the
  7.  * parties.
  8.  */
  9.  
  10.  
  11. /* ------------------------------------------------------------------------ */
  12.  
  13.  
  14. /*
  15.  * func.h: Handles the function hash table
  16.  * 
  17.  * httpd uses a table of internal functions hashed by a name string such that
  18.  * users can reference specific functions from the configuration files.
  19.  * 
  20.  * Any function referenced by configuration files will be passed a 
  21.  * parameter, a Request structure. The functions do not return anything.
  22.  *
  23.  * Rob McCool
  24.  */
  25.  
  26. #ifndef FUNC_H
  27. #define FUNC_H
  28.  
  29.  
  30. #include "netsite.h"
  31. #include "base/pblock.h"
  32. #include "base/session.h"   /* Session structure */
  33. #include "frame/req.h"      /* Request structure */
  34.  
  35.  
  36. /* -------------------------- Structure and Type -------------------------- */
  37.  
  38.  
  39. /*
  40.  * FuncPtr is a pointer to our kind of functions
  41.  */
  42.  
  43. #ifdef XP_UNIX
  44. typedef int Func(pblock *, Session *, Request *);
  45. #else /* XP_WIN32 */
  46. typedef int _cdecl Func(pblock *, Session *, Request *);
  47. #endif /* XP_WIN32 */
  48.  
  49. typedef Func *FuncPtr;
  50.  
  51. /*
  52.  * FuncStruct is a structure used in the static declaration of the 
  53.  * functions. This static declaration is parsed into a hash table at 
  54.  * startup. You should initialize the next entry to NULL.
  55.  */
  56.  
  57. struct FuncStruct {
  58.     char *name;
  59.     FuncPtr func;
  60.     struct FuncStruct *next;
  61. };
  62.  
  63.  
  64. /* --------------------------- Hash definitions --------------------------- */
  65.  
  66.  
  67. /* 
  68.  * This is a primitive hash function. Once more is known about the names of
  69.  * the functions, this will be optimized.
  70.  */
  71.  
  72. #define NUM_HASH 20
  73. #define FUNC_HASH(s) (s[0] % NUM_HASH)
  74.  
  75.  
  76. /* ------------------------------ Prototypes ------------------------------ */
  77.  
  78.  
  79. /*
  80.  * func_init reads the static FuncStruct arrays and creates the global 
  81.  * function table from them.
  82.  *
  83.  * func_init will only read from the static arrays defined in func.c.
  84.  */
  85.  
  86. NSAPI_PUBLIC void func_init(void);
  87.  
  88. /*
  89.  * func_find returns a pointer to the function named name, or NULL if none
  90.  * exists.
  91.  */
  92.  
  93. NSAPI_PUBLIC FuncPtr func_find(char *name);
  94.  
  95. /*
  96.  * func_exec will try to execute the function whose name is the "fn" entry
  97.  * in the given pblock. If name is not found, it will log a misconfig of
  98.  * missing fn parameter. If it can't find it, it will log that. In these
  99.  * cases it will return REQ_ABORTED. Otherwise, it will return what the 
  100.  * function being executed returns.
  101.  */
  102.  
  103. NSAPI_PUBLIC int func_exec(pblock *pb, Session *sn, Request *rq);
  104.  
  105. /*
  106.  * func_insert dynamically inserts a named function into the server's
  107.  * table of functions. Returns the FuncStruct it keeps in internal 
  108.  * databases, because on server restart you are responsible for freeing 
  109.  * (or not) its contents.
  110.  */
  111.  
  112. NSAPI_PUBLIC struct FuncStruct *func_insert(char *name, FuncPtr fn);
  113.  
  114. #endif
  115.