/**
 * ブラウザとの間に新しいソケットを開く
 */
void YASWebProxy::openNewSocket()
{
    QTcpSocket* socket = server->nextPendingConnection();
    connect(socket, SIGNAL(readyRead()), this, SLOT(openTunnel()));
    connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
    HttpParser* parser = new HttpParser(HttpParser::REQUEST, socket);
    parser->setObjectName("requestParser");
    connect(parser, SIGNAL(completeMessage(QByteArray)), this, SLOT(onRequest(QByteArray)));
}
Ejemplo n.º 2
0
 // Initiates a simple GET request to the transport
 void SetUp() override {
   EXPECT_CALL(m_server, onRequest(_))
     .WillOnce(Invoke([] (std::shared_ptr<ProxygenTransport> transport) {
           transport->setEnqueued();
         }));
   auto req = getRequest(HTTPMethod::GET);
   m_transport->onHeadersComplete(std::move(req));
   m_transport->onEOM();
 }
Ejemplo n.º 3
0
void i2c_init(void) {
	I2C_ADDR_DDR  = 0x40;		// All pins input
	I2C_ADDR_PORT = 0x0F;		// PC0 - PC3 enable pullup

	begin(~I2C_ADDR_PIN & 0x0F);
	onReceive(receiveEvent);
	onRequest(requestEvent);
	return;
}
Ejemplo n.º 4
0
void Connection::onRead( const boost::system::error_code& err, size_t bytes )
{
    std::cout << "On read..." << bytes << std::endl;

    if ( err )
	{
        std::cout << err.message() << " in onRead" << std::endl;
        stop();
        return;
    }

    std::string msg( _bigReadBuffer, bytes );
    //std::cout << "From " << _login << " client: " << msg << std::endl;

    Stanza st;
    try
    {
        st.load( msg );
    }
    catch ( ... )
    {
        std::cout << "Corrupted XML stanza" << std::endl;
        stop();
        return;
    }
//    if ( ( _loggedIn == false ) && ( st.getStanzaType() != Stanza::IQ ||
//         ( st.getSubType() != Stanza::SIGNIN && st.getSubType() != Stanza::SIGNUP ) ) )
//    {
//        stop();
//        return;
//    }

    switch ( st.getStanzaType() )
    {
        case Stanza::MESSAGE:
            onMessage( st );
            break;

        case Stanza::PRESENCE:
            onPresence();
            break;

        case Stanza::IQ:
            onRequest( st );
            break;

        case Stanza::ROASTER:
            onRoaster();
            break;

        default:
            break;
    }
}
Ejemplo n.º 5
0
TEST(GTestHttpEcho, TestConnectionClose) {
    GTestOnEnd::clear();
    GTestOnClose::clear();
    GTestHttpServerOnEnd::clear();
    GTestHttpClientOnResponse::clear();

    String::CPtr msg = String::create("xyz");

    http::Server::Ptr srv = http::Server::create();
    GTestHttpServerOnRequest::Ptr onRequest(
        new GTestHttpServerOnRequest(srv, NUM_REQS));
    srv->on(http::Server::EVENT_REQUEST, onRequest);
    srv->listen(10000);

    String::CPtr url = String::create("http://127.0.0.1:10000/abc");
    JsObject::Ptr options = url::parse(url);
    JsObject::Ptr headers = JsObject::create();
    headers->put(
        http::HEADER_CONNECTION,
        String::create("close"));
    headers->put(
        http::HEADER_CONTENT_LENGTH,
        String::valueOf(Buffer::byteLength(msg)));
    options->put(http::OPTION_HEADERS, headers);

    GTestHttpClientOnResponse::Ptr onResponse(new GTestHttpClientOnResponse());
    for (Size i = 0; i < NUM_REQS; i++) {
        http::ClientRequest::Ptr req = http::request(options, onResponse);
        req->write(msg);
        req->end();
    }

    node::run();

    ASSERT_EQ(0, GTestOnClose::count());

    JsArray::CPtr messages = GTestOnEnd::messages();
    JsArray::CPtr statusCodes = GTestHttpClientOnResponse::statusCodes();
    Size numMsgs = messages->length();
    Size numCodes = statusCodes->length();
    ASSERT_EQ(NUM_REQS, numMsgs);
    ASSERT_EQ(NUM_REQS, numCodes);
    for (Size i = 0; i < numMsgs; i++) {
        ASSERT_TRUE(messages->get(i).equals(msg));
        ASSERT_TRUE(statusCodes->get(i).equals(200));
        console::printf(console::INFO, ".");
    }
    console::printf(console::INFO, "\n");
}
Ejemplo n.º 6
0
void StormService::update(int64_t ms) {
	StormListener::Packet* packet;
	while (m_listener->m_queue.pop_front(packet, ms)) {
		switch (packet->type) {
			case StormListener::PacketType_Accept:
				onAccept(packet->conn);
				break;
			case StormListener::PacketType_Close:
				onClose(packet->conn, packet->closeType);
				break;
			case StormListener::PacketType_Packet:
				onRequest(packet->conn, packet->data.c_str(), packet->data.size());
				break;
		}
		delete packet;
	}
}
Ejemplo n.º 7
0
void Channel::onMessage(Json::Value &jsonObj)
{
    LOGI("%s:receive:%s",m_sComponentName.c_str(),jsonObj.toStyledString().data());
    bool run = false;
    // id
    if (jsonObj.isMember("id"))
    {
        int msgID = jsonObj["id"].asInt();
        if(jsonObj.isMember("result")){
            if(msgID==m_iIDRegRequest){
                run=true;
                m_iIDStart = jsonObj["result"].asInt();
                m_iGenerateId= m_iIDStart;
                onRegistered();

            }
            else if(msgID == m_iIDUnRegRequest){
                run=true;
                m_iIDUnRegRequest=jsonObj["result"].asInt();
                onUnregistered();
            }
            else
            {
                run=true;
                onResult(jsonObj);
            }
        }
        else if(jsonObj.isMember("error")){
            run=true;
            onError(jsonObj["error"].asString());
        }
        else{
            run=true;
            onRequest(jsonObj);
        }
    }
    else
    {
        run=true;
        onNotification(jsonObj);
    }

    if(!run){
        LOGE("NOT USED");
    }
}
Ejemplo n.º 8
0
int CEspProtocolThread::run()
{
    Link();
    try 
    {
        bool can_continue = false;      
        do
        {
            can_continue = onRequest();
        }
        while (can_continue);
    }
    catch (IException *e) 
    {
        StringBuffer estr;
        ERRLOG("Exception(%d, %s) in CEspProtocolThread::run while processing request.", e->errorCode(), e->errorMessage(estr).str());
        e->Release();
    }
    catch(...)
    {
        ERRLOG("Unknown Exception in CEspProtocolThread::run while processing request.");
    }

    if(!keepAlive)
    {
        try
        {
            m_socket->shutdown();
            m_socket->close();
        }
        catch (IException *e)
        {
            StringBuffer estr;
            DBGLOG("Exception(%d, %s) - in CEspProtocolThread::run while closing socket.", e->errorCode(), e->errorMessage(estr).str());
            e->Release();
        }
        catch(...)
        {
            DBGLOG("General Exception - in CEspProtocolThread::run while closing socket.");
        }
    }
    Release();
    return 0;
}
Ejemplo n.º 9
0
void InputMethodManager::load() {
    FCITX_D();

    auto inputMethods = d->addonManager_->addonNames(AddonCategory::InputMethod);
    auto &path = StandardPath::global();
    auto files = path.multiOpenAll(StandardPath::Type::Data, "fcitx5/inputmethod", O_RDONLY, filter::Suffix(".conf"));
    for (const auto &file : files) {
        auto &files = file.second;
        RawConfig config;
        // reverse the order, so we end up parse user file at last.
        for (auto iter = files.rbegin(), end = files.rend(); iter != end; iter++) {
            auto fd = iter->fd();
            readFromIni(config, fd);
        }

        InputMethodInfo imInfo;
        imInfo.load(config);
        InputMethodEntry entry = toInputMethodEntry(imInfo);
        if (checkEntry(entry, inputMethods) && d->entries_.count(entry.uniqueName()) == 0) {
            d->entries_.emplace(std::string(entry.uniqueName()), std::move(entry));
        }
    }
    for (const auto &addonName : inputMethods) {
        auto addonInfo = d->addonManager_->addonInfo(addonName);
        // on request input method should always provides entry with config file
        if (!addonInfo || addonInfo->onRequest()) {
            continue;
        }
        auto engine = static_cast<InputMethodEngine *>(d->addonManager_->addon(addonName));
        if (!engine) {
            continue;
        }
        auto newEntries = engine->listInputMethods();
        for (auto &newEntry : newEntries) {
            // ok we can't let you register something werid.
            if (checkEntry(newEntry, inputMethods) && newEntry.addon() == addonName &&
                d->entries_.count(newEntry.uniqueName()) == 0) {
                d->entries_.emplace(std::string(newEntry.uniqueName()), std::move(newEntry));
            }
        }
    }

    loadConfig();
}
Ejemplo n.º 10
0
void CV8DebugAdapter::onCommand(int id, const QVariantMap& Command)
{
	Q_ASSERT(attached || id == 0);

	QString typeStr = Command["type"].toString();
	QVariantMap Attributes = Command["attributes"].toMap();
	//QByteArray Temp = QJson::Serializer().serialize(Attributes);
	//qDebug() << "cmd: " << typeStr;

	pending.insert(id, typeStr);

	QJson::Serializer json;
	QVariantMap Response;
	if(typeStr == "Interrupt")
	{
		QVariantMap Variant;
		Variant["seq"] = id;
		Variant["type"] = "request";
		Variant["command"] = "suspend";

		QByteArray arrJson = json.serialize(Variant);
		onRequest(arrJson);
	}
	else if(typeStr == "Continue" || typeStr == "StepInto" || typeStr == "StepOver" || typeStr == "StepOut" || typeStr == "Resume")
	{
		// Note: Resume is an internal command mostly equivalent to Continue, but not exposed in the gui, 
		//	it is used to resume after breaks that are not intended to start interactive debugging.
		//	The debugger assumes that every event breaks the exectiotion, which is here not the case here,
		//	custome events dont stop the engine, those we ignore Resume commands if running is true
		if(!(typeStr == "Resume" && running))
		{
			// we have to preemptivly set the flag 
			//	or else we would have a short window in which we could mistake the engine for being halted while it actually runs.
			running = true; 

			QVariantMap Variant;
			Variant["seq"] = id;
			Variant["type"] = "request";
			Variant["command"] = "continue";

			Q_ASSERT(step == eNone || typeStr == "Resume");
			if(typeStr == "StepInto" || typeStr == "StepOver" || typeStr == "StepOut")
			{
				QVariantMap Arguments;
				if(typeStr == "StepInto")
				{
					step = eIn;
					Arguments["stepaction"] = "in";
				}
				else if(typeStr == "StepOver")
				{
					step = eNext;
					Arguments["stepaction"] = "next";
				}
				else if(typeStr == "StepOut")
				{
					step = eOut;
					Arguments["stepaction"] = "out";
				}
				//Arguments["stepcount"] = 1; // default is 1
				Variant["arguments"] = Arguments;
			}

			QByteArray arrJson = json.serialize(Variant);
			onRequest(arrJson);
		}

		Response["async"] = true;
	}
	else if(typeStr == "RunToLocation" || typeStr == "RunToLocationByID")
	{
		step = eLocation;

		{
		QVariantMap AuxCommand;
		AuxCommand["type"] = "SetBreakpoint";
		QVariantMap out;
		if(typeStr == "RunToLocationByID")
			out["scriptId"] = Attributes["scriptId"];
		else
			out["fileName"] = Attributes["fileName"];
		out["lineNumber"] = Attributes["lineNumber"];
		out["enabled"] = true;
		out["singleShot"] = true;
		QVariantMap AuxAttributes;
		AuxAttributes["breakpointData"] = out;
		AuxCommand["attributes"] = AuxAttributes;
		onCommand(0, AuxCommand);
		}

		{
		QVariantMap AuxCommand;
		AuxCommand["type"] = "Resume";
		onCommand(0, AuxCommand);
		}

		Response["async"] = true;
	}
	// {"seq":157,"type":"request","command":"restartframe","arguments":{"frame":0}} resets a frame
	else if(typeStr == "ForceReturn") // Used only in console commands
	{
		// Note: V8 currently does not support terminating frame execution early
		qDebug() << "Forced Return is Not Supported by V8";
	}

	else if(typeStr == "SetBreakpoint")
	{
		QVariantMap in = Attributes["breakpointData"].toMap();

		if(id != 0) // Note: breakpoint sets issued internaly are not listed
			breakpoints.insert(-id, in);

		QVariantMap Variant;
		Variant["seq"] = id;
		Variant["type"] = "request";
		Variant["command"] = "setbreakpoint";
		QVariantMap Arguments;
		if(in["scriptId"].toInt() != 0)
		{
			Arguments["type"] = "scriptId";
			Arguments["target"] = in["scriptId"];
		}
		else
		{
			Arguments["type"] = "script";
			Arguments["target"] = in["fileName"];
		}
		Arguments["line"] = in["lineNumber"];
		//Arguments["column"]
		Arguments["enabled"] = in["enabled"];
		Arguments["ignoreCount"] = in["ignoreCount"];
		Arguments["condition"] = in["condition"];
		Variant["arguments"] = Arguments;

		QByteArray arrJson = json.serialize(Variant);
		onRequest(arrJson);
		return;
	}
	else if(typeStr == "DeleteBreakpoint")
	{
		breakpoints.remove(Attributes["breakpointId"].toInt());

		QVariantMap Variant;
		Variant["seq"] = id;
		Variant["type"] = "request";
		Variant["command"] = "clearbreakpoint";
		QVariantMap Arguments;
		Arguments["breakpoint"] = Attributes["breakpointId"].toInt();
		Variant["arguments"] = Arguments;

		QByteArray arrJson = json.serialize(Variant);
		onRequest(arrJson);
	}
	else if(typeStr == "DeleteAllBreakpoints")
	{
		foreach(int break_id, breakpoints.keys())
		{
			QVariantMap AuxCommand;
			AuxCommand["type"] = "DeleteBreakpoint";
			QVariantMap AuxAttributes;
			AuxAttributes["breakpointId"] = break_id;
			AuxCommand["attributes"] = AuxAttributes;
			onCommand(0, AuxCommand);
		}
	}