亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? hash.c

?? boa 一個簡小的web服務器 資源占用極少
?? C
字號:
/*
 *  Boa, an http server
 *  Copyright (C) 1995 Paul Phillips <paulp@go2net.com>
 *  Some changes Copyright (C) 1996 Larry Doolittle <ldoolitt@boa.org>
 *  Some changes Copyright (C) 1997 Jon Nelson <jnelson@boa.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 1, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/* $Id: hash.c,v 1.14.4.4 2002/07/30 03:59:26 jnelson Exp $*/

#include "boa.h"
#include "parse.h"

/*
 * There are two hash tables used, each with a key/value pair
 * stored in a hash_struct.  They are:
 *
 * mime_hashtable:
 *     key = file extension
 *   value = mime type
 *
 * passwd_hashtable:
 *     key = username
 *   value = home directory
 *
 */

struct _hash_struct_ {
    char *key;
    char *value;
    struct _hash_struct_ *next;
};

typedef struct _hash_struct_ hash_struct;

static hash_struct *mime_hashtable[MIME_HASHTABLE_SIZE];
static hash_struct *passwd_hashtable[PASSWD_HASHTABLE_SIZE];

#ifdef WANT_ICKY_HASH
static unsigned four_char_hash(char *buf);
#define boa_hash four_char_hash
#else
#ifdef WANT_SDBM_HASH
static unsigned sdbm_hash(char *str);
#define boa_hash sdbm_hash
#else
static unsigned djb2_hash(char *str);
#define boa_hash djb2_hash
#endif
#endif

#ifdef WANT_ICKY_HASH
static unsigned four_char_hash(char *buf)
{
    unsigned int hash = (buf[0] +
                     (buf[1] ? buf[1] : 241 +
                     (buf[2] ? buf[2] : 251 +
                      (buf[3] ? buf[3] : 257))));
#ifdef DEBUG_HASH
    log_error_time();
    fprintf(stderr, "four_char_hash(%s) = %u\n", buf, hash);
#endif
    return hash;
}

/* The next two hashes taken from
 * http://www.cs.yorku.ca/~oz/hash.html
 *
 * In my (admittedly) very brief testing, djb2_hash performed
 * very slightly better than sdbm_hash.
 */

#else
#define MAX_HASH_LENGTH 4
#ifdef WANT_SDBM_HASH
static unsigned sdbm_hash(char *str)
{
    unsigned hash = 0;
    int c;
    short count = MAX_HASH_LENGTH;

#ifdef DEBUG_HASH
    log_error_time();
    fprintf(stderr, "sdbm_hash(%s) = ", str);
#endif

    while ((c = *str++) && count--)
        hash = c + (hash << 6) + (hash << 16) - hash;

#ifdef DEBUG_HASH
    fprintf(stderr, "%u\n", hash);
#endif
    return hash;
}
#else

static unsigned djb2_hash(char *str)
{
    unsigned hash = 5381;
    int c;
    short count = MAX_HASH_LENGTH;

#ifdef DEBUG_HASH
    log_error_time();
    fprintf(stderr, "djb2_hash(%s) = ", str);
#endif

    while ((c = *(str++)) && count--)
        hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

#ifdef DEBUG_HASH
    fprintf(stderr, "%u\n", hash);
#endif
    return hash;
}
#endif
#endif

/*
 * Name: add_mime_type
 * Description: Adds a key/value pair to the mime_hashtable
 */

void add_mime_type(char *extension, char *type)
{
    unsigned int hash;
    hash_struct *current, *next;

    if (!extension)
        return;

    hash = get_mime_hash_value(extension);

    current = mime_hashtable[hash];

    while (current) {
        if (!strcmp(current->key, extension))
            return;         /* don't add extension twice */
        if (current->next)
            current = current->next;
        else
            break;
    }

    /* if here, we need to add a new one */
    next = (hash_struct *) malloc(sizeof (hash_struct));
    if (!next) {
        DIE("malloc of hash_struct failed!");
    }
    next->key = strdup(extension);
    if (!next->key)
        DIE("malloc of hash_struct->key failed!");
    next->value = strdup(type);
    if (!next->value)
        DIE("malloc of hash_struct->value failed!");
    next->next = NULL;

    if (!current) {
        mime_hashtable[hash] = next;
    } else {
        current->next = next;
    }
}

