This repository has been archived by the owner on Dec 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibfcgi2.h
323 lines (259 loc) · 10.3 KB
/
libfcgi2.h
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
* libfcgi2.h
*
* Prototype Definitions for FCGX Library
*
* www.coastrd.com Coast Research © 2009
*
* NOTES:
* CDECL Calling Convention (same as libfcgi.DLL - see website)
* All Strings are ANSI *NOT* Unicode (for now)
*/
#ifndef _FCGXAPP_H
#define _FCGXAPP_H
//
//#ifdef __cplusplus // for C++ compilers
extern "C" { // (cdecl calling convention)
//#endif
// Request Method Codes for 'ReqMethod' property of the FCGX_REQUEST Structure
// Eliminates parsing strings for logical statements
#define HTTP_GET 1 // Information is appended onto the end of the request URI being requested
#define HTTP_POST 2 // Transmits all data immediately after the request URI.
#define HTTP_HEAD 3 // Headers of a GET request - Information about a document
#define HTTP_PUT 4 // The URI in a PUT request identifies the entity enclosed with the request.
#define HTTP_DELETE 5 // delete the resource identified by the Request-URI
#define HTTP_OPTIONS 6 // enum supported Methods
#define HTTP_TRACE 7 // enum each node along the path
#define HTTP_CONNECT 8 // Request web proxy dynamically switch to a secure IP-based connection (an SSL tunnel)
#define HTTP_UNKNOWN 9 // None of the Above
#define FCGX_NONE 0 // No Flags
#define FCGX_DEBUG 1 // Print Debug info - see comments for the flag in FCGX_InitRequest()
#define FCGX_REQP 2 // Print Debug info + Request Parameters
#define FCGX_ENVP 3 // Print Environment Parameters (only)
// Values for role component of FCGI_BeginRequestBody
#define FCGI_RESPONDER 1
#define FCGI_AUTHORIZER 2 // Not Supported
#define FCGI_FILTER 3 // Not Supported
// fcgx_stream
// this structure defines the fastcgi streams stdin, stdout & stderr
// each stream is an instance of the C++ string builder class
typedef struct FCGX_stream { // plain C structure
unsigned char* pData; // POINTER to the first BYTE of the buffer
unsigned int LenStored; // length of data currently contained in the buffer
unsigned int Capacity; // length of the buffer
char Reserved[12]; // Opaque Stream Variables
} FCGX_Stream;
// FCGX_Request - One instance per Request containing Request variables
typedef struct FCGX_Request { // plain C structure
int Version; // version number *1000
int ReqCount; // Total Requests
int Role; // FastCGI Role
int ConnFlags; // Connection flags
int ReqMethod; // 1=GET, 2=POST, 3=HEAD etc see above
int ContLen; // POST method CONTENT_LENGTH
char* pzQuery; // Pointer to ASCIIZ string containing QUERY_STRING
int nParam; // Total Request Params in the array
char** envp; // Pointer to an array of C-Strings containing Request Params
FCGX_Stream* pIn; // Pointer to input data buffer
FCGX_Stream* pOut; // Pointer to output data buffer
FCGX_Stream* pErr; // Pointer to Error data buffer
char* pzLastErr; // Pointer to ASCIIZ string containing LastError Description
char Reserved[108]; // Opaque FCGI Variables
} FCGX_REQUEST;
// Legacy Functions: (Identical to fcgiapp.h)
/*----------------------------------------------------------------------
* FCGX_InitRequest
*
* Initialize a FCGX_Request for use with FCGX_Accept_r()
*
* Return:
* 0 upon success
* -ve if an error occurred - Call FCGX_GetErrorStr() for Error description
*
* Comments:
* Sockets not supported - 'sock' is ignored
* 'flags' is zero or FCGX_DEBUG
* Create/Append to a 'Per Instance' FCGI Debug File
* IIS path: "C:\FCGIdebug\" (or whatever your drive letter is)
*/
int FCGX_InitRequest(FCGX_Request *request, int sock, int flags);
/*----------------------------------------------------------------------
* FCGX_Accept_r
*
* Accept a new request (Blocks until a Request is received)
*
* Return:
* 0 for successful call, -1 for SIGTERM, <-1 Error code.
*
* Comments:
* Be sure you called FCGX_Init() (once) first.
* Finishes the request accepted by (and frees any
* storage allocated by) the previous call to FCGX_Accept.
* Creates input, output, and error streams and
* assigns them to pIn, pOut, and pErr respectively.
* Creates a parameters data structure to be accessed
*/
int FCGX_Accept_r(FCGX_Request *request);
/*----------------------------------------------------------------------
* FCGX_Finish_r
*
* Complete the request
*
* Return:
* 0 for successful call
* -ve if an error occurred - Call FCGX_GetErrorStr() for Error description
*
* Comments:
* Finishes the request accepted by the previous call
* Returns response and empties buffers
*/
int FCGX_Finish_r(FCGX_Request *request);
/*----------------------------------------------------------------------
* FCGX_GetParam
*
* Obtain value of a specific FCGI ENVIRON parameter
*
* Return:
* Character array pointer to a NULL terminated string
*
* Comments:
* envp is a (misnamed) pointer to an array of C-Strings
* The array contains 4Byte pointers to the C-Strings
* (which by definition are Character array pointers)
* The C-Strings are in the format name=value and
* contain the *Request* parameters (not the Environment Params)
* (to see the Environ Params set FCGX_ENVP flag in FCGX_InitRequest())
*/
char* FCGX_GetParam(const char *name, char **envp); // pArray
/*----------------------------------------------------------------------
* FCGX_GetStr
*
* Obtain n bytes from the input buffer
*
* Return:
* Number of bytes read
* -ve if an error occurred - Call FCGX_GetErrorStr() for Error description
*
* Comments:
* The 'LenStored' member of FCGX_stream contains the input buffer length
* A character array should be dimensioned to this size and a pointer
* to it passed in as the first parameter
* This prototype has been changed slightly
* str is declared as const char* not char*
*/
int FCGX_GetStr(const char *str, int nbytes, FCGX_Stream *stream);
/*----------------------------------------------------------------------
* FCGX_PutStr
*
* Writes n consecutive bytes to the output buffer
*
* Return:
* Number of bytes written
* -ve if an error occurred - Call FCGX_GetErrorStr() for Error description
*/
int FCGX_PutStr(const char *str, int nbytes, FCGX_Stream *stream);
/*----------------------------------------------------------------------
* FCGX_PutS
*
* Write a null-terminated character string to the output buffer
*
* Return:
* Number of bytes written
* -ve if an error occurred - Call FCGX_GetErrorStr() for Error description
*/
int FCGX_PutS(const char *str, FCGX_Stream *stream);
// New Functions:
/*----------------------------------------------------------------------
*
* FCGX_Flush -- (not FCGX_FFlush)
*
* Flushes any buffered output in the StdOut or StdErr buffers
* to the WebServer, emptying the buffer.
* This version takes the *Request* not the Stream handle as the argument
*
* Return:
* 0 for success, -ve Error code.
* -ve if an error occurred - Call FCGX_GetErrorStr() for Error description
*/
int FCGX_Flush(FCGX_Request *request);
/*----------------------------------------------------------------------
* FCGX_GetBytes
*
* Copies nBytes begining at src from any stream buffer to dest
* Uses a very fast ASM memcopy - see notes
* use any time after FCGX_InitRequest() has been called
* Unlike FCGX_GetStr() this function does not advance down the buffer
* with each call. It allows you to read from anywhere within the buffer
* Pointers are verified with IsBadReadPtr/IsBadWritePtr
*
* src is checked to ensure it is valid pointer
* dest is checked to ensure it is within the buffer
* nBytes is checked to ensure it does exceed the buffer length
*
* Return:
* Number of bytes read (can be less than specified)
* -ve if an error occurred - Call FCGX_GetErrorStr() for description
*/
int FCGX_GetBytes(FCGX_Stream *stream, const char *src, const char *dest, int nbytes);
/*----------------------------------------------------------------------
* FCGX_PutBytes
*
* Copies nBytes begining from src to dest within any stream buffer
* Uses a very fast ASM memcopy - see notes
* use any time after FCGX_InitRequest() has been called
* Unlike FCGX_PutStr() this function does not append to the buffer
* It allows you to write anywhere within the buffer.
* Pointers are verified with IsBadReadPtr/IsBadWritePtr
*
* src is checked to ensure it is valid pointer
* dest is checked to ensure it is within the buffer
* nBytes is checked to ensure it does exceed the buffer length
*
* Return:
* exactly nBytes
* -ve if an error occurred - Call FCGX_GetErrorStr() for description
*/
int FCGX_PutBytes(FCGX_Stream *stream, const char *src, const char *dest, int nbytes);
/*----------------------------------------------------------------------
* FCGX_EnsureCap
*
* Use this to ensure enough capacity of any of the stream buffers
* The buffer is doubled in size until it is large enough
*
* Return:
* New buffer length - Capacity
*/
unsigned int FCGX_EnsureCap(FCGX_Stream *stream, int nbytes);
/*----------------------------------------------------------------------
* FCGX_URLDecode
*
* Very fast "in place" URL decoding
*
* Return:
* Decoded length
*/
int FCGX_URLDecode(const char *str, int nbytes);
/*----------------------------------------------------------------------
* FCGX_PutDebug
*
* Add text to the Debug file *only if*
* FCGX_DEBUG flag is set in FCGX_InitRequest()
*
* Comments:
* A FastCGI app may not open a console or a dialog
* This allows you to easily view variable values and
* output text for analysis in the same Debug file.
* Text inserted into the Debug file is clearly deliniated
*/
int FCGX_PutDebug(const char *str);
/*
* FCGX_Read
* FCGX_Write
* FCGX_GetValue
*
* ANSI BSTR version of string functions for convenience in BASIC
*/
//#ifdef __cplusplus // for C++ compilers
}
//#endif
#endif /* _FCGXAPP_H */