Index: xcache-trunk/xcache.c
===================================================================
--- xcache-trunk/xcache.c	(révision 902)
+++ xcache-trunk/xcache.c	(copie de travail)
@@ -14,6 +14,8 @@
 
 #include <signal.h>
 
+#include <pwd.h>
+
 #include "php.h"
 #include "ext/standard/info.h"
 #include "ext/standard/md5.h"
@@ -118,6 +120,90 @@
 
 /* any function in *_unlocked is only safe be called within locked (single thread access) area */
 
+static zval* hg_internal_compute_prefix()
+{
+        zval* zprefix = NULL;
+        int userid = 33; // default id for www-data on Ubuntu
+	// we base the prefix on the user id because we use mpm-itk which run each virtual host under a specific user
+	// the prefix could be set via the INI settings
+        userid = getuid();
+        MAKE_STD_ZVAL(zprefix);
+        Z_TYPE_P(zprefix) = IS_LONG;
+        Z_LVAL_P(zprefix) = userid;
+        convert_to_string(zprefix);
+        return zprefix;
+}
+
+static int hg_internal_startwith_prefix(zval** name)
+{
+	char* from = NULL;
+	char* prefix = NULL;
+
+	zval* zprefix = hg_internal_compute_prefix();
+        prefix = Z_STRVAL_P(zprefix);
+	from = Z_STRVAL_PP(name);
+
+//	php_printf("from= %s<br />", from);
+//	php_printf("prefix= %s<br />", prefix);
+
+	if (strncmp(from, prefix, strlen(prefix)) == 0)
+	{
+//		php_printf("MATCH<br />");
+		return 1;
+	} else {
+		return 0;
+	}	
+}
+
+static void hg_internal_remove_prefix(zval** name)
+{
+	char* from = NULL;
+	char* to = NULL;
+	char* prefix = NULL;
+	int index = 0;
+
+	zval* zprefix = hg_internal_compute_prefix();
+	prefix = Z_STRVAL_P(zprefix);
+
+	from = Z_STRVAL_PP(name);
+	index = strlen(prefix) + 1;
+
+	to = emalloc(strlen(from) - index  + 2);
+	strncpy(to, from + index, strlen(from) - index + 1);
+
+	ZVAL_STRING(*name, to, 1);
+}
+
+static void hg_internal_prefix_entry_name(zval** name)
+{
+	char *string = NULL;
+	char *final = NULL;
+	char *prefix = NULL;
+
+	zval* zprefix = hg_internal_compute_prefix(); // get prefix, should be cache in some way
+	prefix = Z_STRVAL_P(zprefix);
+
+	convert_to_string(*name);
+
+//	php_printf("<br />zname original= ");
+//	PHPWRITE(Z_STRVAL_PP(name), Z_STRLEN_PP(name));
+
+	string = Z_STRVAL_PP(name);
+
+//	php_printf("<br />zprefix= ");
+//	PHPWRITE(Z_STRVAL_P(zprefix), Z_STRLEN_P(zprefix));
+
+	final = emalloc(strlen(prefix) + strlen(string) + 2);
+	snprintf(final, (strlen(prefix) + strlen(string) + 2), "%s_%s", prefix, string);
+//	php_printf("<br />final= %s", final);
+
+	ZVAL_STRING(*name, final, 1);
+
+//	php_printf("<br />zname= ");
+//	PHPWRITE(Z_STRVAL_PP(name), Z_STRLEN_PP(name));
+//	php_printf("<br />");
+}
+
 static void xc_php_add_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */
 {
 	xc_entry_data_php_t **head = &(cache->phps[php->hvalue]);
@@ -663,10 +749,12 @@
 	if (del) {
 		add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime);
 	}
