Lines Matching refs:pReq
134 void Flush_RespBuf_r( LSAPI_Request * pReq );
378 static inline int allocateBuf( LSAPI_Request * pReq, int size ) in allocateBuf() argument
380 char * pBuf = (char *)realloc( pReq->m_pReqBuf, size ); in allocateBuf()
383 pReq->m_pReqBuf = pBuf; in allocateBuf()
384 pReq->m_reqBufSize = size; in allocateBuf()
385 pReq->m_pHeader = (struct lsapi_req_header *)pReq->m_pReqBuf; in allocateBuf()
392 static int allocateIovec( LSAPI_Request * pReq, int n ) in allocateIovec() argument
395 pReq->m_pIovec, sizeof(struct iovec) * n ); in allocateIovec()
398 pReq->m_pIovecToWrite = p + ( pReq->m_pIovecToWrite - pReq->m_pIovec ); in allocateIovec()
399 pReq->m_pIovecCur = p + ( pReq->m_pIovecCur - pReq->m_pIovec ); in allocateIovec()
400 pReq->m_pIovec = p; in allocateIovec()
401 pReq->m_pIovecEnd = p + n; in allocateIovec()
405 static int allocateRespHeaderBuf( LSAPI_Request * pReq, int size ) in allocateRespHeaderBuf() argument
407 char * p = (char *)realloc( pReq->m_pRespHeaderBuf, size ); in allocateRespHeaderBuf()
410 pReq->m_pRespHeaderBufPos = p + ( pReq->m_pRespHeaderBufPos - pReq->m_pRespHeaderBuf ); in allocateRespHeaderBuf()
411 pReq->m_pRespHeaderBuf = p; in allocateRespHeaderBuf()
412 pReq->m_pRespHeaderBufEnd = p + size; in allocateRespHeaderBuf()
517 static inline void fixEndian( LSAPI_Request * pReq ) in fixEndian() argument
519 struct lsapi_req_header *p= pReq->m_pHeader; in fixEndian()
531 static void fixHeaderIndexEndian( LSAPI_Request * pReq ) in fixHeaderIndexEndian() argument
536 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) in fixHeaderIndexEndian()
539 char * p = (char *)(&pReq->m_pHeaderIndex->m_headerLen[i]); in fixHeaderIndexEndian()
543 swapIntEndian( &pReq->m_pHeaderIndex->m_headerOff[i] ); in fixHeaderIndexEndian()
546 if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) in fixHeaderIndexEndian()
549 pCur = pReq->m_pUnknownHeader; in fixHeaderIndexEndian()
550 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in fixHeaderIndexEndian()
563 static int validateHeaders( LSAPI_Request * pReq ) in validateHeaders() argument
565 int totalLen = pReq->m_pHeader->m_httpHeaderLen; in validateHeaders()
569 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) in validateHeaders()
571 if (pReq->m_pHeaderIndex->m_headerOff[i] > totalLen in validateHeaders()
572 || pReq->m_pHeaderIndex->m_headerLen[i] in validateHeaders()
573 + pReq->m_pHeaderIndex->m_headerOff[i] > totalLen) in validateHeaders()
577 if (pReq->m_pHeader->m_cntUnknownHeaders > 0) in validateHeaders()
580 pCur = pReq->m_pUnknownHeader; in validateHeaders()
581 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in validateHeaders()
725 static int LSAPI_perror_r( LSAPI_Request * pReq, const char * pErr1, const char *pErr2 ) in LSAPI_perror_r() argument
729 if ( pReq ) in LSAPI_perror_r()
730 LSAPI_Write_Stderr_r( pReq, achError, n ); in LSAPI_perror_r()
736 static int lsapi_lve_error( LSAPI_Request * pReq ) in lsapi_lve_error() argument
755 LSAPI_ErrResponse_r( pReq, 508, headers, achBody, sizeof( achBody ) - 1 ); in lsapi_lve_error()
759 static int lsapi_enterLVE( LSAPI_Request * pReq, uid_t uid ) in lsapi_enterLVE() argument
770 LSAPI_perror_r(pReq, "LSAPI: lve_enter() failure, reached resource limit.", NULL ); in lsapi_enterLVE()
771 lsapi_lve_error( pReq ); in lsapi_enterLVE()
780 static int lsapi_jailLVE( LSAPI_Request * pReq, uid_t uid, struct passwd * pw ) in lsapi_jailLVE() argument
790 LSAPI_perror_r( pReq, "LSAPI: jail() failure.", NULL ); in lsapi_jailLVE()
826 static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * pChroot) in setUID_LVE() argument
834 if( lsapi_enterLVE( pReq, uid ) == -1 ) in setUID_LVE()
838 rv = lsapi_jailLVE( pReq, uid, pw ); in setUID_LVE()
864 LSAPI_perror_r(pReq, "LSAPI: setgid()", NULL); in setUID_LVE()
872 LSAPI_perror_r(pReq, "LSAPI: initgroups()", NULL); in setUID_LVE()
881 LSAPI_perror_r(pReq, "LSAPI: setgroups()", NULL); in setUID_LVE()
889 LSAPI_perror_r(pReq, "LSAPI: chroot()", NULL); in setUID_LVE()
896 LSAPI_perror_r(pReq, "LSAPI: setuid()", NULL); in setUID_LVE()
906 static int lsapi_suexec_auth( LSAPI_Request *pReq, in lsapi_suexec_auth() argument
925 static int lsapi_changeUGid( LSAPI_Request * pReq ) in lsapi_changeUGid() argument
940 i = pReq->m_pHeader->m_cntSpecialEnv - 1; in lsapi_changeUGid()
943 pEnv = pReq->m_pSpecialEnvList + i; in lsapi_changeUGid()
947 --pReq->m_pHeader->m_cntSpecialEnv; in lsapi_changeUGid()
952 --pReq->m_pHeader->m_cntSpecialEnv; in lsapi_changeUGid()
962 …if ( pEnv&& lsapi_suexec_auth( pReq, pAuth->pValue, pAuth->valLen, pEnv->pValue, pEnv->valLen ) ==… in lsapi_changeUGid()
988 if ( setUID_LVE( pReq, uid, gid, pChroot ) == -1 ) in lsapi_changeUGid()
999 static int parseContentLenFromHeader(LSAPI_Request * pReq) in parseContentLenFromHeader() argument
1001 const char * pContentLen = LSAPI_GetHeader_r( pReq, H_CONTENT_LENGTH ); in parseContentLenFromHeader()
1003 pReq->m_reqBodyLen = strtoll( pContentLen, NULL, 10 ); in parseContentLenFromHeader()
1008 static int parseRequest( LSAPI_Request * pReq, int totalLen ) in parseRequest() argument
1011 char * pBegin = pReq->m_pReqBuf + sizeof( struct lsapi_req_header ); in parseRequest()
1012 char * pEnd = pReq->m_pReqBuf + totalLen; in parseRequest()
1014 pReq->m_pHeader->m_pktHeader.m_flag & LSAPI_ENDIAN_BIT ) ); in parseRequest()
1017 fixEndian( pReq ); in parseRequest()
1019 if ( (pReq->m_specialEnvListSize < pReq->m_pHeader->m_cntSpecialEnv )&& in parseRequest()
1020 allocateEnvList( &pReq->m_pSpecialEnvList, in parseRequest()
1021 &pReq->m_specialEnvListSize, in parseRequest()
1022 pReq->m_pHeader->m_cntSpecialEnv ) == -1 ) in parseRequest()
1024 if ( (pReq->m_envListSize < pReq->m_pHeader->m_cntEnv )&& in parseRequest()
1025 allocateEnvList( &pReq->m_pEnvList, &pReq->m_envListSize, in parseRequest()
1026 pReq->m_pHeader->m_cntEnv ) == -1 ) in parseRequest()
1029 if ( parseEnv( pReq->m_pSpecialEnvList, in parseRequest()
1030 pReq->m_pHeader->m_cntSpecialEnv, in parseRequest()
1033 if ( parseEnv( pReq->m_pEnvList, pReq->m_pHeader->m_cntEnv, in parseRequest()
1036 if (pReq->m_pHeader->m_scriptFileOff < 0 in parseRequest()
1037 || pReq->m_pHeader->m_scriptFileOff >= totalLen in parseRequest()
1038 || pReq->m_pHeader->m_scriptNameOff < 0 in parseRequest()
1039 || pReq->m_pHeader->m_scriptNameOff >= totalLen in parseRequest()
1040 || pReq->m_pHeader->m_queryStringOff < 0 in parseRequest()
1041 || pReq->m_pHeader->m_queryStringOff >= totalLen in parseRequest()
1042 || pReq->m_pHeader->m_requestMethodOff < 0 in parseRequest()
1043 || pReq->m_pHeader->m_requestMethodOff >= totalLen) in parseRequest()
1048 pReq->m_pScriptFile = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptFileOff; in parseRequest()
1049 pReq->m_pScriptName = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptNameOff; in parseRequest()
1050 pReq->m_pQueryString = pReq->m_pReqBuf + pReq->m_pHeader->m_queryStringOff; in parseRequest()
1051 pReq->m_pRequestMethod = pReq->m_pReqBuf + pReq->m_pHeader->m_requestMethodOff; in parseRequest()
1053 pBegin = pReq->m_pReqBuf + (( pBegin - pReq->m_pReqBuf + 7 ) & (~0x7)); in parseRequest()
1054 pReq->m_pHeaderIndex = ( struct lsapi_http_header_index * )pBegin; in parseRequest()
1057 pReq->m_pUnknownHeader = (struct lsapi_header_offset *)pBegin; in parseRequest()
1059 pReq->m_pHeader->m_cntUnknownHeaders; in parseRequest()
1061 pReq->m_pHttpHeader = pBegin; in parseRequest()
1062 pBegin += pReq->m_pHeader->m_httpHeaderLen; in parseRequest()
1066 pBegin - pReq->m_pReqBuf ); in parseRequest()
1071 fixHeaderIndexEndian( pReq ); in parseRequest()
1074 if (validateHeaders(pReq) == -1) in parseRequest()
1080 pReq->m_reqBodyLen = pReq->m_pHeader->m_reqBodyLen; in parseRequest()
1081 if ( pReq->m_reqBodyLen == -2 ) in parseRequest()
1083 parseContentLenFromHeader(pReq); in parseRequest()
1171 static int readReq( LSAPI_Request * pReq ) in readReq() argument
1175 if ( !pReq ) in readReq()
1177 if ( pReq->m_reqBufSize < 8192 ) in readReq()
1179 if ( allocateBuf( pReq, 8192 ) == -1 ) in readReq()
1183 while ( pReq->m_bufRead < LSAPI_PACKET_HEADER_LEN ) in readReq()
1185 len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf, pReq->m_reqBufSize ); in readReq()
1188 pReq->m_bufRead += len; in readReq()
1190 pReq->m_reqState = LSAPI_ST_REQ_HEADER; in readReq()
1192 packetLen = verifyHeader( &pReq->m_pHeader->m_pktHeader, LSAPI_BEGIN_REQUEST ); in readReq()
1204 if ( packetLen + 1024 > pReq->m_reqBufSize ) in readReq()
1206 if ( allocateBuf( pReq, packetLen + 1024 ) == -1 ) in readReq()
1209 while( packetLen > pReq->m_bufRead ) in readReq()
1211 … len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, packetLen - pReq->m_bufRead ); in readReq()
1214 pReq->m_bufRead += len; in readReq()
1216 if ( parseRequest( pReq, packetLen ) < 0 ) in readReq()
1222 pReq->m_reqState = LSAPI_ST_REQ_BODY | LSAPI_ST_RESP_HEADER; in readReq()
1226 if ( lsapi_changeUGid( pReq ) ) in readReq()
1230 pReq->m_bufProcessed = packetLen; in readReq()
1234 return notify_req_received( pReq->m_fd ); in readReq()
1277 int LSAPI_InitRequest( LSAPI_Request * pReq, int fd ) in LSAPI_InitRequest() argument
1280 if ( !pReq ) in LSAPI_InitRequest()
1282 memset( pReq, 0, sizeof( LSAPI_Request ) ); in LSAPI_InitRequest()
1283 if ( allocateIovec( pReq, 16 ) == -1 ) in LSAPI_InitRequest()
1285 pReq->m_pRespBuf = pReq->m_pRespBufPos = (char *)malloc( LSAPI_RESP_BUF_SIZE ); in LSAPI_InitRequest()
1286 if ( !pReq->m_pRespBuf ) in LSAPI_InitRequest()
1288 pReq->m_pRespBufEnd = pReq->m_pRespBuf + LSAPI_RESP_BUF_SIZE; in LSAPI_InitRequest()
1289 pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1; in LSAPI_InitRequest()
1290 pReq->m_respPktHeaderEnd = &pReq->m_respPktHeader[5]; in LSAPI_InitRequest()
1291 if ( allocateRespHeaderBuf( pReq, LSAPI_INIT_RESP_HEADER_LEN ) == -1 ) in LSAPI_InitRequest()
1303 pReq->m_fdListen = -1; in LSAPI_InitRequest()
1304 pReq->m_fd = fd; in LSAPI_InitRequest()
1308 pReq->m_fdListen = fd; in LSAPI_InitRequest()
1309 pReq->m_fd = -1; in LSAPI_InitRequest()
1320 int LSAPI_Is_Listen_r( LSAPI_Request * pReq) in LSAPI_Is_Listen_r() argument
1322 return pReq->m_fdListen != -1; in LSAPI_Is_Listen_r()
1327 int LSAPI_Accept_r( LSAPI_Request * pReq ) in LSAPI_Accept_r() argument
1333 if ( !pReq ) in LSAPI_Accept_r()
1335 if ( LSAPI_Finish_r( pReq ) == -1 ) in LSAPI_Accept_r()
1337 lsapi_set_nblock( pReq->m_fdListen , 0 ); in LSAPI_Accept_r()
1340 if ( pReq->m_fd == -1 ) in LSAPI_Accept_r()
1342 if ( pReq->m_fdListen != -1) in LSAPI_Accept_r()
1345 pReq->m_fd = accept( pReq->m_fdListen, in LSAPI_Accept_r()
1347 if ( pReq->m_fd == -1 ) in LSAPI_Accept_r()
1356 lsapi_set_nblock( pReq->m_fd , 0 ); in LSAPI_Accept_r()
1359 setsockopt(pReq->m_fd, IPPROTO_TCP, TCP_NODELAY, in LSAPI_Accept_r()
1365 if ( notify_req_received( pReq->m_fd ) == -1 ) in LSAPI_Accept_r()
1372 if ( !readReq( pReq ) ) in LSAPI_Accept_r()
1375 lsapi_close( pReq->m_fd ); in LSAPI_Accept_r()
1376 pReq->m_fd = -1; in LSAPI_Accept_r()
1377 LSAPI_Reset_r( pReq ); in LSAPI_Accept_r()
1385 int LSAPI_Finish_r( LSAPI_Request * pReq ) in LSAPI_Finish_r() argument
1388 if ( !pReq ) in LSAPI_Finish_r()
1390 if (pReq->m_reqState) in LSAPI_Finish_r()
1392 if ( pReq->m_fd != -1 ) in LSAPI_Finish_r()
1394 if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) in LSAPI_Finish_r()
1396 LSAPI_FinalizeRespHeaders_r( pReq ); in LSAPI_Finish_r()
1398 if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) in LSAPI_Finish_r()
1400 Flush_RespBuf_r( pReq ); in LSAPI_Finish_r()
1403 pReq->m_pIovecCur->iov_base = (void *)&finish; in LSAPI_Finish_r()
1404 pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN; in LSAPI_Finish_r()
1405 pReq->m_totalLen += LSAPI_PACKET_HEADER_LEN; in LSAPI_Finish_r()
1406 ++pReq->m_pIovecCur; in LSAPI_Finish_r()
1407 LSAPI_Flush_r( pReq ); in LSAPI_Finish_r()
1409 LSAPI_Reset_r( pReq ); in LSAPI_Finish_r()
1415 void LSAPI_Reset_r( LSAPI_Request * pReq ) in LSAPI_Reset_r() argument
1417 pReq->m_pRespBufPos = pReq->m_pRespBuf; in LSAPI_Reset_r()
1418 pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1; in LSAPI_Reset_r()
1419 pReq->m_pRespHeaderBufPos = pReq->m_pRespHeaderBuf; in LSAPI_Reset_r()
1421 memset( &pReq->m_pHeaderIndex, 0, in LSAPI_Reset_r()
1422 (char *)(pReq->m_respHeaderLen) - (char *)&pReq->m_pHeaderIndex ); in LSAPI_Reset_r()
1426 int LSAPI_Release_r( LSAPI_Request * pReq ) in LSAPI_Release_r() argument
1428 if ( pReq->m_pReqBuf ) in LSAPI_Release_r()
1429 free( pReq->m_pReqBuf ); in LSAPI_Release_r()
1430 if ( pReq->m_pSpecialEnvList ) in LSAPI_Release_r()
1431 free( pReq->m_pSpecialEnvList ); in LSAPI_Release_r()
1432 if ( pReq->m_pEnvList ) in LSAPI_Release_r()
1433 free( pReq->m_pEnvList ); in LSAPI_Release_r()
1434 if ( pReq->m_pRespHeaderBuf ) in LSAPI_Release_r()
1435 free( pReq->m_pRespHeaderBuf ); in LSAPI_Release_r()
1440 char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex ) in LSAPI_GetHeader_r() argument
1443 if ( !pReq || ((unsigned int)headerIndex > H_TRANSFER_ENCODING) ) in LSAPI_GetHeader_r()
1445 off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ]; in LSAPI_GetHeader_r()
1448 if ( *(pReq->m_pHttpHeader + off in LSAPI_GetHeader_r()
1449 + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) ) in LSAPI_GetHeader_r()
1451 *( pReq->m_pHttpHeader + off in LSAPI_GetHeader_r()
1452 + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0; in LSAPI_GetHeader_r()
1454 return pReq->m_pHttpHeader + off; in LSAPI_GetHeader_r()
1457 static int readBodyToReqBuf( LSAPI_Request * pReq ) in readBodyToReqBuf() argument
1460 ssize_t len = pReq->m_bufRead - pReq->m_bufProcessed; in readBodyToReqBuf()
1463 pReq->m_bufRead = pReq->m_bufProcessed = pReq->m_pHeader->m_pktHeader.m_packetLen.m_iLen; in readBodyToReqBuf()
1465 bodyLeft = pReq->m_reqBodyLen - pReq->m_reqBodyRead; in readBodyToReqBuf()
1466 len = pReq->m_reqBufSize - pReq->m_bufRead; in readBodyToReqBuf()
1472 len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, len ); in readBodyToReqBuf()
1474 pReq->m_bufRead += len; in readBodyToReqBuf()
1479 int LSAPI_ReqBodyGetChar_r( LSAPI_Request * pReq ) in LSAPI_ReqBodyGetChar_r() argument
1481 if (!pReq || (pReq->m_fd ==-1) ) in LSAPI_ReqBodyGetChar_r()
1483 if ( pReq->m_bufProcessed >= pReq->m_bufRead ) in LSAPI_ReqBodyGetChar_r()
1485 if ( readBodyToReqBuf( pReq ) <= 0 ) in LSAPI_ReqBodyGetChar_r()
1488 ++pReq->m_reqBodyRead; in LSAPI_ReqBodyGetChar_r()
1489 return (unsigned char)*(pReq->m_pReqBuf + pReq->m_bufProcessed++); in LSAPI_ReqBodyGetChar_r()
1494 int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, int *getLF ) in LSAPI_ReqBodyGetLine_r() argument
1502 if (!pReq || (pReq->m_fd ==-1) ||( !pBuf )||(bufLen < 0 )|| !getLF ) in LSAPI_ReqBodyGetLine_r()
1508 len = pReq->m_bufRead - pReq->m_bufProcessed; in LSAPI_ReqBodyGetLine_r()
1511 if ( (len = readBodyToReqBuf( pReq )) <= 0 ) in LSAPI_ReqBodyGetLine_r()
1519 pCur = pReq->m_pReqBuf + pReq->m_bufProcessed; in LSAPI_ReqBodyGetLine_r()
1525 pReq->m_bufProcessed += len; in LSAPI_ReqBodyGetLine_r()
1527 pReq->m_reqBodyRead += len; in LSAPI_ReqBodyGetLine_r()
1541 ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen ) in LSAPI_ReadReqBody_r() argument
1546 if (!pReq || (pReq->m_fd ==-1) || ( !pBuf )||(bufLen < 0 )) in LSAPI_ReadReqBody_r()
1549 total = pReq->m_reqBodyLen - pReq->m_reqBodyRead; in LSAPI_ReadReqBody_r()
1557 len = pReq->m_bufRead - pReq->m_bufProcessed; in LSAPI_ReadReqBody_r()
1562 memmove( pBuf, pReq->m_pReqBuf + pReq->m_bufProcessed, len ); in LSAPI_ReadReqBody_r()
1563 pReq->m_bufProcessed += len; in LSAPI_ReadReqBody_r()
1570 len = lsapi_read( pReq->m_fd, pBuf, bufLen ); in LSAPI_ReadReqBody_r()
1584 pReq->m_reqBodyRead += total; in LSAPI_ReadReqBody_r()
1590 ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) in LSAPI_Write_r() argument
1600 if ( !pReq || !pBuf || (pReq->m_fd == -1) ) in LSAPI_Write_r()
1602 if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) in LSAPI_Write_r()
1604 LSAPI_FinalizeRespHeaders_r( pReq ); in LSAPI_Write_r()
1616 pReq->m_reqState |= LSAPI_ST_RESP_BODY; in LSAPI_Write_r()
1618 if ( (len - skip) < pReq->m_pRespBufEnd - pReq->m_pRespBufPos ) in LSAPI_Write_r()
1620 memmove( pReq->m_pRespBufPos, pBuf + skip, len - skip ); in LSAPI_Write_r()
1621 pReq->m_pRespBufPos += len - skip; in LSAPI_Write_r()
1626 pHeader = pReq->m_respPktHeader; in LSAPI_Write_r()
1629 bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf; in LSAPI_Write_r()
1642 pReq->m_totalLen += packetLen + LSAPI_PACKET_HEADER_LEN; in LSAPI_Write_r()
1644 pReq->m_pIovecCur->iov_base = (void *)pHeader; in LSAPI_Write_r()
1645 pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN; in LSAPI_Write_r()
1646 ++pReq->m_pIovecCur; in LSAPI_Write_r()
1650 pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf; in LSAPI_Write_r()
1651 pReq->m_pIovecCur->iov_len = bufLen; in LSAPI_Write_r()
1652 pReq->m_pRespBufPos = pReq->m_pRespBuf; in LSAPI_Write_r()
1653 ++pReq->m_pIovecCur; in LSAPI_Write_r()
1657 pReq->m_pIovecCur->iov_base = (void *)p; in LSAPI_Write_r()
1658 pReq->m_pIovecCur->iov_len = toWrite; in LSAPI_Write_r()
1659 ++pReq->m_pIovecCur; in LSAPI_Write_r()
1662 if ( pHeader >= pReq->m_respPktHeaderEnd - 1) in LSAPI_Write_r()
1664 if ( LSAPI_Flush_r( pReq ) == -1 ) in LSAPI_Write_r()
1666 pHeader = pReq->m_respPktHeader; in LSAPI_Write_r()
1669 if ( pHeader != pReq->m_respPktHeader ) in LSAPI_Write_r()
1670 if ( LSAPI_Flush_r( pReq ) == -1 ) in LSAPI_Write_r()
1740 ssize_t LSAPI_sendfile_r( LSAPI_Request * pReq, int fdIn, off_t* off, size_t size ) in LSAPI_sendfile_r() argument
1742 struct lsapi_packet_header * pHeader = pReq->m_respPktHeader; in LSAPI_sendfile_r()
1743 if ( !pReq || (pReq->m_fd == -1) || fdIn == -1 ) in LSAPI_sendfile_r()
1745 if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) in LSAPI_sendfile_r()
1747 LSAPI_FinalizeRespHeaders_r( pReq ); in LSAPI_sendfile_r()
1749 pReq->m_reqState |= LSAPI_ST_RESP_BODY; in LSAPI_sendfile_r()
1751 LSAPI_Flush_r(pReq); in LSAPI_sendfile_r()
1757 …if (write(pReq->m_fd, (const char *) pHeader, LSAPI_PACKET_HEADER_LEN ) != LSAPI_PACKET_HEADER_LE… in LSAPI_sendfile_r()
1760 return gsendfile( pReq->m_fd, fdIn, off, size ); in LSAPI_sendfile_r()
1764 void Flush_RespBuf_r( LSAPI_Request * pReq ) in Flush_RespBuf_r() argument
1766 struct lsapi_packet_header * pHeader = pReq->m_respPktHeader; in Flush_RespBuf_r()
1767 int bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf; in Flush_RespBuf_r()
1768 pReq->m_reqState |= LSAPI_ST_RESP_BODY; in Flush_RespBuf_r()
1771 pReq->m_totalLen += bufLen + LSAPI_PACKET_HEADER_LEN; in Flush_RespBuf_r()
1773 pReq->m_pIovecCur->iov_base = (void *)pHeader; in Flush_RespBuf_r()
1774 pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN; in Flush_RespBuf_r()
1775 ++pReq->m_pIovecCur; in Flush_RespBuf_r()
1779 pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf; in Flush_RespBuf_r()
1780 pReq->m_pIovecCur->iov_len = bufLen; in Flush_RespBuf_r()
1781 pReq->m_pRespBufPos = pReq->m_pRespBuf; in Flush_RespBuf_r()
1782 ++pReq->m_pIovecCur; in Flush_RespBuf_r()
1790 int LSAPI_Flush_r( LSAPI_Request * pReq ) in LSAPI_Flush_r() argument
1794 if ( !pReq ) in LSAPI_Flush_r()
1796 n = pReq->m_pIovecCur - pReq->m_pIovecToWrite; in LSAPI_Flush_r()
1797 if (( 0 == n )&&( pReq->m_pRespBufPos == pReq->m_pRespBuf )) in LSAPI_Flush_r()
1799 if ( pReq->m_fd == -1 ) in LSAPI_Flush_r()
1801 pReq->m_pRespBufPos = pReq->m_pRespBuf; in LSAPI_Flush_r()
1802 pReq->m_totalLen = 0; in LSAPI_Flush_r()
1803 pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec; in LSAPI_Flush_r()
1806 if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) in LSAPI_Flush_r()
1808 LSAPI_FinalizeRespHeaders_r( pReq ); in LSAPI_Flush_r()
1810 if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) in LSAPI_Flush_r()
1812 Flush_RespBuf_r( pReq ); in LSAPI_Flush_r()
1815 n = pReq->m_pIovecCur - pReq->m_pIovecToWrite; in LSAPI_Flush_r()
1819 ret = lsapi_writev( pReq->m_fd, &pReq->m_pIovecToWrite, in LSAPI_Flush_r()
1820 n, pReq->m_totalLen ); in LSAPI_Flush_r()
1821 if ( ret < pReq->m_totalLen ) in LSAPI_Flush_r()
1823 lsapi_close( pReq->m_fd ); in LSAPI_Flush_r()
1824 pReq->m_fd = -1; in LSAPI_Flush_r()
1827 pReq->m_totalLen = 0; in LSAPI_Flush_r()
1828 pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec; in LSAPI_Flush_r()
1834 ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) in LSAPI_Write_Stderr_r() argument
1845 if ( !pReq ) in LSAPI_Write_Stderr_r()
1847 if (( pReq->m_fd == -1 )||(pReq->m_fd == pReq->m_fdListen )) in LSAPI_Write_Stderr_r()
1849 if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) in LSAPI_Write_Stderr_r()
1851 LSAPI_Flush_r( pReq ); in LSAPI_Write_Stderr_r()
1875 ret = lsapi_writev( pReq->m_fd, &pIov, in LSAPI_Write_Stderr_r()
1879 lsapi_close( pReq->m_fd ); in LSAPI_Write_Stderr_r()
1880 pReq->m_fd = -1; in LSAPI_Write_Stderr_r()
1887 static char * GetHeaderVar( LSAPI_Request * pReq, const char * name ) in GetHeaderVar() argument
1893 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) in GetHeaderVar()
1897 pValue = pReq->m_pHttpHeader in GetHeaderVar()
1898 + pReq->m_pHeaderIndex->m_headerOff[i]; in GetHeaderVar()
1899 if ( *(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) != '\0') in GetHeaderVar()
1901 *(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) = '\0'; in GetHeaderVar()
1907 if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) in GetHeaderVar()
1914 pCur = pReq->m_pUnknownHeader; in GetHeaderVar()
1915 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in GetHeaderVar()
1918 pKey = pReq->m_pHttpHeader + pCur->nameOff; in GetHeaderVar()
1932 pValue = pReq->m_pHttpHeader + pCur->valueOff; in GetHeaderVar()
1947 char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name ) in LSAPI_GetEnv_r() argument
1949 struct LSAPI_key_value_pair * pBegin = pReq->m_pEnvList; in LSAPI_GetEnv_r()
1950 struct LSAPI_key_value_pair * pEnd = pBegin + pReq->m_pHeader->m_cntEnv; in LSAPI_GetEnv_r()
1951 if ( !pReq || !name ) in LSAPI_GetEnv_r()
1955 return GetHeaderVar( pReq, name ); in LSAPI_GetEnv_r()
1980 int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, in LSAPI_ForeachOrgHeader_r() argument
1990 if ( !pReq || !fn ) in LSAPI_ForeachOrgHeader_r()
1993 if ( !pReq->m_pHeaderIndex ) in LSAPI_ForeachOrgHeader_r()
1998 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) in LSAPI_ForeachOrgHeader_r()
2000 len = pReq->m_pHeaderIndex->m_headerLen[i]; in LSAPI_ForeachOrgHeader_r()
2001 pValue = pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i]; in LSAPI_ForeachOrgHeader_r()
2015 if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) in LSAPI_ForeachOrgHeader_r()
2020 pCur = pReq->m_pUnknownHeader; in LSAPI_ForeachOrgHeader_r()
2021 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in LSAPI_ForeachOrgHeader_r()
2024 pKey = pReq->m_pHttpHeader + pCur->nameOff; in LSAPI_ForeachOrgHeader_r()
2028 pValue = pReq->m_pHttpHeader + pCur->valueOff; in LSAPI_ForeachOrgHeader_r()
2057 int LSAPI_ForeachHeader_r( LSAPI_Request * pReq, in LSAPI_ForeachHeader_r() argument
2065 if ( !pReq || !fn ) in LSAPI_ForeachHeader_r()
2069 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) in LSAPI_ForeachHeader_r()
2071 len = pReq->m_pHeaderIndex->m_headerLen[i]; in LSAPI_ForeachHeader_r()
2072 pValue = pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i]; in LSAPI_ForeachHeader_r()
2081 if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) in LSAPI_ForeachHeader_r()
2089 pCur = pReq->m_pUnknownHeader; in LSAPI_ForeachHeader_r()
2090 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in LSAPI_ForeachHeader_r()
2093 pKey = pReq->m_pHttpHeader + pCur->nameOff; in LSAPI_ForeachHeader_r()
2112 pValue = pReq->m_pHttpHeader + pCur->valueOff; in LSAPI_ForeachHeader_r()
2121 return count + pReq->m_pHeader->m_cntUnknownHeaders; in LSAPI_ForeachHeader_r()
2145 int LSAPI_ForeachEnv_r( LSAPI_Request * pReq, in LSAPI_ForeachEnv_r() argument
2148 if ( !pReq || !fn ) in LSAPI_ForeachEnv_r()
2150 if ( pReq->m_pHeader->m_cntEnv > 0 ) in LSAPI_ForeachEnv_r()
2152 return EnvForeach( pReq->m_pEnvList, pReq->m_pHeader->m_cntEnv, in LSAPI_ForeachEnv_r()
2160 int LSAPI_ForeachSpecialEnv_r( LSAPI_Request * pReq, in LSAPI_ForeachSpecialEnv_r() argument
2163 if ( !pReq || !fn ) in LSAPI_ForeachSpecialEnv_r()
2165 if ( pReq->m_pHeader->m_cntSpecialEnv > 0 ) in LSAPI_ForeachSpecialEnv_r()
2167 return EnvForeach( pReq->m_pSpecialEnvList, in LSAPI_ForeachSpecialEnv_r()
2168 pReq->m_pHeader->m_cntSpecialEnv, in LSAPI_ForeachSpecialEnv_r()
2177 int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq ) in LSAPI_FinalizeRespHeaders_r() argument
2179 if ( !pReq || !pReq->m_pIovec ) in LSAPI_FinalizeRespHeaders_r()
2181 if ( !( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) ) in LSAPI_FinalizeRespHeaders_r()
2183 pReq->m_reqState &= ~LSAPI_ST_RESP_HEADER; in LSAPI_FinalizeRespHeaders_r()
2184 if ( pReq->m_pRespHeaderBufPos > pReq->m_pRespHeaderBuf ) in LSAPI_FinalizeRespHeaders_r()
2186 pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespHeaderBuf; in LSAPI_FinalizeRespHeaders_r()
2187 pReq->m_pIovecCur->iov_len = pReq->m_pRespHeaderBufPos - pReq->m_pRespHeaderBuf; in LSAPI_FinalizeRespHeaders_r()
2188 pReq->m_totalLen += pReq->m_pIovecCur->iov_len; in LSAPI_FinalizeRespHeaders_r()
2189 ++pReq->m_pIovecCur; in LSAPI_FinalizeRespHeaders_r()
2192 pReq->m_pIovec->iov_len = sizeof( struct lsapi_resp_header) in LSAPI_FinalizeRespHeaders_r()
2193 + pReq->m_respHeader.m_respInfo.m_cntHeaders * sizeof( short ); in LSAPI_FinalizeRespHeaders_r()
2194 pReq->m_totalLen += pReq->m_pIovec->iov_len; in LSAPI_FinalizeRespHeaders_r()
2196 lsapi_buildPacketHeader( &pReq->m_respHeader.m_pktHeader, in LSAPI_FinalizeRespHeaders_r()
2197 LSAPI_RESP_HEADER, pReq->m_totalLen ); in LSAPI_FinalizeRespHeaders_r()
2198 pReq->m_pIovec->iov_base = (void *)&pReq->m_respHeader; in LSAPI_FinalizeRespHeaders_r()
2199 pReq->m_pIovecToWrite = pReq->m_pIovec; in LSAPI_FinalizeRespHeaders_r()
2204 int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName, in LSAPI_AppendRespHeader2_r() argument
2208 if ( !pReq || !pHeaderName || !pHeaderValue ) in LSAPI_AppendRespHeader2_r()
2210 if ( pReq->m_reqState & LSAPI_ST_RESP_BODY ) in LSAPI_AppendRespHeader2_r()
2212 if ( pReq->m_respHeader.m_respInfo.m_cntHeaders >= LSAPI_MAX_RESP_HEADERS ) in LSAPI_AppendRespHeader2_r()
2240 if ( pReq->m_pRespHeaderBufPos + len + 1 > pReq->m_pRespHeaderBufEnd ) in LSAPI_AppendRespHeader2_r()
2242 int newlen = pReq->m_pRespHeaderBufPos + len + 4096 - pReq->m_pRespHeaderBuf; in LSAPI_AppendRespHeader2_r()
2244 if ( allocateRespHeaderBuf( pReq, newlen ) == -1 ) in LSAPI_AppendRespHeader2_r()
2247 memmove( pReq->m_pRespHeaderBufPos, pHeaderName, nameLen ); in LSAPI_AppendRespHeader2_r()
2248 pReq->m_pRespHeaderBufPos += nameLen; in LSAPI_AppendRespHeader2_r()
2249 *pReq->m_pRespHeaderBufPos++ = ':'; in LSAPI_AppendRespHeader2_r()
2250 memmove( pReq->m_pRespHeaderBufPos, pHeaderValue, valLen ); in LSAPI_AppendRespHeader2_r()
2251 pReq->m_pRespHeaderBufPos += valLen; in LSAPI_AppendRespHeader2_r()
2252 *pReq->m_pRespHeaderBufPos++ = 0; in LSAPI_AppendRespHeader2_r()
2254 pReq->m_respHeaderLen[pReq->m_respHeader.m_respInfo.m_cntHeaders] = len; in LSAPI_AppendRespHeader2_r()
2255 ++pReq->m_respHeader.m_respInfo.m_cntHeaders; in LSAPI_AppendRespHeader2_r()
2261 int LSAPI_AppendRespHeader_r( LSAPI_Request * pReq, const char * pBuf, int len ) in LSAPI_AppendRespHeader_r() argument
2263 if ( !pReq || !pBuf || len <= 0 || len > LSAPI_RESP_HTTP_HEADER_MAX ) in LSAPI_AppendRespHeader_r()
2265 if ( pReq->m_reqState & LSAPI_ST_RESP_BODY ) in LSAPI_AppendRespHeader_r()
2267 if ( pReq->m_respHeader.m_respInfo.m_cntHeaders >= LSAPI_MAX_RESP_HEADERS ) in LSAPI_AppendRespHeader_r()
2279 if ( pReq->m_pRespHeaderBufPos + len + 1 > pReq->m_pRespHeaderBufEnd ) in LSAPI_AppendRespHeader_r()
2281 int newlen = pReq->m_pRespHeaderBufPos + len + 4096 - pReq->m_pRespHeaderBuf; in LSAPI_AppendRespHeader_r()
2283 if ( allocateRespHeaderBuf( pReq, newlen ) == -1 ) in LSAPI_AppendRespHeader_r()
2286 memmove( pReq->m_pRespHeaderBufPos, pBuf, len ); in LSAPI_AppendRespHeader_r()
2287 pReq->m_pRespHeaderBufPos += len; in LSAPI_AppendRespHeader_r()
2288 *pReq->m_pRespHeaderBufPos++ = 0; in LSAPI_AppendRespHeader_r()
2290 pReq->m_respHeaderLen[pReq->m_respHeader.m_respInfo.m_cntHeaders] = len; in LSAPI_AppendRespHeader_r()
2291 ++pReq->m_respHeader.m_respInfo.m_cntHeaders; in LSAPI_AppendRespHeader_r()
2765 static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Request * pReq ) in lsapi_prefork_server_accept() argument
2863 pReq->m_fd = lsapi_accept( pServer->m_fd ); in lsapi_prefork_server_accept()
2864 if ( pReq->m_fd != -1 ) in lsapi_prefork_server_accept()
2888 lsapi_set_nblock( pReq->m_fd, 0 ); in lsapi_prefork_server_accept()
2889 if ( pReq->m_fdListen != -1 ) in lsapi_prefork_server_accept()
2891 close( pReq->m_fdListen ); in lsapi_prefork_server_accept()
2892 pReq->m_fdListen = -1; in lsapi_prefork_server_accept()
2901 lsapi_notify_pid( pReq->m_fd ); in lsapi_prefork_server_accept()
2921 close( pReq->m_fd ); in lsapi_prefork_server_accept()
2922 pReq->m_fd = -1; in lsapi_prefork_server_accept()
2948 int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) in LSAPI_Prefork_Accept_r() argument
2956 LSAPI_Finish_r( pReq ); in LSAPI_Prefork_Accept_r()
2962 if ( lsapi_prefork_server_accept( g_prefork_server, pReq ) == -1 ) in LSAPI_Prefork_Accept_r()
2976 if ( pReq->m_fd != -1 ) in LSAPI_Prefork_Accept_r()
2978 fd = pReq->m_fd; in LSAPI_Prefork_Accept_r()
2980 else if ( pReq->m_fdListen != -1 ) in LSAPI_Prefork_Accept_r()
2981 fd = pReq->m_fdListen; in LSAPI_Prefork_Accept_r()
3021 if ( fd == pReq->m_fdListen ) in LSAPI_Prefork_Accept_r()
3023 pReq->m_fd = lsapi_accept( pReq->m_fdListen ); in LSAPI_Prefork_Accept_r()
3024 if ( pReq->m_fd != -1 ) in LSAPI_Prefork_Accept_r()
3026 fd = pReq->m_fd; in LSAPI_Prefork_Accept_r()
3031 close( pReq->m_fdListen ); in LSAPI_Prefork_Accept_r()
3032 pReq->m_fdListen = -1; in LSAPI_Prefork_Accept_r()
3035 if ( notify_req_received( pReq->m_fd ) == -1 ) in LSAPI_Prefork_Accept_r()
3051 if ( !readReq( pReq ) ) in LSAPI_Prefork_Accept_r()
3063 lsapi_close( pReq->m_fd ); in LSAPI_Prefork_Accept_r()
3064 pReq->m_fd = -1; in LSAPI_Prefork_Accept_r()
3065 LSAPI_Reset_r( pReq ); in LSAPI_Prefork_Accept_r()
3320 int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders, in LSAPI_ErrResponse_r() argument
3323 LSAPI_SetRespStatus_r( pReq, code ); in LSAPI_ErrResponse_r()
3328 LSAPI_AppendRespHeader_r( pReq, *pRespHeaders, strlen( *pRespHeaders ) ); in LSAPI_ErrResponse_r()
3334 LSAPI_Write_r( pReq, pBody, bodyLen ); in LSAPI_ErrResponse_r()
3336 LSAPI_Finish_r( pReq ); in LSAPI_ErrResponse_r()