X-Git-Url: http://git.indexdata.com/?p=phpyaz-moved-to-github.git;a=blobdiff_plain;f=php_yaz.c;h=3dfdd5d799a6ba68788501c1d84713f38b0e12d4;hp=a6720994c1597ecbe27e65b535fdbf0533114783;hb=ec1920117fc9a3310b64322881906dda20e66d1d;hpb=826d85668f6e97bbf5f10fa93d2f16ae055471ba diff --git a/php_yaz.c b/php_yaz.c index a672099..3dfdd5d 100644 --- a/php_yaz.c +++ b/php_yaz.c @@ -2,12 +2,12 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | + | Copyright (c) 1997-2011 The PHP Group | +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | + | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | + | http://www.php.net/license/3_01.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_yaz.c,v 1.115 2008/02/20 10:08:15 dickmeiss Exp $ */ - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -50,6 +48,10 @@ #include #include +#ifndef ODR_INT_PRINTF +#define ODR_INT_PRINTF %d +#endif + #define MAX_ASSOC 200 typedef struct Yaz_AssociationInfo *Yaz_Association; @@ -70,9 +72,9 @@ struct Yaz_AssociationInfo { static Yaz_Association yaz_association_mk() { - Yaz_Association p = xmalloc (sizeof(*p)); + Yaz_Association p = xmalloc(sizeof(*p)); - p->zoom_conn = ZOOM_connection_create (0); + p->zoom_conn = ZOOM_connection_create(0); p->zoom_set = 0; p->zoom_scan = 0; p->zoom_package = 0; @@ -87,7 +89,7 @@ static Yaz_Association yaz_association_mk() return p; } -static void yaz_association_destroy (Yaz_Association p) +static void yaz_association_destroy(Yaz_Association p) { if (!p) { return; @@ -141,7 +143,7 @@ static unsigned char third_argument_force_ref[] = { #endif -function_entry yaz_functions [] = { +zend_function_entry yaz_functions [] = { PHP_FE(yaz_connect, NULL) PHP_FE(yaz_close, NULL) PHP_FE(yaz_search, NULL) @@ -170,22 +172,22 @@ function_entry yaz_functions [] = { {NULL, NULL, NULL} }; -static void get_assoc(INTERNAL_FUNCTION_PARAMETERS, pval **id, Yaz_Association *assocp) +static void get_assoc(INTERNAL_FUNCTION_PARAMETERS, zval *id, Yaz_Association *assocp) { Yaz_Association *as = 0; - + *assocp = 0; #ifdef ZTS - tsrm_mutex_lock (yaz_mutex); + tsrm_mutex_lock(yaz_mutex); #endif - ZEND_FETCH_RESOURCE(as, Yaz_Association *, id, -1, "YAZ link", le_link); + ZEND_FETCH_RESOURCE(as, Yaz_Association *, &id, -1, "YAZ link", le_link); if (as && *as && (*as)->order == YAZSG(assoc_seq) && (*as)->in_use) { *assocp = *as; } else { #ifdef ZTS - tsrm_mutex_unlock (yaz_mutex); + tsrm_mutex_unlock(yaz_mutex); #endif php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid YAZ handle"); } @@ -202,7 +204,7 @@ static void release_assoc(Yaz_Association assoc) static const char *array_lookup_string(HashTable *ht, const char *idx) { - pval **pvalue; + zval **pvalue; if (ht && zend_hash_find(ht, (char *) idx, strlen(idx) + 1, (void **) &pvalue) == SUCCESS) { SEPARATE_ZVAL(pvalue); @@ -214,7 +216,7 @@ static const char *array_lookup_string(HashTable *ht, const char *idx) static long *array_lookup_long(HashTable *ht, const char *idx) { - pval **pvalue; + zval **pvalue; if (ht && zend_hash_find(ht, (char *) idx, strlen(idx) + 1, (void **) &pvalue) == SUCCESS) { SEPARATE_ZVAL(pvalue); @@ -226,7 +228,7 @@ static long *array_lookup_long(HashTable *ht, const char *idx) static long *array_lookup_bool(HashTable *ht, const char *idx) { - pval **pvalue; + zval **pvalue; if (ht && zend_hash_find(ht, (char *) idx, strlen(idx) + 1, (void **) &pvalue) == SUCCESS) { SEPARATE_ZVAL(pvalue); @@ -269,7 +271,7 @@ static void option_set_int(Yaz_Association as, const char *name, int v) if (as) { char s[30]; - sprintf (s, "%d", v); + sprintf(s, "%d", v); ZOOM_connection_option_set(as->zoom_conn, name, s); } } @@ -292,6 +294,7 @@ PHP_FUNCTION(yaz_connect) int i; char *cp; char *zurl_str; + int zurl_len; const char *sru_str = 0, *sru_version_str = 0; const char *user_str = 0, *group_str = 0, *pass_str = 0; const char *cookie_str = 0, *proxy_str = 0; @@ -302,26 +305,28 @@ PHP_FUNCTION(yaz_connect) const char *preferredMessageSize = 0; int persistent = 1; int piggyback = 1; - pval **zurl, **user = 0; Yaz_Association as; int max_links = YAZSG(max_links); otherInfo[0] = otherInfo[1] = otherInfo[2] = 0; if (ZEND_NUM_ARGS() == 1) { - if (zend_get_parameters_ex (1, &zurl) == FAILURE) { + if (zend_parse_parameters(1 TSRMLS_CC, "s", &zurl_str, &zurl_len) + == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 2) { - if (zend_get_parameters_ex (2, &zurl, &user) == FAILURE) { + zval *user = 0; + if (zend_parse_parameters(2 TSRMLS_CC, "sz", &zurl_str, &zurl_len, + &user) == FAILURE) { WRONG_PARAM_COUNT; } - if (Z_TYPE_PP(user) == IS_ARRAY) { + if (Z_TYPE_PP(&user) == IS_ARRAY) { long *persistent_val; long *piggyback_val; - HashTable *ht = Z_ARRVAL_PP(user); - + HashTable *ht = Z_ARRVAL_PP(&user); + sru_str = array_lookup_string(ht, "sru"); sru_version_str = array_lookup_string(ht, "sru_version"); user_str = array_lookup_string(ht, "user"); @@ -345,16 +350,14 @@ PHP_FUNCTION(yaz_connect) otherInfo[0] = array_lookup_string(ht, "otherInfo0"); otherInfo[1] = array_lookup_string(ht, "otherInfo1"); otherInfo[2] = array_lookup_string(ht, "otherInfo2"); - } else if (Z_TYPE_PP(user) == IS_STRING) { - convert_to_string_ex(user); - if (*(*user)->value.str.val) - user_str = (*user)->value.str.val; + } else if (Z_TYPE_PP(&user) == IS_STRING) { + convert_to_string_ex(&user); + if (*user->value.str.val) + user_str = user->value.str.val; } } else { WRONG_PARAM_COUNT; } - convert_to_string_ex(zurl); - zurl_str = (*zurl)->value.str.val; for (cp = zurl_str; *cp && strchr("\t\n ", *cp); cp++); if (!*cp) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty zurl"); @@ -397,9 +400,9 @@ PHP_FUNCTION(yaz_connect) if (i == -1) { char msg[80]; #ifdef ZTS - tsrm_mutex_unlock (yaz_mutex); + tsrm_mutex_unlock(yaz_mutex); #endif - sprintf(msg, "No YAZ handles available. max_links=%d", + sprintf(msg, "No YAZ handles available. max_links=%d", max_links); php_error_docref(NULL TSRMLS_CC, E_WARNING, "No YAZ handles available. max_links=%ld", @@ -409,7 +412,7 @@ PHP_FUNCTION(yaz_connect) yaz_association_destroy(shared_associations[i]); } } - shared_associations[i] = as = yaz_association_mk (); + shared_associations[i] = as = yaz_association_mk(); option_set(as, "proxy", proxy_str); option_set(as, "sru", sru_str); @@ -443,7 +446,7 @@ PHP_FUNCTION(yaz_connect) as->zoom_set = 0; } #ifdef ZTS - tsrm_mutex_unlock (yaz_mutex); + tsrm_mutex_unlock(yaz_mutex); #endif ZEND_REGISTER_RESOURCE(return_value, &shared_associations[i], le_link); @@ -456,20 +459,18 @@ PHP_FUNCTION(yaz_connect) PHP_FUNCTION(yaz_close) { Yaz_Association p; - pval **id; + zval *id; - if (ZEND_NUM_ARGS() != 1) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(1 TSRMLS_CC, "z", &id) + == FAILURE) { WRONG_PARAM_COUNT; } - if (zend_get_parameters_ex (1, &id) == FAILURE) { - RETURN_FALSE; - } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, id, &p); if (!p) { RETURN_FALSE; } release_assoc(p); - zend_list_delete((*id)->value.lval); + zend_list_delete(id->value.lval); RETURN_TRUE; } @@ -480,27 +481,21 @@ PHP_FUNCTION(yaz_close) PHP_FUNCTION(yaz_search) { char *query_str, *type_str; - pval **id, **type, **query; + int query_len, type_len; + zval *id; Yaz_Association p; - if (ZEND_NUM_ARGS() == 3) { - if (zend_get_parameters_ex(3, &id, &type, &query) == FAILURE) { - WRONG_PARAM_COUNT; - } - } else { + if (ZEND_NUM_ARGS() != 3 || + zend_parse_parameters(3 TSRMLS_CC, "zss", &id, + &type_str, &type_len, + &query_str, &query_len) == FAILURE) { WRONG_PARAM_COUNT; } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, id, &p); if (!p) { RETURN_FALSE; } - convert_to_string_ex(type); - type_str = (*type)->value.str.val; - convert_to_string_ex(query); - query_str = (*query)->value.str.val; - ZOOM_resultset_destroy(p->zoom_set); p->zoom_set = 0; @@ -527,7 +522,7 @@ PHP_FUNCTION(yaz_search) if (p->sort_criteria) { ZOOM_query_sortby(q, p->sort_criteria); } - xfree (p->sort_criteria); + xfree(p->sort_criteria); p->sort_criteria = 0; p->zoom_set = ZOOM_connection_search(p->zoom_conn, q); RETVAL_TRUE; @@ -536,7 +531,7 @@ PHP_FUNCTION(yaz_search) } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid query type %s", type_str); } release_assoc(p); @@ -547,16 +542,13 @@ PHP_FUNCTION(yaz_search) Retrieve records */ PHP_FUNCTION(yaz_present) { - pval **id; + zval *id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - if (zend_get_parameters_ex(1, &id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(1 TSRMLS_CC, "z", &id) + == FAILURE) { WRONG_PARAM_COUNT; } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, id, &p); if (!p) { RETURN_FALSE; @@ -578,7 +570,7 @@ PHP_FUNCTION(yaz_present) Process events. */ PHP_FUNCTION(yaz_wait) { - pval **pval_options = 0; + zval *pval_options = 0; int event_mode = 0; int no = 0; ZOOM_connection conn_ar[MAX_ASSOC]; @@ -589,14 +581,11 @@ PHP_FUNCTION(yaz_wait) long *val = 0; long *event_bool = 0; HashTable *options_ht = 0; - if (zend_get_parameters_ex(1, &pval_options) == FAILURE) { + if (zend_parse_parameters(1 TSRMLS_CC, "a", &pval_options) == + FAILURE) { WRONG_PARAM_COUNT; } - if (Z_TYPE_PP(pval_options) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array parameter"); - RETURN_FALSE; - } - options_ht = Z_ARRVAL_PP(pval_options); + options_ht = Z_ARRVAL_PP(&pval_options); val = array_lookup_long(options_ht, "timeout"); if (val) { timeout = *val; @@ -630,9 +619,10 @@ PHP_FUNCTION(yaz_wait) Yaz_Association p = conn_as[ev-1]; int event_code = ZOOM_connection_last_event(p->zoom_conn); - add_assoc_long(*pval_options, "connid", ev); - - add_assoc_long(*pval_options, "eventcode", event_code); + if (pval_options) { + add_assoc_long(pval_options, "connid", ev); + add_assoc_long(pval_options, "eventcode", event_code); + } zend_list_addref(p->zval_resource); Z_LVAL_P(return_value) = p->zval_resource; @@ -642,7 +632,7 @@ PHP_FUNCTION(yaz_wait) } if (no) { - while (ZOOM_event (no, conn_ar)) + while (ZOOM_event(no, conn_ar)) ; } RETURN_TRUE; @@ -653,10 +643,11 @@ PHP_FUNCTION(yaz_wait) Return last error number (>0 for bib-1 diagnostic, <0 for other error, 0 for no error */ PHP_FUNCTION(yaz_errno) { - pval **id; + zval *id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(1 TSRMLS_CC, "z", &id) + == FAILURE) { WRONG_PARAM_COUNT; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, id, &p); @@ -672,13 +663,13 @@ PHP_FUNCTION(yaz_errno) Return last error message */ PHP_FUNCTION(yaz_error) { - pval **id; + zval *id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(1 TSRMLS_CC, "z", &id) + == FAILURE) { WRONG_PARAM_COUNT; } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, id, &p); if (p) { int code = ZOOM_connection_errcode(p->zoom_conn); @@ -699,13 +690,13 @@ PHP_FUNCTION(yaz_error) Return additional info for last error (empty string if none) */ PHP_FUNCTION(yaz_addinfo) { - pval **id; + zval *id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(1 TSRMLS_CC, "z", &id) + == FAILURE) { WRONG_PARAM_COUNT; } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, id, &p); if (p) { const char *addinfo = ZOOM_connection_addinfo(p->zoom_conn); @@ -713,7 +704,7 @@ PHP_FUNCTION(yaz_addinfo) return_value->value.str.len = strlen(addinfo); return_value->value.str.val = estrndup(addinfo, return_value->value.str.len); return_value->type = IS_STRING; - } + } release_assoc(p); } /* }}} */ @@ -722,22 +713,18 @@ PHP_FUNCTION(yaz_addinfo) Return number of hits (result count) for last search */ PHP_FUNCTION(yaz_hits) { - pval **id, **searchresult = 0; + zval *id, *searchresult = 0; Yaz_Association p; if (ZEND_NUM_ARGS() == 1) { - if (zend_get_parameters_ex(1, &id) == FAILURE) { + if (zend_parse_parameters(1 TSRMLS_CC, "z", &id) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 2) { - if (zend_get_parameters_ex(2, &id, &searchresult) == FAILURE) { + if (zend_parse_parameters(2 TSRMLS_CC, "za", &id, &searchresult) + == FAILURE) { WRONG_PARAM_COUNT; } - if (array_init(*searchresult) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "Could not initialize search result array"); - RETURN_FALSE; - } } else { WRONG_PARAM_COUNT; } @@ -750,7 +737,7 @@ PHP_FUNCTION(yaz_hits) const char *str = ZOOM_resultset_option_get(p->zoom_set, "resultSetStatus"); if (str) - add_assoc_string(*searchresult, "resultSetStatus", + add_assoc_string(searchresult, "resultSetStatus", (char *) str, 1); } if (searchresult) @@ -759,7 +746,6 @@ PHP_FUNCTION(yaz_hits) ZOOM_resultset_option_get(p->zoom_set, "searchresult.size"); int i, sz = 0; - if (sz_str && *sz_str) sz = atoi(sz_str); for (i = 0; izoom_set, opt_name); if (opt_value) @@ -782,7 +768,7 @@ PHP_FUNCTION(yaz_hits) opt_value = ZOOM_resultset_option_get(p->zoom_set, opt_name); if (opt_value) add_assoc_long(zval_element, "count", atoi(opt_value)); - + sprintf(opt_name, "searchresult.%d.subquery.term", i); opt_value = ZOOM_resultset_option_get(p->zoom_set, opt_name); if (opt_value) @@ -821,10 +807,10 @@ static Z_GenericRecord *marc_to_grs1(const char *buf, ODR o) int length_starting; int length_implementation; int max_elements = 256; - Z_GenericRecord *r = odr_malloc (o, sizeof(*r)); - r->elements = odr_malloc (o, sizeof(*r->elements) * max_elements); + Z_GenericRecord *r = odr_malloc(o, sizeof(*r)); + r->elements = odr_malloc(o, sizeof(*r->elements) * max_elements); r->num_elements = 0; - + record_length = atoi_n(buf, 5); if (record_length < 25) { return 0; @@ -832,11 +818,11 @@ static Z_GenericRecord *marc_to_grs1(const char *buf, ODR o) indicator_length = atoi_n(buf + 10, 1); identifier_length = atoi_n(buf + 11, 1); base_address = atoi_n(buf + 12, 5); - + length_data_entry = atoi_n(buf + 20, 1); length_starting = atoi_n(buf + 21, 1); length_implementation = atoi_n(buf + 22, 1); - + for (entry_p = 24; buf[entry_p] != ISO2709_FS; ) { entry_p += 3 + length_data_entry + length_starting; if (entry_p >= record_length) { @@ -852,10 +838,10 @@ static Z_GenericRecord *marc_to_grs1(const char *buf, ODR o) tag->tagOccurrence = 0; tag->metaData = 0; tag->appliedVariant = 0; - tag->tagValue = odr_malloc (o, sizeof(*tag->tagValue)); + tag->tagValue = odr_malloc(o, sizeof(*tag->tagValue)); tag->tagValue->which = Z_StringOrNumeric_string; tag->tagValue->u.string = odr_strdup(o, "leader"); - + tag->content = odr_malloc(o, sizeof(*tag->content)); tag->content->which = Z_ElementData_string; tag->content->u.string = odr_strdupn(o, buf, 24); @@ -869,14 +855,14 @@ static Z_GenericRecord *marc_to_grs1(const char *buf, ODR o) int i; char tag_str[4]; int identifier_flag = 1; - + memcpy(tag_str, buf+entry_p, 3); entry_p += 3; tag_str[3] = '\0'; - + if ((r->num_elements + 1) >= max_elements) { Z_TaggedElement **tmp = r->elements; - + /* double array space, throw away old buffer (nibble memory) */ r->elements = odr_malloc(o, sizeof(*r->elements) * (max_elements *= 2)); memcpy(r->elements, tmp, r->num_elements * sizeof(*tmp)); @@ -887,19 +873,19 @@ static Z_GenericRecord *marc_to_grs1(const char *buf, ODR o) tag->tagOccurrence = 0; tag->metaData = 0; tag->appliedVariant = 0; - tag->tagValue = odr_malloc (o, sizeof(*tag->tagValue)); + tag->tagValue = odr_malloc(o, sizeof(*tag->tagValue)); tag->tagValue->which = Z_StringOrNumeric_string; tag->tagValue->u.string = odr_strdup(o, tag_str); - + tag->content = odr_malloc(o, sizeof(*tag->content)); tag->content->which = Z_ElementData_subtree; - + tag->content->u.subtree = odr_malloc(o, sizeof(*tag->content->u.subtree)); tag->content->u.subtree->elements = odr_malloc(o, sizeof(*r->elements)); tag->content->u.subtree->num_elements = 1; - + tag = tag->content->u.subtree->elements[0] = odr_malloc(o, sizeof(**tag->content->u.subtree->elements)); - + tag->tagType = odr_malloc(o, sizeof(*tag->tagType)); *tag->tagType = 3; tag->tagOccurrence = 0; @@ -908,7 +894,7 @@ static Z_GenericRecord *marc_to_grs1(const char *buf, ODR o) tag->tagValue = odr_malloc(o, sizeof(*tag->tagValue)); tag->tagValue->which = Z_StringOrNumeric_string; tag->content = odr_malloc(o, sizeof(*tag->content)); - + data_length = atoi_n(buf + entry_p, length_data_entry); entry_p += length_data_entry; data_offset = atoi_n(buf + entry_p, length_starting); @@ -920,69 +906,69 @@ static Z_GenericRecord *marc_to_grs1(const char *buf, ODR o) if (buf[i + indicator_length] != ISO2709_IDFS) { identifier_flag = 0; } - } else if (!memcmp (tag_str, "00", 2)) { + } else if (!memcmp(tag_str, "00", 2)) { identifier_flag = 0; } - + if (identifier_flag && indicator_length) { /* indicator */ tag->tagValue->u.string = odr_malloc(o, indicator_length + 1); memcpy(tag->tagValue->u.string, buf + i, indicator_length); tag->tagValue->u.string[indicator_length] = '\0'; i += indicator_length; - + tag->content->which = Z_ElementData_subtree; tag->content->u.subtree = odr_malloc(o, sizeof(*tag->content->u.subtree)); tag->content->u.subtree->elements = odr_malloc(o, 256 * sizeof(*r->elements)); tag->content->u.subtree->num_elements = 0; - + while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset) { int i0; /* prepare tag */ Z_TaggedElement *parent_tag = tag; - Z_TaggedElement *tag = odr_malloc (o, sizeof(*tag)); - + Z_TaggedElement *tag = odr_malloc(o, sizeof(*tag)); + if (parent_tag->content->u.subtree->num_elements < 256) { parent_tag->content->u.subtree->elements[ parent_tag->content->u.subtree->num_elements++] = tag; } - + tag->tagType = odr_malloc(o, sizeof(*tag->tagType)); *tag->tagType = 3; tag->tagOccurrence = 0; tag->metaData = 0; tag->appliedVariant = 0; - tag->tagValue = odr_malloc (o, sizeof(*tag->tagValue)); + tag->tagValue = odr_malloc(o, sizeof(*tag->tagValue)); tag->tagValue->which = Z_StringOrNumeric_string; - + /* sub field */ tag->tagValue->u.string = odr_malloc(o, identifier_length); memcpy(tag->tagValue->u.string, buf + i + 1, identifier_length - 1); tag->tagValue->u.string[identifier_length - 1] = '\0'; i += identifier_length; - + /* data ... */ tag->content = odr_malloc(o, sizeof(*tag->content)); tag->content->which = Z_ElementData_string; - + i0 = i; - while ( buf[i] != ISO2709_RS && - buf[i] != ISO2709_IDFS && + while ( buf[i] != ISO2709_RS && + buf[i] != ISO2709_IDFS && buf[i] != ISO2709_FS && i < end_offset) { i++; } - + tag->content->u.string = odr_malloc(o, i - i0 + 1); memcpy(tag->content->u.string, buf + i0, i - i0); tag->content->u.string[i - i0] = '\0'; } } else { int i0 = i; - + tag->tagValue->u.string = "@"; tag->content->which = Z_ElementData_string; - + while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset) { i++; } @@ -1069,10 +1055,10 @@ static void retval_array3_grs1(zval *return_value, Z_GenericRecord *p, zval *zval_list; Z_TaggedElement *e = p->elements[i]; char tagstr[32], *tag = 0; - + if (e->tagValue->which == Z_StringOrNumeric_numeric) { - sprintf(tagstr, "%d", *e->tagValue->u.numeric); + sprintf(tagstr, ODR_INT_PRINTF, *e->tagValue->u.numeric); tag = tagstr; } else if (e->tagValue->which == Z_StringOrNumeric_string) @@ -1091,7 +1077,7 @@ static void retval_array3_grs1(zval *return_value, Z_GenericRecord *p, MAKE_STD_ZVAL(zval_list); array_init(zval_list); add_assoc_zval(return_value, tag, zval_list); - + tl = nmem_malloc(nmem, sizeof(*tl)); tl->tag = nmem_strdup(nmem, tag); tl->zval_list = zval_list; @@ -1115,7 +1101,7 @@ static void retval_array3_grs1(zval *return_value, Z_GenericRecord *p, const char *tag = 0; if (e->tagValue->which == Z_StringOrNumeric_numeric) { - sprintf(tagstr, "%d", *e->tagValue->u.numeric); + sprintf(tagstr, ODR_INT_PRINTF, *e->tagValue->u.numeric); tag = tagstr; } else if (e->tagValue->which == Z_StringOrNumeric_string) @@ -1129,11 +1115,11 @@ static void retval_array3_grs1(zval *return_value, Z_GenericRecord *p, { char ind_idx[5]; char ind_val[2]; - + sprintf(ind_idx, "ind%d", i+1); ind_val[0] = tag[i]; ind_val[1] = '\0'; - + add_assoc_string(zval_element, ind_idx, ind_val, 1); } for (i = 0; inum_elements; i++) @@ -1142,16 +1128,16 @@ static void retval_array3_grs1(zval *return_value, Z_GenericRecord *p, const char *tag = 0; if (e->tagValue->which == Z_StringOrNumeric_numeric) { - sprintf(tagstr, "%d", *e->tagValue->u.numeric); + sprintf(tagstr, ODR_INT_PRINTF, *e->tagValue->u.numeric); tag = tagstr; } else if (e->tagValue->which == Z_StringOrNumeric_string) tag = e->tagValue->u.string, zval_element; - + if (tag && e->content->which == Z_ElementData_string) { const char *v = cvt_string(e->content->u.string, cvt); - add_assoc_string(zval_element, (char*) tag, (char*) v, + add_assoc_string(zval_element, (char*) tag, (char*) v, 1); } } @@ -1171,25 +1157,25 @@ static void retval_array2_grs1(zval *return_value, Z_GenericRecord *p, struct cvt_handle *cvt) { int i; - + array_init(return_value); - + for (i = 0; inum_elements; i++) { zval *zval_element; zval *zval_sub; Z_TaggedElement *e = p->elements[i]; - + MAKE_STD_ZVAL(zval_element); array_init(zval_element); - + if (e->tagType) - add_assoc_long(zval_element, "tagType", *e->tagType); + add_assoc_long(zval_element, "tagType", (long) *e->tagType); if (e->tagValue->which == Z_StringOrNumeric_string) add_assoc_string(zval_element, "tag", e->tagValue->u.string, 1); else if (e->tagValue->which == Z_StringOrNumeric_numeric) - add_assoc_long(zval_element, "tag", *e->tagValue->u.numeric); + add_assoc_long(zval_element, "tag", (long) *e->tagValue->u.numeric); switch (e->content->which) { case Z_ElementData_string: @@ -1200,7 +1186,7 @@ static void retval_array2_grs1(zval *return_value, Z_GenericRecord *p, } break; case Z_ElementData_numeric: - add_assoc_long(zval_element, "content",*e->content->u.numeric); + add_assoc_long(zval_element, "content", (long) *e->content->u.numeric); break; case Z_ElementData_trueOrFalse: add_assoc_bool(zval_element, "content",*e->content->u.trueOrFalse); @@ -1241,14 +1227,14 @@ static void retval_array1_grs1(zval *return_value, Z_GenericRecord *p, } *tag = '\0'; for (i = 0; i <= level; i++) { - int tag_type = 3; + long tag_type = 3; e = grs[i]->elements[eno[i]]; if (e->tagType) { - tag_type = *e->tagType; + tag_type = (long) *e->tagType; } taglen = strlen(tag); - sprintf(tag + taglen, "(%d,", tag_type); + sprintf(tag + taglen, "(%ld,", tag_type); taglen = strlen(tag); if (e->tagValue->which == Z_StringOrNumeric_string) { @@ -1257,7 +1243,7 @@ static void retval_array1_grs1(zval *return_value, Z_GenericRecord *p, memcpy(tag + taglen, e->tagValue->u.string, len); tag[taglen+len] = '\0'; } else if (e->tagValue->which == Z_StringOrNumeric_numeric) { - sprintf(tag + taglen, "%d", *e->tagValue->u.numeric); + sprintf(tag + taglen, ODR_INT_PRINTF, *e->tagValue->u.numeric); } taglen = strlen(tag); strcpy(tag + taglen, ")"); @@ -1266,7 +1252,7 @@ static void retval_array1_grs1(zval *return_value, Z_GenericRecord *p, ALLOC_ZVAL(my_zval); array_init(my_zval); INIT_PZVAL(my_zval); - + add_next_index_string(my_zval, tag, 1); switch (e->content->which) { @@ -1278,7 +1264,7 @@ static void retval_array1_grs1(zval *return_value, Z_GenericRecord *p, } break; case Z_ElementData_numeric: - add_next_index_long(my_zval, *e->content->u.numeric); + add_next_index_long(my_zval, (long) *e->content->u.numeric); break; case Z_ElementData_trueOrFalse: add_next_index_long(my_zval, *e->content->u.trueOrFalse); @@ -1309,7 +1295,7 @@ static void ext_grs1(zval *return_value, char type_args[][60], cvt = cvt_open(type_args[3], type_args[2]); else cvt = cvt_open(0, 0); - + if (ext->which == Z_External_grs1) { retval_array1_grs1(return_value, ext->u.grs1, cvt); } else if (ext->which == Z_External_octet) { @@ -1332,40 +1318,43 @@ static void ext_grs1(zval *return_value, char type_args[][60], Return record information at given result set position */ PHP_FUNCTION(yaz_record) { - pval **pval_id, **pval_pos, **pval_type; + zval *pval_id; Yaz_Association p; - int pos; + long pos; char *type; + int type_len; if (ZEND_NUM_ARGS() != 3) { WRONG_PARAM_COUNT; } - if (zend_get_parameters_ex(3, &pval_id, &pval_pos, &pval_type) == FAILURE) { + + if (zend_parse_parameters(3 TSRMLS_CC, "zls", &pval_id, &pos, + &type, &type_len) == FAILURE) { WRONG_PARAM_COUNT; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); - convert_to_long_ex(pval_pos); - pos = (*pval_pos)->value.lval; - convert_to_string_ex(pval_type); - type = (*pval_type)->value.str.val; - if (p && p->zoom_set) { ZOOM_record r; - char type_args[4][60]; /* 0; 1=2,3 (1 is assumed charset) */ - type_args[0][0] = 0; - type_args[1][0] = 0; - type_args[2][0] = 0; - type_args[3][0] = 0; - sscanf(type, "%59[^;];%59[^=]=%59[^,],%59[^,]", type_args[0], - type_args[1], type_args[2], type_args[3]); r = ZOOM_resultset_record(p->zoom_set, pos-1); - if (!strcmp(type_args[0], "string")) { - type = "render"; - } if (r) { - if (!strcmp(type_args[0], "array") || + char *type_tmp = 0; + char type_args[4][60]; /* 0; 1=2,3 (1 is assumed charset) */ + type_args[0][0] = 0; + type_args[1][0] = 0; + type_args[2][0] = 0; + type_args[3][0] = 0; + sscanf(type, "%59[^;];%59[^=]=%59[^,],%59[^,]", type_args[0], + type_args[1], type_args[2], type_args[3]); + + if (!strcmp(type_args[0], "string")) { + type_tmp = xstrdup(type); + strcpy(type_tmp, "render"); + strcat(type_tmp, type + 6); + type = type_tmp; + } + if (!strcmp(type_args[0], "array") || !strcmp(type_args[0], "array1")) { ext_grs1(return_value, type_args, r, retval_array1_grs1); @@ -1384,14 +1373,15 @@ PHP_FUNCTION(yaz_record) } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad yaz_record type %s - or unable " "to return record with type given", type); } } + xfree(type_tmp); } } - release_assoc (p); + release_assoc(p); } /* }}} */ @@ -1399,16 +1389,19 @@ PHP_FUNCTION(yaz_record) Set record syntax for retrieval */ PHP_FUNCTION(yaz_syntax) { - pval **pval_id, **pval_syntax; + zval *pval_id; + const char *syntax; + int syntax_len; Yaz_Association p; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_syntax) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || + zend_parse_parameters(2 TSRMLS_CC, "zs", &pval_id, + &syntax, &syntax_len) == FAILURE) { WRONG_PARAM_COUNT; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); - convert_to_string_ex(pval_syntax); - option_set(p, "preferredRecordSyntax", (*pval_syntax)->value.str.val); + option_set(p, "preferredRecordSyntax", syntax); release_assoc(p); } /* }}} */ @@ -1417,17 +1410,19 @@ PHP_FUNCTION(yaz_syntax) Set Element-Set-Name for retrieval */ PHP_FUNCTION(yaz_element) { - pval **pval_id, **pval_element; + zval *pval_id; + const char *element; + int element_len; Yaz_Association p; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_element) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || + zend_parse_parameters(2 TSRMLS_CC, "zs", &pval_id, + &element, &element_len) == FAILURE) { WRONG_PARAM_COUNT; } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); - convert_to_string_ex(pval_element); - option_set(p, "elementSetName", (*pval_element)->value.str.val); + option_set(p, "elementSetName", element); release_assoc(p); } /* }}} */ @@ -1436,16 +1431,19 @@ PHP_FUNCTION(yaz_element) Set Schema for retrieval */ PHP_FUNCTION(yaz_schema) { - pval **pval_id, **pval_element; + zval *pval_id; + const char *schema; + int schema_len; Yaz_Association p; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_element) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || + zend_parse_parameters(2 TSRMLS_CC, "zs", &pval_id, + &schema, &schema_len) == FAILURE) { WRONG_PARAM_COUNT; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); - convert_to_string_ex(pval_element); - option_set(p, "schema", (*pval_element)->value.str.val); + option_set(p, "schema", schema); release_assoc(p); } /* }}} */ @@ -1454,14 +1452,12 @@ PHP_FUNCTION(yaz_schema) Set Option(s) for connection */ PHP_FUNCTION(yaz_set_option) { - pval **pval_ar, **pval_name, **pval_val, **pval_id; Yaz_Association p; if (ZEND_NUM_ARGS() == 2) { - if (zend_get_parameters_ex(2, &pval_id, &pval_ar) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (Z_TYPE_PP(pval_ar) != IS_ARRAY) { + zval *pval_ar, *pval_id; + if (zend_parse_parameters(2 TSRMLS_CC, "za", + &pval_id, &pval_ar) == FAILURE) { WRONG_PARAM_COUNT; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); @@ -1469,8 +1465,8 @@ PHP_FUNCTION(yaz_set_option) HashPosition pos; HashTable *ht; zval **ent; - - ht = Z_ARRVAL_PP(pval_ar); + + ht = Z_ARRVAL_PP(&pval_ar); for(zend_hash_internal_pointer_reset_ex(ht, &pos); zend_hash_get_current_data_ex(ht, (void**) &ent, &pos) == SUCCESS; zend_hash_move_forward_ex(ht, &pos) @@ -1487,17 +1483,19 @@ PHP_FUNCTION(yaz_set_option) } option_set(p, key, (*ent)->value.str.val); } - release_assoc (p); + release_assoc(p); } } else if (ZEND_NUM_ARGS() == 3) { - if (zend_get_parameters_ex(3, &pval_id, &pval_name, &pval_val) == FAILURE) { + zval *pval_id; + char *name, *value; + int name_len, value_len; + if (zend_parse_parameters(3 TSRMLS_CC, "zss", + &pval_id, &name, &name_len, + &value, &value_len) == FAILURE) { WRONG_PARAM_COUNT; } get_assoc (INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); - convert_to_string_ex(pval_name); - convert_to_string_ex(pval_val); - option_set(p, (*pval_name)->value.str.val, (*pval_val)->value.str.val); - + option_set(p, name, value); release_assoc(p); } else { WRONG_PARAM_COUNT; @@ -1509,23 +1507,20 @@ PHP_FUNCTION(yaz_set_option) Set Option(s) for connection */ PHP_FUNCTION(yaz_get_option) { - pval **pval_id, **pval_name; + zval *pval_id; + char *name; + int name_len; Yaz_Association p; - if (ZEND_NUM_ARGS() != 2) { + if (ZEND_NUM_ARGS() != 2 || + zend_parse_parameters(2 TSRMLS_CC, "zs", &pval_id, &name, &name_len) + == FAILURE) { WRONG_PARAM_COUNT; } - if (zend_get_parameters_ex(2, &pval_id, &pval_name) == FAILURE) { - WRONG_PARAM_COUNT; - } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p) { const char *name_str, *v; - convert_to_string_ex (pval_name); - name_str = (*pval_name)->value.str.val; - - v = option_get(p, name_str); + v = option_get(p, name); if (!v) { v = ""; } @@ -1543,18 +1538,19 @@ PHP_FUNCTION(yaz_get_option) Set result set start point and number of records to request */ PHP_FUNCTION(yaz_range) { - pval **pval_id, **pval_start, **pval_number; + zval *pval_id; Yaz_Association p; + long start, number; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &pval_id, &pval_start, &pval_number) == FAILURE) { + if (ZEND_NUM_ARGS() != 3 || + zend_parse_parameters(3 TSRMLS_CC, "zll", &pval_id, &start, &number) + == FAILURE) { WRONG_PARAM_COUNT; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); - convert_to_long_ex(pval_start); - convert_to_long_ex(pval_number); - option_set_int(p, "start", (*pval_start)->value.lval - 1); - option_set_int(p, "count", (*pval_number)->value.lval); + option_set_int(p, "start", start > 0 ? start - 1 : 0); + option_set_int(p, "count", number); release_assoc(p); } /* }}} */ @@ -1563,27 +1559,29 @@ PHP_FUNCTION(yaz_range) Set result set sorting criteria */ PHP_FUNCTION(yaz_sort) { - pval **pval_id, **pval_criteria; + zval *pval_id; + const char *criteria; + int criteria_len; Yaz_Association p; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_criteria) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || + zend_parse_parameters(2 TSRMLS_CC, "zs", &pval_id, &criteria, + &criteria_len) == FAILURE) { WRONG_PARAM_COUNT; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p) { - convert_to_string_ex(pval_criteria); xfree(p->sort_criteria); - p->sort_criteria = xstrdup((*pval_criteria)->value.str.val); + p->sort_criteria = xstrdup(criteria); if (p->zoom_set) - ZOOM_resultset_sort(p->zoom_set, "yaz", - (*pval_criteria)->value.str.val); + ZOOM_resultset_sort(p->zoom_set, "yaz", criteria); } release_assoc(p); } /* }}} */ -const char *ill_array_lookup (void *handle, const char *name) +const char *ill_array_lookup(void *handle, const char *name) { return array_lookup_string((HashTable *) handle, name); } @@ -1592,27 +1590,25 @@ const char *ill_array_lookup (void *handle, const char *name) Sends Item Order request */ PHP_FUNCTION(yaz_itemorder) { - pval **pval_id, **pval_package; + zval *pval_id, *pval_package; Yaz_Association p; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_package) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || + zend_parse_parameters(2 TSRMLS_CC, "za", &pval_id, &pval_package) == + FAILURE) { WRONG_PARAM_COUNT; } - if (Z_TYPE_PP(pval_package) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array parameter"); - RETURN_FALSE; - } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p) { ZOOM_options options = ZOOM_options_create(); - - ZOOM_options_set_callback(options, ill_array_lookup, Z_ARRVAL_PP(pval_package)); + + ZOOM_options_set_callback(options, + ill_array_lookup, Z_ARRVAL_PP(&pval_package)); ZOOM_package_destroy(p->zoom_package); p->zoom_package = ZOOM_connection_package(p->zoom_conn, options); ZOOM_package_send(p->zoom_package, "itemorder"); ZOOM_options_set_callback(options, 0, 0); - ZOOM_options_destroy (options); + ZOOM_options_destroy(options); } release_assoc(p); } @@ -1622,34 +1618,27 @@ PHP_FUNCTION(yaz_itemorder) Sends Extended Services Request */ PHP_FUNCTION(yaz_es) { - pval **pval_id, **pval_type, **pval_package; + zval *pval_id, *pval_package; + const char *type; + int type_len; Yaz_Association p; - + if (ZEND_NUM_ARGS() != 3 || - zend_get_parameters_ex(3, &pval_id, &pval_type, - &pval_package) == FAILURE) { + zend_parse_parameters(3 TSRMLS_CC, "zsa", &pval_id, + &type, &type_len, &pval_package) == FAILURE) { WRONG_PARAM_COUNT; } - if (Z_TYPE_PP(pval_type) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected string parameter"); - RETURN_FALSE; - } - - if (Z_TYPE_PP(pval_package) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array parameter"); - RETURN_FALSE; - } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p) { ZOOM_options options = ZOOM_options_create(); - - ZOOM_options_set_callback(options, ill_array_lookup, Z_ARRVAL_PP(pval_package)); + + ZOOM_options_set_callback(options, ill_array_lookup, + Z_ARRVAL_PP(&pval_package)); ZOOM_package_destroy(p->zoom_package); p->zoom_package = ZOOM_connection_package(p->zoom_conn, options); - ZOOM_package_send(p->zoom_package, (*pval_type)->value.str.val); + ZOOM_package_send(p->zoom_package, type); ZOOM_options_set_callback(options, 0, 0); - ZOOM_options_destroy (options); + ZOOM_options_destroy(options); } release_assoc(p); } @@ -1659,30 +1648,28 @@ PHP_FUNCTION(yaz_es) Sends Scan Request */ PHP_FUNCTION(yaz_scan) { - pval **pval_id, **pval_type, **pval_query, **pval_flags = 0; + zval *pval_id, *pval_flags; + char *type, *query; + int type_len, query_len; HashTable *flags_ht = 0; Yaz_Association p; if (ZEND_NUM_ARGS() == 3) { - if (zend_get_parameters_ex(3, &pval_id, &pval_type, &pval_query) == FAILURE) { + if (zend_parse_parameters(3 TSRMLS_CC, "zss", + &pval_id, &type, &type_len, + &query, &query_len) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 4) { - if (zend_get_parameters_ex(4, &pval_id, &pval_type, &pval_query, &pval_flags) == FAILURE) { + if (zend_parse_parameters(4 TSRMLS_CC, "zssa", + &pval_id, &type, &type_len, + &query, &query_len, &pval_flags) == FAILURE) { WRONG_PARAM_COUNT; } - if (Z_TYPE_PP(pval_flags) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad flags parameter"); - RETURN_FALSE; - } - flags_ht = Z_ARRVAL_PP(pval_flags); + flags_ht = Z_ARRVAL_PP(&pval_flags); } else { WRONG_PARAM_COUNT; } - - convert_to_string_ex(pval_type); - convert_to_string_ex(pval_query); - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); ZOOM_scanset_destroy(p->zoom_scan); p->zoom_scan = 0; @@ -1690,7 +1677,7 @@ PHP_FUNCTION(yaz_scan) option_set(p, "number", array_lookup_string(flags_ht, "number")); option_set(p, "position", array_lookup_string(flags_ht, "position")); option_set(p, "stepSize", array_lookup_string(flags_ht, "stepsize")); - p->zoom_scan = ZOOM_connection_scan(p->zoom_conn, Z_STRVAL_PP(pval_query)); + p->zoom_scan = ZOOM_connection_scan(p->zoom_conn, query); } release_assoc(p); } @@ -1700,10 +1687,11 @@ PHP_FUNCTION(yaz_scan) Inspects Extended Services Result */ PHP_FUNCTION(yaz_es_result) { - pval **pval_id; + zval *pval_id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &pval_id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(1 TSRMLS_CC, "z", + &pval_id) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1711,13 +1699,13 @@ PHP_FUNCTION(yaz_es_result) get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p && p->zoom_package) { - const char *str = ZOOM_package_option_get(p->zoom_package, + const char *str = ZOOM_package_option_get(p->zoom_package, "targetReference"); - + if (str) { add_assoc_string(return_value, "targetReference", (char *) str, 1); } - str = ZOOM_package_option_get(p->zoom_package, + str = ZOOM_package_option_get(p->zoom_package, "xmlUpdateDoc"); if (str) { add_assoc_string(return_value, "xmlUpdateDoc", (char *) str, 1); @@ -1731,15 +1719,17 @@ PHP_FUNCTION(yaz_es_result) Inspects Scan Result */ PHP_FUNCTION(yaz_scan_result) { - pval **pval_id, **pval_opt = 0; + zval *pval_id, *pval_opt = 0; Yaz_Association p; if (ZEND_NUM_ARGS() == 2) { - if (zend_get_parameters_ex(2, &pval_id, &pval_opt) == FAILURE) { + if (zend_parse_parameters(2 TSRMLS_CC, "zz", + &pval_id, &pval_opt) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 1) { - if (zend_get_parameters_ex(1, &pval_id) == FAILURE) { + if (zend_parse_parameters(1 TSRMLS_CC, "z", + &pval_id) == FAILURE) { WRONG_PARAM_COUNT; } } else { @@ -1748,16 +1738,21 @@ PHP_FUNCTION(yaz_scan_result) array_init(return_value); - if (pval_opt && array_init(*pval_opt) == FAILURE) { + if (pval_opt && array_init(pval_opt) == FAILURE) { RETURN_FALSE; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p && p->zoom_scan) { int pos = 0; + /* ZOOM_scanset_term changed from YAZ 3 to YAZ 4 */ +#if YAZ_VERSIONL >= 0x040000 + size_t occ, len; +#else int occ, len; +#endif int size = ZOOM_scanset_size(p->zoom_scan); - + for (pos = 0; pos < size; pos++) { const char *term = ZOOM_scanset_term(p->zoom_scan, pos, &occ, &len); zval *my_zval; @@ -1765,7 +1760,7 @@ PHP_FUNCTION(yaz_scan_result) ALLOC_ZVAL(my_zval); array_init(my_zval); INIT_PZVAL(my_zval); - + add_next_index_string(my_zval, "term", 1); if (term) { @@ -1788,20 +1783,20 @@ PHP_FUNCTION(yaz_scan_result) if (pval_opt) { const char *v; - - add_assoc_long(*pval_opt, "number", size); - + + add_assoc_long(pval_opt, "number", size); + v = ZOOM_scanset_option_get(p->zoom_scan, "stepSize"); if (v) { - add_assoc_long(*pval_opt, "stepsize", atoi(v)); + add_assoc_long(pval_opt, "stepsize", atoi(v)); } v = ZOOM_scanset_option_get(p->zoom_scan, "position"); if (v) { - add_assoc_long(*pval_opt, "position", atoi(v)); + add_assoc_long(pval_opt, "position", atoi(v)); } v = ZOOM_scanset_option_get(p->zoom_scan, "scanStatus"); if (v) { - add_assoc_long(*pval_opt, "status", atoi(v)); + add_assoc_long(pval_opt, "status", atoi(v)); } } } @@ -1813,21 +1808,17 @@ PHP_FUNCTION(yaz_scan_result) Configure CCL package */ PHP_FUNCTION(yaz_ccl_conf) { - pval **pval_id, **pval_package; + zval *pval_id, *pval_package; Yaz_Association p; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_package) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || + zend_parse_parameters(2 TSRMLS_CC, "za", &pval_id, &pval_package) + == FAILURE) { WRONG_PARAM_COUNT; } - - if (Z_TYPE_PP(pval_package) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array parameter"); - RETURN_FALSE; - } - get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p) { - HashTable *ht = Z_ARRVAL_PP(pval_package); + HashTable *ht = Z_ARRVAL_PP(&pval_package); HashPosition pos; zval **ent; char *key; @@ -1835,7 +1826,7 @@ PHP_FUNCTION(yaz_ccl_conf) ccl_qual_rm(&p->bibset); p->bibset = ccl_qual_mk(); - for(zend_hash_internal_pointer_reset_ex(ht, &pos); + for (zend_hash_internal_pointer_reset_ex(ht, &pos); zend_hash_get_current_data_ex(ht, (void**) &ent, &pos) == SUCCESS; zend_hash_move_forward_ex(ht, &pos) ) { @@ -1851,7 +1842,7 @@ PHP_FUNCTION(yaz_ccl_conf) ccl_qual_fitem(p->bibset, (*ent)->value.str.val, key); } } - release_assoc (p); + release_assoc(p); } /* }}} */ @@ -1859,38 +1850,40 @@ PHP_FUNCTION(yaz_ccl_conf) Parse a CCL query */ PHP_FUNCTION(yaz_ccl_parse) { - pval **pval_id, **pval_query, **pval_res = 0; + zval *pval_id, *pval_res = 0; + char *query; + int query_len; Yaz_Association p; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &pval_id, &pval_query, &pval_res) == FAILURE) { + if (ZEND_NUM_ARGS() != 3 || + zend_parse_parameters(3 TSRMLS_CC, "zsz", + &pval_id, &query, &query_len, &pval_res) + == FAILURE) { WRONG_PARAM_COUNT; } - - pval_destructor(*pval_res); - array_init(*pval_res); - convert_to_string_ex (pval_query); + zval_dtor(pval_res); + array_init(pval_res); get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p) { - const char *query_str = (*pval_query)->value.str.val; struct ccl_rpn_node *rpn; int error_pos; int error_code; CCL_parser ccl_parser = ccl_parser_create(p->bibset); - rpn = ccl_parser_find_str(ccl_parser, query_str); + rpn = ccl_parser_find_str(ccl_parser, query); error_code = ccl_parser_get_error(ccl_parser, &error_pos); - add_assoc_long(*pval_res, "errorcode", error_code); + add_assoc_long(pval_res, "errorcode", error_code); - if (error_code) + if (error_code) { - add_assoc_string(*pval_res, "errorstring", + add_assoc_string(pval_res, "errorstring", (char *) ccl_err_msg(error_code), 1); - add_assoc_long(*pval_res, "errorpos", error_pos); + add_assoc_long(pval_res, "errorpos", error_pos); RETVAL_FALSE; - } - else + } + else { WRBUF wrbuf_pqf = wrbuf_alloc(); ccl_stop_words_t csw = ccl_stop_words_create(); @@ -1920,10 +1913,10 @@ PHP_FUNCTION(yaz_ccl_parse) add_assoc_string(zval_stopword, "term", (char *) term, 1); add_next_index_zval(zval_stopwords, zval_stopword); } - add_assoc_zval(*pval_res, "stopwords", zval_stopwords); + add_assoc_zval(pval_res, "stopwords", zval_stopwords); } ccl_pquery(wrbuf_pqf, rpn); - add_assoc_stringl(*pval_res, "rpn", + add_assoc_stringl(pval_res, "rpn", wrbuf_buf(wrbuf_pqf), wrbuf_len(wrbuf_pqf), 1); wrbuf_destroy(wrbuf_pqf); ccl_stop_words_destroy(csw); @@ -1941,16 +1934,19 @@ PHP_FUNCTION(yaz_ccl_parse) Specify the databases within a session */ PHP_FUNCTION(yaz_database) { - pval **pval_id, **pval_database; + zval *pval_id; + char *database; + int database_len; Yaz_Association p; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_database) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || + zend_parse_parameters(2 TSRMLS_CC, "zs", &pval_id, + &database, &database_len) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string_ex(pval_database); get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); - option_set(p, "databaseName", (*pval_database)->value.str.val); + option_set(p, "databaseName", database); RETVAL_TRUE; release_assoc(p); } @@ -1980,7 +1976,7 @@ static void yaz_close_session(Yaz_Association *as TSRMLS_DC) } } -static void yaz_close_link (zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void yaz_close_link(zend_rsrc_list_entry *rsrc TSRMLS_DC) { Yaz_Association *as = (Yaz_Association *) rsrc->ptr; yaz_close_session(as TSRMLS_CC); @@ -2003,7 +1999,7 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("yaz.log_mask", NULL, PHP_INI_ALL, OnUpdateString, log_mask, zend_yaz_globals, yaz_globals) PHP_INI_END() /* }}} */ - + PHP_MINIT_FUNCTION(yaz) { int i; @@ -2016,7 +2012,7 @@ PHP_MINIT_FUNCTION(yaz) ZEND_INIT_MODULE_GLOBALS(yaz, php_yaz_init_globals, NULL); REGISTER_INI_ENTRIES(); - + REGISTER_LONG_CONSTANT("ZOOM_EVENT_NONE", ZOOM_EVENT_NONE, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZOOM_EVENT_CONNECT", ZOOM_EVENT_CONNECT, @@ -2050,7 +2046,7 @@ PHP_MINIT_FUNCTION(yaz) else yaz_log_init_level(0); - le_link = zend_register_list_destructors_ex (yaz_close_link, 0, "YAZ link", module_number); + le_link = zend_register_list_destructors_ex(yaz_close_link, 0, "YAZ link", module_number); order_associations = 1; shared_associations = xmalloc(sizeof(*shared_associations) * MAX_ASSOC); @@ -2072,7 +2068,7 @@ PHP_MSHUTDOWN_FUNCTION(yaz) shared_associations = 0; } #ifdef ZTS - tsrm_mutex_free (yaz_mutex); + tsrm_mutex_free(yaz_mutex); #endif yaz_log_init_file(0);