示例#1
0
static void
add_static_entry (cherokee_plugin_loader_t *loader,
		  const char               *name,
		  void                     *info)
{
	entry_t *entry;

	entry = malloc (sizeof(entry_t));
	entry->dlopen_ref = dlopen (NULL, RTLD_BASE);
	entry->info       = info;
	entry->built_in   = true;

	cherokee_avl_add_ptr (&loader->table, (char *)name, entry);
}
示例#2
0
static ret_t
parse_value (cherokee_buffer_t *value, cherokee_avl_t *extensions)
{
	char              *val;
	char              *tmpp;
	cherokee_buffer_t  tmp = CHEROKEE_BUF_INIT;

	TRACE(ENTRIES, "Adding extensions: '%s'\n", value->buf);
	cherokee_buffer_add_buffer (&tmp, value);

	tmpp = tmp.buf;
	while ((val = strsep(&tmpp, ",")) != NULL) {
		TRACE(ENTRIES, "Adding extension: '%s'\n", val);
		cherokee_avl_add_ptr (extensions, val, (void *)MAGIC);
	}

	cherokee_buffer_mrproper (&tmp);
	return ret_ok;
}
示例#3
0
static ret_t
parse_contry_list (cherokee_buffer_t *value, cherokee_avl_t *countries)
{
	char              *val;
	char              *tmpp;
	cherokee_buffer_t  tmp = CHEROKEE_BUF_INIT;

	TRACE(ENTRIES, "Adding geoip countries: '%s'\n", value->buf);
	cherokee_buffer_add_buffer (&tmp, value);

	tmpp = tmp.buf;
	while ((val = strsep(&tmpp, ",")) != NULL) {
		TRACE(ENTRIES, "Adding country: '%s'\n", val);
		cherokee_avl_add_ptr (countries, val, (void *)MAGIC);
	}

	cherokee_buffer_mrproper (&tmp);
	return ret_ok;
}
示例#4
0
static ret_t
_add (cherokee_regex_table_t *table, char *pattern, void **regex)
{
	ret_t      ret;
	const char *error_msg;
	int         error_offset;
	void       *tmp           = NULL;

	/* It wasn't in the cache. Lets go to compile the pattern..
	 * First of all, we have to check again the table because another
	 * thread could create a new entry after the previous unlock.
	 */
	CHEROKEE_RWLOCK_WRITER (&table->rwlock);

	ret = cherokee_avl_get_ptr (&table->cache, pattern, &tmp);
	if ((tmp != NULL) && (ret == ret_ok)) {
		if (regex != NULL)
			*regex = tmp;

		CHEROKEE_RWLOCK_UNLOCK (&table->rwlock);
		return ret_ok;
	}

	tmp = pcre_compile (pattern, 0, &error_msg, &error_offset, NULL);
	if (tmp == NULL) {
		LOG_ERROR (CHEROKEE_ERROR_REGEX_COMPILATION, pattern, error_msg, error_offset);
		CHEROKEE_RWLOCK_UNLOCK (&table->rwlock);
		return ret_error;
	}

	cherokee_avl_add_ptr (&table->cache, pattern, tmp);
	CHEROKEE_RWLOCK_UNLOCK (&table->rwlock);

	if (regex != NULL)
		*regex = tmp;

	return ret_ok;
}
示例#5
0
static ret_t
add_user  (char *val, void *data)
{
	return cherokee_avl_add_ptr (AVL(data), val, NULL);
}
示例#6
0
static ret_t
load_common (cherokee_plugin_loader_t *loader,
	     const char               *modname,
	     int                       flags)
{
	ret_t                   ret;
	entry_t                *entry     = NULL;
	cherokee_plugin_info_t *info      = NULL;
	void                   *dl_handle = NULL;

	/* If it is already loaded just return
	 */
	ret = cherokee_avl_get_ptr (&loader->table, modname, (void **)&entry);
	if (ret == ret_ok)
		return ret_ok;

	/* Check deps
	 */
	ret = check_deps_file (loader, modname);
	if (ret != ret_ok)
		return ret;

	/* Get the module info
	 */
	ret = get_info (loader, modname, flags, &info, &dl_handle);
	switch (ret) {
	case ret_ok:
		break;
	case ret_error:
		LOG_ERROR (CHEROKEE_ERROR_PLUGIN_NO_OPEN, modname);
		return ret;
	case ret_not_found:
		LOG_ERROR (CHEROKEE_ERROR_PLUGIN_NO_INFO, modname);
		return ret;
	default:
		SHOULDNT_HAPPEN;
		return ret_error;
	}

	/* Add new entry
	 */
	entry = malloc (sizeof(entry_t));
	entry->dlopen_ref = dl_handle;
	entry->info       = info;
	entry->built_in   = false;

	ret = cherokee_avl_add_ptr (&loader->table, modname, entry);
	if (unlikely(ret != ret_ok)) {
		dlclose (entry->dlopen_ref);
		free(entry);
		return ret;
	}

	/* Execute init function
	 */
	ret = execute_init_func (loader, modname, entry);
	if (ret != ret_ok) {
		return ret;
	}

	return ret_ok;
}