コード例 #1
0
ファイル: private.c プロジェクト: commshare/civetweb
END_TEST


START_TEST(test_is_valid_uri)
{
	ck_assert_int_eq(1, is_valid_uri("/api"));
	ck_assert_int_eq(0, is_valid_uri("api"));
	ck_assert_int_eq(1, is_valid_uri("*"));
	ck_assert_int_eq(0, is_valid_uri("*xy"));
}
コード例 #2
0
ファイル: wamp_dealer.cpp プロジェクト: tplgy/bonefish
void wamp_dealer::process_register_message(const wamp_session_id& session_id,
        wamp_register_message* register_message)
{
    auto session_itr = m_sessions.find(session_id);
    if (session_itr == m_sessions.end()) {
        throw std::logic_error("dealer session does not exist");
    }

    BONEFISH_TRACE("%1%, %2%", *session_itr->second % *register_message);

    // If the session registering the procedure does not support the callee
    // role than do not allow the call to be processed and send an error.
    if (!session_itr->second->get_role(wamp_role_type::CALLEE)) {
        send_error(session_itr->second->get_transport(), register_message->get_type(),
                register_message->get_request_id(), "wamp.error.role_violation");
        return;
    }

    const auto procedure = register_message->get_procedure();
    if (!is_valid_uri(procedure)) {
        send_error(session_itr->second->get_transport(), register_message->get_type(),
                register_message->get_request_id(), "wamp.error.invalid_uri");
        return;
    }

    auto procedure_registrations_itr = m_procedure_registrations.find(procedure);
    if (procedure_registrations_itr != m_procedure_registrations.end()) {
        send_error(session_itr->second->get_transport(), register_message->get_type(),
                register_message->get_request_id(), "wamp.error.procedure_already_exists");
        return;
    }

    const wamp_registration_id registration_id = m_registration_id_generator.generate();
    std::unique_ptr<wamp_dealer_registration> dealer_registration(
            new wamp_dealer_registration(session_itr->second, registration_id));
    m_procedure_registrations[procedure] = std::move(dealer_registration);

    m_session_registrations[session_id].insert(registration_id);
    m_registered_procedures[registration_id] = procedure;

    std::unique_ptr<wamp_registered_message> registered_message(
            new wamp_registered_message(register_message->release_zone()));
    registered_message->set_request_id(register_message->get_request_id());
    registered_message->set_registration_id(registration_id);

    // If we fail to send the registered message it is most likely that
    // the underlying network connection has been closed/lost which means
    // that the callee is no longer reachable on this session. So all we
    // do here is trace the fact that this event occured.
    BONEFISH_TRACE("%1%, %2%", *session_itr->second % *registered_message);
    if (!session_itr->second->get_transport()->send_message(std::move(*registered_message))) {
        BONEFISH_TRACE("failed to send registered message to caller: network failure");
    }
}
コード例 #3
0
static IplImage *
load_image (gchar * uri, gchar * dir, gchar * image_name,
    const gchar * name_variant)
{
  IplImage *aux;

  aux = cvLoadImage (uri, CV_LOAD_IMAGE_UNCHANGED);
  if (aux == NULL) {
    if (is_valid_uri (uri)) {
      gchar *file_name;

      file_name =
          g_strconcat (dir, "/", image_name, name_variant, ".png", NULL);
      load_from_url (file_name, uri);
      aux = cvLoadImage (file_name, CV_LOAD_IMAGE_UNCHANGED);
      g_remove (file_name);
      g_free (file_name);
    }
  }

  return aux;
}
コード例 #4
0
ファイル: wamp_dealer.cpp プロジェクト: tplgy/bonefish
void wamp_dealer::process_call_message(const wamp_session_id& session_id,
        wamp_call_message* call_message)
{
    auto session_itr = m_sessions.find(session_id);
    if (session_itr == m_sessions.end()) {
        throw std::logic_error("dealer session does not exist");
    }

    BONEFISH_TRACE("%1%, %2%", *session_itr->second % *call_message);

    // If the session placing the call does not support the caller role
    // than do not allow the call to be processed and send an error.
    if (!session_itr->second->get_role(wamp_role_type::CALLER)) {
        send_error(session_itr->second->get_transport(), call_message->get_type(),
                call_message->get_request_id(), "wamp.error.role_violation");
        return;
    }

    const auto procedure = call_message->get_procedure();
    if (!is_valid_uri(procedure)) {
        send_error(session_itr->second->get_transport(), call_message->get_type(),
                call_message->get_request_id(), "wamp.error.invalid_uri");
        return;
    }

    auto procedure_registrations_itr = m_procedure_registrations.find(procedure);
    if (procedure_registrations_itr == m_procedure_registrations.end()) {
        send_error(session_itr->second->get_transport(), call_message->get_type(),
                call_message->get_request_id(), "wamp.error.no_such_procedure");
        return;
    }

    std::shared_ptr<wamp_session> session =
            procedure_registrations_itr->second->get_session();

    const wamp_request_id request_id = m_request_id_generator.generate();

    const wamp_registration_id& registration_id =
            procedure_registrations_itr->second->get_registration_id();

    wamp_call_options call_options;
    call_options.unmarshal(call_message->get_options());

    // You can't rely on simply assigning the call options to the invocation
    // details. Some call options may only be applicable to the dealer and
    // not the callee. Likewise, some invocation details may be in addition
    // to whatever is provided in the call options. As a result, we only copy
    // specific options over to the invocation details.
    wamp_invocation_details invocation_details;
    if (call_options.get_option_or("receive_progress", false)) {
        invocation_details.set_detail("receive_progress", true);
    }

    std::unique_ptr<wamp_invocation_message> invocation_message(
            new wamp_invocation_message(call_message->release_zone()));
    invocation_message->set_request_id(request_id);
    invocation_message->set_registration_id(registration_id);
    invocation_message->set_details(invocation_details.marshal(invocation_message->get_zone()));
    invocation_message->set_arguments(call_message->get_arguments());
    invocation_message->set_arguments_kw(call_message->get_arguments_kw());

    BONEFISH_TRACE("%1%, %2%", *session_itr->second % *invocation_message);
    if (!session->get_transport()->send_message(std::move(*invocation_message))) {
        BONEFISH_TRACE("sending invocation message to callee failed: network failure");

        send_error(session_itr->second->get_transport(), call_message->get_type(),
                call_message->get_request_id(), "wamp.error.network_failure");
        return;
    }

    unsigned timeout_ms = call_options.get_option_or<unsigned>("timeout", 0);

    // We only setup the invocation state after sending the message is successful.
    // This saves us from having to cleanup any state if the send fails.
    std::unique_ptr<wamp_dealer_invocation> dealer_invocation(
            new wamp_dealer_invocation(m_io_service));

    dealer_invocation->set_session(session_itr->second);
    dealer_invocation->set_request_id(call_message->get_request_id());
    dealer_invocation->set_timeout(
            std::bind(&wamp_dealer::invocation_timeout_handler, this,
                    request_id, std::placeholders::_1), timeout_ms);

    m_pending_invocations.insert(std::make_pair(request_id, std::move(dealer_invocation)));
    m_pending_callee_invocations[session->get_session_id()].insert(request_id);
    m_pending_caller_invocations[session_id].insert(request_id);
}
コード例 #5
0
ファイル: wamp_dealer.cpp プロジェクト: estan/bonefish
void wamp_dealer::process_call_message(const wamp_session_id& session_id,
        wamp_call_message* call_message)
{
    auto session_itr = m_sessions.find(session_id);
    if (session_itr == m_sessions.end()) {
        throw std::logic_error("dealer session does not exist");
    }

    BONEFISH_TRACE("%1%, %2%", *session_itr->second % *call_message);

    // If the session placing the call does not support the caller role
    // than do not allow the call to be processed and send an error.
    if (!session_itr->second->get_role(wamp_role_type::CALLER)) {
        send_error(session_itr->second->get_transport(), call_message->get_type(),
                call_message->get_request_id(), "wamp.error.role_violation");
        return;
    }

    const auto procedure = call_message->get_procedure();
    if (!is_valid_uri(procedure)) {
        send_error(session_itr->second->get_transport(), call_message->get_type(),
                call_message->get_request_id(), "wamp.error.invalid_uri");
        return;
    }

    auto procedure_registrations_itr = m_procedure_registrations.find(procedure);
    if (procedure_registrations_itr == m_procedure_registrations.end()) {
        send_error(session_itr->second->get_transport(), call_message->get_type(),
                call_message->get_request_id(), "wamp.error.no_such_procedure");
        return;
    }

    std::shared_ptr<wamp_session> session =
            procedure_registrations_itr->second->get_session();

    const wamp_request_id request_id = m_request_id_generator.generate();

    const wamp_registration_id& registration_id =
            procedure_registrations_itr->second->get_registration_id();

    std::unique_ptr<wamp_invocation_message> invocation_message(
            new wamp_invocation_message(std::move(call_message->release_zone())));
    invocation_message->set_request_id(request_id);
    invocation_message->set_registration_id(registration_id);
    invocation_message->set_arguments(call_message->get_arguments());
    invocation_message->set_arguments_kw(call_message->get_arguments_kw());

    BONEFISH_TRACE("%1%, %2%", *session_itr->second % *invocation_message);
    if (!session->get_transport()->send_message(std::move(*invocation_message))) {
        BONEFISH_TRACE("sending invocation message to callee failed: network failure");

        send_error(session_itr->second->get_transport(), call_message->get_type(),
                call_message->get_request_id(), "wamp.error.network_failure");
        return;
    } else {
        wamp_call_options options;
        options.unmarshal(call_message->get_options());
        unsigned timeout_ms = options.get_option_or<unsigned>("timeout", 0);

        // We only setup the invocation state after sending the message is successful.
        // This saves us from having to cleanup any state if the send fails.
        std::unique_ptr<wamp_dealer_invocation> dealer_invocation(
                new wamp_dealer_invocation(m_io_service));

        dealer_invocation->set_session(session_itr->second);
        dealer_invocation->set_request_id(call_message->get_request_id());
        dealer_invocation->set_timeout(
                std::bind(&wamp_dealer::invocation_timeout_handler, this,
                        request_id, std::placeholders::_1), timeout_ms);

        m_pending_invocations.insert(std::make_pair(request_id, std::move(dealer_invocation)));
        m_pending_callee_invocations[session->get_session_id()].insert(request_id);
        m_pending_caller_invocations[session_id].insert(request_id);
    }
}