forked from nevali/liburi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uri_create_str.3.xml
179 lines (155 loc) · 5.59 KB
/
uri_create_str.3.xml
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?xml version="1.0" encoding="UTF-8"?>
<refentry version="5.0" xml:id="uri_create_str-3" xmlns="http://docbook.org/ns" xml:lang="en">
<info>
<title>URI Functions</title>
<productname>System Programmer's Manual</productname>
<authorgroup>
<author>
<personname>
<firstname>Mo</firstname>
<surname>McRoberts</surname>
</personname>
</author>
</authorgroup>
<copyright>
<year>2012</year>
<holder>Mo McRoberts</holder>
</copyright>
</info>
<refmeta>
<refentrytitle>uri_create_str</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname>uri_create_str</refname>
<refpurpose>parse a URI or IRI</refpurpose>
</refnamediv>
<refsect1>
<title>Library</title>
<para>URI parsing library (liburi, -luri)</para>
</refsect1>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include <liburi.h></funcsynopsisinfo>
<funcprototype>
<funcdef>URI *<function>uri_create_str</function></funcdef>
<paramdef>const char *restrict <parameter>uristr</parameter></paramdef>
<paramdef>const URI *restrict <parameter>base</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
The <function>uri_create_str</function> function parses a string in order
to produce a <type>URI</type> instance. If the URI to be parsed in
<parameter>uristr</parameter> is not absolute, and an absolute base URI
is supplied as <parameter>base</parameter>, 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
<parameter>uristr</parameter>.
</para>
<para>
The resulting instance must be freed later using <citerefentry><refentrytitle><ulink url="uri_destroy.3.html">uri_destroy</ulink></refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
<para>
URIs are normalised as they are parsed. Normalisation is performed
according to <ulink url="http://tools.ietf.org/html/rfc3986#section-6.2.2">section 6.2.2 of RFC3986</ulink>, 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 <literal>/a/b/c/../d/../../e</literal> will be normalised to
<literal>/a/e</literal>).
</para>
<para>
Once parsed, a URI can be resolved against a base URI if it is relative
using <citerefentry><refentrytitle><ulink url="uri_create_uri.3.html">uri_create_uri</ulink></refentrytitle><manvolnum>3</manvolnum></citerefentry>,
and can be recomposed into a string representation using <citerefentry><refentrytitle><ulink url="uri_str.3.html">uri_str</ulink></refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><parameter>uristr</parameter></term>
<listitem>
<para>
A string to parse as a URI or IRI.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>base</parameter></term>
<listitem>
<para>
An optional absolute base URI. If <parameter>base</parameter> is supplied but is not an absolute URI, the results are undefined.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Return value</title>
<para>
If the URI was parsed successfully, <function>uri_create_str</function>
will return a new <type>URI</type> instance. If the URI could not be
parsed, or some other error occurs, <constant>NULL</constant> will
be returned and <varname>errno</varname> set accordingly.
</para>
</refsect1>
<refsect1>
<title>Diagnostics</title>
<para>
In the event of an error ocurring, <varname>errno</varname> may be
set to one of the following values:
</para>
<variablelist>
<varlistentry>
<term><constant>EINVAL</constant></term>
<listitem>
<para>
The URI was not well-formed and could not be parsed.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>ENOMEM</constant></term>
<listitem>
<para>
A memory allocation operation failed.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Examples</title>
<para>Parsing an absolute URI:</para>
<programlisting language="c">
URI *uri;
uri = uri_create_str("http://example.com/sample", NULL);
</programlisting>
<para>
Parsing a relative URI, and resolving it against an absolute
base URI:
</para>
<programlisting language="c">
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);
</programlisting>
</refsect1>
<refsect1>
<title>See also</title>
<para>
<citerefentry><refentrytitle><ulink url="liburi.3.html">liburi</ulink></refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle><ulink url="uri_create_uri.3.html">uri_create_uri</ulink></refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle><ulink url="uri_destroy.3.html">uri_destroy</ulink></refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle><ulink url="uri_absolute.3.html">uri_absolute</ulink></refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle><ulink url="uri_str.3.html">uri_str</ulink></refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
</refsect1>
</refentry>