cvs: php4 /ext/hyperwave hg_comm.c hg_comm.h hw.c

From: Date: Tue, 12 Dec 2000 12:28:25 +0000
Subject: cvs: php4 /ext/hyperwave hg_comm.c hg_comm.h hw.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-3092@lists.php.net to get a copy of this message
steinm Tue Dec 12 04:28:25 2000 EDT Modified files: /php4/ext/hyperwave hg_comm.c hg_comm.h hw.c Log: - new function hw_insertanchors(). It takes a document, a list of anchors and its destination and inserts the anchors into the text. Index: php4/ext/hyperwave/hg_comm.c diff -u php4/ext/hyperwave/hg_comm.c:1.34 php4/ext/hyperwave/hg_comm.c:1.35 --- php4/ext/hyperwave/hg_comm.c:1.34 Thu Nov 23 06:44:09 2000 +++ php4/ext/hyperwave/hg_comm.c Tue Dec 12 04:28:25 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.c,v 1.34 2000/11/23 14:44:09 steinm Exp $ */ +/* $Id: hg_comm.c,v 1.35 2000/12/12 12:28:25 steinm Exp $ */ /* #define HW_DEBUG */ @@ -364,7 +364,8 @@ if(NULL != anchors[i]) { object = anchors[i]; docofanchorptr = docofanchorrec[i]; - reldestptr = reldestrec[i]; + if(reldestrec) /* FIXME reldestrec may only be NULL if anchormode != 0 */ + reldestptr = reldestrec[i]; /* Determine Position. Doesn't matter if Src or Dest The Position field should always be there. Though there @@ -587,7 +588,8 @@ efree(anchors[i]); if(docofanchorrec[i]) efree(docofanchorrec[i]); - if(reldestrec[i]) efree(reldestrec[i]); + if(reldestrec) + if(reldestrec[i]) efree(reldestrec[i]); } } } @@ -2164,6 +2166,42 @@ if(documenttype) efree(documenttype); return(0); +} + +send_insertanchors(char **text, int *count, char **anchors, char **destrec, int ancount, char **urlprefix, char **bodytag) { + char **reldestrec = NULL; + int mode = 0; + hw_objectID objectID = 0; +#ifdef newlist + zend_llist *pAnchorList = NULL; +#else + DLIST *pAnchorList = NULL; +#endif + pAnchorList = fnCreateAnchorList(objectID, anchors, destrec, reldestrec, ancount, mode); + + /* Free only the array, the objrecs has been freed in fnCreateAnchorList() */ + if(anchors) efree(anchors); + if(destrec) efree(destrec); + if(reldestrec) efree(reldestrec); + + if(pAnchorList != NULL) { + char *newtext; + char *body; + + newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, urlprefix); + +#ifdef newlist + zend_llist_destroy(pAnchorList); + efree(pAnchorList); +#else + dlst_kill(pAnchorList, fnDeleteAnchor); +#endif + *bodytag = strdup(body); + efree(body); + *text = newtext; + *count = strlen(newtext); + } + return 0; } int send_edittext(int sockfd, char *objattr, char *text) Index: php4/ext/hyperwave/hg_comm.h diff -u php4/ext/hyperwave/hg_comm.h:1.11 php4/ext/hyperwave/hg_comm.h:1.12 --- php4/ext/hyperwave/hg_comm.h:1.11 Thu Nov 23 06:44:09 2000 +++ php4/ext/hyperwave/hg_comm.h Tue Dec 12 04:28:25 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.h,v 1.11 2000/11/23 14:44:09 steinm Exp $ */ +/* $Id: hg_comm.h,v 1.12 2000/12/12 12:28:25 steinm Exp $ */ #ifndef HG_COMM_H #define HG_COMM_H @@ -225,6 +225,7 @@ extern int send_getsrcbydest(int sockfd, hw_objectID objid, char ***childrec, int *count); extern int send_mapid(int sockfd, int servid, hw_objectID id, int *virtid); extern int send_dummy(int sockfd, hw_objectID objectID, int msgid, char **attributes); +extern send_insertanchors(char **text, int *count, char **anchors, char **destrec, int ancount, char **urlprefix, char **bodytag); extern char *get_hw_info(hw_connection *conn); #define send_mvcpdocscoll(sockfd,objectIDs,count,from,dest,mvcp) \ Index: php4/ext/hyperwave/hw.c diff -u php4/ext/hyperwave/hw.c:1.70 php4/ext/hyperwave/hw.c:1.71 --- php4/ext/hyperwave/hw.c:1.70 Mon Dec 4 08:34:05 2000 +++ php4/ext/hyperwave/hw.c Tue Dec 12 04:28:25 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hw.c,v 1.70 2000/12/04 16:34:05 steinm Exp $ */ +/* $Id: hw.c,v 1.71 2000/12/12 12:28:25 steinm Exp $ */ #include <stdlib.h> #include <errno.h> @@ -641,18 +641,22 @@ static char **make_strs_from_array(HashTable *arrht) { char **carr = NULL; + char **ptr; zval *data, **dataptr; zend_hash_internal_pointer_reset(arrht); if(NULL == (carr = emalloc(zend_hash_num_elements(arrht) * sizeof(char *)))) - return(NULL); + return(NULL); + ptr = carr; /* Iterate through hash */ while(zend_hash_get_current_data(arrht, (void **) &dataptr) == SUCCESS) { data = *dataptr; switch(data->type) { case IS_STRING: - *carr++ = estrdup(data->value.str.val); + *ptr = estrdup(data->value.str.val); +fprintf(stderr, "carr[] = %s\n", *ptr); + ptr++; break; } @@ -2306,11 +2310,11 @@ { case 2: if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) - RETURN_FALSE; + WRONG_PARAM_COUNT; break; case 3: if (getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) - RETURN_FALSE; + WRONG_PARAM_COUNT; break; default: WRONG_PARAM_COUNT; @@ -4084,20 +4088,35 @@ } /* }}} */ -/* {{{ proto string hw_insertanchors(int hwdoc, array anchorecs, array dest) +/* {{{ proto string hw_insertanchors(int hwdoc, array anchorecs, array dest [, array urlprefixes]) Inserts only anchors into text */ PHP_FUNCTION(hw_insertanchors) { pval **arg1, **arg2, **arg3, **arg4; hw_document *hwdoc; - int type, docid, error; + int type, docid, error, argc, count; char *anchorstr; char **anchorrecs; char **dest; + char **urlprefix; + char *bodytag = NULL; HashTable *arrht; + HashTable *prefixarray; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) { + argc = ZEND_NUM_ARGS(); + switch(argc) + { + case 3: + if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) + WRONG_PARAM_COUNT; + break; + case 4: + if (zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) + WRONG_PARAM_COUNT; + break; + default: WRONG_PARAM_COUNT; } + convert_to_long_ex(arg1); convert_to_array_ex(arg2); convert_to_array_ex(arg3); @@ -4108,6 +4127,50 @@ RETURN_FALSE; } + /* check for the array with urlprefixes */ + if(argc == 4) { + int i; + convert_to_array_ex(arg4); + prefixarray =(*arg4)->value.ht; + if((prefixarray == NULL) || (zend_hash_num_elements(prefixarray) != 5)) { + php_error(E_WARNING,"You must provide 5 urlprefixes (you have provided %d)", zend_hash_num_elements(prefixarray)); + RETURN_FALSE; + } + + urlprefix = emalloc(5*sizeof(char *)); + zend_hash_internal_pointer_reset(prefixarray); + for(i=0; i<5; i++) { + char *key; + zval *data, **dataptr; + ulong ind; + + zend_hash_get_current_key(prefixarray, &key, &ind); + zend_hash_get_current_data(prefixarray, (void *) &dataptr); + data = *dataptr; + if (data->type != IS_STRING) { + php_error(E_WARNING,"%s must be a String", key); + RETURN_FALSE; + } else if ( strcmp(key, "HW_DEFAULT_LINK") == 0 ) { + urlprefix[HW_DEFAULT_LINK] = data->value.str.val; + } else if ( strcmp(key, "HW_IMAGE_LINK") == 0 ) { + urlprefix[HW_IMAGE_LINK] = data->value.str.val; + } else if ( strcmp(key, "HW_BACKGROUND_LINK") == 0 ) { + urlprefix[HW_BACKGROUND_LINK] = data->value.str.val; + } else if ( strcmp(key, "HW_INTAG_LINK") == 0 ) { + urlprefix[HW_INTAG_LINK] = data->value.str.val; + } else if ( strcmp(key, "HW_APPLET_LINK") == 0 ) { + urlprefix[HW_APPLET_LINK] = data->value.str.val; + } else { + php_error(E_WARNING,"%s is not a valid urlprefix", key); + RETURN_FALSE; + } + efree(key); + zend_hash_move_forward(prefixarray); + } + } else { + urlprefix = NULL; + } + if(zend_hash_num_elements((*arg2)->value.ht) != zend_hash_num_elements((*arg3)->value.ht)) { php_error(E_WARNING,"Unequal number of elments in arrays"); RETURN_FALSE; @@ -4118,13 +4181,14 @@ anchorrecs = make_strs_from_array(arrht); arrht = (*arg3)->value.ht; dest = make_strs_from_array(arrht); -/* - if (0 != (error = insertanchors(hwdoc->data, anchorrecs, dest, zend_hash_num_elements(arrht)))) { + + if (0 != (error = send_insertanchors(&(hwdoc->data), &count, anchorrecs, dest, zend_hash_num_elements(arrht), urlprefix, &bodytag))) { php_error(E_WARNING, "command (insertanchors) returned %d\n", error); RETURN_FALSE; } -*/ - RETURN_STRING(anchorstr, 0); + hwdoc->size = count; + + RETURN_TRUE; } /* }}} */

« previous php.cvs (#3092) next »