diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 97c47f14e24..f3d3eae22e4 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -198,6 +198,12 @@ PHP_MSHUTDOWN_FUNCTION(gd) return SUCCESS; } +/* Need this for cpdf. See also comment in file.c php3i_get_le_fp() */ +PHPAPI int phpi_get_le_gd(void){ + GD_TLS_VARS; + return GD_GLOBAL(le_gd); +} + /********************************************************************/ /* gdImageColorResolve is a replacement for the old fragment: */ /* */ diff --git a/ext/hyperwave/hg_comm.c b/ext/hyperwave/hg_comm.c index dcb300de601..812511d4eec 100644 --- a/ext/hyperwave/hg_comm.c +++ b/ext/hyperwave/hg_comm.c @@ -21,12 +21,9 @@ /* #define HW_DEBUG */ #include - -#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 #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); + 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; - /* 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; - - /* 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; + switch(anchormode) { + case 0: + tempptr = docofanchorptr; + break; + default: + tempptr = reldestptr; } - 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); + 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; + 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) { + if(NULL != (str = strstr(object, "Dest="))) { + str += 5; + 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 { /* 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); + } + } - - 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 { /* 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://. + 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 */ /* 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, ""); - sprintf(istr, "", cur_ptr->link, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr, offset); + snprintf(istr, BUFFERLEN, "", 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 */ /* 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, ""); if(cur_ptr->nameanchor) - sprintf(istr, "", scriptname == NULL ? "schade" : scriptname, cur_ptr->destdocname, cur_ptr->nameanchor, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); + snprintf(istr, BUFFERLEN, "", scriptname == NULL ? "schade" : scriptname, cur_ptr->destdocname, cur_ptr->nameanchor, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); else if(cur_ptr->fragment) - sprintf(istr, "", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname, cur_ptr->fragment, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); + snprintf(istr, BUFFERLEN, "", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname, cur_ptr->fragment, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr); else - sprintf(istr, "", scriptname == NULL ? "" : scriptname, cur_ptr->destdocname, cur_ptr->htmlattr == NULL ? "" : cur_ptr->htmlattr, offset); + snprintf(istr, BUFFERLEN, "", 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, "", cur_ptr->keyword); + snprintf(istr, BUFFERLEN, "", cur_ptr->keyword); else if(cur_ptr->nameanchor) - sprintf(istr, "", cur_ptr->nameanchor); + snprintf(istr, BUFFERLEN, "", 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 */ @@ -561,10 +572,11 @@ char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag) { } cur_ptr = (ANCHOR *) dlst_prev(cur_ptr); } - sprintf(istr, "", bgstr); + snprintf(istr, BUFFERLEN, "", 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(" Recv msg: type = %d -- id = %d
\n", msg->msg_type, msg->version_msgid); + php3_printf(" Recv msg: type = %d -- id = %d
\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 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; kh_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("Sending msg: type = %d -- id = %d
\n", msg->msg_type, msg->version_msgid); + php3_printf("Sending msg: type = %d -- id = %d
\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: %d
\n", val); + php3_printf(" Added int to header: %d
\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: %s (%d)
\n", str, strlen(str)); + php3_printf(" Added str to header: %s (%d)
\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 b000c44c50d..12503e8181f 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 de6597d043c..cd4d8823ed7 100644 --- a/ext/hyperwave/hw.c +++ b/ext/hyperwave/hw.c @@ -23,16 +23,22 @@ #include -#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 WIN32|WINNT +#include +#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; iusername = 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; - RETURN_STRING(object, 0); - /* - make_return_array_from_objrec(&return_value, object); - efree(object); - */ + lht = argv[1]->value.ht; + if(0 == (count = zend_hash_num_elements(lht))) + RETURN_FALSE; + ids = emalloc(count * sizeof(hw_objectID)); + + zend_hash_internal_pointer_reset(lht); + for(i=0; itype) { + 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; ivalue.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; itype) { 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; itype) { + 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; itype) { + 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; iswap_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%s---
", 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; idata = strdup(remainder); + doc->data = malloc(len+1); + ptr = doc->data; + for(i=0, j=0; iattributes = 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_content(hwdoc doc) +/* {{{ 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_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; iswap_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; iswap_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; iswap_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; iswap_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 9730995e316..6c782a12f56 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 | diff --git a/ext/pdf/config.m4 b/ext/pdf/config.m4 index c421e2a1c7c..a410edf3b8d 100644 --- a/ext/pdf/config.m4 +++ b/ext/pdf/config.m4 @@ -1,30 +1,54 @@ dnl $Id$ -AC_MSG_CHECKING(whether to include pdflib support) +AC_MSG_CHECKING(whether to include Pdflib 2.0 support) AC_ARG_WITH(pdflib, -[ --with-pdflib[=DIR] Include pdflib support (tested with 0.6). +[ --with-pdflib[=DIR] Include pdflib 2.0 support. DIR is the pdflib install directory, defaults to /usr/local.], [ +echo $withval case "$withval" in no) AC_MSG_RESULT(no) ;; yes) AC_MSG_RESULT(yes) PHP_EXTENSION(pdf) - AC_CHECK_LIB(pdf, PDF_open, [AC_DEFINE(HAVE_PDFLIB) PDFLIB_LIBS="-lpdf"], - [AC_MSG_ERROR(pdflib extension requires pdflib 0.6.)]) + AC_CHECK_LIB(pdf, PDF_close, [AC_DEFINE(HAVE_PDFLIB) PDFLIB_LIBS="-lpdf"], + [AC_MSG_ERROR(pdflib extension requires pdflib 2.0.)]) EXTRA_LIBS="$EXTRA_LIBS $PDFLIB_LIBS" ;; *) - test -f $withval/include/pdf.h && PDFLIB_INCLUDE="-I$withval/include" + test -f $withval/include/pdflib.h && PDFLIB_INCLUDE="-I$withval/include" if test -n "$PDFLIB_INCLUDE" ; then AC_MSG_RESULT(yes) PHP_EXTENSION(pdf) old_LIBS=$LIBS + + if test -z $ZLIB_LIBS; then + old_withval=$withval + AC_MSG_CHECKING([for zlib (needed by pdflib 2.0)]) + AC_ARG_WITH(zlib-dir, + [ --with-zlib-dir[=DIR] zlib dir for pdflib 2.0 or include zlib support],[ + AC_MSG_RESULT( ) + if test -z $withval; then + withval="/usr/local" + fi + LIBS="$LIBS -L$withval/lib -lz" + AC_CHECK_LIB(z,deflate, [PDFLIB_LIBS="-L$withval/lib -lz"],[AC_MSG_RESULT(no)],) + ],[ + AC_MSG_RESULT(no) + AC_MSG_WARN(If configure fails try --with-zlib=) + ]) + else + echo "checking for libz needed by pdflib 2.0... already zlib support" + PDFLIB_LIBS="$ZLIB_LIBS" + LIBS="$LIBS $ZLIB_LIBS" + fi + withval=$old_withval + LIBS="$LIBS -L$withval/lib" - AC_CHECK_LIB(pdf, PDF_open, [AC_DEFINE(HAVE_PDFLIB) PDFLIB_LIBS="-L$withval/lib -lpdf"], - [AC_MSG_ERROR(pdflib extension requires pdflib 0.6.)]) + AC_CHECK_LIB(pdf, PDF_close, [AC_DEFINE(HAVE_PDFLIB) PDFLIB_LIBS="-L$withval/lib -lpdf"], + [AC_MSG_ERROR(pdflib extension requires pdflib 2.0.)]) LIBS=$old_LIBS EXTRA_LIBS="$EXTRA_LIBS $PDFLIB_LIBS" INCLUDES="$INCLUDES $PDFLIB_INCLUDE" diff --git a/ext/pdf/pdf.c b/ext/pdf/pdf.c index 82fb07d78d5..08730ca844d 100644 --- a/ext/pdf/pdf.c +++ b/ext/pdf/pdf.c @@ -1,16 +1,27 @@ /* +----------------------------------------------------------------------+ - | PHP version 4.0 | + | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 The PHP Group | + | Copyright (c) 1997-1999 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ - | This source file is subject to version 2.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | +----------------------------------------------------------------------+ | Authors: Uwe Steinmann | +----------------------------------------------------------------------+ @@ -28,14 +39,15 @@ #endif #include "php.h" -#include "ext/standard/head.h" -#include -#include "php3_pdf.h" +#include "php_globals.h" -#if HAVE_SYS_WAIT_H -# include +#include + +#if HAVE_LIBGD13 +#include "gd.h" #endif -#if HAVE_UNISTD_H + +#ifdef HAVE_UNISTD_H # include #endif #if WIN32|WINNT @@ -45,12 +57,15 @@ #if HAVE_PDFLIB +#include "php3_pdf.h" + #ifdef THREAD_SAFE DWORD PDFlibTls; static int numthreads=0; typedef struct pdflib_global_struct{ - int le_pdf_info; + int le_pdf_image; + int le_outline; int le_pdf; } pdflib_global_struct; @@ -60,73 +75,89 @@ typedef struct pdflib_global_struct{ #else # define PDF_GLOBAL(a) a # define PDF_TLS_VARS -int le_pdf_info; -int le_pdf; +static int le_pdf_image; +static int le_outline; +static int le_pdf; #endif function_entry pdf_functions[] = { - {"pdf_get_info", php3_pdf_get_info, NULL}, - {"pdf_set_info_creator", php3_pdf_set_info_creator, NULL}, - {"pdf_set_info_title", php3_pdf_set_info_title, NULL}, - {"pdf_set_info_subject", php3_pdf_set_info_subject, NULL}, - {"pdf_set_info_author", php3_pdf_set_info_author, NULL}, - {"pdf_set_info_keywords", php3_pdf_set_info_keywords, NULL}, - {"pdf_open", php3_pdf_open, NULL}, - {"pdf_close", php3_pdf_close, NULL}, - {"pdf_begin_page", php3_pdf_begin_page, NULL}, - {"pdf_end_page", php3_pdf_end_page, NULL}, - {"pdf_show", php3_pdf_show, NULL}, - {"pdf_show_xy", php3_pdf_show_xy, NULL}, - {"pdf_set_font", php3_pdf_set_font, NULL}, - {"pdf_set_leading", php3_pdf_set_leading, NULL}, - {"pdf_set_text_rendering", php3_pdf_set_text_rendering,NULL}, - {"pdf_set_horiz_scaling", php3_pdf_set_horiz_scaling, NULL}, - {"pdf_set_text_rise", php3_pdf_set_text_rise, NULL}, - {"pdf_set_text_matrix", php3_pdf_set_text_matrix, NULL}, - {"pdf_set_text_pos", php3_pdf_set_text_pos, NULL}, - {"pdf_set_char_spacing", php3_pdf_set_char_spacing, NULL}, - {"pdf_set_word_spacing", php3_pdf_set_word_spacing, NULL}, - {"pdf_continue_text", php3_pdf_continue_text, NULL}, - {"pdf_stringwidth", php3_pdf_stringwidth, NULL}, - {"pdf_save", php3_pdf_save, NULL}, - {"pdf_restore", php3_pdf_restore, NULL}, - {"pdf_translate", php3_pdf_translate, NULL}, - {"pdf_scale", php3_pdf_scale, NULL}, - {"pdf_rotate", php3_pdf_rotate, NULL}, - {"pdf_setflat", php3_pdf_setflat, NULL}, - {"pdf_setlinejoin", php3_pdf_setlinejoin, NULL}, - {"pdf_setlinecap", php3_pdf_setlinecap, NULL}, - {"pdf_setmiterlimit", php3_pdf_setmiterlimit, NULL}, - {"pdf_setlinewidth", php3_pdf_setlinewidth, NULL}, - {"pdf_setdash", php3_pdf_setdash, NULL}, - {"pdf_moveto", php3_pdf_moveto, NULL}, - {"pdf_lineto", php3_pdf_lineto, NULL}, - {"pdf_curveto", php3_pdf_curveto, NULL}, - {"pdf_circle", php3_pdf_circle, NULL}, - {"pdf_arc", php3_pdf_arc, NULL}, - {"pdf_rect", php3_pdf_rect, NULL}, - {"pdf_closepath", php3_pdf_closepath, NULL}, - {"pdf_stroke", php3_pdf_stroke, NULL}, - {"pdf_closepath_stroke", php3_pdf_closepath_stroke, NULL}, - {"pdf_fill", php3_pdf_fill, NULL}, - {"pdf_fill_stroke", php3_pdf_fill_stroke, NULL}, - {"pdf_closepath_fill_stroke", php3_pdf_closepath_fill_stroke, NULL}, - {"pdf_endpath", php3_pdf_endpath, NULL}, - {"pdf_clip", php3_pdf_clip, NULL}, - {"pdf_setgray_fill", php3_pdf_setgray_fill, NULL}, - {"pdf_setgray_stroke", php3_pdf_setgray_stroke, NULL}, - {"pdf_setgray", php3_pdf_setgray, NULL}, - {"pdf_setrgbcolor_fill", php3_pdf_setrgbcolor_fill, NULL}, - {"pdf_setrgbcolor_stroke", php3_pdf_setrgbcolor_stroke,NULL}, - {"pdf_setrgbcolor", php3_pdf_setrgbcolor, NULL}, - {"pdf_add_outline", php3_pdf_add_outline, NULL}, - {"pdf_set_transition", php3_pdf_set_transition, NULL}, - {"pdf_set_duration", php3_pdf_set_duration, NULL}, + PHP_FE(pdf_set_info_creator, NULL) + PHP_FE(pdf_set_info_title, NULL) + PHP_FE(pdf_set_info_subject, NULL) + PHP_FE(pdf_set_info_author, NULL) + PHP_FE(pdf_set_info_keywords, NULL) + PHP_FE(pdf_open, NULL) + PHP_FE(pdf_close, NULL) + PHP_FE(pdf_begin_page, NULL) + PHP_FE(pdf_end_page, NULL) + PHP_FE(pdf_show, NULL) + PHP_FE(pdf_show_xy, NULL) + PHP_FE(pdf_set_font, NULL) + PHP_FE(pdf_set_leading, NULL) + PHP_FE(pdf_set_text_rendering, NULL) + PHP_FE(pdf_set_horiz_scaling, NULL) + PHP_FE(pdf_set_text_rise, NULL) + PHP_FE(pdf_set_text_matrix, NULL) + PHP_FE(pdf_set_text_pos, NULL) + PHP_FE(pdf_set_char_spacing, NULL) + PHP_FE(pdf_set_word_spacing, NULL) + PHP_FE(pdf_continue_text, NULL) + PHP_FE(pdf_stringwidth, NULL) + PHP_FE(pdf_save, NULL) + PHP_FE(pdf_restore, NULL) + PHP_FE(pdf_translate, NULL) + PHP_FE(pdf_scale, NULL) + PHP_FE(pdf_rotate, NULL) + PHP_FE(pdf_setflat, NULL) + PHP_FE(pdf_setlinejoin, NULL) + PHP_FE(pdf_setlinecap, NULL) + PHP_FE(pdf_setmiterlimit, NULL) + PHP_FE(pdf_setlinewidth, NULL) + PHP_FE(pdf_setdash, NULL) + PHP_FE(pdf_moveto, NULL) + PHP_FE(pdf_lineto, NULL) + PHP_FE(pdf_curveto, NULL) + PHP_FE(pdf_circle, NULL) + PHP_FE(pdf_arc, NULL) + PHP_FE(pdf_rect, NULL) + PHP_FE(pdf_closepath, NULL) + PHP_FE(pdf_stroke, NULL) + PHP_FE(pdf_closepath_stroke, NULL) + PHP_FE(pdf_fill, NULL) + PHP_FE(pdf_fill_stroke, NULL) + PHP_FE(pdf_closepath_fill_stroke, NULL) + PHP_FE(pdf_endpath, NULL) + PHP_FE(pdf_clip, NULL) + PHP_FE(pdf_setgray_fill, NULL) + PHP_FE(pdf_setgray_stroke, NULL) + PHP_FE(pdf_setgray, NULL) + PHP_FE(pdf_setrgbcolor_fill, NULL) + PHP_FE(pdf_setrgbcolor_stroke, NULL) + PHP_FE(pdf_setrgbcolor, NULL) + PHP_FE(pdf_add_outline, NULL) + PHP_FE(pdf_set_transition, NULL) + PHP_FE(pdf_set_duration, NULL) + PHP_FE(pdf_open_jpeg, NULL) +#if HAVE_LIBGD13 + PHP_FE(pdf_open_memory_image, NULL) +#endif + PHP_FE(pdf_open_gif, NULL) + PHP_FE(pdf_close_image, NULL) + PHP_FE(pdf_place_image, NULL) + PHP_FE(pdf_put_image, NULL) + PHP_FE(pdf_execute_image, NULL) + PHP_FE(pdf_add_weblink, NULL) + PHP_FE(pdf_add_pdflink, NULL) + PHP_FE(pdf_add_annotation, NULL) + PHP_FE(pdf_set_border_style, NULL) + PHP_FE(pdf_set_border_color, NULL) + PHP_FE(pdf_get_image_height, NULL) + PHP_FE(pdf_get_image_width, NULL) {NULL, NULL, NULL} }; php3_module_entry pdf_module_entry = { - "pdf", pdf_functions, php3_minit_pdf, php3_mend_pdf, NULL, NULL, php3_info_pdf, STANDARD_MODULE_PROPERTIES + "pdf", pdf_functions, PHP_MINIT(pdf), php3_mend_pdf, NULL, NULL, PHP_MINFO(pdf), 0, 0, 0, NULL }; #if COMPILE_DL @@ -134,56 +165,43 @@ php3_module_entry pdf_module_entry = { DLEXPORT php3_module_entry *get_module(void) { return &pdf_module_entry; } #endif -static void _free_pdf_info(PDF_info *info) +static void _free_pdf_image(int image) { - if(info->Title) efree(info->Title); - if(info->Subject) efree(info->Subject); - if(info->Author) efree(info->Author); - if(info->Keywords) efree(info->Keywords); - if(info->Creator) efree(info->Creator); } -int php3_minit_pdf(INIT_FUNC_ARGS) +static void _free_pdf_doc(PDF *pdf) { - PDF_GLOBAL(le_pdf_info) = register_list_destructors(_free_pdf_info, NULL); - PDF_GLOBAL(le_pdf) = register_list_destructors(php3_pdf_close, NULL); + PDF_close(pdf); + PDF_delete(pdf); +} + +static void _free_outline(int *outline) +{ +} + +PHP_MINIT_FUNCTION(pdf) +{ + PDF_GLOBAL(le_pdf_image) = register_list_destructors(_free_pdf_image, NULL); + PDF_GLOBAL(le_outline) = register_list_destructors(_free_outline, NULL); + PDF_GLOBAL(le_pdf) = register_list_destructors(_free_pdf_doc, NULL); return SUCCESS; } -void php3_info_pdf(ZEND_MODULE_INFO_FUNC_ARGS) { +PHP_MINFO_FUNCTION(pdf) { /* need to use a PHPAPI function here because it is external module in windows */ - php_printf("%s. AFM files in %s", PDFLIB_VERSION, PDF_DEFAULT_FONT_PATH); + php3_printf("pdflib %d.%d", PDF_get_majorversion(), PDF_get_minorversion()); } int php3_mend_pdf(void){ return SUCCESS; } -/* {{{ proto int pdf_get_info(void) - Returns a default info structure for a pdf document */ -PHP_FUNCTION(pdf_get_info) { - PDF_info *pdf_info; - int id; - PDF_TLS_VARS; - - pdf_info = PDF_get_info(); - - if(!pdf_info) { - php_error(E_WARNING, "Could not get PDF info"); - RETURN_FALSE; - } - - id = php3_list_insert(pdf_info,PDF_GLOBAL(le_pdf_info)); - RETURN_LONG(id); -} -/* }}} */ - /* {{{ proto pdf_set_info_creator(int info, string creator) Fills the creator field of the info structure */ PHP_FUNCTION(pdf_set_info_creator) { pval *arg1, *arg2; int id, type; - PDF_info *pdf_info; + PDF *pdf; PDF_TLS_VARS; @@ -194,13 +212,13 @@ PHP_FUNCTION(pdf_set_info_creator) { convert_to_long(arg1); convert_to_string(arg2); id=arg1->value.lval; - pdf_info = php3_list_find(id,&type); - if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) { - php_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); + pdf = php3_list_find(id,&type); + if (!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); RETURN_FALSE; } - pdf_info->Creator = estrdup(arg2->value.str.val); + PDF_set_info(pdf, "Creator", arg2->value.str.val); RETURN_TRUE; } @@ -211,7 +229,7 @@ PHP_FUNCTION(pdf_set_info_creator) { PHP_FUNCTION(pdf_set_info_title) { pval *arg1, *arg2; int id, type; - PDF_info *pdf_info; + PDF *pdf; PDF_TLS_VARS; @@ -222,13 +240,13 @@ PHP_FUNCTION(pdf_set_info_title) { convert_to_long(arg1); convert_to_string(arg2); id=arg1->value.lval; - pdf_info = php3_list_find(id,&type); - if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) { - php_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); + pdf = php3_list_find(id,&type); + if (!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); RETURN_FALSE; } - pdf_info->Title = estrdup(arg2->value.str.val); + PDF_set_info(pdf, "Title", arg2->value.str.val); RETURN_TRUE; } @@ -239,7 +257,7 @@ PHP_FUNCTION(pdf_set_info_title) { PHP_FUNCTION(pdf_set_info_subject) { pval *arg1, *arg2; int id, type; - PDF_info *pdf_info; + PDF *pdf; PDF_TLS_VARS; @@ -250,13 +268,13 @@ PHP_FUNCTION(pdf_set_info_subject) { convert_to_long(arg1); convert_to_string(arg2); id=arg1->value.lval; - pdf_info = php3_list_find(id,&type); - if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) { - php_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); + pdf = php3_list_find(id,&type); + if (!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); RETURN_FALSE; } - pdf_info->Subject = estrdup(arg2->value.str.val); + PDF_set_info(pdf, "Subject", arg2->value.str.val); RETURN_TRUE; } @@ -267,7 +285,7 @@ PHP_FUNCTION(pdf_set_info_subject) { PHP_FUNCTION(pdf_set_info_author) { pval *arg1, *arg2; int id, type; - PDF_info *pdf_info; + PDF *pdf; PDF_TLS_VARS; @@ -278,13 +296,13 @@ PHP_FUNCTION(pdf_set_info_author) { convert_to_long(arg1); convert_to_string(arg2); id=arg1->value.lval; - pdf_info = php3_list_find(id,&type); - if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) { - php_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); + pdf = php3_list_find(id,&type); + if (!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); RETURN_FALSE; } - pdf_info->Author = estrdup(arg2->value.str.val); + PDF_set_info(pdf, "Author", arg2->value.str.val); RETURN_TRUE; } @@ -295,7 +313,7 @@ PHP_FUNCTION(pdf_set_info_author) { PHP_FUNCTION(pdf_set_info_keywords) { pval *arg1, *arg2; int id, type; - PDF_info *pdf_info; + PDF *pdf; PDF_TLS_VARS; @@ -306,13 +324,13 @@ PHP_FUNCTION(pdf_set_info_keywords) { convert_to_long(arg1); convert_to_string(arg2); id=arg1->value.lval; - pdf_info = php3_list_find(id,&type); - if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) { - php_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); + pdf = php3_list_find(id,&type); + if (!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); RETURN_FALSE; } - pdf_info->Keywords = estrdup(arg2->value.str.val); + PDF_set_info(pdf, "Keywords", arg2->value.str.val); RETURN_TRUE; } @@ -325,35 +343,26 @@ PHP_FUNCTION(pdf_open) { pval *info; int id, type; FILE *fp; - PDF_info *pdf_info; PDF *pdf; PDF_TLS_VARS; - if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &file, &info) == FAILURE) { + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &file) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(file); - convert_to_long(info); id=file->value.lval; fp = php3_list_find(id,&type); if (!fp || type!=php3i_get_le_fp()) { - php_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); + php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type); RETURN_FALSE; } - id=info->value.lval; - pdf_info = php3_list_find(id,&type); - if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) { - php_error(E_WARNING,"Unable to find pdf info identifier %d (%d!=%d)",id, type, PDF_GLOBAL(le_pdf_info)); + pdf = PDF_new(); + if (0 > PDF_open_fp(pdf, fp)) { RETURN_FALSE; } - - pdf = PDF_open(fp, pdf_info); - if(!pdf) - RETURN_FALSE; - id = php3_list_insert(pdf,PDF_GLOBAL(le_pdf)); RETURN_LONG(id); } @@ -375,11 +384,11 @@ PHP_FUNCTION(pdf_close) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } - PDF_close(pdf); + php3_list_delete(id); RETURN_TRUE; } @@ -406,7 +415,7 @@ PHP_FUNCTION(pdf_begin_page) { width = arg3->value.dval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -432,7 +441,7 @@ PHP_FUNCTION(pdf_end_page) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -459,7 +468,7 @@ PHP_FUNCTION(pdf_show) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -469,7 +478,7 @@ PHP_FUNCTION(pdf_show) { } /* }}} */ -/* {{{ proto void pdf_show_xy(int pdfdoc, string text) +/* {{{ proto void pdf_show_xy(int pdfdoc, string text, double x-koor, double y-koor) Output text at position */ PHP_FUNCTION(pdf_show_xy) { pval *arg1, *arg2, *arg3, *arg4; @@ -488,7 +497,7 @@ PHP_FUNCTION(pdf_show_xy) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -498,11 +507,11 @@ PHP_FUNCTION(pdf_show_xy) { } /* }}} */ -/* {{{ proto void pdf_set_font(int pdfdoc, string font, double size, string encoding) - Select the current font face and size */ +/* {{{ proto void pdf_set_font(int pdfdoc, string font, double size, int encoding) + Select the current font face, size and encoding */ PHP_FUNCTION(pdf_set_font) { pval *arg1, *arg2, *arg3, *arg4; - int id, type; + int id, type, font; PDF *pdf; PDF_TLS_VARS; @@ -513,15 +522,46 @@ PHP_FUNCTION(pdf_set_font) { convert_to_long(arg1); convert_to_string(arg2); convert_to_double(arg3); - convert_to_string(arg4); + convert_to_long(arg4); id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } - PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, builtin); + if((arg4->value.lval > 5) || (arg4->value.lval < 0)) { + php3_error(E_WARNING,"Font encoding set to 4"); + arg4->value.lval = 4; + } + + switch(arg4->value.lval) { + case 0: + font = PDF_findfont(pdf, arg2->value.str.val, "builtin", 1); + break; + case 1: + font = PDF_findfont(pdf, arg2->value.str.val, "pdfdoc", 1); + break; + case 2: + font = PDF_findfont(pdf, arg2->value.str.val, "macroman", 1); + break; + case 3: + font = PDF_findfont(pdf, arg2->value.str.val, "macexpert", 1); + break; + case 4: + font = PDF_findfont(pdf, arg2->value.str.val, "winansi", 1); + break; + default: + php3_error(E_WARNING,"Encoding out of range, using 0"); + font = PDF_findfont(pdf, arg2->value.str.val, "builtin", 1); + } + + if (font < 0) { + php3_error(E_WARNING,"Font %s not found", arg2->value.str.val); + RETURN_FALSE; + } + + PDF_setfont(pdf, font, (float) arg3->value.dval); RETURN_TRUE; } @@ -544,7 +584,7 @@ PHP_FUNCTION(pdf_set_leading) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -571,11 +611,11 @@ PHP_FUNCTION(pdf_set_text_rendering) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } - PDF_set_text_rendering(pdf, (byte) arg2->value.lval); + PDF_set_text_rendering(pdf, arg2->value.lval); RETURN_TRUE; } @@ -598,7 +638,7 @@ PHP_FUNCTION(pdf_set_horiz_scaling) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -625,7 +665,7 @@ PHP_FUNCTION(pdf_set_text_rise) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -642,7 +682,7 @@ PHP_FUNCTION(pdf_set_text_matrix) { int id, type, i; HashTable *matrix; PDF *pdf; - PDF_matrix pdfmatrix; + float pdfmatrix[6]; float *pdfmatrixptr; PDF_TLS_VARS; @@ -656,36 +696,39 @@ PHP_FUNCTION(pdf_set_text_matrix) { matrix=arg2->value.ht; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } - if(zend_hash_num_elements(matrix) != 6) { - php_error(E_WARNING,"Text matrix must have 6 elements"); + if(_php3_hash_num_elements(matrix) != 6) { + php3_error(E_WARNING,"Text matrix must have 6 elements"); RETURN_FALSE; } pdfmatrixptr = (float *) &pdfmatrix; - zend_hash_internal_pointer_reset(matrix); - for(i=0; itype) { case IS_DOUBLE: *pdfmatrixptr++ = (float) data->value.dval; + break; default: *pdfmatrixptr++ = 0.0; + break; } - zend_hash_move_forward(matrix); + _php3_hash_move_forward(matrix); } - PDF_set_text_matrix(pdf, pdfmatrix); + PDF_set_text_matrix(pdf, pdfmatrix[0], pdfmatrix[1], pdfmatrix[2], + pdfmatrix[3], pdfmatrix[4], pdfmatrix[5]); RETURN_TRUE; } /* }}} */ /* {{{ proto void pdf_set_text_pos(int pdfdoc, double x, double y) - */ + ??? */ PHP_FUNCTION(pdf_set_text_pos) { pval *arg1, *arg2, *arg3; int id, type; @@ -702,7 +745,7 @@ PHP_FUNCTION(pdf_set_text_pos) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -729,7 +772,7 @@ PHP_FUNCTION(pdf_set_char_spacing) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -756,7 +799,7 @@ PHP_FUNCTION(pdf_set_word_spacing) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -783,7 +826,7 @@ PHP_FUNCTION(pdf_continue_text) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -811,11 +854,11 @@ PHP_FUNCTION(pdf_stringwidth) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } - width = (double) PDF_stringwidth(pdf, arg2->value.str.val); + width = (double) PDF_stringwidth(pdf, arg2->value.str.val, PDF_get_font(pdf), PDF_get_fontsize(pdf)); RETURN_DOUBLE((double)width); } @@ -837,7 +880,7 @@ PHP_FUNCTION(pdf_save) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -863,7 +906,7 @@ PHP_FUNCTION(pdf_restore) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -891,7 +934,7 @@ PHP_FUNCTION(pdf_translate) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -919,7 +962,7 @@ PHP_FUNCTION(pdf_scale) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -946,7 +989,7 @@ PHP_FUNCTION(pdf_rotate) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -973,12 +1016,12 @@ PHP_FUNCTION(pdf_setflat) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } if((arg2->value.lval > 100) && (arg2->value.lval < 0)) { - php_error(E_WARNING,"Parameter of pdf_setflat() has to between 0 and 100"); + php3_error(E_WARNING,"Parameter of pdf_setflat() has to between 0 and 100"); RETURN_FALSE; } @@ -1005,16 +1048,16 @@ PHP_FUNCTION(pdf_setlinejoin) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } if((arg2->value.lval > 2) && (arg2->value.lval < 0)) { - php_error(E_WARNING,"Parameter of pdf_setlinejoin() has to between 0 and 2"); + php3_error(E_WARNING,"Parameter of pdf_setlinejoin() has to between 0 and 2"); RETURN_FALSE; } - PDF_setlinejoin(pdf, (byte) arg2->value.lval); + PDF_setlinejoin(pdf, arg2->value.lval); RETURN_TRUE; } @@ -1037,16 +1080,16 @@ PHP_FUNCTION(pdf_setlinecap) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } if((arg2->value.lval > 2) && (arg2->value.lval < 0)) { - php_error(E_WARNING,"Parameter of pdf_setlinecap() has to be > 0 and =< 2"); + php3_error(E_WARNING,"Parameter of pdf_setlinecap() has to be > 0 and =< 2"); RETURN_FALSE; } - PDF_setlinecap(pdf, (byte) arg2->value.lval); + PDF_setlinecap(pdf, arg2->value.lval); RETURN_TRUE; } @@ -1069,12 +1112,12 @@ PHP_FUNCTION(pdf_setmiterlimit) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } if(arg2->value.dval < 1) { - php_error(E_WARNING,"Parameter of pdf_setmiterlimit() has to be >= 1"); + php3_error(E_WARNING,"Parameter of pdf_setmiterlimit() has to be >= 1"); RETURN_FALSE; } @@ -1101,7 +1144,7 @@ PHP_FUNCTION(pdf_setlinewidth) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1129,7 +1172,7 @@ PHP_FUNCTION(pdf_setdash) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1157,7 +1200,7 @@ PHP_FUNCTION(pdf_moveto) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1189,7 +1232,7 @@ PHP_FUNCTION(pdf_curveto) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1222,7 +1265,7 @@ PHP_FUNCTION(pdf_lineto) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1251,7 +1294,7 @@ PHP_FUNCTION(pdf_circle) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1282,7 +1325,7 @@ PHP_FUNCTION(pdf_arc) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1312,7 +1355,7 @@ PHP_FUNCTION(pdf_rect) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1341,7 +1384,7 @@ PHP_FUNCTION(pdf_closepath) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1367,7 +1410,7 @@ PHP_FUNCTION(pdf_closepath_stroke) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1377,7 +1420,7 @@ PHP_FUNCTION(pdf_closepath_stroke) { } /* }}} */ -/* {{{ proto void pdf_closepath_stroke(int pdfdoc) +/* {{{ proto void pdf_stroke(int pdfdoc) Draw line along path path */ PHP_FUNCTION(pdf_stroke) { pval *arg1; @@ -1393,7 +1436,7 @@ PHP_FUNCTION(pdf_stroke) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1419,7 +1462,7 @@ PHP_FUNCTION(pdf_fill) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1445,7 +1488,7 @@ PHP_FUNCTION(pdf_fill_stroke) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1471,7 +1514,7 @@ PHP_FUNCTION(pdf_closepath_fill_stroke) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1497,7 +1540,7 @@ PHP_FUNCTION(pdf_endpath) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1523,7 +1566,7 @@ PHP_FUNCTION(pdf_clip) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1550,7 +1593,7 @@ PHP_FUNCTION(pdf_setgray_fill) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1577,7 +1620,7 @@ PHP_FUNCTION(pdf_setgray_stroke) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1604,7 +1647,7 @@ PHP_FUNCTION(pdf_setgray) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1628,10 +1671,12 @@ PHP_FUNCTION(pdf_setrgbcolor_fill) { convert_to_long(arg1); convert_to_double(arg2); + convert_to_double(arg3); + convert_to_double(arg4); id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1655,10 +1700,12 @@ PHP_FUNCTION(pdf_setrgbcolor_stroke) { convert_to_long(arg1); convert_to_double(arg2); + convert_to_double(arg3); + convert_to_double(arg4); id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1682,10 +1729,12 @@ PHP_FUNCTION(pdf_setrgbcolor) { convert_to_long(arg1); convert_to_double(arg2); + convert_to_double(arg3); + convert_to_double(arg4); id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1695,30 +1744,75 @@ PHP_FUNCTION(pdf_setrgbcolor) { } /* }}} */ -/* {{{ proto void pdf_add_outline(int pdfdoc, string text); +/* {{{ proto int pdf_add_outline(int pdfdoc, string text [, int parent, int open]); Add bookmark for current page */ PHP_FUNCTION(pdf_add_outline) { - pval *arg1, *arg2; + pval *arg1, *arg2, *arg3, *arg4; int id, type; + int *outline, *parent, parentid, open; PDF *pdf; PDF_TLS_VARS; - if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + switch (ARG_COUNT(ht)) { + case 2: + if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 3: + if (getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 4: + if (getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + default: WRONG_PARAM_COUNT; } - convert_to_long(arg1); convert_to_string(arg2); + id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find document identifier %d",id); RETURN_FALSE; } - PDF_add_outline(pdf, arg2->value.str.val); + if (ARG_COUNT(ht) > 2) { + convert_to_long(arg3); + id = arg3->value.lval; - RETURN_TRUE; + if (id > 0) { + parent = php3_list_find(id, &type); + if (!parent || (type != PDF_GLOBAL(le_outline))) { + php3_error(E_WARNING,"Unable to find identifier %d",id); + RETURN_FALSE; + } else { + parentid = *parent; + } + } else { + parentid = 0; + } + + if (ARG_COUNT(ht) > 3) { + convert_to_long(arg4); + open = arg4->value.lval; + } else { + open = 0; + } + } else { + parentid = 0; + open = 0; + } + + outline=emalloc(sizeof(int)); + *outline = PDF_add_bookmark(pdf, estrdup(arg2->value.str.val), parentid, open); + id = php3_list_insert(outline,PDF_GLOBAL(le_outline)); + RETURN_LONG(id); } /* }}} */ @@ -1739,11 +1833,39 @@ PHP_FUNCTION(pdf_set_transition) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } - PDF_set_transition(pdf, arg2->value.lval); + switch(arg2->value.lval) { + case 0: + PDF_set_transition(pdf, "none"); + break; + case 1: + PDF_set_transition(pdf, "split"); + break; + case 2: + PDF_set_transition(pdf, "blinds"); + break; + case 3: + PDF_set_transition(pdf, "box"); + break; + case 4: + PDF_set_transition(pdf, "wipe"); + break; + case 5: + PDF_set_transition(pdf, "dissolve"); + break; + case 6: + PDF_set_transition(pdf, "glitter"); + break; + case 7: + PDF_set_transition(pdf, "replace"); + break; + default: + PDF_set_transition(pdf, "none"); + + } RETURN_TRUE; } @@ -1766,7 +1888,7 @@ PHP_FUNCTION(pdf_set_duration) { id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { - php_error(E_WARNING,"Unable to find file identifier %d",id); + php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } @@ -1776,6 +1898,517 @@ PHP_FUNCTION(pdf_set_duration) { } /* }}} */ +/* {{{ proto int pdf_open_gif(int pdf, string giffile) + Opens a gif file and returns an image for placement in a pdf document */ +PHP_FUNCTION(pdf_open_gif) { + pval *arg1, *arg2; + int id, type; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_string(arg2); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + pdf_image = PDF_open_GIF(pdf, arg2->value.str.val); + + if(pdf_image < 0) { + php3_error(E_WARNING, "Could not open image"); + RETURN_FALSE; + } + + id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image)); + RETURN_LONG(id); +} +/* }}} */ + +/* {{{ proto int pdf_open_jpeg(int pdf, string jpegfile) + Opens a jpeg file and returns an image for placement in a pdf document */ +PHP_FUNCTION(pdf_open_jpeg) { + pval *arg1, *arg2; + int id, type; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_string(arg2); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + pdf_image = PDF_open_JPEG(pdf, arg2->value.str.val); + + if(pdf_image < 0) { + php3_error(E_WARNING, "Could not open image"); + RETURN_FALSE; + } + + id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image)); + RETURN_LONG(id); +} +/* }}} */ + +#if HAVE_LIBGD13 +/* {{{ proto int pdf_open_memory_image(int pdf, int image) + Takes an gd image and returns an image for placement in a pdf document */ +PHP_FUNCTION(pdf_open_memory_image) { + pval *argv[2]; + int argc; + int i, j, id, gid, type, color, count; + int pdf_image; + gdImagePtr im; + unsigned char *buffer, *ptr; + PDF *pdf; + PDF_TLS_VARS; + + argc = ARG_COUNT(ht); + if (getParametersArray(ht, argc, argv) == FAILURE) + WRONG_PARAM_COUNT; + + convert_to_long(argv[0]); + id=argv[0]->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + convert_to_long(argv[1]); + gid=argv[1]->value.lval; + im = php3_list_find(gid, &type); + if (!im || type != phpi_get_le_gd()) { + php3_error(E_WARNING, "pdf: Unable to find image pointer"); + RETURN_FALSE; + } + + count = 3 * im->sx * im->sy; + if(NULL == (buffer = (unsigned char *) emalloc(count))) + RETURN_FALSE; + + ptr = buffer; + for(i=0; isy; i++) { + for(j=0; jsx; j++) { + color = im->pixels[i][j]; + *ptr++ = im->red[color]; + *ptr++ = im->green[color]; + *ptr++ = im->blue[color]; + } + } + + + pdf_image = PDF_open_memory_image(pdf, buffer, im->sx, im->sy, 3, 8); + + if(0 > pdf_image) { + php3_error(E_WARNING, "Could not open image"); + RETURN_FALSE; + } + + id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image)); + RETURN_LONG(id); +} +/* }}} */ +#endif /* HAVE_LIBGD13 */ + +/* {{{ proto void pdf_close_image(int pdfimage) + Closes the pdf image */ +PHP_FUNCTION(pdf_close_image) { + pval *arg1, *arg2; + int id, type; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + convert_to_long(arg2); + id=arg2->value.lval; + pdf_image = (int) php3_list_find(id,&type); + if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + PDF_close_image(pdf, pdf_image); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto void pdf_place_image(int pdf, int pdfimage, int x, int y, int scale) + Places image in the pdf document */ +PHP_FUNCTION(pdf_place_image) { + pval *arg1, *arg2, *arg3, *arg4, *arg5; + int id, type; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 5 || getParameters(ht, 5, &arg1, &arg2, &arg3, &arg4, &arg5) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + convert_to_long(arg2); + id=arg2->value.lval; + pdf_image = (int) php3_list_find(id,&type); + if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + convert_to_double(arg3); + convert_to_double(arg4); + convert_to_double(arg5); + + PDF_place_image(pdf, pdf_image, (float) arg3->value.dval, (float) arg4->value.dval, arg5->value.dval); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto void pdf_put_image(int pdf, int pdfimage) + Stores image in the pdf document for later use */ +PHP_FUNCTION(pdf_put_image) { + pval *arg1, *arg2; + int id, type; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + convert_to_long(arg2); + id=arg2->value.lval; + pdf_image = (int) php3_list_find(id,&type); + if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + PDF_put_image(pdf, pdf_image); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto void pdf_execute_image(int pdf, int pdfimage, int x, int y, int scale) + Places stored image in the pdf document */ +PHP_FUNCTION(pdf_execute_image) { + pval *arg1, *arg2, *arg3, *arg4, *arg5; + int id, type; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 5 || getParameters(ht, 5, &arg1, &arg2, &arg3, &arg4, &arg5) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + convert_to_long(arg2); + id=arg2->value.lval; + pdf_image = (int) php3_list_find(id,&type); + if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + convert_to_double(arg3); + convert_to_double(arg4); + convert_to_double(arg5); + + PDF_execute_image(pdf, pdf_image, (float) arg3->value.dval, (float) arg4->value.dval, arg5->value.dval); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto void pdf_get_image_width(int pdf, int pdfimage) + Returns the width of an image */ +PHP_FUNCTION(pdf_get_image_width) { + pval *arg1, *arg2; + int id, type; + int width; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find identifier %d",id); + RETURN_FALSE; + } + + convert_to_long(arg2); + id=arg2->value.lval; + pdf_image = (int) php3_list_find(id,&type); + if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) { + php3_error(E_WARNING,"Unable to find identifier %d",id); + RETURN_FALSE; + } + + width = PDF_get_image_width(pdf, pdf_image); + + RETURN_LONG(width); +} +/* }}} */ + +/* {{{ proto void pdf_get_image_height(int pdf, int pdfimage) + Returns the height of an image */ +PHP_FUNCTION(pdf_get_image_height) { + pval *arg1, *arg2; + int id, type; + int height; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find identifier %d",id); + RETURN_FALSE; + } + + convert_to_long(arg2); + id=arg2->value.lval; + pdf_image = (int) php3_list_find(id,&type); + if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) { + php3_error(E_WARNING,"Unable to find identifier %d",id); + RETURN_FALSE; + } + + height = PDF_get_image_height(pdf, pdf_image); + + RETURN_LONG(height); +} +/* }}} */ + +/* {{{ proto void pdf_add_weblink(int pdfdoc, double llx, double lly, double urx, double ury, string url) + Adds link to web resource */ +PHP_FUNCTION(pdf_add_weblink) { + pval *arg1, *arg2, *arg3, *arg4, *arg5, *arg6; + int id, type; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 6 || getParameters(ht, 6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_double(arg2); + convert_to_double(arg3); + convert_to_double(arg4); + convert_to_double(arg5); + convert_to_string(arg6); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + PDF_add_weblink(pdf, (float) arg2->value.dval, (float) arg3->value.dval, (float) arg4->value.dval, (float) arg5->value.dval, arg6->value.str.val); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto void pdf_add_pdflink(int pdfdoc, double llx, double lly, double urx, double ury, string filename, int page, string dest) + Adds link to pdf document */ +PHP_FUNCTION(pdf_add_pdflink) { + pval *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8; + int id, type; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 8 || getParameters(ht, 8, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_double(arg2); + convert_to_double(arg3); + convert_to_double(arg4); + convert_to_double(arg5); + convert_to_string(arg6); + convert_to_long(arg7); + convert_to_string(arg8); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + PDF_add_pdflink(pdf, (float) arg2->value.dval, (float) arg3->value.dval, (float) arg4->value.dval, (float) arg5->value.dval, arg6->value.str.val, arg7->value.lval, arg8->value.str.val); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto void pdf_set_border_style(int pdfdoc, string style, double width) + Set style of box surounded weblinks */ +PHP_FUNCTION(pdf_set_border_style) { + pval *arg1, *arg2, *arg3; + int id, type; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_string(arg2); + convert_to_double(arg3); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + PDF_set_border_style(pdf, arg2->value.str.val, (float) arg3->value.dval); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto void pdf_set_border_color(int pdfdoc, double red, double green, double blue) + Set color of box surounded weblinks */ +PHP_FUNCTION(pdf_set_border_color) { + pval *arg1, *arg2, *arg3, *arg4; + int id, type; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 4 || getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_double(arg2); + convert_to_double(arg3); + convert_to_double(arg4); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + PDF_set_border_color(pdf, (float) arg2->value.dval, (float) arg3->value.dval, (float) arg4->value.dval); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto void pdf_add_annotation(int pdfdoc, double xll, double yll, double xur, double xur, string title, string text) + Sets annotation */ +PHP_FUNCTION(pdf_add_annotation) { + pval *argv[11]; + int id, type, argc; + PDF *pdf; + PDF_TLS_VARS; + + argc = ARG_COUNT(ht); + if(argc != 7) + WRONG_PARAM_COUNT; + if (getParametersArray(ht, argc, argv) == FAILURE) + WRONG_PARAM_COUNT; + + convert_to_long(argv[0]); + convert_to_double(argv[1]); + convert_to_double(argv[2]); + convert_to_double(argv[3]); + convert_to_double(argv[4]); + convert_to_string(argv[5]); + convert_to_string(argv[6]); + id=argv[0]->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find identifier %d",id); + RETURN_FALSE; + } + + PDF_add_note(pdf, + (float) argv[1]->value.dval, + (float) argv[2]->value.dval, + (float) argv[3]->value.dval, + (float) argv[4]->value.dval, + argv[6]->value.str.val, + argv[5]->value.str.val, + "note", 1); + + RETURN_TRUE; +} +/* }}} */ + #endif /* diff --git a/ext/pdf/php3_pdf.h b/ext/pdf/php3_pdf.h index d2c81b6ea70..3f311a84992 100644 --- a/ext/pdf/php3_pdf.h +++ b/ext/pdf/php3_pdf.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 one of the following licenses: | @@ -33,17 +33,16 @@ #if HAVE_PDFLIB -#include +#include extern int le_fp; extern php3_module_entry pdf_module_entry; #define pdf_module_ptr &pdf_module_entry -void php3_info_pdf(ZEND_MODULE_INFO_FUNC_ARGS); -extern int php3_minit_pdf(INIT_FUNC_ARGS); +extern PHP_MINFO_FUNCTION(pdf); +extern PHP_MINIT_FUNCTION(pdf); extern int php3_mend_pdf(void); -PHP_FUNCTION(pdf_get_info); PHP_FUNCTION(pdf_set_info_creator); PHP_FUNCTION(pdf_set_info_title); PHP_FUNCTION(pdf_set_info_subject); @@ -100,10 +99,24 @@ PHP_FUNCTION(pdf_setrgbcolor); PHP_FUNCTION(pdf_add_outline); PHP_FUNCTION(pdf_set_transition); PHP_FUNCTION(pdf_set_duration); +PHP_FUNCTION(pdf_open_jpeg); +#if HAVE_LIBGD13 +PHP_FUNCTION(pdf_open_memory_image); +#endif +PHP_FUNCTION(pdf_open_gif); +PHP_FUNCTION(pdf_close_image); +PHP_FUNCTION(pdf_place_image); +PHP_FUNCTION(pdf_put_image); +PHP_FUNCTION(pdf_execute_image); +PHP_FUNCTION(pdf_add_weblink); +PHP_FUNCTION(pdf_add_pdflink); +PHP_FUNCTION(pdf_add_annotation); +PHP_FUNCTION(pdf_set_border_style); +PHP_FUNCTION(pdf_set_border_color); +PHP_FUNCTION(pdf_get_image_width); +PHP_FUNCTION(pdf_get_image_height); #else #define pdf_module_ptr NULL #endif - #define phpext_pdf_ptr pdf_module_ptr - #endif /* _PHP3_PDF_H */