root/sapi/litespeed/lsapilib.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. LSAPI_SetRespStatus_r
  2. LSAPI_SetAppData_r
  3. LSAPI_GetAppData_r
  4. LSAPI_GetQueryString_r
  5. LSAPI_GetScriptFileName_r
  6. LSAPI_GetScriptName_r
  7. LSAPI_GetRequestMethod_r
  8. LSAPI_GetReqBodyLen_r
  9. LSAPI_GetReqBodyRemain_r
  10. LSAPI_Accept
  11. LSAPI_Finish
  12. LSAPI_GetHeader
  13. LSAPI_ForeachHeader
  14. LSAPI_ForeachOrgHeader
  15. LSAPI_ForeachEnv
  16. LSAPI_ForeachSpecialEnv
  17. LSAPI_GetEnv
  18. LSAPI_GetQueryString
  19. LSAPI_GetScriptFileName
  20. LSAPI_GetScriptName
  21. LSAPI_GetRequestMethod
  22. LSAPI_GetReqBodyLen
  23. LSAPI_GetReqBodyRemain
  24. LSAPI_ReadReqBody
  25. LSAPI_ReqBodyGetChar
  26. LSAPI_ReqBodyGetLine
  27. LSAPI_FinalizeRespHeaders
  28. LSAPI_Write
  29. LSAPI_sendfile
  30. LSAPI_Write_Stderr
  31. LSAPI_Flush
  32. LSAPI_AppendRespHeader
  33. LSAPI_SetRespStatus
  34. LSAPI_ErrResponse

   1 /*
   2    +----------------------------------------------------------------------+
   3    | PHP Version 7                                                        |
   4    +----------------------------------------------------------------------+
   5    | Copyright (c) 1997-2016 The PHP Group                                |
   6    +----------------------------------------------------------------------+
   7    | This source file is subject to version 3.01 of the PHP license,      |
   8    | that is bundled with this package in the file LICENSE, and is        |
   9    | available at through the world-wide-web at the following url:        |
  10    | http://www.php.net/license/3_01.txt.                                 |
  11    | If you did not receive a copy of the PHP license and are unable to   |
  12    | obtain it through the world-wide-web, please send a note to          |
  13    | license@php.net so we can mail you a copy immediately.               |
  14    +----------------------------------------------------------------------+
  15    | Author: George Wang <gwang@litespeedtech.com>                        |
  16    +----------------------------------------------------------------------+
  17 */
  18 
  19 /*
  20 Copyright (c) 2002-2015, Lite Speed Technologies Inc.
  21 All rights reserved.
  22 
  23 Redistribution and use in source and binary forms, with or without
  24 modification, are permitted provided that the following conditions are
  25 met:
  26 
  27     * Redistributions of source code must retain the above copyright
  28       notice, this list of conditions and the following disclaimer.
  29     * Redistributions in binary form must reproduce the above
  30       copyright notice, this list of conditions and the following
  31       disclaimer in the documentation and/or other materials provided
  32       with the distribution.
  33     * Neither the name of the Lite Speed Technologies Inc nor the
  34       names of its contributors may be used to endorse or promote
  35       products derived from this software without specific prior
  36       written permission.
  37 
  38 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  39 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  41 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  42 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  44 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  45 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  46 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  48 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49 */
  50 
  51 
  52 #ifndef  _LSAPILIB_H_
  53 #define  _LSAPILIB_H_
  54 
  55 #if defined (c_plusplus) || defined (__cplusplus)
  56 extern "C" {
  57 #endif
  58 
  59 #include <stddef.h>
  60 #include <lsapidef.h>
  61 
  62 #include <sys/time.h>
  63 #include <sys/types.h>
  64 
  65 struct LSAPI_key_value_pair
  66 {
  67     char * pKey;
  68     char * pValue;
  69     int    keyLen;
  70     int    valLen;
  71 };
  72 
  73 
  74 #define LSAPI_MAX_RESP_HEADERS  100
  75 
  76 typedef struct lsapi_request
  77 {
  78     int               m_fdListen;
  79     int               m_fd;
  80 
  81     long              m_lLastActive;
  82     long              m_lReqBegin;
  83 
  84     char            * m_pReqBuf;
  85     int               m_reqBufSize;
  86 
  87     char            * m_pRespBuf;
  88     char            * m_pRespBufEnd;
  89     char            * m_pRespBufPos;
  90 
  91     char            * m_pRespHeaderBuf;
  92     char            * m_pRespHeaderBufEnd;
  93     char            * m_pRespHeaderBufPos;
  94 
  95 
  96     struct iovec    * m_pIovec;
  97     struct iovec    * m_pIovecEnd;
  98     struct iovec    * m_pIovecCur;
  99     struct iovec    * m_pIovecToWrite;
 100 
 101     struct lsapi_packet_header      * m_respPktHeaderEnd;
 102 
 103     struct lsapi_req_header         * m_pHeader;
 104     struct LSAPI_key_value_pair     * m_pEnvList;
 105     struct LSAPI_key_value_pair     * m_pSpecialEnvList;
 106     int                               m_envListSize;
 107     int                               m_specialEnvListSize;
 108 
 109     struct lsapi_http_header_index  * m_pHeaderIndex;
 110     struct lsapi_header_offset      * m_pUnknownHeader;
 111 
 112     char            * m_pScriptFile;
 113     char            * m_pScriptName;
 114     char            * m_pQueryString;
 115     char            * m_pHttpHeader;
 116     char            * m_pRequestMethod;
 117     int               m_totalLen;
 118     int               m_reqState;
 119     off_t             m_reqBodyLen;
 120     off_t             m_reqBodyRead;
 121     int               m_bufProcessed;
 122     int               m_bufRead;
 123 
 124     struct lsapi_packet_header        m_respPktHeader[5];
 125 
 126     struct lsapi_resp_header          m_respHeader;
 127     short                             m_respHeaderLen[LSAPI_MAX_RESP_HEADERS];
 128     void            * m_pAppData;
 129 
 130 }LSAPI_Request;
 131 
 132 extern LSAPI_Request g_req;
 133 
 134 
 135 /* return: >0 continue, ==0 stop, -1 failed  */
 136 typedef int (*LSAPI_CB_EnvHandler )( const char * pKey, int keyLen,
 137                 const char * pValue, int valLen, void * arg );
 138 
 139 
 140 int LSAPI_Init(void);
 141 
 142 void LSAPI_Stop(void);
 143 
 144 int LSAPI_Is_Listen_r( LSAPI_Request * pReq);
 145 
 146 int LSAPI_InitRequest( LSAPI_Request * pReq, int fd );
 147 
 148 int LSAPI_Accept_r( LSAPI_Request * pReq );
 149 
 150 void LSAPI_Reset_r( LSAPI_Request * pReq );
 151 
 152 int LSAPI_Finish_r( LSAPI_Request * pReq );
 153 
 154 int LSAPI_Release_r( LSAPI_Request * pReq );
 155 
 156 char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex );
 157 
 158 int LSAPI_ForeachHeader_r( LSAPI_Request * pReq,
 159             LSAPI_CB_EnvHandler fn, void * arg );
 160 
 161 int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
 162             LSAPI_CB_EnvHandler fn, void * arg );
 163 
 164 int LSAPI_ForeachEnv_r( LSAPI_Request * pReq,
 165             LSAPI_CB_EnvHandler fn, void * arg );
 166 
 167 int LSAPI_ForeachSpecialEnv_r( LSAPI_Request * pReq,
 168             LSAPI_CB_EnvHandler fn, void * arg );
 169 
 170 char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name );
 171 
 172 
 173 ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t len );
 174 
 175 int LSAPI_ReqBodyGetChar_r( LSAPI_Request * pReq );
 176 
 177 int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, int *getLF );
 178 
 179 
 180 int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq );
 181 
 182 ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len );
 183 
 184 ssize_t LSAPI_sendfile_r( LSAPI_Request * pReq, int fdIn, off_t* off, size_t size );
 185 
 186 ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t len );
 187 
 188 int LSAPI_Flush_r( LSAPI_Request * pReq );
 189 
 190 int LSAPI_AppendRespHeader_r( LSAPI_Request * pReq, const char * pBuf, int len );
 191 
 192 int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName,
 193                               const char * pHeaderValue );
 194 
 195 int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders,
 196                          const char * pBody, int bodyLen );
 197 
 198 static inline int LSAPI_SetRespStatus_r( LSAPI_Request * pReq, int code )
 199 {
 200     if ( !pReq )
 201         return -1;
 202     pReq->m_respHeader.m_respInfo.m_status = code;
 203     return 0;
 204 }
 205 
 206 static inline int LSAPI_SetAppData_r( LSAPI_Request * pReq, void * data )
 207 {
 208     if ( !pReq )
 209         return -1;
 210     pReq->m_pAppData = data;
 211     return 0;
 212 }
 213 
 214 static inline void * LSAPI_GetAppData_r( LSAPI_Request * pReq )
 215 {
 216     if ( !pReq )
 217         return NULL;
 218     return pReq->m_pAppData;
 219 }
 220 
 221 static inline char * LSAPI_GetQueryString_r( LSAPI_Request * pReq )
 222 {
 223     if ( pReq )
 224         return pReq->m_pQueryString;
 225     return NULL;
 226 }
 227 
 228 
 229 static inline char * LSAPI_GetScriptFileName_r( LSAPI_Request * pReq )
 230 {
 231     if ( pReq )
 232         return pReq->m_pScriptFile;
 233     return NULL;
 234 }
 235 
 236 
 237 static inline char * LSAPI_GetScriptName_r( LSAPI_Request * pReq )
 238 {
 239     if ( pReq )
 240         return pReq->m_pScriptName;
 241     return NULL;
 242 }
 243 
 244 
 245 static inline char * LSAPI_GetRequestMethod_r( LSAPI_Request * pReq)
 246 {
 247     if ( pReq )
 248         return pReq->m_pRequestMethod;
 249     return NULL;
 250 }
 251 
 252 
 253 
 254 static inline off_t LSAPI_GetReqBodyLen_r( LSAPI_Request * pReq )
 255 {
 256     if ( pReq )
 257         return pReq->m_reqBodyLen;
 258     return -1;
 259 }
 260 
 261 static inline off_t LSAPI_GetReqBodyRemain_r( LSAPI_Request * pReq )
 262 {
 263     if ( pReq )
 264         return pReq->m_reqBodyLen - pReq->m_reqBodyRead;
 265     return -1;
 266 }
 267 
 268 
 269 
 270 int LSAPI_Is_Listen(void);
 271 
 272 static inline int LSAPI_Accept( void )
 273 {   return LSAPI_Accept_r( &g_req );                        }
 274 
 275 static inline int LSAPI_Finish(void)
 276 {   return LSAPI_Finish_r( &g_req );                        }
 277 
 278 static inline char * LSAPI_GetHeader( int headerIndex )
 279 {   return LSAPI_GetHeader_r( &g_req, headerIndex );        }
 280 
 281 static inline int LSAPI_ForeachHeader( LSAPI_CB_EnvHandler fn, void * arg )
 282 {   return LSAPI_ForeachHeader_r( &g_req, fn, arg );        }
 283 
 284 static inline int LSAPI_ForeachOrgHeader(
 285             LSAPI_CB_EnvHandler fn, void * arg )
 286 {   return LSAPI_ForeachOrgHeader_r( &g_req, fn, arg );     }
 287 
 288 static inline int LSAPI_ForeachEnv( LSAPI_CB_EnvHandler fn, void * arg )
 289 {   return LSAPI_ForeachEnv_r( &g_req, fn, arg );           }
 290 
 291 static inline int LSAPI_ForeachSpecialEnv( LSAPI_CB_EnvHandler fn, void * arg )
 292 {   return LSAPI_ForeachSpecialEnv_r( &g_req, fn, arg );    }
 293 
 294 static inline char * LSAPI_GetEnv( const char * name )
 295 {   return LSAPI_GetEnv_r( &g_req, name );                  }
 296 
 297 static inline char * LSAPI_GetQueryString()
 298 {   return LSAPI_GetQueryString_r( &g_req );                }
 299 
 300 static inline char * LSAPI_GetScriptFileName()
 301 {   return LSAPI_GetScriptFileName_r( &g_req );             }
 302 
 303 static inline char * LSAPI_GetScriptName()
 304 {    return LSAPI_GetScriptName_r( &g_req );                }
 305 
 306 static inline char * LSAPI_GetRequestMethod()
 307 {   return LSAPI_GetRequestMethod_r( &g_req );              }
 308 
 309 static inline off_t LSAPI_GetReqBodyLen()
 310 {   return LSAPI_GetReqBodyLen_r( &g_req );                 }
 311 
 312 static inline off_t LSAPI_GetReqBodyRemain()
 313 {   return LSAPI_GetReqBodyRemain_r( &g_req );                 }
 314 
 315 static inline ssize_t LSAPI_ReadReqBody( char * pBuf, size_t len )
 316 {   return LSAPI_ReadReqBody_r( &g_req, pBuf, len );        }
 317 
 318 static inline int LSAPI_ReqBodyGetChar()
 319 {   return LSAPI_ReqBodyGetChar_r( &g_req );        }
 320 
 321 static inline int LSAPI_ReqBodyGetLine( char * pBuf, int len, int *getLF )
 322 {   return LSAPI_ReqBodyGetLine_r( &g_req, pBuf, len, getLF );        }
 323 
 324 
 325 
 326 static inline int LSAPI_FinalizeRespHeaders(void)
 327 {   return LSAPI_FinalizeRespHeaders_r( &g_req );           }
 328 
 329 static inline ssize_t LSAPI_Write( const char * pBuf, ssize_t len )
 330 {   return LSAPI_Write_r( &g_req, pBuf, len );              }
 331 
 332 static inline ssize_t LSAPI_sendfile( int fdIn, off_t* off, size_t size )
 333 {
 334     return LSAPI_sendfile_r(&g_req, fdIn, off, size );
 335 }
 336 
 337 static inline ssize_t LSAPI_Write_Stderr( const char * pBuf, ssize_t len )
 338 {   return LSAPI_Write_Stderr_r( &g_req, pBuf, len );       }
 339 
 340 static inline int LSAPI_Flush()
 341 {   return LSAPI_Flush_r( &g_req );                         }
 342 
 343 static inline int LSAPI_AppendRespHeader( char * pBuf, int len )
 344 {   return LSAPI_AppendRespHeader_r( &g_req, pBuf, len );   }
 345 
 346 static inline int LSAPI_SetRespStatus( int code )
 347 {   return LSAPI_SetRespStatus_r( &g_req, code );           }
 348 
 349 static inline int LSAPI_ErrResponse( int code, const char ** pRespHeaders, const char * pBody, int bodyLen )
 350 {   return LSAPI_ErrResponse_r( &g_req, code, pRespHeaders, pBody, bodyLen );   }
 351 
 352 int LSAPI_IsRunning(void);
 353 
 354 int LSAPI_CreateListenSock( const char * pBind, int backlog );
 355 
 356 typedef int (*fn_select_t)( int, fd_set *, fd_set *, fd_set *, struct timeval * );
 357 
 358 int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork );
 359 
 360 void LSAPI_Set_Server_fd( int fd );
 361 
 362 int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq );
 363 
 364 void LSAPI_Set_Max_Reqs( int reqs );
 365 
 366 void LSAPI_Set_Max_Idle( int secs );
 367 
 368 void LSAPI_Set_Max_Children( int maxChildren );
 369 
 370 void LSAPI_Set_Max_Idle_Children( int maxIdleChld );
 371 
 372 void LSAPI_Set_Server_Max_Idle_Secs( int serverMaxIdle );
 373 
 374 void LSAPI_Set_Max_Process_Time( int secs );
 375 
 376 int LSAPI_Init_Env_Parameters( fn_select_t fp );
 377 
 378 void LSAPI_Set_Slow_Req_Msecs( int msecs );
 379 
 380 int  LSAPI_Get_Slow_Req_Msecs( );
 381 
 382 int LSAPI_is_suEXEC_Daemon();
 383 
 384 #if defined (c_plusplus) || defined (__cplusplus)
 385 }
 386 #endif
 387 
 388 
 389 #endif
 390 
 391 
 392 
 393 
 394 
 395 
 396 

/* [<][>][^][v][top][bottom][index][help] */