forked from nevali/liburi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uri_create_str.3
150 lines (144 loc) · 3.93 KB
/
uri_create_str.3
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'\" t
.\" Title: uri_create_str
.\" Author: Mo McRoberts
.\" Generator: DocBook XSL Stylesheets v1.77.1 <http://docbook.sf.net/>
.\" Date: 12/05/2012
.\" Manual: URI Functions
.\" Source: System Programmer's Manual
.\" Language: English
.\"
.TH "URI_CREATE_STR" "3" "12/05/2012" "System Programmer's Manual" "URI Functions"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
uri_create_str \- parse a URI or IRI
.SH "LIBRARY"
.PP
URI parsing library (liburi, \-luri)
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <liburi\&.h>
.fi
.ft
.HP \w'URI\ *uri_create_str('u
.BI "URI *uri_create_str(const\ char\ *restrict\ " "uristr" ", const\ URI\ *restrict\ " "base" ");"
.SH "DESCRIPTION"
.PP
The
\fBuri_create_str\fR
function parses a string in order to produce a
\fBURI\fR
instance\&. If the URI to be parsed in
\fIuristr\fR
is not absolute, and an absolute base URI is supplied as
\fIbase\fR, the parsed URI will be resolved relative to the base URI and the result will be an absolute URI\&. If no base URI is supplied, the resulting URI instance may be either absolute or relative, depending upon the contents of
\fIuristr\fR\&.
.PP
The resulting instance must be freed later using
\fBuri_destroy\fR(3)\&.
.PP
URIs are normalised as they are parsed\&. Normalisation is performed according to
\m[blue]\fBsection 6\&.2\&.2 of RFC3986\fR\m[], and includes adjusting the case of any scheme, hostname and percent\-encoded characters so as to be consistent, as well as removing redundant components from the path (for example, a path of
/a/b/c/\&.\&./d/\&.\&./\&.\&./e
will be normalised to
/a/e)\&.
.PP
Once parsed, a URI can be resolved against a base URI if it is relative using
\fBuri_create_uri\fR(3), and can be recomposed into a string representation using
\fBuri_str\fR(3)\&.
.SH "PARAMETERS"
.PP
\fIuristr\fR
.RS 4
A string to parse as a URI or IRI\&.
.RE
.PP
\fIbase\fR
.RS 4
An optional absolute base URI\&. If
\fIbase\fR
is supplied but is not an absolute URI, the results are undefined\&.
.RE
.SH "RETURN VALUE"
.PP
If the URI was parsed successfully,
\fBuri_create_str\fR
will return a new
\fBURI\fR
instance\&. If the URI could not be parsed, or some other error occurs,
\fBNULL\fR
will be returned and
\fIerrno\fR
set accordingly\&.
.SH "DIAGNOSTICS"
.PP
In the event of an error ocurring,
\fIerrno\fR
may be set to one of the following values:
.PP
\fBEINVAL\fR
.RS 4
The URI was not well\-formed and could not be parsed\&.
.RE
.PP
\fBENOMEM\fR
.RS 4
A memory allocation operation failed\&.
.RE
.SH "EXAMPLES"
.PP
Parsing an absolute URI:
.sp
.if n \{\
.RS 4
.\}
.nf
URI *uri;
uri = uri_create_str("http://example\&.com/sample", NULL);
.fi
.if n \{\
.RE
.\}
.PP
Parsing a relative URI, and resolving it against an absolute base URI:
.sp
.if n \{\
.RS 4
.\}
.nf
URI *base, *uri;
base = uri_create_str("http://example\&.com/sample", NULL);
/* The result would be as though the string being parsed had been:
* http://example\&.com/switch?toggle=1
*/
uri = uri_create_str("switch?toggle=1", base);
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.PP
\fBliburi\fR(3),
\fBuri_create_uri\fR(3),
\fBuri_destroy\fR(3),
\fBuri_absolute\fR(3),
\fBuri_str\fR(3)\&.