X-Git-Url: http://git.indexdata.com/?p=phpyaz-moved-to-github.git;a=blobdiff_plain;f=php_yaz.c;h=e989db4258fc6ec3b05690e658834427a3a40884;hp=ea7189268ef6c60ca9026bcfeef747dec1f89f61;hb=defd74db71318cc17ea521b58ebc25754c2ae6bb;hpb=86f031ab4c0ce57a28e515f2b7aaecde2a0b44c3 diff --git a/php_yaz.c b/php_yaz.c index ea71892..e989db4 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 @@ -56,6 +54,11 @@ #define MAX_ASSOC 200 +#define GET_PARM1(a) zend_parse_parameters(1 TSRMLS_CC , "z", a) +#define GET_PARM2(a,b) zend_parse_parameters(2 TSRMLS_CC, "zz", a, b) +#define GET_PARM3(a,b,c) zend_parse_parameters(3 TSRMLS_CC, "zzz", a, b, c) +#define GET_PARM4(a,b,c,d) zend_parse_parameters(4 TSRMLS_CC, "zzzz", a, b, c, d) + typedef struct Yaz_AssociationInfo *Yaz_Association; struct Yaz_AssociationInfo { @@ -74,9 +77,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; @@ -91,7 +94,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; @@ -180,7 +183,7 @@ static void get_assoc(INTERNAL_FUNCTION_PARAMETERS, pval *id, Yaz_Association *a *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); @@ -189,7 +192,7 @@ static void get_assoc(INTERNAL_FUNCTION_PARAMETERS, pval *id, Yaz_Association *a *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"); } @@ -273,7 +276,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); } } @@ -313,13 +316,11 @@ PHP_FUNCTION(yaz_connect) otherInfo[0] = otherInfo[1] = otherInfo[2] = 0; if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(1, "z", &zurl) - == FAILURE) { + if (GET_PARM1(&zurl) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 2) { - if (zend_parse_parameters(2, "zz", &zurl, &user) - == FAILURE) { + if (GET_PARM2(&zurl, &user) == FAILURE) { WRONG_PARAM_COUNT; } @@ -403,7 +404,7 @@ 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", max_links); @@ -415,7 +416,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); @@ -449,7 +450,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); @@ -467,7 +468,7 @@ PHP_FUNCTION(yaz_close) if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(1, "z", &id) == FAILURE) { + if (GET_PARM1(&id) == FAILURE) { RETURN_FALSE; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, id, &p); @@ -490,8 +491,7 @@ PHP_FUNCTION(yaz_search) Yaz_Association p; if (ZEND_NUM_ARGS() == 3) { - if (zend_parse_parameters(3, "zzz", &id, &type, &query) - == FAILURE) { + if (GET_PARM3(&id, &type, &query) == FAILURE) { WRONG_PARAM_COUNT; } } else { @@ -534,7 +534,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; @@ -560,7 +560,7 @@ PHP_FUNCTION(yaz_present) if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(1, "z", id) == FAILURE) { + if (GET_PARM1(&id) == FAILURE) { WRONG_PARAM_COUNT; } @@ -596,7 +596,7 @@ PHP_FUNCTION(yaz_wait) long *val = 0; long *event_bool = 0; HashTable *options_ht = 0; - if (zend_parse_parameters(1, "z", &pval_options) == FAILURE) { + if (GET_PARM1(&pval_options) == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(&pval_options) != IS_ARRAY) { @@ -649,7 +649,7 @@ PHP_FUNCTION(yaz_wait) } if (no) { - while (ZOOM_event (no, conn_ar)) + while (ZOOM_event(no, conn_ar)) ; } RETURN_TRUE; @@ -663,8 +663,7 @@ PHP_FUNCTION(yaz_errno) pval *id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1 || - zend_parse_parameters(1, "z", &id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || GET_PARM1(&id) == FAILURE) { WRONG_PARAM_COUNT; } get_assoc(INTERNAL_FUNCTION_PARAM_PASSTHRU, id, &p); @@ -683,8 +682,7 @@ PHP_FUNCTION(yaz_error) pval *id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1 || - zend_parse_parameters(1, "z", &id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || GET_PARM1(&id) == FAILURE) { WRONG_PARAM_COUNT; } @@ -711,8 +709,7 @@ PHP_FUNCTION(yaz_addinfo) pval *id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1 || - zend_parse_parameters(ZEND_NUM_ARGS(), "z", &id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || GET_PARM1(&id) == FAILURE) { WRONG_PARAM_COUNT; } @@ -736,11 +733,11 @@ PHP_FUNCTION(yaz_hits) Yaz_Association p; if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(1, "z", &id) == FAILURE) { + if (GET_PARM1(&id) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 2) { - if (zend_parse_parameters(2, "zz", &id, &searchresult) == FAILURE) { + if (GET_PARM2(&id, &searchresult) == FAILURE) { WRONG_PARAM_COUNT; } if (array_init(searchresult) == FAILURE) { @@ -831,8 +828,8 @@ 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); @@ -862,7 +859,7 @@ 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"); @@ -897,7 +894,7 @@ 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); @@ -930,7 +927,7 @@ 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; } @@ -951,7 +948,7 @@ static Z_GenericRecord *marc_to_grs1(const char *buf, ODR o) 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[ @@ -963,7 +960,7 @@ 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; /* sub field */ @@ -1194,12 +1191,12 @@ static void retval_array2_grs1(zval *return_value, Z_GenericRecord *p, 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: @@ -1210,7 +1207,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); @@ -1251,14 +1248,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) { @@ -1288,7 +1285,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); @@ -1350,8 +1347,7 @@ PHP_FUNCTION(yaz_record) if (ZEND_NUM_ARGS() != 3) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(3, "zzz", &pval_id, &pval_pos, &pval_type) - == FAILURE) { + if (GET_PARM3( &pval_id, &pval_pos, &pval_type) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1402,7 +1398,7 @@ PHP_FUNCTION(yaz_record) } } } - release_assoc (p); + release_assoc(p); } /* }}} */ @@ -1414,7 +1410,7 @@ PHP_FUNCTION(yaz_syntax) Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || - zend_parse_parameters(2, "zz", &pval_id, &pval_syntax) == FAILURE) { + GET_PARM2(&pval_id, &pval_syntax) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1433,7 +1429,7 @@ PHP_FUNCTION(yaz_element) Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || - zend_parse_parameters(2, "zz", &pval_id, &pval_element) == FAILURE) { + GET_PARM2(&pval_id, &pval_element) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1453,7 +1449,7 @@ PHP_FUNCTION(yaz_schema) Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || - zend_parse_parameters(2, "zz", &pval_id, &pval_element) == FAILURE) { + GET_PARM2(&pval_id, &pval_element) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1472,7 +1468,7 @@ PHP_FUNCTION(yaz_set_option) Yaz_Association p; if (ZEND_NUM_ARGS() == 2) { - if (zend_parse_parameters(2, "zz", &pval_id, &pval_ar) == FAILURE) { + if (GET_PARM2(&pval_id, &pval_ar) == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(&pval_ar) != IS_ARRAY) { @@ -1501,11 +1497,10 @@ 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_parse_parameters(3, "zzz", &pval_id, &pval_name, &pval_val) - == FAILURE) { + if (GET_PARM3( &pval_id, &pval_name, &pval_val) == FAILURE) { WRONG_PARAM_COUNT; } get_assoc (INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); @@ -1530,7 +1525,7 @@ PHP_FUNCTION(yaz_get_option) if (ZEND_NUM_ARGS() != 2) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(2, "zz", &pval_id, &pval_name) == FAILURE) { + if (GET_PARM2(&pval_id, &pval_name) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1562,8 +1557,7 @@ PHP_FUNCTION(yaz_range) Yaz_Association p; if (ZEND_NUM_ARGS() != 3 || - zend_parse_parameters(3, "zzz", &pval_id, &pval_start, &pval_number) - == FAILURE) { + GET_PARM3( &pval_id, &pval_start, &pval_number) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1584,7 +1578,7 @@ PHP_FUNCTION(yaz_sort) Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || - zend_parse_parameters(2, "zz", &pval_id, &pval_criteria) == FAILURE) { + GET_PARM2(&pval_id, &pval_criteria) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1601,7 +1595,7 @@ PHP_FUNCTION(yaz_sort) } /* }}} */ -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); } @@ -1614,7 +1608,7 @@ PHP_FUNCTION(yaz_itemorder) Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || - zend_parse_parameters(2, "zz", &pval_id, &pval_package) == FAILURE) { + GET_PARM2(&pval_id, &pval_package) == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(&pval_package) != IS_ARRAY) { @@ -1632,7 +1626,7 @@ PHP_FUNCTION(yaz_itemorder) 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); } @@ -1646,8 +1640,7 @@ PHP_FUNCTION(yaz_es) Yaz_Association p; if (ZEND_NUM_ARGS() != 3 || - zend_parse_parameters(3, "zzz", &pval_id, &pval_type, - &pval_package) == FAILURE) { + GET_PARM3( &pval_id, &pval_type, &pval_package) == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(&pval_type) != IS_STRING) { @@ -1670,7 +1663,7 @@ PHP_FUNCTION(yaz_es) p->zoom_package = ZOOM_connection_package(p->zoom_conn, options); ZOOM_package_send(p->zoom_package, pval_type->value.str.val); ZOOM_options_set_callback(options, 0, 0); - ZOOM_options_destroy (options); + ZOOM_options_destroy(options); } release_assoc(p); } @@ -1685,13 +1678,12 @@ PHP_FUNCTION(yaz_scan) Yaz_Association p; if (ZEND_NUM_ARGS() == 3) { - if (zend_parse_parameters(3, "zzz", &pval_id, &pval_type, &pval_query) - == FAILURE) { + if (GET_PARM3( &pval_id, &pval_type, &pval_query) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 4) { - if (zend_parse_parameters(4, "zzzz", &pval_id, &pval_type, - &pval_query, &pval_flags) == FAILURE) { + if (GET_PARM4(&pval_id, &pval_type, &pval_query, &pval_flags) + == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(&pval_flags) != IS_ARRAY) { @@ -1727,8 +1719,7 @@ PHP_FUNCTION(yaz_es_result) pval *pval_id; Yaz_Association p; - if (ZEND_NUM_ARGS() != 1 || - zend_parse_parameters(1, "z", &pval_id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || GET_PARM1(&pval_id) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1760,11 +1751,11 @@ PHP_FUNCTION(yaz_scan_result) Yaz_Association p; if (ZEND_NUM_ARGS() == 2) { - if (zend_parse_parameters(2, "zz", &pval_id, &pval_opt) == FAILURE) { + if (GET_PARM2(&pval_id, &pval_opt) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(1, "z", &pval_id) == FAILURE) { + if (GET_PARM1(&pval_id) == FAILURE) { WRONG_PARAM_COUNT; } } else { @@ -1847,7 +1838,7 @@ PHP_FUNCTION(yaz_ccl_conf) Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || - zend_parse_parameters(2, "zz", &pval_id, &pval_package) == FAILURE) { + GET_PARM2(&pval_id, &pval_package) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1882,7 +1873,7 @@ PHP_FUNCTION(yaz_ccl_conf) ccl_qual_fitem(p->bibset, (*ent)->value.str.val, key); } } - release_assoc (p); + release_assoc(p); } /* }}} */ @@ -1893,8 +1884,7 @@ PHP_FUNCTION(yaz_ccl_parse) pval *pval_id, *pval_query, *pval_res = 0; Yaz_Association p; - if (ZEND_NUM_ARGS() != 3 || - zend_parse_parameters(3, "zzz", &pval_id, &pval_query, &pval_res) + if (ZEND_NUM_ARGS() != 3 || GET_PARM3( &pval_id, &pval_query, &pval_res) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1978,7 +1968,7 @@ PHP_FUNCTION(yaz_database) Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || - zend_parse_parameters(2, "zz", &pval_id, &pval_database) == FAILURE) { + GET_PARM2(&pval_id, &pval_database) == FAILURE) { WRONG_PARAM_COUNT; } @@ -2014,7 +2004,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); @@ -2084,7 +2074,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); @@ -2106,7 +2096,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);