1688eab9540a5f1331bbed76c47cdbab554b11bb
[petitboot] / test / urls / parse-url.c
1
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include <url/url.h>
6 #include <log/log.h>
7
8 int main(int argc, char **argv)
9 {
10         struct pb_url *url;
11
12         if (argc != 2 && argc != 3) {
13                 fprintf(stderr, "Usage: %s <URL> [update]\n", argv[0]);
14                 return EXIT_FAILURE;
15         }
16
17         url = pb_url_parse(NULL, argv[1]);
18         if (!url)
19                 return EXIT_FAILURE;
20
21         if (argc == 2) {
22                 printf("%s\n", argv[1]);
23
24         } else {
25                 printf("%s %s\n", argv[1], argv[2]);
26                 url = pb_url_join(NULL, url, argv[2]);
27         }
28
29         printf("scheme\t%s\n", pb_url_scheme_name(url->scheme));
30         printf("host\t%s\n", url->host);
31         printf("port\t%s\n", url->port);
32         printf("path\t%s\n", url->path);
33         printf("dir\t%s\n", url->dir);
34         printf("file\t%s\n", url->file);
35
36         return EXIT_SUCCESS;
37 }