/*
 * Name: get_mime_hash_value
 *
 * Description: adds the ASCII values of the file extension letters
 * and mods by the hashtable size to get the hash value
 */

unsigned get_mime_hash_value(char *extension)
{
    unsigned int hash = 0;

    if (extension == NULL || extension[0] == '\0') {
        /* FIXME */
        log_error_time();
        fprintf(stderr, "Attempt to hash NULL or empty string!\n");
        return 0;
    }

    hash = boa_hash(extension);
    hash %= MIME_HASHTABLE_SIZE;

    return hash;
}

/*
 * Name: get_mime_type
 *
 * Description: Returns the mime type for a supplied filename.
 * Returns default type if not found.
 */

char *get_mime_type(char *filename)
{
    char *extension;
    hash_struct *current;

    unsigned int hash;

    extension = strrchr(filename, '.');

    if (!extension || *extension++ == '\0')
        return default_type;

    hash = get_mime_hash_value(extension);
    current = mime_hashtable[hash];

    while (current) {
        if (!strcmp(current->key, extension)) /* hit */
            return current->value;
        current = current->next;
    }

    return default_type;
}

/*
 * Name: get_homedir_hash_value
 *
 * Description: adds the ASCII values of the username letters
 * and mods by the hashtable size to get the hash value
 */

unsigned get_homedir_hash_value(char *name)
{
    unsigned int hash = 0;

    if (name == NULL || name[0] == '\0') {
        /* FIXME */
        log_error_time();
        fprintf(stderr, "Attempt to hash NULL or empty string!\n");
        return 0;
    }

    hash = boa_hash(name);
    hash %= PASSWD_HASHTABLE_SIZE;

    return hash;
}


/*
 * Name: get_home_dir
 *
 * Description: Returns a point to the supplied user's home directory.
 * Adds to the hashtable if it's not already present.
 *
 */

char *get_home_dir(char *name)
{
    struct passwd *passwdbuf;

    hash_struct *current, *next;
    unsigned int hash;

    /* first check hash table -- if username is less than four characters,
       just hash to zero (this should be very rare) */

    hash = get_homedir_hash_value(name);

    for(current = passwd_hashtable[hash];current;current = current->next) {
        if (!strcmp(current->key, name)) /* hit */
            return current->value;
        if (!current->next)
            break;
    }

    /* if here, we have to add a new one */

    passwdbuf = getpwnam(name);

    if (!passwdbuf)         /* does not exist */
        return NULL;

    next = (hash_struct *) malloc(sizeof (hash_struct));
    if (!next) {
        WARN("malloc of hash_struct for passwd_hashtable failed!");
        return NULL;
    }

    next->key = strdup(name);
    if (!next->key) {
        WARN("malloc of passwd_hashtable[hash]->key failed!");
        free(next);
        return NULL;
    }
    next->value = strdup(passwdbuf->pw_dir);
    if (!next->value) {
        WARN("malloc of passwd_hashtable[hash]->value failed!");
        free(next->key);
        free(next);
        return NULL;
    }
    next->next = NULL;

    if (!current) {
        passwd_hashtable[hash] = next;
    } else {
        current->next = next;
    }
    return next->value;
}

void dump_mime(void)
{
    int i;
    hash_struct *temp;
    for (i = 0; i < MIME_HASHTABLE_SIZE; ++i) { /* these limits OK? */
        temp = mime_hashtable[i];
        while (temp) {
            hash_struct *temp_next;

            temp_next = temp->next;
            free(temp->key);
            free(temp->value);
            free(temp);

            temp = temp_next;
        }
        mime_hashtable[i] = NULL;
    }
}

