Example #1
0
void SqlLogger::flush() {
	if (m_buffer.size() > 0) {
		mysqlpp::Query query = Database::getCharDB().query("INSERT INTO logs VALUES ");
		for (vector<LogMessage>::const_iterator iter = m_buffer.begin(); iter != m_buffer.end(); ++iter) {
			if (iter != m_buffer.begin()) {
				query << ",";
			}
			query << "(DEFAULT, "
				<< mysqlpp::quote << mysqlpp::DateTime(iter->time) << ","
				<< getServerType() << ","
				<< iter->type << ","
				<< mysqlpp::quote << iter->identifier << ","
				<< mysqlpp::quote << iter->message << ")";
		}
		query.exec();
		m_buffer.clear();
	}
}
Example #2
0
void AbstractHttpChannel::processTypes(const std::map<TransportType, ChannelDirection>& types
#ifdef KAA_THREADSAFE
                                     , KAA_MUTEX_UNIQUE& lock
#endif
                                       )
{
    auto postRequest = createRequest(currentServer_, multiplexer_->compileRequest(types));

    KAA_MUTEX_UNLOCKING("channelGuard_");
    KAA_UNLOCK(lock);
    KAA_MUTEX_UNLOCKED("channelGuard_");

    try {
        // Sending http request
        EndpointConnectionInfo connection("", "", getServerType());
        auto response = httpClient_.sendRequest(*postRequest, &connection);
        channelManager_.onConnected(connection);

        KAA_MUTEX_LOCKING("channelGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(lockInternal, channelGuard_);
        KAA_MUTEX_LOCKED("channelGuard_");

        // Retrieving the avro data from the HTTP response
        const std::string& processedResponse = retrieveResponse(*response);

        KAA_MUTEX_UNLOCKING("channelGuard_");
        KAA_UNLOCK(lockInternal);
        KAA_MUTEX_UNLOCKED("channelGuard_");

        if (!processedResponse.empty()) {
            demultiplexer_->processResponse(
                    std::vector<std::uint8_t>(reinterpret_cast<const std::uint8_t *>(processedResponse.data()),
                                              reinterpret_cast<const std::uint8_t *>(processedResponse.data() + processedResponse.size())));
        }
    } catch (HttpTransportException& e) {
        KAA_LOG_WARN(boost::format("Channel [%1%] failed to connect %2%:%3%: %4%")
                                                                         % getId()
                                                                         % currentServer_->getHost()
                                                                         % currentServer_->getPort()
                                                                         % e.getHttpStatusCode());

        KaaFailoverReason reason;
        switch (e.getHttpStatusCode()) {
        case HttpStatusCode::UNAUTHORIZED:
            reason = KaaFailoverReason::ENDPOINT_NOT_REGISTERED;
            break;
        case HttpStatusCode::FORBIDDEN:
            reason = KaaFailoverReason::CREDENTIALS_REVOKED;
            break;
        default:
            reason = getNotAccessibleFailoverReason(getServerType());
            break;
        }

        onServerFailed(reason);
    } catch (TransportException& e) {
        KAA_LOG_WARN(boost::format("Channel [%1%] failed to connect %2%:%3%: %4%")
                                                                     % getId()
                                                                     % currentServer_->getHost()
                                                                     % currentServer_->getPort()
                                                                     % e.getErrorCode().message());

        KaaFailoverReason reason = getNotAccessibleFailoverReason(getServerType());
        if (connectivityChecker_ && !connectivityChecker_->checkConnectivity()) {
            KAA_LOG_WARN(boost::format("Channel [%1%] detected loss of connectivity")
                                                                          % getId());
            reason = KaaFailoverReason::NO_CONNECTIVITY;
        }

        onServerFailed(reason);
    }
}
int main(int argc, char **argv)
{
    uSynergyContext context;
    char *synergyClientName = "amiga";
    int keyCodesFromStdin = 0;
    int listUsbDevices = 1;
    int option = 0;

    while ((option = getopt(argc, argv,"n:t:s:x:y:d:h")) != -1) {
        switch (option) {
            case 'n':
                synergyClientName = optarg; 
                break;
            case 't':
                serverType = getServerType(optarg);
                break;
            case 's':
                usbSerialNum = optarg;
                break;
            case 'x':
                amigaMouseResWidth = atoi(optarg);
                break;
            case 'y':
                amigaMouseResHeight = atoi(optarg);
                break;
            case 'd':
                debugLevel = atoi(optarg);
                break;
            case 'h':
            default:
                fprintf(stderr, "Usage: %s [-n synergyClientName] [-t synergyServerType linux/mac/windows] [-s usbSerialNum] [-x amigaMouseResolutionWidth] [-y amigaMouseResulutionHeight] [-d debugLevel] [-]\n", argv[0]);
                exit(EXIT_FAILURE);
        }
    }
    if (optind < argc && strcmp(argv[optind], "-") == 0) {
        keyCodesFromStdin = 1;
    }

    int libusbResult = libusb_init(NULL);
    if(0 != libusbResult) {
        fprintf(stderr, "Initializing libusb: %s\n", libusb_strerror(libusbResult));
    }
    atexit(usb_cleanup);
    if(listUsbDevices)
        listUsbDeviceMatches(VENDOR_ID, PRODUCT_ID);
    usbhandle = find_device(VENDOR_ID, PRODUCT_ID, usbSerialNum);

    if (keyCodesFromStdin) {
        int c;
        fprintf(stderr, "Will send stdin as raw amiga keycodes to the avr\n");
        while((c = getchar())) {
            if (c < 0 || c == EOF) return 0;
            usb_send_amiga_key(c, c & 0x80);
        }
    }
    
    if(UnknownType == serverType) {
        fprintf(stderr, "Unknown server type!\n");
        return 1;
    }

    keycodes = getKeycodes(serverType);
    fprintf(stderr, "Server type: %s\n", getServerTypeName(serverType));

    fprintf(stderr, "Amiga mouse resolution: %dx%d\n", amigaMouseResWidth, amigaMouseResHeight);

    uSynergyInit(&context);
    context.m_connectFunc = &s_connect;
    context.m_sendFunc = &s_send;
    context.m_receiveFunc = &s_receive;
    context.m_sleepFunc = &s_sleep;
    context.m_getTimeFunc = &s_getTime;
    context.m_traceFunc = &s_trace;
    context.m_screenActiveCallback = &s_screenActive;
    context.m_mouseCallback = &s_mouse;
    context.m_mouseRelativeCallback = &s_mouserel;
    context.m_keyboardCallback = &s_keyboard;
    context.m_joystickCallback = &s_joystick;
    context.m_clipboardCallback = &s_clipboard;
    context.m_clientName = synergyClientName;
    context.m_clientWidth = amigaMouseResWidth;
    context.m_clientHeight = amigaMouseResHeight;

    for (;;) {
        uSynergyUpdate(&context);
    }
}
void DefaultOperationTcpChannel::openConnection()
{
    if (isConnected_) {
        KAA_LOG_WARN(boost::format("Channel [%1%] connection is already opened") % getId());
        return;
    }

    KAA_LOG_TRACE(boost::format("Channel [%1%] opening connection to %2%:%3%")
                                                        % getId()
                                                        % currentServer_->getHost()
                                                        % currentServer_->getPort());

    boost::system::error_code errorCode;

    boost::asio::ip::tcp::endpoint ep = HttpUtils::resolveEndpoint(currentServer_->getHost(),
                                                                   currentServer_->getPort(),
                                                                   errorCode);
    if (errorCode) {
        KAA_LOG_ERROR(boost::format("Channel [%1%] failed to resolve endpoint: %2%")
                                                                    % getId()
                                                                    % errorCode.message());
        onServerFailed();
        return;
    }

    responseBuffer_.reset(new boost::asio::streambuf());
    sock_.reset(new boost::asio::ip::tcp::socket(io_));
    sock_->open(ep.protocol(), errorCode);

    if (errorCode) {
        KAA_LOG_ERROR(boost::format("Channel [%1%] failed to open socket: %2%")
                                                            % getId()
                                                            % errorCode.message());
        onServerFailed();
        return;
    }

    sock_->connect(ep, errorCode);

    if (errorCode) {
        KAA_LOG_ERROR(boost::format("Channel [%1%] failed to connect to %2%:%3%: %4%")
                                                                % getId()
                                                                % ep.address().to_string()
                                                                % ep.port()
                                                                % errorCode.message());
        onServerFailed();
        return;
    }

    channelManager_.onConnected({sock_->local_endpoint().address().to_string(), ep.address().to_string(), getServerType()});

    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_LOCK(channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    isConnected_ = true;

    KAA_MUTEX_UNLOCKING("channelGuard_");
    KAA_UNLOCK(channelGuard_);
    KAA_MUTEX_UNLOCKED("channelGuard_");

    sendConnect();
    setConnAckTimer();
    readFromSocket();
    setPingTimer();
}