📄 hg_comm.c
字号:
tmp = build_msg_int(msg.buf, objectID); tmp = build_msg_str(tmp, objrec); if ( send_hg_msg(sockfd, &msg, length) == -1 ) { efree(msg.buf); return(-2); } efree(msg.buf); retmsg = recv_hg_msg(sockfd); if(retmsg == NULL) { return(-1); } ptr = (int *) retmsg->buf; if(0 != (error = *ptr)) { efree(retmsg->buf); efree(retmsg); *new_objectID = 0; return error; } ptr++; *new_objectID = *ptr; efree(retmsg->buf); efree(retmsg); return 0;}int send_insdoc(int sockfd, hw_objectID objectID, char *objrec, char *text, hw_objectID *new_objectID){ hg_msg msg, *retmsg; int length, error; char *tmp; int *ptr; length = HEADER_LENGTH + sizeof(hw_objectID) + strlen(objrec) + 1; if(text) { length += strlen(text); length++; } build_msg_header(&msg, length, msgid++, INSDOC_MESSAGE); if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { lowerror = LE_MALLOC; return(-3); } tmp = build_msg_int(msg.buf, objectID); tmp = build_msg_str(tmp, objrec); if(text) tmp = build_msg_str(tmp, text); if ( send_hg_msg(sockfd, &msg, length) == -1 ) { efree(msg.buf); return(-2); } efree(msg.buf); retmsg = recv_hg_msg(sockfd); if(retmsg == NULL) { return(-1); } ptr = (int *) retmsg->buf; if(0 != (error = *ptr)) { efree(retmsg->buf); efree(retmsg); *new_objectID = 0; return error; } ptr++; *new_objectID = *ptr; efree(retmsg->buf); efree(retmsg); return 0;}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, char *urlprefix){ hg_msg msg, *retmsg; int length, *ptr, ancount, error; char *tmp, *attributes, *documenttype; char **anchors; int i; length = HEADER_LENGTH + sizeof(hw_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); } 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) { attributes = NULL; return(-1); } ptr = (int *) retmsg->buf; if(*ptr == 0) { attributes = estrdup(retmsg->buf+sizeof(int)); efree(retmsg->buf); efree(retmsg); } else { error = *ptr; attributes = NULL; efree(retmsg->buf); efree(retmsg); return error; } length = HEADER_LENGTH + strlen(attributes) + 1; build_msg_header(&msg, length, msgid++, GETTEXT_MESSAGE); if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) {/* perror("send_command"); */ lowerror = LE_MALLOC; return(-1); } tmp = build_msg_str(msg.buf, attributes); documenttype = fnAttributeValue(attributes, "DocumentType"); *objattr = strdup(attributes); efree(attributes); if ( send_hg_msg(sockfd, &msg, length) == -1 ) { efree(msg.buf); return(-1); } efree(msg.buf); retmsg = recv_hg_msg(sockfd); if (retmsg == NULL) { *text = NULL; return(-1); } ptr = (int *) retmsg->buf; if(*ptr == 0) { ptr++; *count = retmsg->length-HEADER_LENGTH-sizeof(int); if(NULL != (*text = malloc(*count + 1))) { memcpy(*text, retmsg->buf+sizeof(int), *count);/* *text[*count] = 0; */ } else { efree(retmsg->buf); efree(retmsg); lowerror = LE_MALLOC; return(-1); } } else { error = *ptr; efree(retmsg->buf); efree(retmsg); *text = NULL; return(error); } efree(retmsg->buf); efree(retmsg); if((documenttype != NULL) && (strcmp(documenttype, "Image") != 0)) { if(send_getanchorsobj(sockfd, objectID, &anchors, &ancount) == 0) { char **destrec, **reldestrec;#ifdef newlist zend_llist *pAnchorList;#else DLIST *pAnchorList;#endif /* Get dest as relative and absolut path */ send_getdestforanchorsobj(sockfd, anchors, &destrec, ancount); send_getreldestforanchorsobj(sockfd, anchors, &reldestrec, ancount, rootid, objectID); pAnchorList = fnCreateAnchorList(objectID, anchors, destrec, reldestrec, ancount, mode); /* Free only the array, the objrecs has been freed in fnCreateAnchorList() */ if(anchors) efree(anchors); if(destrec) efree(destrec); if(reldestrec) efree(reldestrec); if(pAnchorList != NULL) { char *newtext; char *body = NULL; char **prefixarray; prefixarray = emalloc(5*sizeof(char *)); for(i=0; i<5; i++) prefixarray[i] = urlprefix; newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, prefixarray); efree(prefixarray);#ifdef newlist zend_llist_destroy(pAnchorList); efree(pAnchorList);#else dlst_kill(pAnchorList, fnDeleteAnchor);#endif *bodytag = strdup(body); if(body) efree(body); *text = newtext; *count = strlen(newtext); } } } if(documenttype) efree(documenttype); return(0);}int send_insertanchors(char **text, int *count, char **anchors, char **destrec, int ancount, char **urlprefix, char **bodytag) { char **reldestrec = NULL; int mode = 0; hw_objectID objectID = 0;#ifdef newlist zend_llist *pAnchorList = NULL;#else DLIST *pAnchorList = NULL;#endif pAnchorList = fnCreateAnchorList(objectID, anchors, destrec, reldestrec, ancount, mode); /* Free only the array, the objrecs has been freed in fnCreateAnchorList() */ if(anchors) efree(anchors); if(destrec) efree(destrec); if(reldestrec) efree(reldestrec); if(pAnchorList != NULL) { char *newtext; char *body = NULL; newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, urlprefix);#ifdef newlist zend_llist_destroy(pAnchorList); efree(pAnchorList);#else dlst_kill(pAnchorList, fnDeleteAnchor);#endif *bodytag = strdup(body); if(body) efree(body); *text = newtext; *count = strlen(newtext); } return 0;}int send_edittext(int sockfd, char *objattr, char *text){ hg_msg msg, *retmsg; int length, *ptr, error; char *tmp, *path, *objid; hw_objectID objectID; objid = fnAttributeValue(objattr, "ObjectID"); if(objid == NULL) return(-1); if(!sscanf(objid, "0x%x", &objectID)) return(-2); path = fnAttributeValue(objattr, "Path"); if(path == NULL) 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(-4); } tmp = build_msg_int(msg.buf, objectID); tmp = build_msg_str(tmp, path); tmp = build_msg_str(tmp, ""); tmp = build_msg_str(tmp, text); if(path) efree(path); if(objid) efree(objid); if ( send_hg_msg(sockfd, &msg, length) == -1 ) { efree(msg.buf); return(-5); } efree(msg.buf); retmsg = recv_hg_msg(sockfd); if (retmsg == NULL) { *text = '\0'; return(-6); } ptr = (int *) retmsg->buf; error = *ptr; efree(retmsg->buf); efree(retmsg); return(error);}int send_getcgi(int sockfd, hw_objectID objectID, char *cgi_env_str, char **objattr, char **text, int *count){ hg_msg msg, *retmsg; int length, *ptr, error, new_attr_len; char *tmp, *attributes, *new_attr; length = HEADER_LENGTH + sizeof(hw_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); } 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) { attributes = NULL; return(-1); } ptr = (int *) retmsg->buf; if(*ptr == 0) { attributes = estrdup(retmsg->buf+sizeof(int)); efree(retmsg->buf); efree(retmsg); } else { error = *ptr; attributes = NULL; efree(retmsg->buf); efree(retmsg); return error; } new_attr_len = strlen(attributes) + strlen(cgi_env_str) + 2; new_attr = malloc(new_attr_len); strcpy(new_attr, attributes); strcat(new_attr, cgi_env_str); length = HEADER_LENGTH + strlen(new_attr) + 1 + sizeof(int); build_msg_header(&msg, length, msgid++, GETCGI_MESSAGE); if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) {/* perror("send_command"); */ lowerror = LE_MALLOC; return(-1); } tmp = build_msg_str(msg.buf, new_attr); tmp = build_msg_int(tmp, 0); *objattr = strdup(attributes); efree(attributes); free(new_attr); if ( send_hg_msg(sockfd, &msg, length) == -1 ) { efree(msg.buf); return(-1); } efree(msg.buf); retmsg = recv_hg_msg(sockfd); if (retmsg == NULL) { *text = NULL; return(-1); } /* Attention: It looks like the documentation is not quite right. According to the docs the buffer starts with an integer which is followed by the output of the cgi script. This seems not to be true. There is another integer right after the error. The output of the cgi script is also preceded by the 'Content-type' header. */ ptr = (int *) retmsg->buf; if(*ptr++ == 1024) { *count = *ptr++; if(NULL != (*text = malloc(*count + 1))) { memcpy(*text, ptr, *count); } else { efree(retmsg->buf); efree(retmsg); lowerror = LE_MALLOC; return(-1); } } else { error = *ptr + 1024; /* move errors to >2024 */ efree(retmsg->buf); efree(retmsg); *text = NULL; return(error); } efree(retmsg->buf); efree(retmsg); return(0);}int send_getremote(int sockfd, hw_objectID objectID, char **objattr, char **text, int *count){ hg_msg msg, *retmsg; int length, *ptr, error; char *tmp, *attributes; length = HEADER_LENGTH + sizeof(hw_objectID); build_msg_header(&msg, length, msgid++, GETOBJECT_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) { attributes = NULL; return(-1); } ptr = (int *) retmsg->buf; if(*ptr == 0) { attributes = estrdup(retmsg->buf+sizeof(int)); efree(retmsg->buf); efree(retmsg); } else { error = *ptr; attributes = NULL; efree(retmsg->buf); efree(retmsg); return error; } length = HEADER_LENGTH + strlen(attributes) + 1 + sizeof(int); build_msg_header(&msg, length, msgid++, GETREMOTE_MESSAGE); if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) { lowerror = LE_MALLOC; return(-1); } tmp = build_msg_str(msg.buf, attributes); tmp = build_msg_int(tmp, 0); *objattr = strdup(attributes); efree(attributes); if ( send_hg_msg(sockfd, &msg, length) == -1 ) { efree(msg.buf); return(-1); } efree(msg.buf); retmsg = recv_hg_msg(sockfd); if (retmsg == NULL) { *text = NULL; return(-1); } ptr = (int *) retmsg->buf; if(*ptr == 1024) { *count = retmsg->length-HEADER_LENGTH-sizeof(int)-size
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -