1#ifndef URL_H
2#define URL_H 1
3
4/**
5 * Dependencies
6 */
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <stdbool.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/**
17 * url.h version
18 */
19
20#define URL_VERSION 0.2.1
21
22
23/**
24 * Max length of a url protocol scheme
25 */
26
27#define URL_PROTOCOL_MAX_LENGTH 32
28
29
30/**
31 * Max length of a url host part
32 */
33
34#define URL_HOSTNAME_MAX_LENGTH 128
35
36
37/**
38 * Max length of a url tld part
39 */
40
41#define URL_TLD_MAX_LENGTH 16
42
43
44/**
45 * Max length of a url auth part
46 */
47
48#define URL_AUTH_MAX_LENGTH 32
49
50
51/**
52 * `url_data` struct that defines parts
53 * of a parsed URL such as host and protocol
54 */
55
56typedef struct url_data {
57 char *href;
58 char *protocol;
59 char *host;
60 char *auth;
61 char *hostname;
62 char *pathname;
63 char *search;
64 char *path;
65 char *hash;
66 char *query;
67 char *port;
68} url_data_t;
69
70
71// prototype
72
73/**
74 * Parses a url into parts and returns
75 * a `url_data_t *` pointer
76 */
77
78url_data_t *
79url_parse (char* url);
80
81char *
82url_get_protocol (const char* url);
83
84char *
85url_get_auth (const char* url);
86
87char *
88url_get_hostname (const char* url);
89
90char *
91url_get_host (const char* url);
92
93char *
94url_get_pathname (const char* url);
95
96char *
97url_get_path (const char* url);
98
99char *
100url_get_search (const char* url);
101
102char *
103url_get_query (const char* url);
104
105char *
106url_get_hash (const char* url);
107
108char *
109url_get_port (const char* url);
110
111void
112url_free (url_data_t* data);
113
114bool
115url_is_protocol (const char* str);
116
117bool
118url_is_ssh (const char* str);
119
120void
121url_inspect (char* url);
122
123void
124url_data_inspect (const url_data_t* data);
125
126#ifdef __cplusplus
127}
128#endif
129
130#endif
131