OSDN Git Service

change http_contentdecoder_t I/F.
[bbk/bchanf.git] / src / http / http_contentdecoder.h
1 /*
2  * http_contentdecoder.h
3  *
4  * Copyright (c) 2012 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 /* Vendor name: */
28 /* Functionality name: http */
29 /* Detail name: contentdecoder */
30
31 #include    <basic.h>
32 #include        <util/zlib.h>
33
34 #include    "http_typedef.h"
35
36 /* rfc2616 3.5 Content Codings */
37
38 #ifndef __HTTP_CONTENTDECODER_H__
39 #define __HTTP_CONTENTDECODER_H__
40
41 /* Functionality name: http */
42 /* Detail name: contentdecoder */
43 /* Data structure identifier: result */
44 struct http_contentdecoder_result_ {
45         enum {
46                 HTTP_CONTENTDECODER_RESULTTYPE_DATA,
47                 HTTP_CONTENTDECODER_RESULTTYPE_NEED_INPUT,
48                 HTTP_CONTENTDECODER_RESULTTYPE_END,
49         } type;
50         UB *data;
51         W len;
52 };
53 typedef struct http_contentdecoder_result_ http_contentdecoder_result;
54
55 /* Functionality name: http */
56 /* Detail name: contentdecoderidentity */
57 struct http_contentdecoderidentity_t_ {
58         http_contentdecoder_result result[2];
59         enum {
60                 HTTP_CONTENTDECODERIDENTITY_STATE_DATA,
61                 HTTP_CONTENTDECODERIDENTITY_STATE_END,
62         } state;
63         UB *data;
64         W data_len;
65 };
66 typedef struct http_contentdecoderidentity_t_ http_contentdecoderidentity_t;
67
68 /* Functionality name: gzip */
69 /* Detail name: headerskip */
70 struct gzip_headerskip_t_ {
71         enum {
72                 GZIP_HEADERSKIP_STATE_MAGIC_NUMBER_FIRST,
73                 GZIP_HEADERSKIP_STATE_MAGIC_NUMBER_SECOND,
74                 GZIP_HEADERSKIP_STATE_METHOD,
75                 GZIP_HEADERSKIP_STATE_FLAGS,
76                 GZIP_HEADERSKIP_STATE_SKIP_UNUSED_FIELD,
77                 GZIP_HEADERSKIP_STATE_EXTRA_FIELD_LEN_FIRST,
78                 GZIP_HEADERSKIP_STATE_EXTRA_FIELD_LEN_SECOND,
79                 GZIP_HEADERSKIP_STATE_SKIP_EXTRA_FIELD,
80                 GZIP_HEADERSKIP_STATE_SKIP_FILE_NAME,
81                 GZIP_HEADERSKIP_STATE_SKIP_FILE_COMMENT,
82                 GZIP_HEADERSKIP_STATE_SKIP_HEADER_CRC_FIRST,
83                 GZIP_HEADERSKIP_STATE_SKIP_HEADER_CRC_SECOND,
84         } state;
85         UB flags;
86         W extra_len;
87         W unused;
88 };
89 typedef struct gzip_headerskip_t_ gzip_headerskip_t;
90
91 /* Functionality name: http */
92 /* Detail name: contentdecodergzip */
93 #define HTTP_CONTENTDECODERGZIP_BUFLEN 512
94 struct http_contentdecodergzip_t_ {
95         http_contentdecoder_result result[1];
96         enum {
97                 HTTP_CONTENTDECODERGZIP_STATE_SKIP_HEADER,
98                 HTTP_CONTENTDECODERGZIP_STATE_DECODE,
99                 HTTP_CONTENTDECODERGZIP_STATE_END_OF_DATA, /* tmp */
100         } state;
101         gzip_headerskip_t gzipheader;
102         z_stream z;
103         UB buffer[HTTP_CONTENTDECODERGZIP_BUFLEN];
104 };
105 typedef struct http_contentdecodergzip_t_ http_contentdecodergzip_t;
106
107 /* Functionality name: http */
108 /* Detail name: contentdecoder */
109 struct http_contentdecoder_t_ {
110         HTTP_CONTENTCODING_VALUE type;
111         union {
112                 http_contentdecoderidentity_t identity;
113                 http_contentdecodergzip_t gzip;
114         } d;
115 };
116 typedef struct http_contentdecoder_t_ http_contentdecoder_t;
117
118 IMPORT W http_contentdecoder_initialize(http_contentdecoder_t *decoder, HTTP_CONTENTCODING_VALUE type);
119 IMPORT VOID http_contentdecoder_finalize(http_contentdecoder_t *decoder);
120 IMPORT W http_contentdecoder_inputentitybody(http_contentdecoder_t *decoder, UB *data, W data_len);
121 IMPORT W http_contentdecoder_inputendofdata(http_contentdecoder_t *decoder);
122 IMPORT W http_contentdecoder_outputdata(http_contentdecoder_t *decoder, http_contentdecoder_result **result, W *result_len);
123
124 #endif