Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
118861ce
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
118861ce
编写于
11月 28, 2019
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix issue #626 and [TBASE-1192]
上级
8254aba1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
19 deletion
+36
-19
src/modules/http/inc/httpHandle.h
src/modules/http/inc/httpHandle.h
+3
-1
src/modules/http/src/httpSession.c
src/modules/http/src/httpSession.c
+32
-15
src/modules/http/src/httpSql.c
src/modules/http/src/httpSql.c
+1
-3
未找到文件。
src/modules/http/inc/httpHandle.h
浏览文件 @
118861ce
...
...
@@ -68,6 +68,8 @@
#define HTTP_COMPRESS_IDENTITY 0
#define HTTP_COMPRESS_GZIP 2
#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN * 2 + 1)
typedef
enum
{
HTTP_CONTEXT_STATE_READY
,
HTTP_CONTEXT_STATE_HANDLING
,
...
...
@@ -83,7 +85,7 @@ typedef struct {
int
expire
;
int
access
;
void
*
taos
;
char
id
[
TSDB_USER_LEN
];
char
id
[
HTTP_SESSION_ID_LEN
+
1
];
}
HttpSession
;
typedef
enum
{
...
...
src/modules/http/src/httpSession.c
浏览文件 @
118861ce
...
...
@@ -41,8 +41,8 @@ void httpCreateSession(HttpContext *pContext, void *taos) {
pthread_mutex_lock
(
&
server
->
serverMutex
);
if
(
pContext
->
session
!=
NULL
&&
pContext
->
session
==
pContext
->
session
->
signature
)
{
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, set exist session:%p:%
s:%
p expired"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
pContext
->
session
,
pContext
->
session
->
id
,
pContext
->
session
->
taos
);
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, set exist session:%p:%p expired"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
pContext
->
session
,
pContext
->
session
->
taos
);
pContext
->
session
->
expire
=
0
;
pContext
->
session
->
access
--
;
}
...
...
@@ -51,7 +51,7 @@ void httpCreateSession(HttpContext *pContext, void *taos) {
session
.
taos
=
taos
;
session
.
expire
=
(
int
)
taosGetTimestampSec
()
+
server
->
sessionExpire
;
session
.
access
=
1
;
s
trcpy
(
session
.
id
,
pContext
->
user
);
s
nprintf
(
session
.
id
,
HTTP_SESSION_ID_LEN
,
"%s.%s"
,
pContext
->
user
,
pContext
->
pass
);
pContext
->
session
=
(
HttpSession
*
)
taosAddStrHash
(
server
->
pSessionHash
,
session
.
id
,
(
char
*
)(
&
session
));
if
(
pContext
->
session
==
NULL
)
{
httpError
(
"context:%p, fd:%d, ip:%s, user:%s, error:%s"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
...
...
@@ -62,20 +62,23 @@ void httpCreateSession(HttpContext *pContext, void *taos) {
}
pContext
->
session
->
signature
=
pContext
->
session
;
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, create a new session:%p:%
s:%
p"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
pContext
->
session
,
pContext
->
session
->
id
,
pContext
->
session
->
taos
);
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, create a new session:%p:%p"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
pContext
->
session
,
pContext
->
session
->
taos
);
pthread_mutex_unlock
(
&
server
->
serverMutex
);
}
void
httpFetchSession
(
HttpContext
*
pContext
)
{
void
httpFetchSession
Imp
(
HttpContext
*
pContext
)
{
HttpServer
*
server
=
pContext
->
pThread
->
pServer
;
pthread_mutex_lock
(
&
server
->
serverMutex
);
pContext
->
session
=
(
HttpSession
*
)
taosGetStrHashData
(
server
->
pSessionHash
,
pContext
->
user
);
char
sessionId
[
HTTP_SESSION_ID_LEN
];
snprintf
(
sessionId
,
HTTP_SESSION_ID_LEN
,
"%s.%s"
,
pContext
->
user
,
pContext
->
pass
);
pContext
->
session
=
(
HttpSession
*
)
taosGetStrHashData
(
server
->
pSessionHash
,
sessionId
);
if
(
pContext
->
session
!=
NULL
&&
pContext
->
session
==
pContext
->
session
->
signature
)
{
pContext
->
session
->
access
++
;
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, find an exist session:%p:%
s:%
p, access:%d, expire:%d"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
pContext
->
session
,
pContext
->
session
->
id
,
httpTrace
(
"context:%p, fd:%d, ip:%s, user:%s, find an exist session:%p:%p, access:%d, expire:%d"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
,
pContext
->
session
,
pContext
->
session
->
taos
,
pContext
->
session
->
access
,
pContext
->
session
->
expire
);
pContext
->
session
->
expire
=
(
int
)
taosGetTimestampSec
()
+
server
->
sessionExpire
;
}
else
{
...
...
@@ -86,6 +89,20 @@ void httpFetchSession(HttpContext *pContext) {
pthread_mutex_unlock
(
&
server
->
serverMutex
);
}
void
httpFetchSession
(
HttpContext
*
pContext
)
{
if
(
pContext
->
session
==
NULL
)
{
httpFetchSessionImp
(
pContext
);
}
else
{
char
sessionId
[
HTTP_SESSION_ID_LEN
];
snprintf
(
sessionId
,
HTTP_SESSION_ID_LEN
,
"%s.%s"
,
pContext
->
user
,
pContext
->
pass
);
if
(
strcmp
(
pContext
->
session
->
id
,
sessionId
)
!=
0
)
{
httpError
(
"context:%p, fd:%d, ip:%s, user:%s, password may be changed"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
user
);
httpRestoreSession
(
pContext
);
httpFetchSessionImp
(
pContext
);
}
}
}
void
httpRestoreSession
(
HttpContext
*
pContext
)
{
HttpServer
*
server
=
pContext
->
pThread
->
pServer
;
...
...
@@ -97,15 +114,15 @@ void httpRestoreSession(HttpContext *pContext) {
return
;
}
session
->
access
--
;
httpTrace
(
"context:%p, ip:%s, user:%s, restore session:%p:%
s:%
p, access:%d, expire:%d"
,
pContext
,
pContext
->
ipstr
,
pContext
->
user
,
session
,
session
->
id
,
session
->
taos
,
httpTrace
(
"context:%p, ip:%s, user:%s, restore session:%p:%p, access:%d, expire:%d"
,
pContext
,
pContext
->
ipstr
,
pContext
->
user
,
session
,
session
->
taos
,
session
->
access
,
pContext
->
session
->
expire
);
pthread_mutex_unlock
(
&
server
->
serverMutex
);
}
void
httpResetSession
(
char
*
session
)
{
HttpSession
*
pSession
=
(
HttpSession
*
)
session
;
httpTrace
(
"close session:%p:%
s:%p"
,
pSession
,
pSession
->
id
,
pSession
->
taos
);
httpTrace
(
"close session:%p:%
p"
,
pSession
,
pSession
->
taos
);
if
(
pSession
->
taos
!=
NULL
)
{
taos_close
(
pSession
->
taos
);
pSession
->
taos
=
NULL
;
...
...
@@ -144,12 +161,12 @@ int httpSessionExpired(char *session) {
return
0
;
// un-expired, so return false
}
if
(
pSession
->
access
>
0
)
{
httpTrace
(
"session:%p:%
s:%p is expired, but still access:%d"
,
pSession
,
pSession
->
id
,
pSession
->
taos
,
httpTrace
(
"session:%p:%
p is expired, but still access:%d"
,
pSession
,
pSession
->
taos
,
pSession
->
access
);
return
0
;
// still used, so return false
}
httpTrace
(
"need close session:%p:%
s:%
p for it expired, cur:%d, expire:%d, invertal:%d"
,
pSession
,
pSession
->
id
,
pSession
->
taos
,
cur
,
pSession
->
expire
,
cur
-
pSession
->
expire
);
httpTrace
(
"need close session:%p:%p for it expired, cur:%d, expire:%d, invertal:%d"
,
pSession
,
pSession
->
taos
,
cur
,
pSession
->
expire
,
cur
-
pSession
->
expire
);
}
return
1
;
...
...
src/modules/http/src/httpSql.c
浏览文件 @
118861ce
...
...
@@ -378,9 +378,7 @@ void httpProcessRequestCb(void *param, TAOS_RES *result, int code) {
}
void
httpProcessRequest
(
HttpContext
*
pContext
)
{
if
(
pContext
->
session
==
NULL
)
{
httpFetchSession
(
pContext
);
}
httpFetchSession
(
pContext
);
if
(
pContext
->
session
==
NULL
||
pContext
->
session
!=
pContext
->
session
->
signature
||
pContext
->
reqType
==
HTTP_REQTYPE_LOGIN
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录