Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Vincent Wei
web-display-server
Commits
5b59a5f7
Commit
5b59a5f7
authored
Nov 23, 2020
by
Vincent Wei
Browse files
use HTTP to download the PNG files
parent
7a38e7f1
Changes
6
Hide whitespace changes
Inline
Side-by-side
configure.ac
View file @
5b59a5f7
...
...
@@ -68,12 +68,13 @@ AC_CHECK_LIB([png], [png_sig_cmp], DEP_LIBS="$DEP_LIBS -lpng", [AC_MSG_ERROR([pn
if test "$openssl" = 'yes'; then
AC_CHECK_LIB([ssl], [SSL_library_init],
DEP_LIBS="$DEP_LIBS -lssl",
[AC_MSG_
ERROR
([ssl library missing])])
[AC_MSG_
WARN
([ssl library missing])])
AC_CHECK_LIB([crypto], [CRYPTO_num_locks],
DEP_LIBS="$DEP_LIBS -lcrypto",
[AC_MSG_
ERROR
([crypto library missing])])
[AC_MSG_
WARN
([crypto library missing])])
AC_DEFINE(HAVE_LIBSSL, 1,
[Define if libssl available])
DEP_LIBS="$DEP_LIBS -lssl -lcrypto"
fi
if test "$ac_cv_prog_gcc" = "yes"; then
...
...
src/unixsocket.c
View file @
5b59a5f7
...
...
@@ -30,6 +30,7 @@
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
...
...
@@ -343,6 +344,30 @@ void us_reset_dirty_pixels (USClient* us_client)
gettimeofday
(
&
us_client
->
last_flush_time
,
NULL
);
}
static
int
remove_png_files
(
USClient
*
us_client
)
{
const
char
*
dir_name
=
ws_get_config_prefix_path
();
DIR
*
dirp
;
char
file_name
[
32
];
char
full_path
[
1024
];
struct
dirent
*
dp
;
sprintf
(
file_name
,
"wds-%08d"
,
us_client
->
pid
);
dirp
=
opendir
(
dir_name
);
while
((
dp
=
readdir
(
dirp
))
!=
NULL
)
{
if
(
strncmp
(
dp
->
d_name
,
file_name
,
9
)
==
0
)
{
strcpy
(
full_path
,
dir_name
);
strcat
(
full_path
,
"/"
);
strcat
(
full_path
,
dp
->
d_name
);
unlink
(
full_path
);
}
}
closedir
(
dirp
);
return
0
;
}
int
us_client_cleanup
(
USClient
*
us_client
)
{
if
(
us_client
->
shadow_fb
)
{
...
...
@@ -354,6 +379,8 @@ int us_client_cleanup (USClient* us_client)
close
(
us_client
->
fd
);
us_client
->
fd
=
-
1
;
remove_png_files
(
us_client
);
return
0
;
}
src/wdserver.c
View file @
5b59a5f7
...
...
@@ -58,8 +58,8 @@ static struct option long_opts[] = {
{
"echo-mode"
,
no_argument
,
0
,
0
}
,
{
"max-frame-size"
,
required_argument
,
0
,
0
}
,
{
"origin"
,
required_argument
,
0
,
0
}
,
{
"p
ipein"
,
required_argument
,
0
,
0
}
,
{
"p
ipeout"
,
required_argument
,
0
,
0
}
,
{
"p
refix-path"
,
required_argument
,
0
,
0
}
,
{
"p
refix-url"
,
required_argument
,
0
,
0
}
,
#if HAVE_LIBSSL
{
"ssl-cert"
,
required_argument
,
0
,
0
}
,
{
"ssl-key"
,
required_argument
,
0
,
0
}
,
...
...
@@ -89,14 +89,11 @@ cmd_help (void)
" --addr=<addr> - Specify an IP address to bind to.
\n
"
" --echo-mode - Echo all received messages.
\n
"
" --max-frame-size=<bytes> - Maximum size of a websocket frame. This
\n
"
" includes received frames from the client
\n
"
" and messages through the named pipe.
\n
"
" includes received frames from the client.
\n
"
" --origin=<origin> - Ensure clients send the specified origin
\n
"
" header upon the WebSocket handshake.
\n
"
" --pipein=<path/file> - Creates a named pipe (FIFO) that reads
\n
"
" from on the given path/file.
\n
"
" --pipeout=<path/file> - Creates a named pipe (FIFO) that writes
\n
"
" to on the given path/file.
\n
"
" --prefix-path=<path> - The path prefix to save the PNG files of dirty screen.
\n
"
" --prefix-url=<url> - The URL prefix to fetch the PNG files for clients.
\n
"
" --ssl-cert=<cert.crt> - Path to SSL certificate.
\n
"
" --ssl-key=<priv.key> - Path to SSL private key.
\n
"
"
\n
"
...
...
@@ -291,8 +288,6 @@ parse_long_opt (const char *name, const char *oarg)
ws_set_config_origin
(
oarg
);
if
(
!
strcmp
(
"unixsocket"
,
name
))
ws_set_config_unixsocket
(
oarg
);
else
ws_set_config_unixsocket
(
USS_PATH
);
if
(
!
strcmp
(
"access-log"
,
name
))
ws_set_config_accesslog
(
oarg
);
#if HAVE_LIBSSL
...
...
@@ -301,6 +296,10 @@ parse_long_opt (const char *name, const char *oarg)
if
(
!
strcmp
(
"ssl-key"
,
name
))
ws_set_config_sslkey
(
oarg
);
#endif
if
(
!
strcmp
(
"prefix-path"
,
name
))
ws_set_config_prefix_path
(
oarg
);
if
(
!
strcmp
(
"prefix-url"
,
name
))
ws_set_config_prefix_url
(
oarg
);
}
/* Read the user's supplied command line options. */
...
...
@@ -394,6 +393,8 @@ main (int argc, char **argv)
ws_set_config_host
(
"0.0.0.0"
);
ws_set_config_port
(
"7788"
);
ws_set_config_unixsocket
(
USS_PATH
);
ws_set_config_prefix_path
(
DEF_PREFIX_PATH
);
ws_set_config_prefix_url
(
DEF_PREFIX_URL
);
retval
=
read_option_args
(
argc
,
argv
);
if
(
retval
>=
0
)
{
...
...
src/wdserver.h
View file @
5b59a5f7
...
...
@@ -28,7 +28,7 @@
#ifndef WD_SERVER_H_INCLUDED
#define WD_SERVER_H_INCLUDED
#define WD_VERSION "0.9"
#define WD_VERSION "0.9
.2
"
/* The pixel format */
#define USVFB_PSEUDO_RGB332 1
...
...
@@ -54,6 +54,9 @@ struct _vfb_info {
#define USC_PERM S_IRWXU
/* rwx for user only */
#define DEF_PREFIX_PATH "/tmp"
#define DEF_PREFIX_URL "http://localhost/tmp"
#define FT_VFBINFO 10
#define FT_PING 11
#define FT_PONG 12
...
...
@@ -82,5 +85,6 @@ struct _remote_event {
int
wd_set_null_stdio
(
void
);
int
wd_daemon
(
void
);
const
char
*
ws_get_config_prefix_path
(
void
);
#endif // for #ifndef WD_SERVER_H
src/websocket.c
View file @
5b59a5f7
...
...
@@ -2485,6 +2485,42 @@ handle_us_writes (USClient *us_client, WSClient* ws_client, WSServer* server)
LOG
((
"handle_us_writes: do nothing for client #%d.
\n
"
,
us_client
->
pid
));
}
#define PNG_VIA_HTTP 1
#if PNG_VIA_HTTP
static
int
ws_send_dirty_info
(
WSClient
*
ws_client
,
const
RECT
*
rc_dirty
,
const
char
*
png_url
)
{
int
len_url
=
strlen
(
png_url
);
int
len_buf
=
sizeof
(
uint32_t
)
*
4
+
len_url
;
int
retval
;
char
*
p
=
NULL
;
p
=
xmalloc
(
len_buf
);
if
(
p
==
NULL
)
{
retval
=
3
;
goto
error
;
}
char
*
ptr
;
ptr
=
p
;
ptr
+=
pack_uint32
(
ptr
,
(
uint32_t
)
rc_dirty
->
left
,
0
);
ptr
+=
pack_uint32
(
ptr
,
(
uint32_t
)
rc_dirty
->
top
,
0
);
ptr
+=
pack_uint32
(
ptr
,
(
uint32_t
)
rc_dirty
->
right
,
0
);
ptr
+=
pack_uint32
(
ptr
,
(
uint32_t
)
rc_dirty
->
bottom
,
0
);
memcpy
(
ptr
,
png_url
,
len_url
);
retval
=
ws_send_data
(
ws_client
,
WS_OPCODE_BIN
,
p
,
len_buf
);
error:
if
(
p
)
free
(
p
);
return
retval
;
}
#else
static
int
ws_send_dirty_pixels
(
WSClient
*
ws_client
,
const
RECT
*
rc_dirty
,
const
char
*
png_path
)
{
...
...
@@ -2542,6 +2578,8 @@ error:
return
retval
;
}
#endif
/* !PNG_VIA_HTTP */
/* Check and send dirty pixels to WebSocket client */
static
void
check_dirty_pixels
(
WSServer
*
server
)
...
...
@@ -2555,20 +2593,37 @@ check_dirty_pixels (WSServer* server)
us_client
=
ws_client
->
us_buddy
;
if
(
us_client
&&
us_check_dirty_pixels
(
us_client
))
{
int
retval
;
char
png_path
[
20
];
struct
timeval
tv
;
char
png_file
[
128
];
char
png_path
[
1024
];
//LOG (("check_dirty_pixels: UnixSocket Client #%d has dirty pixels (%d, %d, %d, %d) to send.\n", us_client->pid, us_client->rc_dirty.left, us_client->rc_dirty.top, us_client->rc_dirty.right, us_client->rc_dirty.bottom));
gettimeofday
(
&
tv
,
NULL
);
sprintf
(
png_file
,
"wds-%08d-%d-%d.png"
,
us_client
->
pid
,
(
int
)
tv
.
tv_sec
,
(
int
)
tv
.
tv_usec
);
strcpy
(
png_path
,
wsconfig
.
prefix_path
);
strcat
(
png_path
,
"/"
);
strcat
(
png_path
,
png_file
);
sprintf
(
png_path
,
"/tmp/wds-%d.png"
,
us_client
->
pid
);
if
((
retval
=
save_dirty_pixels_to_png
(
png_path
,
us_client
)))
{
printf
(
"check_dirty_pixels: failed when calling save_dirty_pixels_to_png: %d
\n
"
,
retval
);
continue
;
}
strcpy
(
png_path
,
wsconfig
.
prefix_url
);
strcat
(
png_path
,
"/"
);
strcat
(
png_path
,
png_file
);
#if PNG_VIA_HTTP
if
((
retval
=
ws_send_dirty_info
(
ws_client
,
&
us_client
->
rc_dirty
,
png_path
)))
{
printf
(
"check_dirty_pixels: failed when calling ws_send_dirty_info: %d
\n
"
,
retval
);
continue
;
}
#else
if
((
retval
=
ws_send_dirty_pixels
(
ws_client
,
&
us_client
->
rc_dirty
,
png_path
)))
{
printf
(
"check_dirty_pixels: failed when calling ws_send_dirty_pixels: %d
\n
"
,
retval
);
continue
;
}
#endif
us_reset_dirty_pixels
(
us_client
);
}
...
...
@@ -2591,7 +2646,7 @@ static void check_buddy_client (WSServer * server)
if
(
ws_client
->
status_buddy
==
WS_BUDDY_LAUNCHED
&&
(
time
(
NULL
)
-
ws_client
->
launched_time_buddy
)
>
10
)
{
LOG
((
"check_rfds_wfds: force to close client #%d because long ti
e
m no connection
\n
"
,
ws_fd
));
LOG
((
"check_rfds_wfds: force to close client #%d because long tim
e
no connection
\n
"
,
ws_fd
));
handle_tcp_close
(
ws_fd
,
ws_client
,
server
);
}
else
if
(
ws_client
->
status_buddy
==
WS_BUDDY_EXITED
)
{
...
...
@@ -2791,6 +2846,27 @@ ws_set_config_sslkey (const char *sslkey)
wsconfig
.
sslkey
=
sslkey
;
}
/* Set path prefix to save the PNG files. */
void
ws_set_config_prefix_path
(
const
char
*
prefix
)
{
wsconfig
.
prefix_path
=
prefix
;
}
/* Get path prefix to save the PNG files. */
const
char
*
ws_get_config_prefix_path
(
void
)
{
return
wsconfig
.
prefix_path
;
}
/* Set URL prefix to fetch the PNG files. */
void
ws_set_config_prefix_url
(
const
char
*
prefix
)
{
wsconfig
.
prefix_url
=
prefix
;
}
/* Create a new websocket server context. */
WSServer
*
ws_init
(
void
)
...
...
src/websocket.h
View file @
5b59a5f7
...
...
@@ -282,6 +282,8 @@ typedef struct WSConfig_
const
char
*
port
;
const
char
*
sslcert
;
const
char
*
sslkey
;
const
char
*
prefix_path
;
const
char
*
prefix_url
;
int
echomode
;
int
max_frm_size
;
int
use_ssl
;
...
...
@@ -322,6 +324,8 @@ void ws_set_config_unixsocket (const char *unixsocket);
void
ws_set_config_port
(
const
char
*
port
);
void
ws_set_config_sslcert
(
const
char
*
sslcert
);
void
ws_set_config_sslkey
(
const
char
*
sslkey
);
void
ws_set_config_prefix_path
(
const
char
*
prefix
);
void
ws_set_config_prefix_url
(
const
char
*
prefix
);
void
ws_start
(
WSServer
*
server
);
void
ws_stop
(
WSServer
*
server
);
WSServer
*
ws_init
(
void
);
...
...
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