+1998-12-04 Nathan Bryant <bryant@cs.usm.maine.edu>
+ * webserver.c, context_loop.c, webcit.c: add commandline args for host
+ and port
+
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
* up HTTP requests with the session they belong to, using HTTP cookies to
* keep track of things. If the HTTP request doesn't belong to any currently
* active session, a new session is spawned.
+ *
+ * $Id$
*/
#include <stdlib.h>
}
}
+extern const char *defaulthost;
+extern const char *defaultport;
/*
* This loop gets called once for every HTTP connection made to WebCit.
if (f==0) {
dup2(TheSession->inpipe[0], 0);
dup2(TheSession->outpipe[1], 1);
- execlp("./webcit", "webcit", str_session, NULL);
+ execlp("./webcit", "webcit", str_session, defaulthost,
+ defaultport, NULL);
printf("HTTP/1.0 404 WebCit Failure\n\n");
printf("Server: %s\n", SERVER);
printf("Content-type: text/html\n");
* This is the actual program called by the webserver. It maintains a
* persistent session to the Citadel server, handling HTTP WebCit requests as
* they arrive and presenting a user interface.
+ *
+ * $Id$
*/
#include <stdlib.h>
}
}
+static const char *defaulthost = DEFAULT_HOST;
+static const char *defaultport = DEFAULT_PORT;
void session_loop() {
char cmd[256];
char c_password[256];
char c_roomname[256];
- strcpy(c_host, DEFAULT_HOST);
- strcpy(c_port, DEFAULT_PORT);
+ strcpy(c_host, defaulthost);
+ strcpy(c_port, defaultport);
strcpy(c_username, "");
strcpy(c_password, "");
strcpy(c_roomname, "");
free_urls();
}
-
-
int main(int argc, char *argv[]) {
- if (argc != 2) {
- printf("%s: usage: %s <session_id>\n", argv[0], argv[0]);
- exit(1);
+ if (argc < 2 || argc > 4) {
+ fprintf(stderr,
+ "webcit: usage: webcit <session_id> [host [port]]\n");
+ return 1;
}
wc_session = atoi(argv[1]);
+
+ if (argc > 2) {
+ defaulthost = argv[2];
+ if (argc > 3)
+ defaultport = argv[3];
+ }
+
strcpy(wc_host, "");
strcpy(wc_port, "");
strcpy(wc_username, "");
while (1) {
session_loop();
}
-
- exit(0);
}
printf("Location: %s\n\n", url);
}
+const char *defaulthost = DEFAULT_HOST;
+const char *defaultport = DEFAULT_PORT;
/*
* Here's where it all begins.
pthread_t SessThread; /* Thread descriptor */
pthread_attr_t attr; /* Thread attributes */
int a, i; /* General-purpose variables */
+ int port = PORT_NUM; /* Port to listen on */
char convbuf[128];
+
+ /* Parse command line */
+ while ((a = getopt(argc, argv, "hp:")) != EOF)
+ switch (a) {
+ case 'p':
+ port = atoi(optarg);
+ break;
+ default:
+ fprintf(stderr, "usage: webserver [-p localport] "
+ "[remotehost [remoteport]]\n");
+ return 1;
+ }
+
+ if (optind < argc) {
+ defaulthost = argv[optind];
+ if (++optind < argc)
+ defaultport = argv[optind];
+ }
/* Tell 'em who's in da house */
printf("WebCit v2 experimental\n");
* There is no need to check for errors, because ig_tcp_server()
* exits if it doesn't succeed.
*/
- printf("Attempting to bind to port %d...\n", PORT_NUM);
- msock = ig_tcp_server(PORT_NUM, 5);
+ printf("Attempting to bind to port %d...\n", port);
+ msock = ig_tcp_server(port, 5);
printf("Listening on socket %d\n", msock);
pthread_mutex_init(&MasterCritter, NULL);