[PHP-DEV] CVS update: php3/functions From: steinm (php-dev <email protected>)
Date: 04/30/99

Date: Friday April 30, 1999 @ 6:29
Author: steinm

Update of /repository/php3/functions
In directory php:/tmp/cvs-serv23613/functions

Modified Files:
        hg_comm.c hg_comm.h hw.c hw.h
Log Message:
- different parameter evaluation of hw_modifyobject() (see docs)
- updated documentation

Index: php3/functions/hg_comm.c
diff -u php3/functions/hg_comm.c:1.18 php3/functions/hg_comm.c:1.19
--- php3/functions/hg_comm.c:1.18 Fri Apr 16 08:19:01 1999
+++ php3/functions/hg_comm.c Fri Apr 30 06:29:17 1999
@@ -23,7 +23,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: hg_comm.c,v 1.18 1999/04/16 12:19:01 steinm Exp $ */
+/* $Id: hg_comm.c,v 1.19 1999/04/30 10:29:17 steinm Exp $ */
 
 /* #define HW_DEBUG */
 
@@ -1354,7 +1354,6 @@
         build_msg_header(&msg, length, msgid++, CHANGEOBJECT_MESSAGE);
 
         if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) {
-/* perror("send_command"); */
                 lowerror = LE_MALLOC;
                 return(-1);
         }
@@ -1391,6 +1390,28 @@
         return(uh_send_changeobject(sockfd));
 }
 
+int send_groupchangeobject(int sockfd, hw_objectID objectID, char *modification)
+{
+ hw_objectID *childIDs;
+ int count, i;
+
+ if(0 > send_changeobject(sockfd, objectID, modification)) /* {
+ fprintf(stderr, "Cannot change 0x%X\n", objectID);
+ } else
+ fprintf(stderr, "Changed 0x%X\n", objectID);
+*/
+ if(0 == send_children(sockfd, objectID, &childIDs, &count)) {
+/* fprintf(stderr, "Changing Children of 0x%X\n", objectID); */
+ for(i=0; i<count; i++)
+ if(0 > send_groupchangeobject(sockfd, childIDs[i], modification))
+/* fprintf(stderr, "Cannot change 0x%X\n", objectID) */;
+ if(childIDs)
+ efree(childIDs);
+ } /* else
+ fprintf(stderr, "No Children of 0x%X\n", objectID); */
+ return(0);
+}
+
 static int bh_send_getobject(int sockfd, hw_objectID objectID) {
         hg_msg msg;
         int length;
@@ -2368,7 +2389,6 @@
         build_msg_header(&msg, length, msgid++, CHILDREN_MESSAGE);
 
         if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) {
-/* perror("send_command"); */
                 lowerror = LE_MALLOC;
                 return(-1);
         }
Index: php3/functions/hg_comm.h
diff -u php3/functions/hg_comm.h:1.5 php3/functions/hg_comm.h:1.6
--- php3/functions/hg_comm.h:1.5 Tue Mar 30 01:23:42 1999
+++ php3/functions/hg_comm.h Fri Apr 30 06:29:17 1999
@@ -23,7 +23,7 @@
  */
 
 
-/* $Id: hg_comm.h,v 1.5 1999/03/30 06:23:42 steinm Exp $ */
+/* $Id: hg_comm.h,v 1.6 1999/04/30 10:29:17 steinm Exp $ */
 
 #ifndef _HG_COMM_H
 #define _HG_COMM_H
@@ -160,6 +160,7 @@
 
 extern int send_deleteobject(int sockfd, hw_objectID objectID);
 extern int send_changeobject(int sockfd, hw_objectID objectID, char *mod);
+extern int send_groupchangeobject(int sockfd, hw_objectID objectID, char *mod);
 extern int send_getobject(int sockfd, hw_objectID objectID, char **attributes);
 extern int send_getandlock(int sockfd, hw_objectID objectID, char **attributes);
 extern int send_unlock(int sockfd, hw_objectID objectID);
