void listener() { //start timer: struct timeval tv,tv1; gettimeofday(&tv,NULL); int start_time; memcpy(&start_time, &tv.tv_sec, sizeof(int)); //timeout: tv1.tv_sec=PERS_TIME_OUT; tv1.tv_usec=0; setsockopt(newsockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv1,sizeof(struct timeval)); while(tv.tv_sec-start_time<PERS_TIME_OUT) { recv(newsockfd,buf,4096,0); if(std::string(buf).length()==0) { //probably just tcp keepalive message, ignore. gettimeofday(&tv,NULL); continue; } parseRequest(buf); memset(buf,0,4096); std::string content=serializeFile(this->requestFile.c_str()); sendStr(content.c_str(),content.length()); gettimeofday(&tv,NULL); } return; }
string GitFileManager::serializeAllFiles(){ stringstream fileText; for(int i = 0; i < m_fileList.size(); i++){ fileText << serializeFile(m_fileList[i]) << endl; } return fileText.str(); }
api_return ViewFileApi::handleGetFiles(ApiRequest& aRequest) { auto ret = json::array(); auto files = ViewFileManager::getInstance()->getFiles(); for (const auto& file : files | map_values) { ret.push_back(serializeFile(file)); } aRequest.setResponseBody(ret); return websocketpp::http::status_code::ok; }
//non-persistent service: void serviceRequest() { //printf("non-persistent service\n"); //first, create a thread that listens for requests. //int reqsize=read(newsockfd, buf, 4096); read(newsockfd,buf,4096); parseRequest(buf); memset(buf,0,4096); std::string content= serializeFile(this->requestFile.c_str()); //std::cout<<"content:\n"<<content<<std::endl; sendStr(content.c_str(),content.length()); }
TEST_F(WebPageSerializerTest, EncodingAndNormalization) { const char* expectedHTML = "<!DOCTYPE html>\n" "<!-- saved from url=(0020)http://www.test.com/ -->\n" "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-KR\">\n" "<title>Ensure NFC normalization is not performed by page serializer</title>\n" "</head><body>\n" "\xe4\xc5\xd1\xe2\n" "\n</body></html>"; String actualHTML = serializeFile("http://www.test.com", "encoding_normalization.html"); EXPECT_EQ(expectedHTML, actualHTML); }
TEST_F(WebPageSerializerTest, URLAttributeValues) { registerMockedImageURL("javascript:\""); const char* expectedHTML = "\n<!-- saved from url=(0020)http://www.test.com/ -->\n" "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" "</head><body><img src=\"javascript:"\">\n" "<a href=\"http://www.test.com/local#"\">local</a>\n" "<a href=\"http://www.example.com/#"><script>alert(0)</script>\">external</a>\n" "</body></html>"; String actualHTML = serializeFile("http://www.test.com", "url_attribute_values.html"); EXPECT_EQ(expectedHTML, actualHTML); }
void ViewFileApi::onViewFileUpdated(const ViewFilePtr& aFile) noexcept { maybeSend("view_file_updated", [&] { return serializeFile(aFile); }); }
void ViewFileApi::on(ViewFileManagerListener::FileFinished, const ViewFilePtr& aFile) noexcept { onViewFileUpdated(aFile); maybeSend("view_file_finished", [&] { return serializeFile(aFile); }); }
void ViewFileApi::on(ViewFileManagerListener::FileAdded, const ViewFilePtr& aFile) noexcept { maybeSend("view_file_added", [&] { return serializeFile(aFile); }); }
TEST_F(WebPageSerializerTest, FromUrlWithMinusMinus) { String actualHTML = serializeFile("http://www.test.com?--x--", "text_only_page.html"); EXPECT_EQ("<!-- saved from url=(0030)http://www.test.com/?-%2Dx-%2D -->", actualHTML.substring(1, 60)); }
QString MyString::dataToPullbackDotString(Data *data) { QString buffer; //exp buffer += MyString::stateVectorToPullbackString(data->affordanceStates); buffer += MyString::arrowVectorToPullbackString(data->affordanceEdges); buffer += MyString::stateVectorToPullbackString(data->actionStates); buffer += MyString::arrowVectorToPullbackString(data->actionEdges); buffer += MyString::stateVectorToPullbackString(data->abstractStates); buffer += MyString::arrowVectorToPullbackString(data->abstractEdges); buffer += MyString::stateMappingsToPullbackString(data->mapAffordanceToAbstractNodes); //separate collection for states needed? buffer += "\n"; buffer += MyString::edgeMappingsToPullbackString(data->mapAffordanceToAbstractEdges); buffer += "\n"; buffer += MyString::stateMappingsToPullbackString(data->mapActionToAbstractNodes); buffer += "\n"; buffer += MyString::edgeMappingsToPullbackString(data->mapActionToAbstractEdges); buffer += "\n"; //fetch dot file from Haskell routine QString tempPath = QDir::tempPath(); QString serializePath, dotPath; for (int i = 0; ; i++) { serializePath = tempPath; serializePath += "/uic"; serializePath += QString::number(i); serializePath += + ".txt"; if (!QFile::exists(serializePath)) break; } for (int j = 0; ; j++) { dotPath = tempPath; dotPath += "/uic"; dotPath += QString::number(j); dotPath += ".dot"; if (!QFile::exists(dotPath)) break; } QFile serializeFile(serializePath); serializeFile.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&serializeFile); out << buffer; serializeFile.close(); //qDebug() << "Wrote string:\n" << buffer << "to file: " << serializePath; #ifdef Q_OS_LINUX QProcess::execute("cd /tmp"); #endif QString haskellCmd; haskellCmd += QCoreApplication::applicationDirPath(); haskellCmd += "/bin/pullbacks_first "; haskellCmd += serializePath; haskellCmd += " "; haskellCmd += dotPath; qDebug() << haskellCmd; int ret = QProcess::execute(haskellCmd); if (ret) { qDebug() << "Haskell command returned error value"; qDebug() << "Wrote string:\n" << buffer << "to file: " << serializePath; return ""; } //read dot file QString dot; QFile file; file.setFileName(dotPath); file.open(QIODevice::ReadOnly); dot = file.readAll(); file.close(); return dot; }