//如果user和pass不为空,要改写url返回 std::string CPropertyDlg::GetUrl() { if ( !m_sUser.IsEmpty() && !m_sPass.IsEmpty() ) { //用户和密码两个都不空 //但是如果都等于缺省值就不重新构造地址 if ( m_sUser.mb_str( wxConvLocal ) != "anonymous" || //m_sPass.mb_str( wxConvLocal ) != gDefFtpPass m_sPass.mb_str(wxConvLocal) != wxString::FromAscii( gDefFtpPass.c_str()).mb_str() //unicode patch ) { CUrlParser parser; std::string rebuild; std::string origin = std::string( m_sUrl.mb_str( wxConvLocal ) ); if ( parser.RebuildUrl( origin, std::string( m_sUser.mb_str( wxConvLocal ) ), std::string( m_sPass.mb_str( wxConvLocal ) ), rebuild ) ) { return rebuild; } } } #ifndef _UNICODE return m_sUrl.mb_str( wxConvLocal ); #else return m_sUrl.mb_str( wxConvLocal ).data(); #endif }
VOID CommonGetCookie(LPCSTR pchUrl,CHAR *pchCookieData,int nCookieDataLen,BOOL bFromJs = FALSE) { CUrlParser urlParser; urlParser.ParseUrl(pchUrl); CStringA strCheckDomain; strCheckDomain = urlParser.GetDomain(); strCheckDomain = "."+strCheckDomain; CStringA strSqlCmd; strSqlCmd.Format("select cookiename,cookievalue from cookiedata where \"%s\" like \"%%\"||domain and \"%s\" like path||\"%%\" %s %s " ,strCheckDomain ,urlParser.GetPath() ,bFromJs?"and httponly=0":"" ,urlParser.GetProtocol().CompareNoCase("https") == 0?"and secure=1":"and secure=0" ); CStringA strCookieResult; char *pcherrmsg = NULL; DWORD dwTickStart = GetTickCount(); Locker.rlock(); ASSERT(sqlite3_exec(g_pDB,strSqlCmd,query_cookie_callback,&strCookieResult,&pcherrmsg) == 0); Locker.unlock(); DWORD dwUseTime = GetTickCount() - dwTickStart; CStringA strMsgout; strMsgout.Format("查询Cookie 用时:%d\r\n",dwUseTime); OutputDebugStringA(strMsgout); strcpy_s(pchCookieData,nCookieDataLen,strCookieResult.GetBuffer()); }
void CNewTaskDlg::OnUrlText( wxCommandEvent& event ) { //url text changed #ifdef WIN32 if ( !m_bOpenUrlKeyEvent ) return ; //too ugly but work!! TransferDataFromWindow(); CUrlParser par; if ( !par.SetUrl( m_sUrl.c_str() ) ) { m_sRename.Clear(); //m_pTextCtrl->SetInsertionPointEnd(); m_RenameCtrl->SetValue(m_sRename); } else { m_sRename = wxString( par.GetFileName().c_str(), wxConvLocal ); //m_pTextCtrl->SetInsertionPointEnd(); m_RenameCtrl->SetValue(m_sRename); } #else if ( !m_bOpenUrlKeyEvent ) return ; //too ugly but work!! TransferDataFromWindow(); CUrlParser par; #ifndef _UNICODE if ( !par.SetUrl( m_sUrl.mb_str( wxConvLocal ) ) ) #else if ( !par.SetUrl( m_sUrl.mb_str( wxConvLocal ).data() ) ) #endif { m_sRename.Clear(); //TransferDataToWindow(); //this in win32 will cause a new Text Event,and then circle and circle! //m_pTextCtrl->SetInsertionPointEnd(); m_RenameCtrl->SetValue(m_sRename); } else { m_sRename = wxString( par.GetFileName().c_str(), wxConvLocal ); //TransferDataToWindow(); //m_pTextCtrl->SetInsertionPointEnd(); m_RenameCtrl->SetValue(m_sRename); } #endif }
std::string CPropertyDlg::GetSelectFileName() { int len = m_sUrl.Length(); int pos = len; bool found = false; int step = m_nFileSpin; CUrlParser par; wxString ret; if ( step <= 0 ) return std::string( "" ); for ( int i = 0; i < step; i++ ) { found = false; for ( int j = pos - 1; j > 1; j-- ) { if ( wxChar( '/' ) == m_sUrl[ j ] ) { found = true; if ( wxChar( '/' ) != m_sUrl[ j - 1 ] ) { //valid / pos = j; break; } else { //not valid / goto fail; } } } if ( found ) continue; else goto fail; //from end to search '/' } //select it //pos point to / //select from pos+1 to end; ret = m_sUrl.SubString( pos + 1, len ); #ifndef _UNICODE return ret.mb_str( wxConvLocal ); #else return ret.mb_str( wxConvLocal ).data();//unicode patch #endif fail: #ifndef _UNICODE if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ) ) ) #else if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ).data() ) ) //unicode patch #endif { return par.GetFileName(); } return std::string( "" ); }
CPropertyDlg::CPropertyDlg( MainFrame* parent, int taskid ) : wxDialog( parent, -1, _("Task properties"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE| wxRESIZE_BORDER ) { m_pParent = parent; _TaskAttr *tsk = m_pParent->GetTask( taskid ); if ( tsk == NULL ) return ; //m_sUrl = wxString( tsk->sURL.c_str() ); m_sUrl=wxString( tsk->sURL.c_str(), wxConvLocal );//unicode patch //m_sRefer = wxString( tsk->sRefer.c_str() ); m_sRefer=wxString( tsk->sRefer.c_str(), wxConvLocal ); //unicode patch //对这个url分离用户名和密码 if ( !m_sUrl.IsEmpty() ) { CUrlParser par; std::string m_swap; #ifndef _UNICODE if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ) ) ) #else if( par.SetUrl( m_sUrl.mb_str(wxConvLocal).data() ) ) //unicode patch #endif { if ( par.GetUrlType() == FTP_PROTOCOL ) { m_sUser = wxString( par.GetUser().c_str(), wxConvLocal ); m_sPass = wxString( par.GetPass().c_str(), wxConvLocal ); m_sUrl = wxString( par.GetRawUrl().c_str(), wxConvLocal ); } else { m_sUrl = wxString( par.GetRawUrl().c_str(), wxConvLocal ); } if ( par.GetFileName().empty() ) { m_sRename = _( "index.html" ); } else { //m_sRename = par.GetFileName(); m_sRename=wxString(par.GetFileName().c_str(),wxConvLocal); //unicode patch } } } //m_sSavePath = wxString( tsk->sSavePath.c_str() ); m_sSavePath=wxString( tsk->sSavePath.c_str(), wxConvLocal ); //unicode patch m_nThreadNum = tsk->nThread; m_nRetry = tsk->nRetry; m_nRetryWait = tsk->nRetryWait; m_nSocksProxy = 0; m_nFtpProxy = 0; m_nHttpProxy = 0; m_nRunNow = 0; m_nFileSpin = 0; m_pMirrorBox = NULL; m_ThSpin = NULL; m_ThRetry = NULL; m_ThRetryWait = NULL; m_FileSpin = NULL; m_pTextCtrl = NULL; m_bOpenUrlKeyEvent = false; InitProxyList( tsk->sSockProxy, tsk->sFtpProxy, tsk->sHttpProxy ); Init( tsk->nStatus ); //add mirror string for ( int i = 0;i < int( tsk->sMirrorURL.size() );i++ ) { AddMirrorUrl( wxString( tsk->sMirrorURL[ i ].c_str(), wxConvLocal ) ); } }
CNewTaskDlg::CNewTaskDlg( MainFrame* parent, wxString defUrl, wxString refer, wxString defSavePath ) : wxDialog( parent, -1, _MGSTR( _S_NEW_TASK ), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ) { m_pParent = parent; m_sUrl = defUrl; m_sRefer = refer; //对这个url分离用户名和密码 if ( !m_sUrl.IsEmpty() ) { CUrlParser par; std::string m_swap; #ifndef _UNICODE if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ) ) ) #else if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ).data() ) ) #endif { if ( par.GetUrlType() == FTP_PROTOCOL ) { m_sUser = wxString( par.GetUser().c_str(), wxConvLocal ); m_sPass = wxString( par.GetPass().c_str(), wxConvLocal ); m_sUrl = wxString( par.GetRawUrl().c_str(), wxConvLocal ); } else { m_sUrl = wxString( par.GetRawUrl().c_str(), wxConvLocal ); } if ( par.GetFileName().empty() ) { m_sRename = wxT( "index.html" ); } else { //m_sRename = par.GetFileName(); m_sRename=wxString(par.GetFileName().c_str(),wxConvLocal); } } } m_sSavePath = defSavePath; if ( m_sSavePath.IsEmpty() ) { m_sSavePath = wxString( gDefSavePath.c_str(), wxConvLocal ); if ( m_sSavePath.IsEmpty() ) { std::string home; GetUserHome( home ); m_sSavePath = wxString( home.c_str(), wxConvLocal ); } } m_nThreadNum = gTaskDefThread; m_nSocksProxy = 0; m_nFtpProxy = 0; m_nHttpProxy = 0; m_nRunNow = 0; //run m_nFileSpin = 1; m_nRetry = gRetryTime; m_nRetryWait = gRetryWait; m_sSavePath = wxString( gDefSavePath.c_str(), wxConvLocal ); m_pMirrorBox = NULL; m_ThSpin = NULL; m_ThRetry = NULL; m_ThRetryWait = NULL; m_FileSpin = NULL; m_pTextCtrl = NULL; m_RenameCtrl=NULL; m_bOpenUrlKeyEvent = false; //这里准备一下代理列表 InitProxyList(); Init(); }
void CNewTaskDlg::Init() { if ( m_sUrl.IsNull() && wxTheClipboard->Open() ) { if ( wxTheClipboard->IsSupported( wxDF_TEXT ) ) { wxTextDataObject text; if ( wxTheClipboard->GetData( text ) ) { m_sUrl = text.GetText(); CUrlParser upar; if ( !upar.SetUrl( std::string( m_sUrl.mb_str( wxConvLocal ) ) ) ) { m_sUrl = wxT( "" ); } else if ( upar.GetFileName().empty() ) { m_sUrl = wxT( "" ); } } } wxTheClipboard->Close(); } //for border wxBoxSizer *top = new wxBoxSizer( wxVERTICAL ); //old top wxBoxSizer *all = new wxBoxSizer( wxVERTICAL ); //part1 url/mirror/savepath/rename wxBoxSizer *part1 = new wxStaticBoxSizer( wxVERTICAL, this, _MGSTR( _S_NEW_BASIC ) ); //part2 run now/thread wxBoxSizer *part2 = new wxBoxSizer( wxHORIZONTAL ); //part3 proxy wxBoxSizer *part3 = new wxBoxSizer( wxVERTICAL ); //part4 user/pass wxBoxSizer *part4 = new wxBoxSizer( wxVERTICAL ); //part6 insert refer wxBoxSizer *part6 = new wxBoxSizer( wxVERTICAL ); //part5 button wxBoxSizer *part5 = new wxBoxSizer( wxVERTICAL ); //part1 wxBoxSizer *url = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *mirrorurl = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *savepath = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *rename = new wxBoxSizer( wxHORIZONTAL ); url->Add( new wxStaticText( this, -1, _MGSTR( _S_NEW_URL ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_LEFT ); m_pTextCtrl = new wxTextCtrl( this, mgID_URLTEXT, wxT( "" ), wxDefaultPosition, wxSize( 400, 25 ), 0, wxGenericValidator( &m_sUrl ) ); m_pTextCtrl->SetMaxLength( 256 ); url->Add( m_pTextCtrl, 1, wxEXPAND ); m_FileSpin = new wxSpinButton( this, mgID_SPINFILE, wxDefaultPosition, #ifdef WIN32 wxSize( 20, 20 ), wxSP_VERTICAL ); #else wxSize( 25, 25 ), wxSP_VERTICAL ); //wxSP_HORIZONTAL not support by GTK! #endif m_FileSpin->SetRange( 1, 5 ); m_FileSpin->SetValue( 1 ); url->Add( m_FileSpin, 0, wxEXPAND ); mirrorurl->Add( new wxStaticText( this, -1, _MGSTR( _S_NEW_MIRRORURL ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_LEFT | wxALIGN_TOP ); m_pMirrorBox = new wxListBox( this, -1, wxDefaultPosition, wxSize( 400, 75 ), m_sMirrorUrl, wxLB_SINGLE | wxLB_NEEDED_SB ); mirrorurl->Add( m_pMirrorBox, 1, wxEXPAND ); savepath->Add( new wxStaticText( this, -1, _MGSTR( _S_NEW_SAVETO ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_LEFT ); /* savepath->Add( new wxTextCtrl(this,-1,wxT(""),wxDefaultPosition,wxSize(285,25),0,wxGenericValidator(&m_sSavePath)) ,0,wxEXPAND); */ //从历史记录中导出目录 //DBGOUT("history path size="<<gSavePathHistory.size()); wxArrayString pchoice; std::list<std::string>::const_iterator it; for ( it = gSavePathHistory.begin();it != gSavePathHistory.end();it++ ) { if ( it->empty() ) { continue; } else { wxString temp( it->c_str(), wxConvLocal ); //DBGOUT("add a path to dropdown"); //DBGOUT(temp); pchoice.Add( temp ); } } //it seems in win32 m_sSavePath don't show in gui m_SavePathCtrl= new wxComboBox( this, -1, wxT( "" ), wxDefaultPosition, #ifdef WIN32 wxSize( 200, 22 ), #else wxSize( 200, 25 ), #endif pchoice, 1, wxGenericValidator( &m_sSavePath ) ); //it seems in win32 m_sSavePath don't show in gui #ifdef WIN32 m_SavePathCtrl->SetValue(m_sSavePath); #endif savepath->Add(m_SavePathCtrl, 1, wxEXPAND ); savepath->Add( new wxButton( this, mgID_PICKPATH, wxT( "..." ), wxDefaultPosition, #ifdef WIN32 wxSize( 35, 22 ) ), 0, wxEXPAND ); #else wxSize( 35, 25 ) ), 0, wxALIGN_RIGHT ); #endif rename->Add( new wxStaticText( this, -1, _MGSTR( _S_NEW_RENAME ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_LEFT ); m_RenameCtrl=new wxTextCtrl( this, mgID_RENAMETEXT, wxT( "" ), wxDefaultPosition, wxSize( 200, 25 ),1,wxGenericValidator( &m_sRename )); rename->Add( m_RenameCtrl, 1, wxEXPAND ); //add part1 to global part1->Add( url, 0, wxEXPAND ); part1->AddSpacer( 3 ); part1->Add( mirrorurl, 1, wxEXPAND ); part1->AddSpacer( 3 ); part1->Add( savepath, 0, wxEXPAND ); part1->AddSpacer( 3 ); part1->Add( rename, 0, wxEXPAND ); //part2 wxBoxSizer *threads = new wxStaticBoxSizer( wxHORIZONTAL, this, _MGSTR( _S_NEW_THREADNUM ) ); m_ThSpin = new wxSpinCtrl( this, mgID_SPINTHREAD, wxT( "" ), wxDefaultPosition, wxSize( 20, 25 ) ); // m_ThSpin->SetRange( 1, 10 ); m_ThSpin->SetValue( m_nThreadNum ); threads->AddSpacer( 10 ); threads->Add( m_ThSpin, 1, wxEXPAND ); threads->AddSpacer( 10 ); part2->Add( threads, 1, wxEXPAND ); part2->AddSpacer( 10 ); wxBoxSizer *retry = new wxStaticBoxSizer( wxHORIZONTAL, this, _MGSTR( _S_NEW_RETRY ) ); m_ThRetry = new wxSpinCtrl( this, mgID_SPINRETRY, wxT( "" ), wxDefaultPosition, wxSize( 20, 25 ) ); // m_ThRetry->SetRange( 0, 999 ); m_ThRetry->SetValue( m_nRetry ); retry->AddSpacer( 10 ); retry->Add( m_ThRetry, 1, wxEXPAND ); retry->AddSpacer( 10 ); part2->Add( retry, 1, wxEXPAND ); part2->AddSpacer( 10 ); wxBoxSizer *retrywait = new wxStaticBoxSizer( wxHORIZONTAL, this, _MGSTR( _S_NEW_RETRYWAIT ) ); m_ThRetryWait = new wxSpinCtrl( this, mgID_SPINRETRYWAIT, wxT( "" ), wxDefaultPosition, wxSize( 20, 25 ) ); // m_ThRetryWait->SetRange( 5, 3000 ); m_ThRetryWait->SetValue( m_nRetryWait ); retrywait->AddSpacer( 10 ); retrywait->Add( m_ThRetryWait, 1, wxEXPAND ); retrywait->AddSpacer( 10 ); part2->Add( retrywait, 1, wxEXPAND ); part2->AddSpacer( 10 ); wxString choices[ 2 ] = { _MGSTR( _S_NEW_YES ), _MGSTR( _S_NEW_NO ), }; part2->Add( new wxRadioBox( this, -1, _MGSTR( _S_NEW_RUNNOW ), wxDefaultPosition, wxSize( 50, 25 ), 2, choices, 0, wxRA_SPECIFY_COLS, wxGenericValidator( &m_nRunNow ) ), 1, wxEXPAND | wxALIGN_RIGHT ); //part3 proxy wxStaticBoxSizer* proxy = new wxStaticBoxSizer( wxVERTICAL, this, _MGSTR( _S_NEW_PROXY ) ); wxBoxSizer* socks = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* ftp = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* http = new wxBoxSizer( wxHORIZONTAL ); socks->Add( new wxStaticText( this, -1, wxT( "SOCKS:" ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_LEFT ); wxArrayString socksarray; //socks list //copy string for ( unsigned int i = 0;i < m_SocksProxyList.size();i++ ) { socksarray.Add( m_SocksProxyList[ i ].showname ); } socks->Add( new wxChoice( this, -1, wxDefaultPosition, wxSize( 210, 28 ), socksarray, 0, wxGenericValidator( &m_nSocksProxy ) ), 1, wxEXPAND ); proxy->Add( socks, 1, wxEXPAND ); ftp->Add( new wxStaticText( this, -1, wxT( "FTP:" ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_LEFT ); wxArrayString ftparray; //socks list //copy string for ( unsigned int i = 0;i < m_FtpProxyList.size();i++ ) { ftparray.Add( m_FtpProxyList[ i ].showname ); } ftp->Add( new wxChoice( this, -1, wxDefaultPosition, wxSize( 210, 28 ), ftparray, 0, wxGenericValidator( &m_nFtpProxy ) ), 1, wxEXPAND ); proxy->Add( ftp, 1, wxEXPAND ); http->Add( new wxStaticText( this, -1, wxT( "HTTP:" ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_LEFT ); wxArrayString httparray; //socks list //copy string for ( unsigned int i = 0;i < m_HttpProxyList.size();i++ ) { httparray.Add( m_HttpProxyList[ i ].showname ); } http->Add( new wxChoice( this, -1, wxDefaultPosition, wxSize( 210, 28 ), httparray, 0, wxGenericValidator( &m_nHttpProxy ) ), 1, wxEXPAND ); proxy->Add( http, 1, wxEXPAND ); part3->Add( proxy, 1, wxEXPAND ); //part4 wxStaticBoxSizer* userpass = new wxStaticBoxSizer( wxHORIZONTAL, this, _MGSTR( _S_NEW_LOGIN ) ); userpass->Add( new wxStaticText( this, -1, _MGSTR( _S_NEW_USER ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_RIGHT ); userpass->Add( new wxTextCtrl( this, -1, wxT( "" ), wxDefaultPosition, wxSize( 60, 25 ), 0, wxGenericValidator( &m_sUser ) ), 1, wxEXPAND ); userpass->AddSpacer( 10 ); userpass->Add( new wxStaticText( this, -1, _MGSTR( _S_NEW_PASS ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_RIGHT ); userpass->Add( new wxTextCtrl( this, -1, wxT( "" ), wxDefaultPosition, wxSize( 80, 25 ), 0, wxGenericValidator( &m_sPass ) ), 1, wxEXPAND ); part4->Add( userpass, 1, wxEXPAND ); //part5 wxBoxSizer* but = new wxBoxSizer( wxHORIZONTAL ); but->Add( new wxButton( this, wxID_CANCEL, wxT( "Cancel" ) ), 0, wxALL, 5 ); but->Add( new wxButton( this, wxID_OK, wxT( "OK" ) ), 0, wxALL, 5 ); part5->Add( but, 0, wxALIGN_RIGHT ); //part6 wxStaticBoxSizer* refer = new wxStaticBoxSizer( wxHORIZONTAL, this, _MGSTR( _S_NEW_REFER ) ); refer->Add( new wxStaticText( this, -1, _MGSTR( _S_NEW_REFERADDR ), wxDefaultPosition, wxSize( 70, 25 ) ), 0, wxALIGN_RIGHT ); refer->Add( new wxTextCtrl( this, -1, wxT( "" ), wxDefaultPosition, wxSize( 80, 25 ), 0, wxGenericValidator( &m_sRefer ) ), 1, wxEXPAND ); part6->Add( refer, 1, wxEXPAND ); all->Add( part1, 1, wxEXPAND ); all->AddSpacer( 10 ); all->Add( part2, 0, wxEXPAND ); all->AddSpacer( 10 ); all->Add( part3, 0, wxEXPAND ); all->AddSpacer( 10 ); all->Add( part4, 0, wxEXPAND ); all->AddSpacer( 10 ); all->Add( part6, 0, wxEXPAND ); all->AddSpacer( 10 ); all->Add( part5, 0, wxALIGN_RIGHT ); top->Add( all, 1, wxEXPAND | wxALL | wxFIXED_MINSIZE, 5 ); TransferDataToWindow(); //top->SetMinSize(420,300); top->Fit( this ); SetSizer( top ); top->SetSizeHints( this ); m_bOpenUrlKeyEvent = true; if ( m_sUrl.IsNull() ) { m_pTextCtrl->SetFocus(); } else { m_ThSpin->SetFocus(); } }
void CMgSingleTask::InitThread() { OutMsg( -1, _("Job running..."), MSG_INFO ); pthread_setcanceltype ( PTHREAD_CANCEL_ASYNCHRONOUS, NULL ); CUrlParser upar; if ( !m_Refer.empty() ) upar.SetRefer( m_Refer ); int oldstate; vector<string> cookie; //for http again: OutMsg( -1, _("Analysis URL..."), MSG_INFO ); if ( !upar.SetUrl( m_sUrl ) ) { OutMsg( -1, c_str(_("Not a support URL type.")) + m_sUrl, MSG_ERROR ); FinishTask( _TASK_ERROR ); pthread_exit( 0 ); } OutMsg( -1, _("URL OK."), MSG_INFO ); //任务参数 m_Server = upar.GetServer(); m_ServerPort = upar.GetPort(); m_Username = upar.GetUser(); m_Password = upar.GetPass(); m_EscFilePathName = upar.GetEscFilePathName(); //文件名 if ( upar.GetUrlType() == FTP_PROTOCOL ) //ftp { OutMsg( -1, _("Main URL is ftp type."), MSG_INFO ); m_pFtpInfo = new CMgFtpInfo( this, m_sUrl, m_nRetry, m_nRetryWait, -1 ); //set proxy here if ( m_bUseProxy ) { OutMsg( -1, _("Task will use socks proxy."), MSG_INFO ); m_pFtpInfo->SetProxy( m_Proxy, m_ProxyPort, m_ProxyUser, m_ProxyPass, m_ProxyVersion ); } if ( m_bUseFtpProxy ) { OutMsg( -1, _("Task will use ftp proxy."), MSG_INFO ); m_pFtpInfo->SetFtpProxy( m_FtpProxy, m_FtpProxyPort ); } //go if ( !m_pFtpInfo->GetInfo() ) { //error when get info. 2006/09/21 OutMsg( -1, _("Get file info error."), MSG_ERROR ); pthread_setcancelstate ( PTHREAD_CANCEL_DISABLE, &oldstate ); delete m_pFtpInfo; m_pFtpInfo = NULL; pthread_setcancelstate ( oldstate, NULL ); FinishTask( _TASK_ERROR ); pthread_exit( 0 ); } m_nFileLen = m_pFtpInfo->FileSize(); bool bresume = m_pFtpInfo->IsResume(); pthread_setcancelstate ( PTHREAD_CANCEL_DISABLE, &oldstate ); delete m_pFtpInfo; m_pFtpInfo = NULL; pthread_setcancelstate ( oldstate, NULL ); if ( m_nFileLen == -1 || !bresume ) { if ( m_nFileLen == -1 ) { OutMsg( -1, _("No file length got."), MSG_WARNNING ); } if ( !bresume ) { OutMsg( -1, _("Server cannot support resume method."), MSG_WARNNING ); } m_nAnts = 1; //FinishTask(_TASK_ERROR); //InitThreadQuit(); } } //main url ftp else if ( upar.GetUrlType() == HTTP_PROTOCOL ) { //http OutMsg( -1, _("Main URL is http type."), MSG_INFO ); m_pHttpInfo = new CMgHttpInfo( this, m_sUrl, m_nRetry, m_nRetryWait, upar.GetRefer(), -1 ); //if need proxy, make here if ( m_bUseProxy ) { OutMsg( -1, _("Task will use socks proxy."), MSG_INFO ); m_pHttpInfo->SetProxy( m_Proxy, m_ProxyPort, m_ProxyUser, m_ProxyPass, m_ProxyVersion ); } if ( m_bUseHttpProxy ) { OutMsg( -1, _("Task will use http proxy."), MSG_INFO ); m_pHttpInfo->SetHttpProxy( m_HttpProxy, m_HttpProxyPort ); } if ( !m_pHttpInfo->GetInfo() ) { //error when get info. OutMsg( -1, _("Get file info error."), MSG_ERROR ); pthread_setcancelstate ( PTHREAD_CANCEL_DISABLE, &oldstate ); delete m_pHttpInfo; m_pHttpInfo = NULL; pthread_setcancelstate ( oldstate, NULL ); FinishTask( _TASK_ERROR ); pthread_exit( 0 ); } if ( m_pHttpInfo->IsRedirect() ) { upar.SetRefer( m_sUrl ); m_sUrl = m_pHttpInfo->GetRedirect(); pthread_setcancelstate ( PTHREAD_CANCEL_DISABLE, &oldstate ); delete m_pHttpInfo; m_pHttpInfo = NULL; pthread_setcancelstate ( oldstate, NULL ); //跳转后就不再用原来的名字了。 if ( upar.SetUrl( m_sUrl ) ) { if ( upar.GetFileName() != string( "" ) ) m_sFilename = upar.GetFileName(); } goto again; } // for( int coo=0; coo < m_pHttpInfo->GetCookieNum(); coo++) // { // // cookie.push_back( m_pHttpInfo->GetCookie( coo ) ); // } m_nFileLen = m_pHttpInfo->GetFileSize(); pthread_setcancelstate ( PTHREAD_CANCEL_DISABLE, &oldstate ); delete m_pHttpInfo; m_pHttpInfo = NULL; pthread_setcancelstate ( oldstate, NULL ); if ( m_nFileLen == -1 ) { OutMsg( -1, _("No file length got."), MSG_WARNNING ); m_nAnts = 1; } } //http else { OutMsg( -1, c_str(_("Not a support URL type.")) + m_sUrl, MSG_ERROR ); FinishTask( _TASK_ERROR ); pthread_exit( 0 ); } //create file manager pthread_setcancelstate ( PTHREAD_CANCEL_DISABLE, &oldstate ); m_pFM = new CMgFileManager ( this, m_sUrl, m_sFilename, m_sSavePath, m_nFileLen, upar.GetRefer() ); pthread_setcancelstate ( oldstate, NULL ); //check file if ( !m_pFM->CheckFile() ) { pthread_setcancelstate ( PTHREAD_CANCEL_DISABLE, &oldstate ); delete m_pFM; m_pFM = NULL; pthread_setcancelstate ( oldstate, NULL ); FinishTask( _TASK_ERROR ); pthread_exit( 0 ); } //input mirror url std::vector<std::string>::const_iterator it; for ( it = m_sMirrorUrl.begin();it != m_sMirrorUrl.end();it++ ) { m_pFM->AddMirrorUrl( *it ); } //start work thread pthread_setcancelstate ( PTHREAD_CANCEL_DISABLE, &oldstate ); pthread_mutex_lock( &m_AntsMutex ); for ( int i = 0;i < m_nAnts;i++ ) { //not run when construct 2006/09/03 m_pAnts[ i ] = new CProAnts( this, //用于线程消息回送 m_pFM, i + 1, //线程自然数编号,回送消息时带上,用于分辨消息来源 m_nFileLen, m_nRetry, m_nRetryWait ); //if need proxy, make here if ( m_bUseProxy ) { m_pAnts[ i ] ->SetProxy( m_Proxy, m_ProxyPort, m_ProxyUser, m_ProxyPass, m_ProxyVersion ); } if ( m_bUseFtpProxy ) { m_pAnts[ i ] ->SetFtpProxy( m_FtpProxy, m_FtpProxyPort ); } if ( m_bUseHttpProxy ) { m_pAnts[ i ] ->SetHttpProxy( m_HttpProxy, m_HttpProxyPort ); } m_pAnts[ i ] ->Go(); } m_nRunningAnts = m_nAnts; m_bInitAnts = true; pthread_mutex_unlock( &m_AntsMutex ); pthread_setcancelstate ( oldstate, NULL ); pthread_exit( 0 ); }