http.cc
来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· CC 代码 · 共 2,361 行 · 第 1/5 页
CC
2,361 行
return; m_request.method = HTTP_DELETE; m_request.path = url.path(); m_request.query = QString::null; m_request.cache = CC_Reload; m_request.doProxy = m_bUseProxy; retrieveHeader( false ); // The server returns a HTTP/1.1 200 Ok or HTTP/1.1 204 No Content // on successful completion if ( m_responseCode == 200 || m_responseCode == 204 ) davFinished(); else davError();}#endifvoid HTTPProtocol::post( const KURL& url ){ kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::post " << url.prettyURL() << endl; if ( !checkRequestURL( url ) ) return; m_request.method = HTTP_POST; m_request.path = url.path(); m_request.query = url.query(); m_request.cache = CC_Reload; m_request.doProxy = m_bUseProxy; retrieveContent();}#if !defined(QT_NO_DOM)void HTTPProtocol::davLock( const KURL& url, const QString& scope, const QString& type, const QString& owner ){ kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::davLock " << url.prettyURL() << endl; if ( !checkRequestURL( url ) ) return; m_request.method = DAV_LOCK; m_request.path = url.path(); m_request.query = QString::null; m_request.cache = CC_Reload; m_request.doProxy = m_bUseProxy; /* Create appropriate lock XML request. */ QDomDocument lockReq; QDomElement lockInfo = lockReq.createElementNS( "DAV:", "lockinfo" ); lockReq.appendChild( lockInfo ); QDomElement lockScope = lockReq.createElement( "lockscope" ); lockInfo.appendChild( lockScope ); lockScope.appendChild( lockReq.createElement( scope ) ); QDomElement lockType = lockReq.createElement( "locktype" ); lockInfo.appendChild( lockType ); lockType.appendChild( lockReq.createElement( type ) ); if ( !owner.isNull() ) { QDomElement ownerElement = lockReq.createElement( "owner" ); lockReq.appendChild( ownerElement ); QDomElement ownerHref = lockReq.createElement( "href" ); ownerElement.appendChild( ownerHref ); ownerHref.appendChild( lockReq.createTextNode( owner ) ); } // insert the document into the POST buffer m_bufPOST = lockReq.toCString(); retrieveContent( true ); if ( m_responseCode == 200 ) { // success QDomDocument multiResponse; multiResponse.setContent( m_bufWebDavData, true ); QDomElement prop = multiResponse.documentElement().namedItem( "prop" ).toElement(); QDomElement lockdiscovery = prop.namedItem( "lockdiscovery" ).toElement(); uint lockCount = 0; davParseActiveLocks( lockdiscovery.elementsByTagName( "activelock" ), lockCount ); setMetaData( "davLockCount", QString("%1").arg( lockCount ) ); finished(); } else davError();}void HTTPProtocol::davUnlock( const KURL& url ){ kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::davUnlock " << url.prettyURL() << endl; if ( !checkRequestURL( url ) ) return; m_request.method = DAV_UNLOCK; m_request.path = url.path(); m_request.query = QString::null; m_request.cache = CC_Reload; m_request.doProxy = m_bUseProxy; retrieveContent( true ); if ( m_responseCode == 200 ) finished(); else davError();}QString HTTPProtocol::davError( int code /* = -1 */, QString url ){ bool callError = false; if ( code == -1 ) { code = m_responseCode; callError = true; } if ( code == -2 ) { callError = true; } if ( !url.isNull() ) url = m_request.url.url(); QString action, errorString; KIO::Error kError; // for 412 Precondition Failed QString ow = i18n( "Otherwise, the request would have succeeded." ); switch ( m_request.method ) { case DAV_PROPFIND: action = i18n( "retrieve property values" ); break; case DAV_PROPPATCH: action = i18n( "set property values" ); break; case DAV_MKCOL: action = i18n( "create the requested folder" ); break; case DAV_COPY: action = i18n( "copy the specified file or folder" ); break; case DAV_MOVE: action = i18n( "move the specified file or folder" ); break; case DAV_SEARCH: action = i18n( "search in the specified folder" ); break; case DAV_LOCK: action = i18n( "lock the specified file or folder" ); break; case DAV_UNLOCK: action = i18n( "unlock the specified file or folder" ); break; case HTTP_DELETE: action = i18n( "delete the specified file or folder" ); break; case HTTP_OPTIONS: action = i18n( "query the server's capabilities" ); break; case HTTP_GET: action = i18n( "retrieve the contents of the specified file or folder" ); break; case HTTP_PUT: case HTTP_POST: case HTTP_HEAD: default: // this should not happen, this function is for webdav errors only Q_ASSERT(0); } // default error message if the following code fails kError = ERR_INTERNAL; errorString = i18n("An unexpected error (%1) occurred while attempting to %2.") .arg( code ).arg( action ); switch ( code ) { case -2: // internal error: OPTIONS request did not specify DAV compliance kError = ERR_UNSUPPORTED_PROTOCOL; errorString = i18n("The server does not support the WebDAV protocol."); break; case 207: // 207 Multi-status { // our error info is in the returned XML document. // retrieve the XML document // there was an error retrieving the XML document. // ironic, eh? if ( !readBody( true ) && m_bError ) return QString::null; QStringList errors; QDomDocument multiResponse; multiResponse.setContent( m_bufWebDavData, true ); QDomElement multistatus = multiResponse.documentElement().namedItem( "multistatus" ).toElement(); QDomNodeList responses = multistatus.elementsByTagName( "response" ); for (uint i = 0; i < responses.count(); i++) { int errCode; QString errUrl; QDomElement response = responses.item(i).toElement(); QDomElement code = response.namedItem( "status" ).toElement(); if ( !code.isNull() ) { errCode = codeFromResponse( code.text() ); QDomElement href = response.namedItem( "href" ).toElement(); if ( !href.isNull() ) errUrl = href.text(); errors << davError( errCode, errUrl ); } } //kError = ERR_SLAVE_DEFINED; errorString = i18n("An error occurred while attempting to %1, %2. A " "summary of the reasons is below.<ul>").arg( action ).arg( url ); for ( QStringList::Iterator it = errors.begin(); it != errors.end(); ++it ) errorString += "<li>" + *it + "</li>"; errorString += "</ul>"; } case 403: case 500: // hack: Apache mod_dav returns this instead of 403 (!) // 403 Forbidden kError = ERR_ACCESS_DENIED; errorString = i18n("Access was denied while attempting to %1.").arg( action ); break; case 405: // 405 Method Not Allowed if ( m_request.method == DAV_MKCOL ) { kError = ERR_DIR_ALREADY_EXIST; errorString = i18n("The specified folder already exists."); } break; case 409: // 409 Conflict kError = ERR_ACCESS_DENIED; errorString = i18n("A resource cannot be created at the destination " "until one or more intermediate collections (folders) " "have been created."); break; case 412: // 412 Precondition failed if ( m_request.method == DAV_COPY || m_request.method == DAV_MOVE ) { kError = ERR_ACCESS_DENIED; errorString = i18n("The server was unable to maintain the liveness of " "the properties listed in the propertybehavior XML " "element or you attempted to overwrite a file while " "requesting that files are not overwritten. %1") .arg( ow ); } else if ( m_request.method == DAV_LOCK ) { kError = ERR_ACCESS_DENIED; errorString = i18n("The requested lock could not be granted. %1").arg( ow ); } break; case 415: // 415 Unsupported Media Type kError = ERR_ACCESS_DENIED; errorString = i18n("The server does not support the request type of the body."); break; case 423: // 423 Locked kError = ERR_ACCESS_DENIED; errorString = i18n("Unable to %1 because the resource is locked.").arg( action ); break; case 425: // 424 Failed Dependency errorString = i18n("This action was prevented by another error."); break; case 502: // 502 Bad Gateway if ( m_request.method == DAV_COPY || m_request.method == DAV_MOVE ) { kError = ERR_WRITE_ACCESS_DENIED; errorString = i18n("Unable to %1 because the destination server refuses " "to accept the file or folder.").arg( action ); } break; case 507: // 507 Insufficient Storage kError = ERR_DISK_FULL; errorString = i18n("The destination resource does not have sufficient space " "to record the state of the resource after the execution " "of this method."); break; } // if ( kError != ERR_SLAVE_DEFINED ) //errorString += " (" + url + ")"; if ( callError ) error( ERR_SLAVE_DEFINED, errorString ); return errorString;}#endifvoid HTTPProtocol::httpError(){ QString action, errorString; KIO::Error kError; switch ( m_request.method ) { case HTTP_PUT: action = i18n( "upload %1" ).arg(m_request.url.prettyURL()); break; default: // this should not happen, this function is for http errors only Q_ASSERT(0); } // default error message if the following code fails kError = ERR_INTERNAL; errorString = i18n("An unexpected error (%1) occurred while attempting to %2.") .arg( m_responseCode ).arg( action ); switch ( m_responseCode ) { case 403: case 405: case 500: // hack: Apache mod_dav returns this instead of 403 (!) // 403 Forbidden // 405 Method Not Allowed kError = ERR_ACCESS_DENIED; errorString = i18n("Access was denied while attempting to %1.").arg( action ); break; case 409: // 409 Conflict kError = ERR_ACCESS_DENIED; errorString = i18n("A resource cannot be created at the destination " "until one or more intermediate collections (folders) " "have been created."); break; case 423: // 423 Locked kError = ERR_ACCESS_DENIED; errorString = i18n("Unable to %1 because the resource is locked.").arg( action ); break; case 502: // 502 Bad Gateway kError = ERR_WRITE_ACCESS_DENIED; errorString = i18n("Unable to %1 because the destination server refuses " "to accept the file or folder.").arg( action ); break; case 507: // 507 Insufficient Storage kError = ERR_DISK_FULL; errorString = i18n("The destination resource does not have sufficient space " "to record the state of the resource after the execution " "of this method."); break; } // if ( kError != ERR_SLAVE_DEFINED ) //errorString += " (" + url + ")"; error( ERR_SLAVE_DEFINED, errorString );}bool HTTPProtocol::isOffline(const KURL &url){ const int NetWorkStatusUnknown = 1; const int NetWorkStatusOnline = 8; QCString replyType; QByteArray params; QByteArray reply; QDataStream stream(params, IO_WriteOnly); stream << url.url(); if ( dcopClient()->call( "kded", "networkstatus", "status(QString)", params, replyType, reply ) && (replyType == "int") ) { int result; QDataStream stream2( reply, IO_ReadOnly ); stream2 >> result; kdDebug(7113) << "(" << m_pid << ") networkstatus status = " << result << endl; return (result != NetWorkStatusUnknown) && (result != NetWorkStatusOnline); } kdDebug(7113) << "(" << m_pid << ") networkstatus <unreachable>" << endl; return false; // On error, assume we are online}void HTTPProtocol::multiGet(const QByteArray &data){ QDataStream stream(data, IO_ReadOnly); Q_UINT32 n; stream >> n; kdDebug(7113) << "(" << m_pid << ") HTTPProtcool::multiGet n = " << n << endl; HTTPRequest saveRequest; if (m_bBusy) saveRequest = m_request;// m_requestQueue.clear(); for(unsigned i = 0; i < n; i++) { KURL url; stream >> url >> mIncomingMetaData; if ( !checkRequestURL( url ) ) continue; kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::multi_get " << url.url() << endl; m_request.method = HTTP_GET; m_request.path = url.path(); m_request.query = url.query(); QString tmp = metaData("cache"); if (!tmp.isEmpty()) m_request.cache = parseCacheControl(tmp); else m_request.cache = DEFAULT_CACHE_CONTROL; m_request.passwd = url.pass(); m_request.user = url.user(); m_request.doProxy = m_bUseProxy; HTTPRequest *newRequest = new HTTPRequest(m_request); m_requestQueue.append(newRequest); } if (m_bBusy) m_request = saveRequest; if (!m_bBusy) { m_bBusy = true; while(!m_requestQueue.isEmpty()) { HTTPRequest *request = m_requestQueue.take(0); m_request = *request; delete request; retrieveContent(); } m_bBusy = false; }}ssize_t HTTPProtocol::write (const void *_buf, size_t nbytes){ int bytes_sent = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?