From: Adam Dickmeiss Date: Mon, 30 Apr 2001 14:11:15 +0000 (+0000) Subject: Timeout setting for yaz_wait. Force call by reference for yaz_ccl_parse X-Git-Tag: php-4.0.6RC1~235 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8e177c7a3431f4897b60185c1c9f5ed51361ca9;p=php Timeout setting for yaz_wait. Force call by reference for yaz_ccl_parse and yaz_scan_result. --- diff --git a/ext/yaz/php_yaz.c b/ext/yaz/php_yaz.c index b82097ec8a..ca241b6bb0 100644 --- a/ext/yaz/php_yaz.c +++ b/ext/yaz/php_yaz.c @@ -205,11 +205,17 @@ static MUTEX_T yaz_mutex; 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 @@ function_entry yaz_functions [] = { 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 @@ static void response_diag (Yaz_Association t, Z_DiagRec *p) 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 @@ static void send_init(Yaz_Association t) 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 @@ static int do_event (int *id) 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 @@ static int do_event (int *id) { 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 @@ PHP_FUNCTION(yaz_present) } /* }}} */ -/* {{{ 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 @@ PHP_FUNCTION(yaz_wait) #ifdef ZTS tsrm_mutex_unlock (yaz_mutex); #endif - while (do_event(&id)) + while (do_event(&id, timeout)) ; RETURN_TRUE; } @@ -1788,23 +1840,9 @@ PHP_FUNCTION(yaz_range) } /* }}} */ -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 @@ static Z_ItemOrder *encode_item_order(Yaz_Association t, 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 @@ static Z_ItemOrder *encode_item_order(Yaz_Association t, 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 @@ static Z_APDU *encode_es_itemorder (Yaz_Association t, HashTable *ht) 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 @@ static Z_APDU *encode_scan (Yaz_Association t, const char *type, 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_conf) 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 @@ PHP_FUNCTION(yaz_ccl_parse) { 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);