/* REGISTER ALL KNOWN PROTOCOLS IN THE LIBRARY PREEMPTIVELY ** -------------------------------------------------------- ** Not done automaticly - may be done by application! */ PUBLIC void HTProtocolPreemptiveInit (void) { #ifndef DECNET HTProtocol_add("ftp", "tcp", FTP_PORT, YES, HTLoadFTP, NULL); HTProtocol_add("nntp", "tcp", NEWS_PORT, YES, HTLoadNews, NULL); HTProtocol_add("news", "tcp", NEWS_PORT, YES, HTLoadNews, NULL); HTProtocol_add("gopher", "tcp", GOPHER_PORT, YES, HTLoadGopher, NULL); #ifdef HT_DIRECT_WAIS HTProtocol_add("wais", "", WAIS_PORT, YES, HTLoadWAIS, NULL); #endif #endif /* DECNET */ HTProtocol_add("http", "buffered_tcp", HTTP_PORT, YES, HTLoadHTTP, NULL); HTProtocol_add("file", "local", 0, YES, HTLoadFile, NULL); HTProtocol_add("telnet", "", 0, YES, HTLoadTelnet, NULL); HTProtocol_add("tn3270", "", 0, YES, HTLoadTelnet, NULL); HTProtocol_add("rlogin", "", 0, YES, HTLoadTelnet, NULL); HTProtocol_add("cache","local",0,YES,HTLoadCache, NULL); }
int main (int argc, char ** argv) { ListenTool * ms = ListenTool_new(); int status = HT_ERROR; int arg = 0; /* ** Initiate libwww. Note that we don't call a profile as these set up ** all the client side specific things. Here we just want a very basic ** server which doesn't do anything but forwarding what it reads to ** stdout. */ HTLibInit(APP_NAME, APP_VERSION); /* Set up default event loop */ HTEventInit(); /* Need our own trace and print functions */ HTPrint_setCallback(printer); HTTrace_setCallback(tracer); /* Add our own filter to handle termination */ HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST); /* Check if we should just provide some help */ if (argc==1) { VersionInfo(argv[0]); Cleanup(ms, 0); } /* Scan command Line for parameters */ for (arg=1; arg<argc ; arg++) { if (*argv[arg] == '-') { /* server port */ if (!strncmp(argv[arg], "-p", 2)) { ms->port = (arg+1 < argc && *argv[arg+1] != '-') ? atoi(argv[++arg]) : DEFAULT_PORT; /* Print version and exit */ } else if (!strcmp(argv[arg], "-version")) { VersionInfo(argv[0]); Cleanup(ms, 0); #ifdef HTDEBUG /* trace flags */ } else if (!strncmp(argv[arg], "-v", 2)) { HTSetTraceMessageMask(argv[arg]+2); #endif } else { VersionInfo(argv[0]); Cleanup(ms, 0); } } else { VersionInfo(argv[0]); Cleanup(ms, 0); } } /* Set up a tool to listen on this port */ if (ms->port >= 0) { /* Register TCP as the transport */ HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new); /* Register the "noop" application layer protocol for reading */ HTProtocol_add("noop", "tcp", ms->port, NO, NULL, HTLoadSocket); /* Set up the request */ ms->request = HTRequest_new(); HTRequest_setOutputFormat(ms->request, DEFAULT_FORMAT); HTRequest_setOutputStream(ms->request, HTFWriter_new(ms->request, OUTPUT, YES)); /* Start listening on the socket */ HTPrint("Listening on port %d\n", ms->port); if ((status = HTServeAbsolute("noop://localhost", ms->request)) == NO) { HTPrint("Can't listen on port %d\n", ms->port); Cleanup(ms, -1); } /* Go into the event loop... */ if (status == YES) HTEventList_newLoop(); } Cleanup(ms, 0); return 0; }