static BaseType_t prvOpenUrl( xHTTPClient *pxClient ) { BaseType_t xRc; char pcSlash[ 2 ]; pxClient->bits.ulFlags = 0; if( pxClient->pcUrlData[ 0 ] != '/' ) { /* Insert a slah before the file name */ pcSlash[ 0 ] = '/'; pcSlash[ 1 ] = '\0'; } else { /* The browser provided a starting '/' already */ pcSlash[ 0 ] = '\0'; } snprintf( pxClient->pcCurrentFilename, sizeof pxClient->pcCurrentFilename, "%s%s%s", pxClient->pcRootDir, pcSlash, pxClient->pcUrlData); pxClient->pxFileHandle = ff_fopen( pxClient->pcCurrentFilename, "rb" ); FreeRTOS_printf( ( "Open file '%s': %s\n", pxClient->pcCurrentFilename, pxClient->pxFileHandle != NULL ? "Ok" : strerror( stdioGET_ERRNO() ) ) ); if( pxClient->pxFileHandle == NULL ) { xRc = prvSendReply( pxClient, WEB_NOT_FOUND ); /* "404 File not found" */ } else { pxClient->xBytesLeft = pxClient->pxFileHandle->ulFileSize; xRc = prvSendFile( pxClient ); } return xRc; }
static BaseType_t prvOpenURL( HTTPClient_t *pxClient ) { BaseType_t xRc; char pcSlash[ 2 ]; pxClient->bits.ulFlags = 0; #if( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 ) { if( strchr( pxClient->pcUrlData, ipconfigHTTP_REQUEST_CHARACTER ) != NULL ) { size_t xResult; xResult = uxApplicationHTTPHandleRequestHook( pxClient->pcUrlData, pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ) ); if( xResult > 0 ) { strcpy( pxClient->pxParent->pcContentsType, "text/html" ); snprintf( pxClient->pxParent->pcExtraContents, sizeof( pxClient->pxParent->pcExtraContents ), "Content-Length: %d\r\n", ( int ) xResult ); xRc = prvSendReply( pxClient, WEB_REPLY_OK ); /* "Requested file action OK" */ if( xRc > 0 ) { xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pcCurrentFilename, xResult, 0 ); } /* Although against the coding standard of FreeRTOS, a return is done here to simplify this conditional code. */ return xRc; } } } #endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */ if( pxClient->pcUrlData[ 0 ] != '/' ) { /* Insert a slash before the file name. */ pcSlash[ 0 ] = '/'; pcSlash[ 1 ] = '\0'; } else { /* The browser provided a starting '/' already. */ pcSlash[ 0 ] = '\0'; } snprintf( pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ), "%s%s%s", pxClient->pcRootDir, pcSlash, pxClient->pcUrlData); pxClient->pxFileHandle = ff_fopen( pxClient->pcCurrentFilename, "rb" ); FreeRTOS_printf( ( "Open file '%s': %s\n", pxClient->pcCurrentFilename, pxClient->pxFileHandle != NULL ? "Ok" : strerror( stdioGET_ERRNO() ) ) ); if( pxClient->pxFileHandle == NULL ) { /* "404 File not found". */ xRc = prvSendReply( pxClient, WEB_NOT_FOUND ); } else { pxClient->uxBytesLeft = ( size_t ) pxClient->pxFileHandle->ulFileSize; xRc = prvSendFile( pxClient ); } return xRc; }