1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 #ifndef IOTJS_MODULE_HTTPPARSER_H
18 #define IOTJS_MODULE_HTTPPARSER_H
21 #include "iotjs_objectwrap.h"
23 #include "http_parser.h"
26 // If # of header fields == HEADER_MAX, flush header to JS side.
27 // This is weired : # of maximum headers in C equals to HEADER_MAX-1.
28 // This is because , OnHeaders cb, we increase n_fields first,
29 // and check whether field == HEADER_MAX.
30 // ex) HEADER_MAX 2 means that we can keep at most 1 header field/value
31 // during http parsing.
32 // Increase this to minimize inter JS-C call
37 iotjs_jobjectwrap_t jobjectwrap;
42 iotjs_string_t status_msg;
44 iotjs_string_t fields[HEADER_MAX];
45 iotjs_string_t values[HEADER_MAX];
49 iotjs_jval_t* cur_jbuf;
54 } IOTJS_VALIDATED_STRUCT(iotjs_httpparserwrap_t);
57 typedef enum http_parser_type http_parser_type;
60 #define THIS iotjs_httpparserwrap_t* httpparserwrap
63 iotjs_httpparserwrap_t* iotjs_httpparserwrap_create(const iotjs_jval_t* jparser,
64 http_parser_type type);
66 void iotjs_httpparserwrap_initialize(THIS, http_parser_type type);
67 iotjs_jval_t iotjs_httpparserwrap_make_header(THIS);
69 void iotjs_httpparserwrap_flush(THIS);
71 void iotjs_httpparserwrap_set_buf(THIS, iotjs_jval_t* jbuf, char* buf, int sz);
73 iotjs_jval_t* iotjs_httpparserwrap_jobject(THIS);
74 http_parser* iotjs_httpparserwrap_parser(THIS);
80 #endif /* IOTJS_MODULE_HTTPPARSER_H */