cvs: php4 /ext/yaz php_yaz.c
| From: | Adam Dickmeiss | Date: | Mon, 30 Apr 2001 14:11:12 +0000 |
| Subject: | cvs: php4 /ext/yaz php_yaz.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-5390@lists.php.net to get a copy of this message | ||
dickmeiss Mon Apr 30 07:11:12 2001 EDT
Modified files:
/php4/ext/yaz php_yaz.c
Log:
Timeout setting for yaz_wait. Force call by reference for yaz_ccl_parse
and yaz_scan_result.
Index: php4/ext/yaz/php_yaz.c
diff -u php4/ext/yaz/php_yaz.c:1.15 php4/ext/yaz/php_yaz.c:1.16
--- php4/ext/yaz/php_yaz.c:1.15 Wed Apr 18 08:03:23 2001
+++ php4/ext/yaz/php_yaz.c Mon Apr 30 07:11:12 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_yaz.c,v 1.15 2001/04/18 15:03:23 dickmeiss Exp $ */
+/* $Id: php_yaz.c,v 1.16 2001/04/30 14:11:12 dickmeiss Exp $ */
#include "php.h"
@@ -205,11 +205,17 @@
static Yaz_Association *shared_associations;
static int order_associations;
+static unsigned char third_argument_force_ref[] = {
+ 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
+
+static unsigned char second_argument_force_ref[] = {
+ 2, BYREF_NONE, BYREF_FORCE };
+
function_entry yaz_functions [] = {
PHP_FE(yaz_connect, NULL)
PHP_FE(yaz_close, NULL)
PHP_FE(yaz_search, NULL)
- PHP_FE(yaz_wait, NULL)
+ PHP_FE(yaz_wait, second_argument_force_ref)
PHP_FE(yaz_errno, NULL)
PHP_FE(yaz_error, NULL)
PHP_FE(yaz_addinfo, NULL)
@@ -220,10 +226,10 @@
PHP_FE(yaz_range, NULL)
PHP_FE(yaz_itemorder, NULL)
PHP_FE(yaz_scan, NULL)
- PHP_FE(yaz_scan_result, NULL)
+ PHP_FE(yaz_scan_result, second_argument_force_ref)
PHP_FE(yaz_present, NULL)
PHP_FE(yaz_ccl_conf, NULL)
- PHP_FE(yaz_ccl_parse, NULL)
+ PHP_FE(yaz_ccl_parse, third_argument_force_ref)
PHP_FE(yaz_database, NULL)
{NULL, NULL, NULL}
};
@@ -325,6 +331,35 @@
t->error = *r->condition;
}
+static const char *array_lookup_string(HashTable *ht, const char *idx)
+{
+ pval **pvalue;
+
+ if (ht && zend_hash_find(ht, (char*) idx, strlen(idx)+1,
+ (void**) &pvalue) == SUCCESS)
+ {
+ SEPARATE_ZVAL(pvalue);
+ convert_to_string(*pvalue);
+ return (*pvalue)->value.str.val;
+ }
+ return 0;
+}
+
+static long *array_lookup_long(HashTable *ht, const char *idx)
+{
+ pval **pvalue;
+
+ if (ht && zend_hash_find(ht, (char*) idx, strlen(idx)+1,
+ (void**) &pvalue) == SUCCESS)
+ {
+ SEPARATE_ZVAL(pvalue);
+ convert_to_long(*pvalue);
+ return &(*pvalue)->value.lval;
+ }
+ return 0;
+}
+
+
static int send_present (Yaz_Association t);
static void handle_records (Yaz_Association t, Z_Records *sr,
@@ -894,7 +929,7 @@
send_APDU (t, apdu);
}
-static int do_event (int *id)
+static int do_event (int *id, int timeout)
{
fd_set input, output;
int i;
@@ -902,7 +937,7 @@
int max_fd = 0;
struct timeval tv;
- tv.tv_sec = 15;
+ tv.tv_sec = timeout;
tv.tv_usec = 0;
#ifdef ZTS
@@ -951,10 +986,7 @@
{
if (p->mask_select) /* only mark for those still pending */
{
- if (p->state == PHP_YAZ_STATE_CONNECTING)
- p->error = PHP_YAZ_ERROR_CONNECT;
- else
- p->error = PHP_YAZ_ERROR_TIMEOUT;
+ p->error = PHP_YAZ_ERROR_TIMEOUT;
do_close (p);
}
}
@@ -1208,12 +1240,32 @@
}
/* }}} */
-/* {{{ proto int yaz_wait()
- Process all outstanding events. */
+/* {{{ proto int yaz_wait([array options])
+ Process events. */
PHP_FUNCTION(yaz_wait)
{
int i;
int id;
+ int timeout = 15;
+ if (ZEND_NUM_ARGS() == 1)
+ {
+ long *val = 0;
+ pval **pval_options = 0;
+ HashTable *options_ht = 0;
+ if (zend_get_parameters_ex(1, &pval_options) == FAILURE)
+ {
+ WRONG_PARAM_COUNT;
+ }
+ if (Z_TYPE_PP(pval_options) != IS_ARRAY)
+ {
+ php_error(E_WARNING, "yaz_wait: Expected array parameter");
+ RETURN_FALSE;
+ }
+ options_ht = Z_ARRVAL_PP(pval_options);
+ val = array_lookup_long(options_ht, "timeout");
+ if (val)
+ timeout = *val;
+ }
#ifdef ZTS
tsrm_mutex_lock (yaz_mutex);
#endif
@@ -1236,7 +1288,7 @@
#ifdef ZTS
tsrm_mutex_unlock (yaz_mutex);
#endif
- while (do_event(&id))
+ while (do_event(&id, timeout))
;
RETURN_TRUE;
}
@@ -1788,23 +1840,9 @@
}
/* }}} */
-static const char *array_lookup(HashTable *ht, const char *idx)
-{
- pval **pvalue;
-
- if (ht && zend_hash_find(ht, (char*) idx, strlen(idx)+1,
- (void**) &pvalue) == SUCCESS)
- {
- SEPARATE_ZVAL(pvalue);
- convert_to_string(*pvalue);
- return (*pvalue)->value.str.val;
- }
- return 0;
-}
-
static const char *ill_array_lookup (void *clientData, const char *idx)
{
- return array_lookup((HashTable *) clientData, idx+4);
+ return array_lookup_string((HashTable *) clientData, idx+4);
}
static Z_External *encode_ill_request (Yaz_Association t, HashTable *ht)
@@ -1876,15 +1914,15 @@
req->u.esRequest->toKeep->contact =
odr_malloc (t->odr_out, sizeof(*req->u.esRequest->toKeep->contact));
- str = array_lookup (ht, "contact-name");
+ str = array_lookup_string (ht, "contact-name");
req->u.esRequest->toKeep->contact->name = str ?
nmem_strdup (t->odr_out->mem, str) : 0;
- str = array_lookup (ht, "contact-phone");
+ str = array_lookup_string (ht, "contact-phone");
req->u.esRequest->toKeep->contact->phone = str ?
nmem_strdup (t->odr_out->mem, str) : 0;
- str = array_lookup (ht, "contact-email");
+ str = array_lookup_string (ht, "contact-email");
req->u.esRequest->toKeep->contact->email = str ?
nmem_strdup (t->odr_out->mem, str) : 0;
@@ -1900,7 +1938,7 @@
req->u.esRequest->notToKeep->resultSetItem->item =
(int *) odr_malloc(t->odr_out, sizeof(int));
- str = array_lookup (ht, "itemorder-item");
+ str = array_lookup_string (ht, "itemorder-item");
*req->u.esRequest->notToKeep->resultSetItem->item =
(str ? atoi(str) : 1);
@@ -1932,11 +1970,11 @@
r->u.itemOrder = encode_item_order (t, ht);
req->packageType = odr_oiddup(t->odr_out, oid_ent_to_oid(&oident, oid));
- str = array_lookup(ht, "package-name");
+ str = array_lookup_string(ht, "package-name");
if (str && *str)
req->packageName = nmem_strdup (t->odr_out->mem, str);
- str = array_lookup(ht, "user-id");
+ str = array_lookup_string(ht, "user-id");
if (str)
req->userId = nmem_strdup (t->odr_out->mem, str);
@@ -2008,17 +2046,17 @@
php_error (E_WARNING, str);
return 0;
}
- val = array_lookup(ht, "number");
+ val = array_lookup_string(ht, "number");
if (val && *val)
*req->numberOfTermsRequested = atoi(val);
- val = array_lookup(ht, "position");
+ val = array_lookup_string(ht, "position");
if (val && *val)
{
req->preferredPositionInResponse =
odr_malloc (t->odr_out, sizeof(int));
*req->preferredPositionInResponse = atoi(val);
}
- val = array_lookup(ht, "stepsize");
+ val = array_lookup_string(ht, "stepsize");
if (val && *val)
{
req->stepSize = odr_malloc (t->odr_out, sizeof(int));
@@ -2229,7 +2267,7 @@
PHP_FUNCTION(yaz_ccl_parse)
{
- pval **pval_id, **pval_query, **pval_res;
+ pval **pval_id, **pval_query, **pval_res = 0;
Yaz_Association p;
if (ZEND_NUM_ARGS() != 3 ||
zend_get_parameters_ex(3, &pval_id, &pval_query, &pval_res) ==
@@ -2237,12 +2275,15 @@
{
WRONG_PARAM_COUNT;
}
- if (!ParameterPassedByReference(ht, 3))
- {
- WRONG_PARAM_COUNT;
+
+ if (!ParameterPassedByReference(ht, 3)) {
+ php_error(E_WARNING, "Third argument must be passed by reference.");
+ RETURN_FALSE;
}
+ pval_destructor(*pval_res);
if (array_init(*pval_res) == FAILURE)
{
+ php_error(E_WARNING, "cannot initialize array");
RETURN_FALSE;
}
convert_to_string_ex (pval_query);