int heading(void) { char *o, *s, *e; int n; for(s = "======"; *s; s++) if(got(s)) break; if(*s == 0) return 0; n = strlen(s); e = look("=", look("\n", nil)); if(e == nil) e = look("\n", nil); if(e == nil) e = epos; eatspace(); string("<h"); output("0123456"+n, 1); string("><a name=\""); o = pos; s = trimback(e); while(pos < s){ if((*pos >= 'a' && *pos <= 'z') || (*pos >= 'A' && *pos <= 'Z') || (*pos >= '0' && *pos <= '9') || (strchr("!#$%()_+,-./{|}~:;=?@[\\]^_`", *pos) != 0)) output(pos, 1); else if(*pos == ' ' || *pos == '\t') output("_", 1); else if(*pos == '<') string("<"); else if(*pos == '>') string(">"); else if(*pos == '&') string("&"); else if(*pos == '"') string("""); else if(*pos == '\'') string("'"); pos++; } string("\"></a>"); pos = o; ebody(e); while(got("=")) ; string("</h"); output("0123456"+n, 1); string(">"); return 1; }
void PlayerStatus::gotReply(QNetworkReply* reply) { StrAbstractor commTcpi(QString(reply->readAll())); QString status = commTcpi.midStr("status=\"","\""); if (status != "ok") { QString code = commTcpi.midStr("<code>","</code>"); emit error(code); return; } const QString& broadID = commTcpi.midStr("<id>", "</id>"); const QString& title = commTcpi.midStr("<title>", "</title>"); const QString& communityID = commTcpi.midStr("<default_community>", "</default_community>"); const QString& ownerID = commTcpi.midStr("<owner_id>", "</owner_id>"); const QString& ownerName = commTcpi.midStr("<owner_name>", "</owner_name>"); const uint stTime = commTcpi.midStr("<start_time>","</start_time>").toUInt(); const uint edTime = commTcpi.midStr("<end_time>","</end_time>").toUInt(); const QString& broadcastToken = commTcpi.midStr("<broadcast_token>","</broadcast_token>"); const QString& userID = commTcpi.midStr("<user_id>", "</user_id>"); const bool isPremium = commTcpi.midStr("<is_premium>", "</is_premium>")!="0"; const QString& addr = commTcpi.midStr("<addr>", "</addr>"); const qint16 port = commTcpi.midStr("<port>", "</port>").toInt(); const QString& thread = commTcpi.midStr("<thread>", "</thread>"); emit got(broadID, title, communityID, ownerID, ownerName, stTime, edTime, broadcastToken, userID, isPremium, addr, port, thread); }
void value(T& a, const char* name = 0) const { if (got(name)) { who->found(a, name); } }
void container_start(T& a, const char* name) const { if (got(name)) { who->found(a, name); } }
void ExtendInfo::gotReply(QNetworkReply* reply) { StrAbstractor data(QString(reply->readAll())); QString status = data.midStr("status=\"", "\""); if (status != "ok") { QString code = data.midStr("<code>", "</code>"); QString description = data.midStr("<description>", "</description>"); emit error(code, description); qDebug() << data.toString(); return; } StrAbstractor* item; while ((item = data.mid("<item>", "</item>")) != nullptr) { QString label = item->midStr("<label>", "</label>"); QString price = item->midStr("<price>", "</price>"); QString num = item->midStr("<num>", "</num>"); QString code = item->midStr("<code>", "</code>"); QString itemType = item->midStr("<item>", ""); emit got(ExtendItem{label, price, num, code, itemType, broadID}); } }
void LocaleDisplayNamesTest::TestUldnDisplayContext() { const LocNameDispContextItem * ctxtItemPtr; for (ctxtItemPtr = ctxtItems; ctxtItemPtr->displayLocale != NULL; ctxtItemPtr++) { UDisplayContext contexts[2] = {ctxtItemPtr->dialectHandling, ctxtItemPtr->capitalization}; UErrorCode status = U_ZERO_ERROR; ULocaleDisplayNames * uldn = uldn_openForContext(ctxtItemPtr->displayLocale, contexts, 2, &status); if (U_FAILURE(status)) { errln(UnicodeString("FAIL: uldn_openForContext failed for locale ") + ctxtItemPtr->displayLocale + ", dialectHandling " + ctxtItemPtr->dialectHandling + ", capitalization " + ctxtItemPtr->capitalization); } else { UDisplayContext dialectHandling = uldn_getContext(uldn, UDISPCTX_TYPE_DIALECT_HANDLING, &status); UDisplayContext capitalization = uldn_getContext(uldn, UDISPCTX_TYPE_CAPITALIZATION, &status); if (U_FAILURE(status)) { errln(UnicodeString("FAIL: uldn_getContext status ") + (int)status); } else if (dialectHandling != ctxtItemPtr->dialectHandling || capitalization != ctxtItemPtr->capitalization) { errln("FAIL: uldn_getContext retrieved incorrect dialectHandling or capitalization"); } else { UChar nameBuf[ULOC_FULLNAME_CAPACITY]; int32_t len = uldn_localeDisplayName(uldn, ctxtItemPtr->localeToBeNamed, nameBuf, ULOC_FULLNAME_CAPACITY, &status); if (U_FAILURE(status)) { dataerrln(UnicodeString("FAIL: uldn_localeDisplayName status: ") + u_errorName(status)); } else if (u_strcmp(ctxtItemPtr->result, nameBuf) != 0) { UnicodeString exp(ctxtItemPtr->result, u_strlen(ctxtItemPtr->result)); UnicodeString got(nameBuf, len); dataerrln(UnicodeString("FAIL: uldn_localeDisplayName, capitalization ") + ctxtItemPtr->capitalization + ", expected " + exp + ", got " + got ); } } uldn_close(uldn); } } }
// ----------------------------------------------------------------------------- bool tzn::got(long tm_gmtoff) { DEBUGLOGB; TzInfo nfo; TzLocation loc; bool ret = got(tm_gmtoff, loc, nfo); DEBUGLOGE; return ret; }
void CommPostKey::gotReply(QNetworkReply* reply) { const auto postKey = QString(reply->readAll().mid(8)); if(postKey.isEmpty()) { emit error(); return; } emit got(postKey); }
// ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- bool tzn::got(const char* tzcode, bool exact) { DEBUGLOGB; TzInfo nfo; TzLocation loc; bool ret = got(tzcode, loc, nfo, exact); DEBUGLOGE; return ret; }
std::vector<msg_on_chan> get_all_msg_on_chan(context const&pb) { std::vector<msg_on_chan> result; for (;;) { msg_on_chan got(pb.get(), pb.get_channel()); if (got.message().empty() && got.channel().empty()) { break; } result.emplace_back(got); } return result; }
Test::Result run_one_test(const std::string&, const VarMap& vars) override { const std::vector<uint8_t> secret = get_req_bin(vars, "Secret"); const std::vector<uint8_t> basepoint = get_req_bin(vars, "Basepoint"); const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); std::vector<uint8_t> got(32); Botan::curve25519_donna(got.data(), secret.data(), basepoint.data()); Test::Result result("Curve25519 scalarmult"); result.test_eq("basemult", got, expected); return result; }
void OwnerComment::gotReply(QNetworkReply* reply) { nicolive::StrAbstractor rep(QString(reply->readAll())); const QString& status = rep.midStr("status=", "&"); if ( status == "error" ) { emit error(rep.midStr("error=", "")); qDebug() << rep.toString(); return; } emit got(); }
// ----------------------------------------------------------------------------- bool tzn::get(long tm_gmtoff, int* loc_offset, int* utc_offset, double* latitude, double* longitude, char* tzname, size_t tzn_len, char* comment, size_t cmt_len) { DEBUGLOGB; TzInfo nfo; TzLocation loc; bool ret = got(tm_gmtoff, loc, nfo); if( ret ) get(loc, nfo, loc_offset, utc_offset, latitude, longitude, tzname, tzn_len, comment, cmt_len); DEBUGLOGE; return ret; }
void test_checkers_board_list_to_string() { std::cout<<" To String"<<std::endl; skynet::checkers::board_list_t boards{"rrrrrrrr_rrrr_______bbbbbbbbbbbb","rrrrrrrr_rrr_r______bbbbbbbbbbbb"}; std::string stringify("{\"rrrrrrrr_rrrr_______bbbbbbbbbbbb\",\"rrrrrrrr_rrr_r______bbbbbbbbbbbb\"}"); std::string expected("[\"rrrrrrrr_rrrr_______bbbbbbbbbbbb\",\"rrrrrrrr_rrr_r______bbbbbbbbbbbb\"]"); std::string got(std::to_string(boards)); if(expected!=got) { std::cout<<" FAIL std::to_string("<<stringify<<") should yield \""+expected+"\" but got \""+got+"\"."<<std::endl; failed=true; } }
void Extend::gotReply(QNetworkReply* reply) { nicolive::StrAbstractor data(QString(reply->readAll())); nicolive::StrAbstractor* errord = data.mid("<error>", "</error>"); if (errord != nullptr) { const QString& code = errord->midStr("<code>", "</code>"); const QString& description = errord->midStr("<description>", "</description>"); emit error(code, description); return; } if (data.midStr("<mode>", "</mode>") == "extend") emit got(); }
void StreamInfo::gotReply(QNetworkReply* reply) { StrAbstractor receivedData(QString(reply->readAll())); const QString status = receivedData.midStr("status=\"", "\""); if ( status == "fail" ) { emit error(); return; } const QString& broadID = receivedData.midStr("<request_id>lv", "</request_id>"); const QString& title = receivedData.midStr("<title>", "</title>"); const QString& description = receivedData.midStr("<description>", "</description>"); const QString& communityID = receivedData.midStr("<default_community>co", "</default_community>"); emit got(broadID, title, description, communityID); }
int tag(char *term, char *tag) { char *e; if(!got(term)) return 0; if(e = look(term, nil)){ eatspace(); string("<"); string(tag); string(">"); ebody(e); string("</"); string(tag); string(">"); pos += strlen(term); } else string(term); return 1; }
vector<vector<int> > fourSum(vector<int> &num, int target) { vector<vector<int> > ans; vector<int> a(num); int n = num.size(); sort(a.begin(), a.end()); for(int i = 0; i < n; i++) { for(int j = i+1; j < n; j++) { int p = j+1, q = n-1; while(p < q) { while (p < q && a[i]+a[j]+a[p]+a[q]<target) { p++; } while (p < q && a[i]+a[j]+a[p]+a[q]>target) { q--; } if (p < q && a[i]+a[j]+a[p]+a[q] == target) { vector<int> got({a[i], a[j], a[p], a[q]}); ans.push_back(got); while(p < q && a[p] == a[p+1]) { p++; } p++; while(p < q && a[q] == a[q-1]) { q--; } } } while(j < n-1 && a[j]==a[j+1]) { j++; } } while(i < n-1 && a[i]==a[i+1]) { i++; } } return ans; }
void body(void) { char *s; int t; Next: if(pos >= epos) return; if(got("\n") || got("\r\n")) indent = -1; if(got("\n") || got("\r\n")){ string("<br>"); while(got("\n") || got("\r\n")) ; } if(indent == -1){ indent = 0; for(;;){ if(got(" ")) indent++; else if(got("\t")){ indent += 8; indent %= 8; } else break; } if(intable && look("||", look("\n", nil)) == nil){ string("</table>"); intable = 0; } string("\n"); if((indent < inlist) || (indent < inquote)) return; while(indent > 0){ if(pos >= epos) return; if(got("*") || got("#")){ s = pos-1; eatspace(); if(indent > inlist){ if(*s == '*') string("<ul><li>"); else string("<ol><li>"); t = inlist; inlist = indent; body(); inlist = t; if(*s == '*') string("</li></ul>"); else string("</li></ol>"); } else { string("</li><li>"); break; } } else if(indent > inquote){ string("<blockquote>"); t = inquote; inquote = indent; body(); inquote = t; string("</blockquote>"); } else break; } if(indent == 0){ if(got("#")){ if((pos = look("\n", nil)) == nil) pos = epos; goto Next; } if(heading()) goto Next; if(got("----")){ while(got("-")) ; string("<hr>"); goto Next; } } } if(got("`")){ if(s = look("`", nil)){ escape(s); pos = s+1; } else string("`"); } else if(got("<")){ string("<"); if(s = look(">", nil)){ s++; output(pos, s - pos); pos = s; } } else if(got("[")){ if(s = look("]", nil)){ link(s); pos = s+1; } else string("["); } else if(tag("*", "b") || tag("_", "i") || tag("^", "sup") || tag(",,", "sub") || tag("~~", "strike")){ } else if(got("{{{")){ if(s = look("}}}", nil)){ if(look("\n", s)){ string("<pre>"); escape(s); string("</pre>"); } else { string("<tt>"); escape(s); string("</tt>"); } pos = s+3; } else string("{{{"); } else if(got("||")){ if(s = look("||", look("\n", nil))){ eatspace(); switch(intable){ case 0: string("<table>"); intable++; case 1: string("<tr>"); intable++; } string("<td>"); ebody(s); string("</td>"); } else if(intable){ string("</tr>"); intable = 1; } } else if(match("http://")) link(nil); else if(match("https://")) link(nil); else if(match("ftp://")) link(nil); else{ output(pos, 1); pos++; } goto Next; }
ProcessImage::ProcessImage( QWidget* parent ): DropArea(parent), _currentItem(-1), _currentImage(-1) { layout = new QHBoxLayout( this ); layout->setContentsMargins(0,0,0,0); layout->setSpacing(0); QFrame *processLeftColFrame = new QFrame(); processLeftColFrame->setObjectName( "processLeftColFrame" ); QVBoxLayout *leftLayout = new QVBoxLayout( processLeftColFrame ); layout->addWidget( processLeftColFrame ); QHBoxLayout *topLayout = new QHBoxLayout(); topLayout->addWidget( backButton = new QPushButton( this ) ); backButton->setText( "Choisir un autre media" ); backButton->setObjectName("backButton"); connect(backButton, SIGNAL(clicked()), SLOT(onBackButtonClicked()) ); topLayout->addWidget( newSearch = new QPushButton( "Nouvelle recherche" ) ); newSearch->setObjectName("newSearch"); connect( newSearch, SIGNAL(clicked()), SLOT(onNewSearch()) ); topLayout->addStretch(0); topLayout->addWidget( nbFacesLbl = new QLabel( this ) ); nbFacesLbl->setObjectName( "nbFacesLbl" ); /* overlap = new QLabel( this ); overlap->setObjectName( "overlapLoader" ); QMovie *loaderMovie = new QMovie(":/res/loader.gif"); overlap->setMovie( loaderMovie ); loaderMovie->start() */ // overlap->setGeometry( imageLbl->geometry() ); // topLayout->addWidget( overlap ); leftLayout->addLayout( topLayout ); leftLayout->addWidget( theater = new Theater( this ) ); theater->imageOverlay->setOverlayText("Traitement en cours..."); connect( theater, SIGNAL(rectClicked(int)), SLOT(onPersonSelected(int)) ); QScrollArea *imagesScrollArea = new QScrollArea( this ); leftLayout->addWidget( imagesScrollArea ); imagesScrollArea->setWidgetResizable( true ); imagesScrollArea->setObjectName( "imagesScrollArea" ); imagesScrollArea->setWidget( showCase = new ShowCase( this ) ); connect( showCase, SIGNAL(imageSelected(int)), SLOT(loadImageData(int)) ); // COL 3 layout->addWidget( sidePanel = new SidePanel(this, "view") ); connect(sidePanel, SIGNAL(confirmChanges(QJsonObject)), SLOT(savePanelChanges(QJsonObject)) ); connect( sidePanel, SIGNAL(confirmPerson()), SLOT( onConfirmPerson()) ); connect( sidePanel, SIGNAL(refutePerson()), SLOT( onRefutePerson()) ); //COL2 QVBoxLayout* col2 = new QVBoxLayout(); col2->setSpacing(0); col2->addWidget( detectedFacesScrollArea = new QScrollArea( this ) ); detectedFacesScrollArea->setWidgetResizable( true ); detectedFacesScrollArea->setObjectName( "detectedFacesScrollArea" ); detectedFacesScrollArea->setWidget( detectedFaces = new DetectedFaces( this ) ); layout->addLayout( col2 ); connect( detectedFaces, SIGNAL(itemClicked(int)), SLOT(onPersonSelected(int)) ); connect( &Socket::sock(), SIGNAL(faceRecognized(int, int, int, int, int, int)), SLOT(onFaceRecognized(int, int, int, int, int, int)) ); connect( &Socket::sock(), SIGNAL(faceIs(int, QString, QString)), SLOT(onFaceIs(int, QString, QString)) ); connect( &Socket::sock(), SIGNAL(got(QJsonObject, QByteArray)), sidePanel, SLOT(populate(QJsonObject, QByteArray)) ); }
/// Returns whether the given message was received on the given /// channel on the context inline bool got_message_on_channel(context const &pb, msg_on_chan expected) { pubnub::msg_on_chan got(pb.get(), pb.get_channel()); return got == expected; }
void Pull::run() { QLOG_TRACE() << "Receiving file " << m_sourceFilePath; qDebug() << "SecureConnection::Pull " << m_sourceFilePath << "->" << m_destinationFilePath; // Set blocking, which apparently is required. QByteArray source(m_sourceFilePath.toLocal8Bit()); libssh2_session_set_blocking(m_session, 1); struct stat fileInfo; LIBSSH2_CHANNEL* channel(libssh2_scp_recv(m_session, source.data(), &fileInfo)); if (channel == 0) { QString msg("Could not stat file "); msg += m_sourceFilePath; throw Exception(m_session, msg); } QByteArray destination(m_destinationFilePath.toLocal8Bit()); FILE* localFileHandle(fopen(destination.data(), "wb")); if (!localFileHandle) { QString msg("Could not open file for writing "); msg += m_destinationFilePath; throw Exception(msg); } // If the buffer size changes, anything connected to the copyProgress will // need updating as it assumes kbyte increments. char buffer[1024]; off_t got(0); while (got < fileInfo.st_size && !m_terminate) { int amount(sizeof(buffer)); if ((fileInfo.st_size - got) < amount) { amount = fileInfo.st_size - got; } int bc(libssh2_channel_read(channel, buffer, amount)); if (bc > 0) { fwrite(buffer, 1, bc, localFileHandle); }else if (bc < 0) { m_success = false; m_errorMessage = "Error reading from channel"; break; } got += bc; copyProgress(); //qDebug() << "sleeping 1"; sleep(1); } fclose(localFileHandle); libssh2_channel_send_eof(channel); // This seems to cause a hang sometimes // libssh2_channel_wait_eof(channel); libssh2_channel_wait_closed(channel); libssh2_channel_free(channel); if (!m_errorMessage.isEmpty()) throw Exception(m_errorMessage); if (!m_terminate) m_success = true; }
void FGAdvice::onRequestFinished() { switch(m_state) { case GetText: { bool clearState = true; m_respData.clear(); if(!m_getAudio) { m_state = Idle; } if(m_stateData.activeReply->error() == QNetworkReply::NoError) { _interpretResponse(); } else { m_state = Error; m_respData.error = m_stateData.activeReply->errorString(); } if(m_state != GetText) { emit got(m_state == Error ? ReplyError : ReplyText); } else { QFile cfl(soundFilePath()); if(cfl.isReadable()) { m_state = Idle; emit got(ReplySound); } else { m_state = StartGetSound; QString u = QString(FGA_SOUND_URI).arg(m_respData.soundFile); QUrl url = QString(u); QNetworkRequest nrAudio(url); m_stateData.restart(m_netAccMgr->get(nrAudio)); connect(m_stateData.activeReply, SIGNAL(readyRead()), SLOT(onDataReady())); connect(m_stateData.activeReply, SIGNAL(finished()), SLOT(onRequestFinished())); clearState = false; } } if(clearState) m_stateData.clear(); } break; case GetSound: { if(m_stateData.activeReply->error() != QNetworkReply::NoError) { m_state = Error; m_respData.error = m_stateData.activeReply->errorString(); emit got(ReplyError); } else { m_state = Idle; emit got(ReplySound); } m_stateData.clear(); } break; case Error: emit got(ReplyError); break; default: m_state = Error; m_stateData.clear(); break; } }