summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Steinmann <steinm@php.net>2000-11-23 14:44:10 +0000
committerUwe Steinmann <steinm@php.net>2000-11-23 14:44:10 +0000
commit4a60447800b0d5e8126e55ef6a9ca01e081858c9 (patch)
treeb290b24a2aeac52fba0eab59f948f833dcfe2b13
parent5ebbef16f2563ee0c7aebfc458e8c7d527a5e57b (diff)
downloadphp-git-4a60447800b0d5e8126e55ef6a9ca01e081858c9.tar.gz
- optional argument for hw_pipedocument() to specify link prefix
-rw-r--r--ext/hyperwave/hg_comm.c42
-rw-r--r--ext/hyperwave/hg_comm.h6
-rw-r--r--ext/hyperwave/hw.c124
3 files changed, 155 insertions, 17 deletions
diff --git a/ext/hyperwave/hg_comm.c b/ext/hyperwave/hg_comm.c
index b56926e89b..c87eeec057 100644
--- a/ext/hyperwave/hg_comm.c
+++ b/ext/hyperwave/hg_comm.c
@@ -604,17 +604,21 @@ DLIST *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorr
***********************************************************************/
#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 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char
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 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char
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 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char
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 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char
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 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char
}
snprintf(istr, BUFFERLEN, "<BODY %s>", bgstr);
*bodytag = estrdup(istr);
+ if(scriptname != urlprefix) efree(scriptname);
return(newtext);
}
#undef BUFFERLEN
@@ -2020,6 +2028,7 @@ int send_gettext(int sockfd, hw_objectID objectID, int mode, int rootid, char **
int length, *ptr, ancount, error;
char *tmp, *attributes, *documenttype;
char **anchors;
+ int i;
length = HEADER_LENGTH + sizeof(hw_objectID);
@@ -2130,8 +2139,15 @@ int send_gettext(int sockfd, hw_objectID objectID, int mode, int rootid, char **
if(pAnchorList != NULL) {
char *newtext;
char *body;
+ char **prefixarray;
- newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, urlprefix);
+ prefixarray = emalloc(5*sizeof(char *));
+ for(i=0; i<5; i++)
+ prefixarray[i] = urlprefix;
+
+ newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, prefixarray);
+
+ efree(prefixarray);
#ifdef newlist
zend_llist_destroy(pAnchorList);
efree(pAnchorList);
@@ -4875,7 +4891,7 @@ int send_getparentsobj(int sockfd, hw_objectID objectID, char ***childrec, int *
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;
diff --git a/ext/hyperwave/hg_comm.h b/ext/hyperwave/hg_comm.h
index 94826e4dbf..4c88d08dd7 100644
--- a/ext/hyperwave/hg_comm.h
+++ b/ext/hyperwave/hg_comm.h
@@ -152,14 +152,14 @@ typedef float hw_float;
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_identify(int sockfd, char *name, char *passwd, char **userdata);
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);
diff --git a/ext/hyperwave/hw.c b/ext/hyperwave/hw.c
index 0351c4d7ac..5815967c41 100644
--- a/ext/hyperwave/hw.c
+++ b/ext/hyperwave/hw.c
@@ -2278,9 +2278,131 @@ PHP_FUNCTION(hw_setlinkroot) {
}
/* }}} */
+/* {{{ 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;