LibVNCServer/LibVNCClient
cargs.c
Go to the documentation of this file.
1 /*
2  * This parses the command line arguments. It was separated from main.c by
3  * Justin Dearing <jdeari01@longisland.poly.edu>.
4  */
5 
6 /*
7  * LibVNCServer (C) 2001 Johannes E. Schindelin <Johannes.Schindelin@gmx.de>
8  * Original OSXvnc (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
9  * Original Xvnc (C) 1999 AT&T Laboratories Cambridge.
10  * All Rights Reserved.
11  *
12  * see GPL (latest version) for full details
13  */
14 
15 #include <rfb/rfb.h>
16 
17 extern int rfbStringToAddr(char *str, in_addr_t *iface);
18 
19 void
20 rfbUsage(void)
21 {
22  rfbProtocolExtension* extension;
23 
24  fprintf(stderr, "-rfbport port TCP port for RFB protocol\n");
25 #ifdef LIBVNCSERVER_IPv6
26  fprintf(stderr, "-rfbportv6 port TCP6 port for RFB protocol\n");
27 #endif
28  fprintf(stderr, "-rfbwait time max time in ms to wait for RFB client\n");
29  fprintf(stderr, "-rfbauth passwd-file use authentication on RFB protocol\n"
30  " (use 'storepasswd' to create a password file)\n");
31  fprintf(stderr, "-rfbversion 3.x Set the version of the RFB we choose to advertise\n");
32  fprintf(stderr, "-permitfiletransfer permit file transfer support\n");
33  fprintf(stderr, "-passwd plain-password use authentication \n"
34  " (use plain-password as password, USE AT YOUR RISK)\n");
35  fprintf(stderr, "-deferupdate time time in ms to defer updates "
36  "(default 40)\n");
37  fprintf(stderr, "-deferptrupdate time time in ms to defer pointer updates"
38  " (default none)\n");
39  fprintf(stderr, "-desktop name VNC desktop name (default \"LibVNCServer\")\n");
40  fprintf(stderr, "-alwaysshared always treat new clients as shared\n");
41  fprintf(stderr, "-nevershared never treat new clients as shared\n");
42  fprintf(stderr, "-dontdisconnect don't disconnect existing clients when a "
43  "new non-shared\n"
44  " connection comes in (refuse new connection "
45  "instead)\n");
46 #ifdef LIBVNCSERVER_WITH_WEBSOCKETS
47  fprintf(stderr, "-sslkeyfile path set path to private key file for encrypted WebSockets connections\n");
48  fprintf(stderr, "-sslcertfile path set path to certificate file for encrypted WebSockets connections\n");
49 #endif
50  fprintf(stderr, "-httpdir dir-path enable http server using dir-path home\n");
51  fprintf(stderr, "-httpport portnum use portnum for http connection\n");
52 #ifdef LIBVNCSERVER_IPv6
53  fprintf(stderr, "-httpportv6 portnum use portnum for IPv6 http connection\n");
54 #endif
55  fprintf(stderr, "-enablehttpproxy enable http proxy support\n");
56  fprintf(stderr, "-progressive height enable progressive updating for slow links\n");
57  fprintf(stderr, "-listen ipaddr listen for connections only on network interface with\n");
58  fprintf(stderr, " addr ipaddr. '-listen localhost' and hostname work too.\n");
59 #ifdef LIBVNCSERVER_IPv6
60  fprintf(stderr, "-listenv6 ipv6addr listen for IPv6 connections only on network interface with\n");
61  fprintf(stderr, " addr ipv6addr. '-listen localhost' and hostname work too.\n");
62 #endif
63 
64  for(extension=rfbGetExtensionIterator();extension;extension=extension->next)
65  if(extension->usage)
66  extension->usage();
68 }
69 
70 /* purges COUNT arguments from ARGV at POSITION and decrements ARGC.
71  POSITION points to the first non purged argument afterwards. */
72 void rfbPurgeArguments(int* argc,int* position,int count,char *argv[])
73 {
74  int amount=(*argc)-(*position)-count;
75  if(amount)
76  memmove(argv+(*position),argv+(*position)+count,sizeof(char*)*amount);
77  (*argc)-=count;
78 }
79 
80 rfbBool
81 rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[])
82 {
83  int i,i1;
84 
85  if(!argc) return TRUE;
86 
87  for (i = i1 = 1; i < *argc;) {
88  if (strcmp(argv[i], "-help") == 0) {
89  rfbUsage();
90  return FALSE;
91  } else if (strcmp(argv[i], "-rfbport") == 0) { /* -rfbport port */
92  if (i + 1 >= *argc) {
93  rfbUsage();
94  return FALSE;
95  }
96  rfbScreen->port = atoi(argv[++i]);
97 #ifdef LIBVNCSERVER_IPv6
98  } else if (strcmp(argv[i], "-rfbportv6") == 0) { /* -rfbportv6 port */
99  if (i + 1 >= *argc) {
100  rfbUsage();
101  return FALSE;
102  }
103  rfbScreen->ipv6port = atoi(argv[++i]);
104 #endif
105  } else if (strcmp(argv[i], "-rfbwait") == 0) { /* -rfbwait ms */
106  if (i + 1 >= *argc) {
107  rfbUsage();
108  return FALSE;
109  }
110  rfbScreen->maxClientWait = atoi(argv[++i]);
111  } else if (strcmp(argv[i], "-rfbauth") == 0) { /* -rfbauth passwd-file */
112  if (i + 1 >= *argc) {
113  rfbUsage();
114  return FALSE;
115  }
116  rfbScreen->authPasswdData = argv[++i];
117 
118  } else if (strcmp(argv[i], "-permitfiletransfer") == 0) { /* -permitfiletransfer */
119  rfbScreen->permitFileTransfer = TRUE;
120  } else if (strcmp(argv[i], "-rfbversion") == 0) { /* -rfbversion 3.6 */
121  if (i + 1 >= *argc) {
122  rfbUsage();
123  return FALSE;
124  }
125  sscanf(argv[++i],"%d.%d", &rfbScreen->protocolMajorVersion, &rfbScreen->protocolMinorVersion);
126  } else if (strcmp(argv[i], "-passwd") == 0) { /* -passwd password */
127  char **passwds = malloc(sizeof(char**)*2);
128  if (!passwds || i + 1 >= *argc) {
129  rfbUsage();
130  free(passwds);
131  return FALSE;
132  }
133  passwds[0] = argv[++i];
134  passwds[1] = NULL;
135  rfbScreen->authPasswdData = (void*)passwds;
136  rfbScreen->passwordCheck = rfbCheckPasswordByList;
137  } else if (strcmp(argv[i], "-deferupdate") == 0) { /* -deferupdate milliseconds */
138  if (i + 1 >= *argc) {
139  rfbUsage();
140  return FALSE;
141  }
142  rfbScreen->deferUpdateTime = atoi(argv[++i]);
143  } else if (strcmp(argv[i], "-deferptrupdate") == 0) { /* -deferptrupdate milliseconds */
144  if (i + 1 >= *argc) {
145  rfbUsage();
146  return FALSE;
147  }
148  rfbScreen->deferPtrUpdateTime = atoi(argv[++i]);
149  } else if (strcmp(argv[i], "-desktop") == 0) { /* -desktop desktop-name */
150  if (i + 1 >= *argc) {
151  rfbUsage();
152  return FALSE;
153  }
154  rfbScreen->desktopName = argv[++i];
155  } else if (strcmp(argv[i], "-alwaysshared") == 0) {
156  rfbScreen->alwaysShared = TRUE;
157  } else if (strcmp(argv[i], "-nevershared") == 0) {
158  rfbScreen->neverShared = TRUE;
159  } else if (strcmp(argv[i], "-dontdisconnect") == 0) {
160  rfbScreen->dontDisconnect = TRUE;
161  } else if (strcmp(argv[i], "-httpdir") == 0) { /* -httpdir directory-path */
162  if (i + 1 >= *argc) {
163  rfbUsage();
164  return FALSE;
165  }
166  rfbScreen->httpDir = argv[++i];
167  } else if (strcmp(argv[i], "-httpport") == 0) { /* -httpport portnum */
168  if (i + 1 >= *argc) {
169  rfbUsage();
170  return FALSE;
171  }
172  rfbScreen->httpPort = atoi(argv[++i]);
173 #ifdef LIBVNCSERVER_IPv6
174  } else if (strcmp(argv[i], "-httpportv6") == 0) { /* -httpportv6 portnum */
175  if (i + 1 >= *argc) {
176  rfbUsage();
177  return FALSE;
178  }
179  rfbScreen->http6Port = atoi(argv[++i]);
180 #endif
181  } else if (strcmp(argv[i], "-enablehttpproxy") == 0) {
182  rfbScreen->httpEnableProxyConnect = TRUE;
183  } else if (strcmp(argv[i], "-progressive") == 0) { /* -httpport portnum */
184  if (i + 1 >= *argc) {
185  rfbUsage();
186  return FALSE;
187  }
188  rfbScreen->progressiveSliceHeight = atoi(argv[++i]);
189  } else if (strcmp(argv[i], "-listen") == 0) { /* -listen ipaddr */
190  if (i + 1 >= *argc) {
191  rfbUsage();
192  return FALSE;
193  }
194  if (! rfbStringToAddr(argv[++i], &(rfbScreen->listenInterface))) {
195  return FALSE;
196  }
197 #ifdef LIBVNCSERVER_IPv6
198  } else if (strcmp(argv[i], "-listenv6") == 0) { /* -listenv6 ipv6addr */
199  if (i + 1 >= *argc) {
200  rfbUsage();
201  return FALSE;
202  }
203  rfbScreen->listen6Interface = argv[++i];
204 #endif
205 #ifdef LIBVNCSERVER_WITH_WEBSOCKETS
206  } else if (strcmp(argv[i], "-sslkeyfile") == 0) { /* -sslkeyfile sslkeyfile */
207  if (i + 1 >= *argc) {
208  rfbUsage();
209  return FALSE;
210  }
211  rfbScreen->sslkeyfile = argv[++i];
212  } else if (strcmp(argv[i], "-sslcertfile") == 0) { /* -sslcertfile sslcertfile */
213  if (i + 1 >= *argc) {
214  rfbUsage();
215  return FALSE;
216  }
217  rfbScreen->sslcertfile = argv[++i];
218 #endif
219  } else {
220  rfbProtocolExtension* extension;
221  int handled=0;
222 
223  for(extension=rfbGetExtensionIterator();handled==0 && extension;
224  extension=extension->next)
225  if(extension->processArgument)
226  handled = extension->processArgument(*argc - i, argv + i);
228 
229  if(handled==0) {
230  i++;
231  i1=i;
232  continue;
233  }
234  i+=handled-1;
235  }
236  /* we just remove the processed arguments from the list */
237  rfbPurgeArguments(argc,&i1,i-i1+1,argv);
238  i=i1;
239  }
240  return TRUE;
241 }
242 
243 rfbBool
244 rfbProcessSizeArguments(int* width,int* height,int* bpp,int* argc, char *argv[])
245 {
246  int i,i1;
247 
248  if(!argc) return TRUE;
249  for (i = i1 = 1; i < *argc-1;) {
250  if (strcmp(argv[i], "-bpp") == 0) {
251  *bpp = atoi(argv[++i]);
252  } else if (strcmp(argv[i], "-width") == 0) {
253  *width = atoi(argv[++i]);
254  } else if (strcmp(argv[i], "-height") == 0) {
255  *height = atoi(argv[++i]);
256  } else {
257  i++;
258  i1=i;
259  continue;
260  }
261  rfbPurgeArguments(argc,&i1,i-i1,argv);
262  i=i1;
263  }
264  return TRUE;
265 }
266 
#define TRUE
Definition: rfbproto.h:112
struct _rfbProtocolExtension * next
Definition: rfb.h:183
int8_t rfbBool
Definition: rfbproto.h:108
rfbBool rfbProcessSizeArguments(int *width, int *height, int *bpp, int *argc, char *argv[])
Definition: cargs.c:244
#define height
Definition: vncev.c:19
Protocol extension handling.
Definition: rfb.h:161
int rfbStringToAddr(char *str, in_addr_t *iface)
Definition: sockets.c:891
rfbBool rfbProcessArguments(rfbScreenInfoPtr rfbScreen, int *argc, char *argv[])
Definition: cargs.c:81
void rfbReleaseExtensionIterator()
Definition: main.c:159
void(* usage)(void)
Definition: rfb.h:180
void rfbUsage(void)
Definition: cargs.c:20
rfbBool rfbCheckPasswordByList(rfbClientPtr cl, const char *response, int len)
to check against plain passwords
Definition: main.c:786
struct _rfbProtocolExtension * rfbGetExtensionIterator()
Definition: main.c:148
#define FALSE
Definition: rfbproto.h:110
int(* processArgument)(int argc, char *argv[])
processArguments returns the number of handled arguments
Definition: rfb.h:182
#define width
Definition: vncev.c:18
void rfbPurgeArguments(int *argc, int *position, int count, char *argv[])
Definition: cargs.c:72