xref: /qemu/include/qemu/uri.h (revision c3bef3b4)
1 /**
2  * Summary: library of generic URI related routines
3  * Description: library of generic URI related routines
4  *              Implements RFC 2396
5  *
6  * Copyright (C) 1998-2003 Daniel Veillard.  All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21  * DANIEL VEILLARD BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Except as contained in this notice, the name of Daniel Veillard shall not
26  * be used in advertising or otherwise to promote the sale, use or other
27  * dealings in this Software without prior written authorization from him.
28  *
29  * Author: Daniel Veillard
30  **
31  * Copyright (C) 2007 Red Hat, Inc.
32  *
33  * This library is free software; you can redistribute it and/or
34  * modify it under the terms of the GNU Lesser General Public
35  * License as published by the Free Software Foundation; either
36  * version 2.1 of the License, or (at your option) any later version.
37  *
38  * This library is distributed in the hope that it will be useful,
39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
41  * Lesser General Public License for more details.
42  *
43  * You should have received a copy of the GNU Lesser General Public
44  * License along with this library; if not, write to the Free Software
45  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
46  *
47  * Authors:
48  *    Richard W.M. Jones <rjones@redhat.com>
49  *
50  * Utility functions to help parse and assemble query strings.
51  */
52 
53 #ifndef QEMU_URI_H
54 #define QEMU_URI_H
55 
56 /**
57  * URI:
58  *
59  * A parsed URI reference. This is a struct containing the various fields
60  * as described in RFC 2396 but separated for further processing.
61  */
62 typedef struct URI {
63     char *scheme;	/* the URI scheme */
64     char *opaque;	/* opaque part */
65     char *authority;	/* the authority part */
66     char *server;	/* the server part */
67     char *user;		/* the user part */
68     int port;		/* the port number */
69     char *path;		/* the path string */
70     char *fragment;	/* the fragment identifier */
71     int  cleanup;	/* parsing potentially unclean URI */
72     char *query;	/* the query string (as it appears in the URI) */
73 } URI;
74 
75 URI *uri_new(void);
76 char *uri_resolve(const char *URI, const char *base);
77 char *uri_resolve_relative(const char *URI, const char *base);
78 URI *uri_parse(const char *str);
79 URI *uri_parse_raw(const char *str, int raw);
80 int uri_parse_into(URI *uri, const char *str);
81 char *uri_to_string(URI *uri);
82 char *uri_string_escape(const char *str, const char *list);
83 char *uri_string_unescape(const char *str, int len, char *target);
84 void uri_free(URI *uri);
85 
86 /* Single web service query parameter 'name=value'. */
87 typedef struct QueryParam {
88   char *name;			/* Name (unescaped). */
89   char *value;			/* Value (unescaped). */
90   int ignore;			/* Ignore this field in qparam_get_query */
91 } QueryParam;
92 
93 /* Set of parameters. */
94 typedef struct QueryParams {
95   int n;			/* number of parameters used */
96   int alloc;			/* allocated space */
97   QueryParam *p;		/* array of parameters */
98 } QueryParams;
99 
100 struct QueryParams *query_params_new (int init_alloc);
101 extern QueryParams *query_params_parse (const char *query);
102 extern void query_params_free (QueryParams *ps);
103 
104 #endif /* QEMU_URI_H */
105