summary refs log tree commit diff stats
path: root/test.c
blob: c1cdd72580e0a335ee6413c7f2bc7f6d969cec45 (plain) (blame)
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
#include <stdio.h>

#include "yuri.h"

static void
_print_uri(struct uri *u)
{
	int i;

	printf("Scheme: \"%s\"\n", u->scheme);
	printf("Authority type: %d\n", u->authority.type);
	printf("Authority user: \"%s\"\n", u->authority.user);
	printf("Authority host: \"%s\"\n", u->authority.host);
	printf("Authority port: %d\n", u->authority.port);
	for (i = 0; i < u->npath; i++)
		printf("Path: %d: \"%s\"\n", i+1, u->path[i]);
	printf("Query: \"%s\"\n", u->query);
	printf("Fragment: \"%s\"\n", u->fragment);
}

int
main(int argc, char *argv[])
{
	struct uri *u;

	if (argc < 2) {
		fprintf(stderr, "Usage %s url\n", argv[0]);
		return 1;
	}
	u = uri_decode(argv[1]);
	if (u == NULL)
		return 1;
	if (uri_normalize(u) == -1)
		return 1;
	_print_uri(u);
	uri_free(u);
	return 0;
}