24
// optimization on Linux; no-op for platforms that don't know it
29
25
#define REPLEVEL (m_type==rechecks::FILE_INDEX ? 4 : (m_type==rechecks::FILE_PKG ? 5 : SPAMLEVEL))
31
27
//void DispatchAndRunMaintTask(const MYSTD::string &, int, const MYSTD::string &);
231
227
LOGSTART("job::PrepareDownload");
233
string sTmp; // for raw uri and other tasks
229
string sRawUriPath, sPathResdiual;
234
230
tHttpUrl tUrl; // parsed URL
236
232
acfg::tHostiVec * pBackends(NULL); // appropriate backends
265
261
if(3 == Tokenize(m_pReqHead->frontLine, SPACECHARS, tmp))
268
264
goto report_invpath; // invalid uri
270
LOG("raw uri: " << sRawUriPath);
273
271
// filesystem browsing attempt?
274
if(stmiss != sTmp.find("..") || stmiss != sTmp.find("/_actmp"))
272
if(stmiss != sRawUriPath.find("..") || stmiss != sRawUriPath.find("/_actmp"))
275
273
goto report_notallowed;
277
if (0==sTmp.compare(0, 12, "apt-cacher?/"))
279
if (0==sTmp.compare(0, 11, "apt-cacher/"))
275
if (0==sRawUriPath.compare(0, 12, "apt-cacher?/"))
276
sRawUriPath.erase(0, 12);
277
if (0==sRawUriPath.compare(0, 11, "apt-cacher/"))
278
sRawUriPath.erase(11);
282
if(!tUrl.SetHttpUrl(sTmp)) goto report_info;
280
if(!tUrl.SetHttpUrl(sRawUriPath))
285
LOG("refined path: " << tUrl.sPath);
284
287
if(!tUrl.sPort.empty() && tUrl.sPort!="80")
302
305
LOG("input uri: "<<tUrl.ToURI()<<" , dontcache-flag? " << bPtMode);
304
307
tStrPos nRepNameLen=acfg::reportpage.size();
305
if(nRepNameLen>0 && 0==tUrl.sHost.compare(0, nRepNameLen, acfg::reportpage))
307
m_sMaintCmd=tUrl.sHost;
310
if(0==tUrl.sHost.compare(0, nRepNameLen, acfg::reportpage))
312
m_sMaintCmd=tUrl.sHost;
315
if (tUrl.sHost == "style.css")
317
LOG("support CSS style file");
318
m_sMaintCmd = "/style.css";
322
if(!sPath.empty() && endsWithSzAr(sPath, "/"))
324
LOG("generic user information page");
310
if(!tUrl.sPath.empty() && tUrl.sPath[tUrl.sPath.size()-1]=='/' )
312
330
m_type = rechecks::GetFiletype(sPath);
314
332
if ( m_type == rechecks::FILE_INVALID ) goto report_notallowed;
316
334
// got something valid, has type now, trace it
317
USRDBG(REPLEVEL, "Processing new job, " << m_pReqHead->frontLine);
335
USRDBG(REPLEVEL, string("Processing new job, ")+m_pReqHead->frontLine);
319
337
// resolve to an internal location
320
psVname = acfg::GetRepNameAndPathResidual(tUrl, sTmp);
338
psVname = acfg::GetRepNameAndPathResidual(tUrl, sPathResdiual);
323
m_sFileLoc=*psVname+sPathSep+sTmp;
341
m_sFileLoc=*psVname+sPathSep+sPathResdiual;
325
343
m_sFileLoc=tUrl.sHost+tUrl.sPath;
390
408
if(psVname && NULL != (pBackends=acfg::GetBackendVec(psVname)))
392
LOG("Backends found, using them with " << sTmp
410
LOG("Backends found, using them with " << sPathResdiual
393
411
<< ", first backend: " <<pBackends->front().ToURI());
395
if(! bPtMode && rechecks::MatchUncacheableTarget(pBackends->front().ToURI()+sTmp))
413
if(! bPtMode && rechecks::MatchUncacheableTarget(pBackends->front().ToURI()+sPathResdiual))
396
414
fistate=_SwitchToPtItem(m_sFileLoc);
398
m_pParentCon->m_pDlClient->AddJob(m_pItem, pBackends, sTmp);
416
m_pParentCon->m_pDlClient->AddJob(m_pItem, pBackends, sPathResdiual);
664
680
LOG("or STATE_ERRORCONT?");
665
681
case(STATE_FINISHJOB):
666
682
LOG("or STATE_FINISHJOB");
667
LOG("what's the head? " << m_pReqHead << " and close flag? "
668
<< (m_pReqHead ? "(unset)" : m_pReqHead->h[header::CONNECTION] ));
687
bool bhttp11 = m_pReqHead->frontLine.find("HTTP/1.1") != stmiss;
688
if(m_pReqHead->h[header::CONNECTION])
689
bClose = 0==strcasecmp(m_pReqHead->h[header::CONNECTION], "close");
670
if(m_pReqHead && m_pReqHead->h[header::CONNECTION])
672
LOG("close-Header found, advising to disconnect");
673
if(0==strcasecmp(m_pReqHead->h[header::CONNECTION], "close"))
696
LOG("Reporting job done")
676
LOG("Reporting job done")
678
700
case(STATE_TODISCON):
757
779
// if missing completely, chunked mode is to be used below
758
780
if(m_RespHead.h[header::CONTENT_LENGTH])
760
if(0==atol(m_RespHead.h[header::CONTENT_LENGTH]))
782
if(0==atoofft(m_RespHead.h[header::CONTENT_LENGTH]))
804
826
// is it fresh? or is this relevant? or is range mode forced?
805
827
if( bFreshnessForced || bIfModSeenAndChecked)
807
off_t nContLen=atol(m_RespHead.h[header::CONTENT_LENGTH]);
829
off_t nContLen=atoofft(m_RespHead.h[header::CONTENT_LENGTH]);
810
832
* Range: bytes=453291-