1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 5                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2007 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 |
16   | Lead:                                                                |
17   | - Pieter de Zwart                                                    |
18   | Maintainers:                                                         |
19   | - Brad Rodriguez                                                     |
20   | - Jonathan Tansavatdi                                                |
21   +----------------------------------------------------------------------+
22 */
23 
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 
29 #include "php.h"
30 #include "php_ini.h"
31 #include "zend_exceptions.h"
32 
33 #ifdef PHP_WIN32
34 # include "win32/php_stdint.h"
35 # include "win32/signal.h"
36 #else
37 # include <signal.h>
38 # include <stdint.h>
39 #endif
40 #include <amqp.h>
41 #include <amqp_framing.h>
42 #include <amqp_tcp_socket.h>
43 
44 #ifdef PHP_WIN32
45 # include "win32/unistd.h"
46 #else
47 # include <unistd.h>
48 #endif
49 
50 #include "php_amqp.h"
51 #include "amqp_channel.h"
52 #include "amqp_connection_resource.h"
53 #include "amqp_connection.h"
54 
55 #ifndef E_DEPRECATED
56 #define E_DEPRECATED E_WARNING
57 #endif
58 
59 zend_class_entry *amqp_connection_class_entry;
60 #define this_ce amqp_connection_class_entry
61 
62 zend_object_handlers amqp_connection_object_handlers;
63 
64 #define PHP_AMQP_EXTRACT_CONNECTION_STR(name) \
65 	zdata = NULL; \
66 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), (name), sizeof(name), zdata)) { \
67 		SEPARATE_ZVAL(zdata); \
68 		convert_to_string(PHP5to7_MAYBE_DEREF(zdata)); \
69 	} \
70 	if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) { \
71 		zend_update_property_string(this_ce, getThis(), ZEND_STRL(name), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); \
72 	} else { \
73 		zend_update_property_string(this_ce, getThis(), ZEND_STRL(name), INI_STR("amqp." name) TSRMLS_CC); \
74 	}
75 
76 #define PHP_AMQP_EXTRACT_CONNECTION_BOOL(name) \
77 	zdata = NULL; \
78 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), (name), sizeof(name), zdata)) { \
79 		SEPARATE_ZVAL(zdata); \
80 		convert_to_long(PHP5to7_MAYBE_DEREF(zdata)); \
81 	} \
82 	if (zdata) { \
83 		zend_update_property_bool(this_ce, getThis(), ZEND_STRL(name), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); \
84 	} else { \
85 		zend_update_property_bool(this_ce, getThis(), ZEND_STRL(name), INI_INT("amqp." name) TSRMLS_CC); \
86 	}
87 
php_amqp_connection_resource_deleter(PHP5to7_zend_resource_le_t * el,amqp_connection_resource * connection_resource TSRMLS_DC)88 static int php_amqp_connection_resource_deleter(PHP5to7_zend_resource_le_t *el, amqp_connection_resource *connection_resource TSRMLS_DC)
89 {
90 	if (Z_RES_P(el)->ptr == connection_resource) {
91 		return ZEND_HASH_APPLY_REMOVE | ZEND_HASH_APPLY_STOP;
92 	}
93 
94 	return ZEND_HASH_APPLY_KEEP;
95 }
96 
php_amqp_get_connection_hash(amqp_connection_params * params,char ** hash)97 static PHP5to7_param_str_len_type_t php_amqp_get_connection_hash(amqp_connection_params *params, char **hash) {
98 	return spprintf(hash,
99 					0,
100 					"amqp_conn_res_h:%s_p:%d_v:%s_l:%s_p:%s_f:%d_c:%d_h:%d_cacert:%s_cert:%s_key:%s_sasl_method:%d_connection_name:%s",
101 					params->host,
102 					params->port,
103 					params->vhost,
104 					params->login,
105 					params->password,
106 					params->frame_max,
107 					params->channel_max,
108 					params->heartbeat,
109 					params->cacert,
110 					params->cert,
111 					params->key,
112 					params->sasl_method,
113 					params->connection_name
114 	);
115 }
116 
php_amqp_cleanup_connection_resource(amqp_connection_resource * connection_resource TSRMLS_DC)117 static void php_amqp_cleanup_connection_resource(amqp_connection_resource *connection_resource TSRMLS_DC)
118 {
119 	if (!connection_resource) {
120 		return;
121 	}
122 
123 	PHP5to7_zend_resource_t resource = connection_resource->resource;
124 
125 	connection_resource->parent->connection_resource = NULL;
126 	connection_resource->parent = NULL;
127 
128 	if (connection_resource->is_dirty) {
129 		if (connection_resource->is_persistent) {
130 			zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t)php_amqp_connection_resource_deleter, (void*)connection_resource TSRMLS_CC);
131 		}
132 
133 		zend_list_delete(resource);
134 	} else {
135 		if (connection_resource->is_persistent) {
136 			connection_resource->resource = PHP5to7_ZEND_RESOURCE_EMPTY;
137 		}
138 
139 		if (connection_resource->resource != PHP5to7_ZEND_RESOURCE_EMPTY) {
140 			zend_list_delete(resource);
141 		}
142 	}
143 }
144 
php_amqp_disconnect(amqp_connection_resource * resource TSRMLS_DC)145 static void php_amqp_disconnect(amqp_connection_resource *resource TSRMLS_DC)
146 {
147 	php_amqp_prepare_for_disconnect(resource TSRMLS_CC);
148 	php_amqp_cleanup_connection_resource(resource TSRMLS_CC);
149 }
150 
151 
php_amqp_disconnect_force(amqp_connection_resource * resource TSRMLS_DC)152 void php_amqp_disconnect_force(amqp_connection_resource *resource TSRMLS_DC)
153 {
154 	php_amqp_prepare_for_disconnect(resource TSRMLS_CC);
155 	resource->is_dirty = '\1';
156 	php_amqp_cleanup_connection_resource(resource TSRMLS_CC);
157 }
158 
159 /**
160  * 	php_amqp_connect
161  *	handles connecting to amqp
162  *	called by connect(), pconnect(), reconnect(), preconnect()
163  */
php_amqp_connect(amqp_connection_object * connection,zend_bool persistent,INTERNAL_FUNCTION_PARAMETERS)164 int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, INTERNAL_FUNCTION_PARAMETERS)
165 {
166 	PHP5to7_READ_PROP_RV_PARAM_DECL;
167 
168 	char *key = NULL;
169 	PHP5to7_param_str_len_type_t key_len = 0;
170 
171 	if (connection->connection_resource) {
172 		/* Clean up old memory allocations which are now invalid (new connection) */
173 		php_amqp_cleanup_connection_resource(connection->connection_resource TSRMLS_CC);
174 	}
175 
176 	assert(connection->connection_resource == NULL);
177 
178 	amqp_connection_params connection_params;
179 
180 	connection_params.host = PHP_AMQP_READ_THIS_PROP_STR("host");
181 	connection_params.port = (int)PHP_AMQP_READ_THIS_PROP_LONG("port");
182 	connection_params.vhost = PHP_AMQP_READ_THIS_PROP_STR("vhost");
183 	connection_params.login = PHP_AMQP_READ_THIS_PROP_STR("login");
184 	connection_params.password = PHP_AMQP_READ_THIS_PROP_STR("password");
185 	connection_params.frame_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("frame_max");
186 	connection_params.channel_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("channel_max");
187 	connection_params.heartbeat = (int) PHP_AMQP_READ_THIS_PROP_LONG("heartbeat");
188 	connection_params.read_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("read_timeout");
189 	connection_params.write_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("write_timeout");
190 	connection_params.connect_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("connect_timeout");
191 	connection_params.rpc_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("rpc_timeout");
192 	connection_params.cacert = PHP_AMQP_READ_THIS_PROP_STRLEN("cacert") ? PHP_AMQP_READ_THIS_PROP_STR("cacert") : NULL;
193 	connection_params.cert = PHP_AMQP_READ_THIS_PROP_STRLEN("cert") ? PHP_AMQP_READ_THIS_PROP_STR("cert") : NULL;
194 	connection_params.key = PHP_AMQP_READ_THIS_PROP_STRLEN("key") ? PHP_AMQP_READ_THIS_PROP_STR("key") : NULL;
195 	connection_params.verify = (int) PHP_AMQP_READ_THIS_PROP_BOOL("verify");
196 	connection_params.sasl_method = (int) PHP_AMQP_READ_THIS_PROP_LONG("sasl_method");
197 	connection_params.connection_name = PHP_AMQP_READ_THIS_PROP_STRLEN("connection_name") ? PHP_AMQP_READ_THIS_PROP_STR("connection_name") : NULL;
198 
199 	if (persistent) {
200 		PHP5to7_zend_resource_store_t *le = PHP5to7_ZEND_RESOURCE_EMPTY;
201 
202 		/* Look for an established resource */
203 		key_len = php_amqp_get_connection_hash(&connection_params, &key);
204 
205 		if (PHP5to7_ZEND_HASH_STR_FIND_PTR(&EG(persistent_list), key, key_len, le)) {
206 			efree(key);
207 
208 			if (le->type != le_amqp_connection_resource_persistent) {
209 				/* hash conflict, given name associate with non-amqp persistent connection resource */
210 				return 0;
211 			}
212 
213 			/* An entry for this connection resource already exists */
214 			/* Stash the connection resource in the connection */
215 			connection->connection_resource = le->ptr;
216 
217 			if (connection->connection_resource->resource != PHP5to7_ZEND_RESOURCE_EMPTY) {
218 				/*  resource in use! */
219 				connection->connection_resource = NULL;
220 
221 				zend_throw_exception(amqp_connection_exception_class_entry, "There are already established persistent connection to the same resource.", 0 TSRMLS_CC);
222 				return 0;
223 			}
224 
225 			connection->connection_resource->resource = PHP5to7_ZEND_REGISTER_RESOURCE(connection->connection_resource, persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource);
226 			connection->connection_resource->parent = connection;
227 
228 			/* Set desired timeouts */
229 			if (php_amqp_set_resource_read_timeout(connection->connection_resource, PHP_AMQP_READ_THIS_PROP_DOUBLE("read_timeout") TSRMLS_CC) == 0
230 				|| php_amqp_set_resource_write_timeout(connection->connection_resource, PHP_AMQP_READ_THIS_PROP_DOUBLE("write_timeout") TSRMLS_CC) == 0
231 				|| php_amqp_set_resource_rpc_timeout(connection->connection_resource, PHP_AMQP_READ_THIS_PROP_DOUBLE("rpc_timeout") TSRMLS_CC) == 0) {
232 
233 				php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC);
234 				return 0;
235 			}
236 
237 			/* Set connection status to connected */
238 			connection->connection_resource->is_connected = '\1';
239 			connection->connection_resource->is_persistent = persistent;
240 
241 			return 1;
242 		}
243 
244 		efree(key);
245 	}
246 
247 	connection->connection_resource = connection_resource_constructor(&connection_params, persistent TSRMLS_CC);
248 
249 	if (connection->connection_resource == NULL) {
250 		return 0;
251 	}
252 
253 	connection->connection_resource->resource = PHP5to7_ZEND_REGISTER_RESOURCE(connection->connection_resource, persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource);
254 	connection->connection_resource->parent = connection;
255 
256 	/* Set connection status to connected */
257 	connection->connection_resource->is_connected = '\1';
258 
259 	if (persistent) {
260 		connection->connection_resource->is_persistent = persistent;
261 
262 		key_len = php_amqp_get_connection_hash(&connection_params, &key);
263 
264 		PHP5to7_zend_resource_store_t new_le;
265 
266 		/* Store a reference in the persistence list */
267 		new_le.ptr  = connection->connection_resource;
268 		new_le.type = persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource;
269 
270 		if (!PHP5to7_ZEND_HASH_STR_UPD_MEM(&EG(persistent_list), key, key_len, new_le, sizeof(PHP5to7_zend_resource_store_t))) {
271 			efree(key);
272 			php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC);
273 			return 0;
274 		}
275 		efree(key);
276 	}
277 
278 	return 1;
279 }
280 
amqp_connection_free(PHP5to7_obj_free_zend_object * object TSRMLS_DC)281 void amqp_connection_free(PHP5to7_obj_free_zend_object *object TSRMLS_DC)
282 {
283 	amqp_connection_object *connection = PHP_AMQP_FETCH_CONNECTION(object);
284 
285 	if (connection->connection_resource) {
286 		php_amqp_disconnect(connection->connection_resource TSRMLS_CC);
287 	}
288 
289 	zend_object_std_dtor(&connection->zo TSRMLS_CC);
290 
291 #if PHP_MAJOR_VERSION < 7
292 	efree(object);
293 #endif
294 }
295 
amqp_connection_ctor(zend_class_entry * ce TSRMLS_DC)296 PHP5to7_zend_object_value amqp_connection_ctor(zend_class_entry *ce TSRMLS_DC)
297 {
298 	amqp_connection_object* connection = PHP5to7_ECALLOC_CONNECTION_OBJECT(ce);
299 
300 	zend_object_std_init(&connection->zo, ce TSRMLS_CC);
301 	AMQP_OBJECT_PROPERTIES_INIT(connection->zo, ce);
302 
303 #if PHP_MAJOR_VERSION >=7
304 	connection->zo.handlers = &amqp_connection_object_handlers;
305 
306 	return &connection->zo;
307 #else
308 	PHP5to7_zend_object_value new_value;
309 
310 	new_value.handle = zend_objects_store_put(
311 			connection,
312 			NULL,
313 			(zend_objects_free_object_storage_t) amqp_connection_free,
314 			NULL TSRMLS_CC
315 	);
316 
317 	new_value.handlers = zend_get_std_object_handlers();
318 
319 	return new_value;
320 #endif
321 }
322 
323 
324 /* {{{ proto AMQPConnection::__construct([array optional])
325  * The array can contain 'host', 'port', 'login', 'password', 'vhost', 'read_timeout', 'write_timeout', 'connect_timeout', 'rpc_timeout' and 'timeout' (deprecated) indexes
326  */
PHP_METHOD(amqp_connection_class,__construct)327 static PHP_METHOD(amqp_connection_class, __construct)
328 {
329 	zval* ini_arr = NULL;
330 
331 	PHP5to7_zval_t *zdata = NULL;
332 
333 	/* Parse out the method parameters */
334 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/", &ini_arr) == FAILURE) {
335 		return;
336 	}
337 
338 	/* Pull the login out of the $params array */
339 	zdata = NULL;
340 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "login", sizeof("login"), zdata)) {
341 		SEPARATE_ZVAL(zdata);
342 		convert_to_string(PHP5to7_MAYBE_DEREF(zdata));
343 	}
344 	/* Validate the given login */
345 	if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) {
346 		if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) < 128) {
347 			zend_update_property(this_ce, getThis(), ZEND_STRL("login"), PHP5to7_MAYBE_DEREF(zdata)TSRMLS_CC);
348 		} else {
349 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'login' exceeds 128 character limit.", 0 TSRMLS_CC);
350 			return;
351 		}
352 	} else {
353 		zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("login"), INI_STR("amqp.login"), (PHP5to7_param_str_len_type_t) (strlen(INI_STR("amqp.login")) > 128 ? 128 : strlen(INI_STR("amqp.login"))) TSRMLS_CC);
354 	}
355 
356 	/* Pull the password out of the $params array */
357 	zdata = NULL;
358 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "password", sizeof("password"), zdata)) {
359 		SEPARATE_ZVAL(zdata);
360 		convert_to_string(PHP5to7_MAYBE_DEREF(zdata));
361 	}
362 	/* Validate the given password */
363 	if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) {
364 		if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) < 128) {
365 			zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("password"), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)), Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
366 		} else {
367 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'password' exceeds 128 character limit.", 0 TSRMLS_CC);
368 			return;
369 		}
370 	} else {
371 		zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("password"), INI_STR("amqp.password"), (PHP5to7_param_str_len_type_t) (strlen(INI_STR("amqp.password")) > 128 ? 128 : strlen(INI_STR("amqp.password"))) TSRMLS_CC);
372 	}
373 
374 	/* Pull the host out of the $params array */
375 	zdata = NULL;
376 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "host", sizeof("host"), zdata)) {
377 		SEPARATE_ZVAL(zdata);
378 		convert_to_string(PHP5to7_MAYBE_DEREF(zdata));
379 	}
380 	/* Validate the given host */
381 	if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) {
382 		if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) < 128) {
383 			zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("host"), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)), Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
384 		} else {
385 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'host' exceeds 128 character limit.", 0 TSRMLS_CC);
386 			return;
387 		}
388 	} else {
389 		zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("host"), INI_STR("amqp.host"), (PHP5to7_param_str_len_type_t) (strlen(INI_STR("amqp.host")) > 128 ? 128 : strlen(INI_STR("amqp.host"))) TSRMLS_CC);
390 	}
391 
392 	/* Pull the vhost out of the $params array */
393 	zdata = NULL;
394 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "vhost", sizeof("vhost"), zdata)) {
395 		SEPARATE_ZVAL(zdata);
396 		convert_to_string(PHP5to7_MAYBE_DEREF(zdata));
397 	}
398 	/* Validate the given vhost */
399 	if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) {
400 		if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) < 128) {
401 			zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("vhost"), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)), Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
402 		} else {
403 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'vhost' exceeds 128 character limit.", 0 TSRMLS_CC);
404 			return;
405 		}
406 	} else {
407 		zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("vhost"), INI_STR("amqp.vhost"), (PHP5to7_param_str_len_type_t) (strlen(INI_STR("amqp.vhost")) > 128 ? 128 : strlen(INI_STR("amqp.vhost"))) TSRMLS_CC);
408 
409 	}
410 
411 	zend_update_property_long(this_ce, getThis(), ZEND_STRL("port"), INI_INT("amqp.port") TSRMLS_CC);
412 
413 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "port", sizeof("port"), zdata)) {
414 		SEPARATE_ZVAL(zdata);
415 		convert_to_long(PHP5to7_MAYBE_DEREF(zdata));
416 		zend_update_property_long(this_ce, getThis(), ZEND_STRL("port"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
417 	}
418 
419 	zend_update_property_double(this_ce, getThis(), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC);
420 
421 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "read_timeout", sizeof("read_timeout"), zdata)) {
422 		SEPARATE_ZVAL(zdata);
423 		convert_to_double(PHP5to7_MAYBE_DEREF(zdata));
424 		if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) {
425 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'read_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
426 		} else {
427 			zend_update_property_double(this_ce, getThis(), ZEND_STRL("read_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
428 		}
429 
430 		if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "timeout", sizeof("timeout"), zdata)) {
431 			/* 'read_timeout' takes precedence on 'timeout' but users have to know this */
432 			php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Parameter 'timeout' is deprecated, 'read_timeout' used instead");
433 		}
434 
435 	} else if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "timeout", sizeof("timeout"), zdata)) {
436 
437 		php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "Parameter 'timeout' is deprecated; use 'read_timeout' instead");
438 
439 		SEPARATE_ZVAL(zdata);
440 		convert_to_double(PHP5to7_MAYBE_DEREF(zdata));
441 		if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) {
442 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
443 		} else {
444 			zend_update_property_double(this_ce, getThis(), ZEND_STRL("read_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
445 		}
446 	} else {
447 
448 		assert(DEFAULT_TIMEOUT != NULL);
449 		if (strcmp(DEFAULT_TIMEOUT, INI_STR("amqp.timeout")) != 0) {
450 			php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "INI setting 'amqp.timeout' is deprecated; use 'amqp.read_timeout' instead");
451 
452 			if (strcmp(DEFAULT_READ_TIMEOUT, INI_STR("amqp.read_timeout")) == 0) {
453 				zend_update_property_double(this_ce, getThis(), ZEND_STRL("read_timeout"), INI_FLT("amqp.timeout") TSRMLS_CC);
454 			} else {
455 				php_error_docref(NULL TSRMLS_CC, E_NOTICE, "INI setting 'amqp.read_timeout' will be used instead of 'amqp.timeout'");
456 				zend_update_property_double(this_ce, getThis(), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC);
457 			}
458 		} else {
459 			zend_update_property_double(this_ce, getThis(), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC);
460 		}
461 	}
462 
463 	zend_update_property_double(this_ce, getThis(), ZEND_STRL("write_timeout"), INI_FLT("amqp.write_timeout") TSRMLS_CC);
464 
465 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "write_timeout", sizeof("write_timeout"), zdata)) {
466 		SEPARATE_ZVAL(zdata);
467 		convert_to_double(PHP5to7_MAYBE_DEREF(zdata));
468 		if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) {
469 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'write_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
470 		} else {
471 			zend_update_property_double(this_ce, getThis(), ZEND_STRL("write_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
472 		}
473 	}
474 
475 	zend_update_property_double(this_ce, getThis(), ZEND_STRL("rpc_timeout"), INI_FLT("amqp.rpc_timeout") TSRMLS_CC);
476 
477 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "rpc_timeout", sizeof("rpc_timeout"), zdata)) {
478 		SEPARATE_ZVAL(zdata);
479 		convert_to_double(PHP5to7_MAYBE_DEREF(zdata));
480 		if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) {
481 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'rpc_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
482 		} else {
483 			zend_update_property_double(this_ce, getThis(), ZEND_STRL("rpc_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
484 		}
485 	}
486 
487 	zend_update_property_double(this_ce, getThis(), ZEND_STRL("connect_timeout"), INI_FLT("amqp.connect_timeout") TSRMLS_CC);
488 
489 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "connect_timeout", sizeof("connect_timeout"), zdata)) {
490 		SEPARATE_ZVAL(zdata);
491 		convert_to_double(PHP5to7_MAYBE_DEREF(zdata));
492 		if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) {
493 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'connect_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
494 		} else {
495 			zend_update_property_double(this_ce, getThis(), ZEND_STRL("connect_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
496 
497 		}
498 	}
499 
500 	zend_update_property_long(this_ce, getThis(), ZEND_STRL("channel_max"), INI_INT("amqp.channel_max") TSRMLS_CC);
501 
502 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "channel_max", sizeof("channel_max"), zdata)) {
503 		SEPARATE_ZVAL(zdata);
504 		convert_to_long(PHP5to7_MAYBE_DEREF(zdata));
505 		if (Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0 || Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) > PHP_AMQP_MAX_CHANNELS) {
506 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'channel_max' is out of range.", 0 TSRMLS_CC);
507 		} else {
508 			if(Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) == 0) {
509 				zend_update_property_long(this_ce, getThis(), ZEND_STRL("channel_max"), PHP_AMQP_DEFAULT_CHANNEL_MAX TSRMLS_CC);
510 			} else {
511 				zend_update_property_long(this_ce, getThis(), ZEND_STRL("channel_max"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
512 			}
513 		}
514 	}
515 
516 	zend_update_property_long(this_ce, getThis(), ZEND_STRL("frame_max"), INI_INT("amqp.frame_max") TSRMLS_CC);
517 
518 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "frame_max", sizeof("frame_max"), zdata)) {
519 		SEPARATE_ZVAL(zdata);
520 		convert_to_long(PHP5to7_MAYBE_DEREF(zdata));
521 		if (Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0 || Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) > PHP_AMQP_MAX_FRAME) {
522 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'frame_max' is out of range.", 0 TSRMLS_CC);
523 		} else {
524 			if(Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) == 0) {
525 				zend_update_property_long(this_ce, getThis(), ZEND_STRL("frame_max"), PHP_AMQP_DEFAULT_FRAME_MAX TSRMLS_CC);
526 			} else {
527 				zend_update_property_long(this_ce, getThis(), ZEND_STRL("frame_max"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
528 			}
529 		}
530 	}
531 
532 	zend_update_property_long(this_ce, getThis(), ZEND_STRL("heartbeat"), INI_INT("amqp.heartbeat") TSRMLS_CC);
533 
534 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "heartbeat", sizeof("heartbeat"), zdata)) {
535 		SEPARATE_ZVAL(zdata);
536 		convert_to_long(PHP5to7_MAYBE_DEREF(zdata));
537 		if (Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0 || Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) > PHP_AMQP_MAX_HEARTBEAT) {
538 			zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'heartbeat' is out of range.", 0 TSRMLS_CC);
539 		} else {
540 			zend_update_property_long(this_ce, getThis(), ZEND_STRL("heartbeat"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
541 		}
542 	}
543 
544 	zend_update_property_long(this_ce, getThis(), ZEND_STRL("sasl_method"), INI_INT("amqp.sasl_method") TSRMLS_CC);
545 
546 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "sasl_method", sizeof("sasl_method"), zdata)) {
547 		SEPARATE_ZVAL(zdata);
548 		convert_to_long(PHP5to7_MAYBE_DEREF(zdata));
549 		zend_update_property_long(this_ce, getThis(), ZEND_STRL("sasl_method"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
550 	}
551 
552 
553 	PHP_AMQP_EXTRACT_CONNECTION_STR("cacert");
554 	PHP_AMQP_EXTRACT_CONNECTION_STR("key");
555 	PHP_AMQP_EXTRACT_CONNECTION_STR("cert");
556 
557 	PHP_AMQP_EXTRACT_CONNECTION_BOOL("verify");
558 
559 	/* Pull the connection_name out of the $params array */
560 	zdata = NULL;
561 	if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "connection_name", sizeof("connection_name"), zdata)) {
562 		SEPARATE_ZVAL(zdata);
563 		convert_to_string(PHP5to7_MAYBE_DEREF(zdata));
564 	}
565 	if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) {
566 		zend_update_property_string(this_ce, getThis(), ZEND_STRL("connection_name"), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC);
567 	}
568 }
569 /* }}} */
570 
571 
572 /* {{{ proto amqp::isConnected()
573 check amqp connection */
PHP_METHOD(amqp_connection_class,isConnected)574 static PHP_METHOD(amqp_connection_class, isConnected)
575 {
576 	amqp_connection_object *connection;
577 
578 	PHP_AMQP_NOPARAMS();
579 
580 	/* Get the connection object out of the store */
581 	connection = PHP_AMQP_GET_CONNECTION(getThis());
582 
583 	/* If the channel_connect is 1, we have a connection */
584 	if (connection->connection_resource != NULL && connection->connection_resource->is_connected) {
585 		RETURN_TRUE;
586 	}
587 
588 	/* We have no connection */
589 	RETURN_FALSE;
590 }
591 /* }}} */
592 
593 
594 /* {{{ proto amqp::connect()
595 create amqp connection */
PHP_METHOD(amqp_connection_class,connect)596 static PHP_METHOD(amqp_connection_class, connect)
597 {
598 	amqp_connection_object *connection;
599 
600 	PHP_AMQP_NOPARAMS();
601 
602 	/* Get the connection object out of the store */
603 	connection = PHP_AMQP_GET_CONNECTION(getThis());
604 
605 	if (connection->connection_resource && connection->connection_resource->is_connected) {
606 		if (connection->connection_resource->is_persistent) {
607 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to start transient connection while persistent transient one already established. Continue.");
608 		}
609 
610 		RETURN_TRUE;
611 	}
612 
613 	/* Actually connect this resource to the broker */
614 	RETURN_BOOL(php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU));
615 }
616 /* }}} */
617 
618 
619 /* {{{ proto amqp::connect()
620 create amqp connection */
PHP_METHOD(amqp_connection_class,pconnect)621 static PHP_METHOD(amqp_connection_class, pconnect)
622 {
623 	amqp_connection_object *connection;
624 
625 	PHP_AMQP_NOPARAMS();
626 
627 	/* Get the connection object out of the store */
628 	connection = PHP_AMQP_GET_CONNECTION(getThis());
629 
630 	if (connection->connection_resource && connection->connection_resource->is_connected) {
631 
632 		assert(connection->connection_resource != NULL);
633 		if (!connection->connection_resource->is_persistent) {
634 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to start persistent connection while transient one already established. Continue.");
635 		}
636 
637 		RETURN_TRUE;
638 	}
639 
640 	/* Actually connect this resource to the broker or use stored connection */
641 	RETURN_BOOL(php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU));
642 }
643 /* }}} */
644 
645 
646 /* {{{ proto amqp:pdisconnect()
647 destroy amqp persistent connection */
PHP_METHOD(amqp_connection_class,pdisconnect)648 static PHP_METHOD(amqp_connection_class, pdisconnect)
649 {
650 	amqp_connection_object *connection;
651 
652 	PHP_AMQP_NOPARAMS();
653 
654 	/* Get the connection object out of the store */
655 	connection = PHP_AMQP_GET_CONNECTION(getThis());
656 
657 	if (!connection->connection_resource || !connection->connection_resource->is_connected) {
658 		RETURN_TRUE;
659 	}
660 
661 	assert(connection->connection_resource != NULL);
662 
663 	if (!connection->connection_resource->is_persistent) {
664 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to close persistent connection while transient one already established. Abort.");
665 
666 		RETURN_FALSE;
667 	}
668 
669 	php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC);
670 
671 	RETURN_TRUE;
672 }
673 /* }}} */
674 
675 
676 /* {{{ proto amqp::disconnect()
677 destroy amqp connection */
PHP_METHOD(amqp_connection_class,disconnect)678 static PHP_METHOD(amqp_connection_class, disconnect)
679 {
680 	amqp_connection_object *connection;
681 
682 	PHP_AMQP_NOPARAMS();
683 
684 	/* Get the connection object out of the store */
685 	connection = PHP_AMQP_GET_CONNECTION(getThis());
686 
687 	if (!connection->connection_resource || !connection->connection_resource->is_connected) {
688 		RETURN_TRUE;
689 	}
690 
691 	if (connection->connection_resource->is_persistent) {
692 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to close transient connection while persistent one already established. Abort.");
693 
694 		RETURN_FALSE;
695 	}
696 
697 	assert(connection->connection_resource != NULL);
698 
699 	php_amqp_disconnect(connection->connection_resource TSRMLS_CC);
700 
701 	RETURN_TRUE;
702 }
703 
704 /* }}} */
705 
706 /* {{{ proto amqp::reconnect()
707 recreate amqp connection */
PHP_METHOD(amqp_connection_class,reconnect)708 static PHP_METHOD(amqp_connection_class, reconnect)
709 {
710 	amqp_connection_object *connection;
711 
712 	PHP_AMQP_NOPARAMS();
713 
714 	/* Get the connection object out of the store */
715 	connection = PHP_AMQP_GET_CONNECTION(getThis());
716 
717 	if (connection->connection_resource && connection->connection_resource->is_connected) {
718 
719 		assert(connection->connection_resource != NULL);
720 
721 		if (connection->connection_resource->is_persistent) {
722 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to reconnect persistent connection while transient one already established. Abort.");
723 
724 			RETURN_FALSE;
725 		}
726 
727 		php_amqp_disconnect(connection->connection_resource TSRMLS_CC);
728 	}
729 
730 	RETURN_BOOL(php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU));
731 }
732 /* }}} */
733 
734 /* {{{ proto amqp::preconnect()
735 recreate amqp connection */
PHP_METHOD(amqp_connection_class,preconnect)736 static PHP_METHOD(amqp_connection_class, preconnect)
737 {
738 	amqp_connection_object *connection;
739 
740 	PHP_AMQP_NOPARAMS();
741 
742 	/* Get the connection object out of the store */
743 	connection = PHP_AMQP_GET_CONNECTION(getThis());
744 
745 
746 	if (connection->connection_resource && connection->connection_resource->is_connected) {
747 
748 		assert(connection->connection_resource != NULL);
749 
750 		if (!connection->connection_resource->is_persistent) {
751 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to reconnect transient connection while persistent one already established. Abort.");
752 
753 			RETURN_FALSE;
754 		}
755 
756 		php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC);
757 	}
758 
759 	RETURN_BOOL(php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU));
760 }
761 /* }}} */
762 
763 
764 /* {{{ proto amqp::getLogin()
765 get the login */
PHP_METHOD(amqp_connection_class,getLogin)766 static PHP_METHOD(amqp_connection_class, getLogin)
767 {
768 	PHP5to7_READ_PROP_RV_PARAM_DECL;
769 	PHP_AMQP_NOPARAMS();
770 	PHP_AMQP_RETURN_THIS_PROP("login");
771 }
772 /* }}} */
773 
774 
775 /* {{{ proto amqp::setLogin(string login)
776 set the login */
PHP_METHOD(amqp_connection_class,setLogin)777 static PHP_METHOD(amqp_connection_class, setLogin)
778 {
779 	char *login = NULL;	PHP5to7_param_str_len_type_t login_len = 0;
780 
781 	/* Get the login from the method params */
782 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &login, &login_len) == FAILURE) {
783 		return;
784 	}
785 
786 	/* Validate login length */
787 	if (login_len > 128) {
788 		zend_throw_exception(amqp_connection_exception_class_entry, "Invalid 'login' given, exceeds 128 characters limit.", 0 TSRMLS_CC);
789 		return;
790 	}
791 
792 	zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("login"), login, login_len TSRMLS_CC);
793 
794 	RETURN_TRUE;
795 }
796 /* }}} */
797 
798 /* {{{ proto amqp::getPassword()
799 get the password */
PHP_METHOD(amqp_connection_class,getPassword)800 static PHP_METHOD(amqp_connection_class, getPassword)
801 {
802 	PHP5to7_READ_PROP_RV_PARAM_DECL;
803 	PHP_AMQP_NOPARAMS();
804 	PHP_AMQP_RETURN_THIS_PROP("password");
805 }
806 /* }}} */
807 
808 
809 /* {{{ proto amqp::setPassword(string password)
810 set the password */
PHP_METHOD(amqp_connection_class,setPassword)811 static PHP_METHOD(amqp_connection_class, setPassword)
812 {
813 	char *password = NULL;	PHP5to7_param_str_len_type_t password_len = 0;
814 
815 	/* Get the password from the method params */
816 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &password, &password_len) == FAILURE) {
817 		return;
818 	}
819 
820 	/* Validate password length */
821 	if (password_len > 128) {
822 		zend_throw_exception(amqp_connection_exception_class_entry, "Invalid 'password' given, exceeds 128 characters limit.", 0 TSRMLS_CC);
823 		return;
824 	}
825 
826 	zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("password"), password, password_len TSRMLS_CC);
827 
828 	RETURN_TRUE;
829 }
830 /* }}} */
831 
832 
833 /* {{{ proto amqp::getHost()
834 get the host */
PHP_METHOD(amqp_connection_class,getHost)835 static PHP_METHOD(amqp_connection_class, getHost)
836 {
837 	PHP5to7_READ_PROP_RV_PARAM_DECL;
838 	PHP_AMQP_NOPARAMS();
839 	PHP_AMQP_RETURN_THIS_PROP("host");
840 }
841 /* }}} */
842 
843 
844 /* {{{ proto amqp::setHost(string host)
845 set the host */
PHP_METHOD(amqp_connection_class,setHost)846 static PHP_METHOD(amqp_connection_class, setHost)
847 {
848 	char *host = NULL;	PHP5to7_param_str_len_type_t host_len = 0;
849 
850 	/* Get the host from the method params */
851 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &host, &host_len) == FAILURE) {
852 		return;
853 	}
854 
855 	/* Validate host length */
856 	if (host_len > 1024) {
857 		zend_throw_exception(amqp_connection_exception_class_entry, "Invalid 'host' given, exceeds 1024 character limit.", 0 TSRMLS_CC);
858 		return;
859 	}
860 
861 	zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("host"), host, host_len TSRMLS_CC);
862 
863 	RETURN_TRUE;
864 }
865 /* }}} */
866 
867 
868 /* {{{ proto amqp::getPort()
869 get the port */
PHP_METHOD(amqp_connection_class,getPort)870 static PHP_METHOD(amqp_connection_class, getPort)
871 {
872 	PHP5to7_READ_PROP_RV_PARAM_DECL;
873 	PHP_AMQP_NOPARAMS();
874 	PHP_AMQP_RETURN_THIS_PROP("port");
875 }
876 /* }}} */
877 
878 
879 /* {{{ proto amqp::setPort(mixed port)
880 set the port */
PHP_METHOD(amqp_connection_class,setPort)881 static PHP_METHOD(amqp_connection_class, setPort)
882 {
883 	zval *zvalPort;
884 	int port;
885 
886 	/* Get the port from the method params */
887 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zvalPort) == FAILURE) {
888 		return;
889 	}
890 
891 	/* Parse out the port*/
892 	switch (Z_TYPE_P(zvalPort)) {
893 		case IS_DOUBLE:
894 			port = (int)Z_DVAL_P(zvalPort);
895 			break;
896 		case IS_LONG:
897 			port = (int)Z_LVAL_P(zvalPort);
898 			break;
899 		case IS_STRING:
900 			convert_to_long(zvalPort);
901 			port = (int)Z_LVAL_P(zvalPort);
902 			break;
903 		default:
904 			port = 0;
905 	}
906 
907 	/* Check the port value */
908 	if (port <= 0 || port > 65535) {
909 		zend_throw_exception(amqp_connection_exception_class_entry, "Invalid port given. Value must be between 1 and 65535.", 0 TSRMLS_CC);
910 		return;
911 	}
912 
913 	zend_update_property_long(this_ce, getThis(), ZEND_STRL("port"), port TSRMLS_CC);
914 
915 	RETURN_TRUE;
916 }
917 /* }}} */
918 
919 /* {{{ proto amqp::getVhost()
920 get the vhost */
PHP_METHOD(amqp_connection_class,getVhost)921 static PHP_METHOD(amqp_connection_class, getVhost)
922 {
923 	PHP5to7_READ_PROP_RV_PARAM_DECL;
924 	PHP_AMQP_NOPARAMS();
925 	PHP_AMQP_RETURN_THIS_PROP("vhost");
926 }
927 /* }}} */
928 
929 
930 /* {{{ proto amqp::setVhost(string vhost)
931 set the vhost */
PHP_METHOD(amqp_connection_class,setVhost)932 static PHP_METHOD(amqp_connection_class, setVhost)
933 {
934 	char *vhost = NULL;	PHP5to7_param_str_len_type_t vhost_len = 0;
935 
936 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &vhost, &vhost_len) == FAILURE) {
937 		return;
938 	}
939 
940 	/* Validate vhost length */
941 	if (vhost_len > 128) {
942 		zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'vhost' exceeds 128 characters limit.", 0 TSRMLS_CC);
943 		return;
944 	}
945 
946 	zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("vhost"), vhost, vhost_len TSRMLS_CC);
947 
948 	RETURN_TRUE;
949 }
950 /* }}} */
951 
952 /* {{{ proto amqp::getTimeout()
953 @deprecated
954 get the timeout */
PHP_METHOD(amqp_connection_class,getTimeout)955 static PHP_METHOD(amqp_connection_class, getTimeout)
956 {
957 	php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead");
958 
959 	PHP5to7_READ_PROP_RV_PARAM_DECL;
960 	PHP_AMQP_NOPARAMS();
961 	PHP_AMQP_RETURN_THIS_PROP("read_timeout");
962 }
963 /* }}} */
964 
965 /* {{{ proto amqp::setTimeout(double timeout)
966 @deprecated
967 set the timeout */
PHP_METHOD(amqp_connection_class,setTimeout)968 static PHP_METHOD(amqp_connection_class, setTimeout)
969 {
970 	amqp_connection_object *connection;
971 	double read_timeout;
972 
973 	php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead");
974 
975 	/* Get the timeout from the method params */
976 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &read_timeout) == FAILURE) {
977 		return;
978 	}
979 
980 	/* Validate timeout */
981 	if (read_timeout < 0) {
982 		zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
983 		return;
984 	}
985 
986 	/* Get the connection object out of the store */
987 	connection = PHP_AMQP_GET_CONNECTION(getThis());
988 
989 	zend_update_property_double(this_ce, getThis(), ZEND_STRL("read_timeout"), read_timeout TSRMLS_CC);
990 
991 	if (connection->connection_resource && connection->connection_resource->is_connected) {
992 		if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) {
993 
994 			php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC);
995 
996 			RETURN_FALSE;
997 		}
998 	}
999 
1000 	RETURN_TRUE;
1001 }
1002 /* }}} */
1003 
1004 /* {{{ proto amqp::getReadTimeout()
1005 get the read timeout */
PHP_METHOD(amqp_connection_class,getReadTimeout)1006 static PHP_METHOD(amqp_connection_class, getReadTimeout)
1007 {
1008 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1009 	PHP_AMQP_NOPARAMS();
1010 	PHP_AMQP_RETURN_THIS_PROP("read_timeout");
1011 }
1012 /* }}} */
1013 
1014 /* {{{ proto amqp::setReadTimeout(double timeout)
1015 set read timeout */
PHP_METHOD(amqp_connection_class,setReadTimeout)1016 static PHP_METHOD(amqp_connection_class, setReadTimeout)
1017 {
1018 	amqp_connection_object *connection;
1019 	double read_timeout;
1020 
1021 	/* Get the timeout from the method params */
1022 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &read_timeout) == FAILURE) {
1023 		return;
1024 	}
1025 
1026 	/* Validate timeout */
1027 	if (read_timeout < 0) {
1028 		zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'read_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
1029 		return;
1030 	}
1031 
1032 	/* Get the connection object out of the store */
1033 	connection = PHP_AMQP_GET_CONNECTION(getThis());
1034 
1035 	zend_update_property_double(this_ce, getThis(), ZEND_STRL("read_timeout"), read_timeout TSRMLS_CC);
1036 
1037 	if (connection->connection_resource && connection->connection_resource->is_connected) {
1038 		if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) {
1039 
1040 			php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC);
1041 
1042 			RETURN_FALSE;
1043 		}
1044 	}
1045 
1046 	RETURN_TRUE;
1047 }
1048 /* }}} */
1049 
1050 /* {{{ proto amqp::getWriteTimeout()
1051 get write timeout */
PHP_METHOD(amqp_connection_class,getWriteTimeout)1052 static PHP_METHOD(amqp_connection_class, getWriteTimeout)
1053 {
1054 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1055 	PHP_AMQP_NOPARAMS();
1056 	PHP_AMQP_RETURN_THIS_PROP("write_timeout");
1057 }
1058 /* }}} */
1059 
1060 /* {{{ proto amqp::setWriteTimeout(double timeout)
1061 set write timeout */
PHP_METHOD(amqp_connection_class,setWriteTimeout)1062 static PHP_METHOD(amqp_connection_class, setWriteTimeout)
1063 {
1064 	amqp_connection_object *connection;
1065 	double write_timeout;
1066 
1067 	/* Get the timeout from the method params */
1068 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &write_timeout) == FAILURE) {
1069 		return;
1070 	}
1071 
1072 	/* Validate timeout */
1073 	if (write_timeout < 0) {
1074 		zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'write_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
1075 		return;
1076 	}
1077 
1078 	/* Get the connection object out of the store */
1079 	connection = PHP_AMQP_GET_CONNECTION(getThis());
1080 
1081 	zend_update_property_double(this_ce, getThis(), ZEND_STRL("write_timeout"), write_timeout TSRMLS_CC);
1082 
1083 	if (connection->connection_resource && connection->connection_resource->is_connected) {
1084 		if (php_amqp_set_resource_write_timeout(connection->connection_resource, write_timeout TSRMLS_CC) == 0) {
1085 
1086 			php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC);
1087 
1088 			RETURN_FALSE;
1089 		}
1090 	}
1091 
1092 	RETURN_TRUE;
1093 }
1094 /* }}} */
1095 
1096 /* {{{ proto amqp::getRpcTimeout()
1097 get rpc timeout */
PHP_METHOD(amqp_connection_class,getRpcTimeout)1098 static PHP_METHOD(amqp_connection_class, getRpcTimeout)
1099 {
1100 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1101 	PHP_AMQP_NOPARAMS();
1102 	PHP_AMQP_RETURN_THIS_PROP("rpc_timeout");
1103 }
1104 /* }}} */
1105 
1106 /* {{{ proto amqp::setRpcTimeout(double timeout)
1107 set rpc timeout */
PHP_METHOD(amqp_connection_class,setRpcTimeout)1108 static PHP_METHOD(amqp_connection_class, setRpcTimeout)
1109 {
1110 	amqp_connection_object *connection;
1111 	double rpc_timeout;
1112 
1113 	/* Get the timeout from the method params */
1114 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &rpc_timeout) == FAILURE) {
1115 		return;
1116 	}
1117 
1118 	/* Validate timeout */
1119 	if (rpc_timeout < 0) {
1120 		zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'rpc_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC);
1121 		return;
1122 	}
1123 
1124 	/* Get the connection object out of the store */
1125 	connection = PHP_AMQP_GET_CONNECTION(getThis());
1126 
1127 	zend_update_property_double(this_ce, getThis(), ZEND_STRL("rpc_timeout"), rpc_timeout TSRMLS_CC);
1128 
1129 	if (connection->connection_resource && connection->connection_resource->is_connected) {
1130 		if (php_amqp_set_resource_rpc_timeout(connection->connection_resource, rpc_timeout TSRMLS_CC) == 0) {
1131 
1132 			php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC);
1133 
1134 			RETURN_FALSE;
1135 		}
1136 	}
1137 
1138 	RETURN_TRUE;
1139 }
1140 /* }}} */
1141 
1142 /* {{{ proto amqp::getUsedChannels()
1143 Get max used channels number */
PHP_METHOD(amqp_connection_class,getUsedChannels)1144 static PHP_METHOD(amqp_connection_class, getUsedChannels)
1145 {
1146 	amqp_connection_object *connection;
1147 
1148 	/* Get the timeout from the method params */
1149 	PHP_AMQP_NOPARAMS();
1150 
1151 	/* Get the connection object out of the store */
1152 	connection = PHP_AMQP_GET_CONNECTION(getThis());
1153 
1154 	if (!connection->connection_resource || !connection->connection_resource->is_connected) {
1155 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Connection is not connected.");
1156 
1157 		RETURN_LONG(0);
1158 	}
1159 
1160 	RETURN_LONG(connection->connection_resource->used_slots);
1161 }
1162 /* }}} */
1163 
1164 /* {{{ proto amqp::getMaxChannels()
1165 Get max supported channels number per connection */
PHP_METHOD(amqp_connection_class,getMaxChannels)1166 PHP_METHOD(amqp_connection_class, getMaxChannels)
1167 {
1168 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1169 	amqp_connection_object *connection;
1170 
1171 	PHP_AMQP_NOPARAMS();
1172 
1173 	/* Get the connection object out of the store */
1174 	connection = PHP_AMQP_GET_CONNECTION(getThis());
1175 
1176 	if (connection->connection_resource && connection->connection_resource->is_connected) {
1177 		RETURN_LONG(connection->connection_resource->max_slots);
1178 	}
1179 
1180 	PHP_AMQP_RETURN_THIS_PROP("channel_max");
1181 }
1182 /* }}} */
1183 
1184 /* {{{ proto amqp::getMaxFrameSize()
1185 Get max supported frame size per connection in bytes */
PHP_METHOD(amqp_connection_class,getMaxFrameSize)1186 static PHP_METHOD(amqp_connection_class, getMaxFrameSize)
1187 {
1188 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1189 	amqp_connection_object *connection;
1190 
1191 	PHP_AMQP_NOPARAMS();
1192 
1193 	/* Get the connection object out of the store */
1194 	connection = PHP_AMQP_GET_CONNECTION(getThis());
1195 
1196 	if (connection->connection_resource && connection->connection_resource->is_connected) {
1197 		RETURN_LONG(amqp_get_frame_max(connection->connection_resource->connection_state));
1198 	}
1199 
1200 	PHP_AMQP_RETURN_THIS_PROP("frame_max");
1201 }
1202 /* }}} */
1203 
1204 /* {{{ proto amqp::getHeartbeatInterval()
1205 Get number of seconds between heartbeats of the connection in seconds */
PHP_METHOD(amqp_connection_class,getHeartbeatInterval)1206 static PHP_METHOD(amqp_connection_class, getHeartbeatInterval)
1207 {
1208 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1209 	amqp_connection_object *connection;
1210 
1211 	PHP_AMQP_NOPARAMS();
1212 
1213 	/* Get the connection object out of the store */
1214 	connection = PHP_AMQP_GET_CONNECTION(getThis());
1215 
1216 	if (connection->connection_resource != NULL
1217 		&& connection->connection_resource->is_connected != '\0') {
1218 		RETURN_LONG(amqp_get_heartbeat(connection->connection_resource->connection_state));
1219 	}
1220 
1221 	PHP_AMQP_RETURN_THIS_PROP("heartbeat");
1222 }
1223 /* }}} */
1224 
1225 /* {{{ proto amqp::isPersistent()
1226 check whether amqp connection is persistent */
PHP_METHOD(amqp_connection_class,isPersistent)1227 static PHP_METHOD(amqp_connection_class, isPersistent)
1228 {
1229 	amqp_connection_object *connection;
1230 
1231 	PHP_AMQP_NOPARAMS();
1232 
1233 	connection = PHP_AMQP_GET_CONNECTION(getThis());
1234 
1235 	RETURN_BOOL(connection->connection_resource && connection->connection_resource->is_persistent);
1236 }
1237 /* }}} */
1238 
1239 
1240 /* {{{ proto amqp::getCACert() */
PHP_METHOD(amqp_connection_class,getCACert)1241 static PHP_METHOD(amqp_connection_class, getCACert)
1242 {
1243 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1244 	PHP_AMQP_NOPARAMS();
1245 	PHP_AMQP_RETURN_THIS_PROP("cacert");
1246 }
1247 /* }}} */
1248 
1249 /* {{{ proto amqp::setCACert(string cacert) */
PHP_METHOD(amqp_connection_class,setCACert)1250 static PHP_METHOD(amqp_connection_class, setCACert)
1251 {
1252 	char *str = NULL;	PHP5to7_param_str_len_type_t str_len = 0;
1253 
1254 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
1255 		return;
1256 	}
1257 
1258 	zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("cacert"), str, str_len TSRMLS_CC);
1259 
1260 	RETURN_TRUE;
1261 }
1262 /* }}} */
1263 
1264 /* {{{ proto amqp::getCert() */
PHP_METHOD(amqp_connection_class,getCert)1265 static PHP_METHOD(amqp_connection_class, getCert)
1266 {
1267 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1268 	PHP_AMQP_NOPARAMS();
1269 	PHP_AMQP_RETURN_THIS_PROP("cert");
1270 }
1271 /* }}} */
1272 
1273 /* {{{ proto amqp::setCert(string cert) */
PHP_METHOD(amqp_connection_class,setCert)1274 static PHP_METHOD(amqp_connection_class, setCert)
1275 {
1276 	char *str = NULL;	PHP5to7_param_str_len_type_t str_len = 0;
1277 
1278 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
1279 		return;
1280 	}
1281 
1282 	zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("cert"), str, str_len TSRMLS_CC);
1283 
1284 	RETURN_TRUE;
1285 }
1286 /* }}} */
1287 
1288 /* {{{ proto amqp::getKey() */
PHP_METHOD(amqp_connection_class,getKey)1289 static PHP_METHOD(amqp_connection_class, getKey)
1290 {
1291 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1292 	PHP_AMQP_NOPARAMS();
1293 	PHP_AMQP_RETURN_THIS_PROP("key");
1294 }
1295 /* }}} */
1296 
1297 /* {{{ proto amqp::setKey(string key) */
PHP_METHOD(amqp_connection_class,setKey)1298 static PHP_METHOD(amqp_connection_class, setKey)
1299 {
1300 	char *str = NULL;	PHP5to7_param_str_len_type_t str_len = 0;
1301 
1302 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
1303 		return;
1304 	}
1305 
1306 	zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("key"), str, str_len TSRMLS_CC);
1307 
1308 	RETURN_TRUE;
1309 }
1310 /* }}} */
1311 
1312 
1313 /* {{{ proto amqp::getVerify() */
PHP_METHOD(amqp_connection_class,getVerify)1314 static PHP_METHOD(amqp_connection_class, getVerify)
1315 {
1316 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1317 	PHP_AMQP_NOPARAMS();
1318 	PHP_AMQP_RETURN_THIS_PROP("verify");
1319 }
1320 /* }}} */
1321 
1322 /* {{{ proto amqp::setVerify(bool verify) */
PHP_METHOD(amqp_connection_class,setVerify)1323 static PHP_METHOD(amqp_connection_class, setVerify)
1324 {
1325 	zend_bool verify = 1;
1326 
1327 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &verify) == FAILURE) {
1328 		return;
1329 	}
1330 
1331 	zend_update_property_bool(this_ce, getThis(), ZEND_STRL("verify"), verify TSRMLS_CC);
1332 
1333 	RETURN_TRUE;
1334 }
1335 /* }}} */
1336 
1337 /* {{{ proto amqp::getSaslMethod()
1338 get sasl method */
PHP_METHOD(amqp_connection_class,getSaslMethod)1339 static PHP_METHOD(amqp_connection_class, getSaslMethod)
1340 {
1341 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1342 	PHP_AMQP_NOPARAMS();
1343 	PHP_AMQP_RETURN_THIS_PROP("sasl_method");
1344 }
1345 /* }}} */
1346 
1347 /* {{{ proto amqp::setSaslMethod(mixed method)
1348 set sasl method */
PHP_METHOD(amqp_connection_class,setSaslMethod)1349 static PHP_METHOD(amqp_connection_class, setSaslMethod)
1350 {
1351 	long method;
1352 
1353 	/* Get the port from the method params */
1354 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method) == FAILURE) {
1355 		return;
1356 	}
1357 
1358 	/* Check the method value */
1359 	if (method != AMQP_SASL_METHOD_PLAIN && method != AMQP_SASL_METHOD_EXTERNAL) {
1360 		zend_throw_exception(amqp_connection_exception_class_entry, "Invalid SASL method given. Method must be AMQP_SASL_METHOD_PLAIN or AMQP_SASL_METHOD_EXTERNAL.", 0 TSRMLS_CC);
1361 		return;
1362 	}
1363 
1364 	zend_update_property_long(this_ce, getThis(), ZEND_STRL("sasl_method"), method TSRMLS_CC);
1365 
1366 	RETURN_TRUE;
1367 }
1368 /* }}} */
1369 
1370 /* {{{ proto amqp::getConnectionName() */
PHP_METHOD(amqp_connection_class,getConnectionName)1371 static PHP_METHOD(amqp_connection_class, getConnectionName)
1372 {
1373 	PHP5to7_READ_PROP_RV_PARAM_DECL;
1374 	PHP_AMQP_NOPARAMS();
1375 	PHP_AMQP_RETURN_THIS_PROP("connection_name");
1376 }
1377 /* }}} */
1378 
1379 /* {{{ proto amqp::setConnectionName(string connectionName) */
PHP_METHOD(amqp_connection_class,setConnectionName)1380 static PHP_METHOD(amqp_connection_class, setConnectionName)
1381 {
1382 	char *str = NULL;	PHP5to7_param_str_len_type_t str_len = 0;
1383 
1384 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &str, &str_len) == FAILURE) {
1385 		return;
1386 	}
1387 	if (str == NULL) {
1388 		zend_update_property_null(this_ce, getThis(), ZEND_STRL("connection_name") TSRMLS_CC);
1389 	} else {
1390 		zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("connection_name"), str, str_len TSRMLS_CC);
1391 	}
1392 
1393 
1394 	RETURN_TRUE;
1395 }
1396 /* }}} */
1397 
1398 /* amqp_connection_class ARG_INFO definition */
1399 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1400 				ZEND_ARG_ARRAY_INFO(0, credentials, 0)
1401 ZEND_END_ARG_INFO()
1402 
1403 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_isConnected, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1404 ZEND_END_ARG_INFO()
1405 
1406 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_connect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1407 ZEND_END_ARG_INFO()
1408 
1409 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_pconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1410 ZEND_END_ARG_INFO()
1411 
1412 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_pdisconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1413 ZEND_END_ARG_INFO()
1414 
1415 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_disconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1416 ZEND_END_ARG_INFO()
1417 
1418 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_reconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1419 ZEND_END_ARG_INFO()
1420 
1421 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_preconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1422 ZEND_END_ARG_INFO()
1423 
1424 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getLogin, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1425 ZEND_END_ARG_INFO()
1426 
1427 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setLogin, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1428 				ZEND_ARG_INFO(0, login)
1429 ZEND_END_ARG_INFO()
1430 
1431 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getPassword, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1432 ZEND_END_ARG_INFO()
1433 
1434 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setPassword, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1435 				ZEND_ARG_INFO(0, password)
1436 ZEND_END_ARG_INFO()
1437 
1438 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getHost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1439 ZEND_END_ARG_INFO()
1440 
1441 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setHost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1442 				ZEND_ARG_INFO(0, host)
1443 ZEND_END_ARG_INFO()
1444 
1445 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getPort, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1446 ZEND_END_ARG_INFO()
1447 
1448 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setPort, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1449 				ZEND_ARG_INFO(0, port)
1450 ZEND_END_ARG_INFO()
1451 
1452 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getVhost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1453 ZEND_END_ARG_INFO()
1454 
1455 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setVhost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1456 				ZEND_ARG_INFO(0, vhost)
1457 ZEND_END_ARG_INFO()
1458 
1459 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1460 ZEND_END_ARG_INFO()
1461 
1462 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1463 				ZEND_ARG_INFO(0, timeout)
1464 ZEND_END_ARG_INFO()
1465 
1466 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getReadTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1467 ZEND_END_ARG_INFO()
1468 
1469 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setReadTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1470 				ZEND_ARG_INFO(0, timeout)
1471 ZEND_END_ARG_INFO()
1472 
1473 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getWriteTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1474 ZEND_END_ARG_INFO()
1475 
1476 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setWriteTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1477 				ZEND_ARG_INFO(0, timeout)
1478 ZEND_END_ARG_INFO()
1479 
1480 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getRpcTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1481 ZEND_END_ARG_INFO()
1482 
1483 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setRpcTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1484 				ZEND_ARG_INFO(0, timeout)
1485 ZEND_END_ARG_INFO()
1486 
1487 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getUsedChannels, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1488 ZEND_END_ARG_INFO()
1489 
1490 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getMaxChannels, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1491 ZEND_END_ARG_INFO()
1492 
1493 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getMaxFrameSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1494 ZEND_END_ARG_INFO()
1495 
1496 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getHeartbeatInterval, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1497 ZEND_END_ARG_INFO()
1498 
1499 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_isPersistent, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1500 ZEND_END_ARG_INFO()
1501 
1502 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getCACert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1503 ZEND_END_ARG_INFO()
1504 
1505 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setCACert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1506 				ZEND_ARG_INFO(0, cacert)
1507 ZEND_END_ARG_INFO()
1508 
1509 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getCert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1510 ZEND_END_ARG_INFO()
1511 
1512 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setCert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1513 				ZEND_ARG_INFO(0, cert)
1514 ZEND_END_ARG_INFO()
1515 
1516 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getKey, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1517 ZEND_END_ARG_INFO()
1518 
1519 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setKey, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1520 				ZEND_ARG_INFO(0, key)
1521 ZEND_END_ARG_INFO()
1522 
1523 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getVerify, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1524 ZEND_END_ARG_INFO()
1525 
1526 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setVerify, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1527 				ZEND_ARG_INFO(0, verify)
1528 ZEND_END_ARG_INFO()
1529 
1530 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getSaslMethod, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1531 ZEND_END_ARG_INFO()
1532 
1533 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setSaslMethod, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1534 				ZEND_ARG_INFO(0, sasl_method)
1535 ZEND_END_ARG_INFO()
1536 
1537 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getConnectionName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
1538 ZEND_END_ARG_INFO()
1539 
1540 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setConnectionName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
1541 				ZEND_ARG_INFO(0, connection_name)
1542 ZEND_END_ARG_INFO()
1543 
1544 
1545 zend_function_entry amqp_connection_class_functions[] = {
1546 		PHP_ME(amqp_connection_class, __construct, 	arginfo_amqp_connection_class__construct,	ZEND_ACC_PUBLIC)
1547 		PHP_ME(amqp_connection_class, isConnected, 	arginfo_amqp_connection_class_isConnected,	ZEND_ACC_PUBLIC)
1548 		PHP_ME(amqp_connection_class, connect, 		arginfo_amqp_connection_class_connect, 		ZEND_ACC_PUBLIC)
1549 		PHP_ME(amqp_connection_class, pconnect, 	arginfo_amqp_connection_class_pconnect, 	ZEND_ACC_PUBLIC)
1550 		PHP_ME(amqp_connection_class, pdisconnect, 	arginfo_amqp_connection_class_pdisconnect,	ZEND_ACC_PUBLIC)
1551 		PHP_ME(amqp_connection_class, disconnect, 	arginfo_amqp_connection_class_disconnect,	ZEND_ACC_PUBLIC)
1552 		PHP_ME(amqp_connection_class, reconnect, 	arginfo_amqp_connection_class_reconnect,	ZEND_ACC_PUBLIC)
1553 		PHP_ME(amqp_connection_class, preconnect, 	arginfo_amqp_connection_class_preconnect,	ZEND_ACC_PUBLIC)
1554 
1555 		PHP_ME(amqp_connection_class, getLogin, 	arginfo_amqp_connection_class_getLogin,		ZEND_ACC_PUBLIC)
1556 		PHP_ME(amqp_connection_class, setLogin, 	arginfo_amqp_connection_class_setLogin,		ZEND_ACC_PUBLIC)
1557 
1558 		PHP_ME(amqp_connection_class, getPassword, 	arginfo_amqp_connection_class_getPassword,	ZEND_ACC_PUBLIC)
1559 		PHP_ME(amqp_connection_class, setPassword, 	arginfo_amqp_connection_class_setPassword,	ZEND_ACC_PUBLIC)
1560 
1561 		PHP_ME(amqp_connection_class, getHost, 		arginfo_amqp_connection_class_getHost,		ZEND_ACC_PUBLIC)
1562 		PHP_ME(amqp_connection_class, setHost, 		arginfo_amqp_connection_class_setHost,		ZEND_ACC_PUBLIC)
1563 
1564 		PHP_ME(amqp_connection_class, getPort, 		arginfo_amqp_connection_class_getPort,		ZEND_ACC_PUBLIC)
1565 		PHP_ME(amqp_connection_class, setPort, 		arginfo_amqp_connection_class_setPort,		ZEND_ACC_PUBLIC)
1566 
1567 		PHP_ME(amqp_connection_class, getVhost, 	arginfo_amqp_connection_class_getVhost,		ZEND_ACC_PUBLIC)
1568 		PHP_ME(amqp_connection_class, setVhost, 	arginfo_amqp_connection_class_setVhost,		ZEND_ACC_PUBLIC)
1569 
1570 		PHP_ME(amqp_connection_class, getTimeout, 	arginfo_amqp_connection_class_getTimeout,	ZEND_ACC_PUBLIC)
1571 		PHP_ME(amqp_connection_class, setTimeout, 	arginfo_amqp_connection_class_setTimeout,	ZEND_ACC_PUBLIC)
1572 
1573 		PHP_ME(amqp_connection_class, getReadTimeout, 	arginfo_amqp_connection_class_getReadTimeout,	ZEND_ACC_PUBLIC)
1574 		PHP_ME(amqp_connection_class, setReadTimeout, 	arginfo_amqp_connection_class_setReadTimeout,	ZEND_ACC_PUBLIC)
1575 
1576 		PHP_ME(amqp_connection_class, getWriteTimeout, 	arginfo_amqp_connection_class_getWriteTimeout,	ZEND_ACC_PUBLIC)
1577 		PHP_ME(amqp_connection_class, setWriteTimeout, 	arginfo_amqp_connection_class_setWriteTimeout,	ZEND_ACC_PUBLIC)
1578 
1579 		PHP_ME(amqp_connection_class, getRpcTimeout, 	arginfo_amqp_connection_class_getRpcTimeout,	ZEND_ACC_PUBLIC)
1580 		PHP_ME(amqp_connection_class, setRpcTimeout, 	arginfo_amqp_connection_class_setRpcTimeout,	ZEND_ACC_PUBLIC)
1581 
1582 		PHP_ME(amqp_connection_class, getUsedChannels, arginfo_amqp_connection_class_getUsedChannels,	ZEND_ACC_PUBLIC)
1583 		PHP_ME(amqp_connection_class, getMaxChannels,  arginfo_amqp_connection_class_getMaxChannels,	ZEND_ACC_PUBLIC)
1584 		PHP_ME(amqp_connection_class, isPersistent, 	arginfo_amqp_connection_class_isPersistent,		ZEND_ACC_PUBLIC)
1585 		PHP_ME(amqp_connection_class, getHeartbeatInterval,  arginfo_amqp_connection_class_getHeartbeatInterval,	ZEND_ACC_PUBLIC)
1586 		PHP_ME(amqp_connection_class, getMaxFrameSize,  arginfo_amqp_connection_class_getMaxFrameSize,	ZEND_ACC_PUBLIC)
1587 
1588 		PHP_ME(amqp_connection_class, getCACert, 	arginfo_amqp_connection_class_getCACert,		ZEND_ACC_PUBLIC)
1589 		PHP_ME(amqp_connection_class, setCACert, 	arginfo_amqp_connection_class_setCACert,		ZEND_ACC_PUBLIC)
1590 
1591 		PHP_ME(amqp_connection_class, getCert, 	arginfo_amqp_connection_class_getCert,		ZEND_ACC_PUBLIC)
1592 		PHP_ME(amqp_connection_class, setCert, 	arginfo_amqp_connection_class_setCert,		ZEND_ACC_PUBLIC)
1593 
1594 		PHP_ME(amqp_connection_class, getKey, 	arginfo_amqp_connection_class_getKey,		ZEND_ACC_PUBLIC)
1595 		PHP_ME(amqp_connection_class, setKey, 	arginfo_amqp_connection_class_setKey,		ZEND_ACC_PUBLIC)
1596 
1597 		PHP_ME(amqp_connection_class, getVerify, 	arginfo_amqp_connection_class_getVerify,		ZEND_ACC_PUBLIC)
1598 		PHP_ME(amqp_connection_class, setVerify, 	arginfo_amqp_connection_class_setVerify,		ZEND_ACC_PUBLIC)
1599 
1600 		PHP_ME(amqp_connection_class, getSaslMethod, 	arginfo_amqp_connection_class_getSaslMethod,		ZEND_ACC_PUBLIC)
1601 		PHP_ME(amqp_connection_class, setSaslMethod, 	arginfo_amqp_connection_class_setSaslMethod,		ZEND_ACC_PUBLIC)
1602 
1603 		PHP_ME(amqp_connection_class, getConnectionName, 	arginfo_amqp_connection_class_getConnectionName,		ZEND_ACC_PUBLIC)
1604 		PHP_ME(amqp_connection_class, setConnectionName, 	arginfo_amqp_connection_class_setConnectionName,		ZEND_ACC_PUBLIC)
1605 
1606 		{NULL, NULL, NULL}
1607 };
1608 
1609 
PHP_MINIT_FUNCTION(amqp_connection)1610 PHP_MINIT_FUNCTION(amqp_connection)
1611 {
1612 	zend_class_entry ce;
1613 
1614 	INIT_CLASS_ENTRY(ce, "AMQPConnection", amqp_connection_class_functions);
1615 	ce.create_object = amqp_connection_ctor;
1616 	this_ce = zend_register_internal_class(&ce TSRMLS_CC);
1617 
1618 	zend_declare_property_null(this_ce, ZEND_STRL("login"), ZEND_ACC_PRIVATE TSRMLS_CC);
1619 	zend_declare_property_null(this_ce, ZEND_STRL("password"), ZEND_ACC_PRIVATE TSRMLS_CC);
1620 	zend_declare_property_null(this_ce, ZEND_STRL("host"), ZEND_ACC_PRIVATE TSRMLS_CC);
1621 	zend_declare_property_null(this_ce, ZEND_STRL("vhost"), ZEND_ACC_PRIVATE TSRMLS_CC);
1622 	zend_declare_property_null(this_ce, ZEND_STRL("port"), ZEND_ACC_PRIVATE TSRMLS_CC);
1623 
1624 	zend_declare_property_null(this_ce, ZEND_STRL("read_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC);
1625 	zend_declare_property_null(this_ce, ZEND_STRL("write_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC);
1626 	zend_declare_property_null(this_ce, ZEND_STRL("connect_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC);
1627 	zend_declare_property_null(this_ce, ZEND_STRL("rpc_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC);
1628 
1629 	zend_declare_property_null(this_ce, ZEND_STRL("channel_max"), ZEND_ACC_PRIVATE TSRMLS_CC);
1630 	zend_declare_property_null(this_ce, ZEND_STRL("frame_max"), ZEND_ACC_PRIVATE TSRMLS_CC);
1631 	zend_declare_property_null(this_ce, ZEND_STRL("heartbeat"), ZEND_ACC_PRIVATE TSRMLS_CC);
1632 
1633 	zend_declare_property_null(this_ce, ZEND_STRL("cacert"), ZEND_ACC_PRIVATE TSRMLS_CC);
1634 	zend_declare_property_null(this_ce, ZEND_STRL("key"), ZEND_ACC_PRIVATE TSRMLS_CC);
1635 	zend_declare_property_null(this_ce, ZEND_STRL("cert"), ZEND_ACC_PRIVATE TSRMLS_CC);
1636 	zend_declare_property_null(this_ce, ZEND_STRL("verify"), ZEND_ACC_PRIVATE TSRMLS_CC);
1637 
1638 	zend_declare_property_null(this_ce, ZEND_STRL("sasl_method"), ZEND_ACC_PRIVATE TSRMLS_CC);
1639 
1640 	zend_declare_property_null(this_ce, ZEND_STRL("connection_name"), ZEND_ACC_PRIVATE TSRMLS_CC);
1641 
1642 #if PHP_MAJOR_VERSION >=7
1643 	memcpy(&amqp_connection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1644 
1645 	amqp_connection_object_handlers.offset = XtOffsetOf(amqp_connection_object, zo);
1646 	amqp_connection_object_handlers.free_obj = amqp_connection_free;
1647 #endif
1648 
1649 	return SUCCESS;
1650 }
1651 
1652 /*
1653 *Local variables:
1654 *tab-width: 4
1655 *c-basic-offset: 4
1656 *End:
1657 *vim600: noet sw=4 ts=4 fdm=marker
1658 *vim<6
1659 */
1660