bool KManualProxyDlg::validate() { KURL filteredURL; unsigned short count = 0; if ( isValidURL( mDlg->leHttp->text(), &filteredURL ) ) { mDlg->leHttp->setText( filteredURL.url() ); count++; } else setHighLight( mDlg->lbHttp, true ); if ( !mDlg->cbSameProxy->isChecked () ) { if ( isValidURL( mDlg->leHttps->text(), &filteredURL ) ) { mDlg->leHttps->setText( filteredURL.url() ); count++; } else setHighLight( mDlg->lbHttps, true ); if ( isValidURL( mDlg->leFtp->text(), &filteredURL ) ) { mDlg->leFtp->setText( filteredURL.url() ); count++; } else setHighLight( mDlg->lbFtp, true ); } if ( count == 0 ) { showErrorMsg( i18n("Invalid Proxy Setting"), i18n("One or more of the specified proxy settings are " "invalid. The incorrect entries are highlighted.") ); } return (count > 0); }
bool KManualProxyDlg::getException ( QString& result, const QString& caption, const QString& value ) { QString label; // Specify the appropriate message... if ( mDlg->cbReverseProxy->isChecked() ) label = i18n("Enter the URL or address that should use the above proxy " "settings:"); else label = i18n("Enter the address or URL that should be excluded from " "using the above proxy settings:"); QString whatsThis = i18n("<qt>Enter a valid address or url.<p>" "<b><u>NOTE:</u></b> Wildcard matching such as " "<code>*.kde.org</code> is not supported. If you want " "to match any host in the <code>.kde.org</code> domain, " "e.g. <code>printing.kde.org</code>, then simply enter " "<code>.kde.org</code></qt>"); bool ok; result = KInputDialog::text( caption, label, value, &ok, 0, 0, 0, QString::null, whatsThis ); // If the user pressed cancel, do nothing... if (!ok) return false; // If the typed URL is malformed, and the filters cannot filter it // then it must be an invalid entry, if( isValidURL(result) || (result.length() >= 3 && result.startsWith("."))) return true; showErrorMsg(); return false; }
void KManualProxyDlg::setProxyData( const KProxyData &data ) { KURL url; // Set the HTTP proxy... if (!isValidURL(data.proxyList["http"], &url)) mDlg->sbHttp->setValue( DEFAULT_PROXY_PORT ); else { int port = url.port(); if ( port <= 0 ) port = DEFAULT_PROXY_PORT; url.setPort( 0 ); mDlg->leHttp->setText( url.url() ); mDlg->sbHttp->setValue( port ); } bool useSameProxy = (!mDlg->leHttp->text().isEmpty () && data.proxyList["http"] == data.proxyList["https"] && data.proxyList["http"] == data.proxyList["ftp"]); mDlg->cbSameProxy->setChecked ( useSameProxy ); if ( useSameProxy ) { mDlg->leHttps->setText ( mDlg->leHttp->text() ); mDlg->leFtp->setText ( mDlg->leHttp->text() ); mDlg->sbHttps->setValue( mDlg->sbHttp->value() ); mDlg->sbFtp->setValue( mDlg->sbHttp->value() ); sameProxy ( true ); } else { // Set the HTTPS proxy... if( !isValidURL( data.proxyList["https"], &url ) ) mDlg->sbHttps->setValue( DEFAULT_PROXY_PORT ); else { int port = url.port(); if ( port <= 0 ) port = DEFAULT_PROXY_PORT; url.setPort( 0 ); mDlg->leHttps->setText( url.url() ); mDlg->sbHttps->setValue( port ); } // Set the FTP proxy... if( !isValidURL( data.proxyList["ftp"], &url ) ) mDlg->sbFtp->setValue( DEFAULT_PROXY_PORT ); else { int port = url.port(); if ( port <= 0 ) port = DEFAULT_PROXY_PORT; url.setPort( 0 ); mDlg->leFtp->setText( url.url() ); mDlg->sbFtp->setValue( port ); } } QStringList::ConstIterator it = data.noProxyFor.begin(); for( ; it != data.noProxyFor.end(); ++it ) { // "no_proxy" is a keyword used by the environment variable // based configuration. We ignore it here as it is not applicable... if ((*it).lower() != "no_proxy" && !(*it).isEmpty()) { // Validate the NOPROXYFOR entries and use only hostnames if the entry is // a valid or legitimate URL. NOTE: needed to catch manual manipulation // of the proxy config files... if( isValidURL( *it ) || ((*it).length() >= 3 && (*it).startsWith(".")) ) mDlg->lbExceptions->insertItem( *it ); } } mDlg->cbReverseProxy->setChecked( data.useReverseProxy ); }
/*--------------------------------------------------------------------------*/ httpdownloadfile_error_code httpDownloadFile(char * szURL,char * szSaveFilePath) { if (isValidURL(szURL)) { HINTERNET hiConnex = NULL; /* * / * : /*rfc 2616 protocole http. all files type accepted*/ char szHeader[]="Accept: */*\r\n\r\n"; HINTERNET hiDownload; hiConnex = dynlib_InternetOpen("Scilab_Download", OPENURL_MODE,NULL,NULL,0); if(hiConnex == NULL) return HTTP_DOWNLOAD_ERROR_INTERNET_OPEN; hiDownload = dynlib_InternetOpenUrl(hiConnex,szURL,szHeader,lstrlen(szHeader),INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE,0); if(!hiDownload) { dynlib_InternetCloseHandle(hiConnex); return HTTP_DOWNLOAD_ERROR_OPEN_URL; } else { HANDLE haFile; haFile = CreateFile(szSaveFilePath,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,0,0); if(haFile == INVALID_HANDLE_VALUE) { dynlib_InternetCloseHandle(hiConnex); return HTTP_DOWNLOAD_ERROR_CREATEFILE; } else { char *szBuff = NULL; DWORD dwBytesRequired = 0; DWORD dwSizeOfByReq = 4; DWORD dwBytesRead = 0; DWORD dwBytesWritten = 0; /* Get file size */ if(!dynlib_HttpQueryInfo(hiDownload,HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,(LPVOID)&dwBytesRequired,&dwSizeOfByReq,0)) { dynlib_InternetCloseHandle(hiConnex); return HTTP_DOWNLOAD_ERROR_INVALID_FILE_SIZE; } else { if(dwBytesRequired > MO) { szBuff = (char*)MALLOC(MO); if(szBuff == NULL) { CloseHandle(haFile); dynlib_InternetCloseHandle(hiConnex); return HTTP_DOWNLOAD_OUTOFMEMORY; } } else { szBuff = (char*)MALLOC(dwBytesRequired); if(szBuff == NULL) { CloseHandle(haFile); dynlib_InternetCloseHandle(hiConnex); return HTTP_DOWNLOAD_OUTOFMEMORY; } } while(dwBytesRequired > 0) { /* we read 1Mo from file. */ if(dwBytesRequired >= MO) { if(!dynlib_InternetReadFile(hiDownload,szBuff,MO,&dwBytesRead) || dwBytesRead != MO) { CloseHandle(haFile); dynlib_InternetCloseHandle(hiConnex); FREE(szBuff); return HTTP_DOWNLOAD_ERROR_INTERNET_READFILE; } dwBytesRequired -= MO; /* we write buffer */ if(!WriteFile(haFile,szBuff,MO,&dwBytesWritten,NULL) || dwBytesWritten != MO) { CloseHandle(haFile); dynlib_InternetCloseHandle(hiConnex); FREE(szBuff); return HTTP_DOWNLOAD_ERROR_WRITEFILE; } } else { if(!dynlib_InternetReadFile(hiDownload,szBuff,dwBytesRequired,&dwBytesRead) || dwBytesRead != dwBytesRequired) { CloseHandle(haFile); dynlib_InternetCloseHandle(hiConnex); FREE(szBuff); return HTTP_DOWNLOAD_ERROR_INTERNET_READFILE; } /* we write buffer in a backup file*/ if(!WriteFile(haFile,szBuff,dwBytesRequired,&dwBytesWritten,NULL) || dwBytesWritten != dwBytesRequired) { CloseHandle(haFile); dynlib_InternetCloseHandle(hiConnex); FREE(szBuff); return HTTP_DOWNLOAD_ERROR_WRITEFILE; } dwBytesRequired = 0; } } dynlib_InternetCloseHandle(hiConnex); CloseHandle(haFile); FREE(szBuff); return HTTP_DOWNLOAD_ERROR_OK; } } } } else return HTTP_DOWNLOAD_ERROR_INVALID_URL; }