コード例 #1
0
ファイル: mod_memcached.c プロジェクト: Aivaras/lighttpd2
static void mc_ctx_build_key(GString *dest, memcached_ctx *ctx, liVRequest *vr) {
	GMatchInfo *match_info = NULL;

	if (vr->action_stack.regex_stack->len) {
		GArray *rs = vr->action_stack.regex_stack;
		match_info = g_array_index(rs, liActionRegexStackElement, rs->len - 1).match_info;
	}

	g_string_truncate(dest, 0);
	li_pattern_eval(vr, dest, ctx->pattern, NULL, NULL, li_pattern_regex_cb, match_info);

	li_memcached_mutate_key(dest);
}
コード例 #2
0
ファイル: mod_redirect.c プロジェクト: AlexShiLucky/lighttpd2
static gboolean redirect_internal(liVRequest *vr, GString *dest, redirect_rule *rule) {
	gchar *path;
	GMatchInfo *match_info = NULL;
	GMatchInfo *prev_match_info = NULL;

	path = vr->request.uri.path->str;

	if (NULL != rule->regex && !g_regex_match(rule->regex, path, 0, &match_info)) {
		if (match_info) {
			g_match_info_free(match_info);
		}

		return FALSE;
	}

	if (vr->action_stack.regex_stack->len) {
		GArray *rs = vr->action_stack.regex_stack;
		prev_match_info = g_array_index(rs, liActionRegexStackElement, rs->len - 1).match_info;
	}

	g_string_truncate(dest, 0);

	switch (rule->type) {
	case REDIRECT_ABSOLUTE_URI:
		/* http://example.tld/foo/bar?baz */
		break;
	case REDIRECT_ABSOLUTE_PATH:
		/* /foo/bar?baz */
		g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
		g_string_append_len(dest, CONST_STR_LEN("://"));
		g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
		break;
	case REDIRECT_RELATIVE_PATH:
		/* foo/bar?baz */
		g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
		g_string_append_len(dest, CONST_STR_LEN("://"));
		g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
		/* search for last slash /foo/bar */
		{
			gchar *c;
			for (c = (vr->request.uri.path->str + vr->request.uri.path->len); c-- > vr->request.uri.path->str;) {
				if (*c == '/') break;
			}

			g_string_append_len(dest, vr->request.uri.path->str, c - vr->request.uri.path->str + 1);
		}
		break;
	case REDIRECT_RELATIVE_QUERY:
		/* ?bar */
		g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
		g_string_append_len(dest, CONST_STR_LEN("://"));
		g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
		g_string_append_len(dest, GSTR_LEN(vr->request.uri.path));
		break;
	}

	li_pattern_eval(vr, dest, rule->pattern, li_pattern_regex_cb, match_info, li_pattern_regex_cb, prev_match_info);

	if (match_info) {
		g_match_info_free(match_info);
	}

	return TRUE;
}