]> git.ozlabs.org Git - petitboot/blob - test/urls/parse-url.c
test/lib: Implement process_init change in testcases
[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         FILE *null;
12
13         if (argc != 2 && argc != 3) {
14                 fprintf(stderr, "Usage: %s <URL> [update]\n", argv[0]);
15                 return EXIT_FAILURE;
16         }
17
18         /* discard log output */
19         null = fopen("/dev/null", "w");
20         pb_log_set_stream(null);
21
22         url = pb_url_parse(NULL, argv[1]);
23         if (!url)
24                 return EXIT_FAILURE;
25
26         if (argc == 2) {
27                 printf("%s\n", argv[1]);
28
29         } else {
30                 printf("%s %s\n", argv[1], argv[2]);
31                 url = pb_url_join(NULL, url, argv[2]);
32         }
33
34         printf("scheme\t%s\n", pb_url_scheme_name(url->scheme));
35         printf("host\t%s\n", url->host);
36         printf("port\t%s\n", url->port);
37         printf("path\t%s\n", url->path);
38         printf("dir\t%s\n", url->dir);
39         printf("file\t%s\n", url->file);
40
41         return EXIT_SUCCESS;
42 }