OSDN Git Service

implement x-www-form-urlencoded encoder.
[bbk/bchanf.git] / src / coding / htmlform_urlencoder.h
1 /*
2  * htmlform_urlencoder.h
3  *
4  * Copyright (c) 2015 project bchan
5  *
6  * This software is provided 'as-is', without any express or implied
7  * warranty. In no event will the authors be held liable for any damages
8  * arising from the use of this software.
9  *
10  * Permission is granted to anyone to use this software for any purpose,
11  * including commercial applications, and to alter it and redistribute it
12  * freely, subject to the following restrictions:
13  *
14  * 1. The origin of this software must not be misrepresented; you must not
15  *    claim that you wrote the original software. If you use this software
16  *    in a product, an acknowledgment in the product documentation would be
17  *    appreciated but is not required.
18  *
19  * 2. Altered source versions must be plainly marked as such, and must not be
20  *    misrepresented as being the original software.
21  *
22  * 3. This notice may not be removed or altered from any source
23  *    distribution.
24  *
25  */
26
27 /* http://tools.ietf.org/html/rfc1866#section-8.2.1 */
28
29 /* Vendor name: */
30 /* Functionality name: htmlform */
31 /* Detail name: urnencoder */
32
33 #include    <basic.h>
34
35 #ifndef __HTMLFORM_URLENCODER_H__
36 #define __HTMLFORM_URLENCODER_H__
37
38 /* Functionality name: htmlform */
39 /* Detail name: */
40 /* Data structure identifier: field */
41 struct htmlform_field_ {
42         UB *name;
43         W name_len;
44         UB *value;
45         W value_len;
46 };
47 typedef struct htmlform_field_ htmlform_field;
48
49 /* Functionality name: htmlform */
50 /* Detail name: urlencoder */
51 struct htmlform_urlencoder_t_ {
52         htmlform_field *fields;
53         W fields_len;
54         enum {
55                 HTMLFORM_URLENCODER_STATE_NAME,
56                 HTMLFORM_URLENCODER_STATE_EQUAL,
57                 HTMLFORM_URLENCODER_STATE_VALUE,
58                 HTMLFORM_URLENCODER_STATE_AMP
59         } state;
60         W field_index;
61         W src_pos;
62         UB buf[3];
63 };
64 typedef struct htmlform_urlencoder_t_ htmlform_urlencoder_t;
65
66 IMPORT VOID htmlform_urlencoder_initialize(htmlform_urlencoder_t *encoder, htmlform_field *fields, W fields_len);
67 IMPORT VOID htmlform_urlencoder_finalize(htmlform_urlencoder_t *encoder);
68 IMPORT Bool htmlform_urlencoder_next(htmlform_urlencoder_t *encoder, UB **str, W *len);
69
70 #endif