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

📄 msgutils.c

📁 在LINUX下实现HA的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	char *local_uuid;	char *local_client_name;	char *local_major_version;	char *local_minor_version;	FNIN();	*uuid = NULL;	*client_name = NULL;	*major_version = NULL;	*minor_version = NULL;	if (hello_message == NULL || hello_message->msg_body == NULL) {		FNRET(FALSE);	}	hello_doc = xmlParseMemory(		hello_message->msg_body,		strlen(hello_message->msg_body));	if (hello_doc == NULL) {		cl_log(LOG_ERR,		       "Expected a Hello message, Got: %s",		       (char*)hello_message->msg_body);		FNRET(FALSE);	}    	hello = xmlDocGetRootElement(hello_doc);	if (hello == NULL) {		FNRET(FALSE);	} else if (strcmp("hello", hello->name) != 0) {		FNRET(FALSE);	}	local_uuid = xmlGetProp(hello, "client_uuid");	local_client_name = xmlGetProp(hello, "client_name");	local_major_version = xmlGetProp(hello, "major_version");	local_minor_version = xmlGetProp(hello, "minor_version");	if (local_uuid == NULL || strlen(local_uuid) == 0) {		cl_log(LOG_ERR,		       "Hello message was not valid (field %s not found): %s",		       "uuid", (char*)hello_message->msg_body);		FNRET(FALSE);	} else if (local_client_name==NULL || strlen(local_client_name)==0){		cl_log(LOG_ERR,		       "Hello message was not valid (field %s not found): %s",		       "client name", (char*)hello_message->msg_body);		FNRET(FALSE);	} else if(local_major_version == NULL		  || strlen(local_major_version) == 0){		cl_log(LOG_ERR,		       "Hello message was not valid (field %s not found): %s",		       "major version", (char*)hello_message->msg_body);		FNRET(FALSE);	} else if (local_minor_version == NULL		   || strlen(local_minor_version) == 0){		cl_log(LOG_ERR,		       "Hello message was not valid (field %s not found): %s",		       "minor version", (char*)hello_message->msg_body);		FNRET(FALSE);	}    	*uuid           = cl_strdup(local_uuid);	*client_name   = cl_strdup(local_client_name);	*major_version = cl_strdup(local_major_version);	*minor_version = cl_strdup(local_minor_version);	FNRET(TRUE);}gbooleanforward_ipc_request(IPC_Channel *ipc_channel,		    xmlNodePtr xml_request, xmlNodePtr xml_response_data,		    const char *sys_to, const char *sys_from){	gboolean was_sent = FALSE;	xmlNodePtr forward;	FNIN();	forward = create_forward(xml_request,					    xml_response_data,					    sys_to);	if (forward != NULL)	{		was_sent = send_xmlipc_message(ipc_channel, forward);		free_xml(forward);	}	FNRET(was_sent);}/* * This method adds a copy of xml_response_data */gbooleansend_ipc_request(IPC_Channel *ipc_channel,		 xmlNodePtr msg_options, xmlNodePtr msg_data, 		 const char *host_to, const char *sys_to,		 const char *sys_from, const char *uuid_from,		 const char *crm_msg_reference){	gboolean was_sent = FALSE;	xmlNodePtr request = NULL;	FNIN();	request = create_request(msg_options, msg_data,				 host_to, sys_to,				 sys_from, uuid_from,				 crm_msg_reference);/* 	xml_message_debug(request, "Final request..."); */	was_sent = send_xmlipc_message(ipc_channel, request);	free_xml(request);	FNRET(was_sent);}/* * This method adds a copy of xml_response_data */gbooleansend_ha_request(ll_cluster_t *hb_fd,		xmlNodePtr msg_options, xmlNodePtr msg_data, 		const char *host_to, const char *sys_to,		const char *sys_from, const char *uuid_from,		const char *crm_msg_reference){	gboolean was_sent = FALSE;	xmlNodePtr request = NULL;	FNIN();	request = create_request(msg_options, msg_data,				 host_to, sys_to,				 sys_from, uuid_from,				 crm_msg_reference);/* 	xml_message_debug(request, "Final request..."); */	was_sent = send_xmlha_message(hb_fd, request);	free_xml(request);    	FNRET(was_sent);}xmlNodePtrcreate_request(xmlNodePtr msg_options, xmlNodePtr msg_data,	       const char *host_to, const char *sys_to,	       const char *sys_from, const char *uuid_from,	       const char *crm_msg_reference){	const char *true_from = sys_from;	xmlNodePtr request;	FNIN();	if (uuid_from != NULL)		true_from = generate_hash_key(sys_from, uuid_from);	/*  else make sure we are internal */	else {		if (strcmp(CRM_SYSTEM_LRMD, sys_from) != 0		    && strcmp(CRM_SYSTEM_PENGINE, sys_from) != 0		    && strcmp(CRM_SYSTEM_TENGINE, sys_from) != 0		    && strcmp(CRM_SYSTEM_DC, sys_from) != 0		    && strcmp(CRM_SYSTEM_CRMD, sys_from) != 0) {			cl_log(LOG_ERR,			       "only internal systems can leave uuid_from blank");			FNRET(FALSE);		}	}	if (crm_msg_reference == NULL) {		crm_msg_reference =			generateReference(				xmlGetProp(msg_options,XML_ATTR_OP),sys_from);	}		/*  host_from will get set for us if necessary by CRMd when routed */	request = create_xml_node(NULL, XML_MSG_TAG);	set_node_tstamp(request);	set_xml_property_copy(request, XML_ATTR_VERSION, CRM_VERSION);	set_xml_property_copy(request, XML_ATTR_MSGTYPE, XML_ATTR_REQUEST);	set_xml_property_copy(request, XML_ATTR_SYSTO,   sys_to);	set_xml_property_copy(request, XML_ATTR_SYSFROM, true_from);	set_xml_property_copy(request, XML_ATTR_REFERENCE, crm_msg_reference);	if(host_to != NULL && strlen(host_to) > 0)		set_xml_property_copy(request, XML_ATTR_HOSTTO,  host_to);	if (msg_options != NULL) {		add_node_copy(request, msg_options);	}	if (msg_data != NULL) {		add_node_copy(request, msg_data);	}	FNRET(request);}/* * This method adds a copy of xml_response_data */gbooleansend_ipc_reply(IPC_Channel *ipc_channel,	       xmlNodePtr xml_request,	       xmlNodePtr xml_response_data){	gboolean was_sent = FALSE;	xmlNodePtr reply;	FNIN();	reply = create_reply(xml_request, xml_response_data);/* 	xml_message_debug(reply, "Final reply..."); */	if (reply != NULL) {		was_sent = send_xmlipc_message(ipc_channel, reply);		free_xml(reply);	}	FNRET(was_sent);}/*  required?  or just send to self an let relay_message do its thing? *//* * This method adds a copy of xml_response_data */gbooleansend_ha_reply(ll_cluster_t *hb_cluster,	      xmlNodePtr xml_request,	      xmlNodePtr xml_response_data){	gboolean was_sent = FALSE;	xmlNodePtr reply;	FNIN();	was_sent = FALSE;	reply = create_reply(xml_request, xml_response_data);	if (reply != NULL) {		was_sent = send_xmlha_message(hb_cluster, reply);		free_xml(reply);	}	FNRET(was_sent);}/* * This method adds a copy of xml_response_data */xmlNodePtrcreate_reply(xmlNodePtr original_request,	     xmlNodePtr xml_response_data){	const char *host_from = NULL;	const char *sys_from  = NULL;	const char *sys_to    = NULL;	xmlNodePtr reply;		FNIN();	host_from = xmlGetProp(original_request, XML_ATTR_HOSTFROM);	sys_from  = xmlGetProp(original_request, XML_ATTR_SYSFROM);	sys_to  = xmlGetProp(original_request, XML_ATTR_SYSTO);	reply = create_common_message(original_request,						 xml_response_data);		set_xml_property_copy(reply, XML_ATTR_MSGTYPE, XML_ATTR_RESPONSE);		/* since this is a reply, we reverse the from and to */	/*  HOSTTO will be ignored if it is to the DC anyway. */	if(host_from != NULL && strlen(host_from) > 0)		set_xml_property_copy(reply, XML_ATTR_HOSTTO,   host_from);	set_xml_property_copy(reply, XML_ATTR_SYSTO,    sys_from);	set_xml_property_copy(reply, XML_ATTR_SYSFROM,  sys_to);	FNRET(reply);}/* * This method adds a copy of xml_response_data */xmlNodePtrcreate_forward(xmlNodePtr original_request,	       xmlNodePtr xml_response_data,	       const char *sys_to){	const char *host_from = NULL;	const char *host_to   = NULL;	const char *sys_from  = NULL;	xmlNodePtr forward;		FNIN();	host_from = xmlGetProp(original_request, XML_ATTR_HOSTFROM);	host_to   = xmlGetProp(original_request, XML_ATTR_HOSTTO);	sys_from  = xmlGetProp(original_request, XML_ATTR_SYSFROM);	forward = create_common_message(original_request,						    xml_response_data);		set_xml_property_copy(forward,			      XML_ATTR_MSGTYPE,			      XML_ATTR_REQUEST);		/*  HOSTTO will be ignored if it is to the DC anyway. */	if(host_to != NULL && strlen(host_to) > 0)		set_xml_property_copy(forward, XML_ATTR_HOSTTO,   host_to);	if(host_from != NULL)		set_xml_property_copy(forward, XML_ATTR_HOSTFROM, host_from);		set_xml_property_copy(forward, XML_ATTR_SYSTO,    sys_to);	set_xml_property_copy(forward, XML_ATTR_SYSFROM,  sys_from);	FNRET(forward);}xmlNodePtrcreate_common_message(xmlNodePtr original_request,		      xmlNodePtr xml_response_data){	const char *crm_msg_reference = NULL;	const char *type      = NULL;	const char *operation = NULL;	xmlNodePtr options = NULL;	xmlNodePtr new_message;		FNIN();	crm_msg_reference = xmlGetProp(original_request,				       XML_ATTR_REFERENCE);	type      = xmlGetProp(original_request, XML_ATTR_MSGTYPE);	operation = xmlGetProp(original_request, XML_ATTR_OP);		if (type == NULL) {		cl_log(LOG_ERR,		       "Cannot create new_message,"		       " no message type in original message");		FNRET(NULL);#if 0	} else if (strcmp(XML_ATTR_REQUEST, type) != 0) {		cl_log(LOG_ERR,		       "Cannot create new_message,"		       " original message was not a request");		FNRET(NULL);#endif	}	new_message = create_xml_node(NULL, XML_MSG_TAG);	set_node_tstamp(new_message);	set_xml_property_copy(new_message, XML_ATTR_VERSION, CRM_VERSION);	set_xml_property_copy(new_message, XML_ATTR_OP, operation);	set_xml_property_copy(new_message,			      XML_ATTR_REFERENCE,			      crm_msg_reference);    	if (xml_response_data != NULL) {		add_node_copy(new_message, xml_response_data);	}    	options = find_xml_node(original_request, XML_TAG_OPTIONS);	if (options != NULL) {		add_node_copy(new_message, options);	}	FNRET(new_message);}

⌨️ 快捷键说明

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