📄 hg_comm.c
字号:
htmlattr[0] = '\0'; offset = 0; while(NULL != (str = strstr(str1, "HtmlAttr="))) { str += 9; str1 = str; while((*str1 != '\n') && (*str1 != '\0')) str1++; /* Find the '=' in the HTML attr and make sure it is part of the attr and not somewhere in the objrec. */ if((NULL != (str2 = strchr(str, '='))) && (str2 < str1)) { str2++; strncpy(&htmlattr[offset], str, str2 - str); offset = offset + (str2 - str); htmlattr[offset++] = '"'; strncpy(&htmlattr[offset], str2, str1 - str2); offset = offset + (str1 - str2); htmlattr[offset++] = '"'; htmlattr[offset++] = ' '; htmlattr[offset] = '\0'; } } if(offset){ /* remove last space */ htmlattr[offset-1] = '\0'; cur_ptr->htmlattr = estrdup(htmlattr); } efree(htmlattr); } if(NULL != (str = strstr(object, "LinkType="))) { str += 9; if(strncmp(str, "background", 10) == 0) cur_ptr->linktype=HW_BACKGROUND_LINK; else if(strncmp(str, "intagnodel", 10) == 0) { /* New type introduced by Uwe Steinmann 16.03.2001 */ cur_ptr->linktype=HW_INTAGNODEL_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, "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); } } } /* free memory even if it is an invisible anchor */ efree(anchors[i]); if(docofanchorrec[i]) efree(docofanchorrec[i]); if(reldestrec) if(reldestrec[i]) efree(reldestrec[i]); } } return pAnchorList;}/************************************************************************ Function fnInsAnchorsIntoText() ** ** Returns the text document with all anchors inserted form list ** Parameter: char *text: text without anchors ** DList *pAnchorList: list of anchors ** Return: Text with anchors ************************************************************************/#define BUFFERLEN 200#ifdef newlistchar *fnInsAnchorsIntoText(char *text, zend_llist *pAnchorList, char **bodytag, char **urlprefix) { ANCHOR **ptr;#elsechar *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char **urlprefix) {#endif ANCHOR *cur_ptr; char bgstr[BUFFERLEN], istr[BUFFERLEN]; char **scriptname; char *newtext; int offset = 0; int laststart=0; char emptystring[BUFFERLEN]; int i; TSRMLS_FETCH(); emptystring[0] = '\0';/* The following is very tricky and depends on how rewriting is setup on your webserver. If you skip the scriptname in the url you will have to map each hyperwave name to http://<hwname>. This may not always be a good idea. The best solution is probably to provide a prefix for such a case which is an optional parameter to hw_gettext() or hw_pipedocument(). FIXME: Currently, the variable SCRIPT_NAME is empty thouht SCRIPT_URL is not. In our case this is OK, since as mentioned above it is better to have no SCRIPT_NAME than to have if rewriting is on.*/ if(urlprefix) { scriptname = urlprefix; } else { zval **script_name; scriptname = emalloc(5*sizeof(char *)); if (zend_hash_find(&EG(symbol_table), "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &script_name)==FAILURE) for(i=0; i<5; i++) scriptname[i] = &emptystring; else { convert_to_string_ex(script_name); for(i=0; i<5; i++) scriptname[i] = Z_STRVAL_PP(script_name); }#if 0#if APACHE { 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")) || (0 == strcmp(elts[j].key, "SCRIPT_URL"))) break; } scriptname = elts[j].val; }#else scriptname = getenv("SCRIPT_FILENAME");#endif#endif } newtext = text; bgstr[0] = '\0';#ifdef newlist zend_llist_sort(pAnchorList, (llist_compare_func_t) fnCmpAnchors TSRMLS_CC); ptr = (ANCHOR **) zend_llist_get_last(pAnchorList); if(ptr) cur_ptr = *ptr; while(NULL != ptr) {#else dlst_mergesort(pAnchorList, fnCmpAnchors); cur_ptr = (ANCHOR *) dlst_last(pAnchorList); while(NULL != cur_ptr) {#endif istr[0] = '\0'; if(cur_ptr->tanchor == 1) { /* Src Anchor */ if(laststart >= cur_ptr->end) offset = 0; if((cur_ptr->link != NULL) && (cur_ptr->link[0] != '\0')) { /* The link is only set if the Link points to an external document */ switch(cur_ptr->linktype) { case HW_BACKGROUND_LINK: snprintf(istr, BUFFERLEN, " background='%s'", cur_ptr->link); break; case HW_INTAG_LINK: snprintf(istr, BUFFERLEN, " %s='%s'", cur_ptr->tagattr, cur_ptr->link); offset -= 4; /* because there is no closing tag </A> *//* laststart = cur_ptr->start; */ break; case HW_INTAGNODEL_LINK: snprintf(istr, BUFFERLEN, "%s", cur_ptr->link); offset -= 4; /* because there is no closing tag </A> *//* laststart = cur_ptr->start; */ break; case HW_APPLET_LINK: if(cur_ptr->codebase) snprintf(istr, BUFFERLEN, " CODEBASE='%s' CODE='%s'", cur_ptr->codebase, cur_ptr->code); else snprintf(istr, BUFFERLEN, " CODEBASE='/' CODE='%s'", cur_ptr->code); break; default: newtext = fnInsStr(newtext, cur_ptr->end+offset, "</A>"); if(cur_ptr->fragment) snprintf(istr, BUFFERLEN, "<A HREF='%s#%s'", cur_ptr->link, cur_ptr->fragment); else snprintf(istr, BUFFERLEN, "<A HREF='%s'", cur_ptr->link); if(cur_ptr->htmlattr) { strncat(istr, " ", BUFFERLEN - 1 - strlen(istr)); strncat(istr, cur_ptr->htmlattr, BUFFERLEN - 1 - strlen(istr)); } strncat(istr, ">", BUFFERLEN - 1 - strlen(istr)); } } else { switch(cur_ptr->linktype) { case HW_BACKGROUND_LINK: if(NULL != cur_ptr->destdocname) { snprintf(istr, BUFFERLEN, " background='%s/%s'", scriptname[HW_BACKGROUND_LINK], cur_ptr->destdocname); } else istr[0] = '\0'; break; case HW_INTAG_LINK: if(cur_ptr->fragment) snprintf(istr, BUFFERLEN, " %s='#%s'", cur_ptr->tagattr, cur_ptr->fragment); else snprintf(istr, BUFFERLEN, " %s='%s/%s'", cur_ptr->tagattr, scriptname[HW_INTAG_LINK], cur_ptr->destdocname); offset -= 4; /* because there is no closing tag </A> */ break; case HW_INTAGNODEL_LINK: snprintf(istr, BUFFERLEN, "%s", cur_ptr->destdocname); offset -= 4; /* because there is no closing tag </A> */ break; case HW_APPLET_LINK: if(cur_ptr->codebase)/* snprintf(istr, BUFFERLEN, " CODEBASE='%s%s' CODE='%s'", scriptname == NULL ? "" : scriptname, cur_ptr->codebase, cur_ptr->code); */ snprintf(istr, BUFFERLEN, " CODEBASE='%s%s' CODE='%s'", scriptname[HW_APPLET_LINK], cur_ptr->codebase, cur_ptr->code); else snprintf(istr, BUFFERLEN, " CODEBASE='/' CODE='%s'", cur_ptr->code); break; default: newtext = fnInsStr(newtext, cur_ptr->end+offset, "</A>"); if(cur_ptr->nameanchor) snprintf(istr, BUFFERLEN, "<A HREF='%s/%s#%s'", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname, cur_ptr->nameanchor); else if(cur_ptr->fragment) snprintf(istr, BUFFERLEN, "<A HREF=\"%s/%s#%s\"", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname, cur_ptr->fragment); else snprintf(istr, BUFFERLEN, "<A HREF='%s/%s'", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname); if(cur_ptr->htmlattr) { strncat(istr, " ", BUFFERLEN - 1 - strlen(istr)); strncat(istr, cur_ptr->htmlattr, BUFFERLEN - 1 - strlen(istr)); } strncat(istr, ">", BUFFERLEN - 1 - strlen(istr)); } } } else { if(laststart >= cur_ptr->end) offset = 0; newtext = fnInsStr(newtext, cur_ptr->end+offset, "</a>"); /* If we have a keyword, we assume we had a fragment which has been used instead of the destdocname */ if(cur_ptr->keyword) snprintf(istr, BUFFERLEN, "<A NAME='%s'>", cur_ptr->keyword); else if(cur_ptr->nameanchor) snprintf(istr, BUFFERLEN, "<A NAME='%s'>", cur_ptr->nameanchor); } newtext = fnInsStr(newtext, cur_ptr->start, istr); /* In case there are several TAGS nested, we accumulate the offset You wonder what the 4 means? It's the length of </A> */ offset += strlen(istr) + 4; laststart = cur_ptr->start;#ifdef newlist ptr = (ANCHOR **) zend_llist_get_prev(pAnchorList); if(ptr) cur_ptr = *ptr;#else cur_ptr = (ANCHOR *) dlst_prev(cur_ptr);#endif } snprintf(istr, BUFFERLEN, "<BODY %s>", bgstr); *bodytag = estrdup(istr);/* if(scriptname != urlprefix) efree(scriptname); */ if(scriptname != NULL) efree(scriptname); return(newtext);}#undef BUFFERLEN /************************************************************************ Function fnAttributeValue() ** ** Returns the value of an attribute ** Parameter: char *object: object record ** char *attrname: attribute name ** Return: char*: attribute value, NULL if name not found ************************************************************************/char *fnAttributeValue(char *object, char *attrname){ char *str, *str1, *attrvalue; int len; str = strstr(object, attrname); if(NULL == str) return(NULL); str += strlen(attrname); str++; str1 = str; while((*str1 != '\0') && (*str1 != '\n')) str1++; len = str1 - str; if(NULL == (attrvalue = emalloc(len+1))) { lowerror = LE_MALLOC; return NULL; } memcpy(attrvalue, str, len); attrvalue[len] = '\0'; return(attrvalue);}/************************************************************************ Function fnAttributeCompare() ** ** Checks if an attribute in an objrec has a certain value ** Parameter: char *object: object record ** char *attrname: attribute name ** char *value: value of attribute ** Return: char*: as strcmp ************************************************************************/int fnAttributeCompare(char *object, char *attrname, char *value){ char *str, *str1; int len; if((NULL == object) || (NULL == attrname) || (NULL == value)) return -2; /* Find the attribute Name and make sure it is followed by a '=' sign and preceded by a '\n'; */ str = strstr(object, attrname); if((NULL == str) || (str[strlen(attrname)] != '=') || (str[-1] != '\n')) { return(-2); } str += strlen(attrname); /* skip the attribute name */ str++; /* skip the equal sign */ /* Search for end of attribute value */ str1 = str; while((*str1 != '\0') && (*str1 != '\n')) str1++; len = str1 - str; return(strncmp(str, value, len));}/********************************************************************** Function fnCOpenDataCon() ** ** Opens data connection on client side. This function is called ** right after the client has requested any data from the server ** Parameter: int sockfd: socket of control connection ** int *port: port of control und data connection ** Return : sockfd on success, <0 if error **********************************************************************/static int fnCOpenDataCon(int sockfd, int *port) { int fd; struct sockaddr_in serv_addr; int len; int option = 1;/* len = sizeof(com_addr); if(getsockname(sockfd, (struct sockaddr *) &com_addr, &len) < 0) { return(-1); } *port = htons(com_addr.sin_port); */ /* ** Open a TCP socket (an Internet stream socket) */ if((fd = socket(AF_INET, SOCK_STREAM, 0)) == SOCK_ERR) { return(-1); } /* ** Make sure that address may be reused */#if defined(SUN) || defined(PHP_WIN32) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&option, sizeof(option));#else setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));#endif /* ** Open connection aktiv ** Let bind() select a port number */ bzero((char *) &serv_addr, sizeof(serv_addr)); if(bind(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { return(-1); } /* ** Get the port number bind selected */ len = sizeof (serv_addr); if(getsockname(fd, (struct sockaddr *)&serv_addr, &len) < 0) { return(-1); } *port = ntohs(serv_addr.sin_port); listen(fd, 5); return(fd); }/*====================================================================== * * Read/write routines with timeout detection. * * Usage: write_to(fd, buffer, n, timeout) * read_to(fd, buffer, n, timeout) * * David Chavez * Engineering Services & Software * 7841 New Salem Street * San Diego, CA 92126 * USA * * dec@essw.com * *====================================================================*/#ifdef PHP_WIN32#include <time.h>#else#include <sys/fcntl.h>#include <sys/time.h>#include <sys/types.h>#endif#include <errno.h>#include <signal.h>#ifndef PHP_WIN32static sigset_t newmask, oldmask, zeromask;#endifstatic int set_noblock(int fd){#ifdef PHP_WIN32 u_long argp=1; return ioctlsocket (fd, FIONBIO , &argp); #else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -