You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4539 lines
118 KiB

27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
26 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
26 years ago
25 years ago
25 years ago
26 years ago
26 years ago
26 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
26 years ago
25 years ago
25 years ago
26 years ago
26 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
27 years ago
25 years ago
25 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP version 4.0 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2001 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.02 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://www.php.net/license/2_02.txt. |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Uwe Steinmann |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #include <stdlib.h>
  20. #include <errno.h>
  21. #ifdef HAVE_CONFIG_H
  22. #include "config.h"
  23. #endif
  24. #include "php.h"
  25. #include "php_globals.h"
  26. #include "ext/standard/php_standard.h"
  27. #include "ext/standard/head.h"
  28. #include "ext/standard/info.h"
  29. #include "fopen_wrappers.h"
  30. #include "SAPI.h"
  31. #ifdef PHP_WIN32
  32. #include <winsock.h>
  33. #else
  34. #include "build-defs.h"
  35. #endif
  36. #ifdef HAVE_MMAP
  37. #include <sys/mman.h>
  38. #endif
  39. #if HYPERWAVE
  40. #include "php_ini.h"
  41. #include "php_hyperwave.h"
  42. static int le_socketp, le_psocketp, le_document;
  43. /*hw_module php_hw_module;*/
  44. #define HW_ATTR_NONE 1
  45. #define HW_ATTR_LANG 2
  46. #define HW_ATTR_NR 3
  47. function_entry hw_functions[] = {
  48. PHP_FE(hw_connect, NULL)
  49. PHP_FE(hw_pconnect, NULL)
  50. PHP_FE(hw_close, NULL)
  51. PHP_FE(hw_root, NULL)
  52. PHP_FE(hw_info, NULL)
  53. PHP_FE(hw_connection_info, NULL)
  54. PHP_FE(hw_error, NULL)
  55. PHP_FE(hw_errormsg, NULL)
  56. PHP_FE(hw_getparentsobj, NULL)
  57. PHP_FE(hw_getparents, NULL)
  58. PHP_FE(hw_children, NULL)
  59. PHP_FE(hw_childrenobj, NULL)
  60. PHP_FE(hw_getchildcoll, NULL)
  61. PHP_FE(hw_getchildcollobj, NULL)
  62. PHP_FE(hw_getobject, NULL)
  63. PHP_FE(hw_getandlock, NULL)
  64. PHP_FE(hw_unlock, NULL)
  65. PHP_FE(hw_gettext, NULL)
  66. PHP_FE(hw_edittext, NULL)
  67. PHP_FE(hw_getcgi, NULL)
  68. PHP_FE(hw_getremote, NULL)
  69. PHP_FE(hw_getremotechildren, NULL)
  70. PHP_FE(hw_pipedocument, NULL)
  71. PHP_FE(hw_pipecgi, NULL)
  72. PHP_FE(hw_insertdocument, NULL)
  73. PHP_FE(hw_mv, NULL)
  74. PHP_FE(hw_cp, NULL)
  75. PHP_FE(hw_deleteobject, NULL)
  76. PHP_FE(hw_changeobject, NULL)
  77. PHP_FE(hw_modifyobject, NULL)
  78. PHP_FE(hw_docbyanchor, NULL)
  79. PHP_FE(hw_docbyanchorobj, NULL)
  80. PHP_FE(hw_getobjectbyquery, NULL)
  81. PHP_FE(hw_getobjectbyqueryobj, NULL)
  82. PHP_FE(hw_getobjectbyquerycoll, NULL)
  83. PHP_FE(hw_getobjectbyquerycollobj, NULL)
  84. PHP_FE(hw_getobjectbyftquery, NULL)
  85. PHP_FE(hw_getobjectbyftqueryobj, NULL)
  86. PHP_FE(hw_getobjectbyftquerycoll, NULL)
  87. PHP_FE(hw_getobjectbyftquerycollobj, NULL)
  88. PHP_FE(hw_getchilddoccoll, NULL)
  89. PHP_FE(hw_getchilddoccollobj, NULL)
  90. PHP_FE(hw_getanchors, NULL)
  91. PHP_FE(hw_getanchorsobj, NULL)
  92. PHP_FE(hw_getusername, NULL)
  93. PHP_FE(hw_setlinkroot, NULL)
  94. PHP_FE(hw_identify, NULL)
  95. PHP_FE(hw_free_document, NULL)
  96. PHP_FE(hw_new_document, NULL)
  97. PHP_FE(hw_new_document_from_file, NULL)
  98. PHP_FE(hw_output_document, NULL)
  99. PHP_FE(hw_document_size, NULL)
  100. PHP_FE(hw_document_attributes, NULL)
  101. PHP_FE(hw_document_bodytag, NULL)
  102. PHP_FE(hw_document_content, NULL)
  103. PHP_FE(hw_document_setcontent, NULL)
  104. PHP_FE(hw_objrec2array, NULL)
  105. PHP_FE(hw_array2objrec, NULL)
  106. PHP_FE(hw_incollections, NULL)
  107. PHP_FE(hw_inscoll, NULL)
  108. PHP_FE(hw_insertobject, NULL)
  109. PHP_FE(hw_insdoc, NULL)
  110. PHP_FE(hw_getsrcbydestobj, NULL)
  111. PHP_FE(hw_insertanchors, NULL)
  112. PHP_FE(hw_getrellink, NULL)
  113. PHP_FE(hw_who, NULL)
  114. PHP_FE(hw_stat, NULL)
  115. PHP_FE(hw_mapid, NULL)
  116. PHP_FE(hw_dummy, NULL)
  117. {NULL, NULL, NULL}
  118. };
  119. zend_module_entry hw_module_entry = {
  120. "hyperwave", hw_functions, PHP_MINIT(hw), PHP_MSHUTDOWN(hw), NULL, NULL, PHP_MINFO(hw), STANDARD_MODULE_PROPERTIES
  121. };
  122. /*
  123. #ifdef ZTS
  124. int hw_globals_id;
  125. #else
  126. PHP_HW_API php_hw_globals hw_globals;
  127. #endif
  128. */
  129. ZEND_DECLARE_MODULE_GLOBALS(hw)
  130. #ifdef COMPILE_DL_HYPERWAVE
  131. ZEND_GET_MODULE(hw)
  132. #endif
  133. void print_msg(hg_msg *msg, char *str, int txt);
  134. void _close_hw_link(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  135. {
  136. hw_connection *conn = (hw_connection *)rsrc->ptr;
  137. if(conn->hostname)
  138. free(conn->hostname);
  139. if(conn->username)
  140. free(conn->username);
  141. close(conn->socket);
  142. free(conn);
  143. HwSG(num_links)--;
  144. }
  145. void _close_hw_plink(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  146. {
  147. hw_connection *conn = (hw_connection *)rsrc->ptr;
  148. if(conn->hostname)
  149. free(conn->hostname);
  150. if(conn->username)
  151. free(conn->username);
  152. close(conn->socket);
  153. free(conn);
  154. HwSG(num_links)--;
  155. HwSG(num_persistent)--;
  156. }
  157. void _free_hw_document(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  158. {
  159. hw_document *doc = (hw_document *)rsrc->ptr;
  160. if(doc->data)
  161. free(doc->data);
  162. if(doc->attributes)
  163. free(doc->attributes);
  164. if(doc->bodytag)
  165. free(doc->bodytag);
  166. free(doc);
  167. }
  168. static void php_hw_init_globals(zend_hw_globals *hw_globals)
  169. {
  170. hw_globals->num_persistent = 0;
  171. }
  172. static PHP_INI_MH(OnHyperwavePort)
  173. {
  174. if (new_value==NULL) {
  175. HwSG(default_port) = HG_SERVER_PORT;
  176. } else {
  177. HwSG(default_port) = atoi(new_value);
  178. }
  179. return SUCCESS;
  180. }
  181. PHP_INI_BEGIN()
  182. STD_PHP_INI_ENTRY("hyerwave.allow_persistent", "0", PHP_INI_SYSTEM, OnUpdateInt, allow_persistent, zend_hw_globals, hw_globals)
  183. PHP_INI_ENTRY("hyperwave.default_port", "418", PHP_INI_ALL, OnHyperwavePort)
  184. PHP_INI_END()
  185. PHP_MINIT_FUNCTION(hw)
  186. {
  187. ZEND_INIT_MODULE_GLOBALS(hw, php_hw_init_globals, NULL);
  188. REGISTER_INI_ENTRIES();
  189. le_socketp = zend_register_list_destructors_ex(_close_hw_link, NULL, "hyperwave link", module_number);
  190. le_psocketp = zend_register_list_destructors_ex(NULL, _close_hw_plink, "hyperwave link persistent", module_number);
  191. le_document = zend_register_list_destructors_ex(_free_hw_document, NULL, "hyperwave document", module_number);
  192. hw_module_entry.type = type;
  193. REGISTER_LONG_CONSTANT("HW_ATTR_LANG", HW_ATTR_LANG, CONST_CS | CONST_PERSISTENT);
  194. REGISTER_LONG_CONSTANT("HW_ATTR_NR", HW_ATTR_NR, CONST_CS | CONST_PERSISTENT);
  195. REGISTER_LONG_CONSTANT("HW_ATTR_NONE", HW_ATTR_NONE, CONST_CS | CONST_PERSISTENT);
  196. return SUCCESS;
  197. }
  198. PHP_MSHUTDOWN_FUNCTION(hw)
  199. {
  200. UNREGISTER_INI_ENTRIES();
  201. return SUCCESS;
  202. }
  203. /* {{{ make_return_objrec
  204. * creates an array in return value and frees all memory
  205. * Also adds as an assoc. array at the end of the return array with
  206. * statistics.
  207. */
  208. int make_return_objrec(pval **return_value, char **objrecs, int count)
  209. {
  210. zval *stat_arr;
  211. int i;
  212. int hidden, collhead, fullcollhead, total;
  213. int collheadnr, fullcollheadnr;
  214. if (array_init(*return_value) == FAILURE) {
  215. /* Ups, failed! Let's at least free the memory */
  216. for(i=0; i<count; i++)
  217. efree(objrecs[i]);
  218. efree(objrecs);
  219. return -1;
  220. }
  221. hidden = collhead = fullcollhead = total = 0;
  222. collheadnr = fullcollheadnr = -1;
  223. for(i=0; i<count; i++) {
  224. /* Fill the array with entries. No need to free objrecs[i], since
  225. * it is not duplicated in add_next_index_string().
  226. */
  227. if(NULL != objrecs[i]) {
  228. if(0 == fnAttributeCompare(objrecs[i], "PresentationHints", "Hidden"))
  229. hidden++;
  230. if(0 == fnAttributeCompare(objrecs[i], "PresentationHints", "CollectionHead")) {
  231. collhead++;
  232. collheadnr = total;
  233. }
  234. if(0 == fnAttributeCompare(objrecs[i], "PresentationHints", "FullCollectionHead")) {
  235. fullcollhead++;
  236. fullcollheadnr = total;
  237. }
  238. total++;
  239. add_next_index_string(*return_value, objrecs[i], 0);
  240. }
  241. }
  242. efree(objrecs);
  243. /* Array for statistics */
  244. MAKE_STD_ZVAL(stat_arr);
  245. if (array_init(stat_arr) == FAILURE) {
  246. return -1;
  247. }
  248. add_assoc_long(stat_arr, "Hidden", hidden);
  249. add_assoc_long(stat_arr, "CollectionHead", collhead);
  250. add_assoc_long(stat_arr, "FullCollectionHead", fullcollhead);
  251. add_assoc_long(stat_arr, "Total", total);
  252. add_assoc_long(stat_arr, "CollectionHeadNr", collheadnr);
  253. add_assoc_long(stat_arr, "FullCollectionHeadNr", fullcollheadnr);
  254. /* Add the stat array */
  255. zend_hash_next_index_insert((*return_value)->value.ht, &stat_arr, sizeof(zval), NULL);
  256. return 0;
  257. }
  258. /* }}} */
  259. /* {{{ make2_return_array_from_objrec
  260. ** creates an array return value from object record
  261. */
  262. int make2_return_array_from_objrec(pval **return_value, char *objrec, zval *sarr) {
  263. char *attrname, *str, *temp, language[3];
  264. zval *spec_arr;
  265. char *strtok_buf = NULL;
  266. /* Create an array with an entry containing specs for each attribute
  267. and fill in the specs for Title, Description, Keyword, Group.
  268. If an array is passed as the last argument use it instead.
  269. */
  270. if(NULL != sarr) {
  271. spec_arr = sarr;
  272. } else {
  273. MAKE_STD_ZVAL(spec_arr);
  274. array_init(spec_arr);
  275. add_assoc_long(spec_arr, "Title", HW_ATTR_LANG);
  276. add_assoc_long(spec_arr, "Description", HW_ATTR_LANG);
  277. add_assoc_long(spec_arr, "Keyword", HW_ATTR_LANG);
  278. add_assoc_long(spec_arr, "Group", HW_ATTR_NONE);
  279. add_assoc_long(spec_arr, "HtmlAttr", HW_ATTR_NONE);
  280. add_assoc_long(spec_arr, "Parent", HW_ATTR_NONE);
  281. }
  282. if (array_init(*return_value) == FAILURE) {
  283. (*return_value)->type = IS_STRING;
  284. (*return_value)->value.str.val = empty_string;
  285. (*return_value)->value.str.len = 0;
  286. return -1;
  287. }
  288. /* Loop through the attributes of object record and check
  289. if the attribute has a specification. If it has the value
  290. is added to array in spec record. If not it is added straight
  291. to the return_value array.
  292. */
  293. temp = estrdup(objrec);
  294. attrname = php_strtok_r(temp, "\n", &strtok_buf);
  295. while(attrname != NULL) {
  296. zval *data, **dataptr;
  297. long spec;
  298. str = attrname;
  299. /* Check if a specification is available.
  300. If it isn't available then insert the attribute as
  301. a string into the return array
  302. */
  303. while((*str != '=') && (*str != '\0'))
  304. str++;
  305. *str = '\0';
  306. str++;
  307. if(zend_hash_find(spec_arr->value.ht, attrname, strlen(attrname)+1, (void **) &dataptr) == FAILURE) {
  308. add_assoc_string(*return_value, attrname, str, 1);
  309. } else {
  310. zval *newarr;
  311. data = *dataptr;
  312. spec = data->value.lval;
  313. if(zend_hash_find((*return_value)->value.ht, attrname, strlen(attrname)+1, (void **) &dataptr) == FAILURE) {
  314. MAKE_STD_ZVAL(newarr);
  315. array_init(newarr);
  316. zend_hash_add((*return_value)->value.ht, attrname, strlen(attrname)+1, &newarr, sizeof(zval *), NULL);
  317. } else {
  318. newarr = *dataptr;
  319. }
  320. switch(spec) {
  321. case HW_ATTR_LANG:
  322. if(str[2] == ':') {
  323. str[2] = '\0';
  324. strcpy(language, str);
  325. str += 3;
  326. } else
  327. strcpy(language, "xx");
  328. add_assoc_string(newarr, language, str, 1);
  329. break;
  330. case HW_ATTR_NR:
  331. if(str[1] == ':') {
  332. str[1] = '\0';
  333. strcpy(language, str);
  334. str += 2;
  335. } else
  336. strcpy(language, "x");
  337. add_assoc_string(newarr, language, str, 1);
  338. break;
  339. case HW_ATTR_NONE:
  340. add_next_index_string(newarr, str, 1);
  341. break;
  342. }
  343. }
  344. attrname = php_strtok_r(NULL, "\n", &strtok_buf);
  345. }
  346. if(NULL == sarr){
  347. /*
  348. spec_arr->refcount--;
  349. zend_hash_destroy(spec_arr->value.ht);
  350. efree(spec_arr->value.ht);
  351. */
  352. zval_dtor(spec_arr);
  353. efree(spec_arr);
  354. }
  355. efree(temp);
  356. return(0);
  357. }
  358. /* }}} */
  359. /* {{{ make_return_array_from_objrec
  360. */
  361. int make_return_array_from_objrec(pval **return_value, char *objrec) {
  362. char *attrname, *str, *temp, language[3], *title;
  363. int iTitle, iDesc, iKeyword, iGroup;
  364. zval *title_arr;
  365. zval *desc_arr;
  366. zval *keyword_arr;
  367. zval *group_arr;
  368. int hasTitle = 0;
  369. int hasDescription = 0;
  370. int hasKeyword = 0;
  371. int hasGroup = 0;
  372. char *strtok_buf;
  373. MAKE_STD_ZVAL(title_arr);
  374. MAKE_STD_ZVAL(desc_arr);
  375. MAKE_STD_ZVAL(keyword_arr);
  376. MAKE_STD_ZVAL(group_arr);
  377. if (array_init(*return_value) == FAILURE) {
  378. (*return_value)->type = IS_STRING;
  379. (*return_value)->value.str.val = empty_string;
  380. (*return_value)->value.str.len = 0;
  381. return -1;
  382. }
  383. /* Fill Array of titles, descriptions and keywords */
  384. temp = estrdup(objrec);
  385. attrname = php_strtok_r(temp, "\n", &strtok_buf);
  386. while(attrname != NULL) {
  387. str = attrname;
  388. iTitle = 0;
  389. iDesc = 0;
  390. iKeyword = 0;
  391. iGroup = 0;
  392. if(0 == strncmp(attrname, "Title=", 6)) {
  393. if ((hasTitle == 0) && (array_init(title_arr) == FAILURE)) {
  394. return -1;
  395. }
  396. hasTitle = 1;
  397. str += 6;
  398. iTitle = 1;
  399. } else if(0 == strncmp(attrname, "Description=", 12)) {
  400. if ((hasDescription == 0) && (array_init(desc_arr) == FAILURE)) {
  401. return -1;
  402. }
  403. hasDescription = 1;
  404. str += 12;
  405. iDesc = 1;
  406. } else if(0 == strncmp(attrname, "Keyword=", 8)) {
  407. if ((hasKeyword == 0) && (array_init(keyword_arr) == FAILURE)) {
  408. return -1;
  409. }
  410. hasKeyword = 1;
  411. str += 8;
  412. iKeyword = 1;
  413. } else if(0 == strncmp(attrname, "Group=", 6)) {
  414. if ((hasGroup == 0) && (array_init(group_arr) == FAILURE)) {
  415. return -1;
  416. }
  417. hasGroup = 1;
  418. str += 6;
  419. iGroup = 1;
  420. }
  421. if(iTitle || iDesc || iKeyword) { /* Poor error check if end of string */
  422. if(str[2] == ':') {
  423. str[2] = '\0';
  424. strcpy(language, str);
  425. str += 3;
  426. } else
  427. strcpy(language, "xx");
  428. title = str;
  429. if(iTitle)
  430. add_assoc_string(title_arr, language, title, 1);
  431. else if(iDesc)
  432. add_assoc_string(desc_arr, language, title, 1);
  433. else if(iKeyword)
  434. add_assoc_string(keyword_arr, language, title, 1);
  435. } else if(iGroup) {
  436. if(iGroup)
  437. add_next_index_string(group_arr, str, 1);
  438. }
  439. attrname = php_strtok_r(NULL, "\n", &strtok_buf);
  440. }
  441. efree(temp);
  442. /* Add the title array, if we have one */
  443. if(hasTitle) {
  444. zend_hash_update((*return_value)->value.ht, "Title", 6, &title_arr, sizeof(zval *), NULL);
  445. } else {
  446. efree(title_arr);
  447. }
  448. if(hasDescription) {
  449. /* Add the description array, if we have one */
  450. zend_hash_update((*return_value)->value.ht, "Description", 12, &desc_arr, sizeof(zval *), NULL);
  451. } else {
  452. efree(desc_arr);
  453. }
  454. if(hasKeyword) {
  455. /* Add the keyword array, if we have one */
  456. zend_hash_update((*return_value)->value.ht, "Keyword", 8, &keyword_arr, sizeof(zval *), NULL);
  457. } else {
  458. efree(keyword_arr);
  459. }
  460. if(hasGroup) {
  461. /* Add the Group array, if we have one */
  462. zend_hash_update((*return_value)->value.ht, "Group", 6, &group_arr, sizeof(zval *), NULL);
  463. } else {
  464. efree(group_arr);
  465. }
  466. /* All other attributes. Make a another copy first */
  467. temp = estrdup(objrec);
  468. attrname = php_strtok_r(temp, "\n", &strtok_buf);
  469. while(attrname != NULL) {
  470. str = attrname;
  471. /* We don't want to insert titles, descr., keywords a second time */
  472. if((0 != strncmp(attrname, "Title=", 6)) &&
  473. (0 != strncmp(attrname, "Description=", 12)) &&
  474. (0 != strncmp(attrname, "Group=", 6)) &&
  475. (0 != strncmp(attrname, "Keyword=", 8))) {
  476. while((*str != '=') && (*str != '\0'))
  477. str++;
  478. *str = '\0';
  479. str++;
  480. add_assoc_string(*return_value, attrname, str, 1);
  481. }
  482. attrname = php_strtok_r(NULL, "\n", &strtok_buf);
  483. }
  484. efree(temp);
  485. return(0);
  486. }
  487. /* }}} */
  488. #define BUFFERLEN 1024
  489. /* {{{ make_objrec_from_array
  490. */
  491. static char * make_objrec_from_array(HashTable *lht) {
  492. int i, count, keytype;
  493. ulong length;
  494. char *key, str[BUFFERLEN], *objrec = NULL;
  495. zval *keydata, **keydataptr;
  496. if(NULL == lht)
  497. return NULL;
  498. if(0 == (count = zend_hash_num_elements(lht)))
  499. return NULL;
  500. zend_hash_internal_pointer_reset(lht);
  501. objrec = malloc(1);
  502. *objrec = '\0';
  503. for(i=0; i<count; i++) {
  504. keytype = zend_hash_get_current_key(lht, &key, &length, 0);
  505. /* if(HASH_KEY_IS_STRING == keytype) { */
  506. zend_hash_get_current_data(lht, (void **) &keydataptr);
  507. keydata = *keydataptr;
  508. switch(keydata->type) {
  509. case IS_STRING:
  510. if(HASH_KEY_IS_STRING == keytype)
  511. snprintf(str, BUFFERLEN, "%s=%s\n", key, keydata->value.str.val);
  512. else
  513. snprintf(str, BUFFERLEN, "%s\n", keydata->value.str.val);
  514. break;
  515. case IS_LONG:
  516. if(HASH_KEY_IS_STRING == keytype)
  517. snprintf(str, BUFFERLEN, "%s=0x%lX\n", key, keydata->value.lval);
  518. else
  519. snprintf(str, BUFFERLEN, "0x%lX\n", keydata->value.lval);
  520. break;
  521. case IS_ARRAY: {
  522. int i, len, keylen, count;
  523. char *strarr, *ptr, *ptr1;
  524. count = zend_hash_num_elements(keydata->value.ht);
  525. if(count > 0) {
  526. strarr = make_objrec_from_array(keydata->value.ht);
  527. len = strlen(strarr) - 1;
  528. keylen = strlen(key);
  529. if(NULL == (ptr = malloc(len + 1 + count*(keylen+1)))) {
  530. free(objrec);
  531. return(NULL);
  532. }
  533. ptr1 = ptr;
  534. *ptr1 = '\0';
  535. strcpy(ptr1, key);
  536. ptr1 += keylen;
  537. *ptr1++ = '=';
  538. for(i=0; i<len; i++) {
  539. *ptr1++ = strarr[i];
  540. if(strarr[i] == '\n') {
  541. strcpy(ptr1, key);
  542. ptr1 += keylen;
  543. *ptr1++ = '=';
  544. } else if(strarr[i] == '=')
  545. ptr1[-1] = ':';
  546. }
  547. *ptr1++ = '\n';
  548. *ptr1 = '\0';
  549. strlcpy(str, ptr, sizeof(str));
  550. }
  551. break;
  552. }
  553. }
  554. objrec = realloc(objrec, strlen(objrec)+strlen(str)+1);
  555. strcat(objrec, str);
  556. /* } */
  557. zend_hash_move_forward(lht);
  558. }
  559. return objrec;
  560. }
  561. /* }}} */
  562. #undef BUFFERLEN
  563. /* {{{ make_ints_from_array
  564. */
  565. static int * make_ints_from_array(HashTable *lht) {
  566. int i, count;
  567. int *objids = NULL;
  568. zval **keydata;
  569. if(NULL == lht)
  570. return NULL;
  571. if(0 == (count = zend_hash_num_elements(lht)))
  572. return NULL;
  573. zend_hash_internal_pointer_reset(lht);
  574. if(NULL == (objids = emalloc(count*sizeof(int))))
  575. return NULL;
  576. for(i=0; i<count; i++) {
  577. zend_hash_get_current_data(lht, (void **) &keydata);
  578. switch((*keydata)->type) {
  579. case IS_LONG:
  580. objids[i] = (*keydata)->value.lval;
  581. break;
  582. default:
  583. objids[i] = 0;
  584. }
  585. zend_hash_move_forward(lht);
  586. }
  587. return objids;
  588. }
  589. /* }}} */
  590. /* {{{ make_strs_from_array
  591. */
  592. static char **make_strs_from_array(HashTable *arrht) {
  593. char **carr = NULL;
  594. char **ptr;
  595. zval *data, **dataptr;
  596. zend_hash_internal_pointer_reset(arrht);
  597. if(NULL == (carr = emalloc(zend_hash_num_elements(arrht) * sizeof(char *))))
  598. return(NULL);
  599. ptr = carr;
  600. /* Iterate through hash */
  601. while(zend_hash_get_current_data(arrht, (void **) &dataptr) == SUCCESS) {
  602. data = *dataptr;
  603. switch(data->type) {
  604. case IS_STRING:
  605. *ptr = estrdup(data->value.str.val);
  606. /*fprintf(stderr, "carr[] = %s\n", *ptr); */
  607. break;
  608. default:
  609. *ptr = NULL;
  610. }
  611. ptr++;
  612. zend_hash_move_forward(arrht);
  613. }
  614. return(carr);
  615. }
  616. /* }}} */
  617. #define BUFFERLEN 30
  618. /* {{{ php_hw_do_connect
  619. */
  620. static void php_hw_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
  621. {
  622. zval **argv[4];
  623. int argc;
  624. int sockfd;
  625. int port = 0;
  626. char *host = NULL;
  627. char *userdata = NULL;
  628. char *server_string = NULL;
  629. char *username = NULL;
  630. char *password = NULL;
  631. char *hashed_details;
  632. char *str = NULL;
  633. char buffer[BUFFERLEN];
  634. int hashed_details_length;
  635. hw_connection *ptr;
  636. int do_swap;
  637. int version = 0;
  638. argc = ZEND_NUM_ARGS();
  639. switch(argc) {
  640. case 2:
  641. case 4:
  642. if (zend_get_parameters_array_ex(argc, argv) == FAILURE) {
  643. WRONG_PARAM_COUNT;
  644. }
  645. break;
  646. default:
  647. WRONG_PARAM_COUNT;
  648. }
  649. /* Host: */
  650. convert_to_string_ex(argv[0]);
  651. host = (char *) estrndup((*argv[0])->value.str.val, (*argv[0])->value.str.len);
  652. /* Port: */
  653. convert_to_long_ex(argv[1]);
  654. port = (*argv[1])->value.lval;
  655. /* Username and Password */
  656. if(argc > 2) {
  657. /* Username */
  658. convert_to_string_ex(argv[2]);
  659. username = (char *) estrndup((*argv[2])->value.str.val, (*argv[2])->value.str.len);
  660. /* Password */
  661. convert_to_string_ex(argv[3]);
  662. password = (char *) estrndup((*argv[3])->value.str.val, (*argv[3])->value.str.len);
  663. }
  664. /* Create identifier string for connection */
  665. snprintf(buffer, BUFFERLEN, "%d", port);
  666. hashed_details_length = strlen(host)+strlen(buffer)+8;
  667. if(NULL == (hashed_details = (char *) emalloc(hashed_details_length+1))) {
  668. if(host) efree(host);
  669. if(password) efree(password);
  670. if(username) efree(username);
  671. php_error(E_ERROR, "Could not get memory for connection details");
  672. RETURN_FALSE;
  673. }
  674. sprintf(hashed_details, "hw_%s_%d", host, port);
  675. if (persistent) {
  676. list_entry *le;
  677. /* try to find if we already have this link in our persistent list */
  678. if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_length+1, (void **) &le)==FAILURE) {
  679. list_entry new_le;
  680. if (HwSG(max_links)!=-1 && HwSG(num_links)>=HwSG(max_links)) {
  681. php_error(E_ERROR, "Hyperwave: Too many open links (%d)", HwSG(num_links));
  682. if(host) efree(host);
  683. if(username) efree(username);
  684. if(password) efree(password);
  685. efree(hashed_details);
  686. RETURN_FALSE;
  687. }
  688. if (HwSG(max_persistent!=-1) && HwSG(num_persistent)>=HwSG(max_persistent)) {
  689. php_error(E_ERROR, "Hyperwave: Too many open persistent links (%d)", HwSG(num_persistent));
  690. if(host) efree(host);
  691. if(username) efree(username);
  692. if(password) efree(password);
  693. efree(hashed_details);
  694. RETURN_FALSE;
  695. }
  696. if ( (sockfd = open_hg_connection(host, port)) < 0 ) {
  697. php_error(E_ERROR, "Could not open connection to %s, Port: %d (retval=%d, errno=%d)", host, port, sockfd, errno);
  698. if(host) efree(host);
  699. if(username) efree(username);
  700. if(password) efree(password);
  701. efree(hashed_details);
  702. RETURN_FALSE;
  703. }
  704. if(NULL == (ptr = malloc(sizeof(hw_connection)))) {
  705. php_error(E_ERROR, "Could not get memory for connection structure");
  706. if(host) efree(host);
  707. if(username) efree(username);
  708. if(password) efree(password);
  709. efree(hashed_details);
  710. RETURN_FALSE;
  711. }
  712. if(0 != (ptr->lasterror = initialize_hg_connection(sockfd, &do_swap, &version, &userdata, &server_string, username, password))) {
  713. php_error(E_ERROR, "Could not initalize hyperwave connection");
  714. if(host) efree(host);
  715. if(username) efree(username);
  716. if(password) efree(password);
  717. if(userdata) efree(userdata);
  718. if(server_string) free(server_string);
  719. efree(hashed_details);
  720. RETURN_FALSE;
  721. }
  722. if(username) efree(username);
  723. if(password) efree(password);
  724. ptr->version = version;
  725. ptr->server_string = server_string;
  726. ptr->socket = sockfd;
  727. ptr->swap_on = do_swap;
  728. ptr->linkroot = 0;
  729. ptr->hostname = strdup(host);
  730. ptr->username = strdup("anonymous");
  731. new_le.ptr = (void *) ptr;
  732. new_le.type = le_psocketp;
  733. if (zend_hash_update(&EG(persistent_list), hashed_details, hashed_details_length+1, (void *) &new_le, sizeof(list_entry), NULL)==FAILURE) {
  734. php_error(E_ERROR, "Could not hash table with connection details");
  735. if(host) efree(host);
  736. if(username) efree(username);
  737. if(password) efree(password);
  738. if(server_string) free(server_string);
  739. efree(hashed_details);
  740. RETURN_FALSE;
  741. }
  742. HwSG(num_links)++;
  743. HwSG(num_persistent)++;
  744. } else {
  745. /*php_printf("Found already open connection\n"); */
  746. if (le->type != le_psocketp) {
  747. RETURN_FALSE;
  748. }
  749. ptr = le->ptr;
  750. }
  751. return_value->value.lval = zend_list_insert(ptr, le_psocketp);
  752. return_value->type = IS_RESOURCE;
  753. } else {
  754. list_entry *index_ptr, new_index_ptr;
  755. /* first we check the hash for the hashed_details key. if it exists,
  756. * it should point us to the right offset where the actual hyperwave link sits.
  757. * if it doesn't, open a new hyperwave link, add it to the resource list,
  758. * and add a pointer to it with hashed_details as the key.
  759. */
  760. if (zend_hash_find(&EG(regular_list), hashed_details, hashed_details_length+1, (void **) &index_ptr)==SUCCESS) {
  761. int type, link;
  762. void *ptr;
  763. if (index_ptr->type != le_index_ptr) {
  764. RETURN_FALSE;
  765. }
  766. link = (int) index_ptr->ptr;
  767. ptr = (hw_connection *) zend_list_find(link, &type); /* check if the link is still there */
  768. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  769. return_value->value.lval = HwSG(default_link) = link;
  770. return_value->type = IS_LONG;
  771. efree(hashed_details);
  772. if(username) efree(username);
  773. if(password) efree(password);
  774. if(host) efree(host);
  775. return;
  776. } else {
  777. zend_hash_del(&EG(regular_list), hashed_details, hashed_details_length+1);
  778. }
  779. }
  780. if ( (sockfd = open_hg_connection(host, port)) < 0 ) {
  781. php_error(E_ERROR, "Could not open connection to %s, Port: %d (retval=%d", host, port, sockfd);
  782. if(host) efree(host);
  783. if(username) efree(username);
  784. if(password) efree(password);
  785. efree(hashed_details);
  786. RETURN_FALSE;
  787. }
  788. if(NULL == (ptr = malloc(sizeof(hw_connection)))) {
  789. if(host) efree(host);
  790. if(username) efree(username);
  791. if(password) efree(password);
  792. efree(hashed_details);
  793. RETURN_FALSE;
  794. }
  795. if(0 != (ptr->lasterror = initialize_hg_connection(sockfd, &do_swap, &version, &userdata, &server_string, username, password))) {
  796. php_error(E_ERROR, "Could not initalize hyperwave connection");
  797. if(host) efree(host);
  798. if(username) efree(username);
  799. if(password) efree(password);
  800. if(userdata) efree(userdata);
  801. if(server_string) free(server_string);
  802. efree(hashed_details);
  803. RETURN_FALSE;
  804. }
  805. if(username) efree(username);
  806. if(password) efree(password);
  807. ptr->version = version;
  808. ptr->server_string = server_string;
  809. ptr->socket = sockfd;
  810. ptr->swap_on = do_swap;
  811. ptr->linkroot = 0;
  812. ptr->hostname = strdup(host);
  813. ptr->username = strdup("anonymous");
  814. return_value->value.lval = zend_list_insert(ptr, le_socketp);
  815. return_value->type = IS_RESOURCE;
  816. new_index_ptr.ptr = (void *) return_value->value.lval;
  817. new_index_ptr.type = le_index_ptr;
  818. if (zend_hash_update(&EG(regular_list), hashed_details, hashed_details_length+1, (void *) &new_index_ptr, sizeof(list_entry), NULL)==FAILURE) {
  819. php_error(E_ERROR, "Could not update connection details in hash table");
  820. if(host) efree(host);
  821. efree(hashed_details);
  822. RETURN_FALSE;
  823. }
  824. }
  825. efree(hashed_details);
  826. if(host) efree(host);
  827. HwSG(default_link)=return_value->value.lval;
  828. /* At this point we have a working connection. If userdata was given
  829. we are also indentified.
  830. If there is no userdata because hw_connect was called without username
  831. and password, we don't evaluate userdata.
  832. */
  833. if(NULL == userdata)
  834. return;
  835. if(ptr->username) free(ptr->username);
  836. str = userdata;
  837. while((*str != 0) && (*str != ' '))
  838. str++;
  839. if(*str != '\0')
  840. ptr->username = strdup(++str);
  841. else
  842. ptr->username = NULL;
  843. efree(userdata);
  844. }
  845. /* }}} */
  846. #undef BUFFERLEN
  847. /* Start of user level functions */
  848. /* ***************************** */
  849. /* {{{ proto int hw_connect(string host, int port [string username [, string password]])
  850. Connect to the Hyperwave server */
  851. PHP_FUNCTION(hw_connect)
  852. {
  853. php_hw_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  854. }
  855. /* }}} */
  856. /* {{{ proto int hw_pconnect(string host, int port [, string username [, string password]])
  857. Connect to the Hyperwave server persistent */
  858. PHP_FUNCTION(hw_pconnect)
  859. {
  860. php_hw_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  861. }
  862. /* }}} */
  863. /* {{{ proto void hw_close(int link)
  864. Close connection to Hyperwave server */
  865. PHP_FUNCTION(hw_close)
  866. {
  867. pval **arg1;
  868. int id, type;
  869. hw_connection *ptr;
  870. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
  871. WRONG_PARAM_COUNT;
  872. }
  873. convert_to_long_ex(arg1);
  874. id=(*arg1)->value.lval;
  875. ptr = zend_list_find(id, &type);
  876. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  877. php_error(E_WARNING, "Unable to find file identifier %d", id);
  878. RETURN_FALSE;
  879. }
  880. zend_list_delete(id);
  881. RETURN_TRUE;
  882. }
  883. /* }}} */
  884. /* {{{ proto void hw_info(int link)
  885. Outputs info string */
  886. PHP_FUNCTION(hw_info)
  887. {
  888. pval **arg1;
  889. int id, type;
  890. hw_connection *ptr;
  891. char *str;
  892. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
  893. WRONG_PARAM_COUNT;
  894. }
  895. convert_to_long_ex(arg1);
  896. id=(*arg1)->value.lval;
  897. ptr = zend_list_find(id, &type);
  898. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  899. php_error(E_WARNING, "Unable to find file identifier %d", id);
  900. RETURN_FALSE;
  901. }
  902. if(NULL != (str = get_hw_info(ptr))) {
  903. /*
  904. php_printf("%s\n", str);
  905. efree(str);
  906. */
  907. return_value->value.str.len = strlen(str);
  908. return_value->value.str.val = str;
  909. return_value->type = IS_STRING;
  910. return;
  911. }
  912. RETURN_FALSE;
  913. }
  914. /* }}} */
  915. /* {{{ proto int hw_error(int link)
  916. Returns last error number */
  917. PHP_FUNCTION(hw_error)
  918. {
  919. pval **arg1;
  920. int id, type;
  921. hw_connection *ptr;
  922. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
  923. WRONG_PARAM_COUNT;
  924. }
  925. convert_to_long_ex(arg1);
  926. id=(*arg1)->value.lval;
  927. ptr = zend_list_find(id, &type);
  928. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  929. php_error(E_WARNING, "Unable to find file identifier %d", id);
  930. RETURN_FALSE;
  931. }
  932. RETURN_LONG(ptr->lasterror);
  933. }
  934. /* }}} */
  935. /* {{{ proto string hw_errormsg(int link)
  936. Returns last error message */
  937. PHP_FUNCTION(hw_errormsg)
  938. {
  939. pval **arg1;
  940. int id, type;
  941. hw_connection *ptr;
  942. char errstr[100];
  943. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
  944. WRONG_PARAM_COUNT;
  945. }
  946. convert_to_long_ex(arg1);
  947. id=(*arg1)->value.lval;
  948. ptr = zend_list_find(id, &type);
  949. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  950. php_error(E_WARNING, "Unable to find file identifier %d", id);
  951. RETURN_FALSE;
  952. }
  953. switch (ptr->lasterror) {
  954. case 0:
  955. sprintf(errstr, "No error");
  956. break;
  957. case NOACCESS:
  958. sprintf(errstr, "Access denied");
  959. break;
  960. case NODOCS:
  961. sprintf(errstr, "No documents");
  962. break;
  963. case NONAME:
  964. sprintf(errstr, "No collection name");
  965. break;
  966. case NODOC:
  967. sprintf(errstr, "Object is not a document");
  968. break;
  969. case NOOBJ:
  970. sprintf(errstr, "No object received");
  971. break;
  972. case NOCOLLS:
  973. sprintf(errstr, "No collections received");
  974. break;
  975. case DBSTUBNG:
  976. sprintf(errstr, "Connection to low-level database failed");
  977. break;
  978. case NOTFOUND:
  979. sprintf(errstr, "Object not found");
  980. break;
  981. case EXIST:
  982. sprintf(errstr, "Collection already exists");
  983. break;
  984. case FATHERDEL:
  985. sprintf(errstr, "parent collection disappeared");
  986. break;
  987. case FATHNOCOLL:
  988. sprintf(errstr, "parent collection not a collection");
  989. break;
  990. case NOTEMPTY:
  991. sprintf(errstr, "Collection not empty");
  992. break;
  993. case DESTNOCOLL:
  994. sprintf(errstr, "Destination not a collection");
  995. break;
  996. case SRCEQDEST:
  997. sprintf(errstr, "Source equals destination");
  998. break;
  999. case REQPEND:
  1000. sprintf(errstr, "Request pending");
  1001. break;
  1002. case TIMEOUT:
  1003. sprintf(errstr, "Timeout");
  1004. break;
  1005. case NAMENOTUNIQUE:
  1006. sprintf(errstr, "Name not unique");
  1007. break;
  1008. case WRITESTOPPED:
  1009. sprintf(errstr, "Database now read-only; try again later");
  1010. break;
  1011. case LOCKED:
  1012. sprintf(errstr, "Object locked; try again later");
  1013. break;
  1014. case CHANGEBASEFLD:
  1015. sprintf(errstr, "Change of base-attribute");
  1016. break;
  1017. case NOTREMOVED:
  1018. sprintf(errstr, "Attribute not removed");
  1019. break;
  1020. case FLDEXISTS:
  1021. sprintf(errstr, "Attribute exists");
  1022. break;
  1023. case CMDSYNTAX:
  1024. sprintf(errstr, "Syntax error in command");
  1025. break;
  1026. case NOLANGUAGE:
  1027. sprintf(errstr, "No or unknown language specified");
  1028. break;
  1029. case WRGTYPE:
  1030. sprintf(errstr, "Wrong type in object");
  1031. break;
  1032. case WRGVERSION:
  1033. sprintf(errstr, "Client version too old");
  1034. break;
  1035. case CONNECTION:
  1036. sprintf(errstr, "No connection to other server");
  1037. break;
  1038. case SYNC:
  1039. sprintf(errstr, "Synchronization error");
  1040. break;
  1041. case NOPATH:
  1042. sprintf(errstr, "No path entry");
  1043. break;
  1044. case WRGPATH:
  1045. sprintf(errstr, "Wrong path entry");
  1046. break;
  1047. case PASSWD:
  1048. sprintf(errstr, "Wrong password (server-to-server server authentication)");
  1049. break;
  1050. case LC_NO_MORE_USERS:
  1051. sprintf(errstr, "No more users for license");
  1052. break;
  1053. case LC_NO_MORE_DOCS:
  1054. sprintf(errstr, "No more documents for this session and license");
  1055. break;
  1056. case RSERV_NRESP:
  1057. sprintf(errstr, "Remote server not responding");
  1058. break;
  1059. case Q_OVERFLOW:
  1060. sprintf(errstr, "Query overflow");
  1061. break;
  1062. case USR_BREAK:
  1063. sprintf(errstr, "Break by user");
  1064. break;
  1065. case N_IMPL:
  1066. sprintf(errstr, "Not implemented");
  1067. break;
  1068. case WRG_VALUE:
  1069. sprintf(errstr, "Wrong value");
  1070. break;
  1071. case INSUFF_FUNDS:
  1072. sprintf(errstr, "Insufficient funds");
  1073. break;
  1074. case REORG:
  1075. sprintf(errstr, "Reorganization in progress");
  1076. break;
  1077. case USER_LIMIT:
  1078. sprintf(errstr, "Limit of simultaneous users reached");
  1079. break;
  1080. case FTCONNECT:
  1081. sprintf(errstr, "No connection to fulltext server");
  1082. break;
  1083. case FTTIMEOUT:
  1084. sprintf(errstr, "Connection timed out");
  1085. break;
  1086. case FTINDEX:
  1087. sprintf(errstr, "Something wrong with fulltext index");
  1088. break;
  1089. case FTSYNTAX:
  1090. sprintf(errstr, "Query syntax error");
  1091. break;
  1092. case REQUESTPENDING:
  1093. sprintf(errstr, "Request pending");
  1094. break;
  1095. case NOCONNECTION:
  1096. sprintf(errstr, "No connection to document server");
  1097. break;
  1098. case WRONGVERSION:
  1099. sprintf(errstr, "Wrong protocol version");
  1100. break;
  1101. case NOTINITIALIZED:
  1102. sprintf(errstr, "Not initialized");
  1103. break;
  1104. case BADREQUEST:
  1105. sprintf(errstr, "Bad request");
  1106. break;
  1107. case BADLRN:
  1108. sprintf(errstr, "Bad document number");
  1109. break;
  1110. case OPENSTORE_WRITE:
  1111. sprintf(errstr, "Cannot write to local store");
  1112. break;
  1113. case OPENSTORE_READ:
  1114. sprintf(errstr, "Cannot read from local store");
  1115. break;
  1116. case READSTORE:
  1117. sprintf(errstr, "Store read error");
  1118. break;
  1119. case WRITESTORE:
  1120. sprintf(errstr, "Write error");
  1121. break;
  1122. case CLOSESTORE:
  1123. sprintf(errstr, "Close error");
  1124. break;
  1125. case BADPATH:
  1126. sprintf(errstr, "Bad path");
  1127. break;
  1128. case NOPATHDC:
  1129. sprintf(errstr, "No path");
  1130. break;
  1131. case OPENFILE:
  1132. sprintf(errstr, "Cannot open file");
  1133. break;
  1134. case READFILE:
  1135. sprintf(errstr, "Cannot read from file // same");
  1136. break;
  1137. case WRITEFILE:
  1138. sprintf(errstr, "Cannot write to file");
  1139. break;
  1140. case CONNECTCLIENT:
  1141. sprintf(errstr, "Could not connect to client");
  1142. break;
  1143. case ACCEPT:
  1144. sprintf(errstr, "Could not accept connection");
  1145. break;
  1146. case READSOCKET:
  1147. sprintf(errstr, "Could not read from socket");
  1148. break;
  1149. case WRITESOCKET:
  1150. sprintf(errstr, "Could not write to socket");
  1151. break;
  1152. case TOOMUCHDATA:
  1153. sprintf(errstr, "Received too much data");
  1154. break;
  1155. case TOOFEWDATA:
  1156. sprintf(errstr, "Received too few data // ...");
  1157. break;
  1158. case NOTIMPLEMENTED:
  1159. sprintf(errstr, "Not implemented");
  1160. break;
  1161. case USERBREAK:
  1162. sprintf(errstr, "User break");
  1163. break;
  1164. case INTERNAL:
  1165. sprintf(errstr, "Internal error");
  1166. break;
  1167. case INVALIDOBJECT:
  1168. sprintf(errstr, "Invalid object");
  1169. break;
  1170. case JOBTIMEOUT:
  1171. sprintf(errstr, "Job timed out");
  1172. break;
  1173. case OPENPORT:
  1174. sprintf(errstr, "Cannot open port // ... for several resons");
  1175. break;
  1176. case NODATA:
  1177. sprintf(errstr, "Received no data");
  1178. break;
  1179. case NOPORT:
  1180. sprintf(errstr, "No port to handle this request");
  1181. break;
  1182. case NOTCACHED:
  1183. sprintf(errstr, "Document not cached");
  1184. break;
  1185. case BADCACHETYPE:
  1186. sprintf(errstr, "Bad cache type");
  1187. break;
  1188. case OPENCACHE_WRITE:
  1189. sprintf(errstr, "Cannot write to cache");
  1190. break;
  1191. case OPENCACHE_READ:
  1192. sprintf(errstr, "Cannot read from cache // same");
  1193. break;
  1194. case NOSOURCE:
  1195. sprintf(errstr, "Do not know what to read");
  1196. break;
  1197. case CLOSECACHE:
  1198. sprintf(errstr, "Could not insert into cache");
  1199. break;
  1200. case CONNECTREMOTE:
  1201. sprintf(errstr, "Could not connect to remote server");
  1202. break;
  1203. case LOCKREFUSED:
  1204. sprintf(errstr, "Lock refused // could not lock the stores");
  1205. break;
  1206. default:
  1207. sprintf(errstr, "Unknown error: %d", ptr->lasterror);
  1208. }
  1209. RETURN_STRING(errstr, 1);
  1210. }
  1211. /* }}} */
  1212. /* {{{ proto int hw_root(void)
  1213. Returns object id of root collection */
  1214. PHP_FUNCTION(hw_root)
  1215. {
  1216. if (ZEND_NUM_ARGS() != 0) {
  1217. WRONG_PARAM_COUNT;
  1218. }
  1219. return_value->value.lval = 0;
  1220. return_value->type = IS_LONG;
  1221. }
  1222. /* }}} */
  1223. /* {{{ php_hw_command
  1224. */
  1225. char *php_hw_command(INTERNAL_FUNCTION_PARAMETERS, int comm) {
  1226. pval **arg1;
  1227. int link, type;
  1228. hw_connection *ptr;
  1229. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
  1230. return NULL;
  1231. }
  1232. convert_to_long_ex(arg1);
  1233. link=(*arg1)->value.lval;
  1234. ptr = zend_list_find(link, &type);
  1235. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1236. php_error(E_WARNING, "Unable to find file identifier %d", link);
  1237. return NULL;
  1238. }
  1239. set_swap(ptr->swap_on);
  1240. {
  1241. char *object = NULL;
  1242. if (0 != (ptr->lasterror = send_command(ptr->socket, comm, &object)))
  1243. return NULL;
  1244. return object;
  1245. }
  1246. }
  1247. /* }}} */
  1248. /* {{{ proto string hw_stat(int link)
  1249. Returns status string */
  1250. PHP_FUNCTION(hw_stat)
  1251. {
  1252. char *object;
  1253. object = php_hw_command(INTERNAL_FUNCTION_PARAM_PASSTHRU, STAT_COMMAND);
  1254. if(object == NULL)
  1255. RETURN_FALSE;
  1256. return_value->value.str.val = object;
  1257. return_value->value.str.len = strlen(object);
  1258. return_value->type = IS_STRING;
  1259. }
  1260. /* }}} */
  1261. /* {{{ proto array hw_who(int link)
  1262. Returns names and info of users loged in */
  1263. PHP_FUNCTION(hw_who)
  1264. {
  1265. zval *user_arr;
  1266. char *object, *ptr, *temp, *attrname;
  1267. int i;
  1268. char *strtok_buf;
  1269. object = php_hw_command(INTERNAL_FUNCTION_PARAM_PASSTHRU, WHO_COMMAND);
  1270. if(object == NULL)
  1271. RETURN_FALSE;
  1272. ptr = object;
  1273. php_printf("%s\n", ptr);
  1274. /* Skip first two lines, they just contain:
  1275. Users in Database
  1276. */
  1277. while((*ptr != '\0') && (*ptr != '\n'))
  1278. ptr++;
  1279. while((*ptr != '\0') && (*ptr != '\n'))
  1280. ptr++;
  1281. if(*ptr == '\0') {
  1282. efree(object);
  1283. RETURN_FALSE;
  1284. }
  1285. if (array_init(return_value) == FAILURE) {
  1286. efree(object);
  1287. RETURN_FALSE;
  1288. }
  1289. temp = estrdup(ptr);
  1290. attrname = php_strtok_r(temp, "\n", &strtok_buf);
  1291. i = 0;
  1292. while(attrname != NULL) {
  1293. char *name;
  1294. ALLOC_ZVAL(user_arr);
  1295. if (array_init(user_arr) == FAILURE) {
  1296. efree(object);
  1297. RETURN_FALSE;
  1298. }
  1299. ptr = attrname;
  1300. if(*ptr++ == '*')
  1301. add_assoc_long(user_arr, "self", 1);
  1302. else
  1303. add_assoc_long(user_arr, "self", 0);
  1304. ptr++;
  1305. name = ptr;
  1306. while((*ptr != '\0') && (*ptr != ' '))
  1307. ptr++;
  1308. *ptr = '\0';
  1309. add_assoc_string(user_arr, "id", name, 1);
  1310. ptr++;
  1311. name = ptr;
  1312. while((*ptr != '\0') && (*ptr != ' '))
  1313. ptr++;
  1314. *ptr = '\0';
  1315. add_assoc_string(user_arr, "name", name, 1);
  1316. ptr++;
  1317. while((*ptr != '\0') && (*ptr == ' '))
  1318. ptr++;
  1319. name = ptr;
  1320. while((*ptr != '\0') && (*ptr != ' '))
  1321. ptr++;
  1322. *ptr = '\0';
  1323. add_assoc_string(user_arr, "system", name, 1);
  1324. ptr++;
  1325. while((*ptr != '\0') && (*ptr == ' '))
  1326. ptr++;
  1327. name = ptr;
  1328. while((*ptr != '\0') && (*ptr != ' '))
  1329. ptr++;
  1330. *ptr = '\0';
  1331. add_assoc_string(user_arr, "onSinceDate", name, 1);
  1332. ptr++;
  1333. while((*ptr != '\0') && (*ptr == ' '))
  1334. ptr++;
  1335. name = ptr;
  1336. while((*ptr != '\0') && (*ptr != ' '))
  1337. ptr++;
  1338. *ptr = '\0';
  1339. add_assoc_string(user_arr, "onSinceTime", name, 1);
  1340. ptr++;
  1341. while((*ptr != '\0') && (*ptr == ' '))
  1342. ptr++;
  1343. name = ptr;
  1344. while((*ptr != '\0') && (*ptr != ' '))
  1345. ptr++;
  1346. *ptr = '\0';
  1347. add_assoc_string(user_arr, "TotalTime", name, 1);
  1348. /* Add the user array */
  1349. zend_hash_index_update(return_value->value.ht, i++, &user_arr, sizeof(pval), NULL);
  1350. attrname = php_strtok_r(NULL, "\n", &strtok_buf);
  1351. }
  1352. efree(temp);
  1353. efree(object);
  1354. }
  1355. /* }}} */
  1356. /* {{{ proto string hw_dummy(int link, int id, int msgid)
  1357. Hyperwave dummy function */
  1358. PHP_FUNCTION(hw_dummy)
  1359. {
  1360. pval **arg1, **arg2, **arg3;
  1361. int link, id, type, msgid;
  1362. hw_connection *ptr;
  1363. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
  1364. WRONG_PARAM_COUNT;
  1365. }
  1366. convert_to_long_ex(arg1);
  1367. convert_to_long_ex(arg2);
  1368. convert_to_long_ex(arg3);
  1369. link=(*arg1)->value.lval;
  1370. id=(*arg2)->value.lval;
  1371. msgid=(*arg3)->value.lval;
  1372. ptr = zend_list_find(link, &type);
  1373. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1374. php_error(E_WARNING, "Unable to find file identifier %d", id);
  1375. RETURN_FALSE;
  1376. }
  1377. set_swap(ptr->swap_on);
  1378. {
  1379. char *object = NULL;
  1380. if (0 != (ptr->lasterror = send_dummy(ptr->socket, id, msgid, &object)))
  1381. RETURN_FALSE;
  1382. php_printf("%s", object);
  1383. return_value->value.str.val = object;
  1384. return_value->value.str.len = strlen(object);
  1385. return_value->type = IS_STRING;
  1386. }
  1387. }
  1388. /* }}} */
  1389. /* {{{ proto string hw_getobject(int link, int objid [, string query])
  1390. Returns object record */
  1391. PHP_FUNCTION(hw_getobject)
  1392. {
  1393. pval **argv[3];
  1394. int argc, link, id, type, multi;
  1395. char *query;
  1396. hw_connection *ptr;
  1397. argc = ZEND_NUM_ARGS();
  1398. if(argc < 2 || argc > 3)
  1399. WRONG_PARAM_COUNT;
  1400. if (zend_get_parameters_array_ex(argc, argv) == FAILURE)
  1401. WRONG_PARAM_COUNT;
  1402. convert_to_long_ex(argv[0]);
  1403. if((*argv[1])->type == IS_ARRAY) {
  1404. multi = 1;
  1405. convert_to_array_ex(argv[1]);
  1406. } else {
  1407. multi = 0;
  1408. convert_to_long_ex(argv[1]);
  1409. }
  1410. if(argc == 3) {
  1411. convert_to_string_ex(argv[2]);
  1412. query = (*argv[2])->value.str.val;
  1413. } else
  1414. query = NULL;
  1415. link=(*argv[0])->value.lval;
  1416. ptr = zend_list_find(link, &type);
  1417. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1418. php_error(E_WARNING, "Unable to find file identifier %d", link);
  1419. RETURN_FALSE;
  1420. }
  1421. set_swap(ptr->swap_on);
  1422. if(multi) {
  1423. char **objects = NULL;
  1424. int count, *ids, i;
  1425. HashTable *lht;
  1426. zval **keydata;
  1427. lht = (*argv[1])->value.ht;
  1428. if(0 == (count = zend_hash_num_elements(lht))) {
  1429. RETURN_FALSE;
  1430. }
  1431. ids = emalloc(count * sizeof(hw_objectID));
  1432. zend_hash_internal_pointer_reset(lht);
  1433. for(i=0; i<count; i++) {
  1434. zend_hash_get_current_data(lht, (void **) &keydata);
  1435. switch((*keydata)->type) {
  1436. case IS_LONG:
  1437. ids[i] = (*keydata)->value.lval;
  1438. break;
  1439. default:
  1440. ids[i] = (*keydata)->value.lval;
  1441. }
  1442. zend_hash_move_forward(lht);
  1443. }
  1444. if (0 != (ptr->lasterror = send_objectbyidquery(ptr->socket, ids, &count, query, &objects))) {
  1445. efree(ids);
  1446. RETURN_FALSE;
  1447. }
  1448. efree(ids);
  1449. if (array_init(return_value) == FAILURE) {
  1450. efree(objects);
  1451. RETURN_FALSE;
  1452. }
  1453. for(i=0; i<count; i++) {
  1454. add_index_string(return_value, i, objects[i], 0);
  1455. }
  1456. efree(objects);
  1457. } else {
  1458. char *object = NULL;
  1459. id=(*argv[1])->value.lval;
  1460. if (0 != (ptr->lasterror = send_getobject(ptr->socket, id, &object)))
  1461. RETURN_FALSE;
  1462. RETURN_STRING(object, 0);
  1463. }
  1464. }
  1465. /* }}} */
  1466. /* {{{ proto int hw_insertobject(int link, string objrec, string parms)
  1467. Inserts an object */
  1468. PHP_FUNCTION(hw_insertobject)
  1469. {
  1470. pval *arg1, *arg2, *arg3;
  1471. int link, type;
  1472. char *objrec, *parms;
  1473. hw_connection *ptr;
  1474. if (ZEND_NUM_ARGS() != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) {
  1475. WRONG_PARAM_COUNT;
  1476. }
  1477. convert_to_long(arg1);
  1478. convert_to_string(arg2);
  1479. convert_to_string(arg3);
  1480. link=arg1->value.lval;
  1481. objrec=arg2->value.str.val;
  1482. parms=arg3->value.str.val;
  1483. ptr = zend_list_find(link, &type);
  1484. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1485. php_error(E_WARNING, "Unable to find file identifier %d", link);
  1486. RETURN_FALSE;
  1487. }
  1488. set_swap(ptr->swap_on);
  1489. {
  1490. int objid;
  1491. if (0 != (ptr->lasterror = send_insertobject(ptr->socket, objrec, parms, &objid)))
  1492. RETURN_FALSE;
  1493. RETURN_LONG(objid);
  1494. }
  1495. }
  1496. /* }}} */
  1497. /* {{{ proto string hw_getandlock(int link, int objid)
  1498. Returns object record and locks object */
  1499. PHP_FUNCTION(hw_getandlock)
  1500. {
  1501. pval *arg1, *arg2;
  1502. int link, id, type;
  1503. hw_connection *ptr;
  1504. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  1505. WRONG_PARAM_COUNT;
  1506. }
  1507. convert_to_long(arg1);
  1508. convert_to_long(arg2);
  1509. link=arg1->value.lval;
  1510. id=arg2->value.lval;
  1511. ptr = zend_list_find(link, &type);
  1512. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1513. php_error(E_WARNING, "Unable to find file identifier %d", id);
  1514. RETURN_FALSE;
  1515. }
  1516. set_swap(ptr->swap_on);
  1517. {
  1518. char *object = NULL;
  1519. if (0 != (ptr->lasterror = send_getandlock(ptr->socket, id, &object)))
  1520. RETURN_FALSE;
  1521. RETURN_STRING(object, 0);
  1522. }
  1523. }
  1524. /* }}} */
  1525. /* {{{ proto void hw_unlock(int link, int objid)
  1526. Unlocks object */
  1527. PHP_FUNCTION(hw_unlock)
  1528. {
  1529. pval *arg1, *arg2;
  1530. int link, id, type;
  1531. hw_connection *ptr;
  1532. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  1533. WRONG_PARAM_COUNT;
  1534. }
  1535. convert_to_long(arg1);
  1536. convert_to_long(arg2);
  1537. link=arg1->value.lval;
  1538. id=arg2->value.lval;
  1539. ptr = zend_list_find(link, &type);
  1540. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1541. php_error(E_WARNING, "Unable to find file identifier %d", id);
  1542. RETURN_FALSE;
  1543. }
  1544. set_swap(ptr->swap_on);
  1545. if (0 != (ptr->lasterror = send_unlock(ptr->socket, id)))
  1546. RETURN_FALSE;
  1547. RETURN_TRUE;
  1548. }
  1549. /* }}} */
  1550. /* {{{ proto void hw_deleteobject(int link, int objid)
  1551. Deletes object */
  1552. PHP_FUNCTION(hw_deleteobject)
  1553. {
  1554. pval *arg1, *arg2;
  1555. int link, id, type;
  1556. hw_connection *ptr;
  1557. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  1558. WRONG_PARAM_COUNT;
  1559. }
  1560. convert_to_long(arg1);
  1561. convert_to_long(arg2);
  1562. link=arg1->value.lval;
  1563. id=arg2->value.lval;
  1564. ptr = zend_list_find(link, &type);
  1565. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1566. php_error(E_WARNING, "Unable to find file identifier %d", id);
  1567. RETURN_FALSE;
  1568. }
  1569. set_swap(ptr->swap_on);
  1570. if (0 != (ptr->lasterror = send_deleteobject(ptr->socket, id)))
  1571. RETURN_FALSE;
  1572. RETURN_TRUE;
  1573. }
  1574. /* }}} */
  1575. /* {{{ proto void hw_changeobject(int link, int objid, array attributes)
  1576. Changes attributes of an object (obsolete) */
  1577. #define BUFFERLEN 200
  1578. PHP_FUNCTION(hw_changeobject)
  1579. {
  1580. pval *arg1, *arg2, *arg3;
  1581. int link, id, type, i;
  1582. hw_connection *ptr;
  1583. char *modification, *oldobjrec, buf[BUFFERLEN];
  1584. HashTable *newobjarr;
  1585. if (ZEND_NUM_ARGS() != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) {
  1586. WRONG_PARAM_COUNT;
  1587. }
  1588. convert_to_long(arg1); /* Connection */
  1589. convert_to_long(arg2); /* object ID */
  1590. convert_to_array(arg3); /* Array with new attributes */
  1591. link=arg1->value.lval;
  1592. id=arg2->value.lval;
  1593. newobjarr=arg3->value.ht;
  1594. ptr = zend_list_find(link, &type);
  1595. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1596. php_error(E_WARNING, "Unable to find file identifier %d", id);
  1597. RETURN_FALSE;
  1598. }
  1599. /* get the old object record */
  1600. if(0 != (ptr->lasterror = send_getandlock(ptr->socket, id, &oldobjrec)))
  1601. RETURN_FALSE;
  1602. zend_hash_internal_pointer_reset(newobjarr);
  1603. modification = strdup("");
  1604. for(i=0; i<zend_hash_num_elements(newobjarr); i++) {
  1605. char *key, *str, *str1, newattribute[BUFFERLEN];
  1606. pval *data, **dataptr;
  1607. int j, noinsert=1;
  1608. ulong ind;
  1609. zend_hash_get_current_key(newobjarr, &key, &ind, 0);
  1610. zend_hash_get_current_data(newobjarr, (void *) &dataptr);
  1611. data = *dataptr;
  1612. switch(data->type) {
  1613. case IS_STRING:
  1614. if(strlen(data->value.str.val) == 0)
  1615. snprintf(newattribute, BUFFERLEN, "rem %s", key);
  1616. else
  1617. snprintf(newattribute, BUFFERLEN, "add %s=%s", key, data->value.str.val);
  1618. noinsert = 0;
  1619. break;
  1620. default:
  1621. newattribute[0] = '\0';
  1622. }
  1623. if(!noinsert) {
  1624. modification = fnInsStr(modification, 0, "\\");
  1625. modification = fnInsStr(modification, 0, newattribute);
  1626. /* modification = fnInsStr(modification, 0, "add "); */
  1627. /* Retrieve the old attribute from object record */
  1628. if(NULL != (str = strstr(oldobjrec, key))) {
  1629. str1 = str;
  1630. j = 0;
  1631. while((str1 != NULL) && (*str1 != '\n') && (j < BUFFERLEN-1)) {
  1632. buf[j++] = *str1++;
  1633. }
  1634. buf[j] = '\0';
  1635. modification = fnInsStr(modification, 0, "\\");
  1636. modification = fnInsStr(modification, 0, buf);
  1637. modification = fnInsStr(modification, 0, "rem ");
  1638. }
  1639. }
  1640. zend_hash_move_forward(newobjarr);
  1641. }
  1642. efree(oldobjrec);
  1643. set_swap(ptr->swap_on);
  1644. modification[strlen(modification)-1] = '\0';
  1645. if (0 != (ptr->lasterror = send_changeobject(ptr->socket, id, modification))) {
  1646. free(modification);
  1647. send_unlock(ptr->socket, id);
  1648. RETURN_FALSE;
  1649. }
  1650. free(modification);
  1651. if (0 != (ptr->lasterror = send_unlock(ptr->socket, id))) {
  1652. RETURN_FALSE;
  1653. }
  1654. RETURN_TRUE;
  1655. }
  1656. #undef BUFFERLEN
  1657. /* }}} */
  1658. /* {{{ proto void hw_modifyobject(int link, int objid, array remattributes, array addattributes [, int mode])
  1659. Modifies attributes of an object */
  1660. #define BUFFERLEN 200
  1661. PHP_FUNCTION(hw_modifyobject)
  1662. {
  1663. zval **argv[5];
  1664. int argc;
  1665. int link, id, type, i, mode;
  1666. hw_connection *ptr;
  1667. char *modification;
  1668. HashTable *remobjarr, *addobjarr;
  1669. argc = ZEND_NUM_ARGS();
  1670. if((argc > 5) || (argc < 4))
  1671. WRONG_PARAM_COUNT;
  1672. if (zend_get_parameters_array_ex(argc, argv) == FAILURE)
  1673. if(argc < 4) {
  1674. WRONG_PARAM_COUNT;
  1675. }
  1676. convert_to_long_ex(argv[0]); /* Connection */
  1677. convert_to_long_ex(argv[1]); /* object ID */
  1678. convert_to_array_ex(argv[2]); /* Array with attributes to remove */
  1679. convert_to_array_ex(argv[3]); /* Array with attributes to add */
  1680. if(argc == 5) {
  1681. convert_to_long_ex(argv[4]);
  1682. mode = (*argv[4])->value.lval;
  1683. } else
  1684. mode = 0;
  1685. link=(*argv[0])->value.lval;
  1686. id=(*argv[1])->value.lval;
  1687. remobjarr=(*argv[2])->value.ht;
  1688. addobjarr=(*argv[3])->value.ht;
  1689. ptr = zend_list_find(link, &type);
  1690. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1691. php_error(E_WARNING, "Unable to find file identifier %d", id);
  1692. RETURN_FALSE;
  1693. }
  1694. modification = strdup("");
  1695. if(addobjarr != NULL) {
  1696. zend_hash_internal_pointer_reset(addobjarr);
  1697. for(i=0; i<zend_hash_num_elements(addobjarr); i++) {
  1698. char *key, addattribute[BUFFERLEN];
  1699. zval *data, **dataptr;
  1700. int noinsert=1;
  1701. ulong ind;
  1702. zend_hash_get_current_key(addobjarr, &key, &ind, 0);
  1703. zend_hash_get_current_data(addobjarr, (void *) &dataptr);
  1704. data = *dataptr;
  1705. switch(data->type) {
  1706. case IS_STRING:
  1707. if(strlen(data->value.str.val) > 0) {
  1708. snprintf(addattribute, BUFFERLEN, "add %s=%s", key, data->value.str.val);
  1709. /* fprintf(stderr, "add: %s\n", addattribute); */
  1710. noinsert = 0;
  1711. }
  1712. break;
  1713. case IS_ARRAY: {
  1714. int i, len, keylen, count;
  1715. char *strarr, *ptr, *ptr1;
  1716. count = zend_hash_num_elements(data->value.ht);
  1717. if(count > 0) {
  1718. strarr = make_objrec_from_array(data->value.ht);
  1719. len = strlen(strarr) - 1;
  1720. keylen = strlen(key);
  1721. if(NULL == (ptr = malloc(len + 1 + count*(keylen+1+4)))) {
  1722. if(modification)
  1723. free(modification);
  1724. RETURN_FALSE;
  1725. }
  1726. ptr1 = ptr;
  1727. *ptr1 = '\0';
  1728. strcpy(ptr1, "add ");
  1729. ptr1 += 4;
  1730. strcpy(ptr1, key);
  1731. ptr1 += keylen;
  1732. *ptr1++ = '=';
  1733. for(i=0; i<len; i++) {
  1734. *ptr1++ = strarr[i];
  1735. if(strarr[i] == '\n') {
  1736. ptr1[-1] = '\\';
  1737. strcpy(ptr1, "add ");
  1738. ptr1 += 4;
  1739. strcpy(ptr1, key);
  1740. ptr1 += keylen;
  1741. *ptr1++ = '=';
  1742. } else if(strarr[i] == '=')
  1743. ptr1[-1] = ':';
  1744. }
  1745. *ptr1 = '\0';
  1746. strlcpy(addattribute, ptr, sizeof(addattribute));
  1747. noinsert = 0;
  1748. }
  1749. break;
  1750. }
  1751. }
  1752. if(!noinsert) {
  1753. modification = fnInsStr(modification, 0, "\\");
  1754. modification = fnInsStr(modification, 0, addattribute);
  1755. }
  1756. zend_hash_move_forward(addobjarr);
  1757. }
  1758. }
  1759. if(remobjarr != NULL) {
  1760. int nr;
  1761. zend_hash_internal_pointer_reset(remobjarr);
  1762. nr = zend_hash_num_elements(remobjarr);
  1763. for(i=0; i<nr; i++) {
  1764. char *key, remattribute[BUFFERLEN];
  1765. zval *data, **dataptr;
  1766. int noinsert=1;
  1767. ulong ind;
  1768. zend_hash_get_current_key(remobjarr, &key, &ind, 0);
  1769. zend_hash_get_current_data(remobjarr, (void *) &dataptr);
  1770. data = *dataptr;
  1771. switch(data->type) {
  1772. case IS_STRING:
  1773. if(strlen(data->value.str.val) > 0) {
  1774. snprintf(remattribute, BUFFERLEN, "rem %s=%s", key, data->value.str.val);
  1775. noinsert = 0;
  1776. } else {
  1777. snprintf(remattribute, BUFFERLEN, "rem %s", key);
  1778. noinsert = 0;
  1779. }
  1780. break;
  1781. case IS_ARRAY: {
  1782. int i, len, keylen, count;
  1783. char *strarr, *ptr, *ptr1;
  1784. count = zend_hash_num_elements(data->value.ht);
  1785. if(count > 0) {
  1786. strarr = make_objrec_from_array(data->value.ht);
  1787. len = strlen(strarr) - 1;
  1788. keylen = strlen(key);
  1789. if(NULL == (ptr = malloc(len + 1 + count*(keylen+1+4)))) {
  1790. if(modification)
  1791. free(modification);
  1792. RETURN_FALSE;
  1793. }
  1794. ptr1 = ptr;
  1795. *ptr1 = '\0';
  1796. strcpy(ptr1, "rem ");
  1797. ptr1 += 4;
  1798. strcpy(ptr1, key);
  1799. ptr1 += keylen;
  1800. *ptr1++ = '=';
  1801. for(i=0; i<len; i++) {
  1802. *ptr1++ = strarr[i];
  1803. if(strarr[i] == '\n') {
  1804. ptr1[-1] = '\\';
  1805. strcpy(ptr1, "rem ");
  1806. ptr1 += 4;
  1807. strcpy(ptr1, key);
  1808. ptr1 += keylen;
  1809. *ptr1++ = '=';
  1810. } else if(strarr[i] == '=')
  1811. ptr1[-1] = ':';
  1812. }
  1813. *ptr1++ = '\n';
  1814. *ptr1 = '\0';
  1815. strlcpy(remattribute, ptr, sizeof(remattribute));
  1816. noinsert = 0;
  1817. }
  1818. break;
  1819. }
  1820. }
  1821. if(!noinsert) {
  1822. modification = fnInsStr(modification, 0, "\\");
  1823. modification = fnInsStr(modification, 0, remattribute);
  1824. }
  1825. zend_hash_move_forward(remobjarr);
  1826. }
  1827. }
  1828. set_swap(ptr->swap_on);
  1829. modification[strlen(modification)-1] = '\0';
  1830. if(strlen(modification) == 0) {
  1831. ptr->lasterror = 0;
  1832. free(modification);
  1833. RETURN_TRUE;
  1834. }
  1835. /* fprintf(stderr, "modifyobject: %s\n", modification); */
  1836. switch(mode) {
  1837. case 0:
  1838. if (0 == (ptr->lasterror = send_lock(ptr->socket, id))) {
  1839. if (0 == (ptr->lasterror = send_changeobject(ptr->socket, id, modification))) {
  1840. if (0 != (ptr->lasterror = send_unlock(ptr->socket, id))) {
  1841. php_error(E_WARNING, "Aiii, Changeobject failed and couldn't unlock object (id = 0x%X)", id);
  1842. free(modification);
  1843. RETURN_FALSE;
  1844. }
  1845. free(modification);
  1846. RETURN_FALSE;
  1847. } else {
  1848. send_unlock(ptr->socket, id);
  1849. free(modification);
  1850. RETURN_FALSE;
  1851. }
  1852. } else {
  1853. php_error(E_WARNING, "Could not lock object (id = 0x%X)", id);
  1854. free(modification);
  1855. RETURN_FALSE;
  1856. }
  1857. break;
  1858. case 1:
  1859. /* WARNING: send_groupchangobject() only works right, if each attribute
  1860. can be modified. Doing a changeobject recursively often tries to
  1861. modify objects which cannot be modified e.g. because an attribute cannot
  1862. be removed. In such a case no further modification on that object is done.
  1863. Doing a 'rem Rights\add Rights=R:a' will fail completely if the attribute
  1864. Rights is not there already. The object locking is done in send_groupchangeobject();
  1865. */
  1866. if (0 != (ptr->lasterror = send_groupchangeobject(ptr->socket, id, modification))) {
  1867. free(modification);
  1868. RETURN_FALSE;
  1869. }
  1870. break;
  1871. default:
  1872. php_error(E_WARNING, "hw_modifyobject: Mode must be 0 or 1 (recursive)");
  1873. }
  1874. free(modification);
  1875. RETURN_TRUE;
  1876. }
  1877. #undef BUFFERLEN
  1878. /* }}} */
  1879. /* {{{ php_hw_mvcp
  1880. */
  1881. void php_hw_mvcp(INTERNAL_FUNCTION_PARAMETERS, int mvcp) {
  1882. pval *arg1, *arg2, *arg3, *arg4;
  1883. int link, type, dest=0, from=0, count;
  1884. HashTable *src_arr;
  1885. hw_connection *ptr;
  1886. int collIDcount, docIDcount, i, *docIDs, *collIDs;
  1887. switch(mvcp) {
  1888. case MOVE: /* Move also has fromID */
  1889. if (ZEND_NUM_ARGS() != 4 || getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE)
  1890. WRONG_PARAM_COUNT;
  1891. break;
  1892. case COPY:
  1893. if (ZEND_NUM_ARGS() != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE)
  1894. WRONG_PARAM_COUNT;
  1895. break;
  1896. }
  1897. convert_to_long(arg1);
  1898. convert_to_array(arg2);
  1899. convert_to_long(arg3);
  1900. link=arg1->value.lval;
  1901. src_arr=arg2->value.ht;
  1902. switch(mvcp) {
  1903. case MOVE: /* Move also has fromID, which is arg3 --> arg4 becomes destID */
  1904. convert_to_long(arg4);
  1905. from=arg3->value.lval;
  1906. dest=arg4->value.lval;
  1907. break;
  1908. case COPY: /* No fromID for Copy needed --> arg3 is destID */
  1909. dest=arg3->value.lval;
  1910. from = 0;
  1911. break;
  1912. }
  1913. ptr = zend_list_find(link, &type);
  1914. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  1915. php_error(E_WARNING, "Unable to find file identifier %d", link);
  1916. RETURN_FALSE;
  1917. }
  1918. set_swap(ptr->swap_on);
  1919. count = zend_hash_num_elements(src_arr);
  1920. if(NULL == (collIDs = emalloc(count * sizeof(int)))) {
  1921. RETURN_FALSE;
  1922. }
  1923. if(NULL == (docIDs = emalloc(count * sizeof(int)))) {
  1924. efree(collIDs);
  1925. RETURN_FALSE;
  1926. }
  1927. collIDcount = docIDcount = 0;
  1928. zend_hash_internal_pointer_reset(src_arr);
  1929. for(i=0; i<count; i++) {
  1930. char *objrec;
  1931. zval *keydata, **keydataptr;
  1932. zend_hash_get_current_data(src_arr, (void **) &keydataptr);
  1933. keydata = *keydataptr;
  1934. if(keydata->type == IS_LONG) {
  1935. if(0 != (ptr->lasterror = send_getobject(ptr->socket, keydata->value.lval, &objrec))) {
  1936. efree(collIDs);
  1937. efree(docIDs);
  1938. RETURN_FALSE;
  1939. }
  1940. if(0 == fnAttributeCompare(objrec, "DocumentType", "collection"))
  1941. collIDs[collIDcount++] = keydata->value.lval;
  1942. else
  1943. docIDs[docIDcount++] = keydata->value.lval;
  1944. efree(objrec);
  1945. }
  1946. zend_hash_move_forward(src_arr);
  1947. }
  1948. if (0 != (ptr->lasterror = send_mvcpdocscoll(ptr->socket, docIDs, docIDcount, from, dest, mvcp))) {
  1949. efree(collIDs);
  1950. efree(docIDs);
  1951. RETURN_FALSE;
  1952. }
  1953. if (0 != (ptr->lasterror = send_mvcpcollscoll(ptr->socket, collIDs, collIDcount, from, dest, mvcp))) {
  1954. efree(collIDs);
  1955. efree(docIDs);
  1956. RETURN_FALSE;
  1957. }
  1958. efree(collIDs);
  1959. efree(docIDs);
  1960. RETURN_LONG(docIDcount + collIDcount);
  1961. }
  1962. /* }}} */
  1963. /* {{{ proto void hw_mv(int link, array objrec, int from, int dest)
  1964. Moves object */
  1965. PHP_FUNCTION(hw_mv)
  1966. {
  1967. php_hw_mvcp(INTERNAL_FUNCTION_PARAM_PASSTHRU, MOVE);
  1968. }
  1969. /* }}} */
  1970. /* {{{ proto void hw_cp(int link, array objrec, int dest)
  1971. Copies object */
  1972. PHP_FUNCTION(hw_cp)
  1973. {
  1974. php_hw_mvcp(INTERNAL_FUNCTION_PARAM_PASSTHRU, COPY);
  1975. }
  1976. /* }}} */
  1977. /* {{{ proto hwdoc hw_gettext(int link, int objid [, int rootid])
  1978. Returns text document. Links are relative to rootid if given */
  1979. PHP_FUNCTION(hw_gettext)
  1980. {
  1981. pval *argv[3];
  1982. int argc, link, id, type, mode;
  1983. int rootid = 0;
  1984. char *urlprefix;
  1985. hw_document *doc;
  1986. hw_connection *ptr;
  1987. argc = ZEND_NUM_ARGS();
  1988. if((argc > 3) || (argc < 2))
  1989. WRONG_PARAM_COUNT;
  1990. if (getParametersArray(ht, argc, argv) == FAILURE)
  1991. RETURN_FALSE;
  1992. convert_to_long(argv[0]);
  1993. convert_to_long(argv[1]);
  1994. mode = 0;
  1995. urlprefix = NULL;
  1996. if(argc == 3) {
  1997. switch(argv[2]->type) {
  1998. case IS_LONG:
  1999. convert_to_long(argv[2]);
  2000. rootid = argv[2]->value.lval;
  2001. mode = 1;
  2002. break;
  2003. case IS_STRING:
  2004. convert_to_string(argv[2]);
  2005. urlprefix = argv[2]->value.str.val;
  2006. break;
  2007. }
  2008. }
  2009. link=argv[0]->value.lval;
  2010. id=argv[1]->value.lval;
  2011. ptr = zend_list_find(link, &type);
  2012. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2013. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2014. RETURN_FALSE;
  2015. }
  2016. set_swap(ptr->swap_on);
  2017. {
  2018. char *object = NULL;
  2019. char *attributes = NULL;
  2020. char *bodytag = NULL;
  2021. int count;
  2022. /* !!!! memory for object and attributes is allocated with malloc !!!! */
  2023. if (0 != (ptr->lasterror = send_gettext(ptr->socket, id, mode, rootid, &attributes, &bodytag, &object, &count, urlprefix)))
  2024. RETURN_FALSE;
  2025. doc = malloc(sizeof(hw_document));
  2026. doc->data = object;
  2027. doc->attributes = attributes;
  2028. doc->bodytag = bodytag;
  2029. doc->size = count;
  2030. return_value->value.lval = zend_list_insert(doc, le_document);
  2031. return_value->type = IS_LONG;
  2032. }
  2033. }
  2034. /* }}} */
  2035. /* {{{ proto void hw_edittext(int link, hwdoc doc)
  2036. Modifies text document */
  2037. PHP_FUNCTION(hw_edittext)
  2038. {
  2039. pval *arg1, *arg2;
  2040. int link, doc, type;
  2041. hw_connection *ptr;
  2042. hw_document *docptr;
  2043. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  2044. WRONG_PARAM_COUNT;
  2045. }
  2046. convert_to_long(arg1);
  2047. convert_to_long(arg2);
  2048. link=arg1->value.lval;
  2049. ptr = zend_list_find(link, &type);
  2050. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2051. php_error(E_WARNING, "Unable to find socket identifier %d", link);
  2052. RETURN_FALSE;
  2053. }
  2054. doc=arg2->value.lval;
  2055. docptr = zend_list_find(doc, &type);
  2056. if(!docptr || (type!=le_document)) {
  2057. php_error(E_WARNING, "Unable to find document identifier %d", doc);
  2058. RETURN_FALSE;
  2059. }
  2060. set_swap(ptr->swap_on);
  2061. {
  2062. if (0 != (ptr->lasterror = send_edittext(ptr->socket, docptr->attributes, docptr->data))) {
  2063. RETURN_FALSE;
  2064. }
  2065. }
  2066. RETURN_TRUE;
  2067. }
  2068. /* }}} */
  2069. /* {{{ proto hwdoc hw_getcgi(int link, int objid)
  2070. Returns the output of a CGI script */
  2071. #define BUFFERLEN 1000
  2072. /* FIX ME: The buffer cgi_env_str should be allocated dynamically */
  2073. PHP_FUNCTION(hw_getcgi)
  2074. {
  2075. pval *arg1, *arg2;
  2076. int link, id, type;
  2077. hw_document *doc;
  2078. hw_connection *ptr;
  2079. char cgi_env_str[BUFFERLEN];
  2080. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  2081. WRONG_PARAM_COUNT;
  2082. }
  2083. convert_to_long(arg1);
  2084. convert_to_long(arg2);
  2085. link=arg1->value.lval;
  2086. id=arg2->value.lval;
  2087. ptr = zend_list_find(link, &type);
  2088. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2089. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2090. RETURN_FALSE;
  2091. }
  2092. set_swap(ptr->swap_on);
  2093. {
  2094. char *object = NULL;
  2095. char *attributes = NULL;
  2096. int count;
  2097. /* Here is another undocument function of Hyperwave.
  2098. If you call a cgi script with getcgi-message, you will
  2099. have to provide the complete cgi enviroment, since it is
  2100. only known to the webserver (or wavemaster). This is done
  2101. by extending the object record with the following incomplete
  2102. string. It should contain any enviroment variable a cgi script
  2103. requires.
  2104. */
  2105. #ifdef PHP_WIN32
  2106. snprintf(cgi_env_str, BUFFERLEN, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
  2107. getenv("REQUEST_METHOD"),
  2108. getenv("PATH_INFO"),
  2109. getenv("QUERY_STRING"));
  2110. #else
  2111. snprintf(cgi_env_str, BUFFERLEN, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
  2112. SG(request_info).request_method,
  2113. SG(request_info).request_uri,
  2114. SG(request_info).query_string);
  2115. #endif
  2116. /* !!!! memory for object and attributes is allocated with malloc !!!! */
  2117. if (0 != (ptr->lasterror = send_getcgi(ptr->socket, id, cgi_env_str, &attributes, &object, &count)))
  2118. RETURN_FALSE;
  2119. doc = malloc(sizeof(hw_document));
  2120. doc->data = object;
  2121. doc->attributes = attributes;
  2122. doc->bodytag = NULL;
  2123. doc->size = count;
  2124. return_value->value.lval = zend_list_insert(doc, le_document);
  2125. return_value->type = IS_LONG;
  2126. }
  2127. }
  2128. #undef BUFFERLEN
  2129. /* }}} */
  2130. /* {{{ proto int hw_getremote(int link, int objid)
  2131. Returns the content of a remote document */
  2132. PHP_FUNCTION(hw_getremote)
  2133. {
  2134. pval *arg1, *arg2;
  2135. int link, id, type;
  2136. hw_document *doc;
  2137. hw_connection *ptr;
  2138. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  2139. WRONG_PARAM_COUNT;
  2140. }
  2141. convert_to_long(arg1);
  2142. convert_to_long(arg2);
  2143. link=arg1->value.lval;
  2144. id=arg2->value.lval;
  2145. ptr = zend_list_find(link, &type);
  2146. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2147. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2148. RETURN_FALSE;
  2149. }
  2150. set_swap(ptr->swap_on);
  2151. {
  2152. char *object = NULL;
  2153. char *attributes = NULL;
  2154. int count;
  2155. /* !!!! memory for object and attributes is allocated with malloc !!!! */
  2156. if (0 != (ptr->lasterror = send_getremote(ptr->socket, id, &attributes, &object, &count)))
  2157. RETURN_FALSE;
  2158. doc = malloc(sizeof(hw_document));
  2159. doc->data = object;
  2160. doc->attributes = attributes;
  2161. doc->bodytag = NULL;
  2162. doc->size = count;
  2163. return_value->value.lval = zend_list_insert(doc, le_document);
  2164. return_value->type = IS_LONG;
  2165. }
  2166. }
  2167. /* }}} */
  2168. /* {{{ proto [array|int] hw_getremotechildren(int link, string objrec)
  2169. Returns the remote document or an array of object records */
  2170. PHP_FUNCTION(hw_getremotechildren)
  2171. {
  2172. pval *arg1, *arg2;
  2173. int link, type, i;
  2174. hw_connection *ptr;
  2175. char *objrec;
  2176. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  2177. WRONG_PARAM_COUNT;
  2178. }
  2179. convert_to_long(arg1);
  2180. convert_to_string(arg2);
  2181. link=arg1->value.lval;
  2182. objrec=arg2->value.str.val;
  2183. ptr = zend_list_find(link, &type);
  2184. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2185. php_error(E_WARNING, "Unable to find file identifier %d", link);
  2186. RETURN_FALSE;
  2187. }
  2188. set_swap(ptr->swap_on);
  2189. {
  2190. int count, *offsets;
  2191. char *remainder, *ptr1;
  2192. if (0 != (ptr->lasterror = send_getremotechildren(ptr->socket, objrec, &remainder, &offsets, &count)))
  2193. RETURN_FALSE;
  2194. /*
  2195. for(i=0;i<count;i++)
  2196. php_printf("offset[%d] = %d--\n", i, offsets[i]);
  2197. php_printf("count = %d, remainder = <HR>%s---<HR>", count, remainder);
  2198. */
  2199. /* The remainder depends on the number of returned objects and
  2200. whether the MimeType of the object to retrieve is set. If
  2201. the MimeType is set the result will start with the
  2202. HTTP header 'Content-type: mimetype', otherwise it will be
  2203. a list of object records and therefore starts with
  2204. 'ObjectID=0'. In the first case the offset and count are somewhat
  2205. strange. Quite often count had a value of 6 which appears to be
  2206. meaningless, but if you sum up the offsets you get the length
  2207. of the remainder which is the lenght of the document.
  2208. The document must have been chopped up into 6 pieces, each ending
  2209. with 'ServerId=0xYYYYYYYY'.
  2210. In the second case the offset contains the lenght of
  2211. each object record; count contains the number of object records.
  2212. Even if a remote object has children
  2213. (several sql statements) but the MimeType is set, it will
  2214. return a document in the format of MimeType. On the other
  2215. hand a remote object does not have any children but just
  2216. returns a docuement will not be shown unless the MimeType
  2217. is set. It returns the pure object record of the object without
  2218. the SQLStatement attribute. Quite senseless.
  2219. Though, this behavior depends on how the hgi gateway in Hyperwave
  2220. is implemented.
  2221. */
  2222. if(strncmp(remainder, "ObjectID=0 ", 10)) {
  2223. hw_document *doc;
  2224. char *ptr;
  2225. int i, j, len;
  2226. /* For some reason there is always the string
  2227. 'SeverId=0xYYYYYYYY' at the end, so we cut it off.
  2228. The document may as well be divided into several pieces
  2229. and each of them has the ServerId at the end.
  2230. The following will put the pieces back together and
  2231. strip the ServerId. count contains the number of pieces.
  2232. */
  2233. for(i=0, len=0; i<count; i++)
  2234. len += offsets[i]-18;
  2235. /*fprintf(stderr, "len = %d\n", len); */
  2236. doc = malloc(sizeof(hw_document));
  2237. doc->data = malloc(len+1);
  2238. ptr = doc->data;
  2239. for(i=0, j=0; i<count; i++) {
  2240. memcpy((char *)ptr, (char *)&remainder[j], offsets[i]-18);
  2241. /*fprintf(stderr, "rem = %s\n", &remainder[j]); */
  2242. j += offsets[i];
  2243. ptr += offsets[i] - 18;
  2244. }
  2245. *ptr = '\0';
  2246. doc->attributes = strdup(objrec);
  2247. doc->bodytag = NULL;
  2248. doc->size = strlen(doc->data);
  2249. return_value->value.lval = zend_list_insert(doc, le_document);
  2250. return_value->type = IS_LONG;
  2251. } else {
  2252. if (array_init(return_value) == FAILURE) {
  2253. efree(offsets);
  2254. RETURN_FALSE;
  2255. }
  2256. ptr1 = remainder;
  2257. for(i=0; i<count; i++) {
  2258. *(ptr1+offsets[i]-1) = '\0';
  2259. add_index_string(return_value, i, ptr1, 1);
  2260. ptr1 += offsets[i];
  2261. }
  2262. }
  2263. efree(offsets);
  2264. efree(remainder);
  2265. }
  2266. }
  2267. /* }}} */
  2268. /* {{{ proto void hw_setlinkroot(int link, int rootid)
  2269. Set the id to which links are calculated */
  2270. PHP_FUNCTION(hw_setlinkroot)
  2271. {
  2272. pval *arg1, *arg2;
  2273. int link, type, rootid;
  2274. hw_connection *ptr;
  2275. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  2276. WRONG_PARAM_COUNT;
  2277. }
  2278. convert_to_long(arg1);
  2279. convert_to_long(arg2);
  2280. link = arg1->value.lval;
  2281. rootid = arg2->value.lval;
  2282. ptr = zend_list_find(link, &type);
  2283. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2284. php_error(E_WARNING, "Unable to find file identifier %d", link);
  2285. RETURN_FALSE;
  2286. }
  2287. ptr->linkroot = rootid;
  2288. RETURN_LONG(rootid);
  2289. }
  2290. /* }}} */
  2291. /* {{{ proto hwdoc hw_pipedocument(int link, int objid [, array urlprefixes])
  2292. Returns document with links inserted. Optionally a array with five urlprefixes may be passed, which will be inserted for the different types of anchors. This should be a named array with the following keys: HW_DEFAULT_LINK, HW_IMAGE_LINK, HW_BACKGROUND_LINK, HW_INTAG_LINK, and HW_APPLET_LINK */
  2293. PHP_FUNCTION(hw_pipedocument)
  2294. {
  2295. pval *arg1, *arg2, *arg3;
  2296. int i, link, id, type, argc, mode;
  2297. int rootid = 0;
  2298. HashTable *prefixarray;
  2299. char **urlprefix;
  2300. hw_connection *ptr;
  2301. hw_document *doc;
  2302. #if APACHE
  2303. server_rec *serv = ((request_rec *) SG(server_context))->server;
  2304. #endif
  2305. argc = ZEND_NUM_ARGS();
  2306. switch(argc)
  2307. {
  2308. case 2:
  2309. if (getParameters(ht, 2, &arg1, &arg2) == FAILURE)
  2310. WRONG_PARAM_COUNT;
  2311. break;
  2312. case 3:
  2313. if (getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE)
  2314. WRONG_PARAM_COUNT;
  2315. break;
  2316. default:
  2317. WRONG_PARAM_COUNT;
  2318. }
  2319. convert_to_long(arg1);
  2320. convert_to_long(arg2);
  2321. link=arg1->value.lval;
  2322. id=arg2->value.lval;
  2323. ptr = zend_list_find(link, &type);
  2324. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2325. php_error(E_WARNING, "Unable to find file identifier %d", link);
  2326. RETURN_FALSE;
  2327. }
  2328. /* check for the array with urlprefixes */
  2329. if(argc == 3) {
  2330. convert_to_array(arg3);
  2331. prefixarray =arg3->value.ht;
  2332. if((prefixarray == NULL) || (zend_hash_num_elements(prefixarray) != 5)) {
  2333. php_error(E_WARNING, "You must provide 5 urlprefixes (you have provided %d)", zend_hash_num_elements(prefixarray));
  2334. RETURN_FALSE;
  2335. }
  2336. urlprefix = emalloc(5*sizeof(char *));
  2337. zend_hash_internal_pointer_reset(prefixarray);
  2338. for(i=0; i<5; i++) {
  2339. char *key;
  2340. zval *data, **dataptr;
  2341. ulong ind;
  2342. zend_hash_get_current_key(prefixarray, &key, &ind, 0);
  2343. zend_hash_get_current_data(prefixarray, (void *) &dataptr);
  2344. data = *dataptr;
  2345. if (data->type != IS_STRING) {
  2346. php_error(E_WARNING, "%s must be a String", key);
  2347. RETURN_FALSE;
  2348. } else if ( strcmp(key, "HW_DEFAULT_LINK") == 0 ) {
  2349. urlprefix[HW_DEFAULT_LINK] = data->value.str.val;
  2350. } else if ( strcmp(key, "HW_IMAGE_LINK") == 0 ) {
  2351. urlprefix[HW_IMAGE_LINK] = data->value.str.val;
  2352. } else if ( strcmp(key, "HW_BACKGROUND_LINK") == 0 ) {
  2353. urlprefix[HW_BACKGROUND_LINK] = data->value.str.val;
  2354. } else if ( strcmp(key, "HW_INTAG_LINK") == 0 ) {
  2355. urlprefix[HW_INTAG_LINK] = data->value.str.val;
  2356. } else if ( strcmp(key, "HW_APPLET_LINK") == 0 ) {
  2357. urlprefix[HW_APPLET_LINK] = data->value.str.val;
  2358. } else {
  2359. php_error(E_WARNING, "%s is not a valid urlprefix", key);
  2360. RETURN_FALSE;
  2361. }
  2362. zend_hash_move_forward(prefixarray);
  2363. }
  2364. } else {
  2365. urlprefix = NULL;
  2366. }
  2367. mode = 0;
  2368. if(ptr->linkroot > 0)
  2369. mode = 1;
  2370. rootid = ptr->linkroot;
  2371. set_swap(ptr->swap_on);
  2372. {
  2373. char *object = NULL;
  2374. char *attributes = NULL;
  2375. char *bodytag = NULL;
  2376. int count;
  2377. /* !!!! memory for object, bodytag and attributes is allocated with malloc !!!! */
  2378. if (0 != (ptr->lasterror = send_pipedocument(ptr->socket,
  2379. #if APACHE
  2380. serv->server_hostname,
  2381. #else
  2382. getenv("HOSTNAME"),
  2383. #endif
  2384. id, mode, rootid, &attributes, &bodytag, &object, &count, urlprefix)))
  2385. RETURN_FALSE;
  2386. if(urlprefix) efree(urlprefix);
  2387. doc = malloc(sizeof(hw_document));
  2388. doc->data = object;
  2389. doc->attributes = attributes;
  2390. doc->bodytag = bodytag;
  2391. doc->size = count;
  2392. /* fprintf(stderr, "size = %d\n", count); */
  2393. return_value->value.lval = zend_list_insert(doc, le_document);
  2394. return_value->type = IS_LONG;
  2395. }
  2396. }
  2397. /* }}} */
  2398. /* {{{ proto hwdoc hw_pipedocument(int link, int objid)
  2399. Returns document */
  2400. PHP_FUNCTION(hw_oldpipedocument)
  2401. {
  2402. pval *argv[3];
  2403. int link, id, type, argc, mode;
  2404. int rootid = 0;
  2405. hw_connection *ptr;
  2406. hw_document *doc;
  2407. #if APACHE
  2408. server_rec *serv = ((request_rec *) SG(server_context))->server;
  2409. #endif
  2410. argc = ZEND_NUM_ARGS();
  2411. if((argc > 2) || (argc < 2))
  2412. WRONG_PARAM_COUNT;
  2413. if (getParametersArray(ht, argc, argv) == FAILURE)
  2414. RETURN_FALSE;
  2415. convert_to_long(argv[0]);
  2416. convert_to_long(argv[1]);
  2417. /* if(argc == 3) {
  2418. convert_to_long(argv[2]);
  2419. rootid = argv[2]->value.lval;
  2420. if(rootid != 0)
  2421. mode = 1;
  2422. }
  2423. */ link=argv[0]->value.lval;
  2424. id=argv[1]->value.lval;
  2425. ptr = zend_list_find(link, &type);
  2426. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2427. php_error(E_WARNING, "Unable to find file identifier %d", link);
  2428. RETURN_FALSE;
  2429. }
  2430. mode = 0;
  2431. if(ptr->linkroot > 0)
  2432. mode = 1;
  2433. rootid = ptr->linkroot;
  2434. set_swap(ptr->swap_on);
  2435. {
  2436. char *object = NULL;
  2437. char *attributes = NULL;
  2438. char *bodytag = NULL;
  2439. int count;
  2440. /* !!!! memory for object, bodytag and attributes is allocated with malloc !!!! */
  2441. if (0 != (ptr->lasterror = send_pipedocument(ptr->socket,
  2442. #if APACHE
  2443. serv->server_hostname,
  2444. #else
  2445. getenv("HOSTNAME"),
  2446. #endif
  2447. id, mode, rootid, &attributes, &bodytag, &object, &count, NULL)))
  2448. RETURN_FALSE;
  2449. doc = malloc(sizeof(hw_document));
  2450. doc->data = object;
  2451. doc->attributes = attributes;
  2452. doc->bodytag = bodytag;
  2453. doc->size = count;
  2454. /* fprintf(stderr, "size = %d\n", count); */
  2455. return_value->value.lval = zend_list_insert(doc, le_document);
  2456. return_value->type = IS_LONG;
  2457. }
  2458. }
  2459. /* }}} */
  2460. /* {{{ proto hwdoc hw_pipecgi(int link, int objid)
  2461. Returns output of CGI script */
  2462. #define BUFFERLEN 1000
  2463. /* FIX ME: The buffer cgi_env_str should be allocated dynamically */
  2464. PHP_FUNCTION(hw_pipecgi)
  2465. {
  2466. pval *arg1, *arg2;
  2467. int link, id, type;
  2468. hw_connection *ptr;
  2469. hw_document *doc;
  2470. char cgi_env_str[1000];
  2471. #if APACHE
  2472. server_rec *serv = ((request_rec *) SG(server_context))->server;
  2473. #endif
  2474. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  2475. WRONG_PARAM_COUNT;
  2476. }
  2477. convert_to_long(arg1);
  2478. convert_to_long(arg2);
  2479. link=arg1->value.lval;
  2480. id=arg2->value.lval;
  2481. ptr = zend_list_find(link, &type);
  2482. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2483. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2484. RETURN_FALSE;
  2485. }
  2486. set_swap(ptr->swap_on);
  2487. {
  2488. char *object = NULL;
  2489. char *attributes = NULL;
  2490. int count;
  2491. #ifdef PHP_WIN32
  2492. snprintf(cgi_env_str, BUFFERLEN, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
  2493. getenv("REQUEST_METHOD"),
  2494. getenv("PATH_INFO"),
  2495. getenv("QUERY_STRING"));
  2496. #else
  2497. snprintf(cgi_env_str, BUFFERLEN, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
  2498. SG(request_info).request_method,
  2499. SG(request_info).request_uri,
  2500. SG(request_info).query_string);
  2501. #endif
  2502. /* !!!! memory for object, bodytag and attributes is allocated with malloc !!!! */
  2503. if (0 != (ptr->lasterror = send_pipecgi(ptr->socket,
  2504. #if APACHE
  2505. serv->server_hostname,
  2506. #else
  2507. getenv("HOSTNAME"),
  2508. #endif
  2509. id, cgi_env_str, &attributes, &object, &count)))
  2510. RETURN_FALSE;
  2511. doc = malloc(sizeof(hw_document));
  2512. doc->data = object;
  2513. doc->attributes = attributes;
  2514. doc->bodytag = NULL;
  2515. doc->size = count;
  2516. return_value->value.lval = zend_list_insert(doc, le_document);
  2517. return_value->type = IS_LONG;
  2518. }
  2519. }
  2520. #undef BUFFERLEN
  2521. /* }}} */
  2522. /* {{{ proto void hw_insertdocument(int link, int parentid, hwdoc doc)
  2523. Insert new document */
  2524. PHP_FUNCTION(hw_insertdocument)
  2525. {
  2526. pval *arg1, *arg2, *arg3;
  2527. int link, id, doc, type;
  2528. hw_connection *ptr;
  2529. hw_document *docptr;
  2530. hw_objectID objid;
  2531. #if APACHE
  2532. server_rec *serv = ((request_rec *) SG(server_context))->server;
  2533. #endif
  2534. if (ZEND_NUM_ARGS() != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) {
  2535. WRONG_PARAM_COUNT;
  2536. }
  2537. convert_to_long(arg1);
  2538. convert_to_long(arg2);
  2539. convert_to_long(arg3);
  2540. link=arg1->value.lval;
  2541. id=arg2->value.lval;
  2542. ptr = zend_list_find(link, &type);
  2543. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2544. php_error(E_WARNING, "Unable to find connection identifier %d", link);
  2545. RETURN_FALSE;
  2546. }
  2547. doc=arg3->value.lval;
  2548. docptr = zend_list_find(doc, &type);
  2549. if(!docptr || (type!=le_document)) {
  2550. php_error(E_WARNING, "Unable to find document identifier %d", doc);
  2551. RETURN_FALSE;
  2552. }
  2553. set_swap(ptr->swap_on);
  2554. {
  2555. if (0 != (ptr->lasterror = send_putdocument(ptr->socket,
  2556. #if APACHE
  2557. serv->server_hostname,
  2558. #else
  2559. getenv("HOSTNAME"),
  2560. #endif
  2561. id, docptr->attributes, docptr->data, docptr->size, &objid))) {
  2562. RETURN_FALSE;
  2563. }
  2564. }
  2565. RETURN_LONG(objid);
  2566. }
  2567. /* }}} */
  2568. /* {{{ proto hwdoc hw_new_document(string objrec, string data, int size)
  2569. Create a new document */
  2570. PHP_FUNCTION(hw_new_document)
  2571. {
  2572. pval *arg1, *arg2, *arg3;
  2573. char *ptr;
  2574. hw_document *doc;
  2575. if (ZEND_NUM_ARGS() != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) {
  2576. WRONG_PARAM_COUNT;
  2577. }
  2578. convert_to_string(arg1);
  2579. convert_to_string(arg2);
  2580. convert_to_long(arg3);
  2581. doc = malloc(sizeof(hw_document));
  2582. if(NULL == doc)
  2583. RETURN_FALSE;
  2584. doc->data = malloc(arg3->value.lval+1);
  2585. if(NULL == doc->data) {
  2586. free(doc);
  2587. RETURN_FALSE;
  2588. }
  2589. memcpy(doc->data, arg2->value.str.val, arg3->value.lval);
  2590. ptr = doc->data;
  2591. ptr[arg3->value.lval] = '\0';
  2592. doc->attributes = strdup(arg1->value.str.val);
  2593. doc->bodytag = NULL;
  2594. doc->size = arg3->value.lval;
  2595. return_value->value.lval = zend_list_insert(doc, le_document);
  2596. return_value->type = IS_LONG;
  2597. }
  2598. /* }}} */
  2599. #define BUFSIZE 8192
  2600. /* {{{ proto hwdoc hw_new_document_from_file(string objrec, string filename)
  2601. Create a new document from a file */
  2602. PHP_FUNCTION(hw_new_document_from_file)
  2603. {
  2604. pval **arg1, **arg2;
  2605. int len, type;
  2606. char *ptr;
  2607. int issock=0;
  2608. int socketd=0;
  2609. FILE *fp;
  2610. int ready=0;
  2611. int bcount=0;
  2612. int use_include_path=0;
  2613. hw_document *doc;
  2614. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  2615. WRONG_PARAM_COUNT;
  2616. }
  2617. convert_to_string_ex(arg1);
  2618. convert_to_string_ex(arg2);
  2619. fp = php_fopen_wrapper((*arg2)->value.str.val, "r", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL TSRMLS_CC);
  2620. if (!fp && !socketd){
  2621. if (issock != BAD_URL) {
  2622. char *tmp = estrndup(Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2));
  2623. php_strip_url_passwd(tmp);
  2624. php_error(E_WARNING, "hw_new_document_from_file(\"%s\") - %s", tmp, strerror(errno));
  2625. efree(tmp);
  2626. }
  2627. RETURN_FALSE;
  2628. }
  2629. doc = malloc(sizeof(hw_document));
  2630. if(NULL == doc)
  2631. RETURN_FALSE;
  2632. #ifdef HAVE_MMAP
  2633. if(!issock) {
  2634. int fd;
  2635. struct stat sbuf;
  2636. off_t off;
  2637. void *p;
  2638. size_t len;
  2639. fd = fileno(fp);
  2640. fstat(fd, &sbuf);
  2641. if (sbuf.st_size > BUFSIZE) {
  2642. /* off = ftell(fp); */
  2643. len = sbuf.st_size;/* - off; */
  2644. p = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, off);
  2645. if (p != (void *) MAP_FAILED) {
  2646. doc->data = malloc(len);
  2647. if(NULL == doc->data) {
  2648. munmap(p, len);
  2649. free(doc);
  2650. RETURN_FALSE;
  2651. }
  2652. memcpy(p, doc->data, len);
  2653. munmap(p, len);
  2654. bcount = len;
  2655. doc->size = len;
  2656. ready = 1;
  2657. }
  2658. }
  2659. }
  2660. #endif
  2661. if(!ready) {
  2662. int b;
  2663. doc->data = malloc(BUFSIZE);
  2664. if(NULL == doc->data) {
  2665. free(doc);
  2666. RETURN_FALSE;
  2667. }
  2668. ptr = doc->data;
  2669. while ((b = FP_FREAD(&ptr[bcount], BUFSIZE, socketd, fp, issock)) > 0) {
  2670. bcount += b;
  2671. doc->data = realloc(doc->data, bcount+BUFSIZE);
  2672. ptr = doc->data;
  2673. }
  2674. }
  2675. if (issock) {
  2676. SOCK_FCLOSE(socketd);
  2677. } else {
  2678. fclose(fp);
  2679. }
  2680. doc->data = realloc(doc->data, bcount+1);
  2681. ptr = doc->data;
  2682. ptr[bcount] = '\0';
  2683. doc->attributes = strdup((*arg1)->value.str.val);
  2684. doc->bodytag = NULL;
  2685. doc->size = bcount;
  2686. return_value->value.lval = zend_list_insert(doc, le_document);
  2687. return_value->type = IS_LONG;
  2688. }
  2689. /* }}} */
  2690. #undef BUFSIZE
  2691. /* {{{ proto void hw_free_document(hwdoc doc)
  2692. Frees memory of document */
  2693. PHP_FUNCTION(hw_free_document)
  2694. {
  2695. pval *arg1;
  2696. int id, type;
  2697. hw_document *ptr;
  2698. if (ZEND_NUM_ARGS() != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
  2699. WRONG_PARAM_COUNT;
  2700. }
  2701. convert_to_long(arg1);
  2702. id=arg1->value.lval;
  2703. ptr = zend_list_find(id, &type);
  2704. if(!ptr || (type!=le_document)) {
  2705. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2706. RETURN_FALSE;
  2707. }
  2708. zend_list_delete(id);
  2709. RETURN_TRUE;
  2710. }
  2711. /* }}} */
  2712. /* {{{ proto void hw_outputdocument(hwdoc doc)
  2713. An alias for hw_output_document */
  2714. /* }}} */
  2715. /* {{{ proto void hw_output_document(hwdoc doc)
  2716. Prints document */
  2717. PHP_FUNCTION(hw_output_document)
  2718. {
  2719. pval *arg1;
  2720. int id, type;
  2721. hw_document *ptr;
  2722. if (ZEND_NUM_ARGS() != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
  2723. WRONG_PARAM_COUNT;
  2724. }
  2725. convert_to_long(arg1);
  2726. id=arg1->value.lval;
  2727. ptr = zend_list_find(id, &type);
  2728. if(!ptr || (type!=le_document)) {
  2729. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2730. RETURN_FALSE;
  2731. }
  2732. php_write(ptr->data, ptr->size TSRMLS_CC);
  2733. RETURN_TRUE;
  2734. }
  2735. /* }}} */
  2736. /* {{{ proto string hw_documentbodytag(hwdoc doc [, string prefix])
  2737. An alias for hw_document_bodytag */
  2738. /* }}} */
  2739. /* {{{ proto string hw_document_bodytag(hwdoc doc [, string prefix])
  2740. Return bodytag prefixed by prefix */
  2741. PHP_FUNCTION(hw_document_bodytag)
  2742. {
  2743. pval *argv[2];
  2744. int id, type, argc;
  2745. hw_document *ptr;
  2746. char *temp, *str = NULL;
  2747. argc = ZEND_NUM_ARGS();
  2748. if((argc > 2) || (argc < 1))
  2749. WRONG_PARAM_COUNT;
  2750. if (getParametersArray(ht, argc, argv) == FAILURE)
  2751. RETURN_FALSE;
  2752. convert_to_long(argv[0]);
  2753. id=argv[0]->value.lval;
  2754. ptr = zend_list_find(id, &type);
  2755. if(!ptr || (type!=le_document)) {
  2756. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2757. RETURN_FALSE;
  2758. }
  2759. if(argc == 2) {
  2760. convert_to_string(argv[1]);
  2761. str=argv[1]->value.str.val;
  2762. }
  2763. if(str != NULL) {
  2764. temp = emalloc(argv[1]->value.str.len + strlen(ptr->bodytag) + 2);
  2765. strcpy(temp, ptr->bodytag);
  2766. strcpy(temp+strlen(ptr->bodytag)-1, str);
  2767. strcpy(temp+strlen(ptr->bodytag)-1+argv[1]->value.str.len, ">\n");
  2768. RETURN_STRING(temp, 0);
  2769. } else {
  2770. //fprintf(stderr, "hw_document_bodytag: %s (%s)\n", ptr->bodytag, ptr->attributes);
  2771. if(ptr->bodytag) {
  2772. RETURN_STRING(ptr->bodytag, 1);
  2773. } else {
  2774. RETURN_EMPTY_STRING();
  2775. }
  2776. }
  2777. }
  2778. /* }}} */
  2779. /* {{{ proto string hw_document_content(hwdoc doc)
  2780. Returns content of document */
  2781. PHP_FUNCTION(hw_document_content)
  2782. {
  2783. pval *argv[1];
  2784. int id, type, argc;
  2785. hw_document *ptr;
  2786. argc = ZEND_NUM_ARGS();
  2787. if(argc != 1)
  2788. WRONG_PARAM_COUNT;
  2789. if (getParametersArray(ht, argc, argv) == FAILURE)
  2790. RETURN_FALSE;
  2791. convert_to_long(argv[0]);
  2792. id=argv[0]->value.lval;
  2793. ptr = zend_list_find(id, &type);
  2794. if(!ptr || (type!=le_document)) {
  2795. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2796. RETURN_FALSE;
  2797. }
  2798. RETURN_STRINGL(ptr->data, ptr->size, 1);
  2799. }
  2800. /* }}} */
  2801. /* {{{ proto int hw_document_setcontent(hwdoc doc, string content)
  2802. Sets/replaces content of document */
  2803. PHP_FUNCTION(hw_document_setcontent)
  2804. {
  2805. pval *argv[2];
  2806. int id, type, argc;
  2807. hw_document *ptr;
  2808. char *str;
  2809. argc = ZEND_NUM_ARGS();
  2810. if(argc != 2)
  2811. WRONG_PARAM_COUNT;
  2812. if (getParametersArray(ht, argc, argv) == FAILURE)
  2813. RETURN_FALSE;
  2814. convert_to_long(argv[0]);
  2815. convert_to_string(argv[1]);
  2816. id=argv[0]->value.lval;
  2817. ptr = zend_list_find(id, &type);
  2818. if(!ptr || (type!=le_document)) {
  2819. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2820. RETURN_FALSE;
  2821. }
  2822. str = ptr->data;
  2823. if(NULL != (ptr->data = strdup(argv[1]->value.str.val))) {
  2824. ptr->size = strlen(ptr->data);
  2825. free(str);
  2826. RETURN_TRUE;
  2827. } else {
  2828. ptr->data = str;
  2829. RETURN_FALSE;
  2830. }
  2831. }
  2832. /* }}} */
  2833. /* {{{ proto int hw_documentsize(hwdoc doc)
  2834. An alias for hw_document_size */
  2835. /* }}} */
  2836. /* {{{ proto int hw_document_size(hwdoc doc)
  2837. Returns size of document */
  2838. PHP_FUNCTION(hw_document_size)
  2839. {
  2840. pval *arg1;
  2841. int id, type;
  2842. hw_document *ptr;
  2843. if (ZEND_NUM_ARGS() != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
  2844. WRONG_PARAM_COUNT;
  2845. }
  2846. convert_to_long(arg1);
  2847. id=arg1->value.lval;
  2848. ptr = zend_list_find(id, &type);
  2849. if(!ptr || (type!=le_document)) {
  2850. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2851. RETURN_FALSE;
  2852. }
  2853. RETURN_LONG(ptr->size);
  2854. }
  2855. /* }}} */
  2856. /* {{{ proto string hw_documentattributes(hwdoc doc)
  2857. An alias for hw_document_attributes */
  2858. /* }}} */
  2859. /* {{{ proto string hw_document_attributes(hwdoc doc)
  2860. Returns object record of document */
  2861. PHP_FUNCTION(hw_document_attributes)
  2862. {
  2863. pval *arg1;
  2864. int id, type;
  2865. hw_document *ptr;
  2866. if (ZEND_NUM_ARGS() != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
  2867. WRONG_PARAM_COUNT;
  2868. }
  2869. convert_to_long(arg1);
  2870. id=arg1->value.lval;
  2871. ptr = zend_list_find(id, &type);
  2872. if(!ptr || (type!=le_document)) {
  2873. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2874. RETURN_FALSE;
  2875. }
  2876. RETURN_STRING(ptr->attributes, 1);
  2877. /* make_return_array_from_objrec(&return_value, ptr->attributes); */
  2878. }
  2879. /* }}} */
  2880. /* {{{ proto array hw_getparentsobj(int link, int objid)
  2881. Returns array of parent object records */
  2882. PHP_FUNCTION(hw_getparentsobj)
  2883. {
  2884. pval *arg1, *arg2;
  2885. int link, id, type;
  2886. int count;
  2887. char **childObjRecs = NULL;
  2888. hw_connection *ptr;
  2889. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  2890. WRONG_PARAM_COUNT;
  2891. }
  2892. convert_to_long(arg1);
  2893. convert_to_long(arg2);
  2894. link=arg1->value.lval;
  2895. id=arg2->value.lval;
  2896. ptr = zend_list_find(link, &type);
  2897. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2898. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2899. RETURN_FALSE;
  2900. }
  2901. set_swap(ptr->swap_on);
  2902. if (0 != (ptr->lasterror = send_getparentsobj(ptr->socket, id, &childObjRecs, &count))) {
  2903. php_error(E_WARNING, "send_command (getparentsobj) returned %d\n", ptr->lasterror);
  2904. RETURN_FALSE;
  2905. }
  2906. /* create return value and free all memory */
  2907. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  2908. RETURN_FALSE;
  2909. }
  2910. /* }}} */
  2911. /* {{{ proto array hw_getparents(int link, int objid)
  2912. Returns array of parent object ids */
  2913. PHP_FUNCTION(hw_getparents)
  2914. {
  2915. pval *arg1, *arg2;
  2916. int link, id, type;
  2917. int count;
  2918. hw_connection *ptr;
  2919. if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
  2920. WRONG_PARAM_COUNT;
  2921. }
  2922. convert_to_long(arg1);
  2923. convert_to_long(arg2);
  2924. link=arg1->value.lval;
  2925. id=arg2->value.lval;
  2926. ptr = zend_list_find(link, &type);
  2927. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2928. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2929. RETURN_FALSE;
  2930. }
  2931. set_swap(ptr->swap_on);
  2932. {
  2933. int *childIDs = NULL;
  2934. int i;
  2935. if (0 != (ptr->lasterror = send_getparents(ptr->socket, id, &childIDs, &count))) {
  2936. php_error(E_WARNING, "send_command (getparents) returned %d\n", ptr->lasterror);
  2937. RETURN_FALSE;
  2938. }
  2939. if (array_init(return_value) == FAILURE) {
  2940. efree(childIDs);
  2941. RETURN_FALSE;
  2942. }
  2943. for(i=0; i<count; i++) {
  2944. add_index_long(return_value, i, childIDs[i]);
  2945. }
  2946. efree(childIDs);
  2947. }
  2948. }
  2949. /* }}} */
  2950. /* {{{ proto array hw_children(int link, int objid)
  2951. Returns array of children object ids */
  2952. PHP_FUNCTION(hw_children)
  2953. {
  2954. zval **arg1, **arg2;
  2955. int link, id, type;
  2956. int count;
  2957. hw_connection *ptr;
  2958. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  2959. WRONG_PARAM_COUNT;
  2960. }
  2961. convert_to_long_ex(arg1);
  2962. convert_to_long_ex(arg2);
  2963. link=(*arg1)->value.lval;
  2964. id=(*arg2)->value.lval;
  2965. ptr = zend_list_find(link, &type);
  2966. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  2967. php_error(E_WARNING, "Unable to find file identifier %d", id);
  2968. RETURN_FALSE;
  2969. }
  2970. set_swap(ptr->swap_on);
  2971. {
  2972. int *childIDs = NULL;
  2973. int i;
  2974. if (0 != (ptr->lasterror = send_children(ptr->socket, id, &childIDs, &count))){
  2975. php_error(E_WARNING, "send_command (getchildcoll) returned %d\n", ptr->lasterror);
  2976. RETURN_FALSE;
  2977. }
  2978. if (array_init(return_value) == FAILURE) {
  2979. efree(childIDs);
  2980. RETURN_FALSE;
  2981. }
  2982. for(i=0; i<count; i++) {
  2983. add_index_long(return_value, i, childIDs[i]);
  2984. }
  2985. efree(childIDs);
  2986. }
  2987. }
  2988. /* }}} */
  2989. /* {{{ proto array hw_childrenobj(int link, int objid)
  2990. Returns array of children object records */
  2991. PHP_FUNCTION(hw_childrenobj)
  2992. {
  2993. pval **arg1, **arg2;
  2994. int link, id, type;
  2995. int count;
  2996. char **childObjRecs = NULL;
  2997. hw_connection *ptr;
  2998. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  2999. WRONG_PARAM_COUNT;
  3000. }
  3001. convert_to_long_ex(arg1);
  3002. convert_to_long_ex(arg2);
  3003. link=(*arg1)->value.lval;
  3004. id=(*arg2)->value.lval;
  3005. ptr = zend_list_find(link, &type);
  3006. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3007. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3008. RETURN_FALSE;
  3009. }
  3010. set_swap(ptr->swap_on);
  3011. if (0 != (ptr->lasterror = send_childrenobj(ptr->socket, id, &childObjRecs, &count))) {
  3012. php_error(E_WARNING, "send_command (getchildcollobj) returned %d\n", ptr->lasterror);
  3013. RETURN_FALSE;
  3014. }
  3015. /* create return value and free all memory */
  3016. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  3017. RETURN_FALSE;
  3018. }
  3019. /* }}} */
  3020. /* {{{ proto array hw_getchildcoll(int link, int objid)
  3021. Returns array of child collection object ids */
  3022. PHP_FUNCTION(hw_getchildcoll)
  3023. {
  3024. pval **arg1, **arg2;
  3025. int link, id, type;
  3026. int count;
  3027. hw_connection *ptr;
  3028. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  3029. WRONG_PARAM_COUNT;
  3030. }
  3031. convert_to_long_ex(arg1);
  3032. convert_to_long_ex(arg2);
  3033. link=(*arg1)->value.lval;
  3034. id=(*arg2)->value.lval;
  3035. ptr = zend_list_find(link, &type);
  3036. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3037. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3038. RETURN_FALSE;
  3039. }
  3040. set_swap(ptr->swap_on);
  3041. {
  3042. int *childIDs = NULL;
  3043. int i;
  3044. if (0 != (ptr->lasterror = send_getchildcoll(ptr->socket, id, &childIDs, &count))){
  3045. php_error(E_WARNING, "send_command (getchildcoll) returned %d\n", ptr->lasterror);
  3046. RETURN_FALSE;
  3047. }
  3048. if (array_init(return_value) == FAILURE) {
  3049. efree(childIDs);
  3050. RETURN_FALSE;
  3051. }
  3052. for(i=0; i<count; i++) {
  3053. add_index_long(return_value, i, childIDs[i]);
  3054. }
  3055. efree(childIDs);
  3056. }
  3057. }
  3058. /* }}} */
  3059. /* {{{ proto array hw_getchildcollobj(int link, int objid)
  3060. Returns array of child collection object records */
  3061. PHP_FUNCTION(hw_getchildcollobj)
  3062. {
  3063. pval **arg1, **arg2;
  3064. int link, id, type;
  3065. int count;
  3066. char **childObjRecs = NULL;
  3067. hw_connection *ptr;
  3068. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  3069. WRONG_PARAM_COUNT;
  3070. }
  3071. convert_to_long_ex(arg1);
  3072. convert_to_long_ex(arg2);
  3073. link=(*arg1)->value.lval;
  3074. id=(*arg2)->value.lval;
  3075. ptr = zend_list_find(link, &type);
  3076. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3077. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3078. RETURN_FALSE;
  3079. }
  3080. set_swap(ptr->swap_on);
  3081. if (0 != (ptr->lasterror = send_getchildcollobj(ptr->socket, id, &childObjRecs, &count))) {
  3082. php_error(E_WARNING, "send_command (getchildcollobj) returned %d\n", ptr->lasterror);
  3083. RETURN_FALSE;
  3084. }
  3085. /* create return value and free all memory */
  3086. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  3087. RETURN_FALSE;
  3088. }
  3089. /* }}} */
  3090. /* {{{ proto int hw_docbyanchor(int link, int anchorid)
  3091. Returns objid of document belonging to anchorid */
  3092. PHP_FUNCTION(hw_docbyanchor)
  3093. {
  3094. pval **arg1, **arg2;
  3095. int link, id, type;
  3096. hw_connection *ptr;
  3097. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(ht, 2, &arg1, &arg2) == FAILURE) {
  3098. WRONG_PARAM_COUNT;
  3099. }
  3100. convert_to_long_ex(arg1);
  3101. convert_to_long_ex(arg2);
  3102. link=(*arg1)->value.lval;
  3103. id=(*arg2)->value.lval;
  3104. ptr = zend_list_find(link, &type);
  3105. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3106. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3107. RETURN_FALSE;
  3108. }
  3109. set_swap(ptr->swap_on);
  3110. {
  3111. int objectID;
  3112. if (0 != (ptr->lasterror = send_docbyanchor(ptr->socket, id, &objectID)))
  3113. RETURN_FALSE;
  3114. RETURN_LONG(objectID);
  3115. }
  3116. }
  3117. /* }}} */
  3118. /* {{{ proto array hw_docbyanchorobj(int link, int anchorid)
  3119. Returns object record of document belonging to anchorid */
  3120. PHP_FUNCTION(hw_docbyanchorobj)
  3121. {
  3122. pval **arg1, **arg2;
  3123. int link, id, type;
  3124. hw_connection *ptr;
  3125. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  3126. WRONG_PARAM_COUNT;
  3127. }
  3128. convert_to_long_ex(arg1);
  3129. convert_to_long_ex(arg2);
  3130. link=(*arg1)->value.lval;
  3131. id=(*arg2)->value.lval;
  3132. ptr = zend_list_find(link, &type);
  3133. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3134. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3135. RETURN_FALSE;
  3136. }
  3137. set_swap(ptr->swap_on);
  3138. {
  3139. char *object = NULL;
  3140. if (0 != (ptr->lasterror = send_docbyanchorobj(ptr->socket, id, &object)))
  3141. RETURN_FALSE;
  3142. RETURN_STRING(object, 0);
  3143. /*
  3144. make_return_array_from_objrec(&return_value, object);
  3145. efree(object);
  3146. */
  3147. }
  3148. }
  3149. /* }}} */
  3150. /* {{{ proto array hw_getobjectbyquery(int link, string query, int maxhits)
  3151. Search for query and return maxhits objids */
  3152. PHP_FUNCTION(hw_getobjectbyquery)
  3153. {
  3154. pval **arg1, **arg2, **arg3;
  3155. int link, type, maxhits;
  3156. char *query;
  3157. int count, i;
  3158. int *childIDs = NULL;
  3159. hw_connection *ptr;
  3160. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
  3161. WRONG_PARAM_COUNT;
  3162. }
  3163. convert_to_long_ex(arg1);
  3164. convert_to_string_ex(arg2);
  3165. convert_to_long_ex(arg3);
  3166. link=(*arg1)->value.lval;
  3167. query=(*arg2)->value.str.val;
  3168. maxhits=(*arg3)->value.lval;
  3169. if (maxhits < 0) maxhits=0x7FFFFFFF;
  3170. ptr = zend_list_find(link, &type);
  3171. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3172. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3173. RETURN_FALSE;
  3174. }
  3175. set_swap(ptr->swap_on);
  3176. if (0 != (ptr->lasterror = send_getobjbyquery(ptr->socket, query, maxhits, &childIDs, &count))) {
  3177. php_error(E_WARNING, "send_command (getobjectbyquery) returned %d\n", ptr->lasterror);
  3178. RETURN_FALSE;
  3179. }
  3180. if (array_init(return_value) == FAILURE) {
  3181. efree(childIDs);
  3182. RETURN_FALSE;
  3183. }
  3184. for(i=0; i<count; i++)
  3185. add_index_long(return_value, i, childIDs[i]);
  3186. efree(childIDs);
  3187. }
  3188. /* }}} */
  3189. /* {{{ proto array hw_getobjectbyqueryobj(int link, string query, int maxhits)
  3190. Search for query and return maxhits object records */
  3191. PHP_FUNCTION(hw_getobjectbyqueryobj)
  3192. {
  3193. pval **arg1, **arg2, **arg3;
  3194. int link, type, maxhits;
  3195. char *query;
  3196. int count;
  3197. char **childObjRecs = NULL;
  3198. hw_connection *ptr;
  3199. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
  3200. WRONG_PARAM_COUNT;
  3201. }
  3202. convert_to_long_ex(arg1);
  3203. convert_to_string_ex(arg2);
  3204. convert_to_long_ex(arg3);
  3205. link=(*arg1)->value.lval;
  3206. query=(*arg2)->value.str.val;
  3207. maxhits=(*arg3)->value.lval;
  3208. if (maxhits < 0) maxhits=0x7FFFFFFF;
  3209. ptr = zend_list_find(link, &type);
  3210. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3211. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3212. RETURN_FALSE;
  3213. }
  3214. set_swap(ptr->swap_on);
  3215. if (0 != (ptr->lasterror = send_getobjbyqueryobj(ptr->socket, query, maxhits, &childObjRecs, &count))) {
  3216. php_error(E_WARNING, "send_command (getobjectbyqueryobj) returned %d\n", ptr->lasterror);
  3217. RETURN_FALSE;
  3218. }
  3219. /* create return value and free all memory */
  3220. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  3221. RETURN_FALSE;
  3222. }
  3223. /* }}} */
  3224. /* {{{ proto array hw_getobjectbyquerycoll(int link, int collid, string query, int maxhits)
  3225. Search for query in collection and return maxhits objids */
  3226. PHP_FUNCTION(hw_getobjectbyquerycoll)
  3227. {
  3228. pval **arg1, **arg2, **arg3, **arg4;
  3229. int link, id, type, maxhits;
  3230. char *query;
  3231. int count, i;
  3232. hw_connection *ptr;
  3233. int *childIDs = NULL;
  3234. if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
  3235. WRONG_PARAM_COUNT;
  3236. }
  3237. convert_to_long_ex(arg1);
  3238. convert_to_long_ex(arg2);
  3239. convert_to_string_ex(arg3);
  3240. convert_to_long_ex(arg4);
  3241. link=(*arg1)->value.lval;
  3242. id=(*arg2)->value.lval;
  3243. query=(*arg3)->value.str.val;
  3244. maxhits=(*arg4)->value.lval;
  3245. if (maxhits < 0) maxhits=0x7FFFFFFF;
  3246. ptr = zend_list_find(link, &type);
  3247. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3248. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3249. RETURN_FALSE;
  3250. }
  3251. set_swap(ptr->swap_on);
  3252. if (0 != (ptr->lasterror = send_getobjbyquerycoll(ptr->socket, id, query, maxhits, &childIDs, &count))) {
  3253. php_error(E_WARNING, "send_command (getobjectbyquerycoll) returned %d\n", ptr->lasterror);
  3254. RETURN_FALSE;
  3255. }
  3256. if (array_init(return_value) == FAILURE) {
  3257. efree(childIDs);
  3258. RETURN_FALSE;
  3259. }
  3260. for(i=0; i<count; i++)
  3261. add_index_long(return_value, i, childIDs[i]);
  3262. efree(childIDs);
  3263. }
  3264. /* }}} */
  3265. /* {{{ proto array hw_getobjectbyquerycollobj(int link, int collid, string query, int maxhits)
  3266. Search for query in collection and return maxhits object records */
  3267. PHP_FUNCTION(hw_getobjectbyquerycollobj)
  3268. {
  3269. pval **arg1, **arg2, **arg3, **arg4;
  3270. int link, id, type, maxhits;
  3271. char *query;
  3272. int count;
  3273. hw_connection *ptr;
  3274. char **childObjRecs = NULL;
  3275. if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
  3276. WRONG_PARAM_COUNT;
  3277. }
  3278. convert_to_long_ex(arg1);
  3279. convert_to_long_ex(arg2);
  3280. convert_to_string_ex(arg3);
  3281. convert_to_long_ex(arg4);
  3282. link=(*arg1)->value.lval;
  3283. id=(*arg2)->value.lval;
  3284. query=(*arg3)->value.str.val;
  3285. maxhits=(*arg4)->value.lval;
  3286. if (maxhits < 0) maxhits=0x7FFFFFFF;
  3287. ptr = zend_list_find(link, &type);
  3288. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3289. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3290. RETURN_FALSE;
  3291. }
  3292. set_swap(ptr->swap_on);
  3293. if (0 != (ptr->lasterror = send_getobjbyquerycollobj(ptr->socket, id, query, maxhits, &childObjRecs, &count))) {
  3294. php_error(E_WARNING, "send_command (getobjectbyquerycollobj) returned %d\n", ptr->lasterror);
  3295. RETURN_FALSE;
  3296. }
  3297. /* create return value and free all memory */
  3298. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  3299. RETURN_FALSE;
  3300. }
  3301. /* }}} */
  3302. /* {{{ proto array hw_getobjectbyftquery(int link, string query, int maxhits)
  3303. Search for query as fulltext and return maxhits objids */
  3304. PHP_FUNCTION(hw_getobjectbyftquery)
  3305. {
  3306. pval **arg1, **arg2, **arg3;
  3307. int link, type, maxhits;
  3308. char *query;
  3309. int count, i;
  3310. int *childIDs = NULL;
  3311. float *weights;
  3312. hw_connection *ptr;
  3313. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
  3314. WRONG_PARAM_COUNT;
  3315. }
  3316. convert_to_long_ex(arg1);
  3317. convert_to_string_ex(arg2);
  3318. convert_to_long_ex(arg3);
  3319. link=(*arg1)->value.lval;
  3320. query=(*arg2)->value.str.val;
  3321. maxhits=(*arg3)->value.lval;
  3322. if (maxhits < 0) maxhits=0x7FFFFFFF;
  3323. ptr = zend_list_find(link, &type);
  3324. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3325. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3326. RETURN_FALSE;
  3327. }
  3328. set_swap(ptr->swap_on);
  3329. if (0 != (ptr->lasterror = send_getobjbyftquery(ptr->socket, query, maxhits, &childIDs, &weights, &count))) {
  3330. php_error(E_WARNING, "send_command (getobjectbyftquery) returned %d\n", ptr->lasterror);
  3331. RETURN_FALSE;
  3332. }
  3333. if (array_init(return_value) == FAILURE) {
  3334. efree(childIDs);
  3335. RETURN_FALSE;
  3336. }
  3337. for(i=0; i<count; i++)
  3338. add_index_long(return_value, i, childIDs[i]);
  3339. efree(childIDs);
  3340. }
  3341. /* }}} */
  3342. /* {{{ proto array hw_getobjectbyftqueryobj(int link, string query, int maxhits)
  3343. Search for query as fulltext and return maxhits object records */
  3344. PHP_FUNCTION(hw_getobjectbyftqueryobj)
  3345. {
  3346. pval **arg1, **arg2, **arg3;
  3347. int link, type, maxhits;
  3348. char *query;
  3349. int count;
  3350. char **childObjRecs = NULL;
  3351. float *weights;
  3352. hw_connection *ptr;
  3353. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
  3354. WRONG_PARAM_COUNT;
  3355. }
  3356. convert_to_long_ex(arg1);
  3357. convert_to_string_ex(arg2);
  3358. convert_to_long_ex(arg3);
  3359. link=(*arg1)->value.lval;
  3360. query=(*arg2)->value.str.val;
  3361. maxhits=(*arg3)->value.lval;
  3362. if (maxhits < 0) maxhits=0x7FFFFFFF;
  3363. ptr = zend_list_find(link, &type);
  3364. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3365. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3366. RETURN_FALSE;
  3367. }
  3368. set_swap(ptr->swap_on);
  3369. if (0 != (ptr->lasterror = send_getobjbyftqueryobj(ptr->socket, query, maxhits, &childObjRecs, &weights, &count))) {
  3370. php_error(E_WARNING, "send_command (getobjectbyftqueryobj) returned %d\n", ptr->lasterror);
  3371. RETURN_FALSE;
  3372. }
  3373. /* create return value and free all memory */
  3374. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  3375. RETURN_FALSE;
  3376. }
  3377. /* }}} */
  3378. /* {{{ proto array hw_getobjectbyftquerycoll(int link, int collid, string query, int maxhits)
  3379. Search for fulltext query in collection and return maxhits objids */
  3380. PHP_FUNCTION(hw_getobjectbyftquerycoll)
  3381. {
  3382. pval **arg1, **arg2, **arg3, **arg4;
  3383. int link, id, type, maxhits;
  3384. char *query;
  3385. int count, i;
  3386. hw_connection *ptr;
  3387. int *childIDs = NULL;
  3388. float *weights;
  3389. if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
  3390. WRONG_PARAM_COUNT;
  3391. }
  3392. convert_to_long_ex(arg1);
  3393. convert_to_long_ex(arg2);
  3394. convert_to_string_ex(arg3);
  3395. convert_to_long_ex(arg4);
  3396. link=(*arg1)->value.lval;
  3397. id=(*arg2)->value.lval;
  3398. query=(*arg3)->value.str.val;
  3399. maxhits=(*arg4)->value.lval;
  3400. if (maxhits < 0) maxhits=0x7FFFFFFF;
  3401. ptr = zend_list_find(link, &type);
  3402. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3403. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3404. RETURN_FALSE;
  3405. }
  3406. set_swap(ptr->swap_on);
  3407. if (0 != (ptr->lasterror = send_getobjbyftquerycoll(ptr->socket, id, query, maxhits, &childIDs, &weights, &count))) {
  3408. php_error(E_WARNING, "send_command (getobjectbyquerycoll) returned %d\n", ptr->lasterror);
  3409. RETURN_FALSE;
  3410. }
  3411. if (array_init(return_value) == FAILURE) {
  3412. efree(childIDs);
  3413. RETURN_FALSE;
  3414. }
  3415. for(i=0; i<count; i++)
  3416. add_index_long(return_value, i, childIDs[i]);
  3417. efree(childIDs);
  3418. }
  3419. /* }}} */
  3420. /* {{{ proto array hw_getobjectbyftquerycollobj(int link, int collid, string query, int maxhits)
  3421. Search for fulltext query in collection and return maxhits object records */
  3422. PHP_FUNCTION(hw_getobjectbyftquerycollobj)
  3423. {
  3424. pval **arg1, **arg2, **arg3, **arg4;
  3425. int link, id, type, maxhits;
  3426. char *query;
  3427. int count;
  3428. hw_connection *ptr;
  3429. char **childObjRecs = NULL;
  3430. float *weights;
  3431. if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
  3432. WRONG_PARAM_COUNT;
  3433. }
  3434. convert_to_long_ex(arg1);
  3435. convert_to_long_ex(arg2);
  3436. convert_to_string_ex(arg3);
  3437. convert_to_long_ex(arg4);
  3438. link=(*arg1)->value.lval;
  3439. id=(*arg2)->value.lval;
  3440. query=(*arg3)->value.str.val;
  3441. maxhits=(*arg4)->value.lval;
  3442. if (maxhits < 0) maxhits=0x7FFFFFFF;
  3443. ptr = zend_list_find(link, &type);
  3444. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3445. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3446. RETURN_FALSE;
  3447. }
  3448. set_swap(ptr->swap_on);
  3449. if (0 != (ptr->lasterror = send_getobjbyftquerycollobj(ptr->socket, id, query, maxhits, &childObjRecs, &weights, &count))) {
  3450. php_error(E_WARNING, "send_command (getobjectbyquerycollobj) returned %d\n", ptr->lasterror);
  3451. RETURN_FALSE;
  3452. }
  3453. /* create return value and free all memory */
  3454. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  3455. RETURN_FALSE;
  3456. }
  3457. /* }}} */
  3458. /* {{{ proto array hw_getchilddoccoll(int link, int objid)
  3459. Returns all children ids which are documents */
  3460. PHP_FUNCTION(hw_getchilddoccoll)
  3461. {
  3462. pval **arg1, **arg2;
  3463. int link, id, type;
  3464. int count, i;
  3465. int *childIDs = NULL;
  3466. hw_connection *ptr;
  3467. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  3468. WRONG_PARAM_COUNT;
  3469. }
  3470. convert_to_long_ex(arg1);
  3471. convert_to_long_ex(arg2);
  3472. link=(*arg1)->value.lval;
  3473. id=(*arg2)->value.lval;
  3474. ptr = zend_list_find(link, &type);
  3475. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3476. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3477. RETURN_FALSE;
  3478. }
  3479. set_swap(ptr->swap_on);
  3480. if (0 != (ptr->lasterror = send_getchilddoccoll(ptr->socket, id, &childIDs, &count))) {
  3481. php_error(E_WARNING, "send_command (getchilddoccoll) returned %d\n", ptr->lasterror);
  3482. RETURN_FALSE;
  3483. }
  3484. if (array_init(return_value) == FAILURE) {
  3485. efree(childIDs);
  3486. RETURN_FALSE;
  3487. }
  3488. for(i=0; i<count; i++)
  3489. add_index_long(return_value, i, childIDs[i]);
  3490. efree(childIDs);
  3491. }
  3492. /* }}} */
  3493. /* {{{ proto array hw_getchilddoccollobj(int link, int objid)
  3494. Returns all children object records which are documents */
  3495. PHP_FUNCTION(hw_getchilddoccollobj)
  3496. {
  3497. pval **arg1, **arg2;
  3498. int link, id, type;
  3499. int count;
  3500. char **childObjRecs = NULL;
  3501. hw_connection *ptr;
  3502. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  3503. WRONG_PARAM_COUNT;
  3504. }
  3505. convert_to_long_ex(arg1);
  3506. convert_to_long_ex(arg2);
  3507. link=(*arg1)->value.lval;
  3508. id=(*arg2)->value.lval;
  3509. ptr = zend_list_find(link, &type);
  3510. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3511. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3512. RETURN_FALSE;
  3513. }
  3514. set_swap(ptr->swap_on);
  3515. if (0 != (ptr->lasterror = send_getchilddoccollobj(ptr->socket, id, &childObjRecs, &count))) {
  3516. php_error(E_WARNING, "send_command (getchilddoccollobj) returned %d\n", ptr->lasterror);
  3517. RETURN_FALSE;
  3518. }
  3519. /* create return value and free all memory */
  3520. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  3521. RETURN_FALSE;
  3522. }
  3523. /* }}} */
  3524. /* {{{ proto array hw_getanchors(int link, int objid)
  3525. Return all anchors of object */
  3526. PHP_FUNCTION(hw_getanchors)
  3527. {
  3528. pval **arg1, **arg2;
  3529. int link, id, type;
  3530. int count, i;
  3531. int *anchorIDs = NULL;
  3532. hw_connection *ptr;
  3533. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  3534. WRONG_PARAM_COUNT;
  3535. }
  3536. convert_to_long_ex(arg1);
  3537. convert_to_long_ex(arg2);
  3538. link=(*arg1)->value.lval;
  3539. id=(*arg2)->value.lval;
  3540. ptr = zend_list_find(link, &type);
  3541. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3542. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3543. RETURN_FALSE;
  3544. }
  3545. set_swap(ptr->swap_on);
  3546. if (0 != (ptr->lasterror = send_getanchors(ptr->socket, id, &anchorIDs, &count))) {
  3547. php_error(E_WARNING, "send_command (getanchors) returned %d\n", ptr->lasterror);
  3548. RETURN_FALSE;
  3549. }
  3550. if (array_init(return_value) == FAILURE) {
  3551. efree(anchorIDs);
  3552. RETURN_FALSE;
  3553. }
  3554. for(i=0; i<count; i++)
  3555. add_index_long(return_value, i, anchorIDs[i]);
  3556. efree(anchorIDs);
  3557. }
  3558. /* }}} */
  3559. /* {{{ proto array hw_getanchorsobj(int link, int objid)
  3560. Return all object records of anchors of object */
  3561. PHP_FUNCTION(hw_getanchorsobj)
  3562. {
  3563. pval **arg1, **arg2;
  3564. int link, id, type;
  3565. int count;
  3566. char **anchorObjRecs = NULL;
  3567. hw_connection *ptr;
  3568. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  3569. WRONG_PARAM_COUNT;
  3570. }
  3571. convert_to_long_ex(arg1);
  3572. convert_to_long_ex(arg2);
  3573. link=(*arg1)->value.lval;
  3574. id=(*arg2)->value.lval;
  3575. ptr = (hw_connection *) zend_list_find(link, &type);
  3576. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3577. php_error(E_WARNING, "Unable to find file identifier %d", id);
  3578. RETURN_FALSE;
  3579. }
  3580. set_swap(ptr->swap_on);
  3581. if (0 != (ptr->lasterror = send_getanchorsobj(ptr->socket, id, &anchorObjRecs, &count))) {
  3582. php_error(E_WARNING, "send_command (getanchors) returned %d\n", ptr->lasterror);
  3583. RETURN_FALSE;
  3584. }
  3585. /* create return value and free all memory */
  3586. if( 0 > make_return_objrec(&return_value, anchorObjRecs, count))
  3587. RETURN_FALSE;
  3588. }
  3589. /* }}} */
  3590. /* {{{ proto string hw_getusername(int link)
  3591. Returns the current user name */
  3592. PHP_FUNCTION(hw_getusername)
  3593. {
  3594. pval **arg1;
  3595. int link, type;
  3596. hw_connection *ptr;
  3597. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
  3598. WRONG_PARAM_COUNT;
  3599. }
  3600. convert_to_long_ex(arg1);
  3601. link = (*arg1)->value.lval;
  3602. ptr = zend_list_find(link, &type);
  3603. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3604. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3605. RETURN_FALSE;
  3606. }
  3607. return_value->value.str.val = estrdup(ptr->username);
  3608. return_value->value.str.len = strlen(ptr->username);
  3609. return_value->type = IS_STRING;
  3610. }
  3611. /* }}} */
  3612. /* {{{ proto void hw_identify(int link, string username, string password)
  3613. Identifies at Hyperwave server */
  3614. PHP_FUNCTION(hw_identify)
  3615. {
  3616. pval **arg1, **arg2, **arg3;
  3617. int link, type;
  3618. char *name, *passwd, *userdata;
  3619. hw_connection *ptr;
  3620. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
  3621. WRONG_PARAM_COUNT;
  3622. }
  3623. convert_to_long_ex(arg1);
  3624. convert_to_string_ex(arg2);
  3625. convert_to_string_ex(arg3);
  3626. link = (*arg1)->value.lval;
  3627. name=(*arg2)->value.str.val;
  3628. passwd=(*arg3)->value.str.val;
  3629. ptr = zend_list_find(link, &type);
  3630. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3631. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3632. RETURN_FALSE;
  3633. }
  3634. set_swap(ptr->swap_on);
  3635. {
  3636. char *str;
  3637. if (0 != (ptr->lasterror = send_identify(ptr->socket, name, passwd, &userdata))) {
  3638. php_error(E_WARNING, "send_identify returned %d\n", ptr->lasterror);
  3639. if(ptr->username) free(ptr->username);
  3640. ptr->username = NULL;
  3641. RETURN_FALSE;
  3642. }
  3643. return_value->value.str.val = userdata;
  3644. return_value->value.str.len = strlen(userdata);
  3645. return_value->type = IS_STRING;
  3646. if(ptr->username) free(ptr->username);
  3647. str = userdata;
  3648. while((*str != 0) && (*str != ' '))
  3649. str++;
  3650. if(*str != '\0')
  3651. ptr->username = strdup(++str);
  3652. else
  3653. ptr->username = NULL;
  3654. }
  3655. }
  3656. /* }}} */
  3657. /* {{{ proto array hw_objrec2array(string objrec, [array format])
  3658. Returns object array of object record */
  3659. PHP_FUNCTION(hw_objrec2array)
  3660. {
  3661. zval **arg1, **arg2;
  3662. switch(ZEND_NUM_ARGS()) {
  3663. case 1:
  3664. if(zend_get_parameters_ex(1, &arg1) == FAILURE)
  3665. WRONG_PARAM_COUNT;
  3666. convert_to_string_ex(arg1);
  3667. make2_return_array_from_objrec(&return_value, (*arg1)->value.str.val, NULL);
  3668. break;
  3669. case 2:
  3670. if(zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE)
  3671. WRONG_PARAM_COUNT;
  3672. convert_to_array_ex(arg2);
  3673. convert_to_string_ex(arg1);
  3674. make2_return_array_from_objrec(&return_value, (*arg1)->value.str.val, *arg2);
  3675. break;
  3676. default:
  3677. WRONG_PARAM_COUNT;
  3678. }
  3679. }
  3680. /* }}} */
  3681. /* {{{ proto string hw_array2objrec(array objarr)
  3682. Returns object record of object array */
  3683. PHP_FUNCTION(hw_array2objrec)
  3684. {
  3685. pval **arg1;
  3686. char *objrec, *retobj;
  3687. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
  3688. WRONG_PARAM_COUNT;
  3689. }
  3690. convert_to_array_ex(arg1);
  3691. objrec = make_objrec_from_array((*arg1)->value.ht);
  3692. if(objrec) {
  3693. retobj = estrdup(objrec);
  3694. free(objrec);
  3695. RETURN_STRING(retobj, 0);
  3696. } else
  3697. RETURN_FALSE;
  3698. }
  3699. /* }}} */
  3700. /* {{{ proto array hw_incollections(int link, array objids, array collids, int para)
  3701. Returns object ids which are in collections */
  3702. PHP_FUNCTION(hw_incollections)
  3703. {
  3704. pval **arg1, **arg2, **arg3, **arg4;
  3705. int type, link, i;
  3706. hw_connection *ptr;
  3707. int cobjids, ccollids, *objectIDs, *collIDs, cretids, *retIDs, retcoll;
  3708. if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
  3709. WRONG_PARAM_COUNT;
  3710. }
  3711. convert_to_long_ex(arg1);
  3712. convert_to_array_ex(arg2);
  3713. convert_to_array_ex(arg3);
  3714. convert_to_long_ex(arg4);
  3715. link = (*arg1)->value.lval;
  3716. retcoll=(*arg4)->value.lval;
  3717. ptr = zend_list_find(link, &type);
  3718. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3719. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3720. RETURN_FALSE;
  3721. }
  3722. cobjids = zend_hash_num_elements((*arg2)->value.ht);
  3723. if(NULL == (objectIDs = make_ints_from_array((*arg2)->value.ht))) {
  3724. php_error(E_WARNING, "Could not create Int Array from Array\n");
  3725. RETURN_FALSE;
  3726. }
  3727. ccollids = zend_hash_num_elements((*arg3)->value.ht);
  3728. if(NULL == (collIDs = make_ints_from_array((*arg3)->value.ht))) {
  3729. php_error(E_WARNING, "Could not create Int Array from Array\n");
  3730. efree(objectIDs);
  3731. RETURN_FALSE;
  3732. }
  3733. set_swap(ptr->swap_on);
  3734. if (0 != (ptr->lasterror = send_incollections(ptr->socket, retcoll,
  3735. cobjids, objectIDs,
  3736. ccollids, collIDs,
  3737. &cretids, &retIDs))) {
  3738. if(objectIDs) efree(objectIDs);
  3739. if(collIDs) efree(collIDs);
  3740. RETURN_FALSE;
  3741. }
  3742. if(objectIDs) efree(objectIDs);
  3743. if(collIDs) efree(collIDs);
  3744. if (array_init(return_value) == FAILURE) {
  3745. efree(retIDs);
  3746. RETURN_FALSE;
  3747. }
  3748. for(i=0; i<cretids; i++)
  3749. add_index_long(return_value, i, retIDs[i]);
  3750. efree(retIDs);
  3751. }
  3752. /* }}} */
  3753. /* {{{ proto void hw_inscoll(int link, int parentid, array objarr)
  3754. Inserts collection */
  3755. PHP_FUNCTION(hw_inscoll)
  3756. {
  3757. pval **arg1, **arg2, **arg3;
  3758. char *objrec;
  3759. int id, newid, type, link;
  3760. hw_connection *ptr;
  3761. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
  3762. WRONG_PARAM_COUNT;
  3763. }
  3764. convert_to_long_ex(arg1);
  3765. convert_to_long_ex(arg2);
  3766. convert_to_array_ex(arg3);
  3767. link = (*arg1)->value.lval;
  3768. id=(*arg2)->value.lval;
  3769. ptr = zend_list_find(link, &type);
  3770. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3771. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3772. RETURN_FALSE;
  3773. }
  3774. if(NULL == (objrec = make_objrec_from_array((*arg3)->value.ht))) {
  3775. php_error(E_WARNING, "Could not create Object Record from Array\n");
  3776. RETURN_FALSE;
  3777. }
  3778. set_swap(ptr->swap_on);
  3779. if (0 != (ptr->lasterror = send_inscoll(ptr->socket, id, objrec, &newid))) {
  3780. if(objrec) free(objrec);
  3781. RETURN_FALSE;
  3782. }
  3783. if(objrec) free(objrec);
  3784. RETURN_LONG(newid);
  3785. }
  3786. /* }}} */
  3787. /* {{{ proto void hw_insdoc(int link, int parentid, string objrec [, string text])
  3788. Inserts document */
  3789. PHP_FUNCTION(hw_insdoc)
  3790. {
  3791. zval **argv[4];
  3792. char *objrec, *text;
  3793. int id, newid, type, link, argc;
  3794. hw_connection *ptr;
  3795. argc = ZEND_NUM_ARGS();
  3796. if((argc < 3) || (argc > 4))
  3797. WRONG_PARAM_COUNT;
  3798. if (zend_get_parameters_array_ex(argc, argv) == FAILURE)
  3799. WRONG_PARAM_COUNT;
  3800. convert_to_long_ex(argv[0]);
  3801. convert_to_long_ex(argv[1]);
  3802. convert_to_string_ex(argv[2]);
  3803. if(argc == 4) {
  3804. convert_to_string_ex(argv[3]);
  3805. text = (*argv[3])->value.str.val;
  3806. } else {
  3807. text = NULL;
  3808. }
  3809. link = (*argv[0])->value.lval;
  3810. id = (*argv[1])->value.lval;
  3811. ptr = zend_list_find(link, &type);
  3812. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3813. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3814. RETURN_FALSE;
  3815. }
  3816. set_swap(ptr->swap_on);
  3817. objrec = (*argv[2])->value.str.val;
  3818. if (0 != (ptr->lasterror = send_insdoc(ptr->socket, id, objrec, text, &newid))) {
  3819. RETURN_FALSE;
  3820. }
  3821. RETURN_LONG(newid);
  3822. }
  3823. /* }}} */
  3824. /* {{{ proto int hw_getsrcbydestobj(int link, int destid)
  3825. Returns object id of source docuent by destination anchor */
  3826. PHP_FUNCTION(hw_getsrcbydestobj)
  3827. {
  3828. pval **arg1, **arg2;
  3829. int link, type, id;
  3830. int count;
  3831. char **childObjRecs = NULL;
  3832. hw_connection *ptr;
  3833. if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
  3834. WRONG_PARAM_COUNT;
  3835. }
  3836. convert_to_long_ex(arg1);
  3837. convert_to_long_ex(arg2);
  3838. link=(*arg1)->value.lval;
  3839. id=(*arg2)->value.lval;
  3840. ptr = zend_list_find(link, &type);
  3841. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3842. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3843. RETURN_FALSE;
  3844. }
  3845. set_swap(ptr->swap_on);
  3846. if (0 != (ptr->lasterror = send_getsrcbydest(ptr->socket, id, &childObjRecs, &count))) {
  3847. php_error(E_WARNING, "send_command (getsrcbydest) returned %d\n", ptr->lasterror);
  3848. RETURN_FALSE;
  3849. }
  3850. /* create return value and free all memory */
  3851. if( 0 > make_return_objrec(&return_value, childObjRecs, count))
  3852. RETURN_FALSE;
  3853. }
  3854. /* }}} */
  3855. /* {{{ proto int hw_mapid(int link, int serverid, int destid)
  3856. Returns virtual object id of document on remote Hyperwave server */
  3857. PHP_FUNCTION(hw_mapid)
  3858. {
  3859. pval **arg1, **arg2, **arg3;
  3860. int link, type, servid, id, virtid;
  3861. hw_connection *ptr;
  3862. if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
  3863. WRONG_PARAM_COUNT;
  3864. }
  3865. convert_to_long_ex(arg1);
  3866. convert_to_long_ex(arg2);
  3867. convert_to_long_ex(arg3);
  3868. link=(*arg1)->value.lval;
  3869. servid=(*arg2)->value.lval;
  3870. id=(*arg3)->value.lval;
  3871. ptr = zend_list_find(link, &type);
  3872. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3873. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3874. RETURN_FALSE;
  3875. }
  3876. set_swap(ptr->swap_on);
  3877. if (0 != (ptr->lasterror = send_mapid(ptr->socket, servid, id, &virtid))) {
  3878. php_error(E_WARNING, "send_command (mapid) returned %d\n", ptr->lasterror);
  3879. RETURN_FALSE;
  3880. }
  3881. RETURN_LONG(virtid);
  3882. }
  3883. /* }}} */
  3884. /* {{{ proto string hw_getrellink(int link, int rootid, int sourceid, int destid)
  3885. Get link from source to dest relative to rootid */
  3886. PHP_FUNCTION(hw_getrellink)
  3887. {
  3888. pval **arg1, **arg2, **arg3, **arg4;
  3889. int link, type;
  3890. int rootid, destid, sourceid;
  3891. char *anchorstr;
  3892. hw_connection *ptr;
  3893. if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
  3894. WRONG_PARAM_COUNT;
  3895. }
  3896. convert_to_long_ex(arg1);
  3897. convert_to_long_ex(arg2);
  3898. convert_to_long_ex(arg3);
  3899. convert_to_long_ex(arg4);
  3900. link=(*arg1)->value.lval;
  3901. rootid=(*arg2)->value.lval;
  3902. sourceid=(*arg3)->value.lval;
  3903. destid=(*arg4)->value.lval;
  3904. ptr = zend_list_find(link, &type);
  3905. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  3906. php_error(E_WARNING, "Unable to find file identifier %d", link);
  3907. RETURN_FALSE;
  3908. }
  3909. set_swap(ptr->swap_on);
  3910. if (0 != (ptr->lasterror = getrellink(ptr->socket, rootid, sourceid, destid, &anchorstr))) {
  3911. php_error(E_WARNING, "command (getrellink) returned %d\n", ptr->lasterror);
  3912. RETURN_FALSE;
  3913. }
  3914. RETURN_STRING(anchorstr, 0);
  3915. }
  3916. /* }}} */
  3917. /* {{{ proto string hw_insertanchors(int hwdoc, array anchorecs, array dest [, array urlprefixes])
  3918. Inserts only anchors into text */
  3919. PHP_FUNCTION(hw_insertanchors)
  3920. {
  3921. pval **arg1, **arg2, **arg3, **arg4;
  3922. hw_document *hwdoc;
  3923. int type, docid, error, argc, count;
  3924. char *anchorstr;
  3925. char **anchorrecs;
  3926. char **dest;
  3927. char **urlprefix;
  3928. char *bodytag = NULL;
  3929. HashTable *arrht;
  3930. HashTable *prefixarray;
  3931. argc = ZEND_NUM_ARGS();
  3932. switch(argc)
  3933. {
  3934. case 3:
  3935. if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE)
  3936. WRONG_PARAM_COUNT;
  3937. break;
  3938. case 4:
  3939. if (zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE)
  3940. WRONG_PARAM_COUNT;
  3941. break;
  3942. default:
  3943. WRONG_PARAM_COUNT;
  3944. }
  3945. convert_to_long_ex(arg1);
  3946. convert_to_array_ex(arg2);
  3947. convert_to_array_ex(arg3);
  3948. docid=(*arg1)->value.lval;
  3949. hwdoc = zend_list_find(docid, &type);
  3950. if(!hwdoc || (type!=le_document)) {
  3951. php_error(E_WARNING, "Unable to find file identifier %d", docid);
  3952. RETURN_FALSE;
  3953. }
  3954. /* check for the array with urlprefixes */
  3955. if(argc == 4) {
  3956. int i;
  3957. convert_to_array_ex(arg4);
  3958. prefixarray =(*arg4)->value.ht;
  3959. if((prefixarray == NULL) || (zend_hash_num_elements(prefixarray) != 5)) {
  3960. php_error(E_WARNING, "You must provide 5 urlprefixes (you have provided %d)", zend_hash_num_elements(prefixarray));
  3961. RETURN_FALSE;
  3962. }
  3963. urlprefix = emalloc(5*sizeof(char *));
  3964. zend_hash_internal_pointer_reset(prefixarray);
  3965. for(i=0; i<5; i++) {
  3966. char *key;
  3967. zval *data, **dataptr;
  3968. ulong ind;
  3969. zend_hash_get_current_key(prefixarray, &key, &ind, 0);
  3970. zend_hash_get_current_data(prefixarray, (void *) &dataptr);
  3971. data = *dataptr;
  3972. if (data->type != IS_STRING) {
  3973. php_error(E_WARNING, "%s must be a String", key);
  3974. RETURN_FALSE;
  3975. } else if ( strcmp(key, "HW_DEFAULT_LINK") == 0 ) {
  3976. urlprefix[HW_DEFAULT_LINK] = data->value.str.val;
  3977. } else if ( strcmp(key, "HW_IMAGE_LINK") == 0 ) {
  3978. urlprefix[HW_IMAGE_LINK] = data->value.str.val;
  3979. } else if ( strcmp(key, "HW_BACKGROUND_LINK") == 0 ) {
  3980. urlprefix[HW_BACKGROUND_LINK] = data->value.str.val;
  3981. } else if ( strcmp(key, "HW_INTAG_LINK") == 0 ) {
  3982. urlprefix[HW_INTAG_LINK] = data->value.str.val;
  3983. } else if ( strcmp(key, "HW_APPLET_LINK") == 0 ) {
  3984. urlprefix[HW_APPLET_LINK] = data->value.str.val;
  3985. } else {
  3986. php_error(E_WARNING, "%s is not a valid urlprefix", key);
  3987. RETURN_FALSE;
  3988. }
  3989. zend_hash_move_forward(prefixarray);
  3990. }
  3991. } else {
  3992. urlprefix = NULL;
  3993. }
  3994. if(zend_hash_num_elements((*arg2)->value.ht) != zend_hash_num_elements((*arg3)->value.ht)) {
  3995. php_error(E_WARNING, "Unequal number of elments in arrays");
  3996. RETURN_FALSE;
  3997. }
  3998. /* Turn PHP-Array of strings into C-Array of strings */
  3999. arrht = (*arg2)->value.ht;
  4000. anchorrecs = make_strs_from_array(arrht);
  4001. arrht = (*arg3)->value.ht;
  4002. dest = make_strs_from_array(arrht);
  4003. if (0 != (error = send_insertanchors(&(hwdoc->data), &count, anchorrecs, dest, zend_hash_num_elements(arrht), urlprefix, &bodytag))) {
  4004. php_error(E_WARNING, "command (insertanchors) returned %d\n", error);
  4005. RETURN_FALSE;
  4006. }
  4007. /*fprintf(stderr, "in hw_insertanchors: %s\n", hwdoc->attributes); */
  4008. hwdoc->size = count;
  4009. if(hwdoc->bodytag) free (hwdoc->bodytag);
  4010. hwdoc->bodytag = bodytag;
  4011. RETURN_TRUE;
  4012. }
  4013. /* }}} */
  4014. PHP_MINFO_FUNCTION(hw)
  4015. {
  4016. php_info_print_table_start();
  4017. php_info_print_table_row(2, "Hyperwave Support", "enabled");
  4018. php_info_print_table_row(2, "HG-CSP Version", "7.17");
  4019. php_info_print_table_end();
  4020. DISPLAY_INI_ENTRIES();
  4021. }
  4022. /* {{{ proto void hw_connection_info(int link)
  4023. Prints information about the connection to Hyperwave server */
  4024. PHP_FUNCTION(hw_connection_info)
  4025. {
  4026. pval **arg1;
  4027. hw_connection *ptr;
  4028. int link, type;
  4029. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
  4030. WRONG_PARAM_COUNT;
  4031. }
  4032. convert_to_long_ex(arg1);
  4033. link=(*arg1)->value.lval;
  4034. ptr = zend_list_find(link, &type);
  4035. if(!ptr || (type!=le_socketp && type!=le_psocketp)) {
  4036. php_error(E_WARNING, "Unable to find file identifier %d", link);
  4037. RETURN_FALSE;
  4038. }
  4039. php_printf("Hyperwave Info:\nhost=%s,\nserver string=%s\nversion=%d\nswap=%d\n", ptr->hostname, ptr->server_string, ptr->version, ptr->swap_on);
  4040. }
  4041. /* }}} */
  4042. void print_msg(hg_msg *msg, char *str, int txt)
  4043. {
  4044. char *ptr;
  4045. int i;
  4046. fprintf(stdout, "\nprint_msg: >>%s<<\n", str);
  4047. fprintf(stdout, "print_msg: length = %d\n", msg->length);
  4048. fprintf(stdout, "print_msg: msgid = %d\n", msg->version_msgid);
  4049. fprintf(stdout, "print_msg: msg_type = %d\n", msg->msg_type);
  4050. if ( msg->length > HEADER_LENGTH ) {
  4051. ptr = msg->buf;
  4052. for ( i = 0; i < msg->length-HEADER_LENGTH; i++ ) {
  4053. if ( *ptr == '\n' )
  4054. fprintf(stdout, "%c", *ptr++);
  4055. else if ( iscntrl(*ptr) )
  4056. {fprintf(stdout, "."); ptr++;}
  4057. else
  4058. fprintf(stdout, "%c", *ptr++);
  4059. }
  4060. }
  4061. fprintf(stdout, "\n\n");
  4062. }
  4063. #endif
  4064. /*
  4065. * Local variables:
  4066. * tab-width: 4
  4067. * c-basic-offset: 4
  4068. * End:
  4069. * vim600: sw=4 ts=4 fdm=marker
  4070. * vim<600: sw=4 ts=4
  4071. */