void SimpleWebScraper::handleStreamRequest(string url_) { string str; try { //specify out url and open stream URI uri(url_); std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri)); //copy to our string StreamCopier::copyToString(*pStr.get(), str); } catch (Exception& exc) { cerr << exc.displayText() << std::endl; } //figure out how many bytes the image is and allocate int bytesToRead = str.size(); unsigned char * buff = new unsigned char [bytesToRead]; memset(buff, 0, bytesToRead); for(int i = 0; i < bytesToRead; i++){ buff[i] = str[i]; } args.buff = buff; args.bytesToRead = bytesToRead; }
/******************************************************************* * User::InfoPrint *******************************************************************/ TInt User_InfoPrint(const char* aString) { TPtrC8 pStr(reinterpret_cast<const TUint8*>(aString)); HBufC* buf = HBufC::New(pStr.Length()); if (buf == NULL) { return KErrNoMemory; } buf->Des().Copy(pStr); User::InfoPrint(*buf); return KErrNone; }
//------------------------------------------------------------- string API::makeAPICall( string method, map<string,string> args, Format format, bool bSigned ){ string path = buildAPICall( method, args, format, bSigned ); string result = ""; try { // Get REST style xml as string from flickr std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open( "https://" + api_base + path )); StreamCopier::copyToString(*pStr.get(), result); } catch (Exception &ex) { cerr << ex.displayText() << endl; } return result; }
TestDigestEngine(ScopedLogMessage& msg, const Poco::URI& uri, const char* passphrase=kPassphrase) : TestDigestEngineBase() { CreateDigestEngine(passphrase); Poco::DigestOutputStream dos(*m_pDigestEngine); std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri)); Poco::StreamCopier::copyStream(*pStr.get(), dos); dos.close(); std::string digestStr(Poco::DigestEngine::digestToHex(m_pDigestEngine->digest())); Poco::URI digestUri("http://poco.roundsquare.net/downloads/test."+digestName[N]); std::auto_ptr<std::istream> pStrDigest(Poco::URIStreamOpener::defaultOpener().open(digestUri)); std::stringstream ss; Poco::StreamCopier::copyStream(*pStrDigest.get(), ss); msg.Message(Poco::format(" %s: %s [%s]" , Poco::toUpper((4 == digestName[N].length()) ? digestName[N]:(" "+digestName[N])) , digestStr , std::string((0 == ss.str().compare(digestStr)) ? "OK":"NG")) ); }
void SimpleWebScraper::getStreamUnthreaded(string url_) { cout << "getStreamUnthreaded " << endl; url = url_; if(!factoryLoaded){ HTTPStreamFactory::registerFactory(); factoryLoaded = true; } string str; try { //specify out url and open stream URI uri(url_); std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri)); //copy to our string StreamCopier::copyToString(*pStr.get(), str); } catch (Exception& exc) { cerr << exc.displayText() << std::endl; } //figure out how many bytes the image is and allocate int bytesToRead = str.size(); unsigned char buff[bytesToRead]; memset(buff, 0, bytesToRead); for(int i = 0; i < bytesToRead; i++){ buff[i] = str[i]; } args.buff = buff; args.bytesToRead = bytesToRead; notifyUnthreadedStreamReceived(args); }
//---------------------------------------- // main //---------------------------------------- int main(int /*argc*/, char** /*argv*/) { PrepareConsoleLogger logger(Poco::Logger::ROOT, Poco::Message::PRIO_INFORMATION); ScopedLogMessage msg("TypeListTest ", "start", "end"); Poco::URI uri("http://poco.roundsquare.net/downloads/test.txt"); Poco::Net::HTTPStreamFactory::registerFactory(); std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri)); msg.Message(" source text:"); Poco::StreamCopier::copyStream(*pStr.get(), std::cout); std::vector<TestDigestEngineBase*> vec(kNumDigestType); #if (POCO_VERSION < 0x01040200) CreateTestDigestEngineInstances<eDigestTypeMD2>(vec, msg, uri); #else CreateTestDigestEngineInstances<eDigestTypeMD4>(vec, msg, uri); #endif std::for_each(vec.begin(), vec.end(), DeleteTestDigestEngineInstance()); return 0; }
//------------------------------------------------------------- void API::threadedFunction(){ while (isThreadRunning()){ // work through queue in order if ( APIqueue.size() > 0 ){ lock(); APICall apiCall = APIqueue.front(); APIqueue.erase(APIqueue.begin()); unlock(); string result = ""; string path; APIEvent args; switch (apiCall.type) { case FLICKR_GETMEDIA: path = buildAPICall( apiCall.method, apiCall.args, apiCall.format, apiCall.bSigned ); try { // Get REST style xml as string from flickr std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open( "https://" + api_base + path )); StreamCopier::copyToString(*pStr.get(), result); // get frob loadedMedia[apiCall.args["id"]] = Media(); loadedMedia[apiCall.args["id"]].loadFromXML( result ); args.results.push_back(loadedMedia[apiCall.args["id"]]); ofNotifyEvent(APIEvent::events, args); } catch (Exception &ex) { cerr << ex.displayText() << endl; } break; case FLICKR_SEARCH: path = buildAPICall( apiCall.method, apiCall.args, apiCall.format, apiCall.bSigned ); try { // Get REST style xml as string from flickr std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open( "https://" + api_base + path )); StreamCopier::copyToString(*pStr.get(), result); ofxXmlSettings xml; xml.loadFromBuffer(result); xml.pushTag("rsp");{ xml.pushTag("photos"); { for (int i=0; i<xml.getNumTags("photo"); i++){ Media med; med.id = xml.getAttribute("photo", "id", "", i); med.farm = xml.getAttribute("photo", "farm", "", i); med.secret = xml.getAttribute("photo", "secret", "", i); med.server = xml.getAttribute("photo", "server", "", i); med.originalsecret = xml.getAttribute("photo", "originalsecret", "", i); med.originalformat = xml.getAttribute("photo", "originalformat", "", i); string t = xml.getAttribute("photo", "media", "", i); if ( t == "photo"){ med.type = FLICKR_PHOTO; } else if ( t == "video"){ med.type = FLICKR_VIDEO; } else { med.type = FLICKR_UNKNOWN; } args.results.push_back(med); } } xml.popTag(); } xml.popTag(); ofNotifyEvent(APIEvent::events, args); } catch (Exception &ex) { cerr << ex.displayText() << endl; } break; case FLICKR_UPLOAD: args.resultString = doUpload( apiCall.method ); ofNotifyEvent(APIEvent::events, args); break; default: break; } } sleep(20); } }
//---------------------------------------- // main //---------------------------------------- int main(int /*argc*/, char** /*argv*/) { PrepareConsoleLogger logger(Poco::Logger::ROOT, Poco::Message::PRIO_INFORMATION); ScopedLogMessage msg("RegularExpressionTest ", "start", "end"); { Poco::FileOutputStream ostr(kOutputFileName); ostr << LeadingHTML; Poco::Net::HTTPStreamFactory::registerFactory(); Poco::URI uri(kSourceFileName); try { std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri)); std::stringstream ss; Poco::StreamCopier::copyStream(*pStr.get(), ss); msg.Message(Poco::format(" Finding out methods/enumerations from \"%s\".", std::string(kSourceFileName))); Poco::RegularExpression re("<a name=\"[0-9]+\">[A-Za-z]+</a>"); Poco::RegularExpression::Match match; match.offset = 0; while(0 != re.match(ss.str(), match.offset, match)) { std::string foundStr(ss.str().substr(match.offset, match.length)); std::string numStr; Poco::RegularExpression re_num("[0-9]+"); re_num.extract(foundStr, 0, numStr); std::string nameStr; Poco::RegularExpression re_name("[A-Za-z]+"); re_name.extract(foundStr, std::strlen("<a name=\"\">")+numStr.length(), nameStr); msg.Message(Poco::format(" found \"%s\"", nameStr)); ostr << "<tr><td><a href='" << uri.toString() << "#" << numStr << "' target='_blank'>" << nameStr << "</a></td>"; std::string descStr; Poco::RegularExpression re_desc("(description\">\n<p>)(.*)(</p>)"); Poco::RegularExpression::Match match_desc; if(re_desc.match(ss.str(), match.offset, match_desc)) { descStr = ss.str().substr(match_desc.offset, match_desc.length); re_desc.subst(descStr, "$2"); Poco::replaceInPlace(descStr, "\"", "'"); Poco::replaceInPlace(descStr, "href='Poco.", "href='http://pocoproject.org/docs/Poco."); } ostr << "<td>" << descStr << "</td></tr>" << std::endl; match.offset += match.length; } } catch(Poco::Exception& exc) { msg.Message(exc.displayText()); } ostr << TrailingHTML; } msg.Message(Poco::format(" HTML file \"%s\" created.", std::string(kOutputFileName))); return 0; }