Пример #1
0
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
static kaa_error_t kaa_context_create(kaa_context_t **context_p, kaa_logger_t *logger)
{
    KAA_RETURN_IF_NIL2(context_p, logger, KAA_ERR_BADPARAM);

    *context_p = (kaa_context_t *) KAA_MALLOC(sizeof(kaa_context_t));
    KAA_RETURN_IF_NIL(*context_p, KAA_ERR_NOMEM);

    (*context_p)->logger = logger;

    kaa_error_t error = KAA_ERR_NONE;
    (*context_p)->status = (kaa_status_holder_t *) KAA_MALLOC(sizeof(kaa_status_holder_t));
    if (!(*context_p)->status)
        error = KAA_ERR_NOMEM;

    if (!error)
        error = kaa_status_create(&((*context_p)->status->status_instance));

    if (!error)
        error = kaa_platform_protocol_create(&((*context_p)->platfrom_protocol), *context_p,
                                             (*context_p)->status->status_instance);

    if (!error)
        error = kaa_channel_manager_create(&((*context_p)->channel_manager), (*context_p));

    if (!error)
        error = kaa_bootstrap_manager_create(&((*context_p)->bootstrap_manager), (*context_p)->channel_manager,
                                             (*context_p)->logger);

    if (!error)
        error = kaa_profile_manager_create(&((*context_p)->profile_manager), (*context_p)->status->status_instance,
                                           (*context_p)->channel_manager, (*context_p)->logger);

#ifndef KAA_DISABLE_FEATURE_EVENTS
    if (!error)
        error = kaa_event_manager_create(&((*context_p)->event_manager), (*context_p)->status->status_instance,
                                         (*context_p)->channel_manager, (*context_p)->logger);
#else
    (*context_p)->event_manager = NULL;
#endif

#ifndef KAA_DISABLE_FEATURE_LOGGING
    if (!error)
        error = kaa_log_collector_create(&((*context_p)->log_collector), (*context_p)->status->status_instance,
                                         (*context_p)->channel_manager, (*context_p)->logger);
#else
    (*context_p)->log_collector = NULL;
#endif

#ifndef KAA_DISABLE_FEATURE_CONFIGURATION
    if (!error)
        error = kaa_configuration_manager_create(&((*context_p)->configuration_manager), (*context_p)->channel_manager,
                                                 (*context_p)->status->status_instance, (*context_p)->logger);
#else
    (*context_p)->configuration_manager = NULL;
#endif

    if (!error)
        error = kaa_user_manager_create(&((*context_p)->user_manager), (*context_p)->status->status_instance,
                                        (*context_p)->channel_manager, (*context_p)->logger);

    if (error) {
        kaa_context_destroy(*context_p);
        *context_p = NULL;
    }

    return error;
}
Пример #3
0
void test_meta_extension_serialize(void)
{
    KAA_TRACE_IN(logger);

    size_t meta_extension_size;
    kaa_error_t error_code = kaa_meta_data_request_get_size(&meta_extension_size);
    char buffer[meta_extension_size];

    kaa_platform_message_writer_t *writer;
    error_code = kaa_platform_message_writer_create(&writer, buffer, meta_extension_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    uint32_t expected_timeout = KAA_SYNC_TIMEOUT;
    kaa_digest expected_public_key_hash = {0x74, 0xc7, 0x51, 0x43, 0x00, 0xf7, 0xb8, 0x21, 0x2c, 0xc3, 0x6b, 0xa5, 0x9c, 0xb4, 0x03, 0xef, 0xc2, 0x5c, 0x65, 0x6c};
    kaa_digest expected_profile_hash = {0xfa, 0x71, 0xb5, 0x02, 0xe7, 0xdf, 0x96, 0x86, 0x6c, 0xdc, 0xe1, 0x4a, 0x17, 0x35, 0x7f, 0xd9, 0xa8, 0xfb, 0x71, 0x09};

    error_code = ext_copy_sha_hash(status->endpoint_public_key_hash, expected_public_key_hash);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_copy_sha_hash(status->profile_hash, expected_profile_hash);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    kaa_context_t *context = NULL;
    kaa_init(&context);
    kaa_platform_protocol_t *protocol = NULL;
    kaa_platform_protocol_create(&protocol, context, status);

    error_code = kaa_meta_data_request_serialize(protocol, writer, 1);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    kaa_deinit(context);

    kaa_platform_message_reader_t *reader;
    error_code = kaa_platform_message_reader_create(&reader, buffer, meta_extension_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    uint8_t extension_type;
    uint32_t extension_options;
    uint32_t extension_payload;

    error_code = kaa_platform_message_read_extension_header(
                    reader, &extension_type, &extension_options, &extension_payload);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(extension_type, KAA_META_DATA_EXTENSION_TYPE);
    ASSERT_EQUAL(extension_options, (TIMEOUT_VALUE | PUBLIC_KEY_HASH_VALUE | PROFILE_HASH_VALUE | APP_TOKEN_VALUE));
    ASSERT_EQUAL(extension_payload, meta_extension_size - KAA_EXTENSION_HEADER_SIZE);

    uint32_t request_id;
    uint32_t timeout;
    kaa_digest public_key_hash;
    kaa_digest profile_hash;
    char sdk_token[KAA_SDK_TOKEN_LENGTH];

    error_code = kaa_platform_message_read(reader, &request_id, sizeof(uint32_t));
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(KAA_NTOHL(request_id), 1);
    error_code = kaa_platform_message_read(reader, &timeout, sizeof(uint32_t));
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    timeout = KAA_NTOHL(timeout);
    ASSERT_EQUAL(expected_timeout, timeout);

    error_code = kaa_platform_message_read_aligned(reader, public_key_hash, SHA_1_DIGEST_LENGTH);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    error_code = (memcmp(public_key_hash, expected_public_key_hash, SHA_1_DIGEST_LENGTH) == 0 ? KAA_ERR_NONE : KAA_ERR_READ_FAILED);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_platform_message_read_aligned(reader, profile_hash, SHA_1_DIGEST_LENGTH);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    error_code = (memcmp(profile_hash, expected_profile_hash, SHA_1_DIGEST_LENGTH) == 0 ? KAA_ERR_NONE : KAA_ERR_READ_FAILED);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_platform_message_read_aligned(reader, sdk_token, KAA_SDK_TOKEN_LENGTH);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    error_code = (memcmp(sdk_token, KAA_SDK_TOKEN, KAA_SDK_TOKEN_LENGTH) == 0 ? KAA_ERR_NONE : KAA_ERR_READ_FAILED);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    kaa_platform_message_reader_destroy(reader);
    kaa_platform_message_writer_destroy(writer);
}
Пример #4
0
static kaa_error_t kaa_context_create(kaa_context_t **context_p, kaa_logger_t *logger)
{
    KAA_RETURN_IF_NIL2(context_p, logger, KAA_ERR_BADPARAM);

    kaa_context_t *context = KAA_MALLOC(sizeof(*context));
    KAA_RETURN_IF_NIL(context, KAA_ERR_NOMEM);

    context->logger = logger;

    kaa_error_t error = KAA_ERR_NONE;
    context->status = KAA_MALLOC(sizeof(*context->status));
    if (!context->status)
        error = KAA_ERR_NOMEM;

    if (!error)
        error = kaa_status_create(&context->status->status_instance);

    if (!error)
        error = kaa_platform_protocol_create(&context->platform_protocol, context,
                                             context->status->status_instance);

    if (!error)
        error = kaa_channel_manager_create(&context->channel_manager, context);

    if (!error)
        error = kaa_bootstrap_manager_create(&context->bootstrap_manager, context);

    if (!error)
        error = kaa_profile_manager_create(&context->profile_manager, context->status->status_instance,
                                           context->channel_manager, context->logger);

    if (!error)
        error = kaa_failover_strategy_create(&context->failover_strategy, logger);

#ifndef KAA_DISABLE_FEATURE_EVENTS
    if (!error)
        error = kaa_event_manager_create(&context->event_manager, context->status->status_instance,
                                         context->channel_manager, context->logger);
#else
    context->event_manager = NULL;
#endif

#ifndef KAA_DISABLE_FEATURE_LOGGING
    if (!error)
        error = kaa_log_collector_create(&context->log_collector, context->status->status_instance,
                                         context->channel_manager, context->logger);
#else
    context->log_collector = NULL;
#endif

#ifndef KAA_DISABLE_FEATURE_CONFIGURATION
    if (!error)
        error = kaa_configuration_manager_create(&context->configuration_manager, context->channel_manager,
                                                 context->status->status_instance, context->logger);
#else
    context->configuration_manager = NULL;
#endif

#ifndef KAA_DISABLE_FEATURE_NOTIFICATION
    if (!error)
        error = kaa_notification_manager_create(&context->notification_manager, context->status->status_instance,
                                                context->channel_manager, context->logger);
#else
    context->notification_manager = NULL;
#endif

    if (!error)
        error = kaa_user_manager_create(&context->user_manager, context->status->status_instance,
                                        context->channel_manager, context->logger);


    if (error) {
        kaa_context_destroy(context);
        *context_p = NULL;
    } else {
        *context_p = context;
    }

    return error;
}