int main(void) { #ifdef NUT_OS NutRegisterDevice(&DEV_CONSOLE, 0, 0); freopen(DEV_CONSOLE.dev_name, "w", stdout); #endif puts("uHTTP form sample\nBuild " __DATE__ " " __TIME__); #ifdef NUT_OS NutRegisterDevice(&DEV_ETHER, 0, 0); NutDhcpIfConfig(DEV_ETHER_NAME, NULL, 60000); NutRegisterDevice(&devUrom, 0, 0); #endif StreamInit(); MediaTypeInitDefaults(); HttpRegisterRedir("", "/index.html", 301); HttpRegisterCgiFunction("getform.cgi", CgiGetForm); HttpRegisterCgiFunction("postform.cgi", CgiPostForm); HttpRegisterMediaType("cgi", NULL, NULL, HttpCgiFunctionHandler); StreamClientAccept(HttpdClientHandler, NULL); puts("Exit"); #ifdef NUT_OS for (;;) ; #endif return 0; }
int UpnpRegisterDeviceTree(SSDP_DEVICE *parent, SSDP_DEVICE *sdev) { int rc = 0; static uint_fast8_t initialized; if (parent) { parent->sdev_next = (SSDP_DEVICE *) sdev; } else { sdev->sdev_next = (SSDP_DEVICE *) device_registration; device_registration = sdev; if (!initialized) { HttpRegisterCgiFunction(sdev->sdev_url_desc, UpnpCgiDeviceDescription); HttpRegisterCgiFunction(((UPNP_SERVICE_INFO *) sdev->sdev_svc->ssvc_info)->usvc_url_scpd, UpnpCgiServiceDescription); } rc = SsdpRegisterDeviceTree(device_registration); } return rc; }
msg_t HttpTask (void *p) { (void)p; chRegSetThreadName("HttpTask"); /* * Initialize the TCP socket interface. */ StreamInit(); /* * Register media type defaults. These are configurable * in include/cfg/http.h or the Nut/OS Configurator. */ MediaTypeInitDefaults(); HttpRegisterRedir("", "/index.html", 301); HttpRegisterCgiFunction("clock.cgi", CgiClock); HttpRegisterCgiFunction("getform.cgi", CgiGetForm); HttpRegisterCgiFunction("postform.cgi", CgiPostForm); HttpRegisterMediaType("cgi", NULL, NULL, HttpCgiFunctionHandler); /* * Wait for a client (browser) and handle its request. * This function will only return on unrecoverable errors. */ StreamClientAccept(HttpdClientHandler, NULL); /* Typically this point will be never reached. */ while(1) { chThdSleepMilliseconds(500); } return(0); } /* HttpTask */