Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
11aed420
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
11aed420
编写于
9月 12, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-1311
上级
a1527b62
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
356 addition
and
356 deletion
+356
-356
src/plugins/http/inc/ehttp_parser.h
src/plugins/http/inc/ehttp_parser.h
+77
-20
src/plugins/http/inc/ehttp_util_string.h
src/plugins/http/inc/ehttp_util_string.h
+10
-15
src/plugins/http/inc/httpInt.h
src/plugins/http/inc/httpInt.h
+3
-4
src/plugins/http/src/ehttp_parser.c
src/plugins/http/src/ehttp_parser.c
+252
-301
src/plugins/http/src/ehttp_util_string.c
src/plugins/http/src/ehttp_util_string.c
+5
-8
src/plugins/http/src/httpContext.c
src/plugins/http/src/httpContext.c
+4
-6
src/plugins/http/src/httpServer.c
src/plugins/http/src/httpServer.c
+5
-2
未找到文件。
src/plugins/http/inc/ehttp_parser.h
浏览文件 @
11aed420
#ifndef
_ehttp_parser_fc7f9ac9_52da_4ee3_b556_deb2e1c3866e
#define
_ehttp_parser_fc7f9ac9_52da_4ee3_b556_deb2e1c3866e
#ifndef
HTTP_PARSER_H
#define
HTTP_PARSER_H
#include <stddef.h>
#include "ehttp_util_string.h"
#include "ehttp_gzip.h"
typedef
struct
ehttp_parser_s
ehttp_parser_t
;
typedef
struct
ehttp_parser_callbacks_s
ehttp_parser_callbacks_t
;
typedef
struct
ehttp_parser_conf_s
ehttp_parser_conf_t
;
typedef
struct
ehttp_status_code_s
ehttp_status_code_t
;
struct
HttpContext
;
struct
ehttp_parser_callbacks_s
{
typedef
enum
HTTP_PARSER_STATE
{
HTTP_PARSER_BEGIN
,
HTTP_PARSER_REQUEST_OR_RESPONSE
,
HTTP_PARSER_METHOD
,
HTTP_PARSER_TARGET
,
HTTP_PARSER_HTTP_VERSION
,
HTTP_PARSER_SP
,
HTTP_PARSER_STATUS_CODE
,
HTTP_PARSER_REASON_PHRASE
,
HTTP_PARSER_CRLF
,
HTTP_PARSER_HEADER
,
HTTP_PARSER_HEADER_KEY
,
HTTP_PARSER_HEADER_VAL
,
HTTP_PARSER_CHUNK_SIZE
,
HTTP_PARSER_CHUNK
,
HTTP_PARSER_END
,
HTTP_PARSER_ERROR
,
}
HTTP_PARSER_STATE
;
typedef
struct
HttpParserStatusObj
{
int32_t
status_code
;
const
char
*
status_desc
;
}
HttpParserStatusObj
;
typedef
struct
HttpParserCallbackObj
{
void
(
*
on_request_line
)(
void
*
arg
,
const
char
*
method
,
const
char
*
target
,
const
char
*
version
,
const
char
*
target_raw
);
void
(
*
on_status_line
)(
void
*
arg
,
const
char
*
version
,
int
status_code
,
const
char
*
reason_phrase
);
void
(
*
on_header_field
)(
void
*
arg
,
const
char
*
key
,
const
char
*
val
);
void
(
*
on_body
)(
void
*
arg
,
const
char
*
chunk
,
size_t
len
);
void
(
*
on_end
)(
void
*
arg
);
void
(
*
on_error
)(
void
*
arg
,
int
status_code
);
};
}
HttpParserCallbackObj
;
typedef
struct
HttpParserConfObj
{
size_t
flush_block_size
;
// <=0: immediately
}
HttpParserConfObj
;
struct
ehttp_parser_conf_s
{
size_t
flush_block_size
;
// <=0: immediately
};
typedef
struct
HttpParseKvObj
{
char
*
key
;
char
*
val
;
}
HttpParseKvObj
;
ehttp_parser_t
*
ehttp_parser_create
(
ehttp_parser_callbacks_t
callbacks
,
ehttp_parser_conf_t
conf
,
void
*
arg
);
void
ehttp_parser_destroy
(
ehttp_parser_t
*
parser
);
int
ehttp_parser_parse
(
ehttp_parser_t
*
parser
,
const
char
*
buf
,
size_t
len
);
int
ehttp_parser_parse_string
(
ehttp_parser_t
*
parser
,
const
char
*
str
);
int
ehttp_parser_parse_char
(
ehttp_parser_t
*
parser
,
const
char
c
);
int
ehttp_parser_parse_end
(
ehttp_parser_t
*
parser
);
typedef
struct
HttpParserObj
{
HttpParserCallbackObj
callbacks
;
HttpParserConfObj
conf
;
void
*
arg
;
char
*
method
;
char
*
target
;
char
*
target_raw
;
char
*
version
;
int
http_10
:
2
;
int
http_11
:
2
;
int
accept_encoding_gzip
:
2
;
int
accept_encoding_chunked
:
2
;
int
transfer_gzip
:
2
;
int
transfer_chunked
:
2
;
int
content_length_specified
:
2
;
int
content_chunked
:
2
;
int
status_code
;
char
*
reason_phrase
;
char
*
key
;
char
*
val
;
HttpParseKvObj
*
kvs
;
size_t
kvs_count
;
char
*
auth_basic
;
char
*
auth_taosd
;
size_t
content_length
;
size_t
chunk_size
;
size_t
received_chunk_size
;
size_t
received_size
;
ehttp_gzip_t
*
gzip
;
HttpUtilString
str
;
HTTP_PARSER_STATE
*
stacks
;
size_t
stacks_count
;
}
HttpParserObj
;
HttpParserObj
*
httpParserCreate
(
HttpParserCallbackObj
callbacks
,
HttpParserConfObj
conf
,
void
*
arg
);
void
httpParserDestroy
(
HttpParserObj
*
parser
);
int32_t
httpParserBuf
(
struct
HttpContext
*
pContext
,
HttpParserObj
*
parser
,
const
char
*
buf
,
int32_t
len
);
char
*
ehttp_parser_urldecode
(
const
char
*
enc
);
const
char
*
ehttp_status_code_get_desc
(
const
int
status_code
);
#endif // _ehttp_parser_fc7f9ac9_52da_4ee3_b556_deb2e1c3866e
#endif
src/plugins/http/inc/ehttp_util_string.h
浏览文件 @
11aed420
#ifndef
_ehttp_util_string_h_99dacde5_2e7d_4662_97d6_04611fde683b_
#define
_ehttp_util_string_h_99dacde5_2e7d_4662_97d6_04611fde683b_
#ifndef
HTTP_UTIL_STRING
#define
HTTP_UTIL_STRING
#include <stddef.h>
typedef
struct
HttpUtilString
{
char
*
str
;
size_t
len
;
}
HttpUtilString
;
typedef
struct
ehttp_util_string_s
ehttp_util_string_t
;
struct
ehttp_util_string_s
{
char
*
str
;
size_t
len
;
};
void
ehttp_util_string_cleanup
(
ehttp_util_string_t
*
str
);
int
ehttp_util_string_append
(
ehttp_util_string_t
*
str
,
const
char
*
s
,
size_t
len
);
void
ehttp_util_string_clear
(
ehttp_util_string_t
*
str
);
#endif // _ehttp_util_string_h_99dacde5_2e7d_4662_97d6_04611fde683b_
void
httpParserCleanupString
(
HttpUtilString
*
str
);
int32_t
httpParserAppendString
(
HttpUtilString
*
str
,
const
char
*
s
,
int32_t
len
);
void
httpParserClearString
(
HttpUtilString
*
str
);
#endif
src/plugins/http/inc/httpInt.h
浏览文件 @
11aed420
...
...
@@ -179,10 +179,9 @@ typedef struct {
HttpBuf
data
;
// body content
HttpBuf
token
;
// auth token
HttpDecodeMethod
*
pMethod
;
ehttp_parser_t
*
parser
;
int
inited
:
2
;
int
failed
:
4
;
HttpParserObj
*
parser
;
int8_t
inited
;
int8_t
failed
;
}
HttpParser
;
typedef
struct
HttpContext
{
...
...
src/plugins/http/src/ehttp_parser.c
浏览文件 @
11aed420
此差异已折叠。
点击以展开。
src/plugins/http/src/ehttp_util_string.c
浏览文件 @
11aed420
#include "os.h"
#include "ehttp_util_string.h"
#include <stdlib.h>
#include <string.h>
void
ehttp_util_string_cleanup
(
ehttp_util_string_t
*
str
)
{
void
httpParserCleanupString
(
HttpUtilString
*
str
)
{
free
(
str
->
str
);
str
->
str
=
NULL
;
str
->
len
=
0
;
}
int
ehttp_util_string_append
(
ehttp_util_string_t
*
str
,
const
char
*
s
,
size_t
len
)
{
// int n = str->str?strlen(str->str):0;
int
n
=
str
->
len
;
int32_t
httpParserAppendString
(
HttpUtilString
*
str
,
const
char
*
s
,
int32_t
len
)
{
int32_t
n
=
str
->
len
;
char
*
p
=
(
char
*
)
realloc
(
str
->
str
,
n
+
len
+
1
);
if
(
!
p
)
return
-
1
;
strncpy
(
p
+
n
,
s
,
len
);
...
...
@@ -21,7 +18,7 @@ int ehttp_util_string_append(ehttp_util_string_t *str, const char *s, size_t len
return
0
;
}
void
ehttp_util_string_clear
(
ehttp_util_string_t
*
str
)
{
void
httpParserClearString
(
HttpUtilString
*
str
)
{
if
(
str
->
str
)
{
str
->
str
[
0
]
=
'\0'
;
str
->
len
=
0
;
...
...
src/plugins/http/src/httpContext.c
浏览文件 @
11aed420
...
...
@@ -26,11 +26,9 @@
#include "httpResp.h"
#include "httpSql.h"
#include "httpSession.h"
#include "httpContext.h"
#include "elog.h"
// dirty tweak
extern
bool
httpGetHttpMethod
(
HttpContext
*
pContext
);
extern
bool
httpParseURL
(
HttpContext
*
pContext
);
extern
bool
httpParseHttpVersion
(
HttpContext
*
pContext
);
...
...
@@ -74,7 +72,7 @@ static void httpDestroyContext(void *data) {
httpFreeMultiCmds
(
pContext
);
if
(
pContext
->
parser
.
parser
)
{
ehttp_parser_d
estroy
(
pContext
->
parser
.
parser
);
httpParserD
estroy
(
pContext
->
parser
.
parser
);
pContext
->
parser
.
parser
=
NULL
;
}
...
...
@@ -195,7 +193,7 @@ bool httpInitContext(HttpContext *pContext) {
memset
(
pParser
,
0
,
sizeof
(
HttpParser
));
pParser
->
pCur
=
pParser
->
pLast
=
pParser
->
buffer
;
ehttp_parser_callbacks_t
callbacks
=
{
HttpParserCallbackObj
callbacks
=
{
httpParseOnRequestLine
,
httpParseOnStatusLine
,
httpParseOnHeaderField
,
...
...
@@ -203,10 +201,10 @@ bool httpInitContext(HttpContext *pContext) {
httpParseOnEnd
,
httpParseOnError
};
ehttp_parser_conf_t
conf
=
{
HttpParserConfObj
conf
=
{
.
flush_block_size
=
0
};
pParser
->
parser
=
ehttp_parser_c
reate
(
callbacks
,
conf
,
pContext
);
pParser
->
parser
=
httpParserC
reate
(
callbacks
,
conf
,
pContext
);
pParser
->
inited
=
1
;
httpDebug
(
"context:%p, fd:%d, parsed:%d"
,
pContext
,
pContext
->
fd
,
pContext
->
parsed
);
...
...
src/plugins/http/src/httpServer.c
浏览文件 @
11aed420
...
...
@@ -352,8 +352,11 @@ static bool httpReadData(HttpContext *pContext) {
int
nread
=
(
int
)
taosReadSocket
(
pContext
->
fd
,
buf
,
sizeof
(
buf
));
if
(
nread
>
0
)
{
buf
[
nread
]
=
'\0'
;
if
(
ehttp_parser_parse
(
pParser
->
parser
,
buf
,
nread
))
{
httpError
(
"context:%p, fd:%d, init parse failed, close connect"
,
pContext
,
pContext
->
fd
);
httpTrace
(
"context:%p, fd:%d, nread:%d content:%s"
,
pContext
,
pContext
->
fd
,
nread
,
buf
);
int
ok
=
httpParserBuf
(
pContext
,
pParser
->
parser
,
buf
,
nread
);
if
(
ok
)
{
httpError
(
"context:%p, fd:%d, init parse failed, reason:%d close connect"
,
pContext
,
pContext
->
fd
,
ok
);
httpNotifyContextClose
(
pContext
);
return
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录