php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
lsapilib.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: George Wang <gwang@litespeedtech.com> |
14 +----------------------------------------------------------------------+
15*/
16
17/*
18Copyright (c) 2002-2018, Lite Speed Technologies Inc.
19All rights reserved.
20
21Redistribution and use in source and binary forms, with or without
22modification, are permitted provided that the following conditions are
23met:
24
25 * Redistributions of source code must retain the above copyright
26 notice, this list of conditions and the following disclaimer.
27 * Redistributions in binary form must reproduce the above
28 copyright notice, this list of conditions and the following
29 disclaimer in the documentation and/or other materials provided
30 with the distribution.
31 * Neither the name of the Lite Speed Technologies Inc nor the
32 names of its contributors may be used to endorse or promote
33 products derived from this software without specific prior
34 written permission.
35
36THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47*/
48
49
50#ifndef _LSAPILIB_H_
51#define _LSAPILIB_H_
52
53#if defined (c_plusplus) || defined (__cplusplus)
54extern "C" {
55#endif
56
57#include "lsapidef.h"
58
59#include <stddef.h>
60#include <sys/time.h>
61#include <sys/types.h>
62
64{
65 char * pKey;
66 char * pValue;
67 int keyLen;
68 int valLen;
69};
70
72#define LSAPI_MAX_RESP_HEADERS 1000
73
130
131extern LSAPI_Request g_req;
132
133
134/* return: >0 continue, ==0 stop, -1 failed */
135typedef int (*LSAPI_CB_EnvHandler )( const char * pKey, int keyLen,
136 const char * pValue, int valLen, void * arg );
137
138
139int LSAPI_Init(void);
140
141void LSAPI_Stop(void);
142
144
145int LSAPI_InitRequest( LSAPI_Request * pReq, int fd );
146
147int LSAPI_Accept_r( LSAPI_Request * pReq );
148
149void LSAPI_Reset_r( LSAPI_Request * pReq );
150
151int LSAPI_Finish_r( LSAPI_Request * pReq );
152
153int LSAPI_Release_r( LSAPI_Request * pReq );
154
155char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex );
156
158 LSAPI_CB_EnvHandler fn, void * arg );
159
161 LSAPI_CB_EnvHandler fn, void * arg );
162
164 LSAPI_CB_EnvHandler fn, void * arg );
165
167 LSAPI_CB_EnvHandler fn, void * arg );
168
169char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name );
170
171ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t len );
172
174
175int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, int *getLF );
176
177
179
180ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len );
181
182ssize_t LSAPI_sendfile_r( LSAPI_Request * pReq, int fdIn, off_t* off, size_t size );
183
184ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t len );
185
186int LSAPI_Flush_r( LSAPI_Request * pReq );
187
188int LSAPI_AppendRespHeader_r( LSAPI_Request * pReq, const char * pBuf, int len );
189
190int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName,
191 const char * pHeaderValue );
192
193int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders,
194 const char * pBody, int bodyLen );
195
196static inline int LSAPI_SetRespStatus_r( LSAPI_Request * pReq, int code )
197{
198 if ( !pReq )
199 return -1;
200 pReq->m_respHeader.m_respInfo.m_status = code;
201 return 0;
202}
203
204static inline int LSAPI_SetAppData_r( LSAPI_Request * pReq, void * data )
205{
206 if ( !pReq )
207 return -1;
208 pReq->m_pAppData = data;
209 return 0;
210}
211
212static inline void * LSAPI_GetAppData_r( LSAPI_Request * pReq )
213{
214 if ( !pReq )
215 return NULL;
216 return pReq->m_pAppData;
217}
218
219static inline char * LSAPI_GetQueryString_r( LSAPI_Request * pReq )
220{
221 if ( pReq )
222 return pReq->m_pQueryString;
223 return NULL;
224}
225
226
227static inline char * LSAPI_GetScriptFileName_r( LSAPI_Request * pReq )
228{
229 if ( pReq )
230 return pReq->m_pScriptFile;
231 return NULL;
232}
233
234
235static inline char * LSAPI_GetScriptName_r( LSAPI_Request * pReq )
236{
237 if ( pReq )
238 return pReq->m_pScriptName;
239 return NULL;
240}
241
242
243static inline char * LSAPI_GetRequestMethod_r( LSAPI_Request * pReq)
244{
245 if ( pReq )
246 return pReq->m_pRequestMethod;
247 return NULL;
248}
249
250
251
252static inline off_t LSAPI_GetReqBodyLen_r( LSAPI_Request * pReq )
253{
254 if ( pReq )
255 return pReq->m_reqBodyLen;
256 return -1;
257}
258
259static inline off_t LSAPI_GetReqBodyRemain_r( LSAPI_Request * pReq )
260{
261 if ( pReq )
262 return pReq->m_reqBodyLen - pReq->m_reqBodyRead;
263 return -1;
264}
265
266
268
269
270
271int LSAPI_Is_Listen(void);
272
273static inline int LSAPI_Accept( void )
274{ return LSAPI_Accept_r( &g_req ); }
275
276static inline int LSAPI_Finish(void)
277{ return LSAPI_Finish_r( &g_req ); }
278
279static inline char * LSAPI_GetHeader( int headerIndex )
280{ return LSAPI_GetHeader_r( &g_req, headerIndex ); }
281
282static inline int LSAPI_ForeachHeader( LSAPI_CB_EnvHandler fn, void * arg )
283{ return LSAPI_ForeachHeader_r( &g_req, fn, arg ); }
284
285static inline int LSAPI_ForeachOrgHeader(
286 LSAPI_CB_EnvHandler fn, void * arg )
287{ return LSAPI_ForeachOrgHeader_r( &g_req, fn, arg ); }
288
289static inline int LSAPI_ForeachEnv( LSAPI_CB_EnvHandler fn, void * arg )
290{ return LSAPI_ForeachEnv_r( &g_req, fn, arg ); }
291
292static inline int LSAPI_ForeachSpecialEnv( LSAPI_CB_EnvHandler fn, void * arg )
293{ return LSAPI_ForeachSpecialEnv_r( &g_req, fn, arg ); }
294
295static inline char * LSAPI_GetEnv( const char * name )
296{ return LSAPI_GetEnv_r( &g_req, name ); }
297
298static inline char * LSAPI_GetQueryString(void)
299{ return LSAPI_GetQueryString_r( &g_req ); }
300
301static inline char * LSAPI_GetScriptFileName(void)
302{ return LSAPI_GetScriptFileName_r( &g_req ); }
303
304static inline char * LSAPI_GetScriptName(void)
305{ return LSAPI_GetScriptName_r( &g_req ); }
306
307static inline char * LSAPI_GetRequestMethod(void)
308{ return LSAPI_GetRequestMethod_r( &g_req ); }
309
310static inline off_t LSAPI_GetReqBodyLen(void)
311{ return LSAPI_GetReqBodyLen_r( &g_req ); }
312
313static inline off_t LSAPI_GetReqBodyRemain(void)
314{ return LSAPI_GetReqBodyRemain_r( &g_req ); }
315
316static inline ssize_t LSAPI_ReadReqBody( char * pBuf, size_t len )
317{ return LSAPI_ReadReqBody_r( &g_req, pBuf, len ); }
318
319static inline int LSAPI_ReqBodyGetChar(void)
320{ return LSAPI_ReqBodyGetChar_r( &g_req ); }
321
322static inline int LSAPI_ReqBodyGetLine( char * pBuf, int len, int *getLF )
323{ return LSAPI_ReqBodyGetLine_r( &g_req, pBuf, len, getLF ); }
324
325
326
327static inline int LSAPI_FinalizeRespHeaders(void)
329
330static inline ssize_t LSAPI_Write( const char * pBuf, ssize_t len )
331{ return LSAPI_Write_r( &g_req, pBuf, len ); }
332
333static inline ssize_t LSAPI_sendfile( int fdIn, off_t* off, size_t size )
334{
335 return LSAPI_sendfile_r(&g_req, fdIn, off, size );
336}
337
338static inline ssize_t LSAPI_Write_Stderr( const char * pBuf, ssize_t len )
339{ return LSAPI_Write_Stderr_r( &g_req, pBuf, len ); }
340
341static inline int LSAPI_Flush(void)
342{ return LSAPI_Flush_r( &g_req ); }
343
344static inline int LSAPI_AppendRespHeader( char * pBuf, int len )
345{ return LSAPI_AppendRespHeader_r( &g_req, pBuf, len ); }
346
347static inline int LSAPI_SetRespStatus( int code )
348{ return LSAPI_SetRespStatus_r( &g_req, code ); }
349
350static inline int LSAPI_ErrResponse( int code, const char ** pRespHeaders, const char * pBody, int bodyLen )
351{ return LSAPI_ErrResponse_r( &g_req, code, pRespHeaders, pBody, bodyLen ); }
352
353static inline int LSAPI_End_Response(void)
354{ return LSAPI_End_Response_r( &g_req ); }
355
356int LSAPI_IsRunning(void);
357
358int LSAPI_CreateListenSock( const char * pBind, int backlog );
359
360typedef int (*fn_select_t)( int, fd_set *, fd_set *, fd_set *, struct timeval * );
361
362int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork );
363
364void LSAPI_Set_Server_fd( int fd );
365
367
368void LSAPI_No_Check_ppid(void);
369
370void LSAPI_Set_Max_Reqs( int reqs );
371
372void LSAPI_Set_Max_Idle( int secs );
373
374void LSAPI_Set_Max_Children( int maxChildren );
375
376void LSAPI_Set_Max_Idle_Children( int maxIdleChld );
377
378void LSAPI_Set_Server_Max_Idle_Secs( int serverMaxIdle );
379
380void LSAPI_Set_Max_Process_Time( int secs );
381
383
384void LSAPI_Set_Slow_Req_Msecs( int msecs );
385
387
388int LSAPI_is_suEXEC_Daemon(void);
389
391
392typedef void (*LSAPI_On_Timer_pf)(int *forked_child_pid);
394
395int LSAPI_Inc_Req_Processed(int cnt);
396
398
400
402
403#define LSAPI_LOG_LEVEL_BITS 0xff
404#define LSAPI_LOG_FLAG_NONE 0
405#define LSAPI_LOG_FLAG_DEBUG 1
406#define LSAPI_LOG_FLAG_INFO 2
407#define LSAPI_LOG_FLAG_NOTICE 3
408#define LSAPI_LOG_FLAG_WARN 4
409#define LSAPI_LOG_FLAG_ERROR 5
410#define LSAPI_LOG_FLAG_CRIT 6
411#define LSAPI_LOG_FLAG_FATAL 7
412
413#define LSAPI_LOG_TIMESTAMP_BITS (0xff00)
414#define LSAPI_LOG_TIMESTAMP_FULL (0x100)
415#define LSAPI_LOG_TIMESTAMP_HMS (0x200)
416#define LSAPI_LOG_TIMESTAMP_STDERR (0x400)
417
418#define LSAPI_LOG_PID (0x10000)
419
420void LSAPI_Log(int flag, const char * fmt, ...)
421#ifdef __GNUC__
422 __attribute__((format(printf, 2, 3)))
423#endif
424;
425
426
427#if defined (c_plusplus) || defined (__cplusplus)
428}
429#endif
430
431
432#endif
size_t len
Definition apprentice.c:174
printf(string $format, mixed ... $values)
new_type size
Definition ffi.c:4365
zval * arg
Definition ffi.c:3975
#define __attribute__(a)
Definition file.h:131
#define NULL
Definition gdcache.h:45
LSAPI_Request g_req
Definition lsapilib.c:173
int LSAPI_ForeachSpecialEnv_r(LSAPI_Request *pReq, LSAPI_CB_EnvHandler fn, void *arg)
Definition lsapilib.c:2451
void LSAPI_Register_Pgrp_Timer_Callback(LSAPI_On_Timer_pf)
Definition lsapilib.c:1475
char * LSAPI_GetEnv_r(LSAPI_Request *pReq, const char *name)
Definition lsapilib.c:2238
ssize_t LSAPI_Write_Stderr_r(LSAPI_Request *pReq, const char *pBuf, size_t len)
Definition lsapilib.c:2125
int LSAPI_ForeachOrgHeader_r(LSAPI_Request *pReq, LSAPI_CB_EnvHandler fn, void *arg)
Definition lsapilib.c:2274
int LSAPI_Accept_r(LSAPI_Request *pReq)
Definition lsapilib.c:1532
int LSAPI_Release_r(LSAPI_Request *pReq)
Definition lsapilib.c:1675
int LSAPI_AppendRespHeader_r(LSAPI_Request *pReq, const char *pBuf, int len)
Definition lsapilib.c:2550
#define LSAPI_MAX_RESP_HEADERS
Definition lsapilib.h:72
int LSAPI_Is_Listen(void)
Definition lsapilib.c:1520
int(* LSAPI_CB_EnvHandler)(const char *pKey, int keyLen, const char *pValue, int valLen, void *arg)
Definition lsapilib.h:135
void LSAPI_Set_Max_Reqs(int reqs)
Definition lsapilib.c:3740
int LSAPI_Init_Env_Parameters(fn_select_t fp)
Definition lsapilib.c:3960
int LSAPI_Set_Restored_Parent_Pid(int pid)
Definition lsapilib.c:4352
void LSAPI_Set_Server_Max_Idle_Secs(int serverMaxIdle)
Definition lsapilib.c:3775
int LSAPI_Init_Prefork_Server(int max_children, fn_select_t fp, int avoidFork)
Definition lsapilib.c:2766
int LSAPI_ReqBodyGetLine_r(LSAPI_Request *pReq, char *pBuf, size_t bufLen, int *getLF)
Definition lsapilib.c:1743
ssize_t LSAPI_sendfile_r(LSAPI_Request *pReq, int fdIn, off_t *off, size_t size)
Definition lsapilib.c:2034
void LSAPI_Set_Max_Idle_Children(int maxIdleChld)
Definition lsapilib.c:3768
struct lsapi_request LSAPI_Request
int LSAPI_IsRunning(void)
Definition lsapilib.c:1469
int LSAPI_ForeachHeader_r(LSAPI_Request *pReq, LSAPI_CB_EnvHandler fn, void *arg)
Definition lsapilib.c:2350
int LSAPI_is_suEXEC_Daemon(void)
Definition lsapilib.c:900
int LSAPI_Postfork_Child(LSAPI_Request *pReq)
Definition lsapilib.c:3362
void(* LSAPI_On_Timer_pf)(int *forked_child_pid)
Definition lsapilib.h:392
int LSAPI_Finish_r(LSAPI_Request *pReq)
Definition lsapilib.c:1599
int(* fn_select_t)(int, fd_set *, fd_set *, fd_set *, struct timeval *)
Definition lsapilib.h:360
int LSAPI_Postfork_Parent(LSAPI_Request *pReq)
Definition lsapilib.c:3403
int LSAPI_ErrResponse_r(LSAPI_Request *pReq, int code, const char **pRespHeaders, const char *pBody, int bodyLen)
Definition lsapilib.c:4103
void LSAPI_No_Check_ppid(void)
Definition lsapilib.c:3794
void LSAPI_Set_Max_Children(int maxChildren)
Definition lsapilib.c:3747
int LSAPI_Inc_Req_Processed(int cnt)
Definition lsapilib.c:4360
void LSAPI_Set_Slow_Req_Msecs(int msecs)
Definition lsapilib.c:3782
int LSAPI_ReqBodyGetChar_r(LSAPI_Request *pReq)
Definition lsapilib.c:1729
void LSAPI_Log(int flag, const char *fmt,...)
Definition lsapilib.c:242
int LSAPI_FinalizeRespHeaders_r(LSAPI_Request *pReq)
Definition lsapilib.c:2467
int LSAPI_Is_Listen_r(LSAPI_Request *pReq)
Definition lsapilib.c:1526
int LSAPI_AppendRespHeader2_r(LSAPI_Request *pReq, const char *pHeaderName, const char *pHeaderValue)
Definition lsapilib.c:2494
int LSAPI_Prefork_Accept_r(LSAPI_Request *pReq)
Definition lsapilib.c:3562
int LSAPI_CreateListenSock(const char *pBind, int backlog)
Definition lsapilib.c:2731
int LSAPI_Get_Slow_Req_Msecs(void)
Definition lsapilib.c:3788
int LSAPI_InitRequest(LSAPI_Request *pReq, int fd)
Definition lsapilib.c:1481
void LSAPI_Stop(void)
Definition lsapilib.c:1463
void LSAPI_Set_Max_Idle(int secs)
Definition lsapilib.c:3743
int LSAPI_Init(void)
Definition lsapilib.c:1435
void LSAPI_Set_Max_Process_Time(int secs)
Definition lsapilib.c:3761
void LSAPI_Set_Server_fd(int fd)
Definition lsapilib.c:2808
int LSAPI_ForeachEnv_r(LSAPI_Request *pReq, LSAPI_CB_EnvHandler fn, void *arg)
Definition lsapilib.c:2437
char * LSAPI_GetHeader_r(LSAPI_Request *pReq, int headerIndex)
Definition lsapilib.c:1689
ssize_t LSAPI_Write_r(LSAPI_Request *pReq, const char *pBuf, size_t len)
Definition lsapilib.c:1839
int LSAPI_Flush_r(LSAPI_Request *pReq)
Definition lsapilib.c:2082
void LSAPI_Reset_r(LSAPI_Request *pReq)
Definition lsapilib.c:1664
ssize_t LSAPI_ReadReqBody_r(LSAPI_Request *pReq, char *pBuf, size_t len)
Definition lsapilib.c:1790
int LSAPI_Accept_Before_Fork(LSAPI_Request *pReq)
Definition lsapilib.c:3418
int LSAPI_End_Response_r(LSAPI_Request *pReq)
Definition lsapilib.c:1629
int fd
Definition phpdbg.h:282
zend_constant * data
char * m_pRespBufEnd
Definition lsapilib.h:86
struct lsapi_req_header * m_pHeader
Definition lsapilib.h:102
char * m_pScriptFile
Definition lsapilib.h:111
short m_respHeaderLen[LSAPI_MAX_RESP_HEADERS]
Definition lsapilib.h:126
struct iovec * m_pIovecCur
Definition lsapilib.h:97
off_t m_reqBodyLen
Definition lsapilib.h:118
char * m_pRespHeaderBuf
Definition lsapilib.h:89
off_t m_reqBodyRead
Definition lsapilib.h:119
int m_bufProcessed
Definition lsapilib.h:120
char * m_pReqBuf
Definition lsapilib.h:82
char * m_pRespBuf
Definition lsapilib.h:85
struct iovec * m_pIovec
Definition lsapilib.h:95
char * m_pQueryString
Definition lsapilib.h:113
struct lsapi_child_status * child_status
Definition lsapilib.h:92
struct iovec * m_pIovecToWrite
Definition lsapilib.h:98
char * m_pHttpHeader
Definition lsapilib.h:114
char * m_pRespBufPos
Definition lsapilib.h:87
struct iovec * m_pIovecEnd
Definition lsapilib.h:96
char * m_pRespHeaderBufPos
Definition lsapilib.h:91
int m_envListSize
Definition lsapilib.h:105
long m_lLastActive
Definition lsapilib.h:79
long m_lReqBegin
Definition lsapilib.h:80
char * m_pRequestMethod
Definition lsapilib.h:115
struct lsapi_resp_header m_respHeader
Definition lsapilib.h:125
struct lsapi_http_header_index * m_pHeaderIndex
Definition lsapilib.h:108
char * m_pScriptName
Definition lsapilib.h:112
struct lsapi_packet_header * m_respPktHeaderEnd
Definition lsapilib.h:100
int m_specialEnvListSize
Definition lsapilib.h:106
struct lsapi_packet_header m_respPktHeader[5]
Definition lsapilib.h:123
struct LSAPI_key_value_pair * m_pSpecialEnvList
Definition lsapilib.h:104
int m_reqBufSize
Definition lsapilib.h:83
struct LSAPI_key_value_pair * m_pEnvList
Definition lsapilib.h:103
char * m_pRespHeaderBufEnd
Definition lsapilib.h:90
struct lsapi_header_offset * m_pUnknownHeader
Definition lsapilib.h:109
void * m_pAppData
Definition lsapilib.h:127
struct lsapi_resp_info m_respInfo
Definition lsapidef.h:185
int32_t m_status
Definition lsapidef.h:179
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
zend_string * name