⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hg_comm.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif	return(msg);}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"); */		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); */		efree(ready_msg);		return(NULL);	}	return(ready_msg);}hg_msg *recv_command(int sockfd){	hg_msg *comm_msg;	if ( (comm_msg = recv_hg_msg(sockfd)) == NULL )  {/*		fprintf(stderr, "recv_command: recv_hg_msg returned NULL\n"); */		return(NULL);	}	if ( comm_msg->msg_type != COMMAND_MESSAGE )  {/*		fprintf(stderr, "recv_command: recv_hg_msg returned wrong message\n"); */		return(NULL);	}	return(comm_msg);}int send_dummy(int sockfd, hw_objectID objectID, int msg_id, char **attributes){	hg_msg msg, *retmsg;	int  length, error;	char *tmp;	length = HEADER_LENGTH + sizeof(hw_objectID);	build_msg_header(&msg, length, msg_id++, msg_id);	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);	}	if(0 == (int) *(retmsg->buf)) {		*attributes = estrdup(retmsg->buf+sizeof(int));		efree(retmsg->buf);		efree(retmsg);	} else {		error = *((int *) retmsg->buf);		*attributes = NULL;		efree(retmsg->buf);		efree(retmsg);		return error;	}	return(0);}static int bh_send_deleteobject(int sockfd, hw_objectID objectID) {	hg_msg msg;	int  length;	char *tmp;	length = HEADER_LENGTH + sizeof(hw_objectID);	build_msg_header(&msg, length, msgid++, DELETEOBJECT_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);	return(msgid-1);}static int uh_send_deleteobject(int sockfd) {	hg_msg *retmsg;	int  error;	retmsg = recv_hg_msg(sockfd);	if ( retmsg == NULL )  {		return(-1);	}	if(NULL == retmsg->buf) {		efree(retmsg);		return -1;	}	error = *((int *) retmsg->buf);	efree(retmsg->buf);	efree(retmsg);	return(error);}int send_deleteobject(int sockfd, hw_objectID objectID){	if(0 > bh_send_deleteobject(sockfd, objectID))		return -1;	return(uh_send_deleteobject(sockfd));}static int bh_send_changeobject(int sockfd, hw_objectID objectID, char *mod) {	hg_msg msg;	int  length;	char *tmp;	length = HEADER_LENGTH + sizeof(hw_objectID) + strlen(mod) + 1;	build_msg_header(&msg, length, msgid++, CHANGEOBJECT_MESSAGE);	if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL )  {		lowerror = LE_MALLOC;		return(-1);	}	tmp = build_msg_int(msg.buf, objectID);	tmp = build_msg_str(tmp, mod);	if ( send_hg_msg(sockfd, &msg, length) == -1 )  {		efree(msg.buf);		return(-1);	}	efree(msg.buf);	return(msgid-1);}static int uh_send_changeobject(int sockfd) {	hg_msg *retmsg;	int  error;	retmsg = recv_hg_msg(sockfd);	if ( retmsg == NULL )  {		return(-1);	}	error = *((int *) retmsg->buf);	efree(retmsg->buf);	efree(retmsg);	return(error);}int send_changeobject(int sockfd, hw_objectID objectID, char *modification){	if(0 > bh_send_changeobject(sockfd, objectID, modification))		return -1;	return(uh_send_changeobject(sockfd));}int send_groupchangeobject(int sockfd, hw_objectID objectID, char *modification){	hw_objectID *childIDs;	int count, i, error;	if(0 == (error = send_lock(sockfd, objectID))) {		send_changeobject(sockfd, objectID, modification);		send_unlock(sockfd, objectID);	}/* else		fprintf(stderr, "Could not lock 0x%X (error = %d)\n", objectID, error); */	if(0 == send_children(sockfd, objectID, &childIDs, &count)) {/*		fprintf(stderr, "Changing Children of 0x%X\n", objectID); */		for(i=0; i<count; i++)			if(0 > send_groupchangeobject(sockfd, childIDs[i], modification))/*				fprintf(stderr, "Cannot change 0x%X\n", objectID) */;		if(childIDs)			efree(childIDs);	}/*  else		fprintf(stderr, "No Children of 0x%X\n", objectID);  */	return(0);}static int bh_send_getobject(int sockfd, hw_objectID objectID) {	hg_msg msg;	int  length;	char *tmp;	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);	return(msgid-1);}static int uh_send_getobject(int sockfd, char **attributes) {	hg_msg *retmsg;	int  error;	retmsg = recv_hg_msg(sockfd);	if ( retmsg == NULL )  {		*attributes = NULL;		return(-1);	}	if(0 == (int) *(retmsg->buf)) {		*attributes = estrdup(retmsg->buf+sizeof(int));		efree(retmsg->buf);		efree(retmsg);	} else {		error = *((int *) retmsg->buf);		*attributes = NULL;		efree(retmsg->buf);		efree(retmsg);		return error;	}	return(0);}int send_getobject(int sockfd, hw_objectID objectID, char **attributes){	if(0 > bh_send_getobject(sockfd, objectID))		return -1;	return(uh_send_getobject(sockfd, attributes));}int send_getandlock(int sockfd, hw_objectID objectID, char **attributes){	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 )  {/*		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);	}	if(0 == (error = (int) *(retmsg->buf))) {		*attributes = estrdup(retmsg->buf+sizeof(int));	} else {		*attributes = NULL;	}	efree(retmsg->buf);	efree(retmsg);	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;	int  length, error;	char *tmp;	int *ptr;	length = HEADER_LENGTH + strlen(objrec) + 1 + strlen(parms) + 1;	build_msg_header(&msg, length, msgid++, INSERTOBJECT_MESSAGE);	if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL )  {/*		perror("send_command"); */		lowerror = LE_MALLOC;		return(-1);	}	tmp = build_msg_str(msg.buf, objrec);	tmp = build_msg_str(tmp, parms);/*fprintf(stderr, "objrec = %s, parms = %s\n", objrec, parms); */	if ( send_hg_msg(sockfd, &msg, length) == -1 )  {		efree(msg.buf);		return(-1);	}	efree(msg.buf);	retmsg = recv_hg_msg(sockfd);	if ( retmsg == NULL )  {		*objectID = 0;		return(-1);	}	ptr = (int *) retmsg->buf;	if(0 == (error = *ptr)) {		ptr++;		*objectID = *ptr;	} else {		*objectID = 0;	}	efree(retmsg->buf);	efree(retmsg);	return error;}int send_unlock(int sockfd, hw_objectID objectID){	hg_msg msg;	int  length;	char *tmp;	length = HEADER_LENGTH + sizeof(hw_objectID);	build_msg_header(&msg, length, msgid++, UNLOCK_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);	return 0;}int send_incollections(int sockfd, int retcol, int cobjids, hw_objectID *objectIDs, int ccollids, hw_objectID *collIDs, int *count, hw_objectID **retIDs){	hg_msg msg, *retmsg;	int  length, error;	char *tmp;	int *ptr, *ptr1, i;	length = HEADER_LENGTH + sizeof(hw_objectID) + (cobjids + ccollids) * sizeof(hw_objectID) + 2 * sizeof(int);	build_msg_header(&msg, length, msgid++, INCOLLECTIONS_MESSAGE);	if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL )  {		lowerror = LE_MALLOC;		return(-3);	}	tmp = build_msg_int(msg.buf, retcol);	tmp = build_msg_int(tmp, cobjids);	for(i=0; i<cobjids; i++)		tmp = build_msg_int(tmp, objectIDs[i]);	tmp = build_msg_int(tmp, ccollids);	for(i=0; i<ccollids; i++)		tmp = build_msg_int(tmp, collIDs[i]);	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(ptr == NULL) {		if(retmsg) efree(retmsg);		return -1;	}	if(*ptr++ == 0) {		*count = *ptr;		ptr++;		if(NULL != (*retIDs = emalloc(*count * sizeof(hw_objectID)))) {			ptr1 = *retIDs;			for(i=0; i<*count; ptr++, i++)				ptr1[i] = *ptr;			efree(retmsg->buf);			efree(retmsg);		} else {			efree(retmsg->buf);			efree(retmsg);			lowerror = LE_MALLOC;			return(-1);		}	} else {		error = *((int *) retmsg->buf);		if(retmsg->buf) efree(retmsg->buf);		if(retmsg) efree(retmsg);		return error;	}	return(0);}int send_inscoll(int sockfd, hw_objectID objectID, char *objrec, hw_objectID *new_objectID){	hg_msg msg, *retmsg;	int  length, error;	char *tmp;	int *ptr;	length = HEADER_LENGTH + sizeof(hw_objectID) + strlen(objrec) + 1;	build_msg_header(&msg, length, msgid++, INSCOLL_MESSAGE);	if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL )  {		lowerror = LE_MALLOC;		return(-3);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -