build and file maintenance
[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-2011, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http.h"
14 #include "php_http_resource_factory.h"
15
16 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))
17 {
18 if (!f) {
19 f = emalloc(sizeof(*f));
20 }
21 memset(f, 0, sizeof(*f));
22
23 memcpy(&f->fops, fops, sizeof(*fops));
24
25 f->data = data;
26 f->dtor = dtor;
27
28 return f;
29 }
30
31 PHP_HTTP_API void php_http_resource_factory_dtor(php_http_resource_factory_t *f)
32 {
33 if (f->dtor) {
34 f->dtor(f->data);
35 }
36 }
37 PHP_HTTP_API void php_http_resource_factory_free(php_http_resource_factory_t **f)
38 {
39 if (*f) {
40 php_http_resource_factory_dtor(*f);
41 efree(*f);
42 *f = NULL;
43 }
44 }
45
46 PHP_HTTP_API void *php_http_resource_factory_handle_ctor(php_http_resource_factory_t *f TSRMLS_DC)
47 {
48 if (f->fops.ctor) {
49 return f->fops.ctor(f->data TSRMLS_CC);
50 }
51 return NULL;
52 }
53
54 PHP_HTTP_API void *php_http_resource_factory_handle_copy(php_http_resource_factory_t *f, void *handle TSRMLS_DC)
55 {
56 if (f->fops.copy) {
57 return f->fops.copy(f->data, handle TSRMLS_CC);
58 }
59 return NULL;
60 }
61
62 PHP_HTTP_API void php_http_resource_factory_handle_dtor(php_http_resource_factory_t *f, void *handle TSRMLS_DC)
63 {
64 if (f->fops.dtor) {
65 f->fops.dtor(f->data, handle TSRMLS_CC);
66 }
67 }
68
69 /*
70 * Local variables:
71 * tab-width: 4
72 * c-basic-offset: 4
73 * End:
74 * vim600: noet sw=4 ts=4 fdm=marker
75 * vim<600: noet sw=4 ts=4
76 */
77