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

📄 config.c

📁 用于移植到嵌入式linux系统的boa http服务器
💻 C
📖 第 1 页 / 共 2 页
字号:
    char *type, *extension, *c2;    int len;    f = fopen(v1, "r");    if (f == NULL)        DIE("Can't open mime-types file");    while (fgets(buf, 255, f) != NULL) {        if (buf[0] == '\0' || buf[0] == '#' || buf[0] == '\n')            continue;        c2 = strchr(buf, '\n');        if (c2)            *c2 = '\0';        len = strcspn(buf, "\t ");        if (!len) {            DEBUG(DEBUG_CONFIG) {                log_error_time();                fprintf(stderr,                        "Improperly formatted mime-type: \"%s\"\n", buf);            }            continue;        }        buf[len] = '\0';        type = buf;        for (p = buf + len + 1; *p; ++p) {            if (isalnum(*p))                break;        }        for (len = strcspn(p, "\t "); len; len = strcspn(p, "\t ")) {            p[len] = '\0';            extension = p;            add_mime_type(extension, type);            /* blah blah */            for (p = p + len + 1; *p; ++p) {                if (isalnum(*p))                    break;            }        }    }    fclose(f);}static void c_add_alias(char *v1, char *v2, void *t){    DEBUG(DEBUG_CONFIG) {        log_error_time();        printf("Calling add_alias with args \"%s\", \"%s\", and %d\n",               v1, v2, *(int *) t);    }    add_alias(v1, v2, *(enum ALIAS *) t);}static void c_add_access(char *v1, char *v2, void *t){#ifdef ACCESS_CONTROL    access_add(v1, *(int *) t);#else    log_error_time();    fprintf(stderr,            "This version of Boa doesn't support access controls.\n"            "Please recompile with --enable-access-control.\n");#endif                          /* ACCESS_CONTROL */}struct ccommand *lookup_keyword(char *c){    struct ccommand *p;    DEBUG(DEBUG_CONFIG) {        log_error_time();        printf("Checking string '%s' against keyword list\n", c);    }    for (p = clist;         p < clist + (sizeof (clist) / sizeof (struct ccommand)); p++) {        if (strcasecmp(c, p->name) == 0)            return p;    }    return NULL;}static void apply_command(Command * p, char *args){    char *second;    switch (p->type) {    case STMT_NO_ARGS:        (p->action) (NULL, NULL, p->object);        break;    case STMT_ONE_ARG:        (p->action) (args, NULL, p->object);        break;    case STMT_TWO_ARGS:        /* FIXME: if no 2nd arg exists, we use NULL. Desirable? */        while (isspace(*args))            ++args;        if (*args == '\0') {            log_error_time();            fprintf(stderr, "expected at least 1 arg! (%s)\n", p->name);            exit(EXIT_FAILURE);        }        second = args;        while (!isspace(*second))            ++second;        if (*second == '\0') {            /* nuthin but spaces */            second = NULL;        } else {            *second = '\0';            ++second;            while (isspace(*second))                ++second;            if (*second == '\0') {                second = NULL;            }        }        (p->action) (args, second, p->object);        break;    default:        exit(EXIT_FAILURE);    }}static void trim(char *s){    char *c = s + strlen(s) - 1;    while (isspace(*c) && c > s) {        *c = '\0';        --c;    }}static void parse(FILE * f){    char buf[1025], *c;    Command *p;    int line = 0;    current_uid = getuid();    while (fgets(buf, 1024, f) != NULL) {        ++line;        if (buf[0] == '\0' || buf[0] == '#' || buf[0] == '\n')            continue;        /* kill the linefeed and any trailing whitespace */        trim(buf);        if (buf[0] == '\0')            continue;        /* look for multiple arguments */        c = buf;        while (!isspace(*c))            ++c;        if (*c == '\0') {            /* no args */            c = NULL;        } else {            /* one or more args */            *c = '\0';            ++c;        }        p = lookup_keyword(buf);        if (!p) {            log_error_time();            fprintf(stderr, "Line %d: Did not find keyword \"%s\"\n", line,                    buf);            exit(EXIT_FAILURE);        } else {            DEBUG(DEBUG_CONFIG) {                log_error_time();                fprintf(stderr,                        "Found keyword %s in \"%s\" (%s)!\n",                        p->name, buf, c);            }            apply_command(p, c);        }    }}/* * Name: read_config_files * * Description: Reads config files, then makes sure that * all required variables were set properly. */void read_config_files(void){    FILE *config;    current_uid = getuid();    if (!config_file_name) {        config_file_name = DEFAULT_CONFIG_FILE;    }#ifdef ACCESS_CONTROL    access_init();#endif                          /* ACCESS_CONTROL */    config = fopen(config_file_name, "r");    if (!config) {        fputs("Could not open boa.conf for reading.\n", stderr);        exit(EXIT_FAILURE);    }    parse(config);    fclose(config);    if (!server_name) {        struct hostent *he;        char temp_name[100];        if (gethostname(temp_name, 100) == -1) {            perror("gethostname:");            exit(EXIT_FAILURE);        }        he = gethostbyname(temp_name);        if (he == NULL) {            perror("gethostbyname:");            exit(EXIT_FAILURE);        }        server_name = strdup(he->h_name);        if (server_name == NULL) {            perror("strdup:");            exit(EXIT_FAILURE);        }    }    tempdir = getenv("TMP");    if (tempdir == NULL)        tempdir = "/tmp";    if (single_post_limit < 0) {        fprintf(stderr, "Invalid value for single_post_limit: %d\n",                single_post_limit);        exit(EXIT_FAILURE);    }    if (vhost_root && virtualhost) {        fprintf(stderr, "Both VHostRoot and VirtualHost were enabled, and "                "they are mutually exclusive.\n");        exit(EXIT_FAILURE);    }    if (vhost_root && document_root) {        fprintf(stderr,                "Both VHostRoot and DocumentRoot were enabled, and "                "they are mutually exclusive.\n");        exit(EXIT_FAILURE);    }    if (!default_vhost) {        default_vhost = DEFAULT_VHOST;    }#ifdef USE_SETRLIMIT    if (cgi_rlimit_cpu < 0)        cgi_rlimit_cpu = 0;    if (cgi_rlimit_data < 0)        cgi_rlimit_data = 0;    if (cgi_nice < 0)        cgi_nice = 0;#endif    if (max_connections < 1) {        struct rlimit rl;        int c;        /* has not been set explicitly */        c = getrlimit(RLIMIT_NOFILE, &rl);        if (c < 0) {            DIE("getrlimit");        }        max_connections = rl.rlim_cur;    }    if (max_connections > FD_SETSIZE - 20)        max_connections = FD_SETSIZE - 20;    if (ka_timeout < 0) ka_timeout=0;  /* not worth a message */    /* save some time */    default_timeout = (ka_timeout ? ka_timeout : REQUEST_TIMEOUT);#ifdef HAVE_POLL    default_timeout *= 1000;#endif    if (default_type == NULL) {        DIE("DefaultType *must* be set!");    }}

⌨️ 快捷键说明

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