Lines Matching refs:pReq

92 void Flush_RespBuf_r( LSAPI_Request * pReq );
268 static inline int allocateBuf( LSAPI_Request * pReq, int size ) in allocateBuf() argument
270 char * pBuf = (char *)realloc( pReq->m_pReqBuf, size ); in allocateBuf()
272 pReq->m_pReqBuf = pBuf; in allocateBuf()
273 pReq->m_reqBufSize = size; in allocateBuf()
274 pReq->m_pHeader = (struct lsapi_req_header *)pReq->m_pReqBuf; in allocateBuf()
281 static int allocateIovec( LSAPI_Request * pReq, int n ) in allocateIovec() argument
284 pReq->m_pIovec, sizeof(struct iovec) * n ); in allocateIovec()
288 pReq->m_pIovecToWrite = p + ( pReq->m_pIovecToWrite - pReq->m_pIovec ); in allocateIovec()
289 pReq->m_pIovecCur = p + ( pReq->m_pIovecCur - pReq->m_pIovec ); in allocateIovec()
290 pReq->m_pIovec = p; in allocateIovec()
291 pReq->m_pIovecEnd = p + n; in allocateIovec()
295 static int allocateRespHeaderBuf( LSAPI_Request * pReq, int size ) in allocateRespHeaderBuf() argument
297 char * p = (char *)realloc( pReq->m_pRespHeaderBuf, size ); in allocateRespHeaderBuf()
301 pReq->m_pRespHeaderBufPos = p + ( pReq->m_pRespHeaderBufPos - pReq->m_pRespHeaderBuf ); in allocateRespHeaderBuf()
302 pReq->m_pRespHeaderBuf = p; in allocateRespHeaderBuf()
303 pReq->m_pRespHeaderBufEnd = p + size; in allocateRespHeaderBuf()
414 static inline void fixEndian( LSAPI_Request * pReq ) in fixEndian() argument
416 struct lsapi_req_header *p= pReq->m_pHeader; in fixEndian()
428 static void fixHeaderIndexEndian( LSAPI_Request * pReq ) in fixHeaderIndexEndian() argument
432 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) { in fixHeaderIndexEndian()
434 char * p = (char *)(&pReq->m_pHeaderIndex->m_headerLen[i]); in fixHeaderIndexEndian()
438 swapIntEndian( &pReq->m_pHeaderIndex->m_headerOff[i] ); in fixHeaderIndexEndian()
441 if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) { in fixHeaderIndexEndian()
443 pCur = pReq->m_pUnknownHeader; in fixHeaderIndexEndian()
444 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in fixHeaderIndexEndian()
455 static int parseRequest( LSAPI_Request * pReq, int totalLen ) in parseRequest() argument
458 char * pBegin = pReq->m_pReqBuf + sizeof( struct lsapi_req_header ); in parseRequest()
459 char * pEnd = pReq->m_pReqBuf + totalLen; in parseRequest()
461 pReq->m_pHeader->m_pktHeader.m_flag & LSAPI_ENDIAN_BIT ) ); in parseRequest()
463 fixEndian( pReq ); in parseRequest()
465 if ( (pReq->m_specialEnvListSize < pReq->m_pHeader->m_cntSpecialEnv )&& in parseRequest()
466 allocateEnvList( &pReq->m_pSpecialEnvList, in parseRequest()
467 &pReq->m_specialEnvListSize, in parseRequest()
468 pReq->m_pHeader->m_cntSpecialEnv ) == -1 ) { in parseRequest()
471 if ( (pReq->m_envListSize < pReq->m_pHeader->m_cntEnv )&& in parseRequest()
472 allocateEnvList( &pReq->m_pEnvList, &pReq->m_envListSize, in parseRequest()
473 pReq->m_pHeader->m_cntEnv ) == -1 ) { in parseRequest()
476 if ( parseEnv( pReq->m_pSpecialEnvList, in parseRequest()
477 pReq->m_pHeader->m_cntSpecialEnv, in parseRequest()
481 if ( parseEnv( pReq->m_pEnvList, pReq->m_pHeader->m_cntEnv, in parseRequest()
485 pReq->m_pScriptFile = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptFileOff; in parseRequest()
486 pReq->m_pScriptName = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptNameOff; in parseRequest()
487 pReq->m_pQueryString = pReq->m_pReqBuf + pReq->m_pHeader->m_queryStringOff; in parseRequest()
488 pReq->m_pRequestMethod = pReq->m_pReqBuf + pReq->m_pHeader->m_requestMethodOff; in parseRequest()
490 pBegin = pReq->m_pReqBuf + (( pBegin - pReq->m_pReqBuf + 7 ) & (~0x7)); in parseRequest()
491 pReq->m_pHeaderIndex = ( struct lsapi_http_header_index * )pBegin; in parseRequest()
494 pReq->m_pUnknownHeader = (struct lsapi_header_offset *)pBegin; in parseRequest()
496 pReq->m_pHeader->m_cntUnknownHeaders; in parseRequest()
498 pReq->m_pHttpHeader = pBegin; in parseRequest()
499 pBegin += pReq->m_pHeader->m_httpHeaderLen; in parseRequest()
505 fixHeaderIndexEndian( pReq ); in parseRequest()
525 static int readReq( LSAPI_Request * pReq ) in readReq() argument
529 if ( !pReq ) { in readReq()
532 if ( pReq->m_reqBufSize < 8192 ) { in readReq()
533 if ( allocateBuf( pReq, 8192 ) == -1 ) { in readReq()
538 while ( pReq->m_bufRead < LSAPI_PACKET_HEADER_LEN ) { in readReq()
539 len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf, pReq->m_reqBufSize ); in readReq()
543 pReq->m_bufRead += len; in readReq()
545 pReq->m_reqState = LSAPI_ST_REQ_HEADER; in readReq()
547 packetLen = verifyHeader( &pReq->m_pHeader->m_pktHeader, LSAPI_BEGIN_REQUEST ); in readReq()
555 if ( packetLen + 1024 > pReq->m_reqBufSize ) { in readReq()
556 if ( allocateBuf( pReq, packetLen + 1024 ) == -1 ) { in readReq()
560 while( packetLen > pReq->m_bufRead ) { in readReq()
561 … len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, packetLen - pReq->m_bufRead ); in readReq()
565 pReq->m_bufRead += len; in readReq()
567 if ( parseRequest( pReq, packetLen ) < 0 ) { in readReq()
570 pReq->m_bufProcessed = packetLen; in readReq()
571 pReq->m_reqState = LSAPI_ST_REQ_BODY | LSAPI_ST_RESP_HEADER; in readReq()
574 return notify_req_received( pReq->m_fd ); in readReq()
613 int LSAPI_InitRequest( LSAPI_Request * pReq, int fd ) in LSAPI_InitRequest() argument
615 if ( !pReq ) { in LSAPI_InitRequest()
618 memset( pReq, 0, sizeof( LSAPI_Request ) ); in LSAPI_InitRequest()
619 if ( allocateIovec( pReq, 16 ) == -1 ) { in LSAPI_InitRequest()
622 pReq->m_pRespBuf = pReq->m_pRespBufPos = (char *)malloc( LSAPI_RESP_BUF_SIZE ); in LSAPI_InitRequest()
623 if ( !pReq->m_pRespBuf ) { in LSAPI_InitRequest()
626 pReq->m_pRespBufEnd = pReq->m_pRespBuf + LSAPI_RESP_BUF_SIZE; in LSAPI_InitRequest()
627 pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1; in LSAPI_InitRequest()
628 pReq->m_respPktHeaderEnd = &pReq->m_respPktHeader[5]; in LSAPI_InitRequest()
629 if ( allocateRespHeaderBuf( pReq, LSAPI_INIT_RESP_HEADER_LEN ) == -1 ) { in LSAPI_InitRequest()
634 pReq->m_fdListen = -1; in LSAPI_InitRequest()
635 pReq->m_fd = fd; in LSAPI_InitRequest()
637 pReq->m_fdListen = fd; in LSAPI_InitRequest()
638 pReq->m_fd = -1; in LSAPI_InitRequest()
649 int LSAPI_Is_Listen_r( LSAPI_Request * pReq) in LSAPI_Is_Listen_r() argument
651 return pReq->m_fdListen != -1; in LSAPI_Is_Listen_r()
656 int LSAPI_Accept_r( LSAPI_Request * pReq ) in LSAPI_Accept_r() argument
662 if ( !pReq ) { in LSAPI_Accept_r()
665 if ( LSAPI_Finish_r( pReq ) == -1 ) { in LSAPI_Accept_r()
669 if ( pReq->m_fd == -1 ) { in LSAPI_Accept_r()
670 if ( pReq->m_fdListen != -1) { in LSAPI_Accept_r()
672 pReq->m_fd = accept( pReq->m_fdListen, in LSAPI_Accept_r()
674 if ( pReq->m_fd == -1 ) { in LSAPI_Accept_r()
681 lsapi_set_nblock( pReq->m_fd , 0 ); in LSAPI_Accept_r()
683 setsockopt(pReq->m_fd, IPPROTO_TCP, TCP_NODELAY, in LSAPI_Accept_r()
688 return notify_req_received( pReq->m_fd ); in LSAPI_Accept_r()
695 if ( !readReq( pReq ) ) { in LSAPI_Accept_r()
698 lsapi_close( pReq->m_fd ); in LSAPI_Accept_r()
699 pReq->m_fd = -1; in LSAPI_Accept_r()
700 LSAPI_Reset_r( pReq ); in LSAPI_Accept_r()
708 int LSAPI_Finish_r( LSAPI_Request * pReq ) in LSAPI_Finish_r() argument
711 if ( !pReq ) { in LSAPI_Finish_r()
714 if (pReq->m_reqState) { in LSAPI_Finish_r()
715 if ( pReq->m_fd != -1 ) { in LSAPI_Finish_r()
716 if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) { in LSAPI_Finish_r()
717 LSAPI_FinalizeRespHeaders_r( pReq ); in LSAPI_Finish_r()
719 if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) { in LSAPI_Finish_r()
720 Flush_RespBuf_r( pReq ); in LSAPI_Finish_r()
723 pReq->m_pIovecCur->iov_base = (void *)&finish; in LSAPI_Finish_r()
724 pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN; in LSAPI_Finish_r()
725 pReq->m_totalLen += LSAPI_PACKET_HEADER_LEN; in LSAPI_Finish_r()
726 ++pReq->m_pIovecCur; in LSAPI_Finish_r()
727 LSAPI_Flush_r( pReq ); in LSAPI_Finish_r()
729 LSAPI_Reset_r( pReq ); in LSAPI_Finish_r()
735 void LSAPI_Reset_r( LSAPI_Request * pReq ) in LSAPI_Reset_r() argument
737 pReq->m_pRespBufPos = pReq->m_pRespBuf; in LSAPI_Reset_r()
738 pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1; in LSAPI_Reset_r()
739 pReq->m_pRespHeaderBufPos = pReq->m_pRespHeaderBuf; in LSAPI_Reset_r()
741 memset( &pReq->m_pHeaderIndex, 0, in LSAPI_Reset_r()
742 (char *)(pReq->m_respHeaderLen) - (char *)&pReq->m_pHeaderIndex ); in LSAPI_Reset_r()
746 int LSAPI_Release_r( LSAPI_Request * pReq ) in LSAPI_Release_r() argument
748 if ( pReq->m_pReqBuf ) { in LSAPI_Release_r()
749 free( pReq->m_pReqBuf ); in LSAPI_Release_r()
751 if ( pReq->m_pSpecialEnvList ) { in LSAPI_Release_r()
752 free( pReq->m_pSpecialEnvList ); in LSAPI_Release_r()
754 if ( pReq->m_pEnvList ) { in LSAPI_Release_r()
755 free( pReq->m_pEnvList ); in LSAPI_Release_r()
757 if ( pReq->m_pRespHeaderBuf ) { in LSAPI_Release_r()
758 free( pReq->m_pRespHeaderBuf ); in LSAPI_Release_r()
764 char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex ) in LSAPI_GetHeader_r() argument
767 if ( !pReq || ((unsigned int)headerIndex > H_TRANSFER_ENCODING) ) { in LSAPI_GetHeader_r()
770 off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ]; in LSAPI_GetHeader_r()
774 if ( *(pReq->m_pHttpHeader + off + in LSAPI_GetHeader_r()
775 pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) ) { in LSAPI_GetHeader_r()
776 *( pReq->m_pHttpHeader + off + in LSAPI_GetHeader_r()
777 pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0; in LSAPI_GetHeader_r()
779 return pReq->m_pHttpHeader + off; in LSAPI_GetHeader_r()
782 static int readBodyToReqBuf( LSAPI_Request * pReq ) in readBodyToReqBuf() argument
785 int len = pReq->m_bufRead - pReq->m_bufProcessed; in readBodyToReqBuf()
789 pReq->m_bufRead = pReq->m_bufProcessed = pReq->m_pHeader->m_pktHeader.m_packetLen.m_iLen; in readBodyToReqBuf()
791 bodyLeft = pReq->m_pHeader->m_reqBodyLen - pReq->m_reqBodyRead; in readBodyToReqBuf()
792 len = pReq->m_reqBufSize - pReq->m_bufRead; in readBodyToReqBuf()
799 len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, len ); in readBodyToReqBuf()
801 pReq->m_bufRead += len; in readBodyToReqBuf()
807 int LSAPI_ReqBodyGetChar_r( LSAPI_Request * pReq ) in LSAPI_ReqBodyGetChar_r() argument
809 if (!pReq || (pReq->m_fd ==-1) ) { in LSAPI_ReqBodyGetChar_r()
812 if ( pReq->m_bufProcessed >= pReq->m_bufRead ) { in LSAPI_ReqBodyGetChar_r()
813 if ( readBodyToReqBuf( pReq ) <= 0 ) { in LSAPI_ReqBodyGetChar_r()
817 ++pReq->m_reqBodyRead; in LSAPI_ReqBodyGetChar_r()
818 return (unsigned char)*(pReq->m_pReqBuf + pReq->m_bufProcessed++); in LSAPI_ReqBodyGetChar_r()
823 int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, int bufLen, int *getLF ) in LSAPI_ReqBodyGetLine_r() argument
831 if (!pReq || (pReq->m_fd ==-1) ||( !pBuf )||(bufLen < 0 )|| !getLF ) { in LSAPI_ReqBodyGetLine_r()
837 len = pReq->m_bufRead - pReq->m_bufProcessed; in LSAPI_ReqBodyGetLine_r()
839 if ( (len = readBodyToReqBuf( pReq )) <= 0 ) { in LSAPI_ReqBodyGetLine_r()
847 pCur = pReq->m_pReqBuf + pReq->m_bufProcessed; in LSAPI_ReqBodyGetLine_r()
854 pReq->m_bufProcessed += len; in LSAPI_ReqBodyGetLine_r()
856 pReq->m_reqBodyRead += len; in LSAPI_ReqBodyGetLine_r()
869 int LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, int bufLen ) in LSAPI_ReadReqBody_r() argument
874 if (!pReq || (pReq->m_fd ==-1) || ( !pBuf )||(bufLen < 0 )) { in LSAPI_ReadReqBody_r()
877 total = pReq->m_pHeader->m_reqBodyLen - pReq->m_reqBodyRead; in LSAPI_ReadReqBody_r()
887 len = pReq->m_bufRead - pReq->m_bufProcessed; in LSAPI_ReadReqBody_r()
892 memmove( pBuf, pReq->m_pReqBuf + pReq->m_bufProcessed, len ); in LSAPI_ReadReqBody_r()
893 pReq->m_bufProcessed += len; in LSAPI_ReadReqBody_r()
899 len = lsapi_read( pReq->m_fd, pBuf, bufLen ); in LSAPI_ReadReqBody_r()
913 pReq->m_reqBodyRead += total; in LSAPI_ReadReqBody_r()
919 int LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, int len ) in LSAPI_Write_r() argument
928 if ( !pReq || !pBuf || (pReq->m_fd == -1) ) { in LSAPI_Write_r()
931 if ( len < pReq->m_pRespBufEnd - pReq->m_pRespBufPos ) { in LSAPI_Write_r()
932 memmove( pReq->m_pRespBufPos, pBuf, len ); in LSAPI_Write_r()
933 pReq->m_pRespBufPos += len; in LSAPI_Write_r()
937 if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) { in LSAPI_Write_r()
938 LSAPI_FinalizeRespHeaders_r( pReq ); in LSAPI_Write_r()
940 pReq->m_reqState |= LSAPI_ST_RESP_BODY; in LSAPI_Write_r()
942 pHeader = pReq->m_respPktHeader; in LSAPI_Write_r()
945 bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf; in LSAPI_Write_r()
956 pReq->m_totalLen += packetLen + LSAPI_PACKET_HEADER_LEN; in LSAPI_Write_r()
958 pReq->m_pIovecCur->iov_base = (void *)pHeader; in LSAPI_Write_r()
959 pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN; in LSAPI_Write_r()
960 ++pReq->m_pIovecCur; in LSAPI_Write_r()
963 pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf; in LSAPI_Write_r()
964 pReq->m_pIovecCur->iov_len = bufLen; in LSAPI_Write_r()
965 pReq->m_pRespBufPos = pReq->m_pRespBuf; in LSAPI_Write_r()
966 ++pReq->m_pIovecCur; in LSAPI_Write_r()
970 pReq->m_pIovecCur->iov_base = (void *)p; in LSAPI_Write_r()
971 pReq->m_pIovecCur->iov_len = toWrite; in LSAPI_Write_r()
972 ++pReq->m_pIovecCur; in LSAPI_Write_r()
975 if ( pHeader >= pReq->m_respPktHeaderEnd - 1) { in LSAPI_Write_r()
976 if ( LSAPI_Flush_r( pReq ) == -1 ) { in LSAPI_Write_r()
979 pHeader = pReq->m_respPktHeader; in LSAPI_Write_r()
982 if ( pHeader != pReq->m_respPktHeader ) { in LSAPI_Write_r()
983 if ( LSAPI_Flush_r( pReq ) == -1 ) { in LSAPI_Write_r()
990 void Flush_RespBuf_r( LSAPI_Request * pReq ) in Flush_RespBuf_r() argument
992 struct lsapi_packet_header * pHeader = pReq->m_respPktHeader; in Flush_RespBuf_r()
993 int bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf; in Flush_RespBuf_r()
994 pReq->m_reqState |= LSAPI_ST_RESP_BODY; in Flush_RespBuf_r()
997 pReq->m_totalLen += bufLen + LSAPI_PACKET_HEADER_LEN; in Flush_RespBuf_r()
999 pReq->m_pIovecCur->iov_base = (void *)pHeader; in Flush_RespBuf_r()
1000 pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN; in Flush_RespBuf_r()
1001 ++pReq->m_pIovecCur; in Flush_RespBuf_r()
1004 pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf; in Flush_RespBuf_r()
1005 pReq->m_pIovecCur->iov_len = bufLen; in Flush_RespBuf_r()
1006 pReq->m_pRespBufPos = pReq->m_pRespBuf; in Flush_RespBuf_r()
1007 ++pReq->m_pIovecCur; in Flush_RespBuf_r()
1015 int LSAPI_Flush_r( LSAPI_Request * pReq ) in LSAPI_Flush_r() argument
1019 if ( !pReq ) { in LSAPI_Flush_r()
1022 n = pReq->m_pIovecCur - pReq->m_pIovecToWrite; in LSAPI_Flush_r()
1023 if (( 0 == n )&&( pReq->m_pRespBufPos == pReq->m_pRespBuf )) { in LSAPI_Flush_r()
1026 if ( pReq->m_fd == -1 ) { in LSAPI_Flush_r()
1027 pReq->m_pRespBufPos = pReq->m_pRespBuf; in LSAPI_Flush_r()
1028 pReq->m_totalLen = 0; in LSAPI_Flush_r()
1029 pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec; in LSAPI_Flush_r()
1032 if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) { in LSAPI_Flush_r()
1033 LSAPI_FinalizeRespHeaders_r( pReq ); in LSAPI_Flush_r()
1035 if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) { in LSAPI_Flush_r()
1036 Flush_RespBuf_r( pReq ); in LSAPI_Flush_r()
1039 n = pReq->m_pIovecCur - pReq->m_pIovecToWrite; in LSAPI_Flush_r()
1042 ret = lsapi_writev( pReq->m_fd, &pReq->m_pIovecToWrite, in LSAPI_Flush_r()
1043 n, pReq->m_totalLen ); in LSAPI_Flush_r()
1044 if ( ret < pReq->m_totalLen ) { in LSAPI_Flush_r()
1045 lsapi_close( pReq->m_fd ); in LSAPI_Flush_r()
1046 pReq->m_fd = -1; in LSAPI_Flush_r()
1049 pReq->m_totalLen = 0; in LSAPI_Flush_r()
1050 pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec; in LSAPI_Flush_r()
1056 int LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, int len ) in LSAPI_Write_Stderr_r() argument
1067 if ( !pReq ) { in LSAPI_Write_Stderr_r()
1070 if (( pReq->m_fd == -1 )||(pReq->m_fd == pReq->m_fdListen )) { in LSAPI_Write_Stderr_r()
1073 if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) { in LSAPI_Write_Stderr_r()
1074 LSAPI_Flush_r( pReq ); in LSAPI_Write_Stderr_r()
1096 ret = lsapi_writev( pReq->m_fd, &pIov, in LSAPI_Write_Stderr_r()
1099 lsapi_close( pReq->m_fd ); in LSAPI_Write_Stderr_r()
1100 pReq->m_fd = -1; in LSAPI_Write_Stderr_r()
1107 static char * GetHeaderVar( LSAPI_Request * pReq, const char * name ) in GetHeaderVar() argument
1111 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) { in GetHeaderVar()
1113 return pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i]; in GetHeaderVar()
1117 if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) { in GetHeaderVar()
1123 pCur = pReq->m_pUnknownHeader; in GetHeaderVar()
1124 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in GetHeaderVar()
1126 pKey = pReq->m_pHttpHeader + pCur->nameOff; in GetHeaderVar()
1139 return pReq->m_pHttpHeader + pCur->valueOff; in GetHeaderVar()
1148 char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name ) in LSAPI_GetEnv_r() argument
1150 struct LSAPI_key_value_pair * pBegin = pReq->m_pEnvList; in LSAPI_GetEnv_r()
1151 struct LSAPI_key_value_pair * pEnd = pBegin + pReq->m_pHeader->m_cntEnv; in LSAPI_GetEnv_r()
1152 if ( !pReq || !name ) { in LSAPI_GetEnv_r()
1156 return GetHeaderVar( pReq, name ); in LSAPI_GetEnv_r()
1167 int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, in LSAPI_ForeachOrgHeader_r() argument
1175 if ( !pReq || !fn ) { in LSAPI_ForeachOrgHeader_r()
1179 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) { in LSAPI_ForeachOrgHeader_r()
1180 len = pReq->m_pHeaderIndex->m_headerLen[i]; in LSAPI_ForeachOrgHeader_r()
1181 pValue = pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i]; in LSAPI_ForeachOrgHeader_r()
1191 if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) { in LSAPI_ForeachOrgHeader_r()
1195 pCur = pReq->m_pUnknownHeader; in LSAPI_ForeachOrgHeader_r()
1196 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in LSAPI_ForeachOrgHeader_r()
1198 pKey = pReq->m_pHttpHeader + pCur->nameOff; in LSAPI_ForeachOrgHeader_r()
1201 pValue = pReq->m_pHttpHeader + pCur->valueOff; in LSAPI_ForeachOrgHeader_r()
1211 return count + pReq->m_pHeader->m_cntUnknownHeaders; in LSAPI_ForeachOrgHeader_r()
1216 int LSAPI_ForeachHeader_r( LSAPI_Request * pReq, in LSAPI_ForeachHeader_r() argument
1224 if ( !pReq || !fn ) { in LSAPI_ForeachHeader_r()
1228 if ( pReq->m_pHeaderIndex->m_headerOff[i] ) { in LSAPI_ForeachHeader_r()
1229 len = pReq->m_pHeaderIndex->m_headerLen[i]; in LSAPI_ForeachHeader_r()
1230 pValue = pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i]; in LSAPI_ForeachHeader_r()
1240 if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) { in LSAPI_ForeachHeader_r()
1247 pCur = pReq->m_pUnknownHeader; in LSAPI_ForeachHeader_r()
1248 pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders; in LSAPI_ForeachHeader_r()
1250 pKey = pReq->m_pHttpHeader + pCur->nameOff; in LSAPI_ForeachHeader_r()
1271 pValue = pReq->m_pHttpHeader + pCur->valueOff; in LSAPI_ForeachHeader_r()
1281 return count + pReq->m_pHeader->m_cntUnknownHeaders; in LSAPI_ForeachHeader_r()
1306 int LSAPI_ForeachEnv_r( LSAPI_Request * pReq, in LSAPI_ForeachEnv_r() argument
1309 if ( !pReq || !fn ) { in LSAPI_ForeachEnv_r()
1312 if ( pReq->m_pHeader->m_cntEnv > 0 ) { in LSAPI_ForeachEnv_r()
1313 return EnvForeach( pReq->m_pEnvList, pReq->m_pHeader->m_cntEnv, in LSAPI_ForeachEnv_r()
1321 int LSAPI_ForeachSpecialEnv_r( LSAPI_Request * pReq, in LSAPI_ForeachSpecialEnv_r() argument
1324 if ( !pReq || !fn ) { in LSAPI_ForeachSpecialEnv_r()
1327 if ( pReq->m_pHeader->m_cntSpecialEnv > 0 ) { in LSAPI_ForeachSpecialEnv_r()
1328 return EnvForeach( pReq->m_pSpecialEnvList, in LSAPI_ForeachSpecialEnv_r()
1329 pReq->m_pHeader->m_cntSpecialEnv, in LSAPI_ForeachSpecialEnv_r()
1338 int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq ) in LSAPI_FinalizeRespHeaders_r() argument
1340 if ( !pReq || !pReq->m_pIovec ) { in LSAPI_FinalizeRespHeaders_r()
1343 if ( !( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) ) { in LSAPI_FinalizeRespHeaders_r()
1346 pReq->m_reqState &= ~LSAPI_ST_RESP_HEADER; in LSAPI_FinalizeRespHeaders_r()
1347 if ( pReq->m_pRespHeaderBufPos > pReq->m_pRespHeaderBuf ) { in LSAPI_FinalizeRespHeaders_r()
1348 pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespHeaderBuf; in LSAPI_FinalizeRespHeaders_r()
1349 pReq->m_pIovecCur->iov_len = pReq->m_pRespHeaderBufPos - pReq->m_pRespHeaderBuf; in LSAPI_FinalizeRespHeaders_r()
1350 pReq->m_totalLen += pReq->m_pIovecCur->iov_len; in LSAPI_FinalizeRespHeaders_r()
1351 ++pReq->m_pIovecCur; in LSAPI_FinalizeRespHeaders_r()
1354 pReq->m_pIovec->iov_len = sizeof( struct lsapi_resp_header) in LSAPI_FinalizeRespHeaders_r()
1355 + pReq->m_respHeader.m_respInfo.m_cntHeaders * sizeof( short ); in LSAPI_FinalizeRespHeaders_r()
1356 pReq->m_totalLen += pReq->m_pIovec->iov_len; in LSAPI_FinalizeRespHeaders_r()
1358 lsapi_buildPacketHeader( &pReq->m_respHeader.m_pktHeader, in LSAPI_FinalizeRespHeaders_r()
1359 LSAPI_RESP_HEADER, pReq->m_totalLen ); in LSAPI_FinalizeRespHeaders_r()
1360 pReq->m_pIovec->iov_base = (void *)&pReq->m_respHeader; in LSAPI_FinalizeRespHeaders_r()
1361 pReq->m_pIovecToWrite = pReq->m_pIovec; in LSAPI_FinalizeRespHeaders_r()
1368 int LSAPI_AppendRespHeader_r( LSAPI_Request * pReq, char * pBuf, int len ) in LSAPI_AppendRespHeader_r() argument
1370 if ( !pReq || !pBuf || len <= 0 || len > LSAPI_RESP_HTTP_HEADER_MAX ) { in LSAPI_AppendRespHeader_r()
1373 if ( pReq->m_reqState & LSAPI_ST_RESP_BODY ) { in LSAPI_AppendRespHeader_r()
1376 if ( pReq->m_respHeader.m_respInfo.m_cntHeaders >= LSAPI_MAX_RESP_HEADERS ) { in LSAPI_AppendRespHeader_r()
1379 if ( pReq->m_pRespHeaderBufPos + len + 1 > pReq->m_pRespHeaderBufEnd ) { in LSAPI_AppendRespHeader_r()
1380 int newlen = pReq->m_pRespHeaderBufPos + len + 4096 - pReq->m_pRespHeaderBuf; in LSAPI_AppendRespHeader_r()
1382 if ( allocateRespHeaderBuf( pReq, newlen ) == -1 ) { in LSAPI_AppendRespHeader_r()
1386 memmove( pReq->m_pRespHeaderBufPos, pBuf, len ); in LSAPI_AppendRespHeader_r()
1387 pReq->m_pRespHeaderBufPos += len; in LSAPI_AppendRespHeader_r()
1388 *pReq->m_pRespHeaderBufPos++ = 0; in LSAPI_AppendRespHeader_r()
1390 pReq->m_respHeaderLen[pReq->m_respHeader.m_respInfo.m_cntHeaders] = len; in LSAPI_AppendRespHeader_r()
1391 ++pReq->m_respHeader.m_respInfo.m_cntHeaders; in LSAPI_AppendRespHeader_r()
1800 static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Request * pReq ) in lsapi_prefork_server_accept() argument
1889 pReq->m_fd = lsapi_accept( pServer->m_fd ); in lsapi_prefork_server_accept()
1890 if ( pReq->m_fd != -1 ) { in lsapi_prefork_server_accept()
1899 lsapi_set_nblock( pReq->m_fd, 0 ); in lsapi_prefork_server_accept()
1920 close( pReq->m_fd ); in lsapi_prefork_server_accept()
1921 pReq->m_fd = -1; in lsapi_prefork_server_accept()
1938 int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) in LSAPI_Prefork_Accept_r() argument
1946 LSAPI_Finish_r( pReq ); in LSAPI_Prefork_Accept_r()
1951 if ( lsapi_prefork_server_accept( g_prefork_server, pReq ) == -1 ) { in LSAPI_Prefork_Accept_r()
1965 if ( pReq->m_fd != -1 ) { in LSAPI_Prefork_Accept_r()
1966 fd = pReq->m_fd; in LSAPI_Prefork_Accept_r()
1968 if ( pReq->m_fdListen != -1 ) { in LSAPI_Prefork_Accept_r()
1969 fd = pReq->m_fdListen; in LSAPI_Prefork_Accept_r()
2010 if ( fd == pReq->m_fdListen ) { in LSAPI_Prefork_Accept_r()
2011 pReq->m_fd = lsapi_accept( pReq->m_fdListen ); in LSAPI_Prefork_Accept_r()
2012 if ( pReq->m_fd != -1 ) { in LSAPI_Prefork_Accept_r()
2013 fd = pReq->m_fd; in LSAPI_Prefork_Accept_r()
2028 if ( !readReq( pReq ) ) { in LSAPI_Prefork_Accept_r()
2036 lsapi_close( pReq->m_fd ); in LSAPI_Prefork_Accept_r()
2037 pReq->m_fd = -1; in LSAPI_Prefork_Accept_r()
2038 LSAPI_Reset_r( pReq ); in LSAPI_Prefork_Accept_r()