📄 hw.c
字号:
/* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Uwe Steinmann <Uwe.Steinmann@fernuni-hagen.de> | +----------------------------------------------------------------------+ *//* $Id: hw.c,v 1.111.2.7.4.2 2007/01/01 09:46:43 sebastian Exp $ */#include <stdlib.h>#include <errno.h>#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_globals.h"#include "ext/standard/php_standard.h"#include "ext/standard/head.h"#include "ext/standard/info.h"#include "fopen_wrappers.h"#include "SAPI.h"#ifdef PHP_WIN32#include <winsock.h>#endif#if HYPERWAVE#include "php_ini.h"#include "php_hyperwave.h"static int le_socketp, le_psocketp, le_document;/*hw_module php_hw_module;*/#define HW_ATTR_NONE 1#define HW_ATTR_LANG 2#define HW_ATTR_NR 3function_entry hw_functions[] = { PHP_FE(hw_connect, NULL) PHP_FE(hw_pconnect, NULL) PHP_FE(hw_close, NULL) PHP_FE(hw_root, NULL) PHP_FE(hw_info, NULL) PHP_FE(hw_connection_info, NULL) PHP_FE(hw_error, NULL) PHP_FE(hw_errormsg, NULL) PHP_FE(hw_getparentsobj, NULL) PHP_FE(hw_getparents, NULL) PHP_FE(hw_children, NULL) PHP_FE(hw_childrenobj, NULL) PHP_FE(hw_getchildcoll, NULL) PHP_FE(hw_getchildcollobj, NULL) PHP_FE(hw_getobject, NULL) PHP_FE(hw_getandlock, NULL) PHP_FE(hw_unlock, NULL) PHP_FE(hw_gettext, NULL) PHP_FE(hw_edittext, NULL) PHP_FE(hw_getcgi, NULL) PHP_FE(hw_getremote, NULL) PHP_FE(hw_getremotechildren, NULL) PHP_FE(hw_pipedocument, NULL) PHP_FE(hw_pipecgi, NULL) PHP_FE(hw_insertdocument, NULL) PHP_FE(hw_mv, NULL) PHP_FE(hw_cp, NULL) PHP_FE(hw_deleteobject, NULL) PHP_FE(hw_changeobject, NULL) PHP_FE(hw_modifyobject, NULL) PHP_FE(hw_docbyanchor, NULL) PHP_FE(hw_docbyanchorobj, NULL) PHP_FE(hw_getobjectbyquery, NULL) PHP_FE(hw_getobjectbyqueryobj, NULL) PHP_FE(hw_getobjectbyquerycoll, NULL) PHP_FE(hw_getobjectbyquerycollobj, NULL) PHP_FE(hw_getobjectbyftquery, NULL) PHP_FE(hw_getobjectbyftqueryobj, NULL) PHP_FE(hw_getobjectbyftquerycoll, NULL) PHP_FE(hw_getobjectbyftquerycollobj, NULL) PHP_FE(hw_getchilddoccoll, NULL) PHP_FE(hw_getchilddoccollobj, NULL) PHP_FE(hw_getanchors, NULL) PHP_FE(hw_getanchorsobj, NULL) PHP_FE(hw_getusername, NULL) PHP_FE(hw_setlinkroot, NULL) PHP_FE(hw_identify, NULL) PHP_FE(hw_free_document, NULL) PHP_FE(hw_new_document, NULL) PHP_FE(hw_new_document_from_file, NULL) PHP_FE(hw_output_document, NULL) PHP_FE(hw_document_size, NULL) PHP_FE(hw_document_attributes, NULL) PHP_FE(hw_document_bodytag, NULL) PHP_FE(hw_document_content, NULL) PHP_FE(hw_document_setcontent, NULL) PHP_FE(hw_objrec2array, NULL) PHP_FE(hw_array2objrec, NULL) PHP_FE(hw_incollections, NULL) PHP_FE(hw_inscoll, NULL) PHP_FE(hw_insertobject, NULL) PHP_FE(hw_insdoc, NULL) PHP_FE(hw_getsrcbydestobj, NULL) PHP_FE(hw_insertanchors, NULL) PHP_FE(hw_getrellink, NULL) PHP_FE(hw_who, NULL) PHP_FE(hw_stat, NULL) PHP_FE(hw_mapid, NULL) PHP_FE(hw_dummy, NULL) {NULL, NULL, NULL}};zend_module_entry hw_module_entry = { STANDARD_MODULE_HEADER, "hyperwave", hw_functions, PHP_MINIT(hw), PHP_MSHUTDOWN(hw), NULL, NULL, PHP_MINFO(hw), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES};/*#ifdef ZTSint hw_globals_id;#elsePHP_HW_API php_hw_globals hw_globals;#endif*/ZEND_DECLARE_MODULE_GLOBALS(hw)#ifdef COMPILE_DL_HYPERWAVEZEND_GET_MODULE(hw)#endifvoid print_msg(hg_msg *msg, char *str, int txt);void _close_hw_link(zend_rsrc_list_entry *rsrc TSRMLS_DC){ hw_connection *conn = (hw_connection *)rsrc->ptr; if(conn->hostname) free(conn->hostname); if(conn->username) free(conn->username); close(conn->socket); free(conn); HwSG(num_links)--;}void _close_hw_plink(zend_rsrc_list_entry *rsrc TSRMLS_DC){ hw_connection *conn = (hw_connection *)rsrc->ptr; if(conn->hostname) free(conn->hostname); if(conn->username) free(conn->username); close(conn->socket); free(conn); HwSG(num_links)--; HwSG(num_persistent)--;}void _free_hw_document(zend_rsrc_list_entry *rsrc TSRMLS_DC){ hw_document *doc = (hw_document *)rsrc->ptr; if(doc->data) free(doc->data); if(doc->attributes) free(doc->attributes); if(doc->bodytag) free(doc->bodytag); free(doc);}static void php_hw_init_globals(zend_hw_globals *hw_globals){ hw_globals->num_persistent = 0;}static PHP_INI_MH(OnHyperwavePort){ if (new_value==NULL) { HwSG(default_port) = HG_SERVER_PORT; } else { HwSG(default_port) = atoi(new_value); } return SUCCESS;}PHP_INI_BEGIN() STD_PHP_INI_ENTRY("hyperwave.allow_persistent", "0", PHP_INI_SYSTEM, OnUpdateInt, allow_persistent, zend_hw_globals, hw_globals) PHP_INI_ENTRY("hyperwave.default_port", "418", PHP_INI_ALL, OnHyperwavePort)PHP_INI_END()PHP_MINIT_FUNCTION(hw){ ZEND_INIT_MODULE_GLOBALS(hw, php_hw_init_globals, NULL); REGISTER_INI_ENTRIES(); le_socketp = zend_register_list_destructors_ex(_close_hw_link, NULL, "hyperwave link", module_number); le_psocketp = zend_register_list_destructors_ex(NULL, _close_hw_plink, "hyperwave link persistent", module_number); le_document = zend_register_list_destructors_ex(_free_hw_document, NULL, "hyperwave document", module_number); Z_TYPE(hw_module_entry) = type; REGISTER_LONG_CONSTANT("HW_ATTR_LANG", HW_ATTR_LANG, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("HW_ATTR_NR", HW_ATTR_NR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("HW_ATTR_NONE", HW_ATTR_NONE, CONST_CS | CONST_PERSISTENT); return SUCCESS;}PHP_MSHUTDOWN_FUNCTION(hw){ UNREGISTER_INI_ENTRIES(); return SUCCESS;}/* {{{ make_return_objrec * creates an array in return value and frees all memory * Also adds as an assoc. array at the end of the return array with * statistics. */int make_return_objrec(pval **return_value, char **objrecs, int count){ zval *stat_arr; int i; int hidden, collhead, fullcollhead, total; int collheadnr, fullcollheadnr; if (array_init(*return_value) == FAILURE) { /* Ups, failed! Let's at least free the memory */ for(i=0; i<count; i++) efree(objrecs[i]); efree(objrecs); return -1; } hidden = collhead = fullcollhead = total = 0; collheadnr = fullcollheadnr = -1; for(i=0; i<count; i++) { /* Fill the array with entries. No need to free objrecs[i], since * it is not duplicated in add_next_index_string(). */ if(NULL != objrecs[i]) { if(0 == fnAttributeCompare(objrecs[i], "PresentationHints", "Hidden")) hidden++; if(0 == fnAttributeCompare(objrecs[i], "PresentationHints", "CollectionHead")) { collhead++; collheadnr = total; } if(0 == fnAttributeCompare(objrecs[i], "PresentationHints", "FullCollectionHead")) { fullcollhead++; fullcollheadnr = total; } total++; add_next_index_string(*return_value, objrecs[i], 0); } } efree(objrecs); /* Array for statistics */ MAKE_STD_ZVAL(stat_arr); if (array_init(stat_arr) == FAILURE) { return -1; } add_assoc_long(stat_arr, "Hidden", hidden); add_assoc_long(stat_arr, "CollectionHead", collhead); add_assoc_long(stat_arr, "FullCollectionHead", fullcollhead); add_assoc_long(stat_arr, "Total", total); add_assoc_long(stat_arr, "CollectionHeadNr", collheadnr); add_assoc_long(stat_arr, "FullCollectionHeadNr", fullcollheadnr); /* Add the stat array */ zend_hash_next_index_insert(Z_ARRVAL_PP(return_value), &stat_arr, sizeof(zval), NULL); return 0;}/* }}} *//* {{{ make2_return_array_from_objrec** creates an array return value from object record*/int make2_return_array_from_objrec(pval **return_value, char *objrec, zval *sarr) { char *attrname, *str, *temp, language[3]; zval *spec_arr; char *strtok_buf = NULL; /* Create an array with an entry containing specs for each attribute and fill in the specs for Title, Description, Keyword, Group. If an array is passed as the last argument use it instead. */ if(NULL != sarr) { spec_arr = sarr; } else { MAKE_STD_ZVAL(spec_arr); array_init(spec_arr); add_assoc_long(spec_arr, "Title", HW_ATTR_LANG); add_assoc_long(spec_arr, "Description", HW_ATTR_LANG); add_assoc_long(spec_arr, "Keyword", HW_ATTR_LANG); add_assoc_long(spec_arr, "Group", HW_ATTR_NONE); add_assoc_long(spec_arr, "HtmlAttr", HW_ATTR_NONE); add_assoc_long(spec_arr, "Parent", HW_ATTR_NONE); add_assoc_long(spec_arr, "SQLStmt", HW_ATTR_NR); } if (array_init(*return_value) == FAILURE) { Z_TYPE_PP(return_value) = IS_STRING; Z_STRVAL_PP(return_value) = empty_string; Z_STRLEN_PP(return_value) = 0; return -1; } /* Loop through the attributes of object record and check if the attribute has a specification. If it has the value is added to array in spec record. If not it is added straight to the return_value array. */ temp = estrdup(objrec); attrname = php_strtok_r(temp, "\n", &strtok_buf); while(attrname != NULL) { zval *data, **dataptr; long spec; str = attrname; /* Check if a specification is available. If it isn't available then insert the attribute as a string into the return array */ while((*str != '=') && (*str != '\0')) str++; *str = '\0'; str++; if(zend_hash_find(Z_ARRVAL_P(spec_arr), attrname, strlen(attrname)+1, (void **) &dataptr) == FAILURE) { add_assoc_string(*return_value, attrname, str, 1); } else { zval *newarr; data = *dataptr; spec = Z_LVAL_P(data); if(zend_hash_find(Z_ARRVAL_PP(return_value), attrname, strlen(attrname)+1, (void **) &dataptr) == FAILURE) { MAKE_STD_ZVAL(newarr); array_init(newarr); zend_hash_add(Z_ARRVAL_PP(return_value), attrname, strlen(attrname)+1, &newarr, sizeof(zval *), NULL); } else { newarr = *dataptr; } switch(spec) { case HW_ATTR_LANG: if(str[2] == ':') { str[2] = '\0'; strcpy(language, str); str += 3; } else strcpy(language, "xx"); add_assoc_string(newarr, language, str, 1); break; case HW_ATTR_NR: if(str[1] == ':') { str[1] = '\0'; strcpy(language, str); str += 2; } else strcpy(language, "x"); add_assoc_string(newarr, language, str, 1); break; case HW_ATTR_NONE: add_next_index_string(newarr, str, 1); break; } } attrname = php_strtok_r(NULL, "\n", &strtok_buf); } if(NULL == sarr){/* spec_arr->refcount--; zend_hash_destroy(Z_ARRVAL_P(spec_arr)); efree(Z_ARRVAL_P(spec_arr));*/ zval_dtor(spec_arr); efree(spec_arr); } efree(temp); return(0);}/* }}} *//* {{{ make_return_array_from_objrec */int make_return_array_from_objrec(pval **return_value, char *objrec) { char *attrname, *str, *temp, language[3], *title; int iTitle, iDesc, iKeyword, iGroup; zval *title_arr; zval *desc_arr; zval *keyword_arr; zval *group_arr; int hasTitle = 0; int hasDescription = 0; int hasKeyword = 0; int hasGroup = 0; char *strtok_buf; MAKE_STD_ZVAL(title_arr); MAKE_STD_ZVAL(desc_arr); MAKE_STD_ZVAL(keyword_arr); MAKE_STD_ZVAL(group_arr); if (array_init(*return_value) == FAILURE) { Z_TYPE_PP(return_value) = IS_STRING; Z_STRVAL_PP(return_value) = empty_string; Z_STRLEN_PP(return_value) = 0; return -1; } /* Fill Array of titles, descriptions and keywords */ temp = estrdup(objrec); attrname = php_strtok_r(temp, "\n", &strtok_buf); while(attrname != NULL) { str = attrname; iTitle = 0; iDesc = 0; iKeyword = 0; iGroup = 0; if(0 == strncmp(attrname, "Title=", 6)) { if ((hasTitle == 0) && (array_init(title_arr) == FAILURE)) { return -1; } hasTitle = 1; str += 6; iTitle = 1; } else if(0 == strncmp(attrname, "Description=", 12)) { if ((hasDescription == 0) && (array_init(desc_arr) == FAILURE)) { return -1; } hasDescription = 1; str += 12; iDesc = 1; } else if(0 == strncmp(attrname, "Keyword=", 8)) { if ((hasKeyword == 0) && (array_init(keyword_arr) == FAILURE)) { return -1; } hasKeyword = 1; str += 8; iKeyword = 1; } else if(0 == strncmp(attrname, "Group=", 6)) { if ((hasGroup == 0) && (array_init(group_arr) == FAILURE)) { return -1; } hasGroup = 1; str += 6; iGroup = 1; } if(iTitle || iDesc || iKeyword) { /* Poor error check if end of string */ if(str[2] == ':') { str[2] = '\0'; strcpy(language, str); str += 3; } else strcpy(language, "xx"); title = str; if(iTitle) add_assoc_string(title_arr, language, title, 1); else if(iDesc) add_assoc_string(desc_arr, language, title, 1); else if(iKeyword) add_assoc_string(keyword_arr, language, title, 1); } else if(iGroup) { if(iGroup) add_next_index_string(group_arr, str, 1); } attrname = php_strtok_r(NULL, "\n", &strtok_buf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -