Re: Php sablot scheme handler extension

From: Date: Tue, 16 Jan 2001 13:57:52 +0000
Subject: Re: Php sablot scheme handler extension
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-44236@lists.php.net to get a copy of this message
Can someone commit this patch to the cvs tree? I don't have patch (shame, shame) on my computer at home (home sick for the week). thanks! -sterling carmelo wrote: > > hello, > here is a modification I made to the sablotron module in php enabling > the use of scheme handlers with an additional function called > xslt_add_schme_handler. > I am using it and found it usefull for multi document handling in xslt. > bye, > carmelo > > -------------------------------------------------------------------------------- > Index: ./ext/sablot/php_sablot.h > =================================================================== > RCS file: /repository/php4/ext/sablot/php_sablot.h,v > retrieving revision 1.11 > diff -r1.11 php_sablot.h > 54a55 > > PHP_FUNCTION(xslt_set_scheme_handler); > 86c87 > < > --- > > > 98c99,102 > < > --- > > > > /* Scheme Handling */ > > zval *getAllHandler; > > > 145a150 > > > Index: ./ext/sablot/sablot.c > =================================================================== > RCS file: /repository/php4/ext/sablot/sablot.c,v > retrieving revision 1.28 > diff -r1.28 sablot.c > 56a57,64 > > /* Scheme Handling Functions */ > > static int _php_sablot_sh_getAll(void *userData, SablotHandle p, const char *scheme, > > const char *rest, char **buffer, int *byteCount); > > static int _php_sablot_sh_freeMemory(void *userData, SablotHandle p, char *buffer); > > static int _php_sablot_sh_open(void *userData, SablotHandle p, const char *scheme, const > > char *rest, int *handle); > > static int _php_sablot_sh_get(void *userData, SablotHandle p, int handle, char *buffer, > > int *byteCount); > > static int _php_sablot_sh_put(void *userData, SablotHandle p, int handle, const char > > *buffer, int *byteCount); > > static int _php_sablot_sh_close(void *userData, SablotHandle p, int handle); > > > 66c74 > < #define FUNCH_FREE(__var) if (__var) zval_del_ref(&(__var)); > --- > > #define FUNCH_FREE(__var) if (__var) zval_del_ref(&(__var)); > 104c112 > < * called when Sablotron's internal expat parser reaches the > --- > > * called when Sablotron's internal expat parser reaches the > 130a139,151 > > /** > > * Scheme Handler structure for use when Sablotron > > * call rhe document Xpath function. > > */ > > static SchemeHandler sh = { > > _php_sablot_sh_getAll, > > _php_sablot_sh_freeMemory, > > _php_sablot_sh_open, > > _php_sablot_sh_get, > > _php_sablot_sh_put, > > _php_sablot_sh_close > > }; > > > 151a173 > > PHP_FE(xslt_set_scheme_handler, NULL) > 233c255 > < > --- > > > 236c258 > < > --- > > > 242c264 > < > --- > > > 245c267 > < > --- > > > 263c285 > < > --- > > > 268c290 > < /** > --- > > /** > 282c304 > < > --- > > > 284,285c306,307 > < > < ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, SABLOTG(output_transform_file), > --- > > > > ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, SABLOTG(output_transform_file), > 287c309 > < > --- > > > 293c315 > < > --- > > > 295c317 > < > --- > > > 307c329 > < */ > --- > > */ > 313c335 > < > --- > > > 316c338 > < * current output buffer (so we don't send data twice) > --- > > * current output buffer (so we don't send data twice) > 320c342 > < > --- > > > 322c344 > < > --- > > > 342,343c364,365 > < zval **xslt_uri, > < **transform_uri, > --- > > zval **xslt_uri, > > **transform_uri, > 345,346c367,368 > < **xslt_params, > < **xslt_args, > --- > > **xslt_params, > > **xslt_args, > 353c375 > < int argc = ZEND_NUM_ARGS(), > --- > > int argc = ZEND_NUM_ARGS(), > 357c379 > < > --- > > > 363c385 > < > --- > > > 365c387 > < * if there are more than 3 function arguments, inspect the value of > --- > > * if there are more than 3 function arguments, inspect the value of > 372c394 > < int numelems, > --- > > int numelems, > 383c405 > < > --- > > > 386c408 > < > --- > > > 388c410 > < * Translate a PHP array (HashTable *) into a > --- > > * Translate a PHP array (HashTable *) into a > 394c416 > < > --- > > > 403c425 > < int numelems, > --- > > int numelems, > 408c430 > < > --- > > > 411c433 > < > --- > > > 415c437 > < > --- > > > 417,418c439,440 > < ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, Z_STRVAL_PP(xslt_uri), > < Z_STRVAL_PP(transform_uri), Z_STRVAL_PP(result_uri), > --- > > ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, Z_STRVAL_PP(xslt_uri), > > Z_STRVAL_PP(transform_uri), Z_STRVAL_PP(result_uri), > 423c445 > < > --- > > > 426c448 > < > --- > > > 429c451 > < > --- > > > 431c453 > < > --- > > > 434c456 > < > --- > > > 437c459 > < > --- > > > 440c462 > < > --- > > > 448c470 > < > --- > > > 451c473 > < > --- > > > 461,463c483,485 > < zval **xslt, > < **input, > < **result, > --- > > zval **xslt, > > **input, > > **result, > 466c488 > < int ret = 0, > --- > > int ret = 0, > 469c491 > < > --- > > > 475c497 > < > --- > > > 477c499 > < > --- > > > 484c506 > < > --- > > > 487c509 > < > --- > > > 497,499c519,521 > < > < ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, "arg:/_stylesheet", > < "arg:/_xmlinput", "arg:/_output", > --- > > > > ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, "arg:/_stylesheet", > > "arg:/_xmlinput", "arg:/_output", > 502c524 > < > --- > > > 507c529 > < > --- > > > 512c534 > < > --- > > > 516c538 > < > --- > > > 534c556 > < > --- > > > 536c558 > < > --- > > > 541c563 > < > --- > > > 548c570 > < > --- > > > 551c573 > < > --- > > > 558c580 > < > --- > > > 563c585,592 > < > --- > > > > ret = SablotRegHandler(handle->p, HLR_SCHEME, (void *)&sh, (void *)handle); > > > > if (ret) { > > SABLOTG(last_errno) = ret; > > RETURN_FALSE; > > } > > > 573,577c602,606 > < zval **xh, > < **xslt_file, > < **data_file, > < **xslt_result, > < **xslt_params, > --- > > zval **xh, > > **xslt_file, > > **data_file, > > **xslt_result, > > **xslt_params, > 586c615 > < > --- > > > 593c622 > < > --- > > > 597c626 > < > --- > > > 602,603c631,632 > < > < if (argc > 4) { > --- > > > > if (argc > 4) { > 608c637 > < > --- > > > 611c640 > < > --- > > > 614c643 > < > --- > > > 618c647 > < > --- > > > 624c653 > < > --- > > > 627c656 > < > --- > > > 630c659 > < > --- > > > 634c663 > < > --- > > > 636c665 > < > --- > > > 645c674 > < > --- > > > 649c678 > < > --- > > > 658,659c687,688 > < zval **xh, > < **logfile, > --- > > zval **xh, > > **logfile, > 662,663c691,692 > < int ret = 0, > < loglevel = 0, > --- > > int ret = 0, > > loglevel = 0, > 666c695 > < > --- > > > 673c702 > < > --- > > > 678c707 > < > --- > > > 680c709 > < > --- > > > 699c728 > < > --- > > > 705c734 > < > --- > > > 707c736 > < > --- > > > 711c740 > < RETURN_TRUE; > --- > > RETURN_TRUE; > 719c748 > < zval **xh, > --- > > zval **xh, > 722c751 > < char *value = NULL, > --- > > char *value = NULL, > 724c753 > < int argc = ZEND_NUM_ARGS(), > --- > > int argc = ZEND_NUM_ARGS(), > 733c762 > < > --- > > > 740c769 > < > --- > > > 742c771 > < > --- > > > 744c773 > < > --- > > > 753c782 > < > --- > > > 768c797 > < > --- > > > 773c802 > < > --- > > > 783,784c812,813 > < zval **xh, > < **handlers, > --- > > zval **xh, > > **handlers, > 791c820 > < > --- > > > 796a826,830 > > > > if ((*handlers)->type != IS_ARRAY) { > > php_error(E_ERROR, "The second parameter must be an array"); > > } > > > 798c832 > < > --- > > > 800c834 > < > --- > > > 804c838 > < > --- > > > 806c840 > < > --- > > > 811c845 > < > --- > > > 813c847 > < _php_sablot_handler_pair(handle, > --- > > _php_sablot_handler_pair(handle, > 817,818c851,852 > < _php_sablot_handler_pair(handle, > < &handle->startElementHandler, > &handle->endElementHandler, > --- > > _php_sablot_handler_pair(handle, > > &handle->startElementHandler, > > &handle->endElementHandler, > 822c856 > < &handle->startNamespaceHandler, > &handle->endNamespaceHandler, > --- > > &handle->startNamespaceHandler, > > &handle->endNamespaceHandler, > 833c867 > < } else { > --- > > } else { > 840a875,922 > > /* {{{ proto void xslt_set_scheme_handler(resource xh, array handlers) > > Set SAX Handlers on the resource handle given by xh. */ > > PHP_FUNCTION(xslt_set_scheme_handler) > > { > > zval **xh, > > **handlers, > > **indiv_handlers; > > php_sablot *handle; > > HashTable *handlers_list; > > char *string_key = NULL; > > ulong num_key; > > SABLOTLS_FETCH(); > > > > if (ZEND_NUM_ARGS() != 2 || > > zend_get_parameters_ex(2, &xh, &handlers) == FAILURE) { > > WRONG_PARAM_COUNT; > > } > > > > if ((*handlers)->type != IS_ARRAY) { > > php_error(E_ERROR, "The second parameter must be an array"); > > } > > > > ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", > > le_sablot); > > > > handlers_list = HASH_OF(*handlers); > > > > for (zend_hash_internal_pointer_reset(handlers_list); > > zend_hash_get_current_data(handlers_list, (void **)&indiv_handlers) == > > SUCCESS; > > zend_hash_move_forward(handlers_list)) { > > > > SEPARATE_ZVAL(indiv_handlers); > > > > if (zend_hash_get_current_key(handlers_list, &string_key, &num_key, 0) == > > HASH_KEY_IS_LONG) { > > php_error(E_WARNING, "The Keys of the first dimension of your array must > > be strings"); > > RETURN_FALSE; > > } > > > > if (!strcasecmp("getall", string_key)) { > > zval_add_ref(indiv_handlers); > > handle->getAllHandler = *indiv_handlers; > > } else { > > php_error(E_WARNING, "Invalid option: %s", string_key); > > } > > > > } > > } > > /* }}} */ > > > 849,850c931,932 > < int ret = 0, > < loglevel = 0, > --- > > int ret = 0, > > loglevel = 0, > 853c935 > < > --- > > > 860c942 > < > --- > > > 882c964 > < > --- > > > 887c969 > < > --- > > > 896c978 > < > --- > > > 906c988 > < > --- > > > 923c1005 > < > --- > > > 930c1012 > < > --- > > > 949c1031 > < > --- > > > 954c1036 > < > --- > > > 958c1040 > < > --- > > > 961c1043 > < > --- > > > 966c1048 > < > --- > > > 969c1051 > < > --- > > > 988c1070 > < > --- > > > 991c1073 > < > --- > > > 1019c1101 > < > --- > > > 1023c1105 > < > --- > > > 1026c1108 > < > --- > > > 1033c1115 > < /* {{{ _php_sablot_startDoc() > --- > > /* {{{ _php_sablot_startDoc() > 1048c1130 > < /* {{{ _php_sablot_sax_startElement() > --- > > /* {{{ _php_sablot_sax_startElement() > 1053c1135 > < > --- > > > 1056c1138 > < > --- > > > 1069c1151 > < > --- > > > 1073c1155 > < > --- > > > 1079c1161 > < /* {{{ _php_sablot_sax_endElement() > --- > > /* {{{ _php_sablot_sax_endElement() > 1087c1169 > < > --- > > > 1090c1172 > < > --- > > > 1096c1178 > < /* {{{ _php_sablot_sax_startNamespace() > --- > > /* {{{ _php_sablot_sax_startNamespace() > 1101c1183 > < > --- > > > 1104c1186 > < > --- > > > 1108c1190 > < > --- > > > 1114c1196 > < /* {{{ _php_sablot_sax_endNamespace() > --- > > /* {{{ _php_sablot_sax_endNamespace() > 1119c1201 > < > --- > > > 1122c1204 > < > --- > > > 1125c1207 > < > --- > > > 1131c1213 > < /* {{{ _php_sablot_sax_comment() > --- > > /* {{{ _php_sablot_sax_comment() > 1136c1218 > < > --- > > > 1139c1221 > < > --- > > > 1142c1224 > < > --- > > > 1148c1230 > < /* {{{ _php_sablot_sax_PI() > --- > > /* {{{ _php_sablot_sax_PI() > 1153c1235 > < > --- > > > 1156c1238 > < > --- > > > 1160c1242 > < > --- > > > 1166c1248 > < /* {{{ _php_sablot_sax_characters() > --- > > /* {{{ _php_sablot_sax_characters() > 1171c1253 > < > --- > > > 1174c1256 > < > --- > > > 1177c1259 > < > --- > > > 1183c1265 > < /* {{{ _php_sablot_sax_endDoc() > --- > > /* {{{ _php_sablot_sax_endDoc() > 1188c1270 > < > --- > > > 1191c1273 > < > --- > > > 1193c1275 > < > --- > > > 1204c1286 > < /* {{{ _php_sablot_make_code() > --- > > /* {{{ _php_sablot_make_code() > 1218c1300 > < > --- > > > 1221c1303 > < > --- > > > 1223c1305 > < > --- > > > 1231c1313 > < > --- > > > 1234c1316 > < > --- > > > 1237c1319 > < > --- > > > 1242c1324 > < > --- > > > 1244c1326 > < > --- > > > 1247c1329 > < > --- > > > 1250c1332 > < > --- > > > 1258c1340 > < > --- > > > 1260c1342 > < > --- > > > 1263c1345 > < > --- > > > 1266c1348 > < > --- > > > 1271c1353 > < > --- > > > 1275c1357 > < > --- > > > 1280c1362 > < > --- > > > 1284c1366 > < > --- > > > 1286c1368 > < > --- > > > 1289c1371 > < > --- > > > 1293c1375 > < > --- > > > 1300c1382 > < > --- > > > 1310c1392 > < > --- > > > 1347c1429 > < > --- > > > 1351,1352c1433,1434 > < > < /** > --- > > > > /** > 1360c1442 > < > --- > > > 1362c1444 > < > --- > > > 1366c1448 > < > --- > > > 1369c1451 > < case MH_LEVEL_ERROR: > --- > > case MH_LEVEL_ERROR: > 1379a1462,1536 > > /* {{{ Sablotron Scheme Handler functions */ > > > > static int _php_sablot_sh_getAll(void *userData, SablotHandle p, const char *scheme, const > > char *rest, char **buffer, int *byteCount) { > > php_sablot *handle = (php_sablot *)userData; > > > > if (handle->getAllHandler) { > > zval *retval; > > zval *args[4]; > > char *mybuff; > > int i; > > int argc; > > > > argc=4; > > args[0] = _php_sablot_resource_zval(handle->index); > > args[1] = _php_sablot_string_zval(scheme); > > args[2] = _php_sablot_string_zval(rest); > > args[3] = _php_sablot_string_zval(""); > > > > MAKE_STD_ZVAL(retval); > > > > if (call_user_function(EG(function_table), NULL, handle->getAllHandler, retval, > > argc, args) == FAILURE) { > > php_error(E_WARNING, "Sorry, couldn't call %s handler", > > "scheme getAll"); > > } > > > > zval_dtor(retval); > > efree(retval); > > > > /** > > * do not destroy xml data. > > */ > > *buffer=Z_STRVAL_P(args[3]); > > *byteCount=Z_STRLEN_P(args[3]); > > /** > > * destroy zvals > > */ > > for (i=0; i<3; i++) { > > zval_del_ref(&(args[i])); > > } > > } > > }; > > > > static int _php_sablot_sh_freeMemory(void *userData, SablotHandle p, char *buffer) { > > /** > > * here we should destroy the buffer containing the xml data > > * buffer to zval and zval-del_ref > > * we should destroy the zval not the pointer. > > */ > > }; > > > > static int _php_sablot_sh_open(void *userData, SablotHandle p, const char *scheme, const > > char *rest, int *handle) { > > /** > > * Not implemented > > */ > > }; > > > > static int _php_sablot_sh_get(void *userData, SablotHandle p, int handle, char *buffer, > > int *byteCount) { > > /** > > * Not implemented > > */ > > }; > > > > static int _php_sablot_sh_put(void *userData, SablotHandle p, int handle, const char > > *buffer, int *byteCount) { > > /** > > * Not implemented > > */ > > }; > > > > static int _php_sablot_sh_close(void *userData, SablotHandle p, int handle) { > > /** > > * Not implemented > > */ > > }; > > > > /* }}} */ > > > 1389a1547 > > SablotUnregHandler(handle->p, HLR_SCHEME, NULL, NULL); > 1392c1550 > < > --- > > > 1401a1560 > > FUNCH_FREE(handle->getAllHandler); > 1420c1579 > < > --- > > > 1426c1585 > < > --- > > > 1448c1607 > < > --- > > > 1463c1622 > < > --- > > > 1466c1625 > < > --- > > > 1484a1644 > > > > -------------------------------------------------------------------------------- > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.dev (#44236) next »