diff options
author | Uwe Steinmann <steinm@php.net> | 1999-08-05 16:25:10 +0000 |
---|---|---|
committer | Uwe Steinmann <steinm@php.net> | 1999-08-05 16:25:10 +0000 |
commit | d172a6b581d8af9041b18d014f92ea5846c93c09 (patch) | |
tree | 5e52b7026c036b721e4cfa6cf52cbe1c685cb5b1 /ext/hyperwave | |
parent | 48c36437533ae9e66c08e465d709c428891e594f (diff) | |
download | php-git-d172a6b581d8af9041b18d014f92ea5846c93c09.tar.gz |
Huge patch to update the hyperwave and pdflib module.
Only pdflib >2.0 is supported.
None is tested yet. Hyperwave seems to be broken now.
Diffstat (limited to 'ext/hyperwave')
-rw-r--r-- | ext/hyperwave/hg_comm.c | 798 | ||||
-rw-r--r-- | ext/hyperwave/hg_comm.h | 30 | ||||
-rw-r--r-- | ext/hyperwave/hw.c | 859 | ||||
-rw-r--r-- | ext/hyperwave/hw_error.h | 2 |
4 files changed, 1173 insertions, 516 deletions
diff --git a/ext/hyperwave/hg_comm.c b/ext/hyperwave/hg_comm.c index dcb300de60..812511d4ee 100644 --- a/ext/hyperwave/hg_comm.c +++ b/ext/hyperwave/hg_comm.c @@ -21,12 +21,9 @@ /* #define HW_DEBUG */ #include <stdlib.h> - -#if WIN32|WINNT -#include "win95nt.h" -#else -#include "php_config.h" -#endif +#include "php.h" +#include "php_globals.h" +#include "SAPI.h" #if HYPERWAVE @@ -51,8 +48,7 @@ #include <alloc.h> #include "hg_comm.h" #include "dlist.h" -#include "php.h" -#include "head.h" +#include "ext/standard/head.h" static int set_nonblocking(int fd); static int set_blocking(int fd); @@ -68,14 +64,14 @@ static char *build_msg_str(char *buf, char *str); static int swap(int val); -int version = VERSION; +int version = HW_VERSION; /* F_DISTRIBUTED has the effect that all object ids are virtual. This means whenever an object is requested a new id is generated for this session. Wavemaster and Harmony set this flag. How do I know? tcpdump tells a lot if investigate the output. - int version = VERSION | F_DISTRIBUTED; */ -/* int version = VERSION | F_DISTRIBUTED | F_COMPRESSED; */ + int version = HW_VERSION | F_DISTRIBUTED; */ +/* int version = HW_VERSION | F_DISTRIBUTED | F_COMPRESSED; */ static int msgid = 1; static int sock_flags = -1; static int non_blocking = 0; @@ -157,7 +153,7 @@ ANCHOR *fnAddAnchor(DLIST *pAnchorList, cur_ptr->keyword = NULL; cur_ptr->fragment = NULL; - dlst_insertafter(pAnchorList, cur_ptr, DLST_HEAD(pAnchorList)); + dlst_insertafter(pAnchorList, cur_ptr, PHP_DLST_HEAD(pAnchorList)); return(cur_ptr); } @@ -244,192 +240,199 @@ DLIST *fnCreateAnchorList(char **anchors, char **docofanchorrec, char **reldestr docofanchorptr = docofanchorrec[i]; reldestptr = reldestrec[i]; - /* Determine Position. Doesn't matter if Src or Dest */ + /* Determine Position. Doesn't matter if Src or Dest + The Position field should always be there. Though there + are case in which the position has no meaning, e.g. if + a document is annotated and the annotation text doesn't + contain a link of type annotation, + In such a case the Position has the value 'invisible' */ str = strstr(object, "Position"); str += 9; - sscanf(str, "0x%X 0x%X", &start, &end); - - /* Determine ObjectID */ - objectID = 0; - if(NULL != (str = strstr(object, "ObjectID"))) { - str += 9; - sscanf(str, "0x%X", &objectID); - } - - cur_ptr = fnAddAnchor(pAnchorList, objectID, start, end); - - /* Determine Type of Anchor */ - str = strstr(object, "TAnchor"); - str += 8; - if(*str == 'S') { - char destdocname[200]; - char nameanchor[200]; - cur_ptr->tanchor = 1; + if(0 != strncmp(str, "invisible", 9)) { + sscanf(str, "0x%X 0x%X", &start, &end); + + /* Determine ObjectID */ + objectID = 0; + if(NULL != (str = strstr(object, "ObjectID"))) { + str += 9; + sscanf(str, "0x%X", &objectID); + } + + cur_ptr = fnAddAnchor(pAnchorList, objectID, start, end); + + /* Determine Type of Anchor */ + str = strstr(object, "TAnchor"); + str += 8; + if(*str == 'S') { + char destdocname[200]; + char nameanchor[200]; + cur_ptr->tanchor = 1; + + cur_ptr->destdocname = NULL; + if(NULL != (str = strstr(object, "Dest"))) { + char *tempptr; - cur_ptr->destdocname = NULL; - if(NULL != (str = strstr(object, "Dest"))) { - char *tempptr; - - /* No need to care about the value of Dest, because we take the info - from docofanchorptr. - Since the anchor has a destination there are two possibilities. - 1. The destination is an anchor or - 2. or the destination is a document already. - In both cases docofanchorptr has the proper info because GETDOCBYANCHOR - is such a nice message. - */ - switch(anchormode) { - case 0: - tempptr = docofanchorptr; - break; - default: - tempptr = reldestptr; - } - if(NULL != tempptr) { - /* It's always nice to deal with names, so let's first check - for a name. If there is none we take the ObjectID. + /* No need to care about the value of Dest, because we take the info + from docofanchorptr. + Since the anchor has a destination there are two possibilities. + 1. The destination is an anchor or + 2. or the destination is a document already. + In both cases docofanchorptr has the proper info because GETDOCBYANCHOR + is such a nice message. */ - if(NULL != (str = strstr(tempptr, "Name="))) { - str += 5; - } else if(NULL != (str = strstr(tempptr, "ObjectID="))) { - str += 9; - } - if(sscanf(str, "%s\n", destdocname)) { - cur_ptr->destdocname = estrdup(destdocname); + switch(anchormode) { + case 0: + tempptr = docofanchorptr; + break; + default: + tempptr = reldestptr; } - destid = 0; - if(NULL != (str = strstr(tempptr, "ObjectID="))) { - str += 9; - sscanf(str, "0x%X", &destid); + if(NULL != tempptr) { + /* It's always nice to deal with names, so let's first check + for a name. If there is none we take the ObjectID. + */ + if(NULL != (str = strstr(tempptr, "Name="))) { + str += 5; + } else if(NULL != (str = strstr(tempptr, "ObjectID="))) { + str += 9; + } + if(sscanf(str, "%s\n", destdocname)) { + cur_ptr->destdocname = estrdup(destdocname); + } + destid = 0; + if(NULL != (str = strstr(tempptr, "ObjectID="))) { + str += 9; + sscanf(str, "0x%X", &destid); + } } } - } - - /* Get the Id of the anchor destination and the document id that belongs - to that anchor. We need that soon in order to determine if the anchor - points to a document or a dest anchor in a document. - */ - anchordestid = 0; - if(NULL != (str = strstr(object, "Dest="))) { - str += 5; - sscanf(str, "0x%X", &anchordestid); - } - - /* if anchordestid != destid then the destination is an anchor in a document whose - name (objectID) is already in destdocname. We will have to extend the link - by '#...' - */ - cur_ptr->nameanchor = NULL; - if(anchordestid != destid) { + + /* Get the Id of the anchor destination and the document id that belongs + to that anchor. We need that soon in order to determine if the anchor + points to a document or a dest anchor in a document. + */ + anchordestid = 0; if(NULL != (str = strstr(object, "Dest="))) { str += 5; - if(sscanf(str, "%s\n", nameanchor)) - cur_ptr->nameanchor = estrdup(nameanchor); + sscanf(str, "0x%X", &anchordestid); } - } - - if(!cur_ptr->destdocname) { - cur_ptr->link = NULL; - if(NULL != (str = strstr(object, "Hint=URL:"))) { - str += 9; - if(sscanf(str, "%s\n", link)) - cur_ptr->link = estrdup(link); - } else if(NULL != (str = strstr(object, "Hint="))) { - str += 5; - if(sscanf(str, "%s\n", link)) - cur_ptr->link = estrdup(link); - } - } - - cur_ptr->fragment = NULL; - if(NULL != (str = strstr(object, "Fragment="))) { - str += 9; - if(sscanf(str, "%s\n", link)) - cur_ptr->fragment = estrdup(link); - } - - cur_ptr->htmlattr = NULL; - if(NULL != (str = strstr(object, "HtmlAttr="))) { - str += 9; - str1 = str; - while((*str1 != '\n') && (*str1 != '\0')) - str1++; - cur_ptr->htmlattr = emalloc(str1 - str + 1); - strncpy(cur_ptr->htmlattr, str, str1 - str); - cur_ptr->htmlattr[str1 - str] = '\0'; - } - - if(NULL != (str = strstr(object, "LinkType="))) { - str += 9; - if(strncmp(str, "background", 10) == 0) - cur_ptr->linktype=HW_BACKGROUND_LINK; - else - if(strncmp(str, "intag", 5) == 0) { - cur_ptr->linktype=HW_INTAG_LINK; - cur_ptr->tagattr = NULL; - if(NULL != (str = strstr(object, "TagAttr="))) { - str += 8; - str1 = str; - while((*str1 != '\n') && (*str1 != '\0')) - str1++; - cur_ptr->tagattr = emalloc(str1 - str + 1); - memcpy(cur_ptr->tagattr, str, str1 - str); - cur_ptr->tagattr[str1 - str] = '\0'; - } - } else - if(strncmp(str, "applet", 6) == 0) { - cur_ptr->linktype=HW_APPLET_LINK; - cur_ptr->codebase = NULL; - if(NULL != (str = strstr(object, "CodeBase="))) { - str += 9; - str1 = str; - while((*str1 != '\n') && (*str1 != '\0')) - str1++; - cur_ptr->codebase = emalloc(str1 - str + 1); - memcpy(cur_ptr->codebase, str, str1 - str); - cur_ptr->codebase[str1 - str] = '\0'; - } - cur_ptr->code = NULL; - if(NULL != (str = strstr(object, "Code="))) { + + /* if anchordestid != destid then the destination is an anchor in a document whose + name (objectID) is already in destdocname. We will have to extend the link + by '#...' + */ + cur_ptr->nameanchor = NULL; + if(anchordestid != destid) { + if(NULL != (str = strstr(object, "Dest="))) { str += 5; - str1 = str; - while((*str1 != '\n') && (*str1 != '\0')) - str1++; - cur_ptr->code = emalloc(str1 - str + 1); - memcpy(cur_ptr->code, str, str1 - str); - cur_ptr->code[str1 - str] = '\0'; + if(sscanf(str, "%s\n", nameanchor)) + cur_ptr->nameanchor = estrdup(nameanchor); } + } + + if(!cur_ptr->destdocname) { + cur_ptr->link = NULL; + if(NULL != (str = strstr(object, "Hint=URL:"))) { + str += 9; + if(sscanf(str, "%s\n", link)) + cur_ptr->link = estrdup(link); + } else if(NULL != (str = strstr(object, "Hint="))) { + str += 5; + if(sscanf(str, "%s\n", link)) + cur_ptr->link = estrdup(link); + } + } + + cur_ptr->fragment = NULL; + if(NULL != (str = strstr(object, "Fragment="))) { + str += 9; + if(sscanf(str, "%s\n", link)) + cur_ptr->fragment = estrdup(link); + } + + cur_ptr->htmlattr = NULL; + if(NULL != (str = strstr(object, "HtmlAttr="))) { + str += 9; + str1 = str; + while((*str1 != '\n') && (*str1 != '\0')) + str1++; + cur_ptr->htmlattr = emalloc(str1 - str + 1); + strncpy(cur_ptr->htmlattr, str, str1 - str); + cur_ptr->htmlattr[str1 - str] = '\0'; + } + + if(NULL != (str = strstr(object, "LinkType="))) { + str += 9; + if(strncmp(str, "background", 10) == 0) + cur_ptr->linktype=HW_BACKGROUND_LINK; + else + if(strncmp(str, "intag", 5) == 0) { + cur_ptr->linktype=HW_INTAG_LINK; + cur_ptr->tagattr = NULL; + if(NULL != (str = strstr(object, "TagAttr="))) { + str += 8; + str1 = str; + while((*str1 != '\n') && (*str1 != '\0')) + str1++; + cur_ptr->tagattr = emalloc(str1 - str + 1); + memcpy(cur_ptr->tagattr, str, str1 - str); + cur_ptr->tagattr[str1 - str] = '\0'; + } + } else + if(strncmp(str, "applet", 6) == 0) { + cur_ptr->linktype=HW_APPLET_LINK; + cur_ptr->codebase = NULL; + if(NULL != (str = strstr(object, "CodeBase="))) { + str += 9; + str1 = str; + while((*str1 != '\n') && (*str1 != '\0')) + str1++; + cur_ptr->codebase = emalloc(str1 - str + 1); + memcpy(cur_ptr->codebase, str, str1 - str); + cur_ptr->codebase[str1 - str] = '\0'; + } + cur_ptr->code = NULL; + if(NULL != (str = strstr(object, "Code="))) { + str += 5; + str1 = str; + while((*str1 != '\n') && (*str1 != '\0')) + str1++; + cur_ptr->code = emalloc(str1 - str + 1); + memcpy(cur_ptr->code, str, str1 - str); + cur_ptr->code[str1 - str] = '\0'; + } + } else + cur_ptr->linktype=HW_DEFAULT_LINK; } else cur_ptr->linktype=HW_DEFAULT_LINK; - } else - cur_ptr->linktype=HW_DEFAULT_LINK; - - } else { /* Destination Anchor */ - char nameanchor[200]; - - cur_ptr->tanchor = 2; - cur_ptr->link = NULL; - - /* Here is the only additional info for the name attribute */ - cur_ptr->nameanchor = NULL; - if(NULL != (str = strstr(object, "ObjectID="))) { - str += 9; - if(sscanf(str, "%s\n", nameanchor)) - cur_ptr->nameanchor = estrdup(nameanchor); - } - - cur_ptr->keyword = NULL; - if(NULL != (str = strstr(object, "Keyword="))) { - str += 8; - if(sscanf(str, "%s\n", nameanchor)) - cur_ptr->keyword = estrdup(nameanchor); + + } else { /* Destination Anchor */ + char nameanchor[200]; + + cur_ptr->tanchor = 2; + cur_ptr->link = NULL; + + /* Here is the only additional info for the name attribute */ + cur_ptr->nameanchor = NULL; + if(NULL != (str = strstr(object, "ObjectID="))) { + str += 9; + if(sscanf(str, "%s\n", nameanchor)) + cur_ptr->nameanchor = estrdup(nameanchor); + } + + cur_ptr->keyword = NULL; + if(NULL != (str = strstr(object, "Keyword="))) { + str += 8; + if(sscanf(str, "%s\n", nameanchor)) + cur_ptr->keyword = estrdup(nameanchor); + } + } - + + efree(anchors[i]); + if(docofanchorrec[i]) efree(docofanchorrec[i]); + if(reldestrec[i]) efree(reldestrec[i]); } - - efree(anchors[i]); - if(docofanchorrec[i]) efree(docofanchorrec[i]); - if(reldestrec[i]) efree(reldestrec[i]); } } return pAnchorList; @@ -443,31 +446,39 @@ DLIST *fnCreateAnchorList(char **anchors, char **docofanchorrec, char **reldestr * DList *pAnchorList: list of anchors * * Return: Text with anchors * ***********************************************************************/ -char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag) { +#define BUFFERLEN 200 +char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char *urlprefix) { ANCHOR *cur_ptr; - char bgstr[100], istr[200]; + char bgstr[BUFFERLEN], istr[BUFFERLEN]; char *scriptname; char *newtext; int offset = 0; int laststart=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 to http://<hwname>. + This may not always be a good idea. The best solution is probably to provide a prefix for such + a case which is an optional parameter to hw_gettext hw_pipedocument. +*/ + if(urlprefix) { + scriptname = urlprefix; + } else { #if APACHE - { - int j; - SLS_FETCH(); - - array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env); - table_entry *elts = (table_entry *)arr->elts; + { + int j; + array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env); + table_entry *elts = (table_entry *)arr->elts; - for (j=0; j < arr->nelts; j++) { - if(0 == strcmp(elts[j].key, "SCRIPT_NAME")) - break; - } - scriptname = elts[j].val; - } + for (j=0; j < arr->nelts; j++) { + if(0 == strcmp(elts[j].key, "SCRIPT_NAME")) + break; + } + scriptname = elts[j].val; + } #else - scriptname = getenv("SCRIPT_FILENAME"); + scriptname = getenv("SCRIPT_FILENAME"); #endif + } newtext = text; bgstr[0] = '\0'; @@ -483,57 +494,57 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag) { /* The link is only set if the Link points to an external document */ switch(cur_ptr->linktype) { case HW_BACKGROUND_LINK: - sprintf(bgstr, " background='%s'", cur_ptr->link); + snprintf(bgstr, BUFFERLEN, " background='%s'", cur_ptr->link); break; case HW_INTAG_LINK: - sprintf(istr, " %s='%s' start=%d", cur_ptr->tagattr, cur_ptr->link, cur_ptr->start); + snprintf(istr, BUFFERLEN, " %s='%s' start=%d", cur_ptr->tagattr, cur_ptr->link, cur_ptr->start); offset -= 4; /* because there is no closing tag </A> */ /* laststart = cur_ptr->start; */ break; case HW_APPLET_LINK: if(cur_ptr->codebase) - sprintf(istr, " CODEBASE='%s' CODE='%s'", cur_ptr->codebase, cur_ptr->code); + snprintf(istr, BUFFERLEN, " CODEBASE='%s' CODE='%s'", cur_ptr->codebase, cur_ptr->code); else - sprintf(istr, " CODEBASE='/' CODE='%s'", cur_ptr->code); + snprintf(istr, BUFFERLEN, " CODEBASE='/' CODE='%s'", cur_ptr->code); break; default: newtext = fnInsStr(newtext, cur_ptr->end+offset, "</A>"); - sprintf(istr, "<A HREF='%s' %s offset=%d>", cur_ptr->link, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr, offset); + snprintf(istr, BUFFERLEN, "<A HREF='%s' %s>", cur_ptr->link, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); } } else { switch(cur_ptr->linktype) { case HW_BACKGROUND_LINK: if(NULL != cur_ptr->destdocname) - sprintf(bgstr, " background='%s/%s'", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname); + snprintf(bgstr, BUFFERLEN, " background='%s/%s'", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname); else - sprintf(bgstr, ""); + bgstr[0] = '\0'; break; case HW_INTAG_LINK: if(cur_ptr->fragment) -/* sprintf(istr, " %s='%s/%s#%s'", cur_ptr->tagattr, scriptname == NULL ? "." : scriptname, cur_ptr->destdocname, cur_ptr->fragment);*/ - sprintf(istr, " %s='#%s'", cur_ptr->tagattr, cur_ptr->fragment); +/* snprintf(istr, BUFFERLEN, " %s='%s/%s#%s'", cur_ptr->tagattr, scriptname == NULL ? "." : scriptname, cur_ptr->destdocname, cur_ptr->fragment);*/ + snprintf(istr, BUFFERLEN, " %s='#%s'", cur_ptr->tagattr, cur_ptr->fragment); else - sprintf(istr, " %s='%s/%s'", cur_ptr->tagattr, scriptname == NULL ? "." : scriptname, cur_ptr->destdocname); + snprintf(istr, BUFFERLEN, " %s='%s/%s'", cur_ptr->tagattr, scriptname == NULL ? "." : scriptname, 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) -/* sprintf(istr, " CODEBASE='%s%s' CODE='%s'", scriptname == NULL ? "" : scriptname, cur_ptr->codebase, cur_ptr->code); */ - sprintf(istr, " CODEBASE='%s' CODE='%s'", cur_ptr->codebase, cur_ptr->code); +/* 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); else - sprintf(istr, " CODEBASE='/' CODE='%s'", cur_ptr->code); + snprintf(istr, BUFFERLEN, " CODEBASE='/' CODE='%s'", cur_ptr->code); break; default: newtext = fnInsStr(newtext, cur_ptr->end+offset, "</A>"); if(cur_ptr->nameanchor) - sprintf(istr, "<A HREF='%s/%s#%s' %s>", scriptname == NULL ? "schade" : scriptname, cur_ptr->destdocname, cur_ptr->nameanchor, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); + snprintf(istr, BUFFERLEN, "<A HREF='%s/%s#%s' %s>", scriptname == NULL ? "schade" : scriptname, cur_ptr->destdocname, cur_ptr->nameanchor, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); else if(cur_ptr->fragment) - sprintf(istr, "<A HREF='%s/%s#%s' %s>", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname, cur_ptr->fragment, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); + snprintf(istr, BUFFERLEN, "<A HREF='%s/%s#%s' %s>", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname, cur_ptr->fragment, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); else - sprintf(istr, "<A HREF='%s/%s' %s offset=%d>", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr, offset); + snprintf(istr, BUFFERLEN, "<A HREF='%s/%s' %s>", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); } } newtext = fnInsStr(newtext, cur_ptr->start, istr); @@ -550,9 +561,9 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag) { instead of the destdocname */ if(cur_ptr->keyword) - sprintf(istr, "<A NAME='%s'>", cur_ptr->keyword); + snprintf(istr, BUFFERLEN, "<A NAME='%s'>", cur_ptr->keyword); else if(cur_ptr->nameanchor) - sprintf(istr, "<A NAME='%s'>", cur_ptr->nameanchor); + snprintf(istr, BUFFERLEN, "<A NAME='%s'>", cur_ptr->nameanchor); newtext = fnInsStr(newtext, cur_ptr->start, istr); /* In case there are several TAGS nested, we accumulate the offset You wonder what the 4 means? It's the length of </A> */ @@ -561,10 +572,11 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag) { } cur_ptr = (ANCHOR *) dlst_prev(cur_ptr); } - sprintf(istr, "<BODY %s>", bgstr); + snprintf(istr, BUFFERLEN, "<BODY %s>", bgstr); *bodytag = estrdup(istr); return(newtext); } +#undef BUFFERLEN /*********************************************************************** * Function fnAttributeValue() * @@ -661,7 +673,7 @@ static int fnCOpenDataCon(int sockfd, int *port) /* ** Open a TCP socket (an Internet stream socket) */ - if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + if((fd = socket(AF_INET, SOCK_STREAM, 0)) == SOCK_ERR) { return(-1); } @@ -929,7 +941,7 @@ int open_hg_connection(char *server_name, int port) server_addr.sin_port = htons(HG_SERVER_PORT); bcopy(hp->h_addr, (char *) &server_addr.sin_addr, hp->h_length); - if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { + if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == SOCK_ERR ) { return(-2); } @@ -939,8 +951,8 @@ int open_hg_connection(char *server_name, int port) setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)); #endif /* SUN */ - if (connect(sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) { - close(sockfd); + if (connect(sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) != 0) { + HWSOCK_FCLOSE(sockfd); return(-3); } @@ -949,6 +961,7 @@ int open_hg_connection(char *server_name, int port) #endif if ( set_nonblocking(sockfd) == -1 ) { + HWSOCK_FCLOSE(sockfd); return(-4); } @@ -1008,7 +1021,7 @@ int initialize_hg_connection(int sockfd, int *do_swap, int *version, char **user return(-9); } - if ((ready_msg->version_msgid & F_VERSION) < VERSION) + if ((ready_msg->version_msgid & F_VERSION) < HW_VERSION) return(-8); *version = ready_msg->version_msgid; *server_string = strdup(ready_msg->buf+4); @@ -1151,38 +1164,38 @@ hg_msg *recv_hg_msg(int sockfd) hg_msg *msg; if ( (msg = (hg_msg *)emalloc(sizeof(hg_msg))) == NULL ) { -/* php_printf("recv_hg_msg"); */ +/* php3_printf("recv_hg_msg"); */ lowerror = LE_MALLOC; return(NULL); } if ( hg_read_exact(sockfd, (char *)&(msg->length), 4) == -1 ) { -/* php_printf("recv_hg_msg: hg_read (1) returned -1\n"); */ +/* php3_printf("recv_hg_msg: hg_read (1) returned -1\n"); */ efree(msg); return(NULL); } if ( hg_read_exact(sockfd, (char *)&(msg->version_msgid), 4) == -1 ) { -/* php_printf("recv_hg_msg: hg_read (2) returned -1\n"); */ +/* php3_printf("recv_hg_msg: hg_read (2) returned -1\n"); */ efree(msg); return(NULL); } if ( hg_read_exact(sockfd, (char *)&(msg->msg_type), 4) == -1 ) { -/* php_printf("recv_hg_msg: hg_read (3) returned -1\n"); */ +/* php3_printf("recv_hg_msg: hg_read (3) returned -1\n"); */ efree(msg); return(NULL); } if ( msg->length > HEADER_LENGTH ) { if ( (msg->buf = (char *) emalloc(msg->length-HEADER_LENGTH)) == NULL ) { -/* php_printf("recv_hg_msg"); */ +/* php3_printf("recv_hg_msg"); */ lowerror = LE_MALLOC; efree(msg); return(NULL); } if ( hg_read_exact(sockfd, msg->buf, msg->length-HEADER_LENGTH) == -1 ) { -/* php_printf("recv_hg_msg: hg_read (4) returned -1\n"); */ +/* php3_printf("recv_hg_msg: hg_read (4) returned -1\n"); */ efree(msg->buf); efree(msg); return(NULL); @@ -1192,7 +1205,7 @@ hg_msg *recv_hg_msg(int sockfd) msg->buf = NULL; #ifdef HW_DEBUG - php_printf("<B> Recv msg: </B>type = %d -- id = %d<BR>\n", msg->msg_type, msg->version_msgid); + php3_printf("<B> Recv msg: </B>type = %d -- id = %d<BR>\n", msg->msg_type, msg->version_msgid); #endif return(msg); } @@ -1203,11 +1216,11 @@ hg_msg *recv_ready(int sockfd) hg_msg *ready_msg; if ( (ready_msg = recv_hg_msg(sockfd)) == NULL ) { -/* php_printf("recv_ready: recv_hg_msg returned NULL\n"); */ +/* php3_printf("recv_ready: recv_hg_msg returned NULL\n"); */ return(NULL); } if ( ready_msg->msg_type != READY_MESSAGE ) { -/* php_printf("recv_ready: recv_hg_msg returned wrong message: %d, %d \n", ready_msg->length, ready_msg->msg_type); */ +/* php3_printf("recv_ready: recv_hg_msg returned wrong message: %d, %d \n", ready_msg->length, ready_msg->msg_type); */ efree(ready_msg); return(NULL); } @@ -1339,7 +1352,6 @@ static int bh_send_changeobject(int sockfd, hw_objectID objectID, char *mod) { 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); } @@ -1376,6 +1388,29 @@ int send_changeobject(int sockfd, hw_objectID objectID, char *modification) return(uh_send_changeobject(sockfd)); } +int send_groupchangeobject(int sockfd, hw_objectID objectID, char *modification) +{ + hw_objectID *childIDs; + int count, i, error; + + if(0 == (error = send_lock(sockfd, objectID))) { + send_changeobject(sockfd, objectID, modification); + send_unlock(sockfd, objectID); + }/* else + fprintf(stderr, "Could not lock 0x%X (error = %d)\n", objectID, error); */ + + 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; @@ -1386,7 +1421,6 @@ static int bh_send_getobject(int sockfd, hw_objectID objectID) { build_msg_header(&msg, length, msgid++, GETOBJECT_MESSAGE); if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { -/* perror("send_command"); */ lowerror = LE_MALLOC; return(-1); } @@ -1475,6 +1509,41 @@ int send_getandlock(int sockfd, hw_objectID objectID, char **attributes) return error; } +int send_lock(int sockfd, hw_objectID objectID) +{ + hg_msg msg, *retmsg; + int length, error; + char *tmp; + + length = HEADER_LENGTH + sizeof(hw_objectID); + + build_msg_header(&msg, length, msgid++, GETANDLOCK_MESSAGE); + + if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { + lowerror = LE_MALLOC; + return(-1); + } + + tmp = build_msg_int(msg.buf, objectID); + + if ( send_hg_msg(sockfd, &msg, length) == -1 ) { + efree(msg.buf); + return(-1); + } + + efree(msg.buf); + retmsg = recv_hg_msg(sockfd); + if ( retmsg == NULL ) { + return(-1); + } + + error = *((int *) retmsg->buf); + + efree(retmsg->buf); + efree(retmsg); + return error; +} + int send_insertobject(int sockfd, char *objrec, char *parms, hw_objectID *objectID) { hg_msg msg, *retmsg; @@ -1522,7 +1591,7 @@ int send_insertobject(int sockfd, char *objrec, char *parms, hw_objectID *object int send_unlock(int sockfd, hw_objectID objectID) { - hg_msg msg, *retmsg; + hg_msg msg; int length, error; char *tmp; @@ -1544,16 +1613,7 @@ int send_unlock(int sockfd, hw_objectID objectID) } efree(msg.buf); - retmsg = recv_hg_msg(sockfd); - if ( retmsg == NULL ) { - return(-1); - } - - error = (int) *(retmsg->buf); - - efree(retmsg->buf); - efree(retmsg); - return error; + return 0; } int send_incollections(int sockfd, int retcol, int cobjids, hw_objectID *objectIDs, int ccollids, hw_objectID *collIDs, int *count, hw_objectID **retIDs) @@ -1716,7 +1776,7 @@ int send_insdoc(int sockfd, hw_objectID objectID, char *objrec, char *text, hw_o int send_getdestforanchorsobj(int sockfd, char **anchorrec, char ***destrec, int count); int send_getreldestforanchorsobj(int sockfd, char **anchorrec, char ***reldestrec, int count, int rootID, int thisID); -int send_gettext(int sockfd, hw_objectID objectID, int mode, int rootid, char **objattr, char **bodytag, char **text, int *count) +int send_gettext(int sockfd, hw_objectID objectID, int mode, int rootid, char **objattr, char **bodytag, char **text, int *count, char *urlprefix) { hg_msg msg, *retmsg; int length, *ptr, ancount, error; @@ -1827,7 +1887,7 @@ int send_gettext(int sockfd, hw_objectID objectID, int mode, int rootid, char ** char *newtext; char *body; - newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body); + newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, urlprefix); dlst_kill(pAnchorList, fnDeleteAnchor); *bodytag = strdup(body); efree(body); @@ -1848,22 +1908,22 @@ int send_edittext(int sockfd, char *objattr, char *text) char *tmp, *path, *objid; hw_objectID objectID; - objid = fnAttributeValue(objattr, "ObjectID="); + objid = fnAttributeValue(objattr, "ObjectID"); if(objid == NULL) return(-1); if(!sscanf(objid, "0x%x", &objectID)) - return(-1); + return(-2); - path = fnAttributeValue(objattr, "Path="); + path = fnAttributeValue(objattr, "Path"); if(path == NULL) - return(-1); - length = HEADER_LENGTH + sizeof(hw_objectID) + strlen(path) + 1 + 1 + strlen(text) + 1; + return(-3); + length = HEADER_LENGTH + sizeof(hw_objectID) + strlen(path) + 1 + 1 + strlen(text) + 1; build_msg_header(&msg, length, msgid++, EDITTEXT_MESSAGE); if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { lowerror = LE_MALLOC; - return(-1); + return(-4); } tmp = build_msg_int(msg.buf, objectID); @@ -1876,20 +1936,20 @@ int send_edittext(int sockfd, char *objattr, char *text) if ( send_hg_msg(sockfd, &msg, length) == -1 ) { efree(msg.buf); - return(-1); + return(-5); } efree(msg.buf); retmsg = recv_hg_msg(sockfd); if (retmsg == NULL) { *text = '\0'; - return(-1); + return(-6); } ptr = (int *) retmsg->buf; error = *ptr; - efree(retmsg); efree(retmsg->buf); + efree(retmsg); return(error); } @@ -2009,7 +2069,6 @@ int send_getremote(int sockfd, hw_objectID objectID, char **objattr, char **text build_msg_header(&msg, length, msgid++, GETOBJECT_MESSAGE); if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { -/* perror("send_command"); */ lowerror = LE_MALLOC; return(-1); } @@ -2045,7 +2104,6 @@ int send_getremote(int sockfd, hw_objectID objectID, char **objattr, char **text build_msg_header(&msg, length, msgid++, GETREMOTE_MESSAGE); if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { -/* perror("send_command"); */ lowerror = LE_MALLOC; return(-1); } @@ -2355,7 +2413,6 @@ int send_children(int sockfd, hw_objectID objectID, hw_objectID **childIDs, int 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); } @@ -3096,7 +3153,7 @@ int send_getreldestforanchorsobj(int sockfd, char **anchorrec, char ***reldestre if(anchorrec[i]) efree(anchorrec[i]); anchorrec[i] = NULL; } else { - int j, k, *retthisIDs, *retdestIDs, equaltill, mincount, countthis, countdest, destdocid; + int j, *retthisIDs, *retdestIDs, equaltill, mincount, countthis, countdest, destdocid; char destdocname[200]; char anchorstr[300]; char temp[200]; @@ -3114,6 +3171,7 @@ int send_getreldestforanchorsobj(int sockfd, char **anchorrec, char ***reldestre send_incollections(sockfd, 1, 1, &thisID, 1, &rootID, &countthis, &retthisIDs); send_incollections(sockfd, 1, 1, &destdocid, 1, &rootID, &countdest, &retdestIDs); +/* fprintf(stderr, "%d: ", thisID); for(k=0; k<countthis; k++) fprintf(stderr,"%d, ", retthisIDs[k]); @@ -3122,6 +3180,7 @@ fprintf(stderr,"%d: ", destdocid); for(k=0; k<countdest; k++) fprintf(stderr,"%d: %d, ", destdocid, retdestIDs[k]); fprintf(stderr,"\n"); +*/ mincount = (countthis < countdest) ? countthis : countdest; for(j=0; (j<mincount) && (retthisIDs[j]==retdestIDs[j]); j++) @@ -3132,7 +3191,7 @@ fprintf(stderr,"\n"); strcat(anchorstr, "../"); strcat(anchorstr, "./"); for(j=equaltill; j<countdest; j++) { - char *temprec, tempname[100], objectidstr[100]; + char *temprec, tempname[100]; send_getobject(sockfd, retdestIDs[j], &temprec); if(NULL != (str = strstr(temprec, "Name="))) { str += 5; @@ -3149,10 +3208,10 @@ fprintf(stderr,"\n"); *strptr = '_'; strptr++; } -fprintf(stderr, "Adding '%s' to '%s'\n", temp, anchorstr); +/* fprintf(stderr, "Adding '%s' to '%s'\n", temp, anchorstr); */ strcat(anchorstr, temp); strcat(anchorstr, "/"); -fprintf(stderr, "Is now '%s'\n", anchorstr); +/* fprintf(stderr, "Is now '%s'\n", anchorstr); */ efree(temprec); } /* if the anchor destination is a collection it may not be added anymore. */ @@ -3170,7 +3229,7 @@ fprintf(stderr, "Is now '%s'\n", anchorstr); strcat(anchorstr, "\n"); sprintf(temp, "ObjectID=0x%x", destdocid); strcat(anchorstr, temp); -fprintf(stderr, "%s\n", anchorstr); +/* fprintf(stderr, "%s\n", anchorstr); */ efree(retthisIDs); efree(retdestIDs); reldestptr[i] = estrdup(anchorstr); @@ -3233,7 +3292,7 @@ int fn_findpath(int sockfd, int *retIDs, int count, int id) { * document with id destID. * ********************************************************************/ int getrellink(int sockfd, int rootID, int thisID, int destID, char **reldeststr) { - int i, j, k, *retthisIDs, *retdestIDs, equaltill, count, mincount, countthis, countdest, destdocid; + int i, j, k, *retthisIDs, *retdestIDs, equaltill, count, mincount, countthis, countdest; char anchorstr[300]; char temp[200]; char *strptr; @@ -3300,7 +3359,7 @@ fprintf(stderr, "first unequal = %d\n", j); strcat(anchorstr, "../"); strcat(anchorstr, "./"); for(j=equaltill; j<countdest; j++) { - char *temprec, *str, tempname[100], objectidstr[100]; + char *temprec, *str, tempname[100]; if(0 == send_getobject(sockfd, retdestIDs[j], &temprec)) { if(NULL != (str = strstr(temprec, "Name="))) { str += 5; @@ -3387,6 +3446,100 @@ int send_identify(int sockfd, char *name, char *passwd, char **userdata) { return(0); } +int send_objectbyidquery(int sockfd, hw_objectID *IDs, int *count, char *query, char ***objrecs) +{ + hg_msg msg, *retmsg; + int length, error; + char *tmp, *str; + int *ptr, i, *ptr1; + int *offsets, *childIDs; + char **childrec; + + length = HEADER_LENGTH + sizeof(int) + sizeof(int) + *count * sizeof(hw_objectID); + if(query) + length = length + strlen(query) + 1; + + build_msg_header(&msg, length, msgid++, OBJECTBYIDQUERY_MESSAGE); + + if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { + lowerror = LE_MALLOC; + return(-1); + } + + tmp = build_msg_int(msg.buf, 1); + tmp = build_msg_int(tmp, *count); + for(i=0; i<*count; i++) + tmp = build_msg_int(tmp, IDs[i]); + if(query) + tmp = build_msg_str(tmp, query); + + if ( send_hg_msg(sockfd, &msg, length) == -1 ) { + efree(msg.buf); + return(-1); + } + efree(msg.buf); + retmsg = recv_hg_msg(sockfd); + if ( retmsg == NULL ) + return(-1); + + ptr = (int *) retmsg->buf; + if(ptr == NULL) { + if(retmsg) efree(retmsg); + return -1; + } + if(*ptr++ != 0) { + error = *((int *) retmsg->buf); + efree(retmsg->buf); + efree(retmsg); + return error; + } + + *count = *ptr++; + if(NULL != (childIDs = emalloc(*count * sizeof(hw_objectID)))) { + ptr1 = childIDs; + for(i=0; i<*count; ptr++, i++) + ptr1[i] = *ptr; + if(NULL != (offsets = emalloc(*count * sizeof(int)))) { + ptr1 = offsets; + for(i=0; i<*count; ptr++, i++) + ptr1[i] = *ptr; + } else { + efree(retmsg->buf); + efree(retmsg); + efree(childIDs); + lowerror = LE_MALLOC; + return(-1); + } + } else { + efree(retmsg->buf); + efree(retmsg); + lowerror = LE_MALLOC; + return(-1); + } + + str = (char *)ptr; + if(NULL == (childrec = (char **) emalloc(*count * sizeof(hw_objrec *)))) { + efree(offsets); + efree(childIDs); + efree(retmsg->buf); + efree(retmsg); + lowerror = LE_MALLOC; + return(-1); + } else { + for(i=0; i<*count; i++) { + childrec[i] = estrdup(str); + str += offsets[i]; + } + *objrecs = childrec; + } + + efree(retmsg->buf); + efree(retmsg); + efree(childIDs); + efree(offsets); + return(0); +} + int send_getobjbyquery(int sockfd, char *query, int maxhits, hw_objectID **childIDs, int *count) { hg_msg msg, *retmsg; @@ -3909,7 +4062,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) +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; @@ -3933,13 +4086,13 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in */ if(host) { if((hostptr = gethostbyname(host)) == NULL) { - php_error(E_WARNING, "gethostbyname failed for %s", host); - close(fd); - return(-1); + php3_error(E_WARNING, "gethostbyname failed for %s", host); + HWSOCK_FCLOSE(fd); + return(-2); } } else { - close(fd); - return(-1); + HWSOCK_FCLOSE(fd); + return(-2); } switch(hostptr->h_addrtype) { @@ -3951,20 +4104,20 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in hostip = inet_ntoa(*ptr1); break; default: - close(fd); - return(-1); + HWSOCK_FCLOSE(fd); + return(-3); break; } /* Bottom half of send_getobject */ if(0 > bh_send_getobject(sockfd, objectID)) { - close(fd); - return -1; + HWSOCK_FCLOSE(fd); + return -4; } /* Upper half of send_getobject */ if(0 > (error = uh_send_getobject(sockfd, &attributes))) { - close(fd); + HWSOCK_FCLOSE(fd); return error; } @@ -3973,7 +4126,7 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { lowerror = LE_MALLOC; - return(-1); + return(-5); } tmp = build_msg_int(msg.buf, objectID); @@ -3984,8 +4137,8 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in if ( send_hg_msg(sockfd, &msg, length) == -1 ) { if(attributes) efree(attributes); efree(msg.buf); - close(fd); - return(-1); + HWSOCK_FCLOSE(fd); + return(-6); } efree(msg.buf); @@ -3993,8 +4146,8 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in retmsg = recv_hg_msg(sockfd); if ( retmsg == NULL ) { if(attributes) efree(attributes); - close(fd); - return(-1); + HWSOCK_FCLOSE(fd); + return(-7); } ptr = (int *) retmsg->buf; @@ -4003,7 +4156,7 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in efree(retmsg); if(retmsg->buf) efree(retmsg->buf); if(attributes) efree(attributes); - close(fd); + HWSOCK_FCLOSE(fd); return(error); } @@ -4015,12 +4168,12 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in */ len = sizeof(serv_addr); if((newfd = accept(fd, (struct sockaddr *) &serv_addr, &len)) < 0) { -/* php_printf("client: can't open data connection to server\n"); */ +/* php3_printf("client: can't open data connection to server\n"); */ if(attributes) efree(attributes); - close(fd); - return(-1); + HWSOCK_FCLOSE(fd); + return(-8); } else { - close(fd); + HWSOCK_FCLOSE(fd); } /* First of all read the header */ @@ -4044,7 +4197,7 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in } /* close the data connection */ - close(newfd); + HWSOCK_FCLOSE(newfd); documenttype = fnAttributeValue(attributes, "DocumentType"); @@ -4071,7 +4224,7 @@ int send_pipedocument(int sockfd, char *host, hw_objectID objectID, int mode, in char *newtext; char *body; - newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body); + newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, urlprefix); dlst_kill(pAnchorList, fnDeleteAnchor); *bodytag = strdup(body); efree(body); @@ -4110,12 +4263,12 @@ int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str */ if(host) { if((hostptr = gethostbyname(host)) == NULL) { - php_error(E_WARNING, "gethostbyname failed for %s", host); - close(fd); + php3_error(E_WARNING, "gethostbyname failed for %s", host); + HWSOCK_FCLOSE(fd); return(-1); } } else { - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } @@ -4128,19 +4281,19 @@ int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str hostip = inet_ntoa(*ptr1); break; default: -/* php_printf(stderr, "unknown address type\n"); */ +/* php3_printf(stderr, "unknown address type\n"); */ break; } /* Bottom half of send_getobject */ if(0 > bh_send_getobject(sockfd, objectID)) { - close(fd); + HWSOCK_FCLOSE(fd); return -1; } /* Upper half of send_getobject */ if(0 > (error = uh_send_getobject(sockfd, &attributes))) { - close(fd); + HWSOCK_FCLOSE(fd); return error; } @@ -4167,7 +4320,7 @@ int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str if ( send_hg_msg(sockfd, &msg, length) == -1 ) { if(attributes) efree(attributes); efree(msg.buf); - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } efree(msg.buf); @@ -4176,7 +4329,7 @@ int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str retmsg = recv_hg_msg(sockfd); if ( retmsg == NULL ) { if(attributes) efree(attributes); - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } @@ -4185,7 +4338,7 @@ int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str efree(retmsg); if(retmsg->buf) efree(retmsg->buf); if(attributes) efree(attributes); - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } @@ -4198,10 +4351,10 @@ int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str len = sizeof(serv_addr); if((newfd = accept(fd, (struct sockaddr *) &serv_addr, &len)) < 0) { if(attributes) efree(attributes); - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } else { - close(fd); + HWSOCK_FCLOSE(fd); } /* First of all read the header */ @@ -4224,7 +4377,7 @@ int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str } /* close the data connection */ - close(newfd); + HWSOCK_FCLOSE(newfd); documenttype = fnAttributeValue(attributes, "DocumentType"); @@ -4238,7 +4391,7 @@ int send_pipecgi(int sockfd, char *host, hw_objectID objectID, char *cgi_env_str return(0); } -int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectRec, char *text, int count) +int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectRec, char *text, int count, hw_objectID *objectID) { hg_msg msg, *retmsg; int length, len; @@ -4246,7 +4399,7 @@ int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectR struct sockaddr_in serv_addr; struct hostent *hostptr; char *hostip = NULL; - int newfd, fd, port, objectID, error; + int newfd, fd, port, error; int *ptr; /* First of all we have to insert the document record */ @@ -4278,7 +4431,7 @@ int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectR ptr = (int *) retmsg->buf; if(0 == (error = *ptr)) { ptr++; - objectID = *ptr; + *objectID = *ptr; } else { efree(retmsg); if(retmsg->buf) efree(retmsg->buf); @@ -4293,7 +4446,7 @@ int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectR */ if(host) { if((hostptr = gethostbyname(host)) == NULL) { - php_error(E_WARNING, "gethostbyname failed for %s", host); + php3_error(E_WARNING, "gethostbyname failed for %s", host); /* close(fd); fd is not set yet */ return(-1); } @@ -4331,7 +4484,7 @@ int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectR return(-1); } - tmp = build_msg_int(msg.buf, objectID); + tmp = build_msg_int(msg.buf, *objectID); tmp = build_msg_int(tmp, port); tmp = build_msg_str(tmp, hostip); tmp = build_msg_str(tmp, "Hyperwave"); @@ -4339,7 +4492,7 @@ int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectR if ( send_hg_msg(sockfd, &msg, length) == -1 ) { efree(msg.buf); - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } efree(msg.buf); @@ -4349,10 +4502,10 @@ int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectR */ len = sizeof(serv_addr); if((newfd = accept(fd, (struct sockaddr *) &serv_addr, &len)) < 0) { - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } else { - close(fd); + HWSOCK_FCLOSE(fd); } /* First of all write the header. According to the documentation @@ -4364,24 +4517,24 @@ int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectR sprintf(header, "HGHDR\nsz=%d\nref=12345678\n", count); len = strlen(header) + 1; if(len != write_to(newfd, header, len, wtimeout)) { - close(newfd); + HWSOCK_FCLOSE(newfd); return(-1); } /* And now the document */ if(count != write_to(newfd, text, count, wtimeout)) { - close(newfd); + HWSOCK_FCLOSE(newfd); return(-1); } /* The data connection has to be close before the return msg can be read. The server will not sent it before. */ - close(newfd); + HWSOCK_FCLOSE(newfd); /* Just check if the command was understood */ retmsg = recv_hg_msg(sockfd); if ( retmsg == NULL ) { - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } @@ -4389,7 +4542,7 @@ int send_putdocument(int sockfd, char *host, hw_objectID parentID, char *objectR if((ptr == NULL) || (*ptr != 0)) { efree(retmsg); if(retmsg->buf) efree(retmsg->buf); - close(fd); + HWSOCK_FCLOSE(fd); return(-1); } @@ -4511,9 +4664,9 @@ int send_getsrcbydest(int sockfd, hw_objectID objectID, char ***childrec, int *c return(0); } -char *get_hw_info(hw_connection *conn) - { - char temp[200]; +#define BUFFERLEN 200 +char *get_hw_info(hw_connection *conn) { + char temp[BUFFERLEN]; int len; struct sockaddr_in serv_addr; @@ -4521,18 +4674,19 @@ char *get_hw_info(hw_connection *conn) if(getsockname(conn->socket, (struct sockaddr *)&serv_addr, &len) < 0) return(NULL); - sprintf(temp, "%s, %s, %d, %s, %d, %d", conn->server_string, conn->hostname, + snprintf(temp, BUFFERLEN, "%s, %s, %d, %s, %d, %d", conn->server_string, conn->hostname, conn->version, conn->username, serv_addr.sin_port, conn->swap_on); return(estrdup(temp)); - } +} +#undef BUFFERLEN static int send_hg_msg(int sockfd, hg_msg *msg, int length) { char *buf, *tmp; #ifdef HW_DEBUG - php_printf("<B>Sending msg: </B>type = %d -- id = %d<BR>\n", msg->msg_type, msg->version_msgid); + php3_printf("<B>Sending msg: </B>type = %d -- id = %d<BR>\n", msg->msg_type, msg->version_msgid); #endif if ( length < HEADER_LENGTH ) { /* fprintf(stderr, "send_hg_msg: bad msg\n"); */ @@ -4644,7 +4798,7 @@ static char *build_msg_int(char *buf, int val) { int tmp; #ifdef HW_DEBUG - php_printf(" Added int to header: <B>%d</B><BR>\n", val); + php3_printf(" Added int to header: <B>%d</B><BR>\n", val); #endif tmp = swap_on ? swap(val) : val; memcpy(buf, (char *)&tmp, 4); @@ -4658,7 +4812,7 @@ static char *build_msg_str(char *buf, char *str) int len = strlen(str)+1; #ifdef HW_DEBUG - php_printf(" Added str to header: <B>%s</B> (%d)<BR>\n", str, strlen(str)); + php3_printf(" Added str to header: <B>%s</B> (%d)<BR>\n", str, strlen(str)); #endif memcpy(buf, str, len); @@ -4682,8 +4836,8 @@ static int swap(int val) void close_hg_connection(int sockfd) { - shutdown(sockfd, 2); - close(sockfd); + shutdown(sockfd, 2); + HWSOCK_FCLOSE(sockfd); } #endif diff --git a/ext/hyperwave/hg_comm.h b/ext/hyperwave/hg_comm.h index b000c44c50..12503e8181 100644 --- a/ext/hyperwave/hg_comm.h +++ b/ext/hyperwave/hg_comm.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + | Copyright (c) 1997-1999 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | | it under the terms of the GNU General Public License as published by | @@ -36,7 +36,7 @@ #define F_DISTRIBUTED 0x80000000 #define F_COMPRESSED 0x40000000 #define F_VERSION 0x00003fff -#define VERSION 717L /* 7.05 */ +#define HW_VERSION 717L /* 7.17 */ #define HEADER_LENGTH 12 @@ -53,6 +53,7 @@ #define GETANCHORS_MESSAGE 8 #define GETOBJBYQUERY_MESSAGE 9 #define GETOBJBYQUERYCOLL_MESSAGE 10 +#define OBJECTBYIDQUERY_MESSAGE 11 #define GETTEXT_MESSAGE 12 #define INSDOC_MESSAGE 14 #define INSCOLL_MESSAGE 17 @@ -88,6 +89,18 @@ #define DOCUMENT 0 #define COLLECTION 1 + +#if WIN32|WINNT +# define SOCK_ERR INVALID_SOCKET +# define SOCK_CONN_ERR SOCKET_ERROR +# define HWSOCK_FCLOSE(s) closesocket(s) +#else +# define SOCK_ERR -1 +# define SOCK_CONN_ERR -1 +# define HWSOCK_FCLOSE(s) close(s) +#endif + + /* Low error messages */ #define LE_MALLOC -1 @@ -132,9 +145,9 @@ typedef struct { typedef int hw_objectID; typedef char hw_objrec; -void set_swap(int do_swap); +extern void set_swap(int do_swap); extern int open_hg_connection(char *server_name, int port); -void close_hg_connection(int sockfd); +extern void close_hg_connection(int sockfd); extern int initialize_hg_connection(int sockfd, int *do_swap, int *version, char **userdata, char **server_string, char *username, char *password); extern int send_ready(int sockfd); @@ -150,10 +163,12 @@ extern int getrellink(int sockfd, int rootID, int thisID, int destID, char **rel 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_lock(int sockfd, hw_objectID objectID); extern int send_unlock(int sockfd, hw_objectID objectID); -extern int send_gettext(int sockfd, hw_objectID objectID, int mode, int rootid, char **objattr, char **bodytag, char **text, int *count); +extern int send_gettext(int sockfd, hw_objectID objectID, int mode, int rootid, char **objattr, char **bodytag, char **text, int *count, char *urlprefix); extern int send_edittext(int sockfd, char *objattr, char *text); extern int send_getcgi(int sockfd, hw_objectID objectID, char *cgi_env_str, char **objattr, char **text, int *count); extern int send_getremote(int sockfd, hw_objectID objectID, char **objattr, char **text, int *count); @@ -168,6 +183,7 @@ extern int send_getchilddoccoll(int sockfd, hw_objectID objectID, hw_objectID ** extern int send_getchilddoccollobj(int sockfd, hw_objectID objectID, hw_objrec ***childrec, int *count); extern int send_getanchors(int sockfd, hw_objectID objectID, hw_objectID **anchorIDs, int *count); extern int send_getanchorsobj(int sockfd, hw_objectID objectID, char ***childrec, int *count); +extern int send_objectbyidquery(int sockfd, hw_objectID *IDs, int *count, char *query, char ***objrecs); extern int send_getobjbyquery(int sockfd, char *query, int maxhits, hw_objectID **childIDs, int *count); extern int send_getobjbyqueryobj(int sockfd, char *query, int maxhits, char ***childrec, int *count); extern int send_getobjbyquerycoll(int sockfd, hw_objectID collID, char *query, int maxhits, hw_objectID **childIDs, int *count); @@ -176,9 +192,9 @@ 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); +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 objectID, char *objectRec, 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); extern int send_insertobject(int sockfd, char *objrec, char *parms, hw_objectID *objectID); extern int send_insdoc(int sockfd, hw_objectID objectID, char *objrec, char *text, hw_objectID *new_objectID); diff --git a/ext/hyperwave/hw.c b/ext/hyperwave/hw.c index de6597d043..cd4d8823ed 100644 --- a/ext/hyperwave/hw.c +++ b/ext/hyperwave/hw.c @@ -23,16 +23,22 @@ #include <stdlib.h> -#if !(WIN32|WINNT) -#include "php_config.h" -#endif #include "php.h" +#include "php_globals.h" +#include "ext/standard/php3_standard.h" #include "ext/standard/head.h" +#include "ext/standard/info.h" +#include "SAPI.h" -#if HYPERWAVE +#if WIN32|WINNT +#include <winsock.h> +#else +#include "build-defs.h" +#endif +#if HYPERWAVE -#include "hw.h" +#include "php3_hyperwave.h" #if APACHE # ifndef DEBUG @@ -72,6 +78,7 @@ function_entry hw_functions[] = { PHP_FE(hw_cp, NULL) PHP_FE(hw_deleteobject, NULL) PHP_FE(hw_changeobject, NULL) + PHP_FE(hw_modifyobject, NULL) PHP_FE(hw_docbyanchor, NULL) PHP_FE(hw_docbyanchorobj, NULL) PHP_FE(hw_getobjectbyquery, NULL) @@ -88,14 +95,11 @@ function_entry hw_functions[] = { PHP_FE(hw_free_document, NULL) PHP_FE(hw_new_document, NULL) PHP_FE(hw_output_document, NULL) - PHP_FE(hw_outputdocument, NULL) PHP_FE(hw_document_size, NULL) - PHP_FE(hw_documentsize, NULL) PHP_FE(hw_document_attributes, NULL) - PHP_FE(hw_documentattributes, NULL) PHP_FE(hw_document_bodytag, NULL) - PHP_FE(hw_documentbodytag, NULL) PHP_FE(hw_document_content, NULL) + PHP_FE(hw_document_setcontent, NULL) PHP_FE(hw_objrec2array, NULL) PHP_FE(hw_array2objrec, NULL) PHP_FE(hw_incollections, NULL) @@ -219,11 +223,14 @@ int make_return_objrec(pval **return_value, char **objrecs, int count) ** creates an array return value from object record */ int make_return_array_from_objrec(pval **return_value, char *objrec) { - pval title_arr, desc_arr; char *attrname, *str, *temp, language[3], *title; - int iTitle, iDesc; + int iTitle, iDesc, iKeyword; + pval title_arr; + pval desc_arr; + pval keyword_arr; int hasTitle = 0; int hasDescription = 0; + int hasKeyword = 0; if (array_init(*return_value) == FAILURE) { (*return_value)->type = IS_STRING; @@ -232,37 +239,37 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { return -1; } - /* Array for titles. Only if we have at least one title */ -/* if(0 == strncmp(objrec, "Title=", 6)) { */ - if (array_init(&title_arr) == FAILURE) { - return -1; - } - hasTitle = 1; -/* } */ - - /* Array for Descriptions. Only if we have at least one description */ -/* if(0 == strncmp(objrec, "Description=", 12)) { */ - if (array_init(&desc_arr) == FAILURE) { - return -1; - } - hasDescription = 1; -/* } */ - - /* Fill Array of titles and descriptions */ + /* Fill Array of titles, descriptions and keywords */ temp = estrdup(objrec); attrname = strtok(temp, "\n"); while(attrname != NULL) { str = attrname; iTitle = 0; iDesc = 0; + iKeyword = 0; if(0 == strncmp(attrname, "Title=", 6)) { + if ((hasTitle == 0) && (array_init(&title_arr) == FAILURE)) { + return -1; + } + hasTitle = 1; str += 6; iTitle = 1; } else if(0 == strncmp(attrname, "Description=", 12)) { + if ((hasDescription == 0) && (array_init(&desc_arr) == FAILURE)) { + return -1; + } + hasDescription = 1; str += 12; iDesc = 1; - } - if(iTitle || iDesc) { /* Poor error check if end of string */ + } else if(0 == strncmp(attrname, "Keyword=", 8)) { + if ((hasKeyword == 0) && (array_init(&keyword_arr) == FAILURE)) { + return -1; + } + hasKeyword = 1; + str += 8; + iKeyword = 1; + } + if(iTitle || iDesc || iKeyword) { /* Poor error check if end of string */ if(str[2] == ':') { str[2] = '\0'; strcpy(language, str); @@ -271,13 +278,12 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { strcpy(language, "xx"); title = str; -/* while((*str != '=') && (*str != '\0')) - str++; - *str = '\0'; -*/ if(iTitle) + if(iTitle) add_assoc_string(&title_arr, language, title, 1); - else + else if(iDesc) add_assoc_string(&desc_arr, language, title, 1); + else if(iKeyword) + add_assoc_string(&keyword_arr, language, title, 1); } attrname = strtok(NULL, "\n"); } @@ -297,14 +303,22 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { /* The description array can now be freed, but I don't know how */ } + if(hasKeyword) { + /* Add the keyword array, if we have one */ + zend_hash_update((*return_value)->value.ht, "Keyword", 8, &keyword_arr, sizeof(pval), NULL); + + /* The keyword array can now be freed, but I don't know how */ + } + /* All other attributes. Make a another copy first */ temp = estrdup(objrec); attrname = strtok(temp, "\n"); while(attrname != NULL) { str = attrname; - /* We don't want to insert titles a second time */ + /* We don't want to insert titles, descr., keywords a second time */ if((0 != strncmp(attrname, "Title=", 6)) && - (0 != strncmp(attrname, "Description=", 12))) { + (0 != strncmp(attrname, "Description=", 12)) && + (0 != strncmp(attrname, "Keyword=", 8))) { while((*str != '=') && (*str != '\0')) str++; *str = '\0'; @@ -318,10 +332,11 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { return(0); } +#define BUFFERLEN 1024 static char * make_objrec_from_array(HashTable *lht) { int i, count, keytype; ulong length; - char *key, str[1024], *objrec = NULL; + char *key, str[BUFFERLEN], *objrec = NULL; pval *keydata; if(NULL == lht) @@ -339,11 +354,43 @@ static char * make_objrec_from_array(HashTable *lht) { zend_hash_get_current_data(lht, (void **) &keydata); switch(keydata->type) { case IS_STRING: - sprintf(str, "%s=%s\n", key, keydata->value.str.val); + snprintf(str, BUFFERLEN, "%s=%s\n", key, keydata->value.str.val); break; case IS_LONG: - sprintf(str, "%s=0x%lX\n", key, keydata->value.lval); + snprintf(str, BUFFERLEN, "%s=0x%lX\n", key, keydata->value.lval); + break; + case IS_ARRAY: { + int i, len, keylen, count; + char *strarr, *ptr, *ptr1; + count = zend_hash_num_elements(keydata->value.ht); + if(count > 0) { + strarr = make_objrec_from_array(keydata->value.ht); + len = strlen(strarr) - 1; + keylen = strlen(key); + if(NULL == (ptr = malloc(len + 1 + count*(keylen+1)))) { + free(objrec); + return(NULL); + } + ptr1 = ptr; + *ptr1 = '\0'; + strcpy(ptr1, key); + ptr1 += keylen; + *ptr1++ = '='; + for(i=0; i<len; i++) { + *ptr1++ = strarr[i]; + if(strarr[i] == '\n') { + strcpy(ptr1, key); + ptr1 += keylen; + *ptr1++ = '='; + } else if(strarr[i] == '=') + ptr1[-1] = ':'; + } + *ptr1++ = '\n'; + *ptr1 = '\0'; + strncpy(str, ptr, 1023); + } break; + } } efree(key); objrec = realloc(objrec, strlen(objrec)+strlen(str)+1); @@ -353,6 +400,7 @@ static char * make_objrec_from_array(HashTable *lht) { } return objrec; } +#undef BUFFERLEN static int * make_ints_from_array(HashTable *lht) { int i, count; @@ -382,8 +430,7 @@ static int * make_ints_from_array(HashTable *lht) { return objrec; } -PHP_MINIT_FUNCTION(hw) -{ +PHP_MINIT_FUNCTION(hw) { if (cfg_get_long("hw.allow_persistent",&php3_hw_module.allow_persistent)==FAILURE) { php3_hw_module.allow_persistent=1; @@ -402,6 +449,7 @@ PHP_MINIT_FUNCTION(hw) return SUCCESS; } +#define BUFFERLEN 30 static void php3_hw_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) { pval *argv[4]; @@ -415,7 +463,7 @@ static void php3_hw_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) char *password = NULL; char *hashed_details; char *str = NULL; - char buffer[20]; + char buffer[BUFFERLEN]; int hashed_details_length; hw_connection *ptr; int do_swap; @@ -424,10 +472,6 @@ static void php3_hw_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) argc = ARG_COUNT(ht); switch(argc) { case 2: - if (getParametersArray(ht, argc, argv) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; case 4: if (getParametersArray(ht, argc, argv) == FAILURE) { WRONG_PARAM_COUNT; @@ -456,7 +500,7 @@ static void php3_hw_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } /* Create identifier string for connection */ - sprintf(buffer, "%d", port); + snprintf(buffer, BUFFERLEN, "%d", port); hashed_details_length = strlen(host)+strlen(buffer)+8; if(NULL == (hashed_details = (char *) emalloc(hashed_details_length+1))) { if(host) efree(host); @@ -465,7 +509,7 @@ static void php3_hw_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) php_error(E_ERROR, "Could not get memory for connection details"); RETURN_FALSE; } - sprintf(hashed_details,"hw_%s_%d",host,port); + sprintf(hashed_details, "hw_%s_%d", host, port); if (persistent) { list_entry *le; @@ -662,6 +706,7 @@ static void php3_hw_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) ptr->username = NULL; efree(userdata); } +#undef BUFFERLEN /* Start of user level functions */ /* ***************************** */ @@ -839,6 +884,18 @@ PHP_FUNCTION(hw_errormsg) case LOCKED: sprintf(errstr, "Object locked; try again later"); break; + case NOTREMOVED: + sprintf(errstr, "Attribute not removed"); + break; + case CHANGEBASEFLD: + sprintf(errstr, "Change of base-attribute"); + break; + case FLDEXISTS: + sprintf(errstr, "Attribute exists"); + break; + case NOLANGUAGE: + sprintf(errstr, "No or unknown language specified"); + break; default: sprintf(errstr, "Unknown error: %d", ptr->lasterror); } @@ -846,7 +903,7 @@ PHP_FUNCTION(hw_errormsg) } /* }}} */ -/* {{{ proto hw_root(void) +/* {{{ proto int hw_root(void) Returns object id of root collection */ PHP_FUNCTION(hw_root) { @@ -909,6 +966,11 @@ PHP_FUNCTION(hw_who) { ptr = object; +php_printf("%s\n", ptr); + /* Skip first two lines, they just contain: + Users in Database + + */ while((*ptr != '\0') && (*ptr != '\n')) ptr++; while((*ptr != '\0') && (*ptr != '\n')) @@ -935,7 +997,7 @@ PHP_FUNCTION(hw_who) { } ptr = attrname; - if(*ptr == '*') + if(*ptr++ == '*') add_assoc_long(&user_arr, "self", 1); else add_assoc_long(&user_arr, "self", 0); @@ -1007,6 +1069,8 @@ PHP_FUNCTION(hw_who) { } /* }}} */ +/* {{{ proto string hw_dummy(int link, int id, int msgid) + ??? */ PHP_FUNCTION(hw_dummy) { pval *arg1, *arg2, *arg3; int link, id, type, msgid; @@ -1039,21 +1103,35 @@ php_printf("%s", object); return_value->type = IS_STRING; } } +/* }}} */ /* {{{ proto string hw_getobject(int link, int objid) Returns object record */ PHP_FUNCTION(hw_getobject) { - pval *arg1, *arg2; - int link, id, type; + pval *argv[3]; + int argc, link, id, type, multi; hw_connection *ptr; - if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + argc = ARG_COUNT(ht); + if(argc < 2 || argc > 3) + WRONG_PARAM_COUNT; + if (getParametersArray(ht, argc, argv) == FAILURE) WRONG_PARAM_COUNT; + + convert_to_long(argv[0]); + if(argv[1]->type == IS_ARRAY) { + multi = 1; + convert_to_array(argv[1]); + } else { + multi = 0; + convert_to_long(argv[1]); } - convert_to_long(arg1); - convert_to_long(arg2); - link=arg1->value.lval; - id=arg2->value.lval; + + if(argc == 3) { + convert_to_string(argv[2]); + } + + link=argv[0]->value.lval; ptr = php3_list_find(link,&type); if(!ptr || (type!=php3_hw_module.le_socketp && type!=php3_hw_module.le_psocketp)) { php_error(E_WARNING,"Unable to find file identifier %d",id); @@ -1061,16 +1139,52 @@ PHP_FUNCTION(hw_getobject) { } set_swap(ptr->swap_on); - { - char *object = NULL; - if (0 != (ptr->lasterror = send_getobject(ptr->socket, id, &object))) - RETURN_FALSE; + if(multi) { + char **objects = NULL; + int count, *ids, i; + HashTable *lht; + pval *keydata; + + lht = argv[1]->value.ht; + if(0 == (count = zend_hash_num_elements(lht))) + RETURN_FALSE; + ids = emalloc(count * sizeof(hw_objectID)); - RETURN_STRING(object, 0); - /* - make_return_array_from_objrec(&return_value, object); - efree(object); - */ + zend_hash_internal_pointer_reset(lht); + for(i=0; i<count; i++) { + zend_hash_get_current_data(lht, (void **) &keydata); + switch(keydata->type) { + case IS_LONG: + ids[i] = keydata->value.lval; + break; + default: + ids[i] = keydata->value.lval; + } + zend_hash_move_forward(lht); + } + + if (0 != (ptr->lasterror = send_objectbyidquery(ptr->socket, ids, &count, argv[2]->value.str.val, &objects))) { + efree(ids); + RETURN_FALSE; + } + efree(ids); + if (array_init(return_value) == FAILURE) { + efree(objects); + RETURN_FALSE; + } + + for(i=0; i<count; i++) { + add_index_string(return_value, i, objects[i], 0); + } + efree(objects); + + } else { + char *object = NULL; + id=argv[1]->value.lval; + if (0 != (ptr->lasterror = send_getobject(ptr->socket, id, &object))) + RETURN_FALSE; + + RETURN_STRING(object, 0); } } /* }}} */ @@ -1132,7 +1246,6 @@ PHP_FUNCTION(hw_getandlock) { set_swap(ptr->swap_on); { char *object = NULL; - char *attrname, *str; if (0 != (ptr->lasterror = send_getandlock(ptr->socket, id, &object))) RETURN_FALSE; @@ -1197,12 +1310,14 @@ PHP_FUNCTION(hw_deleteobject) { /* }}} */ /* {{{ proto void hw_changeobject(int link, int objid, array attributes) - Changes attributes of an object */ + Changes attributes of an object (obsolete) */ +#define BUFFERLEN 200 PHP_FUNCTION(hw_changeobject) { pval *arg1, *arg2, *arg3; int link, id, type, i; hw_connection *ptr; - char *modification, *oldobjrec, buf[200]; + char *modification, *oldobjrec, buf[BUFFERLEN]; + char *tmp; HashTable *newobjarr; if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) { @@ -1221,13 +1336,13 @@ PHP_FUNCTION(hw_changeobject) { } /* get the old object record */ - if(0 != (ptr->lasterror = send_getobject(ptr->socket, id, &oldobjrec))) + if(0 != (ptr->lasterror = send_getandlock(ptr->socket, id, &oldobjrec))) RETURN_FALSE; zend_hash_internal_pointer_reset(newobjarr); modification = strdup(""); for(i=0; i<zend_hash_num_elements(newobjarr); i++) { - char *key, *str, *str1, newattribute[200]; + char *key, *str, *str1, newattribute[BUFFERLEN]; pval *data; int j, noinsert=1; ulong ind; @@ -1237,24 +1352,24 @@ PHP_FUNCTION(hw_changeobject) { switch(data->type) { case IS_STRING: if(strlen(data->value.str.val) == 0) - noinsert = 0; + snprintf(newattribute, BUFFERLEN, "rem %s", key); else - sprintf(newattribute, "%s=%s", key, data->value.str.val); + snprintf(newattribute, BUFFERLEN, "add %s=%s", key, data->value.str.val); + noinsert = 0; break; default: - sprintf(newattribute, "%s", ""); + newattribute[0] = '\0'; } - if(!noinsert) { modification = fnInsStr(modification, 0, "\\"); modification = fnInsStr(modification, 0, newattribute); - modification = fnInsStr(modification, 0, "add "); +/* modification = fnInsStr(modification, 0, "add "); */ /* Retrieve the old attribute from object record */ if(NULL != (str = strstr(oldobjrec, key))) { str1 = str; j = 0; - while((str1 != NULL) && (*str1 != '\n')) { + while((str1 != NULL) && (*str1 != '\n') && (j < BUFFERLEN-1)) { buf[j++] = *str1++; } buf[j] = '\0'; @@ -1270,12 +1385,246 @@ PHP_FUNCTION(hw_changeobject) { set_swap(ptr->swap_on); modification[strlen(modification)-1] = '\0'; -/* php_printf("0x%X, %s", id, modification); */ - if (0 != (ptr->lasterror = send_changeobject(ptr->socket, id, modification))) + if (0 != (ptr->lasterror = send_changeobject(ptr->socket, id, modification))) { + free(modification); + send_unlock(ptr->socket, id); + RETURN_FALSE; + } + free(modification); + if (0 != (ptr->lasterror = send_unlock(ptr->socket, id))) { + RETURN_FALSE; + } + RETURN_TRUE; +} +#undef BUFFERLEN +/* }}} */ + +/* {{{ proto void hw_modifyobject(int link, int objid, array remattributes, array addattributes, [int mode]) + Modifies attributes of an object */ +#define BUFFERLEN 200 +PHP_FUNCTION(hw_modifyobject) { + pval *argv[5]; + int argc; + int link, id, type, i, mode; + hw_connection *ptr; + char *modification; + HashTable *remobjarr, *addobjarr; + + argc = ARG_COUNT(ht); + if((argc > 5) || (argc < 4)) + WRONG_PARAM_COUNT; + + if (getParametersArray(ht, argc, argv) == FAILURE) + if(argc < 4) { + WRONG_PARAM_COUNT; + } + 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)) { + php_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; + } + + modification = strdup(""); + if(addobjarr != NULL) { + zend_hash_internal_pointer_reset(addobjarr); + for(i=0; i<zend_hash_num_elements(addobjarr); i++) { + char *key, addattribute[BUFFERLEN]; + pval *data; + int noinsert=1; + ulong ind; + + zend_hash_get_current_key(addobjarr, &key, &ind); + zend_hash_get_current_data(addobjarr, (void *) &data); + switch(data->type) { + case IS_STRING: + if(strlen(data->value.str.val) > 0) { + snprintf(addattribute, BUFFERLEN, "add %s=%s", key, data->value.str.val); +/* fprintf(stderr, "add: %s\n", addattribute); */ + noinsert = 0; + } + break; + case IS_ARRAY: { + int i, len, keylen, count; + char *strarr, *ptr, *ptr1; + count = zend_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 = '\0'; + strncpy(addattribute, ptr, BUFFERLEN); + noinsert = 0; + } + break; + } + } + if(!noinsert) { + modification = fnInsStr(modification, 0, "\\"); + modification = fnInsStr(modification, 0, addattribute); + } + efree(key); + 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]; + pval *data; + int noinsert=1; + ulong ind; + + zend_hash_get_current_key(remobjarr, &key, &ind); + zend_hash_get_current_data(remobjarr, (void *) &data); + switch(data->type) { + case IS_STRING: + 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 = zend_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; + } + } + if(!noinsert) { + modification = fnInsStr(modification, 0, "\\"); + modification = fnInsStr(modification, 0, remattribute); + } + efree(key); + 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,"Aiii, Changeobject failed and couldn't unlock object (id = 0x%X)", id); + free(modification); + RETURN_FALSE; + } + free(modification); + RETURN_FALSE; + } else { + send_unlock(ptr->socket, id); + free(modification); + RETURN_FALSE; + } + } else { + php_error(E_WARNING,"Could not lock object (id = 0x%X)", 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,"hw_modifyobject: Mode must be 0 or 1 (recursive)"); + } free(modification); RETURN_TRUE; } +#undef BUFFERLEN /* }}} */ void php3_hw_mvcp(INTERNAL_FUNCTION_PARAMETERS, int mvcp) { @@ -1285,6 +1634,7 @@ void php3_hw_mvcp(INTERNAL_FUNCTION_PARAMETERS, int mvcp) { hw_connection *ptr; int collIDcount, docIDcount, i, *docIDs, *collIDs; +fprintf(stderr, "Copy/Move %d\n", mvcp); switch(mvcp) { case MOVE: /* Move also has fromID */ if (ARG_COUNT(ht) != 4 || getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE) @@ -1356,7 +1706,6 @@ void php3_hw_mvcp(INTERNAL_FUNCTION_PARAMETERS, int mvcp) { } } efree(objvIDs); - if (0 != (ptr->lasterror = send_mvcpdocscoll(ptr->socket, docIDs, docIDcount, from, dest, mvcp))) { efree(collIDs); efree(docIDs); @@ -1395,6 +1744,7 @@ PHP_FUNCTION(hw_gettext) { pval *argv[3]; int argc, link, id, type, mode; int rootid = 0; + char *urlprefix; hw_document *doc; hw_connection *ptr; @@ -1407,12 +1757,21 @@ PHP_FUNCTION(hw_gettext) { convert_to_long(argv[0]); convert_to_long(argv[1]); + mode = 0; + urlprefix = NULL; if(argc == 3) { - convert_to_long(argv[2]); - rootid = argv[2]->value.lval; - mode = 1; - } else - mode = 0; + switch(argv[2]->type) { + case IS_LONG: + convert_to_long(argv[2]); + rootid = argv[2]->value.lval; + mode = 1; + break; + case IS_STRING: + convert_to_string(argv[2]); + urlprefix = argv[2]->value.str.val; + break; + } + } link=argv[0]->value.lval; id=argv[1]->value.lval; ptr = php3_list_find(link,&type); @@ -1428,7 +1787,7 @@ PHP_FUNCTION(hw_gettext) { 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))) + 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; @@ -1445,7 +1804,7 @@ PHP_FUNCTION(hw_gettext) { Modifies text document */ PHP_FUNCTION(hw_edittext) { pval *arg1, *arg2; - int link, id, doc, type; + int link, doc, type; hw_connection *ptr; hw_document *docptr; @@ -1457,18 +1816,16 @@ PHP_FUNCTION(hw_edittext) { link=arg1->value.lval; ptr = php3_list_find(link,&type); - /* FIXME id is not set anywhere */ if(!ptr || (type!=php3_hw_module.le_socketp && type!=php3_hw_module.le_psocketp)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php_error(E_WARNING,"Unable to find socket identifier %d",link); RETURN_FALSE; } doc=arg2->value.lval; docptr = php3_list_find(doc,&type); - /* FIXME id is not set anywhere */ if(!docptr || (type!=php3_hw_module.le_document)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php_error(E_WARNING,"Unable to find document identifier %d", doc); RETURN_FALSE; } @@ -1484,12 +1841,14 @@ PHP_FUNCTION(hw_edittext) { /* {{{ 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[1000]; + char cgi_env_str[BUFFERLEN]; if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -1519,12 +1878,12 @@ PHP_FUNCTION(hw_getcgi) { requires. */ #if (WIN32|WINNT) - sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s", + 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 - sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s", + 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); @@ -1541,10 +1900,11 @@ PHP_FUNCTION(hw_getcgi) { return_value->type = IS_LONG; } } +#undef BUFFERLEN /* }}} */ -/* {{{ proto hwdoc hw_getremote(int link, int objid) - Returns the output of a remote document */ +/* {{{ 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; @@ -1583,8 +1943,8 @@ PHP_FUNCTION(hw_getremote) { } /* }}} */ -/* {{{ proto [array|hwdoc] hw_getremotechildren(int link, int objid) - Returns the remote document if only one or an array of object records */ +/* {{{ 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; @@ -1610,15 +1970,61 @@ PHP_FUNCTION(hw_getremotechildren) { 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); +*/ + /* The remainder depends on the number of returned objects and + whether the MimeType of the object to retrieve is set. If + the MimeType is set the result will start with the + HTTP header 'Content-type: mimetype', otherwise it will be + a list of object records and therefore starts with + 'ObjectID=0'. In the first case the offset and count are somewhat + strange. Quite often count had a value of 6 which appears to be + meaningless, but if you sum up the offsets you get the length + of the remainder which is the lenght of the document. + The document must have been chopped up into 6 pieces, each ending + with 'ServerId=0xYYYYYYYY'. + In the second case the offset contains the lenght of + each object record; count contains the number of object records. + Even if a remote object has children + (several sql statements) but the MimeType is set, it will + return a document in the format of MimeType. On the other + hand a remote object does not have any children but just + returns a docuement will not be shown unless the MimeType + is set. It returns the pure object record of the object without + the SQLStatement attribute. Quite senseless. + Though, this behavior depends on how the hgi gateway in Hyperwave + is implemented. + */ if(strncmp(remainder, "ObjectID=0 ", 10)) { hw_document *doc; - remainder[offsets[0]-18] = '\0'; -/*php_printf("offset = %d, remainder = %s---", offsets[0], remainder);*/ + char *ptr; + int i, j, len; + /* For some reason there is always the string + 'SeverId=0xYYYYYYYY' at the end, so we cut it off. + The document may as well be divided into several pieces + and each of them has the ServerId at the end. + The following will put the pieces back together and + strip the ServerId. count contains the number of pieces. + */ + for(i=0, len=0; i<count; i++) + len += offsets[i]-18; +/*fprintf(stderr,"len = %d\n", len); */ doc = malloc(sizeof(hw_document)); - doc->data = strdup(remainder); + doc->data = malloc(len+1); + ptr = doc->data; + for(i=0, j=0; i<count; i++) { + memcpy((char *)ptr, (char *)&remainder[j], offsets[i]-18); +/*fprintf(stderr,"rem = %s\n", &remainder[j]); */ + j += offsets[i]; + ptr += offsets[i] - 18; + } + *ptr = '\0'; doc->attributes = strdup(objrec); doc->bodytag = NULL; - doc->size = offsets[0]-18; + doc->size = strlen(doc->data); return_value->value.lval = php3_list_insert(doc,php3_hw_module.le_document); return_value->type = IS_LONG; } else { @@ -1675,10 +2081,7 @@ PHP_FUNCTION(hw_pipedocument) { hw_connection *ptr; hw_document *doc; #if APACHE - server_rec *serv; - SLS_FETCH(); - - serv = ((request_rec *) SG(server_context))->server; + server_rec *serv = ((request_rec *) SG(server_context))->server; #endif argc = ARG_COUNT(ht); @@ -1720,9 +2123,9 @@ PHP_FUNCTION(hw_pipedocument) { #if APACHE serv->server_hostname, #else - getenv("HOST"), + getenv("HOSTNAME"), #endif - id, mode, rootid, &attributes, &bodytag, &object, &count))) + id, mode, rootid, &attributes, &bodytag, &object, &count, NULL))) RETURN_FALSE; doc = malloc(sizeof(hw_document)); @@ -1730,14 +2133,17 @@ PHP_FUNCTION(hw_pipedocument) { doc->attributes = attributes; doc->bodytag = bodytag; doc->size = count; -fprintf(stderr, "size = %d\n", count); +/* fprintf(stderr, "size = %d\n", count); */ return_value->value.lval = php3_list_insert(doc,php3_hw_module.le_document); return_value->type = IS_LONG; } -} /* }}} */ +} +/* }}} */ /* {{{ proto hwdoc hw_pipecgi(int link, int objid) Returns output of cgi script */ +#define BUFFERLEN 1000 +/* FIX ME: The buffer cgi_env_str should be allocated dynamically */ PHP_FUNCTION(hw_pipecgi) { pval *arg1, *arg2; int link, id, type; @@ -1745,10 +2151,7 @@ PHP_FUNCTION(hw_pipecgi) { hw_document *doc; char cgi_env_str[1000]; #if APACHE - server_rec *serv; - SLS_FETCH(); - - serv = ((request_rec *) SG(server_context))->server; + server_rec *serv = ((request_rec *) SG(server_context))->server; #endif if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { @@ -1771,12 +2174,12 @@ PHP_FUNCTION(hw_pipecgi) { int count; #if (WIN32|WINNT) - sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s", + 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 - sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s", + 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); @@ -1786,7 +2189,7 @@ PHP_FUNCTION(hw_pipecgi) { #if APACHE serv->server_hostname, #else - getenv("HOST"), + getenv("HOSTNAME"), #endif id, cgi_env_str, &attributes, &object, &count))) RETURN_FALSE; @@ -1799,7 +2202,9 @@ PHP_FUNCTION(hw_pipecgi) { return_value->value.lval = php3_list_insert(doc,php3_hw_module.le_document); return_value->type = IS_LONG; } -} /* }}} */ +} +#undef BUFFERLEN +/* }}} */ /* {{{ proto void hw_insertdocument(int link, int parentid, hwdoc doc) Insert new document */ @@ -1808,11 +2213,9 @@ PHP_FUNCTION(hw_insertdocument) { int link, id, doc, type; hw_connection *ptr; hw_document *docptr; + hw_objectID objid; #if APACHE - server_rec *serv; - SLS_FETCH(); - - serv = ((request_rec *) SG(server_context))->server; + server_rec *serv = ((request_rec *) SG(server_context))->server; #endif if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) { @@ -1842,19 +2245,21 @@ PHP_FUNCTION(hw_insertdocument) { #if APACHE serv->server_hostname, #else - getenv("HOST"), + getenv("HOSTNAME"), #endif - id, docptr->attributes, docptr->data, docptr->size))) { + id, docptr->attributes, docptr->data, docptr->size, &objid))) { RETURN_FALSE; } } - RETURN_TRUE; -} /* }}} */ + RETURN_LONG(objid); +} +/* }}} */ -/* {{{ proto hwdoc hw_new_document(int link, string data, string objrec, int size) +/* {{{ proto hwdoc hw_new_document(string objrec, string data, int size) Create a new document */ PHP_FUNCTION(hw_new_document) { pval *arg1, *arg2, *arg3; + char *ptr; hw_document *doc; if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) { @@ -1866,14 +2271,23 @@ PHP_FUNCTION(hw_new_document) { convert_to_long(arg3); doc = malloc(sizeof(hw_document)); - doc->data = malloc(arg3->value.lval); + if(NULL == doc) + RETURN_FALSE; + doc->data = malloc(arg3->value.lval+1); + if(NULL == doc->data) { + free(doc); + RETURN_FALSE; + } memcpy(doc->data, arg2->value.str.val, arg3->value.lval); + ptr = doc->data; + ptr[arg3->value.lval] = '\0'; doc->attributes = strdup(arg1->value.str.val); doc->bodytag = NULL; doc->size = arg3->value.lval; return_value->value.lval = php3_list_insert(doc,php3_hw_module.le_document); return_value->type = IS_LONG; -} /* }}} */ +} +/* }}} */ /* {{{ proto void hw_free_document(hwdoc doc) Frees memory of document */ @@ -1894,15 +2308,19 @@ PHP_FUNCTION(hw_free_document) { } php3_list_delete(id); RETURN_TRUE; -} /* }}} */ +} +/* }}} */ + +/* {{{ proto void hw_outputdocument(hwdoc doc) + An alias for hw_output_document */ +/* }}} */ /* {{{ proto void hw_output_document(hwdoc doc) Prints document */ PHP_FUNCTION(hw_output_document) { pval *arg1; - int id, type, count; + int id, type; hw_document *ptr; - char *ptr1; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -1915,15 +2333,16 @@ PHP_FUNCTION(hw_output_document) { RETURN_FALSE; } - ptr1 = ptr->data; - count = 0; - while(count < ptr->size) { - php3_write(ptr1++, 1); - count++; - } + php3_header(); + php3_write(ptr->data, ptr->size); RETURN_TRUE; -} /* }}} */ +} +/* }}} */ + +/* {{{ proto string hw_documentbodytag(hwdoc doc [, string prefix]) + An alias for hw_document_bodytag */ +/* }}} */ /* {{{ proto string hw_document_bodytag(hwdoc doc [, string prefix]) Return bodytag prefixed by prefix */ @@ -1962,7 +2381,8 @@ PHP_FUNCTION(hw_document_bodytag) { } else { RETURN_STRING(ptr->bodytag, 1); } -} /* }}} */ +} +/* }}} */ /* {{{ proto string hw_document_content(hwdoc doc) Returns content of document */ @@ -1987,9 +2407,50 @@ PHP_FUNCTION(hw_document_content) { } RETURN_STRING(ptr->data, 1); -} /* }}} */ +} +/* }}} */ + +/* {{{ proto int hw_document_setcontent(hwdoc doc, string content) + Sets/replaces content of document */ +PHP_FUNCTION(hw_document_setcontent) { + pval *argv[2]; + int id, type, argc; + hw_document *ptr; + char *str; + + argc = ARG_COUNT(ht); + if(argc != 2) + WRONG_PARAM_COUNT; + + if (getParametersArray(ht, argc, argv) == FAILURE) + RETURN_FALSE; + + convert_to_long(argv[0]); + convert_to_string(argv[1]); + id=argv[0]->value.lval; + ptr = php3_list_find(id,&type); + if(!ptr || (type!=php3_hw_module.le_document)) { + php_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + str = ptr->data; + if(NULL != (ptr->data = strdup(argv[1]->value.str.val))) { + ptr->size = strlen(ptr->data); + free(str); + RETURN_TRUE; + } else { + ptr->data = str; + RETURN_FALSE; + } +} +/* }}} */ -/* {{{ proto int hw_document_content(hwdoc doc) +/* {{{ proto int hw_documentsize(hwdoc doc) + An alias for hw_document_size */ +/* }}} */ + +/* {{{ proto int hw_document_size(hwdoc doc) Returns size of document */ PHP_FUNCTION(hw_document_size) { pval *arg1; @@ -2008,9 +2469,14 @@ PHP_FUNCTION(hw_document_size) { } RETURN_LONG(ptr->size); -} /* }}} */ +} +/* }}} */ -/* {{{ proto string hw_document_content(hwdoc doc) +/* {{{ proto string hw_documentattributes(hwdoc doc) + An alias for hw_document_attributes */ +/* }}} */ + +/* {{{ proto string hw_document_attributes(hwdoc doc) Returns object record of document */ PHP_FUNCTION(hw_document_attributes) { pval *arg1; @@ -2030,7 +2496,8 @@ PHP_FUNCTION(hw_document_attributes) { RETURN_STRING(ptr->attributes, 1); /* make_return_array_from_objrec(&return_value, ptr->attributes); */ -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getparentsobj(int link, int objid) Returns array of parent object records */ @@ -2057,14 +2524,15 @@ PHP_FUNCTION(hw_getparentsobj) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getparentsobj(ptr->socket, id, &childObjRecs, &count))) { - php_error(E_WARNING, "send_command (getparentsobj) returned -1\n"); + php_error(E_WARNING, "send_command (getparentsobj) returned %d\n", ptr->lasterror); RETURN_FALSE; } /* create return value and free all memory */ if( 0 > make_return_objrec(&return_value, childObjRecs, count)) RETURN_FALSE; -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getparents(int link, int objid) Returns array of parent object ids */ @@ -2093,7 +2561,7 @@ PHP_FUNCTION(hw_getparents) { int i; if (0 != (ptr->lasterror = send_getparents(ptr->socket, id, &childIDs, &count))) { - php_error(E_WARNING, "send_command (getparents) returned -1\n"); + php_error(E_WARNING, "send_command (getparents) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2108,7 +2576,8 @@ PHP_FUNCTION(hw_getparents) { efree(childIDs); } -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_children(int link, int objid) Returns array of children object ids */ @@ -2137,7 +2606,7 @@ PHP_FUNCTION(hw_children) { int i; if (0 != (ptr->lasterror = send_children(ptr->socket, id, &childIDs, &count))){ - php_error(E_WARNING, "send_command (getchildcoll) returned -1\n"); + php_error(E_WARNING, "send_command (getchildcoll) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2152,9 +2621,10 @@ PHP_FUNCTION(hw_children) { efree(childIDs); } -} /* }}} */ +} +/* }}} */ -/* {{{ proto array hw_children(int link, int objid) +/* {{{ proto array hw_childrenobj(int link, int objid) Returns array of children object records */ PHP_FUNCTION(hw_childrenobj) { pval *arg1, *arg2; @@ -2179,16 +2649,17 @@ PHP_FUNCTION(hw_childrenobj) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_childrenobj(ptr->socket, id, &childObjRecs, &count))) { - php_error(E_WARNING, "send_command (getchildcollobj) returned -1\n"); + php_error(E_WARNING, "send_command (getchildcollobj) returned %d\n", ptr->lasterror); RETURN_FALSE; } /* create return value and free all memory */ if( 0 > make_return_objrec(&return_value, childObjRecs, count)) RETURN_FALSE; -} /* }}} */ +} +/* }}} */ -/* {{{ proto array hw_childcoll(int link, int objid) +/* {{{ proto array hw_getchildcoll(int link, int objid) Returns array of child collection object ids */ PHP_FUNCTION(hw_getchildcoll) { pval *arg1, *arg2; @@ -2215,7 +2686,7 @@ PHP_FUNCTION(hw_getchildcoll) { int i; if (0 != (ptr->lasterror = send_getchildcoll(ptr->socket, id, &childIDs, &count))){ - php_error(E_WARNING, "send_command (getchildcoll) returned -1\n"); + php_error(E_WARNING, "send_command (getchildcoll) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2230,9 +2701,10 @@ PHP_FUNCTION(hw_getchildcoll) { efree(childIDs); } -} /* }}} */ +} +/* }}} */ -/* {{{ proto array hw_childcollobj(int link, int objid) +/* {{{ proto array hw_getchildcollobj(int link, int objid) Returns array of child collection object records */ PHP_FUNCTION(hw_getchildcollobj) { pval *arg1, *arg2; @@ -2257,14 +2729,15 @@ PHP_FUNCTION(hw_getchildcollobj) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getchildcollobj(ptr->socket, id, &childObjRecs, &count))) { - php_error(E_WARNING, "send_command (getchildcollobj) returned -1\n"); + php_error(E_WARNING, "send_command (getchildcollobj) returned %d\n", ptr->lasterror); RETURN_FALSE; } /* create return value and free all memory */ if( 0 > make_return_objrec(&return_value, childObjRecs, count)) RETURN_FALSE; -} /* }}} */ +} +/* }}} */ /* {{{ proto int hw_docbyanchor(int link, int anchorid) Returns objid of document belonging to anchorid */ @@ -2294,7 +2767,8 @@ PHP_FUNCTION(hw_docbyanchor) { RETURN_LONG(objectID); } -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_docbyanchorobj(int link, int anchorid) Returns object record of document belonging to anchorid */ @@ -2328,7 +2802,8 @@ PHP_FUNCTION(hw_docbyanchorobj) { efree(object); */ } -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getobjectbyquery(int link, string query, int maxhits) Search for query and return maxhits objids */ @@ -2358,7 +2833,7 @@ PHP_FUNCTION(hw_getobjectbyquery) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getobjbyquery(ptr->socket, query, maxhits, &childIDs, &count))) { - php_error(E_WARNING, "send_command (getchildcoll) returned -1\n"); + php_error(E_WARNING, "send_command (getobjectbyquery) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2370,7 +2845,8 @@ PHP_FUNCTION(hw_getobjectbyquery) { for(i=0; i<count; i++) add_index_long(return_value, i, childIDs[i]); efree(childIDs); -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getobjectbyqueryobj(int link, string query, int maxhits) Search for query and return maxhits object records */ @@ -2400,14 +2876,15 @@ PHP_FUNCTION(hw_getobjectbyqueryobj) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getobjbyqueryobj(ptr->socket, query, maxhits, &childObjRecs, &count))) { - php_error(E_WARNING, "send_command (getchildcoll) returned -1\n"); + php_error(E_WARNING, "send_command (getobjectbyqueryobj) returned %d\n", ptr->lasterror); RETURN_FALSE; } /* create return value and free all memory */ if( 0 > make_return_objrec(&return_value, childObjRecs, count)) RETURN_FALSE; -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getobjectbyquerycoll(int link, int collid, string query, int maxhits) Search for query in collection and return maxhits objids */ @@ -2439,7 +2916,7 @@ PHP_FUNCTION(hw_getobjectbyquerycoll) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getobjbyquerycoll(ptr->socket, id, query, maxhits, &childIDs, &count))) { - php_error(E_WARNING, "send_command (getchildcoll) returned -1\n"); + php_error(E_WARNING, "send_command (getobjectbyquerycoll) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2451,7 +2928,8 @@ PHP_FUNCTION(hw_getobjectbyquerycoll) { for(i=0; i<count; i++) add_index_long(return_value, i, childIDs[i]); efree(childIDs); -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getobjectbyquerycollobj(int link, int collid, string query, int maxhits) Search for query in collection and return maxhits object records */ @@ -2483,14 +2961,15 @@ PHP_FUNCTION(hw_getobjectbyquerycollobj) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getobjbyquerycollobj(ptr->socket, id, query, maxhits, &childObjRecs, &count))) { - php_error(E_WARNING, "send_command (getchildcoll) returned -1\n"); + php_error(E_WARNING, "send_command (getobjectbyquerycollobj) returned %d\n", ptr->lasterror); RETURN_FALSE; } /* create return value and free all memory */ if( 0 > make_return_objrec(&return_value, childObjRecs, count)) RETURN_FALSE; -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getchilddoccoll(int link, int objid) Returns all children ids which are documents */ @@ -2516,7 +2995,7 @@ PHP_FUNCTION(hw_getchilddoccoll) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getchilddoccoll(ptr->socket, id, &childIDs, &count))) { - php_error(E_WARNING, "send_command (getchilddoccoll) returned -1\n"); + php_error(E_WARNING, "send_command (getchilddoccoll) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2528,7 +3007,8 @@ PHP_FUNCTION(hw_getchilddoccoll) { for(i=0; i<count; i++) add_index_long(return_value, i, childIDs[i]); efree(childIDs); -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getchilddoccollobj(int link, int objid) Returns all children object records which are documents */ @@ -2554,7 +3034,7 @@ PHP_FUNCTION(hw_getchilddoccollobj) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getchilddoccollobj(ptr->socket, id, &childObjRecs, &count))) { - php_error(E_WARNING, "send_command (getchilddoccollobj) returned -1\n"); + php_error(E_WARNING, "send_command (getchilddoccollobj) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2562,7 +3042,8 @@ PHP_FUNCTION(hw_getchilddoccollobj) { if( 0 > make_return_objrec(&return_value, childObjRecs, count)) RETURN_FALSE; -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getanchors(int link, int objid) Return all anchors of object */ @@ -2588,7 +3069,7 @@ PHP_FUNCTION(hw_getanchors) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getanchors(ptr->socket, id, &anchorIDs, &count))) { - php_error(E_WARNING, "send_command (getanchors) returned -1\n"); + php_error(E_WARNING, "send_command (getanchors) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2600,7 +3081,8 @@ PHP_FUNCTION(hw_getanchors) { for(i=0; i<count; i++) add_index_long(return_value, i, anchorIDs[i]); efree(anchorIDs); -} /* }}} */ +} +/* }}} */ /* {{{ proto array hw_getanchorsobj(int link, int objid) Return all object records of anchors of object */ @@ -2626,14 +3108,15 @@ PHP_FUNCTION(hw_getanchorsobj) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getanchorsobj(ptr->socket, id, &anchorObjRecs, &count))) { - php_error(E_WARNING, "send_command (getanchors) returned -1\n"); + php_error(E_WARNING, "send_command (getanchors) returned %d\n", ptr->lasterror); RETURN_FALSE; } /* create return value and free all memory */ if( 0 > make_return_objrec(&return_value, anchorObjRecs, count)) RETURN_FALSE; -} /* }}} */ +} +/* }}} */ /* {{{ proto string hw_getusername(int link) Returns the current user name */ @@ -2656,8 +3139,8 @@ PHP_FUNCTION(hw_getusername) { return_value->value.str.val = estrdup(ptr->username); return_value->value.str.len = strlen(ptr->username); return_value->type = IS_STRING; -} /* }}} */ - +} +/* }}} */ /* {{{ proto void hw_identify(int link, string username, string password) Identifies at Hyperwave server */ @@ -2687,7 +3170,7 @@ PHP_FUNCTION(hw_identify) { char *str; if (0 != (ptr->lasterror = send_identify(ptr->socket, name, passwd, &userdata))) { - php_error(E_WARNING, "send_identify returned -1\n"); + php_error(E_WARNING, "send_identify returned %d\n", ptr->lasterror); if(ptr->username) free(ptr->username); ptr->username = NULL; RETURN_FALSE; @@ -2730,7 +3213,7 @@ PHP_FUNCTION(hw_array2objrec) { if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string(arg1); + convert_to_array(arg1); objrec = make_objrec_from_array(arg1->value.ht); if(objrec) { retobj = estrdup(objrec); @@ -2840,7 +3323,7 @@ PHP_FUNCTION(hw_inscoll) { } /* }}} */ -/* {{{ proto void hw_inscoll(int link, int parentid, array objarr [, string text]) +/* {{{ proto void hw_insdoc(int link, int parentid, string objrec [, string text]) Inserts document */ PHP_FUNCTION(hw_insdoc) { pval *argv[4]; @@ -2906,7 +3389,7 @@ PHP_FUNCTION(hw_getsrcbydestobj) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = send_getsrcbydest(ptr->socket, id, &childObjRecs, &count))) { - php_error(E_WARNING, "send_command (getsrcbydest) returned -1\n"); + php_error(E_WARNING, "send_command (getsrcbydest) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2944,7 +3427,7 @@ PHP_FUNCTION(hw_getrellink) { set_swap(ptr->swap_on); if (0 != (ptr->lasterror = getrellink(ptr->socket, rootid, sourceid, destid, &anchorstr))) { - php_error(E_WARNING, "command (getrellink) returned -1\n"); + php_error(E_WARNING, "command (getrellink) returned %d\n", ptr->lasterror); RETURN_FALSE; } @@ -2958,6 +3441,8 @@ PHP_MINFO_FUNCTION(hw) php_printf("HG-CSP Version: 7.17"); } +/* {{{ proto void hw_connection_info(int link) + Prints information about the connection to Hyperwave server */ PHP_FUNCTION(hw_connection_info) { pval *arg1; @@ -2977,6 +3462,7 @@ PHP_FUNCTION(hw_connection_info) php_printf("Hyperwave Info:\nhost=%s,\nserver string=%s\nversion=%d\nswap=%d\n", ptr->hostname, ptr->server_string, ptr->version, ptr->swap_on); } +/* }}} */ void print_msg(hg_msg *msg, char *str, int txt) { @@ -3006,5 +3492,6 @@ void print_msg(hg_msg *msg, char *str, int txt) /* * Local variables: * tab-width: 4 + * c-basic-offset: 4 * End: */ diff --git a/ext/hyperwave/hw_error.h b/ext/hyperwave/hw_error.h index 9730995e31..6c782a12f5 100644 --- a/ext/hyperwave/hw_error.h +++ b/ext/hyperwave/hw_error.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + | Copyright (c) 1997-1999 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | | it under the terms of the GNU General Public License as published by | |