Beispiel #1
0
/* {{{ apc_iterator_item */
static apc_iterator_item_t* apc_iterator_item_ctor(apc_iterator_t *iterator, apc_cache_slot_t **slot_pp) {
    zval zvalue;
    apc_cache_slot_t *slot = *slot_pp;
    apc_context_t ctxt = {0, };
    apc_iterator_item_t *item = ecalloc(1, sizeof(apc_iterator_item_t));

    array_init(&item->value);

	item->key = slot->key.str;

    if (APC_ITER_TYPE & iterator->format) {
		add_assoc_string_ex(&item->value, "type", sizeof("type")-1, "user");
	}

	if (APC_ITER_KEY & iterator->format) {
		add_assoc_str(&item->value, "key", zend_string_copy(item->key));
	}

    if (APC_ITER_VALUE & iterator->format) {
    	apc_cache_make_context(
    		apc_user_cache, &ctxt, APC_CONTEXT_NOSHARE, APC_UNPOOL, APC_COPY_OUT, 0);
    	ZVAL_UNDEF(&zvalue);
        apc_cache_fetch_zval(&ctxt, &zvalue, &slot->value->val);
        add_assoc_zval(&item->value, "value", &zvalue);
        apc_pool_destroy(ctxt.pool);
    }

    if (APC_ITER_NUM_HITS & iterator->format) {
        add_assoc_long(&item->value, "num_hits", slot->nhits);
    }
    if (APC_ITER_MTIME & iterator->format) {
        add_assoc_long(&item->value, "mtime", slot->key.mtime);
    }
    if (APC_ITER_CTIME & iterator->format) {
        add_assoc_long(&item->value, "creation_time", slot->ctime);
    }
    if (APC_ITER_DTIME & iterator->format) {
        add_assoc_long(&item->value, "deletion_time", slot->dtime);
    }
    if (APC_ITER_ATIME & iterator->format) {
        add_assoc_long(&item->value, "access_time", slot->atime);
    }
    if (APC_ITER_REFCOUNT & iterator->format) {
        add_assoc_long(&item->value, "ref_count", slot->value->ref_count);
    }
    if (APC_ITER_MEM_SIZE & iterator->format) {
        add_assoc_long(&item->value, "mem_size", slot->value->mem_size);
    }
    if (APC_ITER_TTL & iterator->format) {
        add_assoc_long(&item->value, "ttl", slot->value->ttl);
    }

    return item;
}
Beispiel #2
0
/* {{{ free_slot */
static void free_slot(apc_cache_slot_t* slot)
{
	/* destroy slot pool */
    apc_pool_destroy(
		slot->value->pool);
}
Beispiel #3
0
/* {{{ apc_iterator_item */
static apc_iterator_item_t* apc_iterator_item_ctor(apc_iterator_t *iterator, slot_t **slot_pp) {
    zval *zvalue;
    char md5str[33];
    slot_t *slot = *slot_pp;
    apc_context_t ctxt = {0, };
    apc_iterator_item_t *item = ecalloc(1, sizeof(apc_iterator_item_t));

    if (slot->key.type == APC_CACHE_KEY_FILE) {
        /* keys should be unique and with stat=1 we could have multiple files with the same name, so use '<device> <inode>' instead */
#ifdef PHP_WIN32
        item->key_len = spprintf(&item->key, 0, "%I64d %I64d", slot->key.data.file.device, slot->key.data.file.inode);
#else
        item->key_len = spprintf(&item->key, 0, "%ld %ld", (ulong)slot->key.data.file.device, (ulong)slot->key.data.file.inode);
#endif
        item->filename_key = estrdup(slot->value->data.file.filename);
    } else if (slot->key.type == APC_CACHE_KEY_USER) {
        item->key = estrndup((char*)slot->key.data.user.identifier, slot->key.data.user.identifier_len);
        item->key_len = slot->key.data.user.identifier_len;
        item->filename_key = item->key; 
    } else if (slot->key.type == APC_CACHE_KEY_FPFILE) {
        item->key = estrndup((char*)slot->key.data.fpfile.fullpath, slot->key.data.fpfile.fullpath_len);
        item->key_len = slot->key.data.fpfile.fullpath_len;
    } else {
        apc_eprint("Internal error, invalid entry type.");
    }

    ALLOC_INIT_ZVAL(item->value);
    array_init(item->value);

    if (APC_ITER_TYPE & iterator->format) {
        if(slot->value->type == APC_CACHE_ENTRY_FILE) {
            add_assoc_string(item->value, "type", "file", 1);
        } else if(slot->value->type == APC_CACHE_ENTRY_USER) {
            add_assoc_string(item->value, "type", "user", 1);
        }
    }
    if (APC_ITER_FILENAME & iterator->format) {
        if(slot->value->type == APC_CACHE_ENTRY_FILE) {
            if (slot->key.type == APC_CACHE_KEY_FILE) {
              add_assoc_string(item->value, "filename", slot->value->data.file.filename, 1);
            } else {  /* APC_CACHE_FPFILE */
              add_assoc_string(item->value, "filename", (char*)slot->key.data.fpfile.fullpath, 1);
            }
        }
    }
    if (APC_ITER_DEVICE & iterator->format) {
        if(slot->key.type == APC_CACHE_KEY_FILE) {
#ifdef PHP_WIN32
			char buf[20];
			sprintf(buf, "%I64d", slot->key.data.file.device);
			add_assoc_string(item->value, "device", buf, 1);
#else
            add_assoc_long(item->value, "device", slot->key.data.file.device);
#endif
        }
    }
    if (APC_ITER_INODE & iterator->format) {
        if(slot->key.type == APC_CACHE_KEY_FILE) {
#ifdef PHP_WIN32
			char buf[20];
			sprintf(buf, "%I64d", slot->key.data.file.device);
			add_assoc_string(item->value, "device", buf, 1);
#else
            add_assoc_long(item->value, "inode", slot->key.data.file.inode);
#endif
        }
    }
    if (APC_ITER_KEY & iterator->format) {
        add_assoc_stringl(item->value, "key", item->key, item->key_len, 1);
    }
    if (APC_ITER_VALUE & iterator->format) {
        if(slot->value->type == APC_CACHE_ENTRY_USER) {

            ctxt.pool = apc_pool_create(APC_UNPOOL, apc_php_malloc, apc_php_free, NULL, NULL);
            ctxt.copy = APC_COPY_OUT_USER;

            MAKE_STD_ZVAL(zvalue);
            apc_cache_fetch_zval(zvalue, slot->value->data.user.val, &ctxt);
            apc_pool_destroy(ctxt.pool);
            add_assoc_zval(item->value, "value", zvalue);
        }
    }
    if (APC_ITER_MD5 & iterator->format) {
        if(slot->value->type == APC_CACHE_ENTRY_FILE) {
            if(slot->key.md5) {
                make_digest(md5str, slot->key.md5);
                add_assoc_string(item->value, "md5", md5str, 1);
            }
        }
    }
    if (APC_ITER_NUM_HITS & iterator->format) {
        add_assoc_long(item->value, "num_hits", slot->num_hits);
    }
    if (APC_ITER_MTIME & iterator->format) {
        add_assoc_long(item->value, "mtime", slot->key.mtime);
    }
    if (APC_ITER_CTIME & iterator->format) {
        add_assoc_long(item->value, "creation_time", slot->creation_time);
    }
    if (APC_ITER_DTIME & iterator->format) {
        add_assoc_long(item->value, "deletion_time", slot->deletion_time);
    }
    if (APC_ITER_ATIME & iterator->format) {
        add_assoc_long(item->value, "access_time", slot->access_time);
    }
    if (APC_ITER_REFCOUNT & iterator->format) {
        add_assoc_long(item->value, "ref_count", slot->value->ref_count);
    }
    if (APC_ITER_MEM_SIZE & iterator->format) {
        add_assoc_long(item->value, "mem_size", slot->value->mem_size);
    }
    if (APC_ITER_TTL & iterator->format) {
        if(slot->value->type == APC_CACHE_ENTRY_USER) {
            add_assoc_long(item->value, "ttl", slot->value->data.user.ttl);
        }
    }

    return item;
}