-
Notifications
You must be signed in to change notification settings - Fork 0
/
urltest.c
52 lines (42 loc) · 1.26 KB
/
urltest.c
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
#include "urlinfo.h"
#include <stdlib.h>
#include <stdio.h>
/*
* Program to test makeURL()
*
* The previous output of makeURL() is used as the current address
* The first call to makeURL must include a domain;
* if there is no current address, relative urls will throw errors
* Any subsequent calls may use relative urls
*/
urlinfo *current;
urlinfo *prev;
urlinfo *getparts(char *string)
{
printf("Analyzing %s\n----------------------------\n", string);
// free memory from previous urls
if (prev)
freeURL(prev);
// set prev to current, making room for the new url to be stored in current
prev = current;
// make the url (if prev != NULL, relative addresses may be passed in string
current = makeURL(string, prev);
// print selected substrings
printf("Domain: %s\n", current->host);
printf("Path: %s\n", current->path);
printf("File: %s\n\n", current->filename);
return current;
}
int main(void)
{
getparts("ican.hascheez.com/tags/dogs");
getparts("yep.net/path/path2/test.html");
getparts("google.com/index.html");
getparts("test.php");
getparts("folder/folded.html");
getparts("test.com/folder");
getparts("folder2/newfile.txt");
getparts("/folder3/newerfile.txt");
getparts("../newfolder/horiz.php");
getparts("/../../upone.php");
}