/* REGISTER ALL KNOWN TRANSPORTS IN THE LIBRARY ** -------------------------------------------- ** Not done automaticly - may be done by application! */ PUBLIC void HTTransportInit (void) { HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new); HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new, HTBufferWriter_new); #ifdef HT_MUX HTTransport_add("mux", HT_TP_INTERLEAVE, HTReader_new, HTBufferWriter_new); #endif /* HT_MUX */ #ifndef NO_UNIX_IO HTTransport_add("local", HT_TP_SINGLE, HTReader_new, HTWriter_new); #else HTTransport_add("local", HT_TP_SINGLE, HTANSIReader_new, HTANSIWriter_new); #endif }
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; }