static int findReplyColors() { QColor textColor(QApplication::palette().color(QPalette::Text)); QColor reply1(textColor), reply2(textColor); int r, g, b; textColor.getRgb(&r, &g, &b); int range[3] = { 0 }; if (((r + g + b) / 3) > 127) { // This is a light color - make the reply colors darker than this range[0] = 0 - r; range[1] = 0 - g; range[2] = 0 - b; } else { // This is a dark color - make the reply colors lighter than this range[0] = 255 - r; range[1] = 255 - g; range[2] = 255 - b; } reply1.setRgb(r + (range[0] * 1 / 2), g + (range[1] * 1 / 2), b + (range[2] * 1 / 2)); replyColor1 = reply1.name(); reply2.setRgb(r + (range[0] * 1 / 4), g + (range[1] * 1 / 4), b + (range[2] * 1 / 4)); replyColor2 = reply2.name(); return 0; }
/*-------------------------------------------------------------------------*/ void reply_errno (int32 handle) /* Send a (errcode, errno) message to the driver for <handle>. */ { char mesg[2]; switch(errno) { case EWOULDBLOCK: #if EAGAIN != EWOULDBLOCK case EAGAIN: #endif mesg[0] = ERQ_E_WOULDBLOCK; break; case EPIPE: mesg[0] = ERQ_E_PIPE; break; default: mesg[0] = ERQ_E_UNKNOWN; break; } mesg[1] = errno; reply1(handle, mesg, 2); } /* reply_errno() */
/*-------------------------------------------------------------------------*/ void bad_request (char *mesg) /* ERQ received a bad message in <mesg> - print some diagnostics. */ { fprintf(stderr, "%s Bad request %d\n", time_stamp(), mesg[8]); fprintf(stderr, "%s %x %x %x %x %x %x %x %x %x\n", time_stamp(), mesg[0], mesg[1], mesg[2], mesg[3], mesg[4], mesg[5], mesg[6], mesg[7], mesg[8]); fprintf(stderr, "%s %c %c %c %c %c %c %c %c %c\n", time_stamp(), mesg[0], mesg[1], mesg[2], mesg[3], mesg[4], mesg[5], mesg[6], mesg[7], mesg[8]); reply1(get_handle(mesg), "", 0); } /* bad_request() */
TEST(NetworkAccessManager, Get) { CustomNetworkAccessManagerFactory factory; QObjectPtr<QNetworkAccessManager> nam (factory.create(nullptr)); // Non-localhost:8080 Url QObjectPtr<QNetworkReply> reply1 (nam->get(QNetworkRequest(QUrl("http://www.google.com")))); while (!reply1->isFinished()) { QTest::qWait(100); } EXPECT_EQ(reply1->url(), QUrl()); EXPECT_NE(reply1->error(), QNetworkReply::NoError); // localhost:8080 Url QUrl url2 ("http://localhost:8080/ipfs/hash/test.png"); QObjectPtr<QNetworkReply> reply2 (nam->get(QNetworkRequest(url2))); EXPECT_EQ(reply2->url(), url2); QUrl url3 ("http://127.0.0.1:8080/ipfs/hash/test.png"); QObjectPtr<QNetworkReply> reply3 (nam->get(QNetworkRequest(url3))); EXPECT_EQ(reply3->url(), url3); }
int reply(int chan, int code, char *payload) { int ret = reply1(chan, code, payload); dprint(debug, "ret: %d\n", ret); return ret; }