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