Example #1
0
static int on_config_files(h2o_configurator_t *configurator, h2o_context_t *ctx, const char *config_file, yoml_t *config_node)
{
    size_t i;

    if (config_node->type != YOML_TYPE_MAPPING) {
        h2o_context_print_config_error(configurator, config_file, config_node, "argument must be a mapping");
        return -1;
    }

    for (i = 0; i != config_node->data.mapping.size; ++i) {
        yoml_t *key = config_node->data.mapping.elements[i].key;
        yoml_t *value = config_node->data.mapping.elements[i].value;
        if (key->type != YOML_TYPE_SCALAR) {
            h2o_context_print_config_error(configurator, config_file, key, "key (representing the virtual path) must be a string");
            return -1;
        }
        if (value->type != YOML_TYPE_SCALAR) {
            h2o_context_print_config_error(configurator, config_file, key, "value (representing the local path) must be a string");
            return -1;
        }
        h2o_register_file_handler(ctx, key->data.scalar, value->data.scalar, "index.html" /* FIXME */);
    }

    return 0;
}
Example #2
0
static int on_config_mime_types(h2o_configurator_t *configurator, h2o_context_t *ctx, const char *config_file, yoml_t *config_node)
{
    size_t i;

    if (config_node->type != YOML_TYPE_MAPPING) {
        h2o_context_print_config_error(configurator, config_file, config_node, "argument must be a mapping");
        return -1;
    }

    for (i = 0; i != config_node->data.mapping.size; ++i) {
        yoml_t *key = config_node->data.mapping.elements[i].key;
        yoml_t *value = config_node->data.mapping.elements[i].value;
        if (key->type != YOML_TYPE_SCALAR) {
            h2o_context_print_config_error(configurator, config_file, key, "key (representing the extension) must be a string");
            return -1;
        }
        if (value->type != YOML_TYPE_SCALAR) {
            h2o_context_print_config_error(configurator, config_file, config_node, "value (representing the mime-type) must be a string");
            return -1;
        }
        h2o_define_mimetype(&ctx->mimemap, key->data.scalar, value->data.scalar);
    }

    return 0;
}
Example #3
0
static int on_config_port(h2o_configurator_t *_conf, h2o_context_t *ctx, const char *config_file, yoml_t *config_node)
{
    struct port_configurator_t *conf = (void*)_conf;

    if (config_node->type != YOML_TYPE_SCALAR
        || sscanf(config_node->data.scalar, "%hu", &conf->port) != 1) {
        h2o_context_print_config_error(&conf->super, config_file, config_node, "argument is not a valid port number");
        return -1;
    }

    return 0;
}