Index: php3/functions/hw.c
diff -u php3/functions/hw.c:1.29 php3/functions/hw.c:1.30
--- php3/functions/hw.c:1.29 Fri Apr 16 08:09:50 1999
+++ php3/functions/hw.c Fri Apr 30 06:29:17 1999
@@ -23,7 +23,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: hw.c,v 1.29 1999/04/16 12:09:50 steinm Exp $ */
+/* $Id: hw.c,v 1.30 1999/04/30 10:29:17 steinm Exp $ */
 #if COMPILE_DL
 #include "dl/phpdl.h"
 #endif
@@ -904,6 +904,12 @@
                 case NOTREMOVED:
                         sprintf(errstr, "Attribute not removed");
                         break;
+ case CHANGEBASEFLD:
+ sprintf(errstr, "Change of base-attribute");
+ break;
+ case FLDEXISTS:
+ sprintf(errstr, "Attribute exists");
+ break;
                 default:
                         sprintf(errstr, "Unknown error: %d", ptr->lasterror);
                 }
@@ -1272,7 +1278,7 @@
 /* }}} */
 
 /* {{{ proto void hw_changeobject(int link, int objid, array attributes)
- Changes attributes of an object */
+ Changes attributes of an object (obsolete) */
 #define BUFFERLEN 200
 void php3_hw_changeobject(INTERNAL_FUNCTION_PARAMETERS) {
         pval *arg1, *arg2, *arg3;
@@ -1355,28 +1361,39 @@
 #undef BUFFERLEN
 /* }}} */
 
-/* {{{ proto void hw_modifyobject(int link, int objid, array attributes)
- Changes attributes of an object */
+/* {{{ proto void hw_modifyobject(int link, int objid, array remattributes, array addattributes, [int mode])
+ Modifies attributes of an object */
 #define BUFFERLEN 200
 void php3_hw_modifyobject(INTERNAL_FUNCTION_PARAMETERS) {
- pval *arg1, *arg2, *arg3, *arg4;
- int link, id, type, i;
+ pval *argv[5];
+ int argc;
+ int link, id, type, i, mode;
         hw_connection *ptr;
         char *modification;
         HashTable *remobjarr, *addobjarr;
         TLS_VARS;
+
+ argc = ARG_COUNT(ht);
+ if((argc > 5) || (argc < 4))
+ WRONG_PARAM_COUNT;
 
- if (ARG_COUNT(ht) != 4 || getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
+ if (getParametersArray(ht, argc, argv) == FAILURE)
+ if(argc < 4) {
                 WRONG_PARAM_COUNT;
         }
- convert_to_long(arg1); /* Connection */
- convert_to_long(arg2); /* object ID */
- convert_to_array(arg3); /* Array with attributes to remove */
- convert_to_array(arg4); /* Array with attributes to add */
- link=arg1->value.lval;
- id=arg2->value.lval;
- remobjarr=arg3->value.ht;
- addobjarr=arg4->value.ht;
+ convert_to_long(argv[0]); /* Connection */
+ convert_to_long(argv[1]); /* object ID */
+ convert_to_array(argv[2]); /* Array with attributes to remove */
+ convert_to_array(argv[3]); /* Array with attributes to add */
+ if(argc == 5) {
+ convert_to_long(argv[4]);
+ mode = argv[4]->value.lval;
+ } else
+ mode = 0;
+ link=argv[0]->value.lval;
+ id=argv[1]->value.lval;
+ remobjarr=argv[2]->value.ht;
+ addobjarr=argv[3]->value.ht;
         ptr = php3_list_find(link,&type);
         if(!ptr || (type!=php3_hw_module.le_socketp && type!=php3_hw_module.le_psocketp)) {
                 php3_error(E_WARNING,"Unable to find file identifier %d",id);
@@ -1402,6 +1419,45 @@
                                                 noinsert = 0;
                                         }
                                         break;
+ case IS_ARRAY: {
+ int i, len, keylen, count;
+ char *strarr, *ptr, *ptr1;
+ count = _php3_hash_num_elements(data->value.ht);
+ if(count > 0) {
+ strarr = make_objrec_from_array(data->value.ht);
+ 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, "add ");
+ 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, "add ");
+ ptr1 += 4;
+ strcpy(ptr1, key);
+ ptr1 += keylen;
+ *ptr1++ = '=';
+ } else if(strarr[i] == '=')
+ ptr1[-1] = ':';
+ }
+ *ptr1++ = '\n';
+ *ptr1 = '\0';
+ strncpy(addattribute, ptr, BUFFERLEN);
+ noinsert = 0;
+ }
+ break;
+ }
                         }
                         if(!noinsert) {
                                 modification = fnInsStr(modification, 0, "\\");
@@ -1413,8 +1469,10 @@
         }
 
         if(remobjarr != NULL) {
+ int nr;
                 _php3_hash_internal_pointer_reset(remobjarr);
- for(i=0; i<_php3_hash_num_elements(remobjarr); i++) {
+ nr = _php3_hash_num_elements(remobjarr);
+ for(i=0; i<nr; i++) {
                         char *key, remattribute[BUFFERLEN];
                         pval *data;
                         int noinsert=1;
@@ -1427,8 +1485,50 @@
                                         if(strlen(data->value.str.val) > 0) {
                                                 snprintf(remattribute, BUFFERLEN, "rem %s=%s", key, data->value.str.val);
                                                 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 = _php3_hash_num_elements(data->value.ht);
+ if(count > 0) {
+ strarr = make_objrec_from_array(data->value.ht);
+ 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';
+ strncpy(remattribute, ptr, BUFFERLEN);
+ noinsert = 0;
                                         }
- break;
+ break;
+ }
                         }
                         if(!noinsert) {
                                 modification = fnInsStr(modification, 0, "\\");
@@ -1441,9 +1541,26 @@
 
         set_swap(ptr->swap_on);
         modification[strlen(modification)-1] = '\0';
-/* fprintf(stderr, "modifyobject: %s\n", modification); */
- if (0 != (ptr->lasterror = send_changeobject(ptr->socket, id, modification)))
- RETURN_FALSE;
+ fprintf(stderr, "modifyobject: %s\n", modification);
+ switch(mode) {
+ case 0:
+ if (0 != (ptr->lasterror = send_changeobject(ptr->socket, id, 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.
+*/
+ if (0 != (ptr->lasterror = send_groupchangeobject(ptr->socket, id, modification)))
+ RETURN_FALSE;
+ break;
+ default:
+ php3_error(E_WARNING,"hw_modifyobject: Mode must be 0 or 1");
+ }
         free(modification);
         RETURN_TRUE;
 }
Index: php3/functions/hw.h
diff -u php3/functions/hw.h:1.6 php3/functions/hw.h:1.7
--- php3/functions/hw.h:1.6 Thu Apr 8 11:08:13 1999
+++ php3/functions/hw.h Fri Apr 30 06:29:18 1999
@@ -23,7 +23,7 @@
  */
 
 
-/* $Id: hw.h,v 1.6 1999/04/08 15:08:13 steinm Exp $ */
+/* $Id: hw.h,v 1.7 1999/04/30 10:29:18 steinm Exp $ */
 
 #ifndef _HW_H
 #define _HW_H
@@ -65,6 +65,7 @@
 extern void php3_hw_cp(INTERNAL_FUNCTION_PARAMETERS);
 extern void php3_hw_deleteobject(INTERNAL_FUNCTION_PARAMETERS);
 extern void php3_hw_changeobject(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_hw_groupchangeobject(INTERNAL_FUNCTION_PARAMETERS);
 extern void php3_hw_modifyobject(INTERNAL_FUNCTION_PARAMETERS);
 extern void php3_hw_getparents(INTERNAL_FUNCTION_PARAMETERS);
 extern void php3_hw_getparentsobj(INTERNAL_FUNCTION_PARAMETERS);

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>