-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstat.c
More file actions
224 lines (191 loc) · 6.06 KB
/
stat.c
File metadata and controls
224 lines (191 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*-
* Copyright (c) 2011-2018 Anatol Belski
* All rights reserved.
*
* Author: Anatol Belski <ab@php.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend_exceptions.h"
#include "php_varnish.h"
#include "varnish_lib.h"
#include "exception.h"
#if PHP_MAJOR_VERSION >= 7
extern zend_object_handlers default_varnish_stat_handlers;
#else
extern zend_object_handlers default_varnish_handlers;
#endif
#if PHP_MAJOR_VERSION >= 7
void
php_varnish_stat_obj_destroy(zend_object *obj)
{/*{{{*/
struct ze_varnish_stat_obj *zvso = php_fetch_varnish_stat_obj(obj);
zend_object_std_dtor(&zvso->zo);
if (zvso->zvc.ident_len > 0) {
efree(zvso->zvc.ident);
}
}/*}}}*/
#else
void
php_varnish_stat_obj_destroy(void *obj TSRMLS_DC)
{/*{{{*/
struct ze_varnish_stat_obj *zvso = (struct ze_varnish_stat_obj *)obj;
zend_object_std_dtor(&zvso->zo TSRMLS_CC);
if (zvso->zvc.ident_len > 0) {
efree(zvso->zvc.ident);
}
efree(zvso);
}/*}}}*/
#endif
#if PHP_MAJOR_VERSION >= 7
zend_object *
php_varnish_stat_obj_init(zend_class_entry *ze)
{/*{{{*/
struct ze_varnish_stat_obj *zvso;
zvso = (struct ze_varnish_stat_obj *)ecalloc(1, sizeof(struct ze_varnish_stat_obj));
zend_object_std_init(&zvso->zo, ze);
zvso->zo.handlers = &default_varnish_stat_handlers;
zvso->zvc.ident = NULL;
zvso->zvc.ident_len = 0;
return &zvso->zo;
}/*}}}*/
#else
zend_object_value
php_varnish_stat_obj_init(zend_class_entry *ze TSRMLS_DC)
{ /*{{{*/
zend_object_value ret;
struct ze_varnish_stat_obj *zvso;
#if PHP_VERSION_ID < 50399
zval *tmp;
#endif
zvso = (struct ze_varnish_stat_obj*)emalloc(sizeof(struct ze_varnish_stat_obj));
memset(&zvso->zo, 0, sizeof(zend_object));
zend_object_std_init(&zvso->zo, ze TSRMLS_CC);
#if PHP_VERSION_ID < 50399
zend_hash_copy(zvso->zo.properties, &ze->default_properties, (copy_ctor_func_t) zval_add_ref,
(void *) &tmp, sizeof(zval *));
#else
object_properties_init(&zvso->zo, ze);
#endif
zvso->zvc.ident = NULL;
zvso->zvc.ident_len = 0;
ret.handle = zend_objects_store_put(zvso, NULL,
(zend_objects_free_object_storage_t) php_varnish_stat_obj_destroy,
NULL TSRMLS_CC);
ret.handlers = &default_varnish_handlers;
return ret;
}/*}}}*/
#endif
/* {{{ proto void VarnishStat::__construct(array options)
* Varnish admin constructor */
PHP_METHOD(VarnishStat, __construct)
{
#if defined(HAVE_VARNISHAPILIB) && HAVE_VARNISHAPILIB >= 40
php_varnish_throw_win_unimpl_exception("VarnishStat functionality isn't available for Varnish >= 4" TSRMLS_CC);
return;
#elif !defined(PHP_WIN32)
struct ze_varnish_stat_obj *zvso;
zval *opts = NULL;
#if PHP_MAJOR_VERSION >= 7
zval *ident;
#else
zval **ident;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &opts) == FAILURE) {
return;
}
#if PHP_MAJOR_VERSION >= 7
zvso = php_fetch_varnish_stat_obj(Z_OBJ_P(getThis()));
#else
zvso = (struct ze_varnish_stat_obj *) zend_object_store_get_object(getThis() TSRMLS_CC);
#endif
if (NULL == opts) {
php_varnish_default_ident(&zvso->zvc.ident, (int*)&zvso->zvc.ident_len);
return;
}
#if PHP_MAJOR_VERSION >= 7
if((ident = zend_hash_find(Z_ARRVAL_P(opts), zend_string_init("ident", sizeof("ident")-1, 0))) != NULL) {
convert_to_string(ident);
zvso->zvc.ident = estrdup(Z_STRVAL_P(ident));
zvso->zvc.ident_len = Z_STRLEN_P(ident);
} else {
php_varnish_default_ident(&zvso->zvc.ident, (int*)&zvso->zvc.ident_len);
}
#else
if(zend_hash_find(Z_ARRVAL_P(opts), "ident", sizeof("ident"), (void**)&ident) != FAILURE) {
convert_to_string(*ident);
zvso->zvc.ident = estrdup(Z_STRVAL_PP(ident));
zvso->zvc.ident_len = Z_STRLEN_PP(ident);
} else {
php_varnish_default_ident(&zvso->zvc.ident, (int*)&zvso->zvc.ident_len);
}
#endif
#else
php_varnish_throw_win_unimpl_exception("VarnishStat functionality isn't available on windows" TSRMLS_CC);
return;
#endif
}
/* }}} */
#if defined(HAVE_VARNISHAPILIB) && HAVE_VARNISHAPILIB < 40
/* {{{ proto array VarnishStat::getSnapshot(void)
Get a statistics snapshot */
PHP_METHOD(VarnishStat, getSnapshot)
{
struct ze_varnish_stat_obj *zvso;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
#if PHP_MAJOR_VERSION >= 7
zvso = php_fetch_varnish_stat_obj(Z_OBJ_P(getThis()));
#else
zvso = (struct ze_varnish_stat_obj *) zend_object_store_get_object(getThis() TSRMLS_CC);
#endif
/* Ensure the ctor was called properly and we have an ident to connect to */
if (!zvso->zvc.ident) {
zend_throw_exception_ex(
VarnishException_ce,
PHP_VARNISH_COMM_EXCEPTION TSRMLS_CC,
"Missing ident to connect to"
);
return;
}
array_init(return_value);
(void)php_varnish_snap_stats(return_value, zvso->zvc.ident TSRMLS_CC);
}
/* }}} */
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/