📄 php_yaz.c
字号:
Yaz_Association p; if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &pval_id, &pval_start, &pval_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); release_assoc (p);}/* }}} *//* {{{ proto int yaz_sort(int id, string sortspec) Set result set sorting criteria */PHP_FUNCTION(yaz_sort){ pval **pval_id, **pval_criteria; Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_criteria) == 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); } release_assoc (p);}/* }}} */const char *ill_array_lookup (void *handle, const char *name){ return array_lookup_string((HashTable *) handle, name);}/* {{{ proto int yaz_itemorder(int id, array package) Sends Item Order request */PHP_FUNCTION(yaz_itemorder){ pval **pval_id, **pval_package; Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_package) == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(pval_package) != IS_ARRAY) { php_error(E_WARNING, "yaz_itemorder: 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_package_destroy (p->zoom_package); p->zoom_package = ZOOM_connection_package (p->zoom_conn, options); ZOOM_package_send(p->zoom_package, "itemorder"); ZOOM_options_destroy (options); } release_assoc (p);}/* }}} *//* {{{ proto int yaz_scan(int id, type, query [, flags]) Sends Scan Request */PHP_FUNCTION(yaz_scan){ pval **pval_id, **pval_type, **pval_query, **pval_flags = 0; 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) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 4) { if (zend_get_parameters_ex(4, &pval_id, &pval_type, &pval_query, &pval_flags) == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(pval_flags) != IS_ARRAY) { php_error(E_WARNING, "yaz_scan: Bad flags parameter"); RETURN_FALSE; } 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; if (p) { 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));} release_assoc (p);}/* }}} *//* {{{ proto int yaz_es_result(int id) Inspects Extended Services Result */PHP_FUNCTION(yaz_es_result){ pval **pval_id; Yaz_Association p; if (ZEND_NUM_ARGS() == 1) { if (zend_get_parameters_ex(1, &pval_id) == FAILURE) { WRONG_PARAM_COUNT; } } else { WRONG_PARAM_COUNT; } if (array_init(return_value) == FAILURE) { RETURN_FALSE; } get_assoc (INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p && 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); } release_assoc (p);}/* }}} *//* {{{ proto int yaz_scan_result(int id, array options) Inspects Scan Result */PHP_FUNCTION(yaz_scan_result){ pval **pval_id, **pval_opt = 0; Yaz_Association p; if (ZEND_NUM_ARGS() == 2) { if (zend_get_parameters_ex(2, &pval_id, &pval_opt) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ZEND_NUM_ARGS() == 1) { if (zend_get_parameters_ex(1, &pval_id) == FAILURE) { WRONG_PARAM_COUNT; } } else { WRONG_PARAM_COUNT; } if (array_init(return_value) == FAILURE) { RETURN_FALSE; } 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; int occ, len; 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; ALLOC_ZVAL(my_zval); array_init(my_zval); INIT_PZVAL(my_zval); add_next_index_string(my_zval, "term", 1); if (term) add_next_index_stringl (my_zval, (char*) term, len, 1); else add_next_index_string (my_zval, "?", 1); add_next_index_long (my_zval, occ); zend_hash_next_index_insert ( return_value->value.ht, (void *) &my_zval, sizeof(zval *), NULL); } if (pval_opt) { const char *v; 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)); v = ZOOM_scanset_option_get (p->zoom_scan, "position"); if (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)); } } release_assoc (p);}/* }}} *//* {{{ proto int yaz_ccl_conf(int id, array package) Configure CCL package */PHP_FUNCTION(yaz_ccl_conf){ pval **pval_id, **pval_package; Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_package) == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(pval_package) != IS_ARRAY) { php_error(E_WARNING, "yaz_ccl_conf: Expected array parameter"); RETURN_FALSE; } get_assoc (INTERNAL_FUNCTION_PARAM_PASSTHRU, pval_id, &p); if (p) { HashTable *ht = Z_ARRVAL_PP(pval_package); HashPosition pos; zval **ent; char *key; ccl_qual_rm(&p->ccl_parser->bibset); p->ccl_parser->bibset = ccl_qual_mk(); 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)) { ulong idx;#if PHP_API_VERSION > 20010101 int type = zend_hash_get_current_key_ex(ht, &key, 0, &idx, 0, &pos);#else int type = zend_hash_get_current_key_ex(ht, &key, 0, &idx, &pos);#endif if (type != HASH_KEY_IS_STRING || Z_TYPE_PP(ent) != IS_STRING) continue; ccl_qual_fitem(p->ccl_parser->bibset, (*ent)->value.str.val, key); } } release_assoc (p);}/* }}} *//* {{{ proto int yaz_ccl_parse(int id, string query, array res) Parse a CCL query */PHP_FUNCTION(yaz_ccl_parse){ 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) == FAILURE) { WRONG_PARAM_COUNT; } 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); 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; struct ccl_token *token_list = ccl_parser_tokenize(p->ccl_parser, query_str); rpn = ccl_parser_find(p->ccl_parser, token_list); ccl_token_del(token_list); add_assoc_long(*pval_res, "errorcode", p->ccl_parser->error_code); if (p->ccl_parser->error_code) { add_assoc_string(*pval_res, "errorstring", (char*) ccl_err_msg(p->ccl_parser->error_code), 1); add_assoc_long(*pval_res, "errorpos", p->ccl_parser->error_pos - query_str); RETVAL_FALSE; } else { WRBUF wrbuf_pqf = wrbuf_alloc(); ccl_pquery(wrbuf_pqf, rpn); add_assoc_stringl(*pval_res, "rpn", wrbuf_buf(wrbuf_pqf), wrbuf_len(wrbuf_pqf),1); wrbuf_free(wrbuf_pqf, 1); RETVAL_TRUE; } ccl_rpn_delete(rpn); } else RETVAL_FALSE; release_assoc (p);}/* }}} *//* {{{ proto int yaz_database (int id, string databases) Specify the databases within a session */PHP_FUNCTION(yaz_database){ pval **pval_id, **pval_database; Yaz_Association p; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pval_id, &pval_database) == 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); RETVAL_TRUE; release_assoc (p);}/* }}} *//* {{{ php_yaz_init_globals */static void php_yaz_init_globals(zend_yaz_globals *yaz_globals){ yaz_globals->assoc_seq = 0;}/* }}} */void yaz_close_session(Yaz_Association *as TSRMLS_DC){ if (*as && (*as)->order == YAZSG(assoc_seq)) { if ((*as)->persistent) (*as)->in_use = 0; else { yaz_association_destroy(*as); *as = 0; } }}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);}/* {{{ PHP_INI_BEGIN */PHP_INI_BEGIN() STD_PHP_INI_ENTRY("yaz.max_links", "100", PHP_INI_ALL, OnUpdateInt, max_links, zend_yaz_globals, yaz_globals) STD_PHP_INI_ENTRY("yaz.log_file", "", PHP_INI_ALL, OnUpdateString, log_file, zend_yaz_globals, yaz_globals) PHP_INI_END()/* }}} */ PHP_MINIT_FUNCTION(yaz){ int i; const char *fname; nmem_init();#ifdef ZTS yaz_mutex = tsrm_mutex_alloc();#endif ZEND_INIT_MODULE_GLOBALS(yaz, php_yaz_init_globals, NULL); REGISTER_INI_ENTRIES(); fname = YAZSG(log_file); if (fname && *fname) { yaz_log_init_file(fname); yaz_log_init_level(LOG_ALL); } else yaz_log_init_level(0); 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); for (i = 0; i<MAX_ASSOC; i++) shared_associations[i] = 0; return SUCCESS;}PHP_MSHUTDOWN_FUNCTION(yaz){ int i; if (shared_associations) { for (i = 0; i<MAX_ASSOC; i++) yaz_association_destroy (shared_associations[i]); xfree (shared_associations); shared_associations = 0; nmem_exit(); }#ifdef ZTS tsrm_mutex_free (yaz_mutex);#endif yaz_log_init_file(0); return SUCCESS;}PHP_MINFO_FUNCTION(yaz){ php_info_print_table_start(); php_info_print_table_row(2, "YAZ Support", "enabled"); php_info_print_table_row(2, "YAZ Version", YAZ_VERSION); php_info_print_table_row(2, "ZOOM", "enabled"); php_info_print_table_end();}PHP_RSHUTDOWN_FUNCTION(yaz){ return SUCCESS;}PHP_RINIT_FUNCTION(yaz){ char pidstr[20]; sprintf (pidstr, "%ld", (long) getpid());#ifdef ZTS tsrm_mutex_lock (yaz_mutex);#endif YAZSG(assoc_seq) = order_associations++;#ifdef ZTS tsrm_mutex_unlock (yaz_mutex);#endif yaz_log_init_prefix(pidstr); return SUCCESS;}zend_module_entry yaz_module_entry = {#if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER,#endif "yaz", yaz_functions, PHP_MINIT(yaz), PHP_MSHUTDOWN(yaz), PHP_RINIT(yaz), PHP_RSHUTDOWN(yaz), PHP_MINFO(yaz),#if ZEND_MODULE_API_NO >= 20010901 NO_VERSION_YET,#endif STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_YAZZEND_GET_MODULE(yaz)#endif#endif/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -