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

From: Date: Thu, 23 Nov 2000 14:44:09 +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-2773@lists.php.net to get a copy of this message
steinm Thu Nov 23 06:44:09 2000 EDT Modified files: /php4/ext/hyperwave hg_comm.c hg_comm.h hw.c Log: - optional argument for hw_pipedocument() to specify link prefix

Index: php4/ext/hyperwave/hg_comm.c diff -u php4/ext/hyperwave/hg_comm.c:1.33 php4/ext/hyperwave/hg_comm.c:1.34 --- php4/ext/hyperwave/hg_comm.c:1.33 Thu Nov 9 05:36:53 2000 +++ php4/ext/hyperwave/hg_comm.c Thu Nov 23 06:44:09 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.c,v 1.33 2000/11/09 13:36:53 steinm Exp $ */ +/* $Id: hg_comm.c,v 1.34 2000/11/23 14:44:09 steinm Exp $ */ /* #define HW_DEBUG */ @@ -604,17 +604,21 @@ ***********************************************************************/ #define BUFFERLEN 200 #ifdef newlist -char *fnInsAnchorsIntoText(char *text, zend_llist *pAnchorList, char **bodytag, char *urlprefix) { +char *fnInsAnchorsIntoText(char *text, zend_llist *pAnchorList, char **bodytag, char **urlprefix) { ANCHOR **ptr; #else -char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char *urlprefix) { +char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char **urlprefix) { #endif ANCHOR *cur_ptr; char bgstr[BUFFERLEN], istr[BUFFERLEN]; - char *scriptname; + char **scriptname; char *newtext; int offset = 0; int laststart=0; + char emptystring[BUFFERLEN]; + int i; + + emptystring[0] = '\0'; /* The following is very tricky and depends on how rewriting is setup on your webserver. If you skip the scriptname in the url you will have to map each hyperwave name @@ -629,11 +633,14 @@ scriptname = urlprefix; } else { zval **script_name; + scriptname = emalloc(5*sizeof(char *)); if (zend_hash_find(&EG(symbol_table), "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &script_name)==FAILURE) - scriptname = NULL; + for(i=0; i<5; i++) + scriptname[i] = &emptystring; else { convert_to_string_ex(script_name); - scriptname = (*script_name)->value.str.val; + for(i=0; i<5; i++) + scriptname[i] = (*script_name)->value.str.val; } #if 0 @@ -707,7 +714,7 @@ switch(cur_ptr->linktype) { case HW_BACKGROUND_LINK: if(NULL != cur_ptr->destdocname) - snprintf(bgstr, BUFFERLEN, " background='%s/%s'", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname); + snprintf(bgstr, BUFFERLEN, " background='%s/%s'", scriptname[HW_BACKGROUND_LINK], cur_ptr->destdocname); else bgstr[0] = '\0'; break; @@ -715,14 +722,14 @@ if(cur_ptr->fragment) snprintf(istr, BUFFERLEN, " %s='#%s'", cur_ptr->tagattr, cur_ptr->fragment); else - snprintf(istr, BUFFERLEN, " %s='%s/%s'", cur_ptr->tagattr, scriptname == NULL ? "." : scriptname, cur_ptr->destdocname); + snprintf(istr, BUFFERLEN, " %s='%s/%s'", cur_ptr->tagattr, scriptname[HW_INTAG_LINK], cur_ptr->destdocname); offset -= 4; /* because there is no closing tag </A> */ /* laststart = cur_ptr->start; */ break; case HW_APPLET_LINK: if(cur_ptr->codebase) /* snprintf(istr, BUFFERLEN, " CODEBASE='%s%s' CODE='%s'", scriptname == NULL ? "" : scriptname, cur_ptr->codebase, cur_ptr->code); */ - snprintf(istr, BUFFERLEN, " CODEBASE='%s' CODE='%s'", cur_ptr->codebase, cur_ptr->code); + snprintf(istr, BUFFERLEN, " CODEBASE='%s%s' CODE='%s'", scriptname[HW_APPLET_LINK], cur_ptr->codebase, cur_ptr->code); else snprintf(istr, BUFFERLEN, " CODEBASE='/' CODE='%s'", cur_ptr->code); break; @@ -730,11 +737,11 @@ newtext = fnInsStr(newtext, cur_ptr->end+offset, "</A>"); if(cur_ptr->nameanchor) - snprintf(istr, BUFFERLEN, "<A HREF='%s/%s#%s'", scriptname == NULL ? "schade" : scriptname, cur_ptr->destdocname, cur_ptr->nameanchor); + snprintf(istr, BUFFERLEN, "<A HREF='%s/%s#%s'", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname, cur_ptr->nameanchor); else if(cur_ptr->fragment) - snprintf(istr, BUFFERLEN, "<A HREF=\"%s/%s#%s\"", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname, cur_ptr->fragment); + snprintf(istr, BUFFERLEN, "<A HREF=\"%s/%s#%s\"", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname, cur_ptr->fragment); else - snprintf(istr, BUFFERLEN, "<A HREF='%s/%s'", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname); + snprintf(istr, BUFFERLEN, "<A HREF='%s/%s'", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname); if(cur_ptr->htmlattr) { strncat(istr, " ", BUFFERLEN - 1 - strlen(istr)); @@ -771,6 +778,7 @@ } snprintf(istr, BUFFERLEN, "<BODY %s>", bgstr); *bodytag = estrdup(istr); + if(scriptname != urlprefix) efree(scriptname); return(newtext); } #undef BUFFERLEN @@ -2020,6 +2028,7 @@ int length, *ptr, ancount, error; char *tmp, *attributes, *documenttype; char **anchors; + int i; length = HEADER_LENGTH + sizeof(hw_objectID); @@ -2130,8 +2139,15 @@ if(pAnchorList != NULL) { char *newtext; char *body; + char **prefixarray; + + prefixarray = emalloc(5*sizeof(char *)); + for(i=0; i<5; i++) + prefixarray[i] = urlprefix; + + newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, prefixarray); - newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, urlprefix); + efree(prefixarray); #ifdef newlist zend_llist_destroy(pAnchorList); efree(pAnchorList); @@ -4875,7 +4891,7 @@ return(0); } -int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, int rootid, char **objattr, char **bodytag, char **text, int *count, char *urlprefix) +int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, int rootid, char **objattr, char **bodytag, char **text, int *count, char **urlprefix) { hg_msg msg, *retmsg; int length, len; Index: php4/ext/hyperwave/hg_comm.h diff -u php4/ext/hyperwave/hg_comm.h:1.10 php4/ext/hyperwave/hg_comm.h:1.11 --- php4/ext/hyperwave/hg_comm.h:1.10 Fri Oct 27 02:29:39 2000 +++ php4/ext/hyperwave/hg_comm.h Thu Nov 23 06:44:09 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.h,v 1.10 2000/10/27 09:29:39 steinm Exp $ */ +/* $Id: hg_comm.h,v 1.11 2000/11/23 14:44:09 steinm Exp $ */ #ifndef HG_COMM_H #define HG_COMM_H @@ -152,14 +152,14 @@ void fnDeleteAnchor(void *ptr1); void fnListAnchor(zend_llist *pAnchorList); zend_llist *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorrec, char **reldestrec, int ancount, int anchormode); -char *fnInsAnchorsIntoText(char *text, zend_llist *pAnchorList, char **bodytag, char *urlprefix); +char *fnInsAnchorsIntoText(char *text, zend_llist *pAnchorList, char **bodytag, char **urlprefix); int fnCmpAnchors(const void *e1, const void *e2); ANCHOR *fnAddAnchor(zend_llist *pAnchorList, int objectID, int start, int end); #else void fnDeleteAnchor(ANCHOR *ptr); void fnListAnchor(DLIST *pAnchorList); DLIST *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorrec, char **reldestrec, int ancount, int anchormode); -char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char *urlprefix); +char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char **urlprefix); int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2); ANCHOR *fnAddAnchor(DLIST *pAnchorList, int objectID, int start, int end); #endif @@ -215,7 +215,7 @@ extern int send_getparents(int sockfd, hw_objectID objectID, hw_objectID **childIDs, int *count); extern int send_children(int sockfd, hw_objectID objectID, hw_objectID **childIDs, int *count); extern int send_getparentsobj(int sockfd, hw_objectID objectID, char ***childrec, int *count); -extern int send_pipedocument(int sockfd, char *hostname, hw_objectID objectID, int mode, int rootid, char** objattr, char **bodytag, char **text, int *count, char *urlprefix); +extern int send_pipedocument(int sockfd, char *hostname, hw_objectID objectID, int mode, int rootid, char** objattr, char **bodytag, char **text, int *count, char **urlprefix); extern int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str, char **objattr, char **text, int *count); extern int send_putdocument(int sockfd, char *hostname, hw_objectID parentID, char *objectRec, char *text, int count, hw_objectID *objectID); extern int send_inscoll(int sockfd, hw_objectID objectID, char *objrec, hw_objectID *new_objectID); Index: php4/ext/hyperwave/hw.c diff -u php4/ext/hyperwave/hw.c:1.67 php4/ext/hyperwave/hw.c:1.68 --- php4/ext/hyperwave/hw.c:1.67 Thu Nov 9 05:36:53 2000 +++ php4/ext/hyperwave/hw.c Thu Nov 23 06:44:09 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hw.c,v 1.67 2000/11/09 13:36:53 steinm Exp $ */ +/* $Id: hw.c,v 1.68 2000/11/23 14:44:09 steinm Exp $ */ #include <stdlib.h> #include <errno.h> @@ -2278,9 +2278,131 @@ } /* }}} */ +/* {{{ proto hwdoc hw_pipedocument(int link, int objid [, array urlprefixes ] ) + 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. +*/ +PHP_FUNCTION(hw_pipedocument) { + pval *arg1, *arg2, *arg3; + int i, link, id, type, argc, mode; + int rootid = 0; + HashTable *prefixarray; + char **urlprefix; + hw_connection *ptr; + hw_document *doc; +#if APACHE + server_rec *serv = ((request_rec *) SG(server_context))->server; +#endif + + argc = ZEND_NUM_ARGS(); + switch(argc) + { + case 2: + if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) + RETURN_FALSE; + break; + case 3: + if (getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) + RETURN_FALSE; + break; + default: + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_long(arg2); + + link=arg1->value.lval; + id=arg2->value.lval; + ptr = zend_list_find(link,&type); + if(!ptr || (type!=HwSG(le_socketp) && type!=HwSG(le_psocketp))) { + php_error(E_WARNING,"Unable to find file identifier %d", link); + RETURN_FALSE; + } + + /* check for the array with urlprefixes */ + if(argc == 3) { + convert_to_array(arg3); + prefixarray =arg3->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; + } + + mode = 0; + if(ptr->linkroot > 0) + mode = 1; + rootid = ptr->linkroot; + + set_swap(ptr->swap_on); + { + char *object = NULL; + char *attributes = NULL; + char *bodytag = NULL; + int count; + /* !!!! memory for object, bodytag and attributes is allocated with malloc !!!! */ + if (0 != (ptr->lasterror = send_pipedocument(ptr->socket, +#if APACHE + serv->server_hostname, +#else + getenv("HOSTNAME"), +#endif + id, mode, rootid, &attributes, &bodytag, &object, &count, urlprefix))) + RETURN_FALSE; + + if(urlprefix) efree(urlprefix); + + doc = malloc(sizeof(hw_document)); + doc->data = object; + doc->attributes = attributes; + doc->bodytag = bodytag; + doc->size = count; +/* fprintf(stderr, "size = %d\n", count); */ + return_value->value.lval = zend_list_insert(doc,HwSG(le_document)); + return_value->type = IS_LONG; + } +} +/* }}} */ + /* {{{ proto hwdoc hw_pipedocument(int link, int objid) Returns document */ -PHP_FUNCTION(hw_pipedocument) { +PHP_FUNCTION(hw_oldpipedocument) { pval *argv[3]; int link, id, type, argc, mode; int rootid = 0;
« previous php.cvs (#2773) next »