void dump_passwd(void)
{
    int i;
    hash_struct *temp;
    for (i = 0; i < PASSWD_HASHTABLE_SIZE; ++i) { /* these limits OK? */
        temp = passwd_hashtable[i];
        while (temp) {
            hash_struct *temp_next;

            temp_next = temp->next;
            free(temp->key);
            free(temp->value);
            free(temp);

            temp = temp_next;
        }
        passwd_hashtable[i] = NULL;
    }
}

void show_hash_stats(void)
{
    int i;
    hash_struct *temp;
    int total = 0;
    int count;

    for (i = 0; i < MIME_HASHTABLE_SIZE; ++i) { /* these limits OK? */
        if (mime_hashtable[i]) {
            count = 0;
            temp = mime_hashtable[i];
            while (temp) {
                temp = temp->next;
                ++count;
            }
#ifdef NOISY_SIGALRM
            log_error_time();
            fprintf(stderr, "mime_hashtable[%d] has %d entries\n",
                    i, count);
#endif
            total += count;
        }
    }
    log_error_time();
    fprintf(stderr, "mime_hashtable has %d total entries\n",
            total);

    total = 0;
    for (i = 0; i < PASSWD_HASHTABLE_SIZE; ++i) { /* these limits OK? */
        if (passwd_hashtable[i]) {
            temp = passwd_hashtable[i];
            count = 0;
            while (temp) {
                temp = temp->next;
                ++count;
            }
#ifdef NOISY_SIGALRM
            log_error_time();
            fprintf(stderr, "passwd_hashtable[%d] has %d entries\n",
                    i, count);
#endif
            total += count;
        }
    }

    log_error_time();
    fprintf(stderr, "passwd_hashtable has %d total entries\n",
            total);

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区欧美一区| 欧美激情一区在线观看| aaa国产一区| 国内精品免费**视频| 蜜桃视频第一区免费观看| 日韩成人午夜电影| 老司机精品视频一区二区三区| 亚洲成av人综合在线观看| 亚洲高清视频的网址| 丝袜美腿亚洲综合| 毛片基地黄久久久久久天堂| 久久99国产精品尤物| 国内国产精品久久| 成人性生交大片| 91在线国内视频| 欧美中文字幕一区| 日韩一区二区三区视频| 精品99久久久久久| 国产精品美女久久久久久久久 | 亚洲自拍另类综合| 亚洲福利电影网| 日日骚欧美日韩| 激情欧美一区二区三区在线观看| 国产九色精品成人porny | 亚洲一区二区三区自拍| 性久久久久久久久久久久| 日韩av成人高清| 国产一区二区看久久| 91网页版在线| 日韩一区二区三区免费看| 国产亚洲欧美一级| 亚洲成人精品影院| 国产精品18久久久久久vr| 9l国产精品久久久久麻豆| 欧美区在线观看| 日本一区二区成人在线| 亚洲国产日韩精品| 国产乱码精品一区二区三| 色呦呦一区二区三区| 日韩一区二区在线看| 亚洲免费伊人电影| 狠狠v欧美v日韩v亚洲ⅴ| 91视视频在线观看入口直接观看www | 经典三级在线一区| 99久久99久久精品免费观看| 91精品国产入口在线| 国产精品午夜春色av| 美女一区二区三区在线观看| av毛片久久久久**hd| 欧美一卡2卡3卡4卡| 亚洲卡通欧美制服中文| 国产电影精品久久禁18| 91精品综合久久久久久| 一区二区在线观看免费| 国产精品影视网| 欧美三级中文字| 亚洲视频 欧洲视频| 国产一区二区福利视频| 7777精品伊人久久久大香线蕉经典版下载| 欧美激情中文不卡| 国产乱码精品一区二区三区av | 激情另类小说区图片区视频区| 91在线国内视频| 国产欧美综合在线观看第十页| 丝袜亚洲精品中文字幕一区| 欧美又粗又大又爽| 亚洲免费三区一区二区| 国产精品一二三区| 26uuu亚洲综合色欧美| 奇米影视一区二区三区小说| 欧美日韩黄色影视| 亚洲午夜视频在线观看| 日本高清视频一区二区| 亚洲欧美激情插| 成人国产一区二区三区精品| 国产精品色噜噜| 国产a视频精品免费观看| 久久精品亚洲乱码伦伦中文 | 国产视频一区二区在线| 久久超碰97人人做人人爱| 日韩一区二区三区视频| 青青草国产精品97视觉盛宴| 欧美一区二区免费| 久久国产精品无码网站| 欧美精品一区二区三区久久久 | 99视频精品全部免费在线| 国产精品免费免费| 色乱码一区二区三区88| 亚洲综合久久av| 制服.丝袜.亚洲.中文.综合| 日本不卡在线视频| 久久只精品国产| 国产成人av福利| 亚洲日本丝袜连裤袜办公室| 91国偷自产一区二区三区观看| 一区二区三区91| 日韩欧美不卡在线观看视频| 韩国在线一区二区| 亚洲色图一区二区三区| 欧美色图在线观看| 美腿丝袜亚洲综合| 中文字幕不卡在线播放| 日本黄色一区二区| 精品一区免费av| 欧美激情中文不卡| 91成人国产精品| 麻豆成人免费电影| 国产精品久久久久久亚洲伦 | 日韩你懂的在线观看| 国产成人精品免费网站| 一区二区在线观看视频在线观看| 日韩一本二本av| av高清不卡在线| 轻轻草成人在线| 中文字幕在线不卡国产视频| 制服丝袜中文字幕亚洲| 不卡一卡二卡三乱码免费网站| 亚洲一区二区精品久久av| 精品乱码亚洲一区二区不卡| 一本久久a久久免费精品不卡| 免费观看30秒视频久久| 亚洲欧美日韩在线不卡| 久久亚洲一级片| 在线免费不卡视频| 国产成人精品免费一区二区| 亚洲va韩国va欧美va精品| 亚洲国产精品成人综合色在线婷婷 | 99国产精品国产精品毛片| 日韩精品1区2区3区| 一区视频在线播放| 欧美videos大乳护士334| 欧美亚一区二区| av中文字幕在线不卡| 国产一区二区三区四| 日韩在线卡一卡二| 亚洲精品国产精华液| 国产精品久久久一本精品| 欧美一级在线观看| 欧美肥妇free| 欧美综合一区二区三区| av一二三不卡影片| 岛国精品在线观看| 国产在线麻豆精品观看| 青青国产91久久久久久| 午夜精品久久久久久久久| 亚洲欧美一区二区久久| 国产日韩欧美高清| 久久综合九色综合97_久久久| 91精品国产色综合久久久蜜香臀| 欧美日韩国产成人在线91| 色老汉av一区二区三区| 成人动漫一区二区在线| 国产成人免费在线观看| 蜜桃一区二区三区在线观看| 奇米在线7777在线精品| 麻豆成人久久精品二区三区小说| 裸体一区二区三区| 久久成人18免费观看| 国产原创一区二区三区| 国产一区亚洲一区| 国产精品综合久久| 国产suv精品一区二区883| 成人av在线一区二区| av中文字幕一区| 欧美中文字幕亚洲一区二区va在线| 一本大道av伊人久久综合| 欧美无砖专区一中文字| 欧美日韩国产影片| 日韩三级视频在线看| 精品久久久久av影院| 久久精品视频免费| 亚洲欧洲成人精品av97| 一区二区不卡在线播放| 婷婷成人综合网| 久草精品在线观看| 成人国产视频在线观看| 欧美日韩亚洲综合在线| 日韩欧美第一区| 久久精品水蜜桃av综合天堂| 亚洲欧美偷拍卡通变态| 亚洲成人av中文| 国产精品99久久久久久久女警| 成人h动漫精品| 欧美日韩成人一区| 久久精品视频在线看| 亚洲在线免费播放| 麻豆国产精品官网| 色一区在线观看| 精品国产乱码久久久久久老虎| 国产欧美一区二区精品婷婷| 一个色在线综合| 国产在线精品一区二区| 91久久精品网| 精品成人在线观看| 一区二区三区在线免费播放| 免费观看日韩av| 欧洲一区在线电影| 久久综合九色综合欧美亚洲| 亚洲一区二区三区影院| 国产成人精品免费网站|