本文整理汇总了C++中HttpReq类的典型用法代码示例。如果您正苦于以下问题:C++ HttpReq类的具体用法?C++ HttpReq怎么用?C++ HttpReq使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpReq类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
int L4Handler::init(HttpReq &req, const GSockAddr *pGSockAddr, const char *pIP, int iIpLen)
{
int ret = m_pL4conn->init(pGSockAddr);
if (ret != 0)
return ret;
int hasSlashR = 1; //"\r\n"" or "\n"
LoopBuf *pBuff = m_pL4conn->getBuf();
pBuff->append(req.getOrgReqLine(), req.getHttpHeaderLen());
char *pBuffEnd = pBuff->end();
assert(pBuffEnd[-1] == '\n');
if (pBuffEnd[-2] == 'n')
hasSlashR = 0;
else
{
assert(pBuffEnd[-2] == '\r');
}
pBuff->used( -1 * hasSlashR - 1);
pBuff->append("X-Forwarded-For", 15);
pBuff->append(": ", 2);
pBuff->append(pIP, iIpLen);
if (hasSlashR)
pBuff->append("\r\n\r\n", 4);
else
pBuff->append("\n\n", 2);
continueRead();
if ( D_ENABLED( DL_LESS ) )
{
LOG_D ((getLogger(), "[%s] L4Handler: init web socket, reqheader [%s], len [%d]",
getLogId(), req.getOrgReqLine(), req.getHttpHeaderLen() ));
}
return 0;
}
示例2: buildFcgiEnv
int HttpCgiTool::buildFcgiEnv(FcgiEnv *pEnv, HttpSession *pSession)
{
static const char *SP_ENVs[] =
{
"\017\010SERVER_PROTOCOLHTTP/1.1",
"\017\010SERVER_PROTOCOLHTTP/1.0",
"\017\010SERVER_PROTOCOLHTTP/0.9"
};
static const char *RM_ENVs[10] =
{
"\016\007REQUEST_METHODUNKNOWN",
"\016\007REQUEST_METHODOPTIONS",
"\016\003REQUEST_METHODGET",
"\016\004REQUEST_METHODHEAD",
"\016\004REQUEST_METHODPOST",
"\016\003REQUEST_METHODPUT",
"\016\006REQUEST_METHODDELETE",
"\016\005REQUEST_METHODTRACE",
"\016\007REQUEST_METHODCONNECT",
"\016\004REQUEST_METHODMOVE"
};
static int RM_ENV_LEN[10] =
{ 23, 23, 19, 20, 20, 19, 22, 21, 23, 20 };
HttpReq *pReq = pSession->getReq();
int n;
pEnv->add(GISS_ENV, GISS_ENV_LEN);
n = pReq->getVersion();
pEnv->add(SP_ENVs[n], 25);
n = pReq->getMethod();
if (n < 10)
pEnv->add(RM_ENVs[n], RM_ENV_LEN[n]);
else
pEnv->add("REQUEST_METHOD", 016, HttpMethod::get(n),
HttpMethod::getLen(n));
addSpecialEnv(pEnv, pReq);
buildCommonEnv(pEnv, pSession);
addHttpHeaderEnv(pEnv, pReq);
return 0;
}
示例3: getConnector
int ProxyConn::connectSSL()
{
if (!m_ssl.getSSL())
{
m_ssl.setSSL(getSslConn());
if (!m_ssl.getSSL())
return LS_FAIL;
m_ssl.setfd(getfd());
HttpReq *pReq = getConnector()->getHttpSession()->getReq();
char *pHostName;
int hostLen = pReq->getNewHostLen();
if (hostLen > 0)
pHostName = (char *)pReq->getNewHost();
else
{
pHostName = (char *)pReq->getHeader(HttpHeader::H_HOST);
hostLen = pReq->getHeaderLen(HttpHeader::H_HOST);
}
if (pHostName)
{
char ch = *(pHostName + hostLen);
*(pHostName + hostLen) = 0;
m_ssl.setTlsExtHostName(pHostName);
*(pHostName + hostLen) = ch;
}
}
int ret = m_ssl.connect();
switch (ret)
{
case 0:
setSSLAgain();
break;
case 1:
LS_DBG_L(this, "[SSL] connected!");
break;
default:
if (errno == EIO)
LS_DBG_L(this, "SSL_connect() failed!: %s ", SslError().what());
break;
}
return ret;
}
示例4: getSubstValue
int RequestVars::getSubstValue( const SubstItem * pItem, HttpSession *pSession,
char * &pValue, int bufLen )
{
HttpReq * pReq = pSession->getReq();
int type = pItem->getType();
int i;
if ( type < REF_STRING )
{
pValue = (char *)pReq->getHeader( type );
if ( *pValue )
return pReq->getHeaderLen( type );
else
return 0;
}
switch( type )
{
case REF_STRING:
pValue = (char *)pItem->getStr()->c_str();
return pItem->getStr()->len();
case REF_ENV:
pValue = (char *)RequestVars::getEnv( pSession, pItem->getStr()->c_str(),
pItem->getStr()->len(), i );
if ( !pValue )
{
i = 0;
}
return i;
case REF_HTTP_HEADER:
pValue = (char *)pReq->getHeader( pItem->getStr()->c_str(),
pItem->getStr()->len(), i );
if ( !pValue )
i = 0;
return i;
default:
return RequestVars::getReqVar( pSession, type, pValue, bufLen );
}
return 0;
}
示例5: curl_multi_perform
HttpReq::Status HttpReq::status()
{
if(mStatus == REQ_IN_PROGRESS)
{
int handle_count;
CURLMcode merr = curl_multi_perform(s_multi_handle, &handle_count);
if(merr != CURLM_OK && merr != CURLM_CALL_MULTI_PERFORM)
{
mStatus = REQ_IO_ERROR;
onError(curl_multi_strerror(merr));
return mStatus;
}
int msgs_left;
CURLMsg* msg;
while((msg = curl_multi_info_read(s_multi_handle, &msgs_left)))
{
if(msg->msg == CURLMSG_DONE)
{
HttpReq* req = s_requests[msg->easy_handle];
if(req == NULL)
{
LOG(LogError) << "Cannot find easy handle!";
continue;
}
if(msg->data.result == CURLE_OK)
{
req->mStatus = REQ_SUCCESS;
}else{
req->mStatus = REQ_IO_ERROR;
req->onError(curl_easy_strerror(msg->data.result));
}
}
}
}
return mStatus;
}
示例6: buildEnv
int HttpCgiTool::buildEnv( IEnv* pEnv, HttpConnection* pConn )
{
HttpReq * pReq = pConn->getReq();
int n;
pEnv->add( "GATEWAY_INTERFACE",17, "CGI/1.1", 7 );
if ( getenv( "PATH" ) == NULL )
{
pEnv->add( "PATH", 4, DEFAULT_PATH, DEFAULT_PATHLEN );
}
n = pReq->getVersion();
pEnv->add( "SERVER_PROTOCOL", 15,
HttpVer::getVersionString( n ),
HttpVer::getVersionStringLen( n ));
const char * pServerStr;
pServerStr = HttpServerVersion::getVersion();
n = HttpServerVersion::getVersionLen();
pEnv->add( "SERVER_SOFTWARE", 15, pServerStr, n);
n = pReq->getMethod();
pEnv->add( "REQUEST_METHOD", 14, HttpMethod::get( n ),
HttpMethod::getLen( n ));
// //FIXME: do nslookup
//
// tmp = dnslookup(r->cn->peer.sin_addr, r->c->dns);
// if (tmp) {
// ADD_ENV(pEnv, "REMOTE_HOST", tmp);
// free(tmp);
// }
//
// //ADD_ENV(pEnv, "REMOTE_HOST", achTemp );
addSpecialEnv( pEnv, pReq );
buildCommonEnv( pEnv, pConn );
addHttpHeaderEnv( pEnv, pReq );
pEnv->add( 0, 0, 0, 0);
return 0;
}
示例7: startExecute
int SSIEngine::startExecute( HttpSession *pSession,
SSIScript * pScript )
{
if ( !pScript )
return SC_500;
SSIRuntime * pRuntime = pSession->getReq()->getSSIRuntime();
if ( !pRuntime )
{
char ct[]= "text/html";
HttpReq * pReq = pSession->getReq();
pRuntime = new SSIRuntime();
if (!pRuntime )
return SC_500;
pRuntime->init();
pRuntime->initConfig( pReq->getSSIConfig() );
pReq->setSSIRuntime( pRuntime );
pSession->getResp()->reset();
//pSession->getResp()->prepareHeaders( pReq );
//pSession->setupChunkOS( 0 );
HttpCgiTool::processContentType( pReq, pSession->getResp(),
ct , 9 );
// pSession->setupRespCache();
if ( pReq->isXbitHackFull() )
{
pSession->getResp()->appendLastMod( pReq->getLastMod() );
}
int status = pReq->getStatusCode();
if (( status >= SC_300 )&&( status < SC_400 ))
{
if ( pReq->getLocation() != NULL )
{
pSession->addLocationHeader();
}
}
pSession->setupGzipFilter();
pReq->andGzip( ~GZIP_ENABLED ); //disable GZIP
}
if ( pRuntime->push( pScript ) == -1 )
return SC_500;
pSession->getReq()->backupPathInfo();
pScript->resetRuntime();
return resumeExecute( pSession );
}
示例8: buildMoov
int buildMoov(HttpSession *pSession)
{
int ret = 0;
HttpReq *pReq = pSession->getReq();
SendFileInfo *pData = pSession->getSendFileInfo();
FileCacheDataEx *&pECache = pData->getECache();
unsigned char *mini_moov = NULL;
uint32_t mini_moov_size;
mini_moov = pData->getFileData()->getMiniMoov();
mini_moov_size = pData->getFileData()->getMiniMoovSize();
moov_data_t *moov_data = (moov_data_t *)pData->getParam();
if (!moov_data)
return LS_FAIL;
while (moov_data->remaining_bytes > 0)
{
ret = get_moov(
pECache->getfd(),
moov_data->start_time,
0.0,
moov_data,
mini_moov,
mini_moov_size);
if (ret == -1)
return LS_FAIL;
if (moov_data->is_mem == 1)
{
LS_DBG_L(pReq->getLogSession(), "is_mem, buf_size=%u, remaining=%d",
moov_data->mem.buf_size, moov_data->remaining_bytes);
pSession->appendDynBody((char *)moov_data->mem.buffer,
moov_data->mem.buf_size);
free(moov_data->mem.buffer);
moov_data->mem.buffer = NULL;
}
else
{
//pSession->flushDynBodyChunk();
LS_DBG_L(pReq->getLogSession(),
"Send from file, start=%u, buf_size=%u, remaining=%d",
(uint32_t)moov_data->file.start_offset,
moov_data->file.data_size,
moov_data->remaining_bytes);
pSession->setSendFileBeginEnd(moov_data->file.start_offset,
moov_data->file.start_offset + moov_data->file.data_size);
return 1;
//sendfile( pECache->getfd(), moov_data.file.start_offset,
// moov_data.file.data_size );
//fseek(infile, moov_data.file.start_offset, SEEK_SET);
//copy_data(infile, outfile, moov_data.file.data_size);
}
}
pSession->getReq()->clearContextState(MP4_SEEK);
static char mdat_header64[16] = { 0, 0, 0, 1, 'm', 'd', 'a', 't' };
uint64_t mdat_start;
uint64_t mdat_size;
int mdat_64bit;
uint32_t *pLen32;
ret = get_mdat(
pECache->getfd(),
moov_data->start_time,
0.0,
& mdat_start,
& mdat_size,
& mdat_64bit,
mini_moov,
mini_moov_size);
free(moov_data);
pData->setParam(NULL);
if (ret == -1)
return LS_FAIL;
LS_DBG_L(pReq->getLogSession(),
"mdat_start=%u, mdat_size=%u, mdat_64bit=%d",
(uint32_t)mdat_start, (uint32_t)mdat_size, mdat_64bit);
pLen32 = (uint32_t *)(&mdat_header64[8]);
if (mdat_64bit)
{
*pLen32++ = htonl((uint32_t)((mdat_size + 16) >> 32));
*pLen32 = htonl((uint32_t)((mdat_size + 16) & 0xffffffff));
pSession->appendDynBody(mdat_header64, 16);
}
else
{
示例9: getNextRule
int RewriteEngine::processRuleSet( const RewriteRuleList * pRuleList, HttpConnection * pConn,
const HttpContext * pContext, const HttpContext * pRootContext )
{
const RewriteRule * pRule = NULL;
int loopCount = 0;
int flag = 0;
int ret;
m_pContext = pContext;
if ( pRuleList )
pRule = pRuleList->begin();
else
pRule = getNextRule( NULL, pContext, pRootContext );
if ( !pRule )
return 0;
HttpReq * pReq = pConn->getReq();
const AutoStr2 * pBase = NULL;
AutoStr2 sStrip;
m_rewritten = 0;
//initialize rewrite engine
//strip prefix aka. RewriteBase
m_logLevel = pReq->getRewriteLogLevel();
m_pSourceURL = pReq->getURI();
m_sourceURLLen = pReq->getURILen();
m_pStrip = m_pBase = NULL;
m_iScriptLen = -1;
m_iPathInfoLen = 0;
if ( m_pContext )
{
pBase = m_pContext->getContextURI();
if (( pBase )&&
( strncmp( m_pSourceURL, pBase->c_str(), pBase->len() ) == 0 ))
{
m_pStrip = m_pBase = pBase;
}
else
{
m_pBase = pBase = m_pContext->getRewriteBase();
if (( pBase )&&
( strncmp( m_pSourceURL, pBase->c_str(), pBase->len() ) == 0 ))
{
m_pStrip = m_pBase = pBase;
}
}
if ( m_pContext->getRewriteBase() )
m_pBase = m_pContext->getRewriteBase();
if ( m_pStrip )
{
if ( m_logLevel > 4 )
LOG_INFO(( pConn->getLogger(),
"[%s] [REWRITE] strip base: '%s' from URI: '%s'",
pConn->getLogId(), m_pStrip->c_str(), m_pSourceURL ));
m_pSourceURL += m_pStrip->len();
m_sourceURLLen -= m_pStrip->len();
}
else
{
if ( pConn->getReq()->isMatched() )
{
const char * pURL;
int len;
pConn->getReq()->stripRewriteBase( m_pContext,
pURL, len );
if (( len < m_sourceURLLen )&&( strncmp(
m_pSourceURL + m_sourceURLLen - len, pURL, len ) == 0 ))
{
sStrip.setStr( m_pSourceURL, m_sourceURLLen - len );
m_pStrip = &sStrip;
if ( !m_pBase )
m_pBase = m_pStrip;
}
m_pSourceURL = pURL;
m_sourceURLLen = len;
}
}
}
m_pQS = pReq->getQueryString();
m_qsLen = pReq->getQueryStringLen();
m_pOrgSourceURL = m_pSourceURL;
m_orgSourceURLLen = m_sourceURLLen;
m_condMatches = 0;
m_pDestURLLen = 0;
m_pDestURL = m_rewriteBuf[0];
m_pCondBuf = m_rewriteBuf[1];
m_pFreeBuf = m_rewriteBuf[2];
m_action = RULE_ACTION_NONE;
m_flag = 0;
m_statusCode = 0;
while( pRule )
{
flag = pRule->getFlag();
// if (( flag & RULE_FLAG_NOSUBREQ )&&( pReq->isSubReq() > 0 ))
// ret = -1;
// else
ret = processRule( pRule, pConn );
if ( ret )
//.........这里部分代码省略.........
示例10: getSubstValue
int RewriteEngine::getSubstValue( const RewriteSubstItem * pItem, HttpConnection *pConn,
char * &pValue, int bufLen )
{
HttpReq * pReq = pConn->getReq();
int type = pItem->getType();
int i;
if ( type < REF_STRING )
{
pValue = (char *)pReq->getHeader( type );
if ( *pValue )
return pReq->getHeaderLen( type );
else
return 0;
}
/*
if ( type >= REF_TIME )
{
time_t t = time(NULL);
struct tm *tm = localtime(&t);
switch( type )
{
case REF_TIME:
i = snprintf( pValue, bufLen,
"%04d%02d%02d%02d%02d%02d", tm->tm_year + 1900,
tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
break;
case REF_TIME_YEAR:
i = snprintf( pValue, bufLen, "%04d", tm->tm_year + 1900);
break;
case REF_TIME_MON:
i = snprintf( pValue, bufLen, "%02d", tm->tm_mon+1 );
break;
case REF_TIME_DAY:
i = snprintf( pValue, bufLen, "%02d", tm->tm_mday);
break;
case REF_TIME_HOUR:
i = snprintf( pValue, bufLen, "%02d", tm->tm_hour);
break;
case REF_TIME_MIN:
i = snprintf( pValue, bufLen, "%02d", tm->tm_min);
break;
case REF_TIME_SEC:
i = snprintf( pValue, bufLen, "%02d", tm->tm_sec);
break;
case REF_TIME_WDAY:
i = snprintf( pValue, bufLen, "%d", tm->tm_wday);
break;
default:
return 0;
}
return i;
}
*/
switch( type )
{
case REF_STRING:
pValue = (char *)pItem->getStr()->c_str();
return pItem->getStr()->len();
case REF_MAP:
{
MapRefItem * pRef = pItem->getMapRef();
int len = 1024;
char achBuf[1024];
if ( buildString( pRef->getKeyFormat(), pConn, achBuf, len ) == NULL )
return 0;
if ( (len = pRef->getMap()->lookup( achBuf, len, pValue, bufLen )) == -1 )
{
if ( pRef->getDefaultFormat() )
{
if ( buildString( pRef->getDefaultFormat(), pConn,
pValue, bufLen ) == NULL )
return 0;
len = bufLen;
}
else
len = 0;
}
return len;
}
break;
case REF_RULE_SUBSTR:
return getSubstr( m_pSourceURL, m_ruleVec, m_ruleMatches, pItem->getIndex(),
pValue, m_flag & RULE_FLAG_BR_ESCAPE );
case REF_COND_SUBSTR:
return getSubstr( m_pCondBuf, m_condVec, m_condMatches, pItem->getIndex(),
pValue, m_flag & RULE_FLAG_BR_ESCAPE );
case REF_ENV:
pValue = (char *)RequestVars::getEnv( pConn, pItem->getStr()->c_str(),
pItem->getStr()->len(), i );
if ( !pValue )
{
i = 0;
}
return i;
case REF_HTTP_HEADER:
pValue = (char *)pReq->getHeader( pItem->getStr()->c_str(),
pItem->getStr()->len(), i );
if ( !pValue )
//.........这里部分代码省略.........
示例11: while
int JConn::readRespHeader( unsigned char *&p, unsigned char *pEnd )
{
while( m_iNumHeader > 0 )
{
if ( pEnd - p < 4 )
return 0;
unsigned char id1 = *p;
unsigned char id2;
int headerNameLen;
const char * pHeaderName;
unsigned char * p1;
if ( id1 == 0xA0 )
{
id2 = *(p+1);
if (( id2 > 0 )&&( id2 <= AJP_RESP_HEADERS_NUM ))
{
pHeaderName = JkAjp13::getRespHeaderById( id2 );
headerNameLen = JkAjp13::getRespHeaderLenById( id2 );
p1 = p + 2;
}
else
{
//invalid header id
return -1;
}
}
else
{
headerNameLen = id1 << 8 | *(p+1);
if ( pEnd - p < headerNameLen + 5 )
return 0;
pHeaderName = (const char *)p + 2;
p1 = p + headerNameLen + 3;
}
int headerValLen = peekInt( p1 );
if ( pEnd - p1 < headerValLen + 3 )
return 0;
char * pHeaderVal = (char *)p1 + 2;
p = p1 + headerValLen + 3;
--m_iNumHeader;
HttpResp * pResp = getConnector()->getHttpConn()->getResp();
int ret = pResp->appendHeader(
pHeaderName, headerNameLen, pHeaderVal, headerValLen );
if ( ret )
return ret;
HttpReq * pReq = getConnector()->getHttpConn()->getReq();
if ( pReq->gzipAcceptable() )
{
if ( *pHeaderName == 'C' || *pHeaderName == 'c' )
{
if ( strcasecmp( pHeaderName, "content-type" ) == 0 )
{
char * p = (char *)memchr( pHeaderVal, ';', headerValLen );
if ( !p )
p = pHeaderVal + headerValLen;
register char ch;
ch = *p;
*p = 0;
if ( !HttpGlobals::getMime()->compressable( pHeaderVal ) )
pReq->andGzip( ~GZIP_ENABLED );
*p = ch;
}
else if ( strcasecmp( pHeaderName, "content-encoding" ) == 0 )
{
pReq->andGzip( ~GZIP_ENABLED );
}
}
}
}
getConnector()->getRespState() |= HttpReq::HEADER_OK;
return getConnector()->respHeaderDone( m_pCurPos - p );
}
示例12: if
//Only for types from LSI_REQ_SSL_VERSION to LSI_REQ_PATH_TRANSLATED which are defined in ls.h
int RequestVars::getReqVar2( HttpSession *pSession, int type, char * &pValue, int bufLen)
{
HttpReq * pReq = pSession->getReq();
int ret = 0;
if (type >= LSI_REQ_SSL_VERSION && type <= LSI_REQ_SSL_CLIENT_CERT)
{
if( !pSession->isSSL() )
return 0;
SSLConnection *pSSL = pSession->getSSL();
if( type == LSI_REQ_SSL_VERSION)
{
pValue = (char *)pSSL->getVersion();
ret = strlen( pValue );
return ret;
}
else if( type == LSI_REQ_SSL_SESSION_ID )
{
SSL_SESSION *pSession = pSSL->getSession();
if ( pSession )
{
int idLen = SSLConnection::getSessionIdLen( pSession );
ret = idLen * 2;
if ( ret > bufLen )
ret = bufLen;
StringTool::hexEncode((char *)SSLConnection::getSessionId( pSession ), ret / 2, pValue );
}
return ret;
}
else if( type == LSI_REQ_SSL_CLIENT_CERT )
{
X509 * pClientCert = pSSL->getPeerCertificate();
if ( pClientCert )
ret = SSLCert::PEMWriteCert( pClientCert, pValue, bufLen );
return ret;
}
else
{
const SSL_CIPHER * pCipher = pSSL->getCurrentCipher();
if ( pCipher )
{
if( type == LSI_REQ_SSL_CIPHER )
{
pValue = (char *)pSSL->getCipherName();
ret = strlen( pValue );
}
else
{
int algkeysize;
int keysize = SSLConnection::getCipherBits( pCipher, &algkeysize );
if( type == LSI_REQ_SSL_CIPHER_USEKEYSIZE )
ret = safe_snprintf( pValue, 20, "%d", keysize );
else //LSI_REQ_SSL_CIPHER_ALGKEYSIZE
ret = safe_snprintf( pValue, 20, "%d", algkeysize );
}
}
return ret;
}
}
else if( type == LSI_REQ_GEOIP_ADDR)
{
ret = pSession->getPeerAddrStrLen();
pValue = (char *)pSession->getPeerAddrString();
return ret;
}
else if( type == LSI_REQ_PATH_TRANSLATED)
{
int n = pReq->getPathInfoLen();
if ( n > 0)
ret = pReq->translatePath( pReq->getPathInfo(), n, pValue, bufLen);
return ret;
}
else
return 0;
}
示例13: getReqVar
int RequestVars::getReqVar( HttpSession *pSession, int type, char * &pValue, int bufLen)
{
HttpReq * pReq = pSession->getReq();
int i;
char *p;
if ( type < REF_STRING )
{
pValue = (char *)pReq->getHeader( type );
if ( *pValue )
return pReq->getHeaderLen( type );
else
return 0;
}
switch( type )
{
case REF_REMOTE_HOST:
//FIXME: use remote addr for now
case REF_REMOTE_ADDR:
pValue = (char *)pSession->getPeerAddrString();
return pSession->getPeerAddrStrLen();
case REF_REMOTE_PORT:
return snprintf( pValue, bufLen, "%hu", pSession->getRemotePort() );
case REF_REMOTE_USER:
pValue = (char *)pReq->getAuthUser();
return strlen( pValue );
case REF_REMOTE_IDENT:
//do not support;
return 0;
case REF_REQ_METHOD:
i = pReq->getMethod();
strcpy(pValue, HttpMethod::get( i ) );
return HttpMethod::getLen( i );
case REF_QUERY_STRING:
pValue = (char *)pReq->getQueryString();
return pReq->getQueryStringLen();
case REF_AUTH_TYPE:
//FIXME: hard code for now
strncpy( pValue, "Basic", 6 );
return 5;
case REF_REQUST_FN:
case REF_SCRIPTFILENAME:
case REF_SCRIPT_BASENAME:
case REF_REQ_BASENAME:
{
const AutoStr2 * psTemp = pReq->getRealPath();
if ( psTemp )
{
if (( type == REF_SCRIPT_BASENAME )||
( type == REF_REQ_BASENAME ))
{
const char * pEnd = psTemp->c_str() + psTemp->len();
pValue = (char *)pEnd;
while( pValue[-1] != '/' )
--pValue;
return pEnd - pValue;
}
pValue = (char *)psTemp->c_str();
return psTemp->len();
}
else
return 0;
}
case REF_SCRIPT_UID:
case REF_SCRIPT_GID:
case REF_SCRIPT_USERNAME:
case REF_SCRIPT_GRPNAME:
case REF_SCRIPT_MODE:
{
const AutoStr2 * psTemp = pReq->getRealPath();
if ( psTemp )
{
struct stat& st = pReq->getFileStat();
if ( type == REF_SCRIPT_UID )
{
return snprintf( pValue, bufLen, "%d", st.st_uid );
}
else if ( type == REF_SCRIPT_GID )
{
return snprintf( pValue, bufLen, "%d", st.st_gid );
}
else if ( type == REF_SCRIPT_MODE )
{
return snprintf( pValue, bufLen, "%o", st.st_mode );
}
else if ( type == REF_SCRIPT_USERNAME )
{
struct passwd * pw = getpwuid( st.st_uid );
if ( pw )
return snprintf( pValue, bufLen, "%s", pw->pw_name );
}
else
{
struct group * gr = getgrgid( st.st_gid );
if ( gr )
return snprintf( pValue, bufLen, "%s", gr->gr_name );
}
}
return 0;
}
case REF_PATH_INFO:
//.........这里部分代码省略.........
示例14: getConnector
int CgidConn::buildReqHeader()
{
static unsigned int s_id = 0;
HttpSession *pSession = getConnector()->getHttpSession();
HttpReq * pReq = pSession->getReq();
const char * pQueryString = pReq->getQueryString();
const char * pQsEnd = pReq->getQueryString() + pReq->getQueryStringLen();
const char * pReal;
const AutoStr2 * psChroot;
const AutoStr2 * realPath = pReq->getRealPath();
const char * pChroot;
int ret;
uid_t uid;
gid_t gid;
pReal = realPath->c_str();
ret = pReq->getUGidChroot( &uid, &gid, &psChroot );
if ( ret )
return ret;
// if ( D_ENABLED( DL_LESS ) )
// LOG_D(( getLogger(),
// "[%s] UID: %d, GID: %d",
// getLogId(), pHeader->m_uid, pHeader->m_gid ));
if ( psChroot )
{
// if ( D_ENABLED( DL_LESS ) )
// LOG_D(( getLogger(),
// "[%s] chroot: %s, real path: %s",
// getLogId(), pChroot->c_str(), pReal ));
pChroot = psChroot->c_str();
ret = psChroot->len();
}
else
{
pChroot = NULL;
ret = 0;
}
int priority = ((CgidWorker *)getWorker())->getConfig().getPriority();
m_req.buildReqHeader( uid, gid, priority, pChroot, ret, pReal,
pReq->getRealPath()->len(),
((CgidWorker *)getWorker())->getConfig().getRLimits() );
if ( *pQueryString && (memchr( pQueryString, '=',
pQsEnd - pQueryString ) == NULL ))
{
char * pPlus;
do
{
pPlus = (char*)memchr( pQueryString, '+', pQsEnd - pQueryString);
if ( pPlus != pQueryString )
{
int len;
if ( pPlus )
len = pPlus - pQueryString;
else
len = pQsEnd - pQueryString;
m_req.appendArgv( pQueryString, len );
}
if ( pPlus )
pQueryString = pPlus + 1;
}while( pPlus );
}
m_req.appendArgv( NULL, 0 );
HttpCgiTool::buildEnv( &m_req, pSession );
m_req.finalize( s_id++, ((CgidWorker *)getWorker())->getConfig().getSecret(),
LSCGID_TYPE_CGI );
return 0;
}
示例15: switch
int SSIEngine::processSubReq(HttpSession *pSession, SubstItem *pItem)
{
char achBuf[40960];
char *p;
int len;
int attr;
if (!pItem)
return 0;
SSIRuntime *pRuntime = pSession->getReq()->getSSIRuntime();
attr = pItem->getSubType();
p = achBuf;
len = 40960;
switch (attr)
{
case SSI_INC_FILE:
{
HttpReq *pReq = pSession->getReq();
memmove(p, pReq->getURI(), pReq->getURILen());
p = p + pReq->getURILen() - pReq->getPathInfoLen();
while (p[-1] != '/')
--p;
*p = 0;
len -= p - achBuf;
break;
}
case SSI_EXEC_CGI:
pRuntime->requireCGI();
break;
case SSI_EXEC_CMD:
pRuntime->requireCmd();
p += snprintf(achBuf, 40960, "%s",
pRuntime->getCurrentScript()->getPath());
while (p[-1] != '/')
--p;
*p++ = '&';
*p++ = ' ';
*p++ = '-';
*p++ = 'c';
*p++ = ' ';
len -= p - achBuf;
// make the command looks like "/script/path/& command"
// '&' tell cgid to execute it as shell command
break;
}
RequestVars::appendSubst(pItem, pSession, p, len,
0, pRuntime->getRegexResult());
if (attr == SSI_INC_FILE)
{
if (strstr(achBuf, "/../") != NULL)
return 0;
}
else if (attr == SSI_EXEC_CMD)
{
if (pSession->execExtCmd(achBuf, p - achBuf) == 0)
return -2;
else
return 0;
//len = snprintf( achBuf, 40960, "'exec cmd' is not available, "
// "use 'include virutal' instead.\n" );
//pSession->appendDynBody( achBuf, len );
//return 0;
}
if ((achBuf[0] != '/') && (attr != SSI_EXEC_CMD))
{
if (achBuf[0] == 0)
{
len = snprintf(achBuf, 40960,
"[an error occurred while processing this directive]\n");
pSession->appendDynBody(achBuf, len);
return 0;
}
HttpReq *pReq = pSession->getReq();
const char *pURI = pReq->getURI();
const char *p1 = pURI + pReq->getURILen() - pReq->getPathInfoLen();
while ((p1 > pURI) && p1[-1] != '/')
--p1;
int prefix_len = p1 - pURI;
memmove(&achBuf[prefix_len], achBuf, p - achBuf);
memmove(achBuf, pReq->getURI(), prefix_len);
p += prefix_len;
}
if (achBuf[0] == '/')
{
pSession->getReq()->setLocation(achBuf, p - achBuf);
pSession->changeHandler();
pSession->continueWrite();
return -2;
}
return 0;
}