+	zval *zv;
+	ALLOC_INIT_ZVAL(zv);
 #ifdef IS_UNICODE
 	do {
-		zval *zv;
-		ALLOC_INIT_ZVAL(zv);
+//		zval *zv;
+//		ALLOC_INIT_ZVAL(zv);
 		switch (entry->name_type) {
 			case IS_UNICODE:
 					ZVAL_UNICODEL(zv, entry->name.ustr.val, entry->name.ustr.len, 1);
@@ -678,11 +766,25 @@
 				assert(0);
 		}
 		zv->type = entry->name_type;
-		add_assoc_zval_ex(ei, ZEND_STRS("name"), zv);
+//		hg_internal_remove_prefix(&zv);
+//		add_assoc_zval_ex(ei, ZEND_STRS("name"), zv);
 	} while (0);
 #else
-	add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1);
+	do {
+//	zval *zv;
+//	ALLOC_INIT_ZVAL(zv);
+	ZVAL_STRINGL(zv, entry->name.str.val, entry->name.str.len, 1);
+//	hg_internal_remove_prefix(&zv);
+//	add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1);
+//	add_assoc_zval_ex(ei, ZEND_STRS("name"), zv);
+	} while (0);
 #endif
+	int comp = hg_internal_startwith_prefix(&zv);
+	if (comp == 0) return;
+
+	hg_internal_remove_prefix(&zv);
+	add_assoc_zval_ex(ei, ZEND_STRS("name"), zv);
+
 	switch (type) {
 		case XC_TYPE_PHP:
 			php = entry_php->php;
@@ -2388,6 +2490,7 @@
 			CHECK(xc_var_caches = xc_cache_init(shm, &xc_var_hcache, &xc_var_hentry, NULL, xc_var_size), "failed init variable cache");
 		}
 	}
+
 	return SUCCESS;
 
 err:
@@ -2798,6 +2901,9 @@
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) {
 		return;
 	}
+
+	hg_internal_prefix_entry_name(&name);
+
 	xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC);
 	cache = xc_var_caches[entry_hash.cacheid];
 
@@ -2835,6 +2941,8 @@
 		return;
 	}
 
+	hg_internal_prefix_entry_name(&name);
+
 	/* max ttl */
 	if (xc_var_maxttl && (!entry_var.entry.ttl || entry_var.entry.ttl > xc_var_maxttl)) {
 		entry_var.entry.ttl = xc_var_maxttl;
@@ -2870,6 +2978,9 @@
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) {
 		return;
 	}
+
+	hg_internal_prefix_entry_name(&name);
+
 	xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC);
 	cache = xc_var_caches[entry_hash.cacheid];
 
@@ -2904,6 +3015,9 @@
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) {
 		return;
 	}
+
+	hg_internal_prefix_entry_name(&name);
+
 	xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC);
 	cache = xc_var_caches[entry_hash.cacheid];
 
@@ -2935,6 +3049,8 @@
 		return;
 	}
 
+	hg_internal_prefix_entry_name(&prefix);
+
 	for (i = 0, iend = xc_var_hcache.size; i < iend; i ++) {
 		xc_cache_t *cache = xc_var_caches[i];
 		ENTER_LOCK(cache) {
@@ -2972,6 +3088,8 @@
 		return;
 	}
 
+	hg_internal_prefix_entry_name(&name);
+
 	/* max ttl */
 	if (xc_var_maxttl && (!entry_var.entry.ttl || entry_var.entry.ttl > xc_var_maxttl)) {
 		entry_var.entry.ttl = xc_var_maxttl;
Index: xcache-trunk/xcache.h
===================================================================
--- xcache-trunk/xcache.h	(révision 902)
+++ xcache-trunk/xcache.h	(copie de travail)
@@ -1,7 +1,7 @@
 #ifndef __XCACHE_H
 #define __XCACHE_H
 #define XCACHE_NAME       "XCache"
-#define XCACHE_VERSION    "2.0.0"
+#define XCACHE_VERSION    "2.0.0+itk_vhost"
 #define XCACHE_AUTHOR     "mOo"
 #define XCACHE_COPYRIGHT  "Copyright (c) 2005-2012"
 #define XCACHE_URL        "http://xcache.lighttpd.net"
