X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/15c408ab8635fe45226abc2c55c9bebfe1ccb6c8..d26a9ed5fd6fc60a0dfa61d04f5ae2bd7163a85d:/Projects/Webserver/Lib/WebserverApp.c diff --git a/Projects/Webserver/Lib/WebserverApp.c b/Projects/Webserver/Lib/WebserverApp.c index 6ac94d6ac..02f38be87 100644 --- a/Projects/Webserver/Lib/WebserverApp.c +++ b/Projects/Webserver/Lib/WebserverApp.c @@ -51,9 +51,7 @@ char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n" "Server: LUFA RNDIS\r\n" "Connection: close\r\n\r\n"; -/** HTTP page to serve to the host when a HTTP request is made. This page is too long for a single response, thus it is automatically - * broken up into smaller blocks and sent as a series of packets each time the webserver application callback is run. - */ +/** Static HTTP page to serve to the host when a HTTP request is made from a host. */ char PROGMEM HTTPPage[] = "" " " @@ -78,7 +76,7 @@ char PROGMEM HTTPPage[] = void WebserverApp_Init(void) { /* Listen on port 80 for HTTP connections from hosts */ - uip_listen(HTONS(80)); + uip_listen(HTONS(HTTP_SERVER_PORT)); } /** uIP stack application callback for the simple HTTP webserver. This function must be called each time the @@ -86,8 +84,9 @@ void WebserverApp_Init(void) */ void WebserverApp_Callback(void) { - char* AppDataPtr = (char*)uip_appdata; - uint16_t AppDataSize = 0; + uip_tcp_appstate_t* const AppState = &uip_conn->appstate; + char* AppData = (char*)uip_appdata; + uint16_t AppDataSize = 0; if (uip_closed() || uip_aborted() || uip_timedout()) { @@ -97,12 +96,12 @@ void WebserverApp_Callback(void) else if (uip_connected()) { /* New connection - initialize connection state and data pointer to the appropriate HTTP header */ - uip_conn->appstate.SendPos = HTTP200Header; - uip_conn->appstate.CurrentState = WEBSERVER_STATE_SendHeaders; + AppState->SendPos = HTTP200Header; + AppState->CurrentState = WEBSERVER_STATE_SendHeaders; } /* Calculate the maximum segment size and remaining data size */ - uint16_t BytesRemaining = strlen_P(uip_conn->appstate.SendPos); + uint16_t BytesRemaining = strlen_P(AppState->SendPos); uint16_t MaxSegSize = uip_mss(); /* No more bytes remaining in the current data being sent - progress to next data chunk or @@ -110,15 +109,15 @@ void WebserverApp_Callback(void) if (!(BytesRemaining)) { /* Check which data chunk we are currently sending (header or data) */ - if (uip_conn->appstate.CurrentState == WEBSERVER_STATE_SendHeaders) + if (AppState->CurrentState == WEBSERVER_STATE_SendHeaders) { - uip_conn->appstate.SendPos = HTTPPage; - uip_conn->appstate.CurrentState = WEBSERVER_STATE_SendData; + AppState->SendPos = HTTPPage; + AppState->CurrentState = WEBSERVER_STATE_SendData; } - else if (uip_conn->appstate.CurrentState == WEBSERVER_STATE_SendData) + else if (AppState->CurrentState == WEBSERVER_STATE_SendData) { uip_close(); - uip_conn->appstate.CurrentState = WEBSERVER_STATE_Closed; + AppState->CurrentState = WEBSERVER_STATE_Closed; } return; @@ -135,9 +134,9 @@ void WebserverApp_Callback(void) } /* Copy over the next data segment to the application buffer, advance send position pointer */ - strncpy_P(uip_appdata, uip_conn->appstate.SendPos, AppDataSize); - uip_conn->appstate.SendPos += AppDataSize; + strncpy_P(AppData, AppState->SendPos, AppDataSize); + AppState->SendPos += AppDataSize; /* Send the data to the requesting host */ - uip_send(AppDataPtr, AppDataSize); + uip_send(AppData, AppDataSize); }