FormCatched::FormCatched(const QString &f,const QString &url_page) { //CATCH ACTION / METHOD QRegExp action("action=['\"]?[^>'\"]+"); QRegExp method("method=['\"]?[^>'\"]+"); QUrl urlTmp(url_page); if(action.indexIn(f)!=-1) { this->url=action.capturedTexts().takeFirst(); this->url.replace(QRegExp("action=|'|\""),""); if(this->url.startsWith("/")) {//need to add the host this->url=urlTmp.scheme()+"://"+urlTmp.host()+this->url; } if(!this->url.startsWith("http://"))//here we will get a problem with https forms {//so we need to retrieve the path and add the url : int lastSlashe = urlTmp.path().lastIndexOf("/")+1; this->url=urlTmp.scheme()+"://"+urlTmp.host()+urlTmp.path().replace(lastSlashe,urlTmp.path().length()-lastSlashe,"")+this->url; } } if(method.indexIn(f)!=-1) { this->method=method.capturedTexts().takeFirst(); this->method.replace(QRegExp("method=|'|\""),""); } //CATCH ALL INPUTS QRegExp rx("<(input|textarea)[^>]*>"); QRegExp name("name=['\"]?(?:[^>'\"]+)"); QRegExp value("value=['\"]?[^>'\"]+"); input=new QList<QPair<QString,QString> >(); int pos=0; while((pos = rx.indexIn(f, pos)) != -1) {//here we got a <input.*> QString qs=rx.capturedTexts().takeFirst(); pos += rx.matchedLength(); if(name.indexIn(qs)!=-1) { QString nameContent = name.capturedTexts().takeFirst(); nameContent.replace(QRegExp("(name=|'|\")"),""); QString valueContent(""); if(value.indexIn(qs)!=-1) {//value aren't usefull without name so ... valueContent = value.capturedTexts().takeFirst(); valueContent.replace(QRegExp("(value=|'|\")"),""); } QPair<QString,QString> InputNamVal(nameContent,valueContent); input->push_back(InputNamVal); } } }
QUrl::QUrl( const QUrl& url, const QString& relUrl, bool checkSlash ) { d = new QUrlPrivate; QString rel = relUrl; slashify( rel ); QUrl urlTmp( url ); if ( !urlTmp.isValid() ) { urlTmp.reset(); } if ( isRelativeUrl( rel ) ) { if ( rel[ 0 ] == '#' ) { *this = urlTmp; rel.remove( (uint)0, 1 ); decode( rel ); setRef( rel ); } else if ( rel[ 0 ] == '?' ) { *this = urlTmp; rel.remove( (uint)0, 1 ); setQuery( rel ); } else { decode( rel ); *this = urlTmp; setRef( QString::null ); if ( checkSlash && d->cleanPath[(int)path().length()-1] != '/' ) { if ( isRelativeUrl( path() ) ) setEncodedPathAndQuery( rel ); else setFileName( rel ); } else { QString p = urlTmp.path(); if ( p.isEmpty() ) { // allow URLs like "file:foo" if ( !d->host.isEmpty() && !d->user.isEmpty() && !d->pass.isEmpty() ) p = "/"; } if ( !p.isEmpty() && p.right(1)!="/" ) p += "/"; p += rel; d->path = p; d->cleanPathDirty = TRUE; } } } else { if ( rel[ 0 ] == QChar( '/' ) ) { *this = urlTmp; setEncodedPathAndQuery( rel ); } else { *this = rel; } } }
// --------------------------------------------------------------------------- // Wrapper4DOMLSInput: Stream methods // --------------------------------------------------------------------------- BinInputStream* Wrapper4DOMLSInput::makeStream() const { // The LSParser will use the LSInput object to determine how to read data. The LSParser will look at the different inputs specified in the // LSInput in the following order to know which one to read from, the first one that is not null and not an empty string will be used: // 1. LSInput.characterStream // 2. LSInput.byteStream // 3. LSInput.stringData // 4. LSInput.systemId // 5. LSInput.publicId InputSource* binStream=fInputSource->getByteStream(); if(binStream) return binStream->makeStream(); const XMLCh* xmlString=fInputSource->getStringData(); if(xmlString) { MemBufInputSource is((const XMLByte*)xmlString, XMLString::stringLen(xmlString)*sizeof(XMLCh), "", false, getMemoryManager()); is.setCopyBufToStream(false); return is.makeStream(); } const XMLCh* szSystemId=fInputSource->getSystemId(); if(szSystemId) { XMLURL urlTmp(getMemoryManager()); if (urlTmp.setURL(szSystemId, fInputSource->getBaseURI(), urlTmp) && !urlTmp.isRelative()) { URLInputSource src(urlTmp, getMemoryManager()); return src.makeStream(); } LocalFileInputSource src(szSystemId, getMemoryManager()); return src.makeStream(); } const XMLCh* szPublicId=fInputSource->getPublicId(); if(szPublicId && fEntityResolver) { DOMLSInput* is = fEntityResolver->resolveResource(XMLUni::fgDOMDTDType, 0, szPublicId, 0, fInputSource->getBaseURI()); if (is) return Wrapper4DOMLSInput(is, fEntityResolver, true, getMemoryManager()).makeStream(); } return 0; }
int FlickrPrivate::upload(const FlickrPhoto &photo, const FlickrRequest &request, void* userData) { QByteArray boundary = generateBoundary(); QByteArray payload; QDataStream dataStream(&payload, QIODevice::WriteOnly); QMap<QString,QString> map = photo.args; map.insert("api_key", _apiKey); if(!_token.isEmpty()) { map.insert("auth_token", _token); } bool uploading = photo.photoId.isEmpty(); if(!uploading){ map.insert("photo_id", photo.photoId); } QMapIterator<QString, QString> i(map); QStringList keyList; while(i.hasNext()) { i.next(); keyList << i.key(); } qSort(keyList.begin(), keyList.end()); QString apiSig(_apiSecret); for(int i = 0; i < keyList.size(); ++i) { apiSig.append(keyList.at(i) + map.value(keyList.at(i))); QByteArray field = constructField(keyList.at(i),map.value(keyList.at(i)),boundary); dataStream.writeRawData(field.data(), field.length()); } apiSig = md5(apiSig); QByteArray sigField = constructField("api_sig", apiSig, boundary); dataStream.writeRawData(sigField.data(), sigField.length()); QByteArray fileField = constructField("photo", "", boundary, photo.file); dataStream.writeRawData(fileField.data(), fileField.length()); QFile file(photo.file); file.open(QIODevice::ReadOnly); while(!file.atEnd()) { QByteArray line = file.readLine(); dataStream.writeRawData(line.data(),line.length()); } file.close(); QByteArray endField; endField.append("\r\n--"); endField.append(boundary); endField.append("--\r\n\r\n"); dataStream.writeRawData(endField.data(), endField.length()); QString urlTmp("http://api.flickr.com/services/"); urlTmp.append((uploading)?"upload/":"replace/"); QNetworkRequest uploadRequest(urlTmp); uploadRequest.setRawHeader("Content-Type","multipart/form-data; boundary="+boundary); uploadRequest.setRawHeader("Host","ww.api.flickr.com"); _requestCounter++; RequestData requestData; requestData.request = request.requests; requestData.userData = userData; requestData.requestId = _requestCounter; QNetworkReply *reply = _networkAccessManager->post(uploadRequest,payload); connect(reply,SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64))); requestDataMap.insert(reply,requestData); return requestData.requestId; }
XMLReader* ReaderMgr::createReader( const XMLCh* const baseURI , const XMLCh* const sysId , const XMLCh* const pubId , const bool xmlDecl , const XMLReader::RefFrom refFrom , const XMLReader::Types type , const XMLReader::Sources source , InputSource*& srcToFill , const bool calcSrcOfs) { // Create a buffer for expanding the system id XMLBuffer expSysId(1023, fMemoryManager); // // Allow the entity handler to expand the system id if they choose // to do so. // if (fEntityHandler) { if (!fEntityHandler->expandSystemId(sysId, expSysId)) expSysId.set(sysId); } else { expSysId.set(sysId); } // Call the entity resolver interface to get an input source srcToFill = 0; if (fEntityHandler) { XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity, expSysId.getRawBuffer(), XMLUni::fgZeroLenString, pubId, baseURI); srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier); } // // If they didn't create a source via the entity resolver, then we // have to create one on our own. // if (!srcToFill) { LastExtEntityInfo lastInfo; getLastExtEntityInfo(lastInfo); XMLURL urlTmp(fMemoryManager); if ((!urlTmp.setURL((!baseURI || !*baseURI) ? lastInfo.systemId : baseURI, expSysId.getRawBuffer(), urlTmp)) || (urlTmp.isRelative())) { if (!fStandardUriConformant) srcToFill = new (fMemoryManager) LocalFileInputSource ( lastInfo.systemId , expSysId.getRawBuffer() , fMemoryManager ); else ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } else { if (fStandardUriConformant && urlTmp.hasInvalidChar()) ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); } } // Put a janitor on the input source Janitor<InputSource> janSrc(srcToFill); // // Now call the other version with the input source that we have, and // return the resulting reader. // XMLReader* retVal = createReader ( *srcToFill , xmlDecl , refFrom , type , source , calcSrcOfs ); // Either way, we can release the input source now janSrc.orphan(); // If it failed for any reason, then return zero. if (!retVal) return 0; // Give this reader the next available reader number and return it retVal->setReaderNum(fNextReaderNum++); return retVal; }
XMLReader* ReaderMgr::createReader( const XMLCh* const sysId , const XMLCh* const pubId , const bool xmlDecl , const XMLReader::RefFrom refFrom , const XMLReader::Types type , const XMLReader::Sources source , InputSource*& srcToFill , const bool calcSrcOfs , XMLSize_t lowWaterMark , const bool disableDefaultEntityResolution) { //Normalize sysId XMLBuffer normalizedSysId(1023, fMemoryManager); if(sysId) XMLString::removeChar(sysId, 0xFFFF, normalizedSysId); const XMLCh* normalizedURI = normalizedSysId.getRawBuffer(); // Create a buffer for expanding the system id XMLBuffer expSysId(1023, fMemoryManager); // // Allow the entity handler to expand the system id if they choose // to do so. // if (fEntityHandler) { if (!fEntityHandler->expandSystemId(normalizedURI, expSysId)) expSysId.set(normalizedURI); } else { expSysId.set(normalizedURI); } // Call the entity resolver interface to get an input source srcToFill = 0; if (fEntityHandler) { LastExtEntityInfo lastInfo; getLastExtEntityInfo(lastInfo); XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity, expSysId.getRawBuffer(), XMLUni::fgZeroLenString, pubId, lastInfo.systemId, this); srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier); } // // If they didn't create a source via the entity resolver, then we // have to create one on our own. // if (!srcToFill) { if (disableDefaultEntityResolution) return 0; LastExtEntityInfo lastInfo; getLastExtEntityInfo(lastInfo); // Keep this #if 0 block as it was exposing a threading problem on AIX. // Got rid of the problem by changing XMLURL to not throw malformedurl // exceptions. #if 0 try { XMLURL urlTmp(lastInfo.systemId, expSysId.getRawBuffer(), fMemoryManager); if (urlTmp.isRelative()) { ThrowXMLwithMemMgr ( MalformedURLException , XMLExcepts::URL_NoProtocolPresent , fMemoryManager ); } else { if (fStandardUriConformant && urlTmp.hasInvalidChar()) ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); } } catch(const MalformedURLException& e) { // Its not a URL, so lets assume its a local file name if non-standard uri is allowed if (!fStandardUriConformant) srcToFill = new (fMemoryManager) LocalFileInputSource ( lastInfo.systemId , expSysId.getRawBuffer() , fMemoryManager ); else throw e; } #else XMLURL urlTmp(fMemoryManager); if ((!urlTmp.setURL(lastInfo.systemId, expSysId.getRawBuffer(), urlTmp)) || (urlTmp.isRelative())) { if (!fStandardUriConformant) { XMLBuffer resolvedSysId(1023, fMemoryManager); XMLUri::normalizeURI(expSysId.getRawBuffer(), resolvedSysId); srcToFill = new (fMemoryManager) LocalFileInputSource ( lastInfo.systemId , resolvedSysId.getRawBuffer() , fMemoryManager ); } else ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } else { if (fStandardUriConformant && urlTmp.hasInvalidChar()) ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); } #endif } // Put a janitor on the input source Janitor<InputSource> janSrc(srcToFill); // // Now call the other version with the input source that we have, and // return the resulting reader. // XMLReader* retVal = createReader ( *srcToFill , xmlDecl , refFrom , type , source , calcSrcOfs , lowWaterMark ); // Either way, we can release the input source now janSrc.orphan(); // If it failed for any reason, then return zero. if (!retVal) return 0; // Give this reader the next available reader number and return it retVal->setReaderNum(fNextReaderNum++); return retVal; }