⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filehdlr.c

📁 这是有名的<<嵌入式系统TCP/IP应用层协议>>,M.Tim Jones 著
💻 C
字号:
/* *  Embedded HTTP Server Internal Filesystem Utilities * *  ./software/ch7/emhttps/filehdlr.c * *  mtj@cogitollc.com * */#include "filehdlr.h"#include "log.h"extern unsigned char filedata[];/*---------------------------------------------------------------------------- * lookupFilename() - Locate a file in the internal file system *--------------------------------------------------------------------------*/int lookupFilename(char *filename, struct fileHdrStruct *filehdr){  int offset = 0;  int size;  int i, found;  int ret;  while (filedata[offset] != 0) {    ret = offset;    found = 1;    if ((filedata[offset] == 0xfa) && (filedata[offset+1] == 0xf3)) {      /* Skip the header */      offset+=2;      /* Search the file name, but don't stop if not found... */      for (i = 0 ; filedata[i+offset] != 0 ; i++) {        if (filename[i] != filedata[i+offset]) {          found = 0;        }      }      /* Skip the filename and null terminator */      offset += (i+1);      /* Get the file size */      size = (filedata[offset  ] << 24) | (filedata[offset+1] << 16) |             (filedata[offset+2] <<  8) | (filedata[offset+3]);      if (found) {        filehdr->hdrStart = ret;        filehdr->size = size;        filehdr->fileStart = (offset+4);        emitByte(PREFIX_BYTE); emitByte(NORMAL_REQUEST);        emitString(filename); emitByte(SUFFIX_BYTE);        return(1);      }      offset += (size+4);    }  }  return(0);}/* *  Copyright (c) 2002 Charles River Media.  All rights reserved. *  *  Redistribution and use in source and binary forms, with or  *  without modification, is hereby granted without fee 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.  Neither the name of Charles River Media nor the names of  *        its contributors may be used to endorse or promote products  *        derived from this software without specific prior  *        written permission. *  * THIS SOFTWARE IS PROVIDED BY CHARLES RIVER MEDIA AND CONTRIBUTERS  * 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CHARLES * RIVER MEDIA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  * INCIDENTAL, SPECIAL, EXEMPLARAY, 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. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -