[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] =?utf-8?q?svn:_/pecl/varnish/trunk/_adm.c_exception.h_php=5Fvarnish.h_varnish.c_varnish=5
From:       Anatoliy_Belsky <ab () php ! net>
Date:       2011-09-30 21:34:45
Message-ID: svn-ab-1317418485-317557-518486971 () svn ! php ! net
[Download RAW message or body]

ab                                       Fri, 30 Sep 2011 21:34:45 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=317557

Log:
integrated compatibility stuff for VarnishAdmin and compatibility check

Changed paths:
    U   pecl/varnish/trunk/adm.c
    U   pecl/varnish/trunk/exception.h
    U   pecl/varnish/trunk/php_varnish.h
    U   pecl/varnish/trunk/varnish.c
    U   pecl/varnish/trunk/varnish_lib.c
    U   pecl/varnish/trunk/varnish_lib.h

Modified: pecl/varnish/trunk/adm.c
===================================================================
--- pecl/varnish/trunk/adm.c	2011-09-30 21:17:43 UTC (rev 317556)
+++ pecl/varnish/trunk/adm.c	2011-09-30 21:34:45 UTC (rev 317557)
@@ -90,6 +90,7 @@
 	zvao->zvc.ident	     = NULL;
 	zvao->zvc.authok     = 0;
 	zvao->status		 = PHP_VARNISH_STATUS_CLOSE;
+	zvao->compat		 = PHP_VARNISH_COMPAT_3;

 	ret.handle = zend_objects_store_put(zvao, NULL,
 										(zend_objects_free_object_storage_t) php_varnish_adm_obj_destroy,
@@ -125,7 +126,7 @@
 PHP_METHOD(VarnishAdmin, __construct)
 {
 	struct ze_varnish_adm_obj *zvao;
-	zval *opts = NULL, **secret, **addr, **port, **timeout, **ident;
+	zval *opts = NULL, **secret, **addr, **port, **timeout, **ident, **compat;

 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &opts) == FAILURE) {
 		return;
@@ -172,6 +173,14 @@
 			zvao->zvc.timeout = (int)Z_LVAL_PP(timeout);
 		}

+		if(zend_hash_find(Z_ARRVAL_P(opts), "compat", sizeof("compat"), (void**)&compat) != FAILURE) {
+			convert_to_long(*compat);
+			zvao->compat = (int)Z_LVAL_PP(compat);
+		}
+		if (!php_varnish_check_compat(zvao->compat TSRMLS_CC)) {
+			return;
+		}
+
 		if(zend_hash_find(Z_ARRVAL_P(opts), "secret", sizeof("secret"), (void**)&secret) != FAILURE) {
 			convert_to_string(*secret);
 			zvao->zvc.secret = estrdup(Z_STRVAL_PP(secret));
@@ -600,6 +609,27 @@
 }
 /* }}} */

+/* {{{ proto void VarnishAdmin::setCompat(int compat)
+ Set the varnish compatibility */
+PHP_METHOD(VarnishAdmin, setCompat)
+{
+	struct ze_varnish_adm_obj *zvao;
+	zval *compat;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &compat) == FAILURE) {
+		return;
+	}
+
+	zvao = (struct ze_varnish_adm_obj *) zend_object_store_get_object(getThis() TSRMLS_CC);
+
+	convert_to_long(compat);
+	zvao->compat = (int)Z_LVAL_P(compat);
+
+	php_varnish_check_compat(zvao->compat TSRMLS_CC);
+}
+/* }}} */
+
+
 /*
  * Local variables:
  * tab-width: 4

Modified: pecl/varnish/trunk/exception.h
===================================================================
--- pecl/varnish/trunk/exception.h	2011-09-30 21:17:43 UTC (rev 317556)
+++ pecl/varnish/trunk/exception.h	2011-09-30 21:34:45 UTC (rev 317557)
@@ -47,6 +47,7 @@
 	PHP_VARNISH_HANDSHAKE_EXCEPTION,
 	PHP_VARNISH_TMO_EXCEPTION,
 	PHP_VARNISH_SHM_EXCEPTION,
+	PHP_VARNISH_COMPAT_EXCEPTION,
 };

 void

Modified: pecl/varnish/trunk/php_varnish.h
===================================================================
--- pecl/varnish/trunk/php_varnish.h	2011-09-30 21:17:43 UTC (rev 317556)
+++ pecl/varnish/trunk/php_varnish.h	2011-09-30 21:34:45 UTC (rev 317557)
@@ -75,6 +75,7 @@
 PHP_METHOD(VarnishAdmin, setPort);
 PHP_METHOD(VarnishAdmin, setTimeout);
 PHP_METHOD(VarnishAdmin, setSecret);
+PHP_METHOD(VarnishAdmin, setCompat);

 PHP_METHOD(VarnishStat, __construct);
 PHP_METHOD(VarnishStat, getSnapshot);
@@ -117,6 +118,7 @@
 	zend_object zo;
 	struct ze_varnish_conn zvc;
 	int status;
+	int compat;
 };

 struct ze_varnish_stat_obj {

Modified: pecl/varnish/trunk/varnish.c
===================================================================
--- pecl/varnish/trunk/varnish.c	2011-09-30 21:17:43 UTC (rev 317556)
+++ pecl/varnish/trunk/varnish.c	2011-09-30 21:34:45 UTC (rev 317557)
@@ -77,6 +77,7 @@
 	PHP_ME(VarnishAdmin, setTimeout, NULL, ZEND_ACC_PUBLIC)
 	PHP_ME(VarnishAdmin, setPort, NULL, ZEND_ACC_PUBLIC)
 	PHP_ME(VarnishAdmin, setSecret, NULL, ZEND_ACC_PUBLIC)
+	PHP_ME(VarnishAdmin, setCompat, NULL, ZEND_ACC_PUBLIC)
 	{NULL, NULL, NULL}
 };
 /* }}} */

Modified: pecl/varnish/trunk/varnish_lib.c
===================================================================
--- pecl/varnish/trunk/varnish_lib.c	2011-09-30 21:17:43 UTC (rev 317556)
+++ pecl/varnish/trunk/varnish_lib.c	2011-09-30 21:34:45 UTC (rev 317557)
@@ -812,7 +812,7 @@

 int
 php_varnish_adm_can_go(struct ze_varnish_adm_obj *zvao TSRMLS_DC)
-{
+{/*{{{*/
 	if (zvao->zvc.sock < 0) {
 		php_varnish_throw_conn_exception(TSRMLS_C);
 		return 0;
@@ -824,8 +824,25 @@
 	}

 	return 1;
-}
+}/*}}}*/

+int
+php_varnish_check_compat(int compat TSRMLS_DC)
+{/*{{{*/
+	if (PHP_VARNISH_COMPAT_2 != compat && PHP_VARNISH_COMPAT_3 != compat) {
+		zend_throw_exception_ex(
+			VarnishException_ce,
+			PHP_VARNISH_COMPAT_EXCEPTION TSRMLS_CC,
+			"Unsupported compatibility option '%d'",
+			compat
+		);
+		return 0;
+	}
+
+	return 1;
+}/*}}}*/
+
+
 /*
  * Local variables:
  * tab-width: 4

Modified: pecl/varnish/trunk/varnish_lib.h
===================================================================
--- pecl/varnish/trunk/varnish_lib.h	2011-09-30 21:17:43 UTC (rev 317556)
+++ pecl/varnish/trunk/varnish_lib.h	2011-09-30 21:34:45 UTC (rev 317557)
@@ -86,6 +86,9 @@
 int
 php_varnish_adm_can_go(struct ze_varnish_adm_obj *zvao TSRMLS_DC);

+int
+php_varnish_check_compat(int version TSRMLS_DC);
+
 /* First response line length including '\0' */
 #define PHP_VARNISH_LINE0_MAX_LEN CLI_LINE0_LEN

@@ -199,8 +202,8 @@
 };

 enum {
-	PHP_VARNISH_COMPAT_2,
-	PHP_VARNISH_COMPAT_3,
+	PHP_VARNISH_COMPAT_2 = 2,
+	PHP_VARNISH_COMPAT_3 = 3,
 };

 #endif	/* PHP_VARNISH_LIB_H */



-- 
PECL CVS Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic