void KAsyncFetchObject::sendHeadSuccess(KHttpRequest *rq) { buffer.destroy(); if (rq->left_read>0) { //handle post data if (rq->pre_post_length>0) { /* 还有预数据 */ #if 0 if (client->spdy_ctx) { /* * 如果有spdy,则要处理post请求 * 最后数据块发送一个fin标志. */ buffer.write_all(rq->parser.body,rq->pre_post_length); rq->left_read -= rq->pre_post_length; rq->pre_post_length = 0; sendPost(rq); return; } #endif //send pre load post data client->upstream_write(rq,resultUpstreamSendPost,bufferUpstreamSendPost); return; } //read post data readPost(rq); return; } //发送头成功,无post数据处理. startReadHead(rq); }
void NetWork::search(const QString &search) { QUrl url(SEARCH); QByteArray data = ""; data.append("s=" + search + "&type=1&offset=0&total=true&limit=60"); sendPost(url, data); }
/* Writes the JSON object, *data, to the database represented by *service_url. * *data must be a properly formatted InfluxDB JSON object. * Returns a CURLcode that is stored in influxConn->result_code */ CURLcode influxWrite(influxConn *conn, char *data){ char *url = build_write_url(conn); //freed in sendPost() if(influx_debug){printf("[w: %s]\n", url);} update_ssl_opts(conn); conn->result_code = sendPost(conn, url, data); return conn->result_code; }
void KAsyncFetchObject::readPost(KHttpRequest *rq) { #ifdef ENABLE_TF_EXCHANGE if (rq->tf) { int got = 0; char *tbuf = getPostWBuffer(rq,got); got = rq->tf->readBuffer(tbuf,got); if (got<=0) { handleError(rq,STATUS_SERVER_ERROR,"cann't read post data from temp file"); return; } rq->left_read-=got; buffer.writeSuccess(got); sendPost(rq); return; } #endif #ifdef ENABLE_SIMULATE_HTTP if (TEST(rq->workModel,WORK_MODEL_SIMULATE)) { KSimulateSocket *ss = static_cast<KSimulateSocket *>(rq->c->socket); int got = 0; char *tbuf = getPostWBuffer(rq,got); got = ss->post(ss->arg,tbuf,got); if (got<=0) { handleError(rq,STATUS_SERVER_ERROR,"cann't read post data from temp file"); return; } rq->left_read-=got; buffer.writeSuccess(got); sendPost(rq); return; } #endif //如果没有临时文件交换,因为已经读了客户的post数据,无法重置,这种情况就禁止出错重试 tryCount = -1; client->removeSocket(); rq->c->read(rq,resultUpstreamReadPost,bufferUpstreamReadPost); }
void NetWork::logIn(const QString &name, const QString &passwd) { m_userName = name; m_userPasswd = ""; QCryptographicHash md(QCryptographicHash::Md5); QByteArray ba, bb; ba.append(passwd); md.addData(ba); bb = md.result(); m_userPasswd.append(bb.toHex()); QUrl url(LOGIN); QByteArray data; data.append("username="******"&password="******"&rememberLogin: true"); sendPost(url, data); }
void KAsyncFetchObject::handleReadPost(KHttpRequest *rq,int got) { if (got<=0) { stageEndRequest(rq); return; } #ifdef ENABLE_INPUT_FILTER if (rq->hasInputFilter()) { int len; char *buf = getPostWBuffer(rq,len); if (JUMP_DENY==rq->if_ctx->check(buf,got,rq->left_read<=got)) { denyInputFilter(rq); return; } } #endif rq->left_read-=got; buffer.writeSuccess(got); sendPost(rq); }
void JumpropesCommon::HttpClient::post( const URI *uri, const String *sDataType, const String *sData, bool bBlocking, BaseSocket *anAlternateSocket ) { reset(); this->host.setValue( &uri->host ); if ( this->host.size() == 0 ) { if ( pLookupBase != NULL ) { pLookupBase->lookupHost( &this->host ); } else { JRresolveAll( &this->host ); } } this->path.setValue( &uri->path ); this->port = uri->port.get(); if ( !this->path.startsWith( "/", 1 ) ) { this->path.prepend( "/", 1 ); } if ( uri->query.getLength() > 0 ) { this->path.append( "?", 1 ); this->path.append( &uri->query ); } IPAddress *aDefaultIp = this->host.getAddress(); if ( aDefaultIp != NULL ) { if ( anAlternateSocket != NULL ) { socket = anAlternateSocket; bAlternateSocketUsed = true; } else { socket = new ClientSocket(); } socket->getRemoteAddress()->setValue( aDefaultIp ); socket->remotePort.set( this->port ); if ( socket->connect() ) { connection = new HttpConnection( socket ); connection->start(); start(); onStatusUpdate.execute( JRHTTPSTATUS_CONNECTED ); sendPost( sDataType, sData ); if ( bBlocking ) { while ( isRunning() ) { GFMillisleep( 50 ); } } } else { reset(); onStatusUpdate.execute( JRHTTPSTATUS_ERROR ); } } else { reset(); onStatusUpdate.execute( JRHTTPSTATUS_ERROR ); } }
int main(void) { //BASIC VARS WSADATA Data; SOCKADDR_IN recvSockAddr; SOCKET recvSocket; int status; int numrcv = 0; struct hostent * remoteHost; char * ip; const char * host_name = "pb-homework.appspot.com"; char maxBuff[MAXBUFLEN]; memset(maxBuff,0,MAXBUFLEN); //MOD VAR int avg = 0; // BASIC: Initialize Windows Socket DLL status = initializeWindowsSocketDLL(Data); // BASIC: Get IP address from host name remoteHost = gethostbyname(host_name); ip = inet_ntoa(*(struct in_addr *)*remoteHost->h_addr_list); printf("\n==========\nIP address is: %s\n==========\n", ip); memset(&recvSockAddr, 0, sizeof(recvSockAddr)); // zero the sockaddr_in structure recvSockAddr.sin_port=htons(PORT); // specify the port portion of the address recvSockAddr.sin_family=AF_INET; // specify the address family as Internet recvSockAddr.sin_addr.s_addr= inet_addr(ip); // specify ip address // BASIC: Create socket recvSocket = createSocket(); // BASIC: Connecting connecting(recvSocket, recvSockAddr); // BASIC: Sending request sendRequest(host_name, recvSocket); // BASIC: receiving info and secret recieve(recvSocket, maxBuff); // MOD: GET by secret getBySecret(maxBuff, host_name, recvSocket); // BASIC: receiving info + secret info recieve(recvSocket, maxBuff); // Buff with all needed info puts("==========\nWE GOT THIS INFO:"); printf("\n%s\n==========\n", maxBuff); //MOD: Finding avg avg = avgValue(maxBuff); printf("\n=====\nAverage value: %i\n=====\n\n", avg); //MOD: GET by post sendPost(recvSocket, host_name, avg); // BASIC: receiving result info recieve(recvSocket, maxBuff); // Buff with a result info puts("==========\nTHIS IS THE RESULT:"); printf("\n%s\n==========\n", maxBuff); // closing the sockets and etc. closesocket(recvSocket); WSACleanup(); //end of program puts("\nPress ANY KEY to exit the program..."); getch(); return 0; }
int tryLogin(int hSocket, _MODULE_DATA* _psSessionData, sLogin** login, int nPort, char* szLogin, char* szPassword) { char* pReceiveBuffer = NULL; int nReceiveBufferSize, nRet; char* pTemp = NULL; switch(_psSessionData->nFormType) { case FORM_GET: writeError(ERR_DEBUG_MODULE, "[%s] Sending Web Form Authentication (GET).", MODULE_NAME); nRet = sendGet(hSocket, _psSessionData, szLogin, szPassword); break; case FORM_POST: writeError(ERR_DEBUG_MODULE, "[%s] Sending Web Form Authentication (POST).", MODULE_NAME); nRet = sendPost(hSocket, _psSessionData, szLogin, szPassword); break; default: break; } if (nRet == FAILURE) { writeError(ERR_ERROR, "[%s] Failed during sending of authentication data.", MODULE_NAME); (*login)->iResult = LOGIN_RESULT_UNKNOWN; setPassResult(*login, szPassword); return MSTATE_EXITING; } writeError(ERR_DEBUG_MODULE, "[%s] Retrieving server response.", MODULE_NAME); pReceiveBuffer = medusaReceiveLine(hSocket, &nReceiveBufferSize); if ((pReceiveBuffer == NULL) || (pReceiveBuffer[0] == '\0')) { writeError(ERR_ERROR, "[%s] No data received", MODULE_NAME); (*login)->iResult = LOGIN_RESULT_UNKNOWN; setPassResult(*login, szPassword); return MSTATE_EXITING; } pTemp = (char*)index(pReceiveBuffer, ' '); if ( !pTemp || strncmp(pTemp + 1, "200 OK", 6) != 0 ) { writeError(ERR_ERROR, "The answer was NOT successfully received, understood, and accepted: error code %.4s", pTemp); (*login)->iResult = LOGIN_RESULT_UNKNOWN; setPassResult(*login, szPassword); return MSTATE_EXITING; } while ((strcasestr(pReceiveBuffer, _psSessionData->szDenySignal) == NULL) && (pReceiveBuffer[0] != '\0')) { free(pReceiveBuffer); pReceiveBuffer = medusaReceiveLine(hSocket, &nReceiveBufferSize); } if (strcasestr(pReceiveBuffer, _psSessionData->szDenySignal) != NULL) { (*login)->iResult = LOGIN_RESULT_FAIL; setPassResult(*login, szPassword); return MSTATE_NEW; } writeError(ERR_DEBUG_MODULE, "Login Successful"); (*login)->iResult = LOGIN_RESULT_SUCCESS; setPassResult(*login, szPassword); return MSTATE_NEW; }
Gui_Groups::Gui_Groups(LinqClient* c, QWidget* parent) : QGridLayout(parent), _client(c) { Gui_Avatar* portrait = new Gui_Avatar(QString::fromStdString(_client->avatar())); QPushButton* create = new QPushButton("CREATE"); QLabel* title = new QLabel("NEW GROUP"); showgrp = new Gui_DisplayInfo; newpost = new QTextEdit; newgrp = new QLineEdit; search = new QLineEdit; newbox = new QGroupBox; memlbl = new QLabel("Members"); memlbl->setMaximumSize(80,20); grpname = new QLineEdit; newgrplayout = new QFormLayout; newgrplayout->setSpacing(15); newgrplayout->addRow(title); newgrplayout->addRow("Group name:", grpname); newgrplayout->addRow("Group description:", newgrp); newgrplayout->addRow(create); newbox->setLayout(newgrplayout); if(_client->level() < executive) newbox->hide(); search->setPlaceholderText("Search group.."); search->hide(); connect(search, SIGNAL(returnPressed()), this, SLOT(searchGroup())); post = new QPushButton("POST"); grplist = new QListWidget; memlist = new QListWidget; QLabel* grplbl = new QLabel("Groups"); grplbl->setMaximumSize(120,20); createGroups(); QFormLayout* frm = new QFormLayout; mbuttons[0] = new QPushButton; mbuttons[0]->setIcon(QPixmap("img/document185.png")); mbuttons[0]->setToolTip("New group"); mbuttons[1] = new QPushButton; mbuttons[1]->setIcon(QPixmap("img/cross108.png")); mbuttons[1]->setToolTip("Delete group"); mbuttons[2] = new QPushButton; mbuttons[2]->setIcon(QPixmap("img/mop2.png")); mbuttons[2]->setToolTip("Delete all posts"); mbuttons[3] = new QPushButton; mbuttons[3]->setIcon(QPixmap("img/exit6.png")); mbuttons[3]->setToolTip("Leave this group"); mbuttons[4] = new QPushButton; mbuttons[4]->setIcon(QPixmap("img/enter3.png")); mbuttons[4]->setToolTip("Join this group"); frm->addRow(mbuttons[0]); frm->addRow(mbuttons[3]); frm->addRow(mbuttons[4]); frm->addRow(mbuttons[1]); frm->addRow(mbuttons[2]); connect(mbuttons[0], SIGNAL(clicked()), this, SLOT(showNewGroup())); connect(create, SIGNAL(clicked()), this, SLOT(newGroup())); connect(mbuttons[1], SIGNAL(clicked()), this, SLOT(deleteGroup())); connect(mbuttons[2], SIGNAL(clicked()), this, SLOT(clearPosts())); connect(mbuttons[3], SIGNAL(clicked()), this, SLOT(leaveGroup())); connect(mbuttons[4], SIGNAL(clicked()), this, SLOT(addGroup())); mbuttons[0]->hide(); mbuttons[1]->hide(); mbuttons[2]->hide(); mbuttons[3]->hide(); mbuttons[4]->hide(); if(_client->level() >= executive) mbuttons[0]->show(); tbar = new QToolBar; tbuttons[0] = new QToolButton(tbar); tbuttons[0]->setIcon(QPixmap("img/cross108.png")); tbar->addWidget(tbuttons[0]); newpost->setStyleSheet("background: #1a1a1a; font-weight:400"); newpost->setPlaceholderText("Insert new post into this group."); newpost->hide(); post->hide(); showgrp->hide(); memlbl->hide(); memlist->hide(); memlist->setContextMenuPolicy(Qt::CustomContextMenu); connect(memlist, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(memListMenu(const QPoint&))); addWidget(newbox, 0, 1, 1, 1); addWidget(portrait, 0, 0, 1, 1, Qt::AlignTop); addWidget(showgrp, 0, 1, 3, 1); addLayout(frm, 0, 2, 1, 1, Qt::AlignRight); addWidget(newpost, 3, 1, 2, 3); addWidget(post, 5, 4, 1, 1, Qt::AlignRight); addWidget(grplbl, 1, 0, 1, 1); addWidget(grplist, 2, 0, 1, 1); addWidget(memlbl, 3, 0, 1, 1); addWidget(memlist, 4, 0, 1, 1); addWidget(search, 5, 0, 1, 1); setRowStretch(0, 0); setRowStretch(1, 10); setColumnStretch(0, 1); setColumnStretch(1, 5); connect(grplist, SIGNAL(clicked(QModelIndex)), this, SLOT(showGroup())); connect(post, SIGNAL(clicked()), this, SLOT(sendPost())); connect(this, SIGNAL(created(int)), this, SLOT(refresh(int))); }