Welcome to mirror list, hosted at ThFree Co, Russian Federation.

url_parse.c « myurl « examples - github.com/lexborisov/Modest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b59df93539e4fb0a133eb2f63d11c2bfcc4f0ee7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 Copyright (C) 2017 Alexander Borisov
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 Author: lex.borisov@gmail.com (Alexander Borisov)
*/

#include <string.h>
#include <myurl/url.h>

int main(int argc, const char * argv[])
{
    const char* data_base = "https://lastmac:12345@www.emaple.com:4433/programming/?id=777888999#somehash";
    
    myurl_t *url = myurl_create();
    if(url == NULL) {
        printf("Can't create URL object\n");
        return EXIT_FAILURE;
    }
    
    if(myurl_init(url)) {
        printf("Can't init URL object\n");
        return EXIT_FAILURE;
    }
    
    printf("Parse url \"%s\":\n", data_base);
    
    myurl_entry_t *url_base = myurl_parse(url, data_base, strlen(data_base), NULL, NULL);
    
    const char *scheme   = myurl_entry_scheme_name(url_base, NULL);
    char *authority      = myurl_entry_authority_as_string(url_base, NULL);
    const char *username = myurl_entry_username(url_base, NULL);
    const char *password = myurl_entry_password(url_base, NULL);
    char *host           = myurl_entry_host_as_string(url_base, NULL);
    char *path           = myurl_entry_path_as_string(url_base, NULL);
    const char *query    = myurl_entry_query(url_base, NULL);
    const char *fragment = myurl_entry_fragment(url_base, NULL);
    
    printf("\tScheme: %s\n"         , (scheme ? scheme : ""));
    printf("\tScheme port: %u\n"    , myurl_entry_scheme_port(url_base));
    printf("\tAuthority (%s):\n"    , authority);
    printf("\t\tUsername: %s\n"     , username);
    printf("\t\tPassword: %s\n"     , password);
    printf("\tHost: %s\n"           , host);
    printf("\tPort is defined: %s\n", (myurl_entry_port_is_defined(url_base) ? "true" : "false"));
    printf("\tPort: %u\n"           , myurl_entry_port(url_base));
    printf("\tPath: %s\n"           , path);
    printf("\tQuery: %s\n"          , (query ? query : ""));
    printf("\tFragment: %s\n"       , (fragment ? fragment : ""));
    
    myurl_entry_free_string(url_base, authority);
    myurl_entry_free_string(url_base, host);
    myurl_entry_free_string(url_base, path);
    
    myurl_entry_destroy(url_base, true);
    myurl_destroy(url, true);
    
    return 0;
}