Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
codyshao
TDengine
提交
0da8e9ad
T
TDengine
项目概览
codyshao
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0da8e9ad
编写于
8月 10, 2019
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revise issue #124
上级
0e57b621
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
58 addition
and
83 deletion
+58
-83
src/modules/http/inc/httpJson.h
src/modules/http/inc/httpJson.h
+1
-0
src/modules/http/inc/restJson.h
src/modules/http/inc/restJson.h
+7
-2
src/modules/http/src/httpJson.c
src/modules/http/src/httpJson.c
+16
-3
src/modules/http/src/restHandle.c
src/modules/http/src/restHandle.c
+18
-11
src/modules/http/src/restJson.c
src/modules/http/src/restJson.c
+16
-67
未找到文件。
src/modules/http/inc/httpJson.h
浏览文件 @
0da8e9ad
...
...
@@ -64,6 +64,7 @@ void httpJsonOriginString(JsonBuf* buf, char* sVal, int len);
void
httpJsonStringForTransMean
(
JsonBuf
*
buf
,
char
*
SVal
,
int
maxLen
);
void
httpJsonInt64
(
JsonBuf
*
buf
,
int64_t
num
);
void
httpJsonTimestamp
(
JsonBuf
*
buf
,
int64_t
t
);
void
httpJsonUtcTimestamp
(
JsonBuf
*
buf
,
int64_t
t
);
void
httpJsonInt
(
JsonBuf
*
buf
,
int
num
);
void
httpJsonFloat
(
JsonBuf
*
buf
,
float
num
);
void
httpJsonDouble
(
JsonBuf
*
buf
,
double
num
);
...
...
src/modules/http/inc/restJson.h
浏览文件 @
0da8e9ad
...
...
@@ -39,11 +39,16 @@
#define REST_JSON_AFFECT_ROWS "affected_rows"
#define REST_JSON_AFFECT_ROWS_LEN 13
#define REST_TIMESTAMP_FMT_LOCAL_STRING 0
#define REST_TIMESTAMP_FMT_TIMESTAMP 1
#define REST_TIMESTAMP_FMT_UTC_STRING 2
void
restBuildSqlAffectRowsJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
int
affect_rows
);
void
restStartSqlJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
);
bool
restBuildSqlJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
);
bool
restBuildSqlTimeJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
);
bool
restBuildSqlTimestampJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
);
bool
restBuildSqlLocalTimeStringJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
);
bool
restBuildSqlUtcTimeStringJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
);
void
restStopSqlJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
);
#endif
\ No newline at end of file
src/modules/http/src/httpJson.c
浏览文件 @
0da8e9ad
...
...
@@ -266,11 +266,24 @@ void httpJsonTimestamp(JsonBuf* buf, int64_t t) {
struct
tm
*
ptm
;
time_t
tt
=
t
/
1000
;
ptm
=
localtime
(
&
tt
);
int
length
=
(
int
)
strftime
(
ts
,
30
,
"%Y-%m-%d
T
%H:%M:%S"
,
ptm
);
int
length
=
(
int
)
strftime
(
ts
,
30
,
"%Y-%m-%d
%H:%M:%S"
,
ptm
);
snprintf
(
ts
+
length
,
MAX_NUM_STR_SZ
,
".%03ld
Z
"
,
t
%
1000
);
snprintf
(
ts
+
length
,
MAX_NUM_STR_SZ
,
".%03ld"
,
t
%
1000
);
httpJsonString
(
buf
,
ts
,
length
+
5
);
httpJsonString
(
buf
,
ts
,
length
+
4
);
}
void
httpJsonUtcTimestamp
(
JsonBuf
*
buf
,
int64_t
t
)
{
char
ts
[
35
]
=
{
0
};
struct
tm
*
ptm
;
time_t
tt
=
t
/
1000
;
ptm
=
localtime
(
&
tt
);
int
length
=
(
int
)
strftime
(
ts
,
35
,
"%Y-%m-%dT%H:%M:%S"
,
ptm
);
length
+=
snprintf
(
ts
+
length
,
MAX_NUM_STR_SZ
,
".%03ld"
,
t
%
1000
);
length
+=
(
int
)
strftime
(
ts
+
length
,
35
-
length
,
"%z"
,
ptm
);
httpJsonString
(
buf
,
ts
,
length
+
4
);
}
void
httpJsonInt
(
JsonBuf
*
buf
,
int
num
)
{
...
...
src/modules/http/src/restHandle.c
浏览文件 @
0da8e9ad
...
...
@@ -18,10 +18,12 @@
static
HttpDecodeMethod
restDecodeMethod
=
{
"rest"
,
restProcessRequest
};
static
HttpDecodeMethod
restDecodeMethod2
=
{
"restful"
,
restProcessRequest
};
static
HttpEncodeMethod
restEncodeSqlMethod
=
{
restStartSqlJson
,
restStopSqlJson
,
restBuildSqlJson
,
restBuildSqlAffectRowsJson
,
NULL
,
NULL
,
NULL
,
NULL
};
static
HttpEncodeMethod
restEncodeSqlTimeMethod
=
{
restStartSqlJson
,
restStopSqlJson
,
restBuildSqlTimeJson
,
restBuildSqlAffectRowsJson
,
NULL
,
NULL
,
NULL
,
NULL
};
static
HttpEncodeMethod
restEncodeSqlTimestampMethod
=
{
restStartSqlJson
,
restStopSqlJson
,
restBuildSqlTimestampJson
,
restBuildSqlAffectRowsJson
,
NULL
,
NULL
,
NULL
,
NULL
};
static
HttpEncodeMethod
restEncodeSqlLocalTimeStringMethod
=
{
restStartSqlJson
,
restStopSqlJson
,
restBuildSqlLocalTimeStringJson
,
restBuildSqlAffectRowsJson
,
NULL
,
NULL
,
NULL
,
NULL
};
static
HttpEncodeMethod
restEncodeSqlUtcTimeStringMethod
=
{
restStartSqlJson
,
restStopSqlJson
,
restBuildSqlUtcTimeStringJson
,
restBuildSqlAffectRowsJson
,
NULL
,
NULL
,
NULL
,
NULL
};
void
restInitHandle
(
HttpServer
*
pServer
)
{
httpAddMethod
(
pServer
,
&
restDecodeMethod
);
...
...
@@ -55,7 +57,7 @@ bool restProcessLoginRequest(HttpContext* pContext) {
return
true
;
}
bool
restProcessSqlRequest
(
HttpContext
*
pContext
,
int
isSqlT
)
{
bool
restProcessSqlRequest
(
HttpContext
*
pContext
,
int
timestampFmt
)
{
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, process restful sql msg"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
);
...
...
@@ -74,10 +76,13 @@ bool restProcessSqlRequest(HttpContext* pContext, int isSqlT) {
cmd
->
nativSql
=
sql
;
pContext
->
reqType
=
HTTP_REQTYPE_SINGLE_SQL
;
if
(
!
isSqlT
)
pContext
->
encodeMethod
=
&
restEncodeSqlMethod
;
else
pContext
->
encodeMethod
=
&
restEncodeSqlTimeMethod
;
if
(
timestampFmt
==
REST_TIMESTAMP_FMT_LOCAL_STRING
)
{
pContext
->
encodeMethod
=
&
restEncodeSqlLocalTimeStringMethod
;
}
else
if
(
timestampFmt
==
REST_TIMESTAMP_FMT_TIMESTAMP
)
{
pContext
->
encodeMethod
=
&
restEncodeSqlTimestampMethod
;
}
else
if
(
timestampFmt
==
REST_TIMESTAMP_FMT_UTC_STRING
)
{
pContext
->
encodeMethod
=
&
restEncodeSqlUtcTimeStringMethod
;
}
return
true
;
}
...
...
@@ -94,9 +99,11 @@ bool restProcessRequest(struct HttpContext* pContext) {
}
if
(
httpUrlMatch
(
pContext
,
REST_ACTION_URL_POS
,
"sql"
))
{
return
restProcessSqlRequest
(
pContext
,
0
);
return
restProcessSqlRequest
(
pContext
,
REST_TIMESTAMP_FMT_LOCAL_STRING
);
}
else
if
(
httpUrlMatch
(
pContext
,
REST_ACTION_URL_POS
,
"sqlt"
))
{
return
restProcessSqlRequest
(
pContext
,
1
);
return
restProcessSqlRequest
(
pContext
,
REST_TIMESTAMP_FMT_TIMESTAMP
);
}
else
if
(
httpUrlMatch
(
pContext
,
REST_ACTION_URL_POS
,
"sqlutc"
))
{
return
restProcessSqlRequest
(
pContext
,
REST_TIMESTAMP_FMT_UTC_STRING
);
}
else
if
(
httpUrlMatch
(
pContext
,
REST_ACTION_URL_POS
,
"login"
))
{
return
restProcessLoginRequest
(
pContext
);
}
else
{
...
...
src/modules/http/src/restJson.c
浏览文件 @
0da8e9ad
...
...
@@ -85,7 +85,7 @@ void restStartSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result)
httpJsonToken
(
jsonBuf
,
JsonArrStt
);
}
bool
restBuildSqlJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
)
{
bool
restBuildSqlJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
,
int
timestampFormat
)
{
JsonBuf
*
jsonBuf
=
httpMallocJsonBuf
(
pContext
);
if
(
jsonBuf
==
NULL
)
return
false
;
...
...
@@ -134,10 +134,13 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
httpJsonStringForTransMean
(
jsonBuf
,
row
[
i
],
fields
[
i
].
bytes
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
// httpJsonInt64(jsonBuf, *((int64_t *)row[i]));
// httpTimeToString(*((int64_t *)row[i]), timeBuf, 32);
// httpJsonString(jsonBuf, timeBuf, strlen(timeBuf));
httpJsonTimestamp
(
jsonBuf
,
*
((
int64_t
*
)
row
[
i
]));
if
(
timestampFormat
==
REST_TIMESTAMP_FMT_LOCAL_STRING
)
{
httpJsonTimestamp
(
jsonBuf
,
*
((
int64_t
*
)
row
[
i
]));
}
else
if
(
timestampFormat
==
REST_TIMESTAMP_FMT_TIMESTAMP
)
{
httpJsonInt64
(
jsonBuf
,
*
((
int64_t
*
)
row
[
i
]));
}
else
{
httpJsonUtcTimestamp
(
jsonBuf
,
*
((
int64_t
*
)
row
[
i
]));
}
break
;
default:
break
;
...
...
@@ -167,70 +170,16 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
}
}
bool
restBuildSqlTimeJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
)
{
JsonBuf
*
jsonBuf
=
httpMallocJsonBuf
(
pContext
);
if
(
jsonBuf
==
NULL
)
return
false
;
cmd
->
numOfRows
+=
numOfRows
;
int
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
for
(
int
i
=
0
;
i
<
numOfRows
;
++
i
)
{
TAOS_ROW
row
=
taos_fetch_row
(
result
);
// data row array begin
httpJsonItemToken
(
jsonBuf
);
httpJsonToken
(
jsonBuf
,
JsonArrStt
);
for
(
int
i
=
0
;
i
<
num_fields
;
i
++
)
{
httpJsonItemToken
(
jsonBuf
);
if
(
row
[
i
]
==
NULL
)
{
httpJsonOriginString
(
jsonBuf
,
"null"
,
4
);
continue
;
}
switch
(
fields
[
i
].
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
httpJsonInt
(
jsonBuf
,
*
((
int8_t
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
httpJsonInt
(
jsonBuf
,
*
((
int16_t
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_INT
:
httpJsonInt
(
jsonBuf
,
*
((
int32_t
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_BIGINT
:
httpJsonInt64
(
jsonBuf
,
*
((
int64_t
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_FLOAT
:
httpJsonFloat
(
jsonBuf
,
*
((
float
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
httpJsonDouble
(
jsonBuf
,
*
((
double
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
httpJsonStringForTransMean
(
jsonBuf
,
row
[
i
],
fields
[
i
].
bytes
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
httpJsonInt64
(
jsonBuf
,
*
((
int64_t
*
)
row
[
i
]));
// httpTimeToString(*((int64_t *)row[i]), timeBuf, 32);
// httpJsonString(jsonBuf, timeBuf, strlen(timeBuf));
// httpJsonTimestamp(jsonBuf, *((int64_t *)row[i]));
break
;
default:
break
;
}
}
bool
restBuildSqlTimestampJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
)
{
return
restBuildSqlJson
(
pContext
,
cmd
,
result
,
numOfRows
,
REST_TIMESTAMP_FMT_TIMESTAMP
);
}
// data row array end
httpJsonToken
(
jsonBuf
,
JsonArrEnd
);
}
bool
restBuildSqlLocalTimeStringJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
)
{
return
restBuildSqlJson
(
pContext
,
cmd
,
result
,
numOfRows
,
REST_TIMESTAMP_FMT_LOCAL_STRING
);
}
return
true
;
bool
restBuildSqlUtcTimeStringJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
,
TAOS_RES
*
result
,
int
numOfRows
)
{
return
restBuildSqlJson
(
pContext
,
cmd
,
result
,
numOfRows
,
REST_TIMESTAMP_FMT_UTC_STRING
);
}
void
restStopSqlJson
(
HttpContext
*
pContext
,
HttpSqlCmd
*
cmd
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录