chiark / gitweb /
@@@ fltfmt wip
[mLib] / codec / url.h
1 /* -*-c-*-
2  *
3  * Parsing and construction of url-encoded name/value pairs
4  *
5  * (c) 1999 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of the mLib utilities library.
11  *
12  * mLib is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Library General Public License as
14  * published by the Free Software Foundation; either version 2 of the
15  * License, or (at your option) any later version.
16  *
17  * mLib is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with mLib; if not, write to the Free
24  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  * MA 02111-1307, USA.
26  */
27
28 #ifndef MLIB_URL_H
29 #define MLIB_URL_H
30
31 #ifdef __cplusplus
32   extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #ifndef MLIB_DSTR_H
38 #  include "dstr.h"
39 #endif
40
41 /*----- Data structures ---------------------------------------------------*/
42
43 typedef struct url_ectx {
44   unsigned f;
45 } url_ectx;
46
47 typedef struct url_dctx {
48   const char *p;
49   unsigned f;
50 } url_dctx;
51
52 #define URLF_SEP 1u
53 #define URLF_STRICT 2u
54 #define URLF_LAX 4u
55 #define URLF_SEMI 8u
56
57 /*----- Functions provided ------------------------------------------------*/
58
59 /* --- @url_initenc@ --- *
60  *
61  * Arguments:   @url_ectx *ctx@ = pointer to context block
62  *
63  * Returns:     ---
64  *
65  * Use:         Initializes a URL encoding context.
66  */
67
68 extern void url_initenc(url_ectx */*ctx*/);
69
70 /* --- @url_enc@ --- *
71  *
72  * Arguments:   @url_ectx *ctx@ = pointer to encoding context
73  *              @dstr *d@ = pointer to output string
74  *              @const char *name@ = pointer to name
75  *              @const char *value@ = pointer to value
76  *
77  * Returns:     ---
78  *
79  * Use:         Writes an assignment between @name@ and @value@ to the
80  *              output string, encoding the values properly.
81  */
82
83 extern void url_enc(url_ectx */*ctx*/, dstr */*d*/,
84                     const char */*name*/, const char */*value*/);
85
86 /* --- @url_initdec@ --- *
87  *
88  * Arguments:   @url_dctx *ctx@ = pointer to context block
89  *              @const char *p@ = string to read data from
90  *
91  * Returns:     ---
92  *
93  * Use:         Initializes a URL decoding context.
94  */
95
96 extern void url_initdec(url_dctx */*ctx*/, const char */*p*/);
97
98 /* --- @url_dec@ --- *
99  *
100  * Arguments:   @url_dctx *ctx@ = pointer to decode context
101  *              @dstr *n@ = pointer to output string for name
102  *              @dstr *v@ = pointer to output string for value
103  *
104  * Returns:     Nonzero if it read something, zero if there's nothing left
105  *
106  * Use:         Decodes the next name/value pair from a urlencoded string.
107  */
108
109 extern int url_dec(url_dctx */*ctx*/, dstr */*n*/, dstr */*v*/);
110
111 /*----- That's all, folks -------------------------------------------------*/
112
113 #ifdef __cplusplus
114   }
115 #endif
116
117 #endif