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

📄 response.c

📁 一个很好用的解析
💻 C
📖 第 1 页 / 共 2 页
字号:
                    abyss_bool addedToExt;                                        addedToExt = ListAdd(&MIMETypeP->extList, extItem);                    *successP = addedToExt;                    if (!*successP)                        ListRemove(&MIMETypeP->typeList);                } else                    *successP = FALSE;                if (!*successP)                    PoolReturn(&MIMETypeP->pool, extItem);            } else                *successP = FALSE;        }    } else        *successP = FALSE;}abyss_boolMIMETypeAdd2(MIMEType *   const MIMETypeArg,             const char * const type,             const char * const ext) {    MIMEType * MIMETypeP = MIMETypeArg ? MIMETypeArg : globalMimeTypeP;    abyss_bool success;    if (MIMETypeP == NULL)        success = FALSE;    else         mimeTypeAdd(MIMETypeP, type, ext, &success);    return success;}abyss_boolMIMETypeAdd(const char * const type,            const char * const ext) {    return MIMETypeAdd2(globalMimeTypeP, type, ext);}static const char *mimeTypeFromExt(MIMEType *   const MIMETypeP,                const char * const ext) {    const char * retval;    uint16_t extindex;    abyss_bool extIsInList;    assert(MIMETypeP != NULL);    extIsInList = ListFindString(&MIMETypeP->extList, ext, &extindex);    if (!extIsInList)        retval = NULL;    else        retval = MIMETypeP->typeList.item[extindex];        return retval;}const char *MIMETypeFromExt2(MIMEType *   const MIMETypeArg,                 const char * const ext) {    const char * retval;    MIMEType * MIMETypeP = MIMETypeArg ? MIMETypeArg : globalMimeTypeP;    if (MIMETypeP == NULL)        retval = NULL;    else        retval = mimeTypeFromExt(MIMETypeP, ext);    return retval;}const char *MIMETypeFromExt(const char * const ext) {    return MIMETypeFromExt2(globalMimeTypeP, ext);}static voidfindExtension(const char *  const fileName,              const char ** const extP) {    unsigned int extPos = 0;  /* stifle unset variable warning */        /* Running estimation of where in fileName[] the extension starts */    abyss_bool extFound;    unsigned int i;    /* We're looking for the last dot after the last slash */    for (i = 0, extFound = FALSE; fileName[i]; ++i) {        char const c = fileName[i];                if (c == '.') {            extFound = TRUE;            extPos = i + 1;        }        if (c == '/')            extFound = FALSE;    }    if (extFound)        *extP = &fileName[extPos];    else        *extP = NULL;}static const char *mimeTypeFromFileName(MIMEType *   const MIMETypeP,                     const char * const fileName) {    const char * retval;    const char * ext;    assert(MIMETypeP != NULL);        findExtension(fileName, &ext);    if (ext)        retval = MIMETypeFromExt2(MIMETypeP, ext);    else        retval = "application/octet-stream";    return retval;}const char *MIMETypeFromFileName2(MIMEType *   const MIMETypeArg,                      const char * const fileName) {    const char * retval;        MIMEType * MIMETypeP = MIMETypeArg ? MIMETypeArg : globalMimeTypeP;    if (MIMETypeP == NULL)        retval = NULL;    else        retval = mimeTypeFromFileName(MIMETypeP, fileName);    return retval;}const char *MIMETypeFromFileName(const char * const fileName) {    return MIMETypeFromFileName2(globalMimeTypeP, fileName);}static abyss_boolfileContainsText(const char * const fileName) {/*----------------------------------------------------------------------------   Return true iff we can read the contents of the file named 'fileName'   and see that it appears to be composed of plain text characters.-----------------------------------------------------------------------------*/    abyss_bool retval;    abyss_bool fileOpened;    TFile file;    fileOpened = FileOpen(&file, fileName, O_BINARY | O_RDONLY);    if (fileOpened) {        char const ctlZ = 26;        unsigned char buffer[80];        int32_t readRc;        unsigned int i;        readRc = FileRead(&file, buffer, sizeof(buffer));               if (readRc >= 0) {            unsigned int bytesRead = readRc;            abyss_bool nonTextFound;            nonTextFound = FALSE;  /* initial value */                for (i = 0; i < bytesRead; ++i) {                char const c = buffer[i];                if (c < ' ' && !isspace(c) && c != ctlZ)                    nonTextFound = TRUE;            }            retval = !nonTextFound;        } else            retval = FALSE;        FileClose(&file);    } else        retval = FALSE;    return retval;} static const char *mimeTypeGuessFromFile(MIMEType *   const MIMETypeP,                      const char * const fileName) {    const char * retval;    const char * ext;    findExtension(fileName, &ext);    retval = NULL;    if (ext && MIMETypeP)        retval = MIMETypeFromExt2(MIMETypeP, ext);        if (!retval) {        if (fileContainsText(fileName))            retval = "text/plain";        else            retval = "application/octet-stream";      }    return retval;}const char *MIMETypeGuessFromFile2(MIMEType *   const MIMETypeArg,                       const char * const fileName) {    return mimeTypeGuessFromFile(MIMETypeArg ? MIMETypeArg : globalMimeTypeP,                                 fileName);}const char *MIMETypeGuessFromFile(const char * const fileName) {    return mimeTypeGuessFromFile(globalMimeTypeP, fileName);}                                  /*********************************************************************** Base64*********************************************************************/void Base64Encode(char *s,char *d){    /* Conversion table. */    static char tbl[64] = {        'A','B','C','D','E','F','G','H',        'I','J','K','L','M','N','O','P',        'Q','R','S','T','U','V','W','X',        'Y','Z','a','b','c','d','e','f',        'g','h','i','j','k','l','m','n',        'o','p','q','r','s','t','u','v',        'w','x','y','z','0','1','2','3',        '4','5','6','7','8','9','+','/'    };    uint32_t i,length=strlen(s);    char *p=d;        /* Transform the 3x8 bits to 4x6 bits, as required by base64. */    for (i = 0; i < length; i += 3)    {        *p++ = tbl[s[0] >> 2];        *p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];        *p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];        *p++ = tbl[s[2] & 0x3f];        s += 3;    }        /* Pad the result if necessary... */    if (i == length + 1)        *(p - 1) = '=';    else if (i == length + 2)        *(p - 1) = *(p - 2) = '=';        /* ...and zero-terminate it. */    *p = '\0';}/********************************************************************************** http.c**** Copyright (C) 2000 by Moez Mahfoudh <mmoez@bigfoot.com>.** 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.********************************************************************************/

⌨️ 快捷键说明

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