http\Env::parseParams()
[m6w6/ext-http] / php_http_resource_factory.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id:$ */
14
15 #include "php_http.h"
16 #include "php_http_resource_factory.h"
17
18 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))
19 {
20 if (!f) {
21 f = emalloc(sizeof(*f));
22 }
23 memset(f, 0, sizeof(*f));
24
25 memcpy(&f->fops, fops, sizeof(*fops));
26
27 f->data = data;
28 f->dtor = dtor;
29
30 return f;
31 }
32
33 PHP_HTTP_API void php_http_resource_factory_dtor(php_http_resource_factory_t *f)
34 {
35 if (f->dtor) {
36 f->dtor(f->data);
37 }
38 }
39 PHP_HTTP_API void php_http_resource_factory_free(php_http_resource_factory_t **f)
40 {
41 if (*f) {
42 php_http_resource_factory_dtor(*f);
43 efree(*f);
44 *f = NULL;
45 }
46 }
47
48 PHP_HTTP_API void *php_http_resource_factory_handle_ctor(php_http_resource_factory_t *f TSRMLS_DC)
49 {
50 if (f->fops.ctor) {
51 return f->fops.ctor(f->data TSRMLS_CC);
52 }
53 return NULL;
54 }
55
56 PHP_HTTP_API void *php_http_resource_factory_handle_copy(php_http_resource_factory_t *f, void *handle TSRMLS_DC)
57 {
58 if (f->fops.copy) {
59 return f->fops.copy(f->data, handle TSRMLS_CC);
60 }
61 return NULL;
62 }
63
64 PHP_HTTP_API void php_http_resource_factory_handle_dtor(php_http_resource_factory_t *f, void *handle TSRMLS_DC)
65 {
66 if (f->fops.dtor) {
67 f->fops.dtor(f->data, handle TSRMLS_CC);
68 }
69 }
70
71 /*
72 * Local variables:
73 * tab-width: 4
74 * c-basic-offset: 4
75 * End:
76 * vim600: noet sw=4 ts=4 fdm=marker
77 * vim<600: noet sw=4 ts=4
78 */
79