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)
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}
};
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,
send_APDU (t, apdu);
}
-static int do_event (int *id)
+static int do_event (int *id, int timeout)
{
fd_set input, output;
int i;
int max_fd = 0;
struct timeval tv;
- tv.tv_sec = 15;
+ tv.tv_sec = timeout;
tv.tv_usec = 0;
#ifdef ZTS
{
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);
}
}
}
/* }}} */
-/* {{{ 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
#ifdef ZTS
tsrm_mutex_unlock (yaz_mutex);
#endif
- while (do_event(&id))
+ while (do_event(&id, timeout))
;
RETURN_TRUE;
}
}
/* }}} */
-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)
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;
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);
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);
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));
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) ==
{
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);