Back to index

php5  5.3.10
lsapilib.h
Go to the documentation of this file.
00001 
00002 /*
00003    +----------------------------------------------------------------------+
00004    | PHP Version 5                                                        |
00005    +----------------------------------------------------------------------+
00006    | Copyright (c) 1997-2007 The PHP Group                                |
00007    +----------------------------------------------------------------------+
00008    | This source file is subject to version 3.01 of the PHP license,      |
00009    | that is bundled with this package in the file LICENSE, and is        |
00010    | available at through the world-wide-web at the following url:        |
00011    | http://www.php.net/license/3_01.txt.                                 |
00012    | If you did not receive a copy of the PHP license and are unable to   |
00013    | obtain it through the world-wide-web, please send a note to          |
00014    | license@php.net so we can mail you a copy immediately.               |
00015    +----------------------------------------------------------------------+
00016    | Author: George Wang <gwang@litespeedtech.com>                        |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /*
00021 Copyright (c) 2007, Lite Speed Technologies Inc.
00022 All rights reserved.
00023 
00024 Redistribution and use in source and binary forms, with or without
00025 modification, are permitted provided that the following conditions are
00026 met: 
00027 
00028     * Redistributions of source code must retain the above copyright
00029       notice, this list of conditions and the following disclaimer. 
00030     * Redistributions in binary form must reproduce the above
00031       copyright notice, this list of conditions and the following
00032       disclaimer in the documentation and/or other materials provided
00033       with the distribution. 
00034     * Neither the name of the Lite Speed Technologies Inc nor the
00035       names of its contributors may be used to endorse or promote
00036       products derived from this software without specific prior
00037       written permission.  
00038 
00039 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00040 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00041 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00042 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00043 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00044 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00045 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00046 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00047 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00048 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00049 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00050 */
00051 
00052 
00053 
00054 #ifndef  _LSAPILIB_H_
00055 #define  _LSAPILIB_H_
00056 
00057 #if defined (c_plusplus) || defined (__cplusplus)
00058 extern "C" {
00059 #endif
00060 
00061 #include <stddef.h>
00062 #include <lsapidef.h>
00063 
00064 #include <sys/time.h>
00065 #include <sys/types.h>
00066 
00067 struct LSAPI_key_value_pair
00068 {
00069     char * pKey;
00070     char * pValue;
00071     int    keyLen;
00072     int    valLen;
00073 };
00074 
00075 
00076 #define LSAPI_MAX_RESP_HEADERS  100
00077 
00078 typedef struct lsapi_request
00079 {
00080     int               m_fdListen;
00081     int               m_fd;
00082 
00083     long              m_lLastActive;
00084     long              m_lReqBegin;
00085 
00086     char            * m_pReqBuf;
00087     int               m_reqBufSize;
00088     
00089     char            * m_pRespBuf;
00090     char            * m_pRespBufEnd;
00091     char            * m_pRespBufPos;
00092 
00093     char            * m_pRespHeaderBuf;
00094     char            * m_pRespHeaderBufEnd;
00095     char            * m_pRespHeaderBufPos;
00096 
00097 
00098     struct iovec    * m_pIovec;
00099     struct iovec    * m_pIovecEnd;
00100     struct iovec    * m_pIovecCur;
00101     struct iovec    * m_pIovecToWrite;    
00102 
00103     struct lsapi_packet_header      * m_respPktHeaderEnd;
00104 
00105     struct lsapi_req_header         * m_pHeader;
00106     struct LSAPI_key_value_pair     * m_pEnvList;
00107     struct LSAPI_key_value_pair     * m_pSpecialEnvList;
00108     int                               m_envListSize;
00109     int                               m_specialEnvListSize;
00110 
00111     struct lsapi_http_header_index  * m_pHeaderIndex;
00112     struct lsapi_header_offset      * m_pUnknownHeader;
00113     
00114     char            * m_pScriptFile;
00115     char            * m_pScriptName;
00116     char            * m_pQueryString;
00117     char            * m_pHttpHeader;
00118     char            * m_pRequestMethod;
00119     int               m_totalLen;
00120     int               m_reqState;
00121     int               m_reqBodyRead;
00122     int               m_bufProcessed;
00123     int               m_bufRead;
00124     
00125     struct lsapi_packet_header        m_respPktHeader[5];
00126     
00127     struct lsapi_resp_header          m_respHeader;
00128     short                             m_respHeaderLen[LSAPI_MAX_RESP_HEADERS];
00129 
00130 }LSAPI_Request;
00131 
00132 extern LSAPI_Request g_req;
00133 
00134 
00135 /* return: >0 continue, ==0 stop, -1 failed  */
00136 typedef int (*LSAPI_CB_EnvHandler )( const char * pKey, int keyLen,
00137                 const char * pValue, int valLen, void * arg );
00138 
00139 
00140 int LSAPI_Init(void);
00141 
00142 void LSAPI_Stop(void);
00143 
00144 int LSAPI_Is_Listen_r( LSAPI_Request * pReq);
00145 
00146 int LSAPI_InitRequest( LSAPI_Request * pReq, int fd );
00147 
00148 int LSAPI_Accept_r( LSAPI_Request * pReq );
00149 
00150 void LSAPI_Reset_r( LSAPI_Request * pReq );
00151 
00152 int LSAPI_Finish_r( LSAPI_Request * pReq );
00153 
00154 int LSAPI_Release_r( LSAPI_Request * pReq );
00155 
00156 char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex );
00157 
00158 int LSAPI_ForeachHeader_r( LSAPI_Request * pReq,
00159             LSAPI_CB_EnvHandler fn, void * arg );
00160 
00161 int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
00162             LSAPI_CB_EnvHandler fn, void * arg );
00163 
00164 int LSAPI_ForeachEnv_r( LSAPI_Request * pReq,
00165             LSAPI_CB_EnvHandler fn, void * arg );
00166 
00167 int LSAPI_ForeachSpecialEnv_r( LSAPI_Request * pReq,
00168             LSAPI_CB_EnvHandler fn, void * arg );
00169 
00170 char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name );
00171             
00172 
00173 int LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, int len );
00174 
00175 int LSAPI_ReqBodyGetChar_r( LSAPI_Request * pReq );
00176 
00177 int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, int bufLen, int *getLF );
00178 
00179 
00180 int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq );
00181 
00182 int LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, int len );
00183 
00184 int LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, int len );
00185 
00186 int LSAPI_Flush_r( LSAPI_Request * pReq );
00187 
00188 int LSAPI_AppendRespHeader_r( LSAPI_Request * pHeader, char * pBuf, int len );
00189 
00190 static inline int LSAPI_SetRespStatus_r( LSAPI_Request * pReq, int code )
00191 {
00192     if ( !pReq )
00193         return -1;
00194     pReq->m_respHeader.m_respInfo.m_status = code;
00195     return 0;
00196 }
00197 
00198 static inline char * LSAPI_GetQueryString_r( LSAPI_Request * pReq )
00199 {
00200     if ( pReq )
00201         return pReq->m_pQueryString;
00202     return NULL;
00203 }
00204 
00205 
00206 static inline char * LSAPI_GetScriptFileName_r( LSAPI_Request * pReq )
00207 {
00208     if ( pReq )
00209         return pReq->m_pScriptFile;
00210     return NULL;
00211 }
00212 
00213 
00214 static inline char * LSAPI_GetScriptName_r( LSAPI_Request * pReq )
00215 {
00216     if ( pReq )
00217         return pReq->m_pScriptName;
00218     return NULL;
00219 }
00220 
00221 
00222 static inline char * LSAPI_GetRequestMethod_r( LSAPI_Request * pReq)
00223 {
00224     if ( pReq )
00225         return pReq->m_pRequestMethod;
00226     return NULL;
00227 }
00228 
00229 
00230 
00231 static inline int  LSAPI_GetReqBodyLen_r( LSAPI_Request * pReq )
00232 {
00233     if ( pReq )
00234         return pReq->m_pHeader->m_reqBodyLen;
00235     return -1;
00236 }
00237 
00238 static inline int LSAPI_GetReqBodyRemain_r( LSAPI_Request * pReq )
00239 {
00240     if ( pReq )
00241         return pReq->m_pHeader->m_reqBodyLen - pReq->m_reqBodyRead;
00242     return -1;
00243 }
00244 
00245 
00246 int LSAPI_Is_Listen(void);
00247 
00248 static inline int LSAPI_Accept( void )
00249 {   return LSAPI_Accept_r( &g_req );                        }
00250 
00251 static inline int LSAPI_Finish(void)
00252 {   return LSAPI_Finish_r( &g_req );                        }
00253 
00254 static inline char * LSAPI_GetHeader( int headerIndex )
00255 {   return LSAPI_GetHeader_r( &g_req, headerIndex );        }
00256 
00257 static inline int LSAPI_ForeachHeader( LSAPI_CB_EnvHandler fn, void * arg )
00258 {   return LSAPI_ForeachHeader_r( &g_req, fn, arg );        }
00259 
00260 static inline int LSAPI_ForeachOrgHeader(
00261             LSAPI_CB_EnvHandler fn, void * arg )
00262 {   return LSAPI_ForeachOrgHeader_r( &g_req, fn, arg );     }
00263 
00264 static inline int LSAPI_ForeachEnv( LSAPI_CB_EnvHandler fn, void * arg )
00265 {   return LSAPI_ForeachEnv_r( &g_req, fn, arg );           }
00266 
00267 static inline int LSAPI_ForeachSpecialEnv( LSAPI_CB_EnvHandler fn, void * arg )
00268 {   return LSAPI_ForeachSpecialEnv_r( &g_req, fn, arg );    }
00269 
00270 static inline char * LSAPI_GetEnv( const char * name )
00271 {   return LSAPI_GetEnv_r( &g_req, name );                  }
00272 
00273 static inline char * LSAPI_GetQueryString()
00274 {   return LSAPI_GetQueryString_r( &g_req );                }
00275 
00276 static inline char * LSAPI_GetScriptFileName()
00277 {   return LSAPI_GetScriptFileName_r( &g_req );             }
00278 
00279 static inline char * LSAPI_GetScriptName()
00280 {    return LSAPI_GetScriptName_r( &g_req );                }
00281 
00282 static inline char * LSAPI_GetRequestMethod()
00283 {   return LSAPI_GetRequestMethod_r( &g_req );              }
00284 
00285 static inline int LSAPI_GetReqBodyLen()
00286 {   return LSAPI_GetReqBodyLen_r( &g_req );                 }
00287 
00288 static inline int LSAPI_GetReqBodyRemain()
00289 {   return LSAPI_GetReqBodyRemain_r( &g_req );                 }
00290 
00291 static inline int LSAPI_ReadReqBody( char * pBuf, int len )
00292 {   return LSAPI_ReadReqBody_r( &g_req, pBuf, len );        }
00293 
00294 static inline int LSAPI_ReqBodyGetChar()
00295 {   return LSAPI_ReqBodyGetChar_r( &g_req );        }
00296 
00297 static inline int LSAPI_ReqBodyGetLine( char * pBuf, int len, int *getLF )
00298 {   return LSAPI_ReqBodyGetLine_r( &g_req, pBuf, len, getLF );        }
00299 
00300 
00301 
00302 static inline int LSAPI_FinalizeRespHeaders(void)
00303 {   return LSAPI_FinalizeRespHeaders_r( &g_req );           }
00304 
00305 static inline int LSAPI_Write( const char * pBuf, int len )
00306 {   return LSAPI_Write_r( &g_req, pBuf, len );              }
00307 
00308 static inline int LSAPI_Write_Stderr( const char * pBuf, int len )
00309 {   return LSAPI_Write_Stderr_r( &g_req, pBuf, len );       }
00310 
00311 static inline int LSAPI_Flush()
00312 {   return LSAPI_Flush_r( &g_req );                         }
00313 
00314 static inline int LSAPI_AppendRespHeader( char * pBuf, int len )
00315 {   return LSAPI_AppendRespHeader_r( &g_req, pBuf, len );   }
00316 
00317 static inline int LSAPI_SetRespStatus( int code )
00318 {   return LSAPI_SetRespStatus_r( &g_req, code );           }
00319 
00320 int LSAPI_IsRunning(void);
00321 
00322 int LSAPI_CreateListenSock( const char * pBind, int backlog );
00323 
00324 typedef int (*fn_select_t)( int, fd_set *, fd_set *, fd_set *, struct timeval * );
00325 
00326 int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork );
00327 
00328 void LSAPI_Set_Server_fd( int fd );
00329 
00330 int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq );
00331 
00332 void LSAPI_Set_Max_Reqs( int reqs );
00333 
00334 void LSAPI_Set_Max_Idle( int secs );
00335 
00336 void LSAPI_Set_Max_Children( int maxChildren );
00337 
00338 void LSAPI_Set_Max_Idle_Children( int maxIdleChld );
00339 
00340 void LSAPI_Set_Server_Max_Idle_Secs( int serverMaxIdle );
00341 
00342 void LSAPI_Set_Max_Process_Time( int secs );
00343 
00344 void LSAPI_Init_Env_Parameters( fn_select_t fp );
00345 
00346 void LSAPI_Set_Slow_Req_Msecs( int msecs );
00347 
00348 int  LSAPI_Get_Slow_Req_Msecs( );
00349 
00350 
00351 #if defined (c_plusplus) || defined (__cplusplus)
00352 }
00353 #endif
00354 
00355 
00356 #endif
00357 
00358 
00359 
00360 
00361 
00362 
00363