📄 hw.c
字号:
modification = fnInsStr(modification, 0, "\\"); modification = fnInsStr(modification, 0, addattribute); } zend_hash_move_forward(addobjarr); } } if(remobjarr != NULL) { int nr; zend_hash_internal_pointer_reset(remobjarr); nr = zend_hash_num_elements(remobjarr); for(i=0; i<nr; i++) { char *key, remattribute[BUFFERLEN]; zval *data, **dataptr; int noinsert=1; ulong ind; zend_hash_get_current_key(remobjarr, &key, &ind, 0); zend_hash_get_current_data(remobjarr, (void *) &dataptr); data = *dataptr; switch(Z_TYPE_P(data)) { case IS_STRING: if(strlen(Z_STRVAL_P(data)) > 0) { snprintf(remattribute, BUFFERLEN, "rem %s=%s", key, Z_STRVAL_P(data)); noinsert = 0; } else { snprintf(remattribute, BUFFERLEN, "rem %s", key); noinsert = 0; } break; case IS_ARRAY: { int i, len, keylen, count; char *strarr, *ptr, *ptr1; count = zend_hash_num_elements(Z_ARRVAL_P(data)); if(count > 0) { strarr = make_objrec_from_array(Z_ARRVAL_P(data), ':'); len = strlen(strarr) - 1; keylen = strlen(key); if(NULL == (ptr = malloc(len + 1 + count*(keylen+1+4)))) { if(modification) free(modification); RETURN_FALSE; } ptr1 = ptr; *ptr1 = '\0'; strcpy(ptr1, "rem "); ptr1 += 4; strcpy(ptr1, key); ptr1 += keylen; *ptr1++ = '='; for(i=0; i<len; i++) { *ptr1++ = strarr[i]; if(strarr[i] == '\n') { ptr1[-1] = '\\'; strcpy(ptr1, "rem "); ptr1 += 4; strcpy(ptr1, key); ptr1 += keylen; *ptr1++ = '='; } /* else if(strarr[i] == '=') ptr1[-1] = ':'; */ } *ptr1++ = '\n'; *ptr1 = '\0'; strlcpy(remattribute, ptr, sizeof(remattribute)); noinsert = 0; } break; } } if(!noinsert) { modification = fnInsStr(modification, 0, "\\"); modification = fnInsStr(modification, 0, remattribute); } zend_hash_move_forward(remobjarr); } } set_swap(ptr->swap_on); modification[strlen(modification)-1] = '\0'; if(strlen(modification) == 0) { ptr->lasterror = 0; free(modification); RETURN_TRUE; }/* fprintf(stderr, "modifyobject: %s\n", modification); */ switch(mode) { case 0: if (0 == (ptr->lasterror = send_lock(ptr->socket, id))) { if (0 == (ptr->lasterror = send_changeobject(ptr->socket, id, modification))) { if (0 != (ptr->lasterror = send_unlock(ptr->socket, id))) { php_error(E_WARNING, "%s(): Aiii, Changeobject failed and couldn't unlock object (id = 0x%X)", get_active_function_name(TSRMLS_C), id); free(modification); RETURN_FALSE; } free(modification); RETURN_FALSE; } else { send_unlock(ptr->socket, id); free(modification); RETURN_FALSE; } } else { php_error(E_WARNING, "%s(): Could not lock object (id = 0x%X)", get_active_function_name(TSRMLS_C), id); free(modification); RETURN_FALSE; } break; case 1:/* WARNING: send_groupchangobject() only works right, if each attribute can be modified. Doing a changeobject recursively often tries to modify objects which cannot be modified e.g. because an attribute cannot be removed. In such a case no further modification on that object is done. Doing a 'rem Rights\add Rights=R:a' will fail completely if the attribute Rights is not there already. The object locking is done in send_groupchangeobject();*/ if (0 != (ptr->lasterror = send_groupchangeobject(ptr->socket, id, modification))) { free(modification); RETURN_FALSE; } break; default: php_error(E_WARNING, "%s(): Mode must be 0 or 1 (recursive)", get_active_function_name(TSRMLS_C)); } free(modification); RETURN_TRUE;}#undef BUFFERLEN/* }}} *//* {{{ php_hw_mvcp */void php_hw_mvcp(INTERNAL_FUNCTION_PARAMETERS, int mvcp) { pval *arg1, *arg2, *arg3, *arg4; int link, type, dest=0, from=0, count; HashTable *src_arr; hw_connection *ptr; int collIDcount, docIDcount, i, *docIDs, *collIDs; switch(mvcp) { case MOVE: /* Move also has fromID */ if (ZEND_NUM_ARGS() != 4 || getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE) WRONG_PARAM_COUNT; break; case COPY: if (ZEND_NUM_ARGS() != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) WRONG_PARAM_COUNT; break; } convert_to_long(arg1); convert_to_array(arg2); convert_to_long(arg3); link=Z_LVAL_P(arg1); src_arr=Z_ARRVAL_P(arg2); switch(mvcp) { case MOVE: /* Move also has fromID, which is arg3 --> arg4 becomes destID */ convert_to_long(arg4); from=Z_LVAL_P(arg3); dest=Z_LVAL_P(arg4); break; case COPY: /* No fromID for Copy needed --> arg3 is destID */ dest=Z_LVAL_P(arg3); from = 0; break; } ptr = zend_list_find(link, &type); if(!ptr || (type!=le_socketp && type!=le_psocketp)) { php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), link); RETURN_FALSE; } set_swap(ptr->swap_on); count = zend_hash_num_elements(src_arr); if(NULL == (collIDs = emalloc(count * sizeof(int)))) { RETURN_FALSE; } if(NULL == (docIDs = emalloc(count * sizeof(int)))) { efree(collIDs); RETURN_FALSE; } collIDcount = docIDcount = 0; zend_hash_internal_pointer_reset(src_arr); for(i=0; i<count; i++) { char *objrec; zval *keydata, **keydataptr; zend_hash_get_current_data(src_arr, (void **) &keydataptr); keydata = *keydataptr; if(Z_TYPE_P(keydata) == IS_LONG) { if(0 != (ptr->lasterror = send_getobject(ptr->socket, Z_LVAL_P(keydata), &objrec))) { efree(collIDs); efree(docIDs); RETURN_FALSE; } if(0 == fnAttributeCompare(objrec, "DocumentType", "collection")) collIDs[collIDcount++] = Z_LVAL_P(keydata); else docIDs[docIDcount++] = Z_LVAL_P(keydata); efree(objrec); } zend_hash_move_forward(src_arr); } if (0 != (ptr->lasterror = send_mvcpdocscoll(ptr->socket, docIDs, docIDcount, from, dest, mvcp))) { efree(collIDs); efree(docIDs); RETURN_FALSE; } if (0 != (ptr->lasterror = send_mvcpcollscoll(ptr->socket, collIDs, collIDcount, from, dest, mvcp))) { efree(collIDs); efree(docIDs); RETURN_FALSE; } efree(collIDs); efree(docIDs); RETURN_LONG(docIDcount + collIDcount);}/* }}} *//* {{{ proto void hw_mv(int link, array objrec, int from, int dest) Moves object */PHP_FUNCTION(hw_mv){ php_hw_mvcp(INTERNAL_FUNCTION_PARAM_PASSTHRU, MOVE);}/* }}} *//* {{{ proto void hw_cp(int link, array objrec, int dest) Copies object */PHP_FUNCTION(hw_cp){ php_hw_mvcp(INTERNAL_FUNCTION_PARAM_PASSTHRU, COPY);}/* }}} *//* {{{ proto hwdoc hw_gettext(int link, int objid [, int rootid]) Returns text document. Links are relative to rootid if given */PHP_FUNCTION(hw_gettext){ pval *argv[3]; int argc, link, id, type, mode; int rootid = 0; char *urlprefix; hw_document *doc; hw_connection *ptr; argc = ZEND_NUM_ARGS(); if((argc > 3) || (argc < 2)) WRONG_PARAM_COUNT; if (getParametersArray(ht, argc, argv) == FAILURE) RETURN_FALSE; convert_to_long(argv[0]); convert_to_long(argv[1]); mode = 0; urlprefix = NULL; if(argc == 3) { switch(Z_TYPE_P(argv[2])) { case IS_LONG: convert_to_long(argv[2]); rootid = Z_LVAL_P(argv[2]); mode = 1; break; case IS_STRING: convert_to_string(argv[2]); urlprefix = Z_STRVAL_P(argv[2]); break; } } link=Z_LVAL_P(argv[0]); id=Z_LVAL_P(argv[1]); ptr = zend_list_find(link, &type); if(!ptr || (type!=le_socketp && type!=le_psocketp)) { php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id); RETURN_FALSE; } set_swap(ptr->swap_on); { char *object = NULL; char *attributes = NULL; char *bodytag = NULL; int count; /* !!!! memory for object and attributes is allocated with malloc !!!! */ if (0 != (ptr->lasterror = send_gettext(ptr->socket, id, mode, rootid, &attributes, &bodytag, &object, &count, urlprefix))) RETURN_FALSE; doc = malloc(sizeof(hw_document)); doc->data = object; doc->attributes = attributes; doc->bodytag = bodytag; doc->size = count; Z_LVAL_P(return_value) = zend_list_insert(doc, le_document); Z_TYPE_P(return_value) = IS_LONG; }}/* }}} *//* {{{ proto void hw_edittext(int link, hwdoc doc) Modifies text document */PHP_FUNCTION(hw_edittext){ pval *arg1, *arg2; int link, doc, type; hw_connection *ptr; hw_document *docptr; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); convert_to_long(arg2); link=Z_LVAL_P(arg1); ptr = zend_list_find(link, &type); if(!ptr || (type!=le_socketp && type!=le_psocketp)) { php_error(E_WARNING, "%s(): Unable to find socket identifier %d", get_active_function_name(TSRMLS_C), link); RETURN_FALSE; } doc=Z_LVAL_P(arg2); docptr = zend_list_find(doc, &type); if(!docptr || (type!=le_document)) { php_error(E_WARNING, "%s(): Unable to find document identifier %d", get_active_function_name(TSRMLS_C), doc); RETURN_FALSE; } set_swap(ptr->swap_on); { if (0 != (ptr->lasterror = send_edittext(ptr->socket, docptr->attributes, docptr->data))) { RETURN_FALSE; } } RETURN_TRUE;}/* }}} *//* {{{ proto hwdoc hw_getcgi(int link, int objid) Returns the output of a CGI script */#define BUFFERLEN 1000/* FIX ME: The buffer cgi_env_str should be allocated dynamically */PHP_FUNCTION(hw_getcgi){ pval *arg1, *arg2; int link, id, type; hw_document *doc; hw_connection *ptr; char cgi_env_str[BUFFERLEN]; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); convert_to_long(arg2); link=Z_LVAL_P(arg1); id=Z_LVAL_P(arg2); ptr = zend_list_find(link, &type); if(!ptr || (type!=le_socketp && type!=le_psocketp)) { php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id); RETURN_FALSE; } set_swap(ptr->swap_on); { char *object = NULL; char *attributes = NULL; int count; /* Here is another undocument function of Hyperwave. If you call a cgi script with getcgi-message, you will have to provide the complete cgi enviroment, since it is only known to the webserver (or wavemaster). This is done by extending the object record with the following incomplete string. It should contain any enviroment variable a cgi script requires. */#ifdef PHP_WIN32 snprintf(cgi_env_str, BUFFERLEN, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s", getenv("REQUEST_METHOD"), getenv("PATH_INFO"), getenv("QUERY_STRING"));#else snprintf(cgi_env_str, BUFFERLEN, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s", SG(request_info).request_method, SG(request_info).request_uri, SG(request_info).query_string);#endif /* !!!! memory for object and attributes is allocated with malloc !!!! */ if (0 != (ptr->lasterror = send_getcgi(ptr->socket, id, cgi_env_str, &attributes, &object, &count))) RETURN_FALSE; doc = malloc(sizeof(hw_document)); doc->data = object; doc->attributes = attributes; doc->bodytag = NULL; doc->size = count; Z_LVAL_P(return_value) = zend_list_insert(doc, le_document); Z_TYPE_P(return_value) = IS_LONG; }}#undef BUFFERLEN/* }}} *//* {{{ proto int hw_getremote(int link, int objid) Returns the content of a remote document */PHP_FUNCTION(hw_getremote){ pval *arg1, *arg2; int link, id, type; hw_document *doc; hw_connection *ptr; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); convert_to_long(arg2); link=Z_LVAL_P(arg1); id=Z_LVAL_P(arg2); ptr = zend_list_find(link, &type); if(!ptr || (type!=le_socketp && type!=le_psocketp)) { php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id); RETURN_FALSE; } set_swap(ptr->swap_on); { char *object = NULL; char *attributes = NULL; int count; /* !!!! memory for object and attributes is allocated with malloc !!!! */ if (0 != (ptr->lasterror = send_getremote(ptr->socket, id, &attributes, &object, &count))) RETURN_FALSE; doc = malloc(sizeof(hw_document)); doc->data = object; doc->attributes = attributes; doc->bodytag = NULL; doc->size = count; Z_LVAL_P(return_value) = zend_list_insert(doc, le_document); Z_TYPE_P(return_value) = IS_LONG; }}/* }}} *//* {{{ proto [array|int] hw_getremotechildren(int link, string objrec) Returns the remote document or an array of object records */PHP_FUNCTION(hw_getremotechildren){ pval *arg1, *arg2; int link, type, i; hw_connection *ptr; char *objrec; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); convert_to_string(arg2); link=Z_LVAL_P(arg1); objrec=Z_STRVAL_P(arg2); ptr = zend_list_find(link, &type); if(!ptr || (type!=le_socketp && type!=le_psocketp)) { php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), link); RETURN_FALSE; } set_swap(ptr->swap_on); { int count, *offsets; char *remainder, *ptr1; if (0 != (ptr->lasterror = send_getremotechildren(ptr->socket, objrec, &remainder, &offsets, &count))) RETURN_FALSE;/*for(i=0;i<count;i++) php_printf("offset[%d] = %d--\n", i, offsets[i]);php_printf("count = %d, remainder = <HR>%s---<HR>", count, remainder);*/ /* T
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -