summary refs log tree commit diff stats
path: root/test.c
blob: ff6b1375148ec7118f8e10abe4ba56ecdf7283e4 (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
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.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;
	char *p;

	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);
	p = uri_encode(u);
	if (p == NULL)
		return 1;
	printf("%s\n", p);
	free(p);
	uri_free(u);
	return 0;
}