Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
libvncserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
libvncserver
Commits
2c45d08d
Commit
2c45d08d
authored
Sep 01, 2011
by
Gernot Tenchio
Committed by
Joel Martin
Sep 08, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
websocket: Use a single buffer for both, encoding and decoding
parent
3eec9765
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
16 deletions
+15
-16
websockets.c
libvncserver/websockets.c
+15
-16
No files found.
libvncserver/websockets.c
View file @
2c45d08d
...
...
@@ -71,8 +71,7 @@ typedef int (*wsEncodeFunc)(rfbClientPtr cl, const char *src, int len, char **ds
typedef
int
(
*
wsDecodeFunc
)(
rfbClientPtr
cl
,
char
*
dst
,
int
len
);
typedef
struct
ws_ctx_s
{
char
encodeBuf
[
B64LEN
(
UPDATE_BUF_SIZE
)
+
WSHLENMAX
];
/* base64 + maximum frame header length */
char
decodeBuf
[
8192
];
/* TODO: what makes sense? */
char
codeBuf
[
B64LEN
(
UPDATE_BUF_SIZE
)
+
WSHLENMAX
];
/* base64 + maximum frame header length */
char
readbuf
[
8192
];
int
readbufstart
;
int
readbuflen
;
...
...
@@ -172,7 +171,7 @@ webSocketsGenSha1Key(char * target, int size, char *key)
int
len
;
SHA1Context
sha
;
uint8_t
digest
[
SHA1HashSize
];
if
(
size
<
B64LEN
(
SHA1HashSize
)
+
1
)
{
rfbErr
(
"webSocketsGenSha1Key: not enough space in target
\n
"
);
target
[
0
]
=
'\0'
;
...
...
@@ -490,15 +489,15 @@ webSocketsEncodeHixie(rfbClientPtr cl, const char *src, int len, char **dst)
int
sz
=
0
;
ws_ctx_t
*
wsctx
=
(
ws_ctx_t
*
)
cl
->
wsctx
;
wsctx
->
en
codeBuf
[
sz
++
]
=
'\x00'
;
len
=
__b64_ntop
((
unsigned
char
*
)
src
,
len
,
wsctx
->
encodeBuf
+
sz
,
sizeof
(
wsctx
->
en
codeBuf
)
-
(
sz
+
1
));
wsctx
->
codeBuf
[
sz
++
]
=
'\x00'
;
len
=
__b64_ntop
((
unsigned
char
*
)
src
,
len
,
wsctx
->
codeBuf
+
sz
,
sizeof
(
wsctx
->
codeBuf
)
-
(
sz
+
1
));
if
(
len
<
0
)
{
return
len
;
}
sz
+=
len
;
wsctx
->
en
codeBuf
[
sz
++
]
=
'\xff'
;
*
dst
=
wsctx
->
en
codeBuf
;
wsctx
->
codeBuf
[
sz
++
]
=
'\xff'
;
*
dst
=
wsctx
->
codeBuf
;
return
sz
;
}
...
...
@@ -536,7 +535,7 @@ webSocketsDecodeHixie(rfbClientPtr cl, char *dst, int len)
char
*
buf
,
*
end
=
NULL
;
ws_ctx_t
*
wsctx
=
(
ws_ctx_t
*
)
cl
->
wsctx
;
buf
=
wsctx
->
de
codeBuf
;
buf
=
wsctx
->
codeBuf
;
n
=
ws_peek
(
cl
,
buf
,
len
*
2
+
2
);
...
...
@@ -653,8 +652,8 @@ webSocketsDecodeHybi(rfbClientPtr cl, char *dst, int len)
goto
spor
;
}
buf
=
wsctx
->
de
codeBuf
;
header
=
(
ws_header_t
*
)
wsctx
->
de
codeBuf
;
buf
=
wsctx
->
codeBuf
;
header
=
(
ws_header_t
*
)
wsctx
->
codeBuf
;
if
(
-
1
==
(
ret
=
ws_peek
(
cl
,
buf
,
B64LEN
(
len
)
+
WSHLENMAX
)))
{
rfbErr
(
"%s: peek; %m
\n
"
,
__func__
);
...
...
@@ -730,11 +729,11 @@ webSocketsDecodeHybi(rfbClientPtr cl, char *dst, int len)
errno
=
ECONNRESET
;
break
;
case
WS_OPCODE_TEXT_FRAME
:
if
(
-
1
==
(
flength
=
__b64_pton
(
payload
,
(
unsigned
char
*
)
wsctx
->
decodeBuf
,
sizeof
(
wsctx
->
de
codeBuf
))))
{
if
(
-
1
==
(
flength
=
__b64_pton
(
payload
,
(
unsigned
char
*
)
wsctx
->
codeBuf
,
sizeof
(
wsctx
->
codeBuf
))))
{
rfbErr
(
"%s: Base64 decode error; %m
\n
"
,
__func__
);
break
;
}
payload
=
wsctx
->
de
codeBuf
;
payload
=
wsctx
->
codeBuf
;
/* fall through */
case
WS_OPCODE_BINARY_FRAME
:
if
(
flength
>
len
)
{
...
...
@@ -778,7 +777,7 @@ webSocketsEncodeHybi(rfbClientPtr cl, const char *src, int len, char **dst)
return
0
;
}
header
=
(
ws_header_t
*
)
wsctx
->
en
codeBuf
;
header
=
(
ws_header_t
*
)
wsctx
->
codeBuf
;
if
(
wsctx
->
base64
)
{
opcode
=
WS_OPCODE_TEXT_FRAME
;
...
...
@@ -803,7 +802,7 @@ webSocketsEncodeHybi(rfbClientPtr cl, const char *src, int len, char **dst)
}
if
(
wsctx
->
base64
)
{
if
(
-
1
==
(
ret
=
__b64_ntop
((
unsigned
char
*
)
src
,
len
,
wsctx
->
encodeBuf
+
sz
,
sizeof
(
wsctx
->
en
codeBuf
)
-
sz
)))
{
if
(
-
1
==
(
ret
=
__b64_ntop
((
unsigned
char
*
)
src
,
len
,
wsctx
->
codeBuf
+
sz
,
sizeof
(
wsctx
->
codeBuf
)
-
sz
)))
{
rfbErr
(
"%s: Base 64 encode failed
\n
"
,
__func__
);
}
else
{
if
(
ret
!=
blen
)
...
...
@@ -811,11 +810,11 @@ webSocketsEncodeHybi(rfbClientPtr cl, const char *src, int len, char **dst)
ret
+=
sz
;
}
}
else
{
memcpy
(
wsctx
->
en
codeBuf
+
sz
,
src
,
len
);
memcpy
(
wsctx
->
codeBuf
+
sz
,
src
,
len
);
ret
=
sz
+
len
;
}
*
dst
=
wsctx
->
en
codeBuf
;
*
dst
=
wsctx
->
codeBuf
;
return
ret
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment