PageRenderTime 82ms CodeModel.GetById 33ms app.highlight 44ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/desktop/libvncserver/cargs.c

http://ftk.googlecode.com/
C | 213 lines | 182 code | 16 blank | 15 comment | 87 complexity | e53051428784f341e84d311e92cd35ac MD5 | raw file
  1/*
  2 *  This parses the command line arguments. It was seperated 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
 17extern int rfbStringToAddr(char *str, in_addr_t *iface);
 18
 19void
 20rfbUsage(void)
 21{
 22    rfbProtocolExtension* extension;
 23
 24    fprintf(stderr, "-rfbport port          TCP port for RFB protocol\n");
 25    fprintf(stderr, "-rfbwait time          max time in ms to wait for RFB client\n");
 26    fprintf(stderr, "-rfbauth passwd-file   use authentication on RFB protocol\n"
 27                    "                       (use 'storepasswd' to create a password file)\n");
 28    fprintf(stderr, "-rfbversion 3.x        Set the version of the RFB we choose to advertise\n");
 29    fprintf(stderr, "-permitfiletransfer    permit file transfer support\n");
 30    fprintf(stderr, "-passwd plain-password use authentication \n"
 31                    "                       (use plain-password as password, USE AT YOUR RISK)\n");
 32    fprintf(stderr, "-deferupdate time      time in ms to defer updates "
 33                                                             "(default 40)\n");
 34    fprintf(stderr, "-deferptrupdate time   time in ms to defer pointer updates"
 35                                                           " (default none)\n");
 36    fprintf(stderr, "-desktop name          VNC desktop name (default \"LibVNCServer\")\n");
 37    fprintf(stderr, "-alwaysshared          always treat new clients as shared\n");
 38    fprintf(stderr, "-nevershared           never treat new clients as shared\n");
 39    fprintf(stderr, "-dontdisconnect        don't disconnect existing clients when a "
 40                                                             "new non-shared\n"
 41                    "                       connection comes in (refuse new connection "
 42                                                                "instead)\n");
 43    fprintf(stderr, "-httpdir dir-path      enable http server using dir-path home\n");
 44    fprintf(stderr, "-httpport portnum      use portnum for http connection\n");
 45    fprintf(stderr, "-enablehttpproxy       enable http proxy support\n");
 46    fprintf(stderr, "-progressive height    enable progressive updating for slow links\n");
 47    fprintf(stderr, "-listen ipaddr         listen for connections only on network interface with\n");
 48    fprintf(stderr, "                       addr ipaddr. '-listen localhost' and hostname work too.\n");
 49
 50    for(extension=rfbGetExtensionIterator();extension;extension=extension->next)
 51	if(extension->usage)
 52		extension->usage();
 53    rfbReleaseExtensionIterator();
 54}
 55
 56/* purges COUNT arguments from ARGV at POSITION and decrements ARGC.
 57   POSITION points to the first non purged argument afterwards. */
 58void rfbPurgeArguments(int* argc,int* position,int count,char *argv[])
 59{
 60  int amount=(*argc)-(*position)-count;
 61  if(amount)
 62    memmove(argv+(*position),argv+(*position)+count,sizeof(char*)*amount);
 63  (*argc)-=count;
 64}
 65
 66rfbBool 
 67rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[])
 68{
 69    int i,i1;
 70
 71    if(!argc) return TRUE;
 72    
 73    for (i = i1 = 1; i < *argc;) {
 74        if (strcmp(argv[i], "-help") == 0) {
 75	    rfbUsage();
 76	    return FALSE;
 77	} else if (strcmp(argv[i], "-rfbport") == 0) { /* -rfbport port */
 78            if (i + 1 >= *argc) {
 79		rfbUsage();
 80		return FALSE;
 81	    }
 82	    rfbScreen->port = atoi(argv[++i]);
 83        } else if (strcmp(argv[i], "-rfbwait") == 0) {  /* -rfbwait ms */
 84            if (i + 1 >= *argc) {
 85		rfbUsage();
 86		return FALSE;
 87	    }
 88	    rfbScreen->maxClientWait = atoi(argv[++i]);
 89        } else if (strcmp(argv[i], "-rfbauth") == 0) {  /* -rfbauth passwd-file */
 90            if (i + 1 >= *argc) {
 91		rfbUsage();
 92		return FALSE;
 93	    }
 94            rfbScreen->authPasswdData = argv[++i];
 95
 96        } else if (strcmp(argv[i], "-permitfiletransfer") == 0) {  /* -permitfiletransfer  */
 97            rfbScreen->permitFileTransfer = TRUE;
 98        } else if (strcmp(argv[i], "-rfbversion") == 0) {  /* -rfbversion 3.6  */
 99            if (i + 1 >= *argc) {
100		rfbUsage();
101		return FALSE;
102	    }
103	    sscanf(argv[++i],"%d.%d", &rfbScreen->protocolMajorVersion, &rfbScreen->protocolMinorVersion);
104	} else if (strcmp(argv[i], "-passwd") == 0) {  /* -passwd password */
105	    char **passwds = malloc(sizeof(char**)*2);
106	    if (i + 1 >= *argc) {
107		rfbUsage();
108		return FALSE;
109	    }
110	    passwds[0] = argv[++i];
111	    passwds[1] = NULL;
112	    rfbScreen->authPasswdData = (void*)passwds;
113	    rfbScreen->passwordCheck = rfbCheckPasswordByList;
114        } else if (strcmp(argv[i], "-deferupdate") == 0) {  /* -deferupdate milliseconds */
115            if (i + 1 >= *argc) {
116		rfbUsage();
117		return FALSE;
118	    }
119            rfbScreen->deferUpdateTime = atoi(argv[++i]);
120        } else if (strcmp(argv[i], "-deferptrupdate") == 0) {  /* -deferptrupdate milliseconds */
121            if (i + 1 >= *argc) {
122		rfbUsage();
123		return FALSE;
124	    }
125            rfbScreen->deferPtrUpdateTime = atoi(argv[++i]);
126        } else if (strcmp(argv[i], "-desktop") == 0) {  /* -desktop desktop-name */
127            if (i + 1 >= *argc) {
128		rfbUsage();
129		return FALSE;
130	    }
131            rfbScreen->desktopName = argv[++i];
132        } else if (strcmp(argv[i], "-alwaysshared") == 0) {
133	    rfbScreen->alwaysShared = TRUE;
134        } else if (strcmp(argv[i], "-nevershared") == 0) {
135            rfbScreen->neverShared = TRUE;
136        } else if (strcmp(argv[i], "-dontdisconnect") == 0) {
137            rfbScreen->dontDisconnect = TRUE;
138        } else if (strcmp(argv[i], "-httpdir") == 0) {  /* -httpdir directory-path */
139            if (i + 1 >= *argc) {
140		rfbUsage();
141		return FALSE;
142	    }
143            rfbScreen->httpDir = argv[++i];
144        } else if (strcmp(argv[i], "-httpport") == 0) {  /* -httpport portnum */
145            if (i + 1 >= *argc) {
146		rfbUsage();
147		return FALSE;
148	    }
149            rfbScreen->httpPort = atoi(argv[++i]);
150        } else if (strcmp(argv[i], "-enablehttpproxy") == 0) {
151            rfbScreen->httpEnableProxyConnect = TRUE;
152        } else if (strcmp(argv[i], "-progressive") == 0) {  /* -httpport portnum */
153            if (i + 1 >= *argc) {
154		rfbUsage();
155		return FALSE;
156	    }
157            rfbScreen->progressiveSliceHeight = atoi(argv[++i]);
158        } else if (strcmp(argv[i], "-listen") == 0) {  /* -listen ipaddr */
159            if (i + 1 >= *argc) {
160		rfbUsage();
161		return FALSE;
162	    }
163            if (! rfbStringToAddr(argv[++i], &(rfbScreen->listenInterface))) {
164                return FALSE;
165            }
166        } else {
167	    rfbProtocolExtension* extension;
168	    int handled=0;
169
170	    for(extension=rfbGetExtensionIterator();handled==0 && extension;
171			extension=extension->next)
172		if(extension->processArgument)
173			handled = extension->processArgument(*argc - i, argv + i);
174	    rfbReleaseExtensionIterator();
175
176	    if(handled==0) {
177		i++;
178		i1=i;
179		continue;
180	    }
181	    i+=handled-1;
182	}
183	/* we just remove the processed arguments from the list */
184	rfbPurgeArguments(argc,&i1,i-i1+1,argv);
185	i=i1;
186    }
187    return TRUE;
188}
189
190rfbBool 
191rfbProcessSizeArguments(int* width,int* height,int* bpp,int* argc, char *argv[])
192{
193    int i,i1;
194
195    if(!argc) return TRUE;
196    for (i = i1 = 1; i < *argc-1;) {
197        if (strcmp(argv[i], "-bpp") == 0) {
198               *bpp = atoi(argv[++i]);
199        } else if (strcmp(argv[i], "-width") == 0) {
200               *width = atoi(argv[++i]);
201        } else if (strcmp(argv[i], "-height") == 0) {
202               *height = atoi(argv[++i]);
203        } else {
204	    i++;
205	    i1=i;
206	    continue;
207	}
208	rfbPurgeArguments(argc,&i1,i-i1,argv);
209	i=i1;
210    }
211    return TRUE;
212}
213