Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
ff9571e1
提交
ff9571e1
authored
4月 02, 2013
作者:
Jeff Lenk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sofia windows compiler warnings
上级
ed782ed1
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
65 行增加
和
39 行删除
+65
-39
tport_type_ws.c
libs/sofia-sip/libsofia-sip-ua/tport/tport_type_ws.c
+6
-0
ws.c
libs/sofia-sip/libsofia-sip-ua/tport/ws.c
+40
-26
ws.h
libs/sofia-sip/libsofia-sip-ua/tport/ws.h
+19
-13
没有找到文件。
libs/sofia-sip/libsofia-sip-ua/tport/tport_type_ws.c
浏览文件 @
ff9571e1
...
...
@@ -60,6 +60,12 @@
static
char
const
__func__
[]
=
"tport_type_ws"
;
#endif
#if HAVE_WIN32
#include <io.h>
#define access(_filename, _mode) _access(_filename, _mode)
#define R_OK (04)
#endif
/* ---------------------------------------------------------------------- */
/* WS */
...
...
libs/sofia-sip/libsofia-sip-ua/tport/ws.c
浏览文件 @
ff9571e1
...
...
@@ -120,22 +120,24 @@ static int cheezy_get_var(char *data, char *name, char *buf, size_t buflen)
if
(
p
!=
(
char
*
)
1
&&
*
p
!=
'\0'
)
{
char
*
v
,
*
e
;
char
*
v
,
*
e
=
0
;
if
((
v
=
strchr
(
p
,
':'
)))
{
v
=
strchr
(
p
,
':'
);
if
(
v
)
{
v
++
;
while
(
v
&&
*
v
==
' '
)
{
v
++
;
}
if
(
v
)
{
if
(
!
(
e
=
strchr
(
v
,
'\r'
)))
{
e
=
strchr
(
v
,
'\r'
);
if
(
!
e
)
{
e
=
strchr
(
v
,
'\n'
);
}
}
if
(
v
&&
e
)
{
int
cplen
;
in
t
len
=
e
-
v
;
size_
t
len
=
e
-
v
;
if
(
len
>
buflen
-
1
)
{
cplen
=
buflen
-
1
;
...
...
@@ -159,6 +161,9 @@ static int b64encode(unsigned char *in, size_t ilen, unsigned char *out, size_t
size_t
x
=
0
;
unsigned
int
b
=
0
,
l
=
0
;
if
(
olen
)
{
}
for
(
x
=
0
;
x
<
ilen
;
x
++
)
{
b
=
(
b
<<
8
)
+
in
[
x
];
l
+=
8
;
...
...
@@ -218,8 +223,8 @@ int ws_handshake(wsh_t *wsh)
unsigned
char
output
[
SHA1_HASH_SIZE
]
=
""
;
char
b64
[
256
]
=
""
;
char
respond
[
512
]
=
""
;
ssize_t
bytes
;
char
*
p
,
*
e
;
i
ssize_t
bytes
;
char
*
p
,
*
e
=
0
;
if
(
wsh
->
sock
==
ws_sock_invalid
)
{
return
-
3
;
...
...
@@ -240,7 +245,8 @@ int ws_handshake(wsh_t *wsh)
p
=
wsh
->
buffer
+
4
;
if
(
!
(
e
=
strchr
(
p
,
' '
)))
{
e
=
strchr
(
p
,
' '
);
if
(
!
e
)
{
goto
err
;
}
...
...
@@ -289,15 +295,19 @@ int ws_handshake(wsh_t *wsh)
}
ssize_t
ws_raw_read
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
)
i
ssize_t
ws_raw_read
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
)
{
ssize_t
r
;
i
ssize_t
r
;
int
x
=
0
;
if
(
wsh
->
ssl
)
{
do
{
r
=
SSL_read
(
wsh
->
ssl
,
data
,
bytes
);
#ifndef _MSC_VER
if
(
x
++
)
usleep
(
10000
);
#else
if
(
x
++
)
Sleep
(
10
);
#endif
}
while
(
r
==
-
1
&&
SSL_get_error
(
wsh
->
ssl
,
r
)
==
SSL_ERROR_WANT_READ
&&
x
<
100
);
return
r
;
...
...
@@ -305,7 +315,11 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
do
{
r
=
recv
(
wsh
->
sock
,
data
,
bytes
,
0
);
if
(
x
++
)
usleep
(
10000
);
#ifndef _MSC_VER
if
(
x
++
)
usleep
(
10000
);
#else
if
(
x
++
)
Sleep
(
10
);
#endif
}
while
(
r
==
-
1
&&
(
errno
==
EAGAIN
||
errno
==
EINTR
)
&&
x
<
100
);
//if (r<0) {
...
...
@@ -315,7 +329,7 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
return
r
;
}
ssize_t
ws_raw_write
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
)
i
ssize_t
ws_raw_write
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
)
{
size_t
r
;
...
...
@@ -388,7 +402,7 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int c
return
0
;
}
ssize_t
ws_close
(
wsh_t
*
wsh
,
int16_t
reason
)
i
ssize_t
ws_close
(
wsh_t
*
wsh
,
int16_t
reason
)
{
if
(
wsh
->
down
)
{
...
...
@@ -437,10 +451,10 @@ ssize_t ws_close(wsh_t *wsh, int16_t reason)
}
ssize_t
ws_read_frame
(
wsh_t
*
wsh
,
ws_opcode_t
*
oc
,
uint8_t
**
data
)
i
ssize_t
ws_read_frame
(
wsh_t
*
wsh
,
ws_opcode_t
*
oc
,
uint8_t
**
data
)
{
ssize_t
need
=
2
;
i
ssize_t
need
=
2
;
char
*
maskp
;
again:
...
...
@@ -509,7 +523,7 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
u64
=
(
uint64_t
*
)
wsh
->
payload
;
wsh
->
payload
+=
8
;
wsh
->
plen
=
ntohl
(
*
u64
);
wsh
->
plen
=
ntohl
(
(
u_long
)
*
u64
);
}
else
if
(
wsh
->
plen
==
126
)
{
uint16_t
*
u16
;
...
...
@@ -534,7 +548,7 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
need
=
(
wsh
->
plen
-
(
wsh
->
datalen
-
need
));
if
((
need
+
wsh
->
datalen
)
>
wsh
->
buflen
)
{
if
((
need
+
wsh
->
datalen
)
>
(
issize_t
)
wsh
->
buflen
)
{
/* too big - Ain't nobody got time fo' dat */
*
oc
=
WSOC_CLOSE
;
return
ws_close
(
wsh
,
WS_DATA_TOO_BIG
);
...
...
@@ -543,7 +557,7 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
wsh
->
rplen
=
wsh
->
plen
-
need
;
while
(
need
)
{
ssize_t
r
=
ws_raw_read
(
wsh
,
wsh
->
payload
+
wsh
->
rplen
,
need
);
i
ssize_t
r
=
ws_raw_read
(
wsh
,
wsh
->
payload
+
wsh
->
rplen
,
need
);
if
(
r
<
1
)
{
/* invalid read - protocol err .. */
...
...
@@ -557,7 +571,7 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
}
if
(
mask
&&
maskp
)
{
uint32
_t
i
;
issize
_t
i
;
for
(
i
=
0
;
i
<
wsh
->
datalen
;
i
++
)
{
wsh
->
payload
[
i
]
^=
maskp
[
i
%
4
];
...
...
@@ -590,7 +604,7 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
}
}
ssize_t
ws_feed_buf
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
)
i
ssize_t
ws_feed_buf
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
)
{
if
(
bytes
+
wsh
->
wdatalen
>
wsh
->
buflen
)
{
...
...
@@ -611,9 +625,9 @@ ssize_t ws_feed_buf(wsh_t *wsh, void *data, size_t bytes)
return
bytes
;
}
ssize_t
ws_send_buf
(
wsh_t
*
wsh
,
ws_opcode_t
oc
)
i
ssize_t
ws_send_buf
(
wsh_t
*
wsh
,
ws_opcode_t
oc
)
{
ssize_t
r
=
0
;
i
ssize_t
r
=
0
;
if
(
!
wsh
->
wdatalen
)
{
return
-
1
;
...
...
@@ -627,7 +641,7 @@ ssize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc)
}
ssize_t
ws_write_frame
(
wsh_t
*
wsh
,
ws_opcode_t
oc
,
void
*
data
,
size_t
bytes
)
i
ssize_t
ws_write_frame
(
wsh_t
*
wsh
,
ws_opcode_t
oc
,
void
*
data
,
size_t
bytes
)
{
uint8_t
hdr
[
14
]
=
{
0
};
size_t
hlen
=
2
;
...
...
@@ -638,10 +652,10 @@ ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes)
//printf("WRITE[%ld]-----------------------------:\n[%s]\n-----------------------------------\n", bytes, (char *) data);
hdr
[
0
]
=
oc
|
0x80
;
hdr
[
0
]
=
(
uint8_t
)(
oc
|
0x80
)
;
if
(
bytes
<
126
)
{
hdr
[
1
]
=
bytes
;
hdr
[
1
]
=
(
uint8_t
)
bytes
;
}
else
if
(
bytes
<
0x10000
)
{
uint16_t
*
u16
;
...
...
@@ -661,11 +675,11 @@ ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes)
*
u64
=
htonl
(
bytes
);
}
if
(
ws_raw_write
(
wsh
,
(
void
*
)
&
hdr
[
0
],
hlen
)
!=
hlen
)
{
if
(
ws_raw_write
(
wsh
,
(
void
*
)
&
hdr
[
0
],
hlen
)
!=
(
issize_t
)
hlen
)
{
return
-
1
;
}
if
(
ws_raw_write
(
wsh
,
data
,
bytes
)
!=
bytes
)
{
if
(
ws_raw_write
(
wsh
,
data
,
bytes
)
!=
(
issize_t
)
bytes
)
{
return
-
2
;
}
...
...
libs/sofia-sip/libsofia-sip-ua/tport/ws.h
浏览文件 @
ff9571e1
...
...
@@ -8,19 +8,24 @@
#define B64BUFFLEN 1024
#include <sys/types.h>
#ifndef _MSC_VER
#include <arpa/inet.h>
#include <sys/wait.h>
#include <sys/socket.h>
#else
#pragma warning(disable:4996)
#endif
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <assert.h>
#include <errno.h>
//#include "sha1.h"
#include <openssl/ssl.h>
#include <sofia-sip/su_types.h>
struct
globals_s
{
...
...
@@ -57,11 +62,11 @@ typedef struct wsh_s {
char
*
buffer
;
char
*
wbuffer
;
size_t
buflen
;
ssize_t
datalen
;
ssize_t
wdatalen
;
i
ssize_t
datalen
;
i
ssize_t
wdatalen
;
char
*
payload
;
ssize_t
plen
;
ssize_t
rplen
;
i
ssize_t
plen
;
i
ssize_t
rplen
;
SSL
*
ssl
;
int
handshake
;
uint8_t
down
;
...
...
@@ -70,25 +75,26 @@ typedef struct wsh_s {
unsigned
:
0
;
}
wsh_t
;
ssize_t
ws_send_buf
(
wsh_t
*
wsh
,
ws_opcode_t
oc
);
ssize_t
ws_feed_buf
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
);
i
ssize_t
ws_send_buf
(
wsh_t
*
wsh
,
ws_opcode_t
oc
);
i
ssize_t
ws_feed_buf
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
);
ssize_t
ws_raw_read
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
);
ssize_t
ws_raw_write
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
);
ssize_t
ws_read_frame
(
wsh_t
*
wsh
,
ws_opcode_t
*
oc
,
uint8_t
**
data
);
ssize_t
ws_write_frame
(
wsh_t
*
wsh
,
ws_opcode_t
oc
,
void
*
data
,
size_t
bytes
);
i
ssize_t
ws_raw_read
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
);
i
ssize_t
ws_raw_write
(
wsh_t
*
wsh
,
void
*
data
,
size_t
bytes
);
i
ssize_t
ws_read_frame
(
wsh_t
*
wsh
,
ws_opcode_t
*
oc
,
uint8_t
**
data
);
i
ssize_t
ws_write_frame
(
wsh_t
*
wsh
,
ws_opcode_t
oc
,
void
*
data
,
size_t
bytes
);
int
ws_init
(
wsh_t
*
wsh
,
ws_socket_t
sock
,
size_t
buflen
,
SSL_CTX
*
ssl_ctx
,
int
close_sock
);
ssize_t
ws_close
(
wsh_t
*
wsh
,
int16_t
reason
);
i
ssize_t
ws_close
(
wsh_t
*
wsh
,
int16_t
reason
);
void
init_ssl
(
void
);
void
deinit_ssl
(
void
);
#ifndef _MSC_VER
static
inline
uint64_t
get_unaligned_uint64
(
const
void
*
p
)
{
const
struct
{
uint64_t
d
;
}
__attribute__
((
packed
))
*
pp
=
p
;
return
pp
->
d
;
}
#endif
#endif
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论