Ejemplo n.º 1
0
static ret_t
configure (cherokee_rule_header_t    *rule,
	   cherokee_config_node_t    *conf,
	   cherokee_virtual_server_t *vsrv)
{
	ret_t                   ret;
	cherokee_buffer_t      *type     = NULL;
	cherokee_buffer_t      *header   = NULL;
	cherokee_regex_table_t *regexs   = VSERVER_SRV(vsrv)->regexs;

	/* Read the header
	 */
	ret = cherokee_config_node_read (conf, "header", &header);
	if (ret != ret_ok) {
		LOG_ERROR (CHEROKEE_ERROR_RULE_NO_PROPERTY,
			   RULE(rule)->priority, "header");
		return ret_error;
	}

	ret = header_str_to_type (header, &rule->header);
	if (ret != ret_ok) {
		return ret;
	}

	/* Type
	 */
	ret = cherokee_config_node_read (conf, "type", &type);
	if (ret == ret_ok) {
		ret = type_str_to_type (type, &rule->type);
		if (ret != ret_ok) {
			return ret;
		}
	}

	/* Read the match
	 */
	ret = cherokee_config_node_copy (conf, "match", &rule->match);
	if (ret != ret_ok) {
		if (equal_buf_str (type, "regex")) {
			LOG_ERROR (CHEROKEE_ERROR_RULE_NO_PROPERTY,
				   RULE(rule)->priority, "match");
			return ret_error;
		}
	}

	/* Compile the regular expression
	 */
	if (! cherokee_buffer_is_empty (&rule->match)) {
		ret = cherokee_regex_table_add (regexs, rule->match.buf);
		if (ret != ret_ok)
			return ret;

		ret = cherokee_regex_table_get (regexs, rule->match.buf, &rule->pcre);
		if (ret != ret_ok)
			return ret;
	}

	return ret_ok;
}
Ejemplo n.º 2
0
static ret_t
configure_rewrite_entry (cherokee_list_t        *list,
			 cherokee_config_node_t *conf,
			 cherokee_regex_table_t *regexs)
{
	ret_t                   ret;
	cherokee_regex_entry_t *n;
	cherokee_buffer_t      *substring;
	cherokee_boolean_t      hidden     = true;
	pcre                   *re         = NULL;
	cherokee_buffer_t      *regex      = NULL;

	TRACE(ENTRIES, "Converting rewrite rule '%s'\n", conf->key.buf);

	/* Query conf
	 */
	cherokee_config_node_read_bool (conf, "show", &hidden);
	hidden = !hidden;

	ret = cherokee_config_node_read (conf, "regex", &regex);
	if (ret == ret_ok) {
		ret = cherokee_regex_table_get (regexs, regex->buf, (void **)&re);
		if (ret != ret_ok)
			return ret;
	}

	ret = cherokee_config_node_read (conf, "substring", &substring);
	if (ret != ret_ok)
		return ret;

	/* New RegEx
	 */
	n = (cherokee_regex_entry_t *) malloc(sizeof(cherokee_regex_entry_t));
	if (unlikely (n == NULL))
		return ret_nomem;

	INIT_LIST_HEAD (&n->listed);
	n->re         = re;
	n->hidden     = hidden;

	cherokee_buffer_init (&n->subs);
	cherokee_buffer_add_buffer (&n->subs, substring);

	/* Add the list
	 */
	cherokee_list_add_tail (&n->listed, list);
	return ret_ok;
}
Ejemplo n.º 3
0
static ret_t
config_read_type (cherokee_config_node_t         *config,
                  cherokee_logger_writer_types_t *type)
{
	ret_t              ret;
	cherokee_buffer_t *tmp = NULL;

	ret = cherokee_config_node_read (config, "type", &tmp);
	if (ret != ret_ok) {
		LOG_ERROR_S (CHEROKEE_ERROR_LOGGER_NO_WRITER);
		return ret_error;
	}

	if (equal_buf_str (tmp, "syslog")) {
		*type = cherokee_logger_writer_syslog;
	} else if (equal_buf_str (tmp, "stderr")) {
		*type = cherokee_logger_writer_stderr;
	} else if (equal_buf_str (tmp, "file")) {
		*type = cherokee_logger_writer_file;
	} else if (equal_buf_str (tmp, "exec")) {
		*type = cherokee_logger_writer_pipe;
	} else {
		LOG_CRITICAL (CHEROKEE_ERROR_LOGGER_WRITER_UNKNOWN, tmp->buf);
		return ret_error;
	}

	return ret_ok;
}
Ejemplo n.º 4
0
ret_t
cherokee_logger_writer_get_id (cherokee_config_node_t   *config,
                               cherokee_buffer_t        *id)
{
	ret_t                           ret;
	cherokee_buffer_t              *tmp;
	cherokee_logger_writer_types_t  type;

	ret = config_read_type (config, &type);
	if (ret != ret_ok) {
		return ret;
	}

	switch (type) {
	case cherokee_logger_writer_syslog:
		cherokee_buffer_add_str (id, "syslog");
		break;
	case cherokee_logger_writer_stderr:
		cherokee_buffer_add_str (id, "stderr");
		break;
	case cherokee_logger_writer_file:
		ret = cherokee_config_node_read (config, "filename", &tmp);
		if (ret == ret_ok) {
			cherokee_buffer_add_buffer (id,  tmp);
		} else {
			cherokee_buffer_add_str (id,  "unknown");
		}
		break;
	case cherokee_logger_writer_pipe:
		ret = cherokee_config_node_read (config, "command", &tmp);
		if (ret == ret_ok) {
			cherokee_buffer_add_buffer (id,  tmp);
		} else {
			cherokee_buffer_add_str (id,  "unknown");
		}
		break;
	default:
		SHOULDNT_HAPPEN;
		return ret_error;
	}

	return ret_ok;
}
Ejemplo n.º 5
0
static ret_t
try_read_dh_param(cherokee_config_node_t  *conf,
		  DH                     **dh,
		  int                      bitsize)
{
	ret_t              ret;
	cherokee_buffer_t *buf;
	FILE              *paramfile = NULL;
	cherokee_buffer_t  confentry = CHEROKEE_BUF_INIT;

	cherokee_buffer_add_va (&confentry, "dh_param%d", bitsize);

	/* Read the configuration parameter
	 */
	ret = cherokee_config_node_read (conf, confentry.buf, &buf);
	if (ret != ret_ok) {
		ret = ret_ok;
		goto out;
	}

	/* Read the file
	 */
	paramfile = fopen (buf->buf, "r");
	if (paramfile == NULL) {
		TRACE(ENTRIES, "Cannot open file %s\n", buf->buf);
		ret = ret_file_not_found;
		goto out;
	}

	/* Process the content
	 */
	*dh = PEM_read_DHparams (paramfile, NULL, NULL, NULL);
	if (*dh == NULL) {
		TRACE(ENTRIES, "Failed to load PEM %s\n", buf->buf);
		ret = ret_error;
		goto out;
	}

	ret = ret_ok;

out:
	/* Clean up
	 */
	if (paramfile != NULL) {
		fclose (paramfile);
	}

	cherokee_buffer_mrproper (&confentry);
	return ret;
}
Ejemplo n.º 6
0
ret_t
cherokee_header_op_configure (cherokee_header_op_t   *op,
                              cherokee_config_node_t *conf)
{
	ret_t              ret;
	cherokee_buffer_t *tmp;

	/* Operation type
	 */
	ret = cherokee_config_node_read (conf, "type", &tmp);
	if (ret != ret_ok) {
		free (op);
		return ret_error;
	}

	if (cherokee_buffer_case_cmp_str (tmp, "add") == 0) {
		op->op = cherokee_header_op_add;
	} else if (cherokee_buffer_case_cmp_str (tmp, "del") == 0) {
		op->op = cherokee_header_op_del;
	} else {
		free (op);
		return ret_error;
	}

	/* Details
	 */
	ret = cherokee_config_node_copy (conf, "header", &op->header);
	if (ret != ret_ok) {
		free (op);
		return ret_error;
	}

	if (op->op == cherokee_header_op_add) {
		ret = cherokee_config_node_copy (conf, "value", &op->value);
		if (ret != ret_ok) {
			cherokee_buffer_mrproper (&op->header);
			free (op);
			return ret_error;
		}
	}

	return ret_ok;
}
Ejemplo n.º 7
0
static ret_t
configure (cherokee_rule_geoip_t       *rule,
	   cherokee_config_node_t    *conf,
	   cherokee_virtual_server_t *vsrv)
{
	ret_t              ret;
	cherokee_buffer_t *tmp = NULL;

	UNUSED(vsrv);

	ret = cherokee_config_node_read (conf, "countries", &tmp);
	if (ret != ret_ok) {
		LOG_CRITICAL (CHEROKEE_ERROR_RULE_NO_PROPERTY,
			      RULE(rule)->priority, "geoip");
		return ret_error;
	}

	return parse_contry_list (tmp, &rule->countries);
}
Ejemplo n.º 8
0
static ret_t
configure (cherokee_rule_extensions_t *rule,
	   cherokee_config_node_t     *conf,
	   cherokee_virtual_server_t  *vsrv)
{
	ret_t              ret;
	cherokee_buffer_t *tmp = NULL;

	UNUSED(vsrv);

	ret = cherokee_config_node_read (conf, "extensions", &tmp);
	if (ret != ret_ok) {
		LOG_CRITICAL (CHEROKEE_ERROR_RULE_NO_PROPERTY,
			      RULE(rule)->priority, "extensions");
		return ret_error;
	}

	cherokee_config_node_read_bool (conf, "check_local_file", &rule->check_local_file);
	cherokee_config_node_read_bool (conf, "iocache",          &rule->use_iocache);

	return parse_value (tmp, &rule->extensions);
}
Ejemplo n.º 9
0
ret_t
cherokee_logger_writer_configure (cherokee_logger_writer_t *writer, cherokee_config_node_t *config)
{
	ret_t              ret;
	cherokee_buffer_t *tmp = NULL;

	/* Check the type
	 */
	ret = config_read_type (config, &writer->type);
	if (ret != ret_ok) {
		return ret;
	}

	/* Extra properties
	 */
	switch (writer->type) {
	case cherokee_logger_writer_file:
		ret = cherokee_config_node_read (config, "filename", &tmp);
		if (ret != ret_ok) {
			LOG_ERROR (CHEROKEE_ERROR_LOGGER_WRITER_READ, "file");
			return ret_error;
		}
		cherokee_buffer_add_buffer (&writer->filename, tmp);
		break;

	case cherokee_logger_writer_pipe:
		ret = cherokee_config_node_read (config, "command", &tmp);
		if (ret != ret_ok) {
			LOG_ERROR (CHEROKEE_ERROR_LOGGER_WRITER_READ, "exec");
			return ret_error;
		}
		cherokee_buffer_add_buffer (&writer->command, tmp);
		break;
	default:
		break;
	}

	/* Reside the internal buffer if needed
	 */
	ret = cherokee_config_node_read (config, "bufsize", &tmp);
	if (ret == ret_ok) {
		int buf_len;

		ret = cherokee_atoi (tmp->buf, &buf_len);
		if (ret != ret_ok) {
			return ret_error;
		}

		if (buf_len < LOGGER_MIN_BUFSIZE)
			buf_len = LOGGER_MIN_BUFSIZE;
		else if (buf_len > LOGGER_MAX_BUFSIZE)
			buf_len = LOGGER_MAX_BUFSIZE;

		cherokee_buffer_mrproper (&writer->buffer);
		cherokee_buffer_init (&writer->buffer);

		ret = cherokee_buffer_ensure_size (&writer->buffer, buf_len);
		if (ret != ret_ok) {
			LOG_ERROR (CHEROKEE_ERROR_LOGGER_WRITER_ALLOC, writer->max_bufsize);
			return ret_nomem;
		}

		writer->max_bufsize = (size_t)buf_len;
	}

	return ret_ok;
}