TEST (RouterTester, BasicRouting) { HTTP::Router router; HTTP::Response response; router.Pipe ([&](const auto& data) { response = data; }); MockEndPoint* endPoint1 = new MockEndPoint ("/test"); MockEndPoint* endPoint2 = new MockEndPoint ("/not_test"); router.AddEndPoint (std::shared_ptr <HTTP::AbstractEndPoint> (endPoint1)); router.AddEndPoint (std::shared_ptr <HTTP::AbstractEndPoint> (endPoint2)); EXPECT_CALL (*endPoint1, Get (::testing::_, ::testing::_)).Times (1); EXPECT_CALL (*endPoint1, Put (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint1, Post (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint1, Delete (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint2, Get (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint2, Put (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint2, Post (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint2, Delete (::testing::_, ::testing::_)).Times (0); const HTTP::Request request (HTTP::Method::GET, std::string ("/test")); router.Write (request); ASSERT_EQ (request.mVersion, response.mVersion); // endpoint should set status code }
void sBrowserTree::OnKey(sU32 key) { switch(key&0x8001ffff) { case sKEY_DOWN: if(SelDir) { SerialSelect = 0; DirNext(Dir); } else { SelDir = Dir; } break; case sKEY_UP: if(SelDir) { SerialPrev = 0; DirPrev(Dir); } else { SelDir = Dir; } break; case sKEY_ENTER: if(SelDir) { DirSelect(SelDir); } break; case sKEY_LEFT: if(SelDir) { DirSelect(SelDir); SelDir->SetUserData(DIKey,0); } break; case sKEY_RIGHT: if(SelDir) { DirSelect(SelDir); SelDir->SetUserData(DIKey,1); } break; case sKEY_SPACE: Post(sBTCMD_SELDIR); break; case sKEY_TAB: Post(sBWCMD_FOCLIST); break; case sKEY_ESCAPE: Post(sBWCMD_EXIT); break; } }
void Post(Btree BT) { if(!isEmpty(BT)) { Post(BT->lchild); Post(BT->rchild); printf("%c",BT->data); } }
bool MMatchServer::CheckOnLoginPre(const MUID& CommUID, int nCmdVersion, bool& outbFreeIP, string& strCountryCode3) { MCommObject* pCommObj = (MCommObject*)m_CommRefCache.GetRef(CommUID); if (pCommObj == NULL) return false; // 프로토콜 버전 체크 if (nCmdVersion != MCOMMAND_VERSION) { MCommand* pCmd = CreateCmdMatchResponseLoginFailed(CommUID, MERR_COMMAND_INVALID_VERSION); Post(pCmd); return false; } // free login ip를 검사하기전에 debug서버와 debug ip를 검사한다. // 서버가 debug타입인지 검사. if( MGetServerConfig()->IsDebugServer() && MGetServerConfig()->IsDebugLoginIPList(pCommObj->GetIPString()) ) { outbFreeIP = true; return true; } // 최대인원 체크 bool bFreeLoginIP = false; if (MGetServerConfig()->CheckFreeLoginIPList(pCommObj->GetIPString()) == true) { bFreeLoginIP = true; outbFreeIP = true; return true; } else { outbFreeIP = false; if ((int)m_Objects.size() >= MGetServerConfig()->GetMaxUser()) { MCommand* pCmd = CreateCmdMatchResponseLoginFailed(CommUID, MERR_CLIENT_FULL_PLAYERS); Post(pCmd); return false; } } // 접속을 막아놓은 지역의 IP인가 if( CheckIsValidIP(CommUID, pCommObj->GetIPString(), strCountryCode3, MGetServerConfig()->IsUseFilter()) ) IncreaseNonBlockCount(); else { IncreaseBlockCount(); MCommand* pCmd = CreateCmdMatchResponseLoginFailed(CommUID, MERR_FAILED_BLOCK_IP); Post(pCmd); return false; } return true; }
//******************************************************************** // Name: PostHeader // Input: 1) return path // 2) Subject // 3) destination address // 4) DoMime flag // Output: Error code or Success // Description: // Author/Date: jcar 20/9/96 // History: //******************************************************************** int PostHeader(char *RPath, char *Subject, char *mailTo, char *xheaders) { // Print message header according to RFC 822 // Return-path, Received, Date, From, Subject, Sender, To, cc time_t tNow = time(NULL); struct tm *tm = localtime(&tNow); int zoneh = abs(_timezone); int zonem, res; char *p; TLS_VARS; p = GLOBAL(Buffer); zoneh /= (60 * 60); zonem = (abs(_timezone) / 60) - (zoneh * 60); if(!xheaders || !strstr(xheaders, "Date:")){ p += sprintf(p, "Date: %s, %02d %s %04d %02d:%02d:%02d %s%02d%02d\r\n", days[tm->tm_wday], tm->tm_mday, months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec, (_timezone > 0) ? "+" : (_timezone < 0) ? "-" : "", zoneh, zonem); } if(!xheaders || !strstr(xheaders, "From:")){ p += sprintf(p, "From: %s\r\n", RPath); } p += sprintf(p, "Subject: %s\r\n", Subject); if(!xheaders || !strstr(xheaders, "To:")){ p += sprintf(p, "To: %s\r\n", mailTo); } if(xheaders){ p += sprintf(p, "%s\r\n", xheaders); } if ((res = Post(GLOBAL(Buffer))) != SUCCESS) return (res); if ((res = Post("\r\n")) != SUCCESS) return (res); return (SUCCESS); }
void CTcpSessionManager::OnConnectorStatus(ConnectorID connectorID, bool bConnected, CTcpSessionPtr session) { auto config = m_mapConnectorConfig.find(connectorID); if (config == m_mapConnectorConfig.end()) { LOGE("Unkwon Connector. Not Found ConnectorID=" << connectorID); return; } if (bConnected) { m_mapConnectorPtr[connectorID] = session; config->second.second.curReconnectCount = 0; config->second.second.totalConnectCount++; Post(std::bind(&CMessageDispatcher::DispatchOnConnectorEstablished, &CMessageDispatcher::getRef(), connectorID)); return; } auto iter = m_mapConnectorPtr.find(connectorID); if (!bConnected && iter != m_mapConnectorPtr.end()) { m_mapConnectorPtr.erase(connectorID); Post(std::bind(&CMessageDispatcher::DispatchOnConnectorDisconnect, &CMessageDispatcher::getRef(), connectorID)); } if (!bConnected && config->second.second.curReconnectCount > 0 && config->second.second.curReconnectCount < config->second.first.reconnectMaxCount) { config->second.second.curReconnectCount++; CTcpSocketPtr sockPtr(new zsummer::network::CTcpSocket()); sockPtr->Initialize(m_summer); static const bool EnableFastConnect = false;//fast reconnect. Be careful of remote server access denied. if (config->second.second.curReconnectCount == 1 && EnableFastConnect) { Post(std::bind(&CTcpSession::BindTcpConnectorPtr, session, sockPtr, config->second)); } else { CreateTimer(config->second.first.reconnectInterval, std::bind(&CTcpSession::BindTcpConnectorPtr, session, sockPtr, config->second)); } } else if (config->second.first.reconnectMaxCount > 0) { LOGE("Try Reconnect Failed. End Try. Traits=" << config->second.first); } }
ECode CPagedViewIcon::ResetDrawableState() { mLockDrawableState = FALSE; AutoPtr<MyRunnable> run = new MyRunnable(this); Boolean res; return Post(run, &res); }
bool ZBirdDummyClient::OnSockRecv(SOCKET sock, char* pPacket, DWORD dwSize) { if (m_pCommandBuilder==NULL) return false; // New Cmd Buffer //////////////// m_pCommandBuilder->SetUID(m_This, GetSenderUIDBySocket(sock)); m_pCommandBuilder->Read((char*)pPacket, dwSize); LockRecv(); while(MCommand* pCmd = m_pCommandBuilder->GetCommand()) { Post(pCmd); } UnlockRecv(); while(MPacketHeader* pNetCmd = m_pCommandBuilder->GetNetCommand()) { if (pNetCmd->nMsg == MSGID_REPLYCONNECT) { MReplyConnectMsg* pMsg = (MReplyConnectMsg*)pNetCmd; MUID HostUID, AllocUID; HostUID.High = pMsg->nHostHigh; HostUID.Low = pMsg->nHostLow; AllocUID.High = pMsg->nAllocHigh; AllocUID.Low = pMsg->nAllocLow; free(pNetCmd); LockRecv(); OnConnected(sock, &HostUID, &AllocUID); UnlockRecv(); } } return true; }
void sTextControl::ScrollToCursor() { sInt i,x,y,h,pos; sRect r; Post(CursorCmd); CursorWish = GetCursorX(); h = sPainter->GetHeight(sGui->FixedFont); y = Client.y0+2; x = Client.x0+2; pos = 0; for(;;) { i = 0; while(Text[pos+i]!=0 && Text[pos+i]!='\n') i++; if(Cursor>=pos && Cursor<=pos+i) { r.x0 = x+sPainter->GetWidth(sGui->FixedFont,Text+pos,Cursor-pos); r.y0 = y; r.x1 = r.x0+1; r.y1 = y+h; ScrollTo(r,sGWS_SAFE); return; } y+=h; pos+=i; if(Text[pos]==0) break; if(Text[pos]=='\n') pos++; } }
void CIOServer::Fini(void) { if (!m_binit || m_status == status_null) return; Post(std::bind(&CIOServer::real_fini, this)); }
/** * * Method Name: SDESReportSent() * * * Inputs: IGetSrcDescription *piGetSrcDescription * - Interface to the local Source Description * IRTCPConnection *piRTCPConnection * - Interface to associated RTCP Connection * IRTCPSession *piRTCPSession * - Interface to associated RTCP Session * * Outputs: None * * Returns: None * * Description: The SDESReportSent() event method shall inform the recipient * of a newly transmitted SDES Report and shall include the * IGetSrcDescription interface for accessing the contents of * this transmitted SDES Report. * * Usage Notes: * */ void CRTCManager::SDESReportSent(IGetSrcDescription *piGetSrcDescription, IRTCPConnection *piRTCPConnection, IRTCPSession *piRTCPSession) { // Create a message structure populated with the contents // of this event notification CMessage *poMessage = new CMessage(RTCP_SDES_SENT, (void *)piGetSrcDescription, (void *)piRTCPConnection, (void *)piRTCPSession); // Post the newly created event message to the RTC Manager's message queue // for processing by the Message Queue thread/task. #ifdef TEST_PRINT OsSysLog::add(FAC_MP, PRI_DEBUG, "RTCP - CRTCManager::SDESReportSent new message 0x%08x \n", (int)poMessage); #endif if(poMessage) { Post(poMessage); #if defined(__pingtel_on_posix__) delete poMessage; poMessage = NULL; #endif } }
/** * * Method Name: RemoteSSRCCollision() * * * Inputs: IRTCPConnection *piRTCPConnection * - Interface to associated RTCP Connection * IRTCPSession *piRTCPSession * - Interface to associated RTCP Session * * Outputs: None * * Returns: None * * Description: The RemoteSSRCCollision() event method shall inform the * recipient of a collision between two remote participants. * * Usage Notes: * */ void CRTCManager::RemoteSSRCCollision(IRTCPConnection *piRTCPConnection, IRTCPSession *piRTCPSession) { #if RTCP_DEBUG /* [ */ if(bPingtelDebug) { osPrintf("*** REMOTE SSRC COLLISION DETECTED ****\n"); osPrintf("\t ON SESSION ==> %d\n", piRTCPSession->GetSessionID()); osPrintf("\t WITH SSRC ==> %d\n", piRTCPConnection->GetRemoteSSRC()); } #endif /* INCLUDE_RTCP ] */ // Create a message structure populated with the contents // of this event notification CMessage *poMessage = new CMessage(REMOTE_SSRC_COLLISION, (void *)piRTCPConnection, (void *)piRTCPSession); // Post the newly created event message to the RTC Manager's message queue // for processing by the Message Queue thread/task. #ifdef TEST_PRINT OsSysLog::add(FAC_MP, PRI_DEBUG, "RTCP - CRTCManager::RemoteSSRCCollision new message 0x%08x \n", (int)poMessage); #endif if(poMessage) { Post(poMessage); #if defined(__pingtel_on_posix__) delete poMessage; poMessage = NULL; #endif } }
void ReserveRetunrHomeController::reserveEquipment(char* result) { std::string post_command = NativeLauncher::getNWAdress() + "/send_message?type=50"; Post(post_command.c_str()); return; }
bool DepthFirstOrder::check() { // check that post(v) is consistent with post() std::size_t r = 0; for (std::size_t v : PostOrder()) { if (Post(v) != r) { std::cout<<"post(v) and post() inconsistent"<<std::endl; return false; } r++; } // check that pre(v) is consistent with pre() r = 0; for (std::size_t v : PreOrder()) { if (Pre(v) != r) { std::cout<<"post(v) and post() inconsistent"<<std::endl; return false; } r++; } return true; }
//-------------------------------------------------------------------------------------- // read_posts() // // Reads *Posts.json and generates a MICP container. // Returns the maximum value of a "date_gmt" node. //-------------------------------------------------------------------------------------- time_t read_posts(char const* fname, MICP* micp) { myout << endl << clock()/CLOCKS_PER_SEC << "s\t read_posts: " << fname << " "; time_t max=0, min=LONG_MAX; string line; int count = 0; ifstream infile(fname); getline(infile, line, '\n'); while (!infile.eof()) { int size = line.size(); char* buf = new char[size]; line.copy(buf, size); char* sz = buf; time_t time = read_json_time(sz, "date_gmt"); max = MAX(time, max); int bid = read_json_str2int(sz, "blog"); int pid = read_json_str2int(sz, "post_id"); vector<unsigned> hash; read_json_hash(sz, "tags", &hash); read_json_hash(sz, "categories", &hash); micp->insert(Post(bid, pid, time, hash)); if (++count % 20000 == 0) myout << "." << flush; // progress bar getline(infile, line, '\n'); delete[] buf; } infile.close(); return max; }
Response *RESTRoute::Call(std::string url, std::string method, std::vector<std::pair<std::string, std::string> > get, std::vector<std::pair<std::string, std::string> > post) { std::smatch matches; bool result = std::regex_search(url, matches, route); std::string id = ""; if (result) { std::string match = matches[0]; int index = url.find(match); if (index != -1) { int start_index = index + match.size() + 1; if (start_index < int(url.size())) { id = url.substr(start_index); } } } if (method == "GET") { return Get(id); } else if (method == "POST") { return Post(post); } else if (method == "PUT") { return Put(id, post); } else if (method == "DELETE") { return Delete(id); } else if (method == "OPTIONS") { return Options(); } return nullptr; }
//****************************************************************************************** //function: doSetRelated //params: const QString &relate_this_id, const QString &with_this_ids //return: QJsonObject //Description: //Set relation between records. //param relate_this_id string ID of record we want to related other records with //param with_this_ids string/array either a string with one unique ID or an array of IDs to relate to the first parameter //****************************************************************************************** QJsonObject WSClient::doSetRelated(const QString &relate_this_id, const QString &with_these_ids) { if (!this->getCheckLogin()) { throw WSClientException( this->jsLoginError ); } QHash<QString, QString> params; params.insert("relate_this_id", relate_this_id); params.insert("with_these_ids", with_these_ids); qDebug() << params; QJsonObject response = Post("SetRelation", params); params.clear(); if ( !response.isEmpty() ) { QVariantMap map_json = response.toVariantMap(); QVariant success = map_json.value("success"); if ( success.toBool() ) { return response.value("result").toObject(); } else { QJsonObject error = response.value("error").toObject(); throw WSClientException( error ); } } throw WSClientException( jsNoData ); }
//****************************************************************************************** //function: doDelete //params: const QString &id //return: QJsonObject //Description: //****************************************************************************************** QJsonObject WSClient::doDelete(const QString &id) { if (!this->getCheckLogin()) { throw WSClientException( this->jsLoginError ); } QHash<QString, QString> params; params.insert("id", id); QJsonObject response = Post("delete", params); params.clear(); if ( !response.isEmpty() ) { QVariantMap map_json = response.toVariantMap(); QVariant success = map_json.value("success"); if ( success.toBool() ) { return response.value("result").toObject(); } else { QJsonObject error = response.value("error").toObject(); throw WSClientException( error ); } } throw WSClientException( jsNoData ); }
bool HttpClient::Post(const std::string& url, const std::string& data, HttpResponse* response, ErrorCode *error) { return Post(url, data, Options(), response, error); }
//****************************************************************************************** //function: doUpdate //params: const QHash<QString, QString> ¶ms //return: QJsonObject //Description: //****************************************************************************************** QJsonObject WSClient::doUpdate(const QHash<QString, QString> ¶ms) { if (!this->getCheckLogin()) { throw WSClientException( this->jsLoginError ); } if (params.count() >= 1) { QJsonObject item; QHashIterator<QString, QString> prm(params); while(prm.hasNext()) { prm.next(); item[prm.key()] = prm.value(); } QJsonDocument doc_item(item); QHash<QString, QString> parameters; parameters.insert("element", QString( doc_item.toJson() )); QJsonObject response = Post("update", parameters); return response; } else { throw "Datos incorrectos"; } }
void MMatchServer::OnAsyncInsertEvent( MAsyncJob* pJobResult ) { if( 0 == pJobResult ) return; MAsyncDBJob_EventLog* pEventJob = reinterpret_cast< MAsyncDBJob_EventLog* >( pJobResult ); if( pEventJob->GetAnnounce().empty() ) return; if( MASYNC_RESULT_SUCCEED == pJobResult->GetResult() ) { MCommand* pCmd; AsyncEventObjVec::const_iterator it, end; const AsyncEventObjVec& EventObjList = pEventJob->GetEventObjList(); end = EventObjList.end(); for( it = EventObjList.begin(); it != end; ++it ) { if( MUID(0, 0) != it->uidUser ) { pCmd = CreateCommand( MC_MATCH_ANNOUNCE, it->uidUser ); if( 0 != pCmd ) { pCmd->AddParameter( new MCmdParamUInt(0) ); pCmd->AddParameter( new MCmdParamStr(pEventJob->GetAnnounce().c_str()) ); Post( pCmd ); } } } } }
Word16 G729D_decode(BYTE *encodeddata, Word16 inlen, Word16 *pst_out, Word16 size) { Word16 i; parm[0] = 0; /* No frame erasure */ //for (i=2; i < serial_size; i++) // if (serial[i] == 0 ) // parm[0] = 1; /* frame erased */ BYTE_to_parm(encodeddata, &parm[1]); Decod_ld8kD(parm, voicing, synth, Az_dec, &T0_first); /* Postfilter */ voicing = 0; ptr_Az = Az_dec; for( i = 0 ; i < L_FRAME; i += L_SUBFR) { Post(T0_first, &synth[i], ptr_Az, &pst_out[i], &sf_voic); if (sf_voic != 0) { voicing = sf_voic; } ptr_Az += MP1; } Copy(&synth_buf[L_FRAME], &synth_buf[0], M); Post_Process(pst_out, L_FRAME); return L_FRAME; }
TEST (RouterTester, RegularExpressions) { HTTP::Router router; HTTP::Response response; router.Pipe ([&](const auto& data) { response = data; }); MockRegexEndPoint* endPoint = new MockRegexEndPoint (std::regex("\\/test\\/([A-Z]+)\\/other\\/([0-9]+)")); router.AddEndPoint (std::shared_ptr <HTTP::AbstractEndPoint> (endPoint)); EXPECT_CALL (*endPoint, Get (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint, Put (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint, Post (::testing::_, ::testing::_)).Times (0); EXPECT_CALL (*endPoint, Delete (::testing::_, ::testing::_)).Times (1); const HTTP::Request request (HTTP::Method::DELETE, std::string ("/test/ABCDEF/other/012345678")); router.Write (request); ASSERT_EQ (request.mVersion, response.mVersion); ASSERT_EQ (std::string ("/test/ABCDEF/other/012345678"), endPoint->GetList ()[0]); ASSERT_EQ (std::string ("ABCDEF"), endPoint->GetList ()[1]); ASSERT_EQ (std::string ("012345678"), endPoint->GetList ()[2]); // endpoint should set status code }
void MMatchClient::OnResponseAgentLogin() { MCommand* pCmd = CreateCommand(MC_AGENT_PEER_BINDTCP, GetAgentServerUID()); pCmd->AddParameter(new MCmdParamUID(GetPlayerUID())); Post(pCmd); mlog("Logged in Agent, Bind TCP \n"); }
// Closes the thread normally void QueryThread::GracefulExit() { // Set the exit code and signal thread to exit Post(QueryThread::Exit); // Wait until the thread has closed completely wxThread::Wait(); }
void MMatchServer::OnMatchLoginFailedFromDBAgent(const MUID& CommUID, int nResult) { #ifndef LOCALE_NHNUSA // 프로토콜 버전 체크 MCommand* pCmd = CreateCmdMatchResponseLoginFailed(CommUID, nResult); Post(pCmd); #endif }
void EstateController::postBuildingInterest(int buldingType) { std::string post_command = NativeLauncher::getNWAdress() + "/send_message?type=69&building=" + std::to_string(buldingType); Post(post_command.c_str()); return; }
void sTextControl::OnDrag(sDragData &dd) { if(MMBScrolling(dd,MMBX,MMBY)) return; switch(dd.Mode) { case sDD_START: Cursor = SelPos = ClickToPos(dd.MouseX,dd.MouseY); CursorWish = GetCursorX(); Post(CursorCmd); SelMode = 1; break; case sDD_DRAG: Cursor = ClickToPos(dd.MouseX,dd.MouseY); CursorWish = GetCursorX(); Post(CursorCmd); break; } }
void ReserveRetunrHomeController::update(float dt) { std::string post_command; if(_reserveReturne){ float remain = (NativeLauncher::getDestance())/(NativeLauncher::getNewLocation_speed()); if(remain > 0) { if(remain < 300){ // AirConditionaeer・5分前にエアコンスイッチ post_command = NativeLauncher::getNWAdress() + "/send_message?type=2"; Post(post_command.c_str()); } if(remain < 60){ // LED・1分前にLEDスイッチ post_command = NativeLauncher::getNWAdress() + "/send_message?type=16"; Post(post_command.c_str()); } if(remain < 30){ // post_command = NativeLauncher::getNWAdress() + "/send_message?type=22"; Post(post_command.c_str()); _reserveReturne = false; } if(remain < 15){ // ・目の間に着いたら、電動シャッター窓開放 : 輝度センサーで判断 post_command = NativeLauncher::getNWAdress() + "/send_message?type=27"; Post(post_command.c_str()); post_command = NativeLauncher::getNWAdress() + "/send_message?type=31"; Post(post_command.c_str()); } } } std::string temo = std::to_string(NativeLauncher::getDestance()/1000) + "km 残り" + std::to_string((NativeLauncher::getDestance()/NativeLauncher::getNewLocation_speed())/60) + "分"; }
//******************************************************************** // Name: TSendMail::~TSendMail // Input: // Output: // Description: DESTRUCTOR // Author/Date: jcar 20/9/96 // History: //******************************************************************** void TSMClose() { TLS_VARS; Post("QUIT\r\n"); Ack(); // to guarantee that the cleanup is not made twice and // compomise the rest of the application if sockets are used // elesewhere }