Ejemplo n.º 1
0
VMBOOL read_conf_string(VMSTR variable_name, VMSTR output_buffer, VMUINT output_buffer_size) {
	VMINT res;
	VMUINT conf_size;
	VMUINT bytes_read;
	VMSTR conf_data;
	VMSTR key;
	VMSTR value;
	VMBOOL result_string_valid = FALSE;

	if (conf_handle_valid)
	{
		res = vm_fs_get_size(conf_handle, &conf_size);
		if (VM_IS_SUCCEEDED(res))
		{
			conf_data = vm_calloc(conf_size + strlen(conf_defaults) + 1);
			if (conf_data != NULL)
			{
				vm_fs_seek(conf_handle, 0, VM_FS_BASE_BEGINNING);
				res = vm_fs_read(conf_handle, conf_data, conf_size, &bytes_read);
				if (VM_IS_SUCCEEDED(res))
				{
					strcat(conf_data, conf_defaults);
					key = strtok(conf_data, "=");
					while (key != NULL) 
					{
						value = strtok(NULL, "\n");
						if (value != NULL && strcmp(variable_name, key) == 0 && strlen(value) < output_buffer_size)
						{
							strcpy(output_buffer, value);
							result_string_valid = TRUE;
							break;
						}
						key = strtok(NULL, "=");
					} 
				}
				vm_free(conf_data);
			}
		}
	}
	return result_string_valid;
}
Ejemplo n.º 2
0
void open_conf(VMCWSTR conf_file_name)
{
	VMINT res;
	if (conf_handle_valid)
	{
		close_conf();
	}
	res = vm_fs_open(conf_file_name, VM_FS_MODE_READ, VM_FALSE);
	if (VM_IS_SUCCEEDED(res))
	{
		conf_handle = res;
		conf_handle_valid = TRUE;
	}
}
Ejemplo n.º 3
0
/* Set font and draw hello world text */
static void draw_hello(void) {
	VMWSTR string;
	vm_graphic_color_argb_t color;
	vm_graphic_frame_t frame;
	vm_graphic_frame_t* frame_group[1];
	VMWCHAR font_path[FONT_PATH_MAX_LENGTH + 1];
	VMWSTR font_paths_group[1];
	VM_RESULT result;
	VMUINT32 pool_size;
	VMUINT32 size;

	vm_graphic_point_t positions[1] = { 0, 0 };

	frame.buffer_length = SCREEN_WIDTH * SCREEN_HEIGHT * 2;
	frame.buffer = vm_malloc_dma(frame.buffer_length);
	if (frame.buffer == NULL) {
		return;
	}

	frame.color_format = VM_GRAPHIC_COLOR_FORMAT_16_BIT;
	frame.height = SCREEN_HEIGHT;
	frame.width = SCREEN_WIDTH;
	frame_group[0] = &frame;

	string = vm_res_get_string(STR_ID_HELLO, &size);
	color.a = 255;
	color.r = 243;
	color.g = 154;
	color.b = 30;
	vm_graphic_set_color(color);
	vm_graphic_draw_solid_rectangle(&frame, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

	result = vm_graphic_get_font_pool_size(EXTERNAL_FONT_SIZE, 1,
	FONT_CACHE_SIZE, &pool_size);
	if (VM_IS_SUCCEEDED(result)) {
		font_pool = vm_malloc(pool_size);
		if (NULL != font_pool) {
			result = vm_graphic_init_font_pool(font_pool, pool_size);
		} else {
			vm_log_info("allocate font pool memory failed");
			return;
		}
	}
	if (!(VM_IS_SUCCEEDED(result))) {
		vm_log_info("init font pool failed");
		return;
	}
	vm_chset_ascii_to_ucs2(font_path, (FONT_PATH_MAX_LENGTH + 1) * 2,
	EXTERNAL_FONT_PATH);
	font_paths_group[0] = font_path;
	vm_graphic_reset_font();
	result = vm_graphic_set_font(font_paths_group, 1);
	if (!(VM_IS_SUCCEEDED(result))) {
		vm_log_info("set font failed");
	}

	color.r = 255;
	color.g = 255;
	color.b = 255;
	vm_graphic_set_color(color);
	vm_graphic_set_font_size(VM_GRAPHIC_LARGE_FONT);
	vm_log_info("String: %d, %d, %d, %d, %d, %d", string[0], string[1],
			string[2], string[3], string[4], string[5]);
	vm_graphic_draw_text(&frame, 1, 1, string);
#if defined(__HDK_LINKIT_ASSIST_2502__)
	vm_graphic_blt_frame(frame_group, positions, 1);
#endif
	vm_free(frame.buffer);
	vm_free(font_pool);
	font_pool = NULL;
}
Ejemplo n.º 4
0
/*
 * Load all data from a file into a given buffer.
 *
 * The file is expected to contain either PEM or DER encoded data.
 * A terminating null byte is always appended. It is included in the announced
 * length only if the data looks like it is PEM encoded.
 */
int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n )
{
    
    int ret = 0;
    long size;

    VM_FS_HANDLE file_handle;
    VMWCHAR file_name[100 + 1];
    VMSTR cert_paths[2];
    
    VMUINT8* cert_buffer;
    VMUINT read_size;
    VMINT drv;
    VMWCHAR wpath[FILE_PATH_SIZE] = {0};
    VMCHAR path_cert[FILE_PATH_SIZE] = {0};

    cert_paths[0] = (VMSTR)path;

    memset(file_name, 0, sizeof(file_name));

    vm_ascii_to_ucs2(file_name, SSL_CERT_PATH_MAX_LENGTH, cert_paths[0]);

    file_handle = vm_file_open(file_name, MODE_READ, VM_TRUE);

    if(!(VM_IS_SUCCEEDED(file_handle)))
    {
        return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
    }

    ret = vm_file_seek(file_handle, 0, BASE_END);
    if (ret < 0){
        return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
    }
    size = vm_file_tell(file_handle);
    if (size < 0){
        return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
    }
    ret = vm_file_seek(file_handle, 0, BASE_BEGIN);
    if (ret < 0){
        return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
    }

    *n = (size_t) size;
    
    if( *n + 1 == 0 ||
        ( *buf = mbedtls_calloc( *n + 1 ) ) == NULL )
    {
        vm_file_close( file_handle );
        return( MBEDTLS_ERR_PK_ALLOC_FAILED );
    }

    vm_file_read(file_handle, *buf, *n, &read_size);
    if(read_size != *n)
    {
        vm_file_close( file_handle );
        vm_free( *buf );
        return( MBEDTLS_ERR_X509_FILE_IO_ERROR ); 
    }

    vm_file_close( file_handle );

    (*buf)[*n] = '\0';

    if( strstr( (const char *) *buf, "-----BEGIN " ) != NULL )
        ++*n;

    return( 0 );

    // FILE *f;
    // long size;

    // if( ( f = fopen( path, "rb" ) ) == NULL )
    //     return( MBEDTLS_ERR_PK_FILE_IO_ERROR );

    // fseek( f, 0, SEEK_END );
    // if( ( size = ftell( f ) ) == -1 )
    // {
    //     fclose( f );
    //     return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
    // }
    // fseek( f, 0, SEEK_SET );

    // *n = (size_t) size;

    // if( *n + 1 == 0 ||
    //     ( *buf = mbedtls_calloc( 1, *n + 1 ) ) == NULL )
    // {
    //     fclose( f );
    //     return( MBEDTLS_ERR_PK_ALLOC_FAILED );
    // }

    // if( fread( *buf, 1, *n, f ) != *n )
    // {
    //     fclose( f );
    //     mbedtls_free( *buf );
    //     return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
    // }

    // fclose( f );

    // (*buf)[*n] = '\0';

    // if( strstr( (const char *) *buf, "-----BEGIN " ) != NULL )
    //     ++*n;

    // return( 0 );
}