lwip-contrib-mac/ports/mac/include/fsdata_custom.c

1 line
7.2 KiB
C
Raw Normal View History

/* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. * * Author: Adam Dunkels <adam@sics.se> * */ #include "lwip/opt.h" #include "lwip/def.h" #include "fs.h" #include "fsdata.h" #include <stdio.h> #include <Errors.h> #include <Files.h> #include <string.h> #define FS_ROOT NULL #define FS_FILE_BUFF_SIZE 4096 #if !HTTPD_PRECALCULATED_CHECKSUM static char *fileBuff; static unsigned int fileBuffSize; #endif /* HTTPD_PRECALCULATED_CHECKSUM */ /*-----------------------------------------------------------------------------------*/ void fs_close_custom(struct fs_file *file) { OSErr error; #if HTTPD_PRECALCULATED_CHECKSUM && LWIP_HTTPD_DYNAMIC_FILE_READ /* Slyly store the file reference in the checksum */ long refNum = (long)file->chksum_count; error = FSClose(refNum); LWIP_ERROR("Unable to close File", (error == noErr ), return;); LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("fs_close_custom()\n")); #endif } /*-----------------------------------------------------------------------------------*/ int fs_path_to_mac(char *path_string) { char *curr_loc = path_string; /* HFS Only */ curr_loc = strchr(curr_loc, '/'); while (curr_loc != NULL) { *curr_loc = ':'; curr_loc = strchr(curr_loc, '/'); } } /*-----------------------------------------------------------------------------------*/ #if HTTPD_PRECALCULATED_CHECKSUM && LWIP_HTTPD_DYNAMIC_FILE_READ int fs_open_custom(struct fs_file *file, const char *name) { OSErr error = fsDSIntErr; long readCount; Str255 pName; short vRefNum = 0; short refNum; char firstChar; /* Only open files with an extension for 'security'.*/ if ( strchr(name, '.') == NULL ) return 0; /* Convert file name to pascal string. */ strncpy((char *)pName, name, 255); //fs_path_to_mac((char *)pName); pName[0] = (char)strlen(name)-1; /* Overwrite the first character which is a ':' or '/' */ /* Open the file. */ error = FSOpen(pName, vRefNum, &refNum); if (error != noErr) { LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("FSopen() error:%d\n", error)); return 0; } /* Figure out how long the file is. */ error = GetEOF(refNum, &readCount); file->len = readCount; file->index = 0; file->pextension = NULL; /* Slyly store the file reference in the checksum. */ file->chksum_count = (u16_t)refNum; //file->http_header_included = false; /* Check if the first letter of the file is 'H' which indicates that the HTTP header is included. This doesn't work because if LWIP_HTTPD_DYNAMIC_FILE_READ is enabled, the file is not read until after http_init_file which is where the header