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
ca932ee1
Commit
ca932ee1
authored
Jan 14, 2002
by
dscho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
view mode now toggleable
parent
1d514588
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
192 additions
and
5 deletions
+192
-5
1instance.c
1instance.c
+138
-0
x11vnc.c
x11vnc.c
+54
-5
No files found.
1instance.c
0 → 100644
View file @
ca932ee1
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
typedef
struct
{
char
*
filename
;
/* this file is the pipe (set by user) */
char
is_server
;
/* this is set by open_control_file */
int
fd
;
/* this is set by open_control_file */
}
single_instance_struct
;
/* returns fd, is_server is set to -1 if server, 0 if client */
int
open_control_file
(
single_instance_struct
*
str
)
{
struct
stat
buf
;
if
(
stat
(
str
->
filename
,
&
buf
))
{
mkfifo
(
str
->
filename
,
128
|
256
);
str
->
is_server
=-
1
;
str
->
fd
=
open
(
str
->
filename
,
O_NONBLOCK
|
O_RDONLY
);
}
else
{
str
->
fd
=
open
(
str
->
filename
,
O_NONBLOCK
|
O_WRONLY
);
if
(
errno
==
ENXIO
)
{
str
->
is_server
=-
1
;
str
->
fd
=
open
(
str
->
filename
,
O_NONBLOCK
|
O_RDONLY
);
}
else
str
->
is_server
=
0
;
}
return
(
str
->
fd
);
}
void
delete_control_file
(
single_instance_struct
*
str
)
{
remove
(
str
->
filename
);
}
void
close_control_file
(
single_instance_struct
*
str
)
{
close
(
str
->
fd
);
}
typedef
void
(
*
event_dispatcher
)(
char
*
message
);
int
get_next_message
(
char
*
buffer
,
int
len
,
single_instance_struct
*
str
,
int
usecs
)
{
struct
timeval
tv
;
fd_set
fdset
;
int
num_fds
;
FD_ZERO
(
&
fdset
);
FD_SET
(
str
->
fd
,
&
fdset
);
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
usecs
;
num_fds
=
select
(
str
->
fd
+
1
,
&
fdset
,
NULL
,
NULL
,
&
tv
);
if
(
num_fds
)
{
int
reallen
;
reallen
=
read
(
str
->
fd
,
buffer
,
len
);
if
(
reallen
==
0
)
{
close
(
str
->
fd
);
str
->
fd
=
open
(
str
->
filename
,
O_NONBLOCK
|
O_RDONLY
);
num_fds
--
;
}
buffer
[
reallen
]
=
0
;
#ifdef DEBUG_1INSTANCE
if
(
reallen
!=
0
)
fprintf
(
stderr
,
"message received: %s.
\n
"
,
buffer
);
#endif
}
return
(
num_fds
);
}
int
dispatch_event
(
single_instance_struct
*
str
,
event_dispatcher
dispatcher
,
int
usecs
)
{
char
buffer
[
1024
];
int
num_fds
;
if
((
num_fds
=
get_next_message
(
buffer
,
1024
,
str
,
usecs
))
&&
buffer
[
0
])
dispatcher
(
buffer
);
return
(
num_fds
);
}
int
loop_if_server
(
single_instance_struct
*
str
,
event_dispatcher
dispatcher
)
{
open_control_file
(
str
);
if
(
str
->
is_server
)
{
while
(
1
)
dispatch_event
(
str
,
dispatcher
,
50
);
}
return
(
str
->
fd
);
}
void
send_message
(
single_instance_struct
*
str
,
char
*
message
)
{
int
i
=
write
(
str
->
fd
,
message
,
strlen
(
message
));
#ifdef DEBUG_1INSTANCE
fprintf
(
stderr
,
"send: %s => %d(%d)
\n
"
,
message
,
i
,
strlen
(
message
));
#endif
}
#ifdef DEBUG_MAIN
#include <stdio.h>
#include <stdlib.h>
single_instance_struct
str1
=
{
"/tmp/1instance"
};
void
my_dispatcher
(
char
*
message
)
{
#ifdef DEBUG_1INSTANCE
fprintf
(
stderr
,
"Message arrived: %s.
\n
"
,
message
);
#endif
if
(
!
strcmp
(
message
,
"quit"
))
{
delete_control_file
(
str1
);
exit
(
0
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
loop_if_server
(
str1
,
my_dispatcher
);
for
(
i
=
1
;
i
<
argc
;
i
++
)
send_event
(
str1
,
argv
[
i
]);
return
(
0
);
}
#endif
x11vnc.c
View file @
ca932ee1
/* This file is part of LibVNCServer.
/* This file
(x11vnc.c)
is part of LibVNCServer.
It is a small clone of x0rfbserver by HexoNet, demonstrating the
It is a small clone of x0rfbserver by HexoNet, demonstrating the
capabilities of LibVNCServer.
capabilities of LibVNCServer.
*/
*/
...
@@ -65,6 +65,10 @@ void newClient(rfbClientPtr cl)
...
@@ -65,6 +65,10 @@ void newClient(rfbClientPtr cl)
{
{
if
(
disconnectAfterFirstClient
)
if
(
disconnectAfterFirstClient
)
cl
->
clientGoneHook
=
clientGone
;
cl
->
clientGoneHook
=
clientGone
;
if
(
viewOnly
)
cl
->
clientData
=
(
void
*
)
-
1
;
else
cl
->
clientData
=
(
void
*
)
0
;
}
}
#define LEFTSHIFT 1
#define LEFTSHIFT 1
...
@@ -95,6 +99,8 @@ void tweakModifiers(char mod,Bool down)
...
@@ -95,6 +99,8 @@ void tweakModifiers(char mod,Bool down)
void
keyboard
(
Bool
down
,
KeySym
keySym
,
rfbClientPtr
cl
)
void
keyboard
(
Bool
down
,
KeySym
keySym
,
rfbClientPtr
cl
)
{
{
if
(((
int
)
cl
->
clientData
)
==-
1
)
return
;
/* viewOnly */
#define ADJUSTMOD(sym,state) \
#define ADJUSTMOD(sym,state) \
if(keySym==sym) { if(down) ModifierState|=state; else ModifierState&=~state; }
if(keySym==sym) { if(down) ModifierState|=state; else ModifierState&=~state; }
...
@@ -132,6 +138,8 @@ void mouse(int buttonMask,int x,int y,rfbClientPtr cl)
...
@@ -132,6 +138,8 @@ void mouse(int buttonMask,int x,int y,rfbClientPtr cl)
{
{
int
i
=
0
;
int
i
=
0
;
if
(((
int
)
cl
->
clientData
)
==-
1
)
return
;
/* viewOnly */
XTestFakeMotionEvent
(
dpy
,
0
,
x
,
y
,
CurrentTime
);
XTestFakeMotionEvent
(
dpy
,
0
,
x
,
y
,
CurrentTime
);
while
(
i
<
5
)
{
while
(
i
<
5
)
{
if
((
oldButtonMask
&
(
1
<<
i
))
!=
(
buttonMask
&
(
1
<<
i
)))
if
((
oldButtonMask
&
(
1
<<
i
))
!=
(
buttonMask
&
(
1
<<
i
)))
...
@@ -271,6 +279,12 @@ void probeScreen(rfbScreenInfoPtr s,int xscreen)
...
@@ -271,6 +279,12 @@ void probeScreen(rfbScreenInfoPtr s,int xscreen)
}
}
}
}
#define LOCAL_CONTROL
#ifdef LOCAL_CONTROL
#include "1instance.c"
#endif
/* the main program */
/* the main program */
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
...
@@ -284,7 +298,25 @@ int main(int argc,char** argv)
...
@@ -284,7 +298,25 @@ int main(int argc,char** argv)
int
maxMsecsToConnect
=
5000
;
/* a maximum of 5 seconds to connect */
int
maxMsecsToConnect
=
5000
;
/* a maximum of 5 seconds to connect */
int
updateCounter
;
/* about every 50 ms a screen update should be made. */
int
updateCounter
;
/* about every 50 ms a screen update should be made. */
#ifdef LOCAL_CONTROL
char
message
[
1024
];
single_instance_struct
single_instance
=
{
"/tmp/x11vnc_control"
};
open_control_file
(
&
single_instance
);
#endif
for
(
i
=
argc
-
1
;
i
>
0
;
i
--
)
for
(
i
=
argc
-
1
;
i
>
0
;
i
--
)
#ifdef LOCAL_CONTROL
if
(
i
<
argc
-
1
&&
!
strcmp
(
argv
[
i
],
"-toggleviewonly"
))
{
sprintf
(
message
,
"t%s"
,
argv
[
i
+
1
]);
send_message
(
&
single_instance
,
message
);
exit
(
0
);
}
else
if
(
!
strcmp
(
argv
[
i
],
"-listclients"
))
{
fprintf
(
stderr
,
"list clients
\n
"
);
send_message
(
&
single_instance
,
"l"
);
exit
(
0
);
}
else
#endif
if
(
i
<
argc
-
1
&&
strcmp
(
argv
[
i
],
"-display"
)
==
0
)
{
if
(
i
<
argc
-
1
&&
strcmp
(
argv
[
i
],
"-display"
)
==
0
)
{
fprintf
(
stderr
,
"Using display %s
\n
"
,
argv
[
i
+
1
]);
fprintf
(
stderr
,
"Using display %s
\n
"
,
argv
[
i
+
1
]);
dpy
=
XOpenDisplay
(
argv
[
i
+
1
]);
dpy
=
XOpenDisplay
(
argv
[
i
+
1
]);
...
@@ -387,10 +419,9 @@ int main(int argc,char** argv)
...
@@ -387,10 +419,9 @@ int main(int argc,char** argv)
screen
->
cursor
=
0
;
screen
->
cursor
=
0
;
screen
->
newClientHook
=
newClient
;
screen
->
newClientHook
=
newClient
;
if
(
!
viewOnly
)
{
screen
->
kbdAddEvent
=
keyboard
;
screen
->
kbdAddEvent
=
keyboard
;
screen
->
ptrAddEvent
=
mouse
;
screen
->
ptrAddEvent
=
mouse
;
}
if
(
sharedMode
)
{
if
(
sharedMode
)
{
screen
->
rfbAlwaysShared
=
TRUE
;
screen
->
rfbAlwaysShared
=
TRUE
;
}
}
...
@@ -413,6 +444,24 @@ int main(int argc,char** argv)
...
@@ -413,6 +444,24 @@ int main(int argc,char** argv)
}
}
}
}
#ifdef LOCAL_CONTROL
if
(
get_next_message
(
message
,
1024
,
&
single_instance
,
50
))
{
if
(
message
[
0
]
==
'l'
&&
message
[
1
]
==
0
)
{
rfbClientPtr
cl
;
int
i
;
for
(
i
=
0
,
cl
=
screen
->
rfbClientHead
;
cl
;
cl
=
cl
->
next
,
i
++
)
fprintf
(
stderr
,
"%02d: %s
\n
"
,
i
,
cl
->
host
);
}
else
if
(
message
[
0
]
==
't'
)
{
rfbClientPtr
cl
;
for
(
cl
=
screen
->
rfbClientHead
;
cl
;
cl
=
cl
->
next
)
if
(
!
strcmp
(
message
+
1
,
cl
->
host
))
{
cl
->
clientData
=
(
cl
->
clientData
==
0
)
?-
1
:
0
;
break
;
}
}
}
#endif
rfbProcessEvents
(
screen
,
-
1
);
rfbProcessEvents
(
screen
,
-
1
);
if
(
dontTile
)
{
if
(
dontTile
)
{
...
...
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