Esempio n. 1
0
void config_write( stream_t* stream, hash_t filter_section )
{
	config_section_t* csection;
	config_key_t* bucket;
	int key, ib, bsize;

	stream_set_binary( stream, false );

	//TODO: If random access stream, update section if available, else append at end of stream
	//if( stream_is_sequential( stream ) )
	{
		stream_write_format( stream, "[%s]", hash_to_string( filter_section ) );
		stream_write_endl( stream );

		csection = config_section( filter_section, false );
		if( csection ) for( key = 0; key < CONFIG_KEY_BUCKETS; ++key )
		{
			bucket = csection->key[ key ];
			if( bucket ) for( ib = 0, bsize = array_size( bucket ); ib < bsize; ++ib )
			{
				stream_write_format( stream, "\t%s\t\t\t\t= ", hash_to_string( bucket[ib].name ) );
				switch( bucket[ib].type )
				{
					case CONFIGVALUE_BOOL:
						stream_write_bool( stream, bucket[ib].bval );
						break;

					case CONFIGVALUE_INT:
						stream_write_int64( stream, bucket[ib].ival );
						break;

					case CONFIGVALUE_REAL:
#if FOUNDATION_PLATFORM_REALSIZE == 64
						stream_write_float64( stream, bucket[ib].rval );
#else
						stream_write_float32( stream, bucket[ib].rval );
#endif
						break;

					case CONFIGVALUE_STRING:
					case CONFIGVALUE_STRING_CONST:
					case CONFIGVALUE_STRING_VAR:
					case CONFIGVALUE_STRING_CONST_VAR:
						stream_write_string( stream, bucket[ib].sval );
						break;

					default:
						break;
				}
				stream_write_endl( stream );
			}
		}
	}
}
Esempio n. 2
0
static char*dataset_filename(uint8_t*hash)
{
    char*basename = hash_to_string(hash);
    char*path = concat_paths(config_dataset_cache_directory, basename);
    free(basename);
    return path;
}
Esempio n. 3
0
//preorder tree traversal and printing
static void print_hash_tree(hash_tree_node * root, int n){
    if(root == NULL){
        return;
    }
    
    char * hash = hash_to_string(root->hash);
    printf("hash %s, height %d\n", hash, n);
    free(hash);

    print_hash_tree(root->left, n+1);
    print_hash_tree(root->right, n+1);
     
}
Esempio n. 4
0
/**
 * Gets all data from a list of hash obtained from X-Get-Hash-Array HTTP
 * header.
 * @param server_struct is the main structure for the server.
 * @param connection is the connection in MHD
 * @returns a newlly allocated gchar * string that contains the anwser to be
 *          sent back to the client (hopefully a json string containing
 *          a hash (that is a fake one here), data and size of the data.
 */
static gchar *get_data_from_a_list_of_hashs(server_struct_t *server_struct, struct MHD_Connection *connection)
{
    const char *header = NULL;
    gchar *answer = NULL;
    gchar *hash = NULL;
    GList *head = NULL;
    GList *header_hdl = NULL;
    GList *hash_data_list = NULL;
    hash_data_t *header_hd = NULL;
    hash_data_t *hash_data = NULL;
    backend_t *backend = server_struct->backend;
    guint size = 0;


    header = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "X-Get-Hash-Array");
    header_hdl = make_hash_data_list_from_string((gchar *)header);

    head = header_hdl;
    while (header_hdl != NULL)
        {
            header_hd = header_hdl->data;
            hash = hash_to_string(header_hd->hash);
            hash_data = backend->retrieve_data(server_struct, hash);
            free_variable(hash);
            size = size + hash_data->read;
            hash_data_list = g_list_prepend(hash_data_list, hash_data);
            header_hdl = g_list_next(header_hdl);
        }

    g_list_free_full(head, free_hdt_struct);
    hash_data_list = g_list_reverse(hash_data_list);

    head = hash_data_list;

    hash_data = create_one_hash_data_t_from_hash_data_list(hash_data_list, size);

    g_list_free_full(head, free_hdt_struct);

    answer = convert_hash_data_t_to_string(hash_data);

    free_hash_data_t(hash_data);

    return answer;
}