rename http\Env\Request::getPost() to getForm(), because it actually retrieves form...
[m6w6/ext-http] / php_http_resource_factory.c
index c3ff6f5ff2eeaa5d85ad4b721c335b550504e57b..0813755f06328e47a657f07dd711b8e4b10031ca 100644 (file)
@@ -6,14 +6,11 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2010, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2011, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
-/* $Id:$ */
-
-#include "php_http.h"
-#include "php_http_resource_factory.h"
+#include "php_http_api.h"
 
 PHP_HTTP_API php_http_resource_factory_t *php_http_resource_factory_init(php_http_resource_factory_t *f, php_http_resource_factory_ops_t *fops, void *data, void (*dtor)(void *data))
 {
@@ -27,21 +24,35 @@ PHP_HTTP_API php_http_resource_factory_t *php_http_resource_factory_init(php_htt
        f->data = data;
        f->dtor = dtor;
 
+       f->refcount = 1;
+
        return f;
 }
 
+PHP_HTTP_API unsigned php_http_resource_factory_addref(php_http_resource_factory_t *rf)
+{
+       return ++rf->refcount;
+}
+
 PHP_HTTP_API void php_http_resource_factory_dtor(php_http_resource_factory_t *f)
 {
-       if (f->dtor) {
-               f->dtor(f->data);
+       --f->refcount;
+
+       if (!f->refcount) {
+               if (f->dtor) {
+                       f->dtor(f->data);
+               }
        }
 }
+
 PHP_HTTP_API void php_http_resource_factory_free(php_http_resource_factory_t **f)
 {
        if (*f) {
                php_http_resource_factory_dtor(*f);
-               efree(*f);
-               *f = NULL;
+               if (!(*f)->refcount) {
+                       efree(*f);
+                       *f = NULL;
+               }
        }
 }