Ejemplo n.º 1
0
static kaa_error_t kaa_context_destroy(kaa_context_t *context)
{
    KAA_RETURN_IF_NIL(context, KAA_ERR_BADPARAM);

    kaa_user_manager_destroy(context->user_manager);
#ifndef KAA_DISABLE_FEATURE_EVENTS
    kaa_event_manager_destroy(context->event_manager);
#endif
    kaa_profile_manager_destroy(context->profile_manager);
    kaa_bootstrap_manager_destroy(context->bootstrap_manager);
    kaa_channel_manager_destroy(context->channel_manager);
    kaa_status_destroy(context->status->status_instance);
    kaa_failover_strategy_destroy(context->failover_strategy);
    KAA_FREE(context->status);
#ifndef KAA_DISABLE_FEATURE_LOGGING
    kaa_log_collector_destroy(context->log_collector);
#endif
#ifndef KAA_DISABLE_FEATURE_CONFIGURATION
    kaa_configuration_manager_destroy(context->configuration_manager);
#endif
#ifndef KAA_DISABLE_FEATURE_NOTIFICATION
    kaa_notification_manager_destroy(context->notification_manager);
#endif
    kaa_platform_protocol_destroy(context->platform_protocol);
    KAA_FREE(context);
    return KAA_ERR_NONE;
}
Ejemplo n.º 2
0
static void destroy_log_record(void *record_p)
{
    if (record_p) {
        test_log_record_t *test_rec = record_p;
        KAA_FREE(test_rec->rec.data);
        KAA_FREE(test_rec);
    }
}
Ejemplo n.º 3
0
kaa_error_t kaa_profile_manager_update_profile(kaa_profile_manager_t *self, kaa_profile_t *profile_body)
{
#if KAA_PROFILE_SCHEMA_VERSION > 0
    KAA_RETURN_IF_NIL2(self, profile_body, KAA_ERR_BADPARAM);

    size_t serialized_profile_size = profile_body->get_size(profile_body);
    if (!serialized_profile_size) {
        KAA_LOG_ERROR(self->logger, KAA_ERR_BADDATA,
                      "Failed to update profile: serialize profile size is null. Maybe profile schema is empty");
        return KAA_ERR_BADDATA;
    }

    char *serialized_profile = (char *) KAA_MALLOC(serialized_profile_size * sizeof(char));
    KAA_RETURN_IF_NIL(serialized_profile, KAA_ERR_NOMEM);

    avro_writer_t writer = avro_writer_memory(serialized_profile, serialized_profile_size);
    if (!writer) {
        KAA_FREE(serialized_profile);
        return KAA_ERR_NOMEM;
    }
    profile_body->serialize(writer, profile_body);
    avro_writer_free(writer);

    kaa_digest new_hash;
    ext_calculate_sha_hash(serialized_profile, serialized_profile_size, new_hash);

    if (!memcmp(new_hash, self->status->profile_hash, SHA_1_DIGEST_LENGTH)) {
        self->need_resync = false;
        KAA_FREE(serialized_profile);
        return KAA_ERR_NONE;
    }

    KAA_LOG_INFO(self->logger, KAA_ERR_NONE, "Endpoint profile is updated");

    if (ext_copy_sha_hash(self->status->profile_hash, new_hash)) {
        KAA_FREE(serialized_profile);
        return KAA_ERR_BAD_STATE;
    }

    if (self->profile_body.size > 0) {
        KAA_FREE(self->profile_body.buffer);
        self->profile_body.buffer = NULL;
    }

    self->profile_body.buffer = (uint8_t*)serialized_profile;
    self->profile_body.size = serialized_profile_size;

    self->need_resync = true;

    kaa_transport_channel_interface_t *channel =
            kaa_channel_manager_get_transport_channel(self->channel_manager, profile_sync_services[0]);
    if (channel)
        channel->sync_handler(channel->context, profile_sync_services, 1);

#endif
    return KAA_ERR_NONE;
}
Ejemplo n.º 4
0
kaa_error_t kaa_buffer_destroy(kaa_buffer_t *buffer_p)
{
    KAA_RETURN_IF_NIL(buffer_p, KAA_ERR_BADPARAM);

    if (buffer_p->begin)
        KAA_FREE(buffer_p->begin);

    KAA_FREE(buffer_p);

    return KAA_ERR_NONE;
}
Ejemplo n.º 5
0
Archivo: kaa.c Proyecto: kaaproject/kaa
static kaa_error_t kaa_context_destroy(kaa_context_t *context)
{
    KAA_RETURN_IF_NIL(context, KAA_ERR_BADPARAM);

    kaa_channel_manager_destroy(context->channel_manager);
    kaa_status_destroy(context->status->status_instance);
    kaa_failover_strategy_destroy(context->failover_strategy);
    KAA_FREE(context->status);
    kaa_platform_protocol_destroy(context->platform_protocol);
    KAA_FREE(context);
    return KAA_ERR_NONE;
}
Ejemplo n.º 6
0
/** @deprecated Use kaa_extension_profile_deinit(). */
void kaa_profile_manager_destroy(kaa_profile_manager_t *self)
{
    if (self) {
        if (self->profile_body.buffer && self->profile_body.size > 0) {
            KAA_FREE(self->profile_body.buffer);
        }
        if (self->extension_data) {
            if (self->extension_data->public_key.buffer && self->extension_data->public_key.destroy) {
                self->extension_data->public_key.destroy(self->extension_data->public_key.buffer);
            }
            KAA_FREE(self->extension_data);
        }
        KAA_FREE(self);
    }
}
/*
 * 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);
}
Ejemplo n.º 8
0
kaa_error_t kaa_platform_protocol_create(kaa_platform_protocol_t **platform_protocol_p,
        kaa_logger_t *logger, kaa_status_t *status)
{
    if (!platform_protocol_p || !logger || !status) {
        return KAA_ERR_BADPARAM;
    }

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

    **platform_protocol_p = (kaa_platform_protocol_t){
        .request_id = 0,
        .status = status,
        .logger = logger,
    };

    return KAA_ERR_NONE;
}

void kaa_platform_protocol_destroy(kaa_platform_protocol_t *self)
{
    KAA_FREE(self);
}
Ejemplo n.º 9
0
/** @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;
}
Ejemplo n.º 10
0
void ext_status_read(char **buffer, size_t *buffer_size, bool *needs_deallocation)
{
    *buffer = NULL;
    *buffer_size = 0;
    *needs_deallocation = true;

    FILE* status_file = fopen(KAA_STATUS_STORAGE, "rb");

    if (!status_file) {
        return;
    }

    fseek(status_file, 0, SEEK_END);
    *buffer_size = ftell(status_file);
    *buffer = (char *) KAA_MALLOC((*buffer_size) * sizeof(char));

    if (*buffer == NULL) {
        *buffer_size = 0;
        fclose(status_file);
        return;
    }

    fseek(status_file, 0, SEEK_SET);
    if (fread(*buffer, *buffer_size, 1, status_file) == 0) {
        *buffer_size = 0;
        KAA_FREE(*buffer);
    }
    *needs_deallocation = true;
    fclose(status_file);
}
Ejemplo n.º 11
0
void test_empty_log_collector_extension_count(void)
{
    kaa_service_t service = KAA_SERVICE_LOGGING;
    info = (kaa_serialize_info_t *) KAA_MALLOC(sizeof(kaa_serialize_info_t));
    info->services = &service;
    info->services_count = 1;
    info->allocator = &allocator;
    info->allocator_context = mock;

    void *log_storage_context         = NULL;
    void *log_upload_strategy_context = NULL;

    kaa_error_t error_code = ext_unlimited_log_storage_create(&log_storage_context, kaa_context->logger);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_upload_strategy_create(kaa_context
                                              , &log_upload_strategy_context
                                              , KAA_LOG_UPLOAD_VOLUME_STRATEGY);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_logging_init(kaa_context->log_collector, log_storage_context, log_upload_strategy_context);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_platform_protocol_serialize_client_sync(kaa_context->platform_protocol, info, &buffer, &buffer_size);
    KAA_FREE(info);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    char count_of_extensions = *(buffer + 7);
    KAA_LOG_DEBUG(kaa_context->logger, KAA_ERR_NONE, "count of extensions is %d, expected 1", count_of_extensions);
    ASSERT_EQUAL(count_of_extensions, 1);
}
Ejemplo n.º 12
0
kaa_error_t ext_log_storage_destroy(void *context)
{
    if (context) {
        kaa_list_destroy(((mock_storage_context_t *)context)->logs, &destroy_log_record);
        KAA_FREE(context);
    }
    return KAA_ERR_NONE;
}
Ejemplo n.º 13
0
void kaa_configuration_manager_destroy(kaa_configuration_manager_t *self)
{
    if (self) {
        if (self->root_record)
            self->root_record->destroy(self->root_record);
        KAA_FREE(self);
    }
}
Ejemplo n.º 14
0
kaa_error_t kaa_configuration_manager_create(kaa_configuration_manager_t **configuration_manager_p, kaa_channel_manager_t *channel_manager, kaa_status_t *status, kaa_logger_t *logger)
{
    KAA_RETURN_IF_NIL3(configuration_manager_p, status, logger, KAA_ERR_BADPARAM);
    kaa_configuration_manager_t *manager = (kaa_configuration_manager_t *) KAA_MALLOC(sizeof(kaa_configuration_manager_t));
    KAA_RETURN_IF_NIL(manager, KAA_ERR_NOMEM);

    manager->channel_manager = channel_manager;
    manager->status = status;
    manager->logger = logger;
    manager->root_receiver = (kaa_configuration_root_receiver_t) { NULL, NULL };

    char *buffer = NULL;
    size_t buffer_size = 0;
    bool need_deallocation = false;
    if (status->is_updated)
        ext_configuration_read(&buffer, &buffer_size, &need_deallocation);
    else
        ext_configuration_delete();
    if (!buffer || !buffer_size) {
        need_deallocation = false;
#if KAA_CONFIGURATION_DATA_LENGTH > 0
        buffer = (char *)KAA_CONFIGURATION_DATA;
        buffer_size = KAA_CONFIGURATION_DATA_LENGTH;
#endif
    }

    if (buffer && buffer_size > 0) {
        ext_calculate_sha_hash(buffer, buffer_size, manager->configuration_hash);
        manager->root_record = kaa_configuration_manager_deserialize(buffer, buffer_size);

        if (!manager->root_record) {
            KAA_FREE(manager);
            if (need_deallocation && buffer)
                KAA_FREE(buffer);
            return KAA_ERR_NOMEM;
        }

        if (need_deallocation)
            KAA_FREE(buffer);
    }

    *configuration_manager_p = manager;
    return KAA_ERR_NONE;
}
/*
 * 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);
}
Ejemplo n.º 16
0
kaa_error_t kaa_init(kaa_context_t **kaa_context_p)
{
    KAA_RETURN_IF_NIL(kaa_context_p, KAA_ERR_BADPARAM);

    // Initialize logger
    kaa_logger_t *logger = NULL;

    FILE *logfile = fopen("run.log", "w");

    kaa_error_t error = kaa_log_create(&logger, KAA_MAX_LOG_MESSAGE_LENGTH, KAA_MAX_LOG_LEVEL, logfile); // TODO: make log destination configurable
    if (error)
        return error;

    KAA_LOG_INFO(logger, KAA_ERR_NONE, "Kaa SDK version %s, commit hash %s", BUILD_VERSION, BUILD_COMMIT_HASH);

    // Initialize general Kaa context
    error = kaa_context_create(kaa_context_p, logger);
    if (error) {
        KAA_LOG_FATAL(logger, error, "Failed to create Kaa context");
        kaa_log_destroy(logger);
        *kaa_context_p = NULL;
        return error;
    }

    // Initialize endpoint identity
    char *pub_key_buffer = NULL;
    size_t pub_key_buffer_size = 0;
    bool need_deallocation = false;

    ext_get_endpoint_public_key(&pub_key_buffer, &pub_key_buffer_size, &need_deallocation);
    kaa_digest pub_key_hash;
    error = ext_calculate_sha_hash(pub_key_buffer, pub_key_buffer_size, pub_key_hash);

    if (need_deallocation && pub_key_buffer_size > 0) {
        KAA_FREE(pub_key_buffer);
    }

    if (error) {
        KAA_LOG_FATAL(logger, error, "Failed to calculate EP ID");
        kaa_context_destroy(*kaa_context_p);
        *kaa_context_p = NULL;
        kaa_log_destroy(logger);
        return error;
    }

    error = ext_copy_sha_hash((*kaa_context_p)->status->status_instance->endpoint_public_key_hash, pub_key_hash);
    if (error) {
        KAA_LOG_FATAL(logger, error, "Failed to set Endpoint public key");
        kaa_context_destroy(*kaa_context_p);
        *kaa_context_p = NULL;
        kaa_log_destroy(logger);
        return error;
    }
    return KAA_ERR_NONE;
}
Ejemplo n.º 17
0
int test_deinit(void)
{
    if (context) {
        kaa_deinit(context);
    }
    if (buffer_pointer) {
        KAA_FREE(buffer_pointer);
    }

    return 0;
}
Ejemplo n.º 18
0
void test_serializing(void)
{
    KAA_TRACE_IN(context->logger);

    kaa_serialize_info_t *info = (kaa_serialize_info_t *) KAA_MALLOC(sizeof(kaa_serialize_info_t));

    kaa_service_t service[] = { KAA_SERVICE_NOTIFICATION };

    info->services = service;
    info->services_count = 1;
    info->allocator = &allocator;
    info->allocator_context = &allocator; //mock
    err = kaa_platform_protocol_serialize_client_sync(context->platform_protocol, info, &buffer, &buffer_size);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    KAA_FREE(buffer);
    KAA_FREE(info);

    KAA_TRACE_OUT(context->logger);
}
Ejemplo n.º 19
0
void test_profile_sync_get_size(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = KAA_ERR_NONE;
    kaa_profile_t *profile = kaa_profile_basic_endpoint_profile_test_create();
    profile->profile_body = kaa_string_copy_create("dummy");

    size_t serialized_profile_size = profile->get_size(profile);
    char *serialized_profile = (char *) KAA_MALLOC(serialized_profile_size * sizeof(char));
    avro_writer_t writer = avro_writer_memory(serialized_profile, serialized_profile_size);
    profile->serialize(writer, profile);

    size_t expected_size = KAA_EXTENSION_HEADER_SIZE
                         + sizeof(uint32_t)  // profile size
                         + kaa_aligned_size_get(serialized_profile_size);

    size_t profile_sync_size = 0;

    error_code = kaa_profile_manager_update_profile(profile_manager, profile);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    status->is_registered = true;

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    status->is_registered = false;

    expected_size += sizeof(uint32_t)
                   + TEST_PUB_KEY_SIZE;

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    const char *access_token = "access token";
    error_code = kaa_profile_manager_set_endpoint_access_token(profile_manager, access_token);

    expected_size += sizeof(uint32_t)
                   + strlen(access_token);

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    avro_writer_free(writer);
    KAA_FREE(serialized_profile);
    profile->destroy(profile);

    KAA_TRACE_OUT(logger);
}
Ejemplo n.º 20
0
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;
}
Ejemplo n.º 21
0
static kaa_error_t remember_request(kaa_log_collector_t *self, uint16_t bucket_id)
{
    KAA_RETURN_IF_NIL(self, KAA_ERR_BADPARAM);

    timeout_info_t *info = (timeout_info_t *)KAA_MALLOC(sizeof(timeout_info_t));
    KAA_RETURN_IF_NIL(info, KAA_ERR_NOMEM);

    info->log_bucket_id = bucket_id;
    info->timeout = KAA_TIME() + (kaa_time_t)ext_log_upload_strategy_get_timeout(self->log_upload_strategy_context);

    kaa_list_node_t *it = kaa_list_push_back(self->timeouts, info);
    if (!it) {
        KAA_FREE(info);
        return KAA_ERR_NOMEM;
    }

    return KAA_ERR_NONE;
}
/*
 * 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);
}
/*
 * 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);
}
Ejemplo n.º 24
0
static kaa_error_t remember_request(kaa_log_collector_t *self, uint16_t bucket_id, uint16_t count)
{
    // TODO(KAA-982): Use asserts
    if (!self) {
        return KAA_ERR_BADPARAM;
    }

    timeout_info_t *info = KAA_MALLOC(sizeof(*info));
    if (!info) {
        return KAA_ERR_NOMEM;
    }

    info->log_bucket_id = bucket_id;
    info->deadline = KAA_TIME() + (kaa_time_t)ext_log_upload_strategy_get_timeout(self->log_upload_strategy_context);
    info->log_count = count;

    kaa_list_node_t *it = kaa_list_push_back(self->timeouts, info);
    if (!it) {
        KAA_FREE(info);
        return KAA_ERR_NOMEM;
    }

    return KAA_ERR_NONE;
}
Ejemplo n.º 25
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);
}
Ejemplo n.º 26
0
kaa_error_t ext_log_storage_deallocate_log_record_buffer(void *context, kaa_log_record_t *record)
{
    (void)context;
    KAA_FREE(record->data);
    return KAA_ERR_NONE;
}
Ejemplo n.º 27
0
static kaa_error_t test_kaa_channel_destroy(void *context)
{
    KAA_FREE(context);
    return KAA_ERR_NONE;
}
Ejemplo n.º 28
0
void kaa_platform_protocol_destroy(kaa_platform_protocol_t *self)
{
    if (self) {
        KAA_FREE(self);
    }
}
Ejemplo n.º 29
0
void test_profile_sync_serialize(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    kaa_platform_message_writer_t *manual_writer;
    kaa_platform_message_writer_t *auto_writer;

    const char *access_token = "access token";
    const size_t access_token_size = strlen(access_token);
    kaa_profile_t *profile = kaa_profile_basic_endpoint_profile_test_create();
    profile->profile_body = kaa_string_copy_create("dummy");
    size_t serialized_profile_size = profile->get_size(profile);
    char *serialized_profile = (char *) KAA_MALLOC(serialized_profile_size * sizeof(char));
    avro_writer_t avro_writer = avro_writer_memory(serialized_profile, serialized_profile_size);

    profile->serialize(avro_writer, profile);

    error_code = kaa_profile_manager_update_profile(profile_manager, profile);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    status->is_registered = false;
    error_code = kaa_profile_manager_set_endpoint_access_token(profile_manager, access_token);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t profile_sync_size;
    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    char buffer[profile_sync_size];
    error_code = kaa_platform_message_writer_create(&manual_writer, buffer, profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    uint32_t network_order_32;

    error_code = kaa_platform_message_write_extension_header(manual_writer
                                                           , KAA_PROFILE_EXTENSION_TYPE
                                                           , 0
                                                           , profile_sync_size - KAA_EXTENSION_HEADER_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    bool need_resync = true;
    ASSERT_EQUAL(kaa_profile_need_profile_resync(profile_manager, &need_resync), KAA_ERR_NONE);

    network_order_32 = KAA_HTONL(0);
    if (need_resync)
        network_order_32 = KAA_HTONL(serialized_profile_size);
    error_code = kaa_platform_message_write(manual_writer, &network_order_32, sizeof(uint32_t));
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    if (need_resync) {
        error_code = kaa_platform_message_write_aligned(manual_writer, serialized_profile, serialized_profile_size);
        ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    }

    network_order_32 = KAA_HTONS(TEST_PUB_KEY_SIZE) << 16 | PUB_KEY_VALUE;
    error_code = kaa_platform_message_write(manual_writer, &network_order_32, sizeof(uint32_t));
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_platform_message_write_aligned(manual_writer, test_ep_key, TEST_PUB_KEY_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    network_order_32 = KAA_HTONS(access_token_size) << 16 | ACCESS_TOKEN_VALUE;
    error_code = kaa_platform_message_write(manual_writer, &network_order_32, sizeof(uint32_t));
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_platform_message_write_aligned(manual_writer, access_token, access_token_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    char buffer2[profile_sync_size];
    error_code = kaa_platform_message_writer_create(&auto_writer, buffer2, profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_profile_request_serialize(profile_manager, auto_writer);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = (memcmp(buffer, buffer2, profile_sync_size) == 0 ? KAA_ERR_NONE : KAA_ERR_BADDATA);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    KAA_FREE(serialized_profile);
    avro_writer_free(avro_writer);
    profile->destroy(profile);
    kaa_platform_message_writer_destroy(auto_writer);
    kaa_platform_message_writer_destroy(manual_writer);

    KAA_TRACE_OUT(logger);
}
Ejemplo n.º 30
0
int test_deinit()
{
    kaa_deinit(kaa_context);
    KAA_FREE(buffer);
    return KAA_ERR_NONE;
}