コード例 #1
0
ファイル: kaa.c プロジェクト: kaaproject/kaa
static kaa_error_t kaa_context_create(kaa_context_t **context_p, kaa_logger_t *logger)
{
    // TODO(KAA-982): use asserts
    if (!context_p || !logger) {
        return KAA_ERR_BADPARAM;
    }

    kaa_context_t *context = KAA_CALLOC(1, sizeof(*context));
    if (!context) {
        return KAA_ERR_NOMEM;
    }

    context->logger = logger;

    kaa_error_t error = KAA_ERR_NONE;
    context->status = KAA_CALLOC(1, sizeof(*context->status));
    if (!context->status) {
        error = KAA_ERR_NOMEM;
        goto exit;
    }

    error = kaa_status_create(&context->status->status_instance);
    if (error) {
        goto exit;
    }

    error = kaa_platform_protocol_create(&context->platform_protocol, context->logger,
            context->status->status_instance);
    if (error) {
        goto exit;
    }

    error = kaa_channel_manager_create(&context->channel_manager, context);
    if (error) {
        goto exit;
    }

    error = kaa_extension_init_all(context);
    if (error) {
        goto exit;
    }

    error = kaa_failover_strategy_create(&context->failover_strategy, logger);
    if (error) {
        goto extensions_deinit;
    }

    *context_p = context;

    return KAA_ERR_NONE;

extensions_deinit:
    kaa_extension_deinit_all();

exit:
    kaa_context_destroy(context);

    return error;
}
コード例 #2
0
ファイル: kaa_profile.c プロジェクト: Oleh-Kravchenko/kaa
/** @deprecated Use kaa_extension_profile_init(). */
kaa_error_t kaa_profile_manager_create(kaa_profile_manager_t **profile_manager_p, kaa_status_t *status
        , kaa_channel_manager_t *channel_manager, kaa_logger_t *logger)
{
    if (!profile_manager_p || !channel_manager || !status) {
        return KAA_ERR_BADPARAM;
    }

    kaa_profile_manager_t *profile_manager = KAA_MALLOC(sizeof(kaa_profile_manager_t));
    if (!profile_manager) {
        return KAA_ERR_NOMEM;
    }

    /**
     * KAA_CALLOC is really needed.
     */
    profile_manager->extension_data = KAA_CALLOC(1, sizeof(kaa_profile_extension_data_t));
    if (!profile_manager->extension_data) {
        KAA_FREE(profile_manager);
        return KAA_ERR_NOMEM;
    }

    profile_manager->need_resync = true;

    profile_manager->profile_body.size = 0;
    profile_manager->profile_body.buffer = NULL;
    profile_manager->channel_manager = channel_manager;
    profile_manager->status = status;
    profile_manager->logger = logger;

    ext_calculate_sha_hash(NULL, 0, profile_manager->profile_hash);
    ext_copy_sha_hash(profile_manager->status->profile_hash, profile_manager->profile_hash);

    *profile_manager_p = profile_manager;
    return KAA_ERR_NONE;
}
コード例 #3
0
ファイル: kaa_client.c プロジェクト: kaaproject/kaa
kaa_error_t kaa_client_create(kaa_client_t **client, kaa_client_props_t *props) {
    (void)props;
    KAA_RETURN_IF_NIL(client, KAA_ERR_BADPARAM);

    kaa_client_t *self = (kaa_client_t*)KAA_CALLOC(1, sizeof(kaa_client_t));
    KAA_RETURN_IF_NIL(self, KAA_ERR_NOMEM);
    kaa_error_t error_code = kaa_init(&self->context);

    if(error_code) {
        printf("Error initialising kaa_context\n");
        kaa_client_destroy(self);
        return error_code;
    }

    self->operate = true;

#ifndef KAA_DISABLE_FEATURE_LOGGING
    error_code = kaa_log_collector_init(self);
    if (error_code) {
        KAA_LOG_ERROR(self->context->logger, error_code, "Failed to init Kaa log collector, error %d", error_code);
        kaa_client_destroy(self);
        return error_code;
    }
#endif

    KAA_LOG_INFO(self->context->logger,KAA_ERR_NONE, "Kaa client initiallized");
    *client = self;
    return error_code;
}
コード例 #4
0
/*
 * Test Check bootstrap channel sync call.
 * 1. Set access point, check connect and authorize sending CONNECT and receiving CONNACK
 * 2. Receive Bootstrap Kaa Sync message.
 * 3. Send disconnect, check sending.
 * 4. Check socket close.
 * 5. Call sync
 * 6. Check connect and authorize sending CONNECT and receiving CONNACK
 * 7. Receive Bootstrap Kaa Sync message.
 * 8. Send disconnect, check sending.
 * 9. Check socket close.
 */
void test_bootstrap_sync_success(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;

    kaa_transport_channel_interface_t *channel = NULL;
    channel = KAA_CALLOC(1,sizeof(kaa_transport_channel_interface_t));

    kaa_service_t bootstrap_services[] = {KAA_SERVICE_BOOTSTRAP};

    error_code = kaa_tcp_channel_create(channel,logger,bootstrap_services,1);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    //Set access point and imitate start of connection to destination
    test_set_access_point(channel);

    //Check standard bootstrap flow (connect, authenticate, sync receive and disconnect)
    test_check_bootstrap_sync(channel);


    //Imitate sync call
    channel->sync_handler(channel->context, bootstrap_services, 1);

    //Check standard bootstrap flow (connect, authenticate, sync receive and disconnect)
    test_check_bootstrap_sync(channel);

    channel->destroy(channel->context);

    KAA_TRACE_OUT(logger);

    KAA_FREE(channel);
}
コード例 #5
0
ファイル: test_kaa_log.c プロジェクト: Oleh-Kravchenko/kaa
mock_storage_context_t *create_mock_storage(void)
{
    mock_storage_context_t *storage = KAA_CALLOC(1, sizeof(mock_storage_context_t));
    KAA_RETURN_IF_NIL(storage, NULL);
    storage->logs = kaa_list_create();

    return storage;
}
コード例 #6
0
/*
 * Test IO error during operation.
 * 1. Set access point, check connect and authorize sending CONNECT and receiving CONNACK
 * 2. Imitate IO error on read
 * 3. Close socket, check bootstrap manager access point failure notification
 */
void test_set_access_point_io_error(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;

    kaa_transport_channel_interface_t *channel = NULL;
    channel = KAA_CALLOC(1,sizeof(kaa_transport_channel_interface_t));

    kaa_service_t bootstrap_services[] = {KAA_SERVICE_BOOTSTRAP};

    error_code = kaa_tcp_channel_create(channel,logger,bootstrap_services,1);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    //Set access point and imitate start of connection to destination
    test_set_access_point(channel);


    //Imitate WR event, and wait socket connect call, channel should start authorization, prepare
    //CONNECT message
    error_code = kaa_tcp_channel_process_event(channel,FD_WRITE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(access_point_test_info.socket_connected, true);
    ASSERT_EQUAL(access_point_test_info.socket_connected_callback, true);
    ASSERT_EQUAL(access_point_test_info.fill_connect_message, true);
    ASSERT_EQUAL(access_point_test_info.request_connect, true);


    //Check correct RD,WR operation, in this point we waiting for RD,WR operations true
    CHECK_SOCKET_RW(channel,true,true);

    //Imitate socket ready for writing, and writing CONNECT message
    error_code = kaa_tcp_channel_process_event(channel,FD_WRITE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(access_point_test_info.auth_packet_written, true);

    //Check correct RD,WR operation, in this point we waiting for RD operations true
    //and WR false, no pending services and empty buffer.
    CHECK_SOCKET_RW(channel,true,false);

    //Imitate socket ready for reading, and got IO error during read
    access_point_test_info.socket_connecting_error_scenario = true;
    error_code = kaa_tcp_channel_process_event(channel,FD_READ);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(access_point_test_info.connack_read, false);
    ASSERT_EQUAL(access_point_test_info.socket_disconnected_callback, true);
    ASSERT_EQUAL(access_point_test_info.socket_disconnected_closed, true);
    ASSERT_EQUAL(access_point_test_info.bootstrap_manager_on_access_point_failed, true);


    channel->destroy(channel->context);

    KAA_TRACE_OUT(logger);

    KAA_FREE(channel);
}
コード例 #7
0
ファイル: test_kaa_log.c プロジェクト: Oleh-Kravchenko/kaa
static void test_kaa_channel_create(kaa_transport_channel_interface_t *self)
{
    self->context = KAA_CALLOC(1, sizeof(mock_transport_channel_context_t));

    self->get_protocol_id = test_kaa_get_protocol_id;
    self->get_supported_services = test_kaa_get_supported_services;
    self->destroy = test_kaa_channel_destroy;
    self->sync_handler = test_kaa_sync_handler;
    self->init = test_kaa_init_channel;
    self->set_access_point = test_kaa_set_access_point;
}
コード例 #8
0
ファイル: io.c プロジェクト: Acarus/kaa
avro_writer_t avro_writer_memory(const char *buf, int64_t len)
{
    struct avro_writer_t_ *mem_writer = (struct avro_writer_t_ *) KAA_CALLOC(1,
            sizeof(struct avro_writer_t_));
    if (!mem_writer) {
        return NULL;
    }
    mem_writer->buf = buf;
    mem_writer->len = len;
    mem_writer->written = 0;
    return mem_writer;
}
コード例 #9
0
ファイル: kaa_configuration_gen.c プロジェクト: Acarus/kaa
static kaa_union_t *kaa_union_null_or_fixed_create(void)
{
    kaa_union_t *kaa_union = KAA_CALLOC(1, sizeof(kaa_union_t));

    if (kaa_union) {
        kaa_union->serialize = kaa_union_null_or_fixed_serialize;
        kaa_union->get_size = kaa_union_null_or_fixed_get_size;
        kaa_union->destroy = kaa_union_null_or_fixed_destroy;
    }

    return kaa_union; 
}
コード例 #10
0
ファイル: kaa_profile_gen.c プロジェクト: Acarus/kaa
kaa_profile_basic_endpoint_profile_test_t *kaa_profile_basic_endpoint_profile_test_create(void)
{
    kaa_profile_basic_endpoint_profile_test_t *record = 
            (kaa_profile_basic_endpoint_profile_test_t *)KAA_CALLOC(1, sizeof(kaa_profile_basic_endpoint_profile_test_t));

    if (record) {
        record->serialize = kaa_profile_basic_endpoint_profile_test_serialize;
        record->get_size = kaa_profile_basic_endpoint_profile_test_get_size;
        record->destroy = kaa_profile_basic_endpoint_profile_test_destroy;
    }

    return record;
}
コード例 #11
0
ファイル: kaa_configuration_gen.c プロジェクト: Acarus/kaa
kaa_configuration_root_record_t *kaa_configuration_root_record_create(void)
{
    kaa_configuration_root_record_t *record = 
            (kaa_configuration_root_record_t *)KAA_CALLOC(1, sizeof(kaa_configuration_root_record_t));

    if (record) {
        record->serialize = kaa_configuration_root_record_serialize;
        record->get_size = kaa_configuration_root_record_get_size;
        record->destroy = kaa_configuration_root_record_destroy;
    }

    return record;
}
コード例 #12
0
kaa_movement_class_movement_direction_t *kaa_movement_class_movement_direction_create()
{
    kaa_movement_class_movement_direction_t *record = 
            (kaa_movement_class_movement_direction_t *)KAA_CALLOC(1, sizeof(kaa_movement_class_movement_direction_t));

    if (record) {
        record->serialize = kaa_movement_class_movement_direction_serialize;
        record->get_size = kaa_movement_class_movement_direction_get_size;
        record->destroy = kaa_data_destroy;
    }

    return record;
}
コード例 #13
0
ファイル: kaa_buffer.c プロジェクト: nthevu/kaa
kaa_error_t kaa_buffer_create_buffer(kaa_buffer_t **buffer_p, size_t buffer_size)
{
    KAA_RETURN_IF_NIL2(buffer_p, buffer_size, KAA_ERR_BADPARAM);

    kaa_buffer_t *buffer = (kaa_buffer_t *) KAA_MALLOC(sizeof(kaa_buffer_t));
    KAA_RETURN_IF_NIL(buffer, KAA_ERR_NOMEM);

    buffer->begin = (char *) KAA_CALLOC(buffer_size , sizeof(char));
    if (!buffer->begin) {
        KAA_FREE(buffer);
        return KAA_ERR_NOMEM;
    }

    buffer->end = buffer->begin + buffer_size;
    buffer->current = buffer->begin;
    *buffer_p = buffer;
    return KAA_ERR_NONE;
}
コード例 #14
0
/*
 * Test create and destroy bootstrap channel
 */
void test_create_kaa_tcp_channel(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;

    kaa_transport_channel_interface_t *channel = NULL;
    channel = KAA_CALLOC(1,sizeof(kaa_transport_channel_interface_t));

    kaa_service_t bootstrap_services[] = {KAA_SERVICE_BOOTSTRAP};

    error_code = kaa_tcp_channel_create(channel,logger,bootstrap_services,1);

    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_NOT_NULL(channel->context);
    ASSERT_NOT_NULL(channel->get_protocol_id);
    ASSERT_NOT_NULL(channel->get_supported_services);
    ASSERT_NOT_NULL(channel->init);
    ASSERT_NOT_NULL(channel->destroy);
    ASSERT_NOT_NULL(channel->set_access_point);
    ASSERT_NOT_NULL(channel->sync_handler);

    kaa_transport_protocol_id_t protocol_info;
    error_code = channel->get_protocol_id(channel->context,&protocol_info);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(protocol_info.id, 0x56c8ff92);
    ASSERT_EQUAL(protocol_info.version, 1);

    kaa_service_t *r_supported_services;
    size_t r_supported_service_count = 0;
    error_code = channel->get_supported_services(channel->context,&r_supported_services,&r_supported_service_count);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(r_supported_service_count, 1);
    ASSERT_EQUAL(r_supported_services[0], KAA_SERVICE_BOOTSTRAP);

    channel->destroy(channel->context);

    KAA_TRACE_OUT(logger);

    KAA_FREE(channel);
}
コード例 #15
0
/*
 * Test connecting error during set access point.
 */
void test_set_access_point_connecting_error(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;

    kaa_transport_channel_interface_t *channel = NULL;
    channel = KAA_CALLOC(1,sizeof(kaa_transport_channel_interface_t));

    kaa_service_t bootstrap_services[] = {KAA_SERVICE_BOOTSTRAP};

    error_code = kaa_tcp_channel_create(channel,logger,bootstrap_services,1);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    //Set access point and imitate start of connection to destination
    test_set_access_point(channel);


    //Imitate WR event, and wait socket connect call and return socket connection error
    access_point_test_info.socket_connecting_error_scenario = true;
    error_code = kaa_tcp_channel_process_event(channel,FD_WRITE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(access_point_test_info.socket_connected_callback, false);
    ASSERT_EQUAL(access_point_test_info.fill_connect_message, false);
    ASSERT_EQUAL(access_point_test_info.request_connect, false);
    ASSERT_EQUAL(access_point_test_info.socket_connecting_error_callback, true);
    ASSERT_EQUAL(access_point_test_info.socket_disconnected_closed, true);
    ASSERT_EQUAL(access_point_test_info.bootstrap_manager_on_access_point_failed, true);


    channel->destroy(channel->context);

    KAA_TRACE_OUT(logger);

    KAA_FREE(channel);
}
コード例 #16
0
void test_kaatcp_parser()
{
    KAA_TRACE_IN(logger);

    kaatcp_parser_handlers_t handlers = { NULL, &connack_listener, &disconnect_listener, &kaasync_listener, &ping_listener };
    kaatcp_parser_t parser;

    parser.payload_buffer_size = 1;
    parser.payload = KAA_CALLOC(parser.payload_buffer_size, sizeof(char));

    kaatcp_error_t rval = kaatcp_parser_init(&parser, &handlers);
    ASSERT_EQUAL(rval, KAATCP_ERR_NONE);

    char connack_and_ping_messages[] = { 0x20, 0x02, 0x00, 0x03, 0xD0, 0x00 };
    rval = kaatcp_parser_process_buffer(&parser, connack_and_ping_messages, 6);
    ASSERT_EQUAL(rval, KAATCP_ERR_NONE);

    ASSERT_NOT_EQUAL(ping_received, 0);
    ASSERT_NOT_EQUAL(connack_received, 0);

    unsigned char kaa_sync_message[] = { 0xF0, 0x0D, 0x00, 0x06, 'K', 'a', 'a', 't', 'c', 'p', 0x01, 0x00, 0x05, 0x14, 0xFF };
    rval = kaatcp_parser_process_buffer(&parser, (const char *)kaa_sync_message, 15);
    ASSERT_EQUAL(rval, KAATCP_ERR_NONE);

    ASSERT_NOT_EQUAL(kaasync_received, 0);

    unsigned char disconnect_message[] = { 0xE0, 0x02, 0x00, 0x01 };
    rval = kaatcp_parser_process_buffer(&parser, (const char *) disconnect_message, 4);
    ASSERT_EQUAL(rval, KAATCP_ERR_NONE);

    ASSERT_NOT_EQUAL(disconnect_received, 0);

    KAA_FREE(parser.payload);

    KAA_TRACE_OUT(logger);
}