2
#include "nsIURLParser.h"
4
#include "nsIServiceManager.h"
8
print_field(const char *label, char *str, PRInt32 len)
12
printf("[%s=%s]\n", label, str);
16
#define PRINT_FIELD(x) \
17
print_field(# x, x, x ## Len)
19
#define PRINT_SUBFIELD(base, x) \
22
print_field(# x, base + x ## Pos, x ## Len); \
26
parse_authority(nsIURLParser *urlParser, char *auth, PRInt32 authLen)
30
PRUint32 usernamePos, passwordPos;
31
PRInt32 usernameLen, passwordLen;
33
PRInt32 hostnameLen, port;
35
urlParser->ParseAuthority(auth, authLen,
36
&usernamePos, &usernameLen,
37
&passwordPos, &passwordLen,
38
&hostnamePos, &hostnameLen,
41
PRINT_SUBFIELD(auth, username);
42
PRINT_SUBFIELD(auth, password);
43
PRINT_SUBFIELD(auth, hostname);
45
printf("[port=%d]\n", port);
49
parse_file_path(nsIURLParser *urlParser, char *filepath, PRInt32 filepathLen)
51
PRINT_FIELD(filepath);
53
PRUint32 dirPos, basePos, extPos;
54
PRInt32 dirLen, baseLen, extLen;
56
urlParser->ParseFilePath(filepath, filepathLen,
61
PRINT_SUBFIELD(filepath, dir);
62
PRINT_SUBFIELD(filepath, base);
63
PRINT_SUBFIELD(filepath, ext);
67
parse_path(nsIURLParser *urlParser, char *path, PRInt32 pathLen)
71
PRUint32 filePos, paramPos, queryPos, refPos;
72
PRInt32 fileLen, paramLen, queryLen, refLen;
74
urlParser->ParsePath(path, pathLen,
81
parse_file_path(urlParser, path + filePos, fileLen);
82
PRINT_SUBFIELD(path, param);
83
PRINT_SUBFIELD(path, query);
84
PRINT_SUBFIELD(path, ref);
88
main(int argc, char **argv)
91
printf("usage: TestURLParser [-std|-noauth|-auth] <url>\n");
94
nsCOMPtr<nsIURLParser> urlParser;
95
if (strcmp(argv[1], "-noauth") == 0) {
96
urlParser = do_GetService(NS_NOAUTHURLPARSER_CONTRACTID);
99
else if (strcmp(argv[1], "-auth") == 0) {
100
urlParser = do_GetService(NS_AUTHURLPARSER_CONTRACTID);
104
urlParser = do_GetService(NS_STDURLPARSER_CONTRACTID);
105
if (strcmp(argv[1], "-std") == 0)
108
printf("assuming -std\n");
111
printf("have urlParser @%p\n", urlParser.get());
113
char *spec = argv[1];
114
PRUint32 schemePos, authPos, pathPos;
115
PRInt32 schemeLen, authLen, pathLen;
117
urlParser->ParseURL(spec, -1,
118
&schemePos, &schemeLen,
123
PRINT_SUBFIELD(spec, scheme);
125
parse_authority(urlParser, spec + authPos, authLen);
127
parse_path(urlParser, spec + pathPos, pathLen);
130
printf("no urlParser\n");