Truxton url get format

From truxwiki.com
Revision as of 07:11, 6 February 2021 by Sam (talk | contribs) (→‎Sample)
Jump to navigation Jump to search

This retrieves the format of URL.

Syntax

uint64_t truxton_url_get_format( uint64_t url_handle );

Parameters

url_handle

This handle comes from calling truxton_url_create(), or truxton_file_create_url().

Return value

The way the URL was stored in the parent file. It should be URL_FORMAT_ASCII or URL_FORMAT_UNICODE.

Sample

 1 void dump_url(uint64_t url_handle)
 2 {
 3    uint64_t integer_value = 0;
 4 
 5    char temp_string[ 1024 ];
 6 
 7    truxton_url_get_id( url_handle, temp_string, sizeof(temp_string) );
 8    printf( "URL ID is %s\n", temp_string );
 9 
10    truxton_url_get_media_id( url_handle, temp_string, sizeof(temp_string) );
11    printf( "Media ID is %s\n", temp_string );
12 
13    truxton_url_get_file_id( url_handle, temp_string, sizeof(temp_string) );
14    printf( "File ID is %s\n", temp_string );
15 
16    truxton_url_get_account( url_handle, temp_string, sizeof(temp_string) );
17    printf( "Account is \"%s\"\n", temp_string );
18 
19    integer_value = truxton_url_get_account_offset( url_handle );
20 
21    if ( integer_value == 0xFFFFFFFFFFFFFFFF )
22    {
23       printf( "Account offset is not known\n" );
24    }
25    else
26    {
27       printf( "Account offset is %" PRIu64 "\n", integer_value );
28    }
29 
30    integer_value = truxton_url_get_url_offset( url_handle );
31 
32    if ( integer_value == 0xFFFFFFFFFFFFFFFF )
33    {
34       printf( "URL offset is not known, probably came from a SQLite database\n" );
35    }
36    else
37    {
38       printf( "URL offset is %" PRIu64 "\n", integer_value );
39    }
40 
41    integer_value = truxton_url_get_format( url_handle );
42    printf( "Format is %" PRIu64 "\n", integer_value );
43 
44    integer_value = truxton_url_get_method( url_handle );
45    printf( "Method is %" PRIu64 "\n", integer_value );
46 
47    integer_value = truxton_url_get_type( url_handle );
48    printf( "Type is %" PRIu64 "\n", integer_value );
49 
50    integer_value = truxton_url_get_when( url_handle );
51    printf( "When is %" PRIu64 "\n", integer_value );
52 }

The PRIu64 in the sample code above is a standard way of formatting a 64-bit unsigned integer in C. Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.