Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
a845755e
提交
a845755e
authored
9月 07, 2014
作者:
Seven Du
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
http 1.1 keepalive support
上级
023f6e14
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
60 行增加
和
10 行删除
+60
-10
mod_verto.c
src/mod/endpoints/mod_verto/mod_verto.c
+60
-10
没有找到文件。
src/mod/endpoints/mod_verto/mod_verto.c
浏览文件 @
a845755e
...
@@ -1287,6 +1287,11 @@ static uint8_t *http_stream_read(switch_stream_handle_t *handle, int *len)
...
@@ -1287,6 +1287,11 @@ static uint8_t *http_stream_read(switch_stream_handle_t *handle, int *len)
jsock_t
*
jsock
=
r
->
user_data
;
jsock_t
*
jsock
=
r
->
user_data
;
wsh_t
*
wsh
=
&
jsock
->
ws
;
wsh_t
*
wsh
=
&
jsock
->
ws
;
if
(
!
jsock
->
profile
->
running
)
{
*
len
=
0
;
return
NULL
;
}
*
len
=
r
->
bytes_buffered
-
r
->
bytes_read
;
*
len
=
r
->
bytes_buffered
-
r
->
bytes_read
;
if
(
*
len
>
0
)
{
// we already read part of the body
if
(
*
len
>
0
)
{
// we already read part of the body
...
@@ -1303,7 +1308,7 @@ static uint8_t *http_stream_read(switch_stream_handle_t *handle, int *len)
...
@@ -1303,7 +1308,7 @@ static uint8_t *http_stream_read(switch_stream_handle_t *handle, int *len)
*
len
=
r
->
content_length
-
(
r
->
bytes_read
-
r
->
bytes_header
);
*
len
=
r
->
content_length
-
(
r
->
bytes_read
-
r
->
bytes_header
);
*
len
=
*
len
>
sizeof
(
wsh
->
buffer
)
?
sizeof
(
wsh
->
buffer
)
:
*
len
;
*
len
=
*
len
>
sizeof
(
wsh
->
buffer
)
?
sizeof
(
wsh
->
buffer
)
:
*
len
;
if
((
*
len
=
ws_raw_read
(
wsh
,
wsh
->
buffer
,
*
len
,
wsh
->
block
))
<
=
0
)
{
if
((
*
len
=
ws_raw_read
(
wsh
,
wsh
->
buffer
,
*
len
,
wsh
->
block
))
<
0
)
{
*
len
=
0
;
*
len
=
0
;
return
NULL
;
return
NULL
;
}
}
...
@@ -1354,7 +1359,7 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v
...
@@ -1354,7 +1359,7 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v
if
(
strncmp
(
request
->
method
,
"GET"
,
3
)
&&
strncmp
(
request
->
method
,
"HEAD"
,
4
))
{
if
(
strncmp
(
request
->
method
,
"GET"
,
3
)
&&
strncmp
(
request
->
method
,
"HEAD"
,
4
))
{
char
*
data
=
"HTTP/1.1 415 Method Not Allowed
\r\n
"
char
*
data
=
"HTTP/1.1 415 Method Not Allowed
\r\n
"
"Con
nection: close
\r\n\r\n
"
;
"Con
tent-Length: 0
\r\n\r\n
"
;
ws_raw_write
(
&
jsock
->
ws
,
data
,
strlen
(
data
));
ws_raw_write
(
&
jsock
->
ws
,
data
,
strlen
(
data
));
return
;
return
;
}
}
...
@@ -1381,7 +1386,6 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v
...
@@ -1381,7 +1386,6 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v
switch_snprintf
((
char
*
)
chunk
,
sizeof
(
chunk
),
switch_snprintf
((
char
*
)
chunk
,
sizeof
(
chunk
),
"HTTP/1.1 200 OK
\r\n
"
"HTTP/1.1 200 OK
\r\n
"
"Connection: close
\r\n
"
"Date: %s
\r\n
"
"Date: %s
\r\n
"
"Server: FreeSWITCH-%s-mod_verto
\r\n
"
"Server: FreeSWITCH-%s-mod_verto
\r\n
"
"Content-Type: %s
\r\n
"
"Content-Type: %s
\r\n
"
...
@@ -1408,7 +1412,7 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v
...
@@ -1408,7 +1412,7 @@ static void http_static_handler(switch_http_request_t *request, verto_vhost_t *v
switch_file_close
(
fd
);
switch_file_close
(
fd
);
}
else
{
}
else
{
char
*
data
=
"HTTP/1.1 404 Not Found
\r\n
"
char
*
data
=
"HTTP/1.1 404 Not Found
\r\n
"
"Con
nection: close
\r\n\r\n
"
;
"Con
tent-Length: 0
\r\n\r\n
"
;
ws_raw_write
(
&
jsock
->
ws
,
data
,
strlen
(
data
));
ws_raw_write
(
&
jsock
->
ws
,
data
,
strlen
(
data
));
}
}
}
}
...
@@ -1420,6 +1424,9 @@ static void http_run(jsock_t *jsock)
...
@@ -1420,6 +1424,9 @@ static void http_run(jsock_t *jsock)
char
*
data
=
NULL
;
char
*
data
=
NULL
;
char
*
ext
;
char
*
ext
;
verto_vhost_t
*
vhost
;
verto_vhost_t
*
vhost
;
switch_bool_t
keepalive
;
new_req:
request
.
user_data
=
jsock
;
request
.
user_data
=
jsock
;
...
@@ -1433,11 +1440,13 @@ static void http_run(jsock_t *jsock)
...
@@ -1433,11 +1440,13 @@ static void http_run(jsock_t *jsock)
goto
err
;
goto
err
;
}
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"%s [%4"
SWITCH_SIZE_T_FMT
"] %s
\n
"
,
jsock
->
name
,
jsock
->
ws
.
datalen
,
request
.
uri
);
if
(
!
strncmp
(
request
.
method
,
"OPTIONS"
,
7
))
{
if
(
!
strncmp
(
request
.
method
,
"OPTIONS"
,
7
))
{
char
data
[
512
];
char
data
[
512
];
switch_snprintf
(
data
,
sizeof
(
data
),
switch_snprintf
(
data
,
sizeof
(
data
),
"HTTP/1.1 200 OK
\r\n
"
"HTTP/1.1 200 OK
\r\n
"
"Con
nection: close
\r\n
"
"Con
tent-Length: 0
\r\n
"
"Date: %s
\r\n
"
"Date: %s
\r\n
"
"Allow: HEAD,GET,POST,PUT,DELETE,PATCH,OPTIONS
\r\n
"
"Allow: HEAD,GET,POST,PUT,DELETE,PATCH,OPTIONS
\r\n
"
"Server: FreeSWITCH-%s-mod_verto
\r\n\r\n
"
,
"Server: FreeSWITCH-%s-mod_verto
\r\n\r\n
"
,
...
@@ -1456,7 +1465,7 @@ static void http_run(jsock_t *jsock)
...
@@ -1456,7 +1465,7 @@ static void http_run(jsock_t *jsock)
if
(
request
.
content_length
>
2
*
1024
*
1024
-
1
)
{
if
(
request
.
content_length
>
2
*
1024
*
1024
-
1
)
{
char
*
data
=
"HTTP/1.1 413 Request Entity Too Large
\r\n
"
char
*
data
=
"HTTP/1.1 413 Request Entity Too Large
\r\n
"
"Con
nection: close
\r\n\r\n
"
;
"Con
tent-Length: 0
\r\n\r\n
"
;
ws_raw_write
(
&
jsock
->
ws
,
data
,
strlen
(
data
));
ws_raw_write
(
&
jsock
->
ws
,
data
,
strlen
(
data
));
goto
done
;
goto
done
;
}
}
...
@@ -1515,7 +1524,7 @@ static void http_run(jsock_t *jsock)
...
@@ -1515,7 +1524,7 @@ static void http_run(jsock_t *jsock)
switch_snprintf
(
auth_buffer
,
sizeof
(
auth_buffer
),
switch_snprintf
(
auth_buffer
,
sizeof
(
auth_buffer
),
"HTTP/1.1 401 Authentication Required
\r\n
"
"HTTP/1.1 401 Authentication Required
\r\n
"
"WWW-Authenticate: Basic realm=
\"
%s
\"\r\n
"
"WWW-Authenticate: Basic realm=
\"
%s
\"\r\n
"
"Con
nection: close
\r\n\r\n
"
,
"Con
tent-Length: 0
\r\n\r\n
"
,
vhost
->
auth_realm
);
vhost
->
auth_realm
);
ws_raw_write
(
&
jsock
->
ws
,
auth_buffer
,
strlen
(
auth_buffer
));
ws_raw_write
(
&
jsock
->
ws
,
auth_buffer
,
strlen
(
auth_buffer
));
goto
done
;
goto
done
;
...
@@ -1550,7 +1559,7 @@ static void http_run(jsock_t *jsock)
...
@@ -1550,7 +1559,7 @@ static void http_run(jsock_t *jsock)
switch_snprintf
(
auth_buffer
,
sizeof
(
auth_buffer
),
switch_snprintf
(
auth_buffer
,
sizeof
(
auth_buffer
),
"HTTP/1.1 401 Authentication Required
\r\n
"
"HTTP/1.1 401 Authentication Required
\r\n
"
"WWW-Authenticate: Basic realm=
\"
%s
\"\r\n
"
"WWW-Authenticate: Basic realm=
\"
%s
\"\r\n
"
"Con
nection: close
\r\n\r\n
"
,
"Con
tent-Length: 0
\r\n\r\n
"
,
vhost
->
auth_realm
);
vhost
->
auth_realm
);
ws_raw_write
(
&
jsock
->
ws
,
auth_buffer
,
strlen
(
auth_buffer
));
ws_raw_write
(
&
jsock
->
ws
,
auth_buffer
,
strlen
(
auth_buffer
));
cJSON_Delete
(
params
);
cJSON_Delete
(
params
);
...
@@ -1602,17 +1611,58 @@ authed:
...
@@ -1602,17 +1611,58 @@ authed:
done:
done:
keepalive
=
request
.
keepalive
;
switch_http_free_request
(
&
request
);
switch_http_free_request
(
&
request
);
if
(
keepalive
)
{
wsh_t
*
wsh
=
&
jsock
->
ws
;
memset
(
&
request
,
0
,
sizeof
(
request
));
wsh
->
datalen
=
0
;
*
wsh
->
buffer
=
'\0'
;
while
(
jsock
->
profile
->
running
)
{
int
pflags
=
switch_wait_sock
(
jsock
->
client_socket
,
3000
,
SWITCH_POLL_READ
|
SWITCH_POLL_ERROR
|
SWITCH_POLL_HUP
);
if
(
jsock
->
drop
)
{
die
(
"%s Dropping Connection
\n
"
,
jsock
->
name
);
}
if
(
pflags
<
0
&&
(
errno
!=
EINTR
))
{
die
(
"%s POLL FAILED
\n
"
,
jsock
->
name
);
}
if
(
pflags
&
SWITCH_POLL_ERROR
)
{
die
(
"%s POLL ERROR
\n
"
,
jsock
->
name
);
}
if
(
pflags
&
SWITCH_POLL_HUP
)
{
die
(
"%s POLL HANGUP DETECTED
\n
"
,
jsock
->
name
);
}
if
(
pflags
&
SWITCH_POLL_INVALID
)
{
die
(
"%s POLL INVALID SOCKET
\n
"
,
jsock
->
name
);
}
if
(
pflags
&
SWITCH_POLL_READ
)
{
ssize_t
bytes
;
bytes
=
ws_raw_read
(
wsh
,
wsh
->
buffer
+
wsh
->
datalen
,
wsh
->
buflen
-
wsh
->
datalen
,
wsh
->
block
);
if
(
bytes
<
0
)
{
die
(
"BAD READ %"
SWITCH_SIZE_T_FMT
"
\n
"
,
bytes
);
break
;
}
wsh
->
datalen
+=
bytes
;
if
(
strstr
(
wsh
->
buffer
,
"
\r\n\r\n
"
)
||
strstr
(
wsh
->
buffer
,
"
\n\n
"
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"socket %s is going to handle a new request
\n
"
,
jsock
->
name
);
goto
new_req
;
}
}
else
{
break
;
}
}
}
return
;
return
;
request_err:
request_err:
switch_http_free_request
(
&
request
);
switch_http_free_request
(
&
request
);
err:
err:
data
=
"HTTP/1.1 500 Internal Server Error
\r\n
"
data
=
"HTTP/1.1 500 Internal Server Error
\r\n
"
"Con
nection: close
\r\n\r\n
"
;
"Con
tent-Length: 0
\r\n\r\n
"
;
ws_raw_write
(
&
jsock
->
ws
,
data
,
strlen
(
data
));
ws_raw_write
(
&
jsock
->
ws
,
data
,
strlen
(
data
));
error:
return
;
}
}
static
void
client_run
(
jsock_t
*
jsock
)
static
void
client_run
(
jsock_t
*
jsock
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论