diff --git a/include/crm/Makefile.am b/include/crm/Makefile.am index ba2e99d537..229dd7e8ac 100644 --- a/include/crm/Makefile.am +++ b/include/crm/Makefile.am @@ -1,21 +1,22 @@ # -# Author: Sun Jiang Dong -# Copyright (c) 2004 International Business Machines +# Copyright (C) 2004 Andrew Beekhof # # 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 the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # 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 the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -MAINTAINERCLEANFILES = Makefile.in +MAINTAINERCLEANFILES = Makefile.in -include_HEADERS = crm.h cib.h msg_xml.h +include_HEADERS = crm.h cib.h msg_xml.h + +SUBDIRS = common diff --git a/include/crm/Makefile.am b/include/crm/common/Makefile.am similarity index 84% copy from include/crm/Makefile.am copy to include/crm/common/Makefile.am index ba2e99d537..7947961697 100644 --- a/include/crm/Makefile.am +++ b/include/crm/common/Makefile.am @@ -1,21 +1,21 @@ # -# Author: Sun Jiang Dong -# Copyright (c) 2004 International Business Machines +# Copyright (C) 2004 Andrew Beekhof # # 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 the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # 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 the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # + MAINTAINERCLEANFILES = Makefile.in -include_HEADERS = crm.h cib.h msg_xml.h +include_HEADERS = xml.h ipc.h msg.h ctrl.h util.h diff --git a/include/crm/common/ctrl.h b/include/crm/common/ctrl.h new file mode 100644 index 0000000000..dc6452e6d4 --- /dev/null +++ b/include/crm/common/ctrl.h @@ -0,0 +1,44 @@ +/* $Id: ctrl.h,v 1.1 2004/06/02 11:40:50 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * 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 the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software 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 the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef CRM_COMMON___H +#define CRM_COMMON___H + +#include +#include +//#include + +extern gboolean tickle_apphb_template(gpointer data); + +extern void register_pid( + const char *pid_file, + gboolean do_fork, + void (*shutdown)(int nsig)); + +extern long get_running_pid(const char *pid_file, gboolean* anypidfile); + +extern int init_status(const char *pid_file, const char *client_name); + +extern int init_stop(const char *pid_file); + +extern void register_with_apphb( + const char *client_name, + gboolean(*tickle_fn)(gpointer data)); + + +#endif diff --git a/include/crm/common/ipc.h b/include/crm/common/ipc.h new file mode 100644 index 0000000000..1d16021c84 --- /dev/null +++ b/include/crm/common/ipc.h @@ -0,0 +1,55 @@ +/* $Id: ipc.h,v 1.1 2004/06/02 11:40:50 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * 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 the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software 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 the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef CRM_COMMON_IPC__H +#define CRM_COMMON_IPC__H + +#include +#include + +#include +#include + +typedef struct _crmd_client +{ + char *sub_sys; + char *uuid; + char *table_key; + IPC_Channel *client_channel; + GCHSource *client_source; +} crmd_client_t; + +extern gboolean send_ipc_message(IPC_Channel *ipc_client, IPC_Message *msg); + +extern void default_ipc_input_destroy(gpointer user_data); + +extern xmlNodePtr find_xml_in_ipcmessage(IPC_Message *msg, + gboolean do_free); + +extern gboolean send_xmlipc_message(IPC_Channel *ipc_client, + xmlNodePtr msg); + +extern IPC_Channel *init_client_ipc_comms( + const char *child, + gboolean (*dispatch)(IPC_Channel* source_data, gpointer user_data), + crmd_client_t *user_data); + +extern gboolean subsystem_input_dispatch(IPC_Channel *sender, void *user_data); + +#endif + diff --git a/include/crm/common/msg.h b/include/crm/common/msg.h new file mode 100644 index 0000000000..e397ab4ba9 --- /dev/null +++ b/include/crm/common/msg.h @@ -0,0 +1,67 @@ +/* $Id: msg.h,v 1.1 2004/06/02 11:40:50 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * 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 the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software 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 the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef CRM_COMMON_MSG__H +#define CRM_COMMON_MSG__H + +#include +#include +#include + +extern xmlNodePtr validate_crm_message(xmlNodePtr root, + const char *sys, + const char *uuid, + const char *msg_type); + +extern xmlNodePtr createPingAnswerFragment(const char *from, + const char *status); + +extern xmlNodePtr createPingRequest(const char *crm_msg_reference, + const char *to); + +extern void send_hello_message(IPC_Channel *ipc_client, + const char *uuid, + const char *client_name, + const char *major_version, + const char *minor_version); + +extern gboolean process_hello_message(xmlNodePtr hello, + char **uuid, + char **client_name, + char **major_version, + char **minor_version); + +extern gboolean send_ipc_request(IPC_Channel *ipc_channel, + xmlNodePtr xml_options, xmlNodePtr xml_data, + const char *host_to, const char *sys_to, + const char *sys_from, const char *uuid_from, + const char *crm_msg_reference); + +extern gboolean send_ipc_reply(IPC_Channel *ipc_channel, + xmlNodePtr xml_request, + xmlNodePtr xml_response_data); + +extern xmlNodePtr create_reply(xmlNodePtr xml_request, + xmlNodePtr xml_response_data); + +extern xmlNodePtr create_request(xmlNodePtr xml_options, xmlNodePtr xml_data, + const char *host_to, const char *sys_to, + const char *sys_from, const char *uuid_from, + const char *crm_msg_reference); + +#endif diff --git a/include/crm/common/util.h b/include/crm/common/util.h new file mode 100644 index 0000000000..c9f8595581 --- /dev/null +++ b/include/crm/common/util.h @@ -0,0 +1,41 @@ +/* $Id: util.h,v 1.1 2004/06/02 11:40:50 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * 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 the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software 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 the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef CRM_COMMON_UTIL__H +#define CRM_COMMON_UTIL__H + +extern char *crm_itoa(int an_int); + +extern char *generate_hash_key(const char *crm_msg_reference, + const char *sys); + +extern char *generate_hash_value(const char *src_node, + const char *src_subsys); + +extern gboolean decode_hash_value(gpointer value, + char **node, + char **subsys); + +gboolean decodeNVpair(const char *srcstring, + char separator, + char **name, + char **value); + +extern const char *generateReference(const char *custom1, const char *custom2); + +#endif diff --git a/include/crm/common/xml.h b/include/crm/common/xml.h new file mode 100644 index 0000000000..7efda5156e --- /dev/null +++ b/include/crm/common/xml.h @@ -0,0 +1,234 @@ +/* $Id: xml.h,v 1.1 2004/06/02 11:40:50 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * 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 the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software 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 the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef CRM_COMMON_XML__H +#define CRM_COMMON_XML__H + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +/* + * Replacement function for xmlCopyPropList which at the very least, + * doesnt work the way *I* would expect it to. + * + * Copy all the attributes/properties from src into target. + * + * Not recursive, does not return anything. + * + */ +extern void copy_in_properties(xmlNodePtr target, xmlNodePtr src); + +/* + * Find a child named search_path[i] at level i in the XML fragment where i=0 + * is an immediate child of root. + * + * Terminate with success if i == len, or search_path[i] == NULL. + * + * On success, returns the sub-fragment described by search_path. + * On failure, returns NULL. + */ +extern xmlNodePtr find_xml_node_nested(xmlNodePtr root, + const char **search_path, + int len); + + +/* + * In parent, find a child named node_name whose value for + * elem_filter_name is elem_filter_value and or has id set + * to id. + * + * elem_filter_name, elem_filter_value and id.may all + * be set to NULL, in which case the filter they represent will be ignored. + * + * By setting siblings, you also have the option of searching all + * other nodes at the same level as parent + * + * On success, returns parent or the created parent create + * was specified. + * + * On failure, returns NULL. + */ +extern xmlNodePtr find_entity_nested(xmlNodePtr parent, + const char *node_name, + const char *elem_filter_name, + const char *elem_filter_value, + const char *id, + gboolean siblings); +/* + * Find a child named search_path[i] at level i in the XML fragment where i=0 + * is an immediate child of root. + * + * Once the last child specified by node_path is found, find the value + * of attr_name. + * + * If error is set to TRUE, then it is an error for the attribute not + * to be found and the function will log accordingly. + * + * On success, returns the value of attr_name. + * On failure, returns NULL. + */ +extern const char *get_xml_attr_nested(xmlNodePtr parent, + const char **node_path, int length, + const char *attr_name, gboolean error); + +/* + * Find a child named search_path[i] at level i in the XML fragment where i=0 + * is an immediate child of root. + * + * Once the last child specified by node_path is found, set the value + * of attr_name to be attr_value. + * + * On success, returns parent or the created parent create + * was specified. + * + * On failure, returns NULL. + */ +extern xmlNodePtr set_xml_attr_nested(xmlNodePtr parent, + const char **node_path, int length, + const char *attr_name, + const char *attr_value, + gboolean create); + + + + +extern char * dump_xml_node(xmlNodePtr msg, gboolean whole_doc); + +/* + * Free the XML "stuff" associated with a_node + * + * If a_node is part of a document, free the whole thing + * + * Otherwise, unlink it from its current location and free everything + * from there down. + * + * Wont barf on NULL. + * + */ +extern void free_xml(xmlNodePtr a_node); + +/* + * Dump out the message, print some identifying text and clean up afterwards. + */ +extern void xml_message_debug(xmlNodePtr msg, const char *text); + +/* + * Create a node named "name" as a child of "parent" + * If parent is NULL, creates an unconnected node. + * + * Returns the created node + * + */ +extern xmlNodePtr create_xml_node(xmlNodePtr parent, const char *name); + +/* + * Make a copy of name and value and use the copied memory to create + * an attribute for node. + * + * If node, name or value are NULL, nothing is done. + * + * If name or value are an empty string, nothing is done. + * + * Returns NULL on failure and the attribute created on success. + * + */ +extern xmlAttrPtr set_xml_property_copy(xmlNodePtr node, + const xmlChar *name, + const xmlChar *value); + +/* + * Unlink the node and set its doc pointer to NULL so free_xml() + * will act appropriately + */ +extern void unlink_xml_node(xmlNodePtr node); + +/* + * Set a timestamp attribute on a_node + */ +extern void set_node_tstamp(xmlNodePtr a_node); + +/* + * Returns a deep copy of src_node + * + * Either calls xmlCopyNode() or a home grown alternative (based on + * XML_TRACE being defined) that does more logging... + * helpful when part of the XML document has been freed :) + */ +extern xmlNodePtr copy_xml_node_recursive(xmlNodePtr src_node); + +/* + * Add a copy of xml_node to new_parent + */ +extern xmlNodePtr add_node_copy(xmlNodePtr new_parent, xmlNodePtr xml_node); + + +/* + * Read in the contents of a pre-opened file descriptor (until EOF) and + * produce an XML fragment (it will have an attached document). + * + * input will need to be closed on completion. + * + * Whitespace between tags is discarded. + * + */ +extern xmlNodePtr file2xml(FILE *input); + +/* + * Read in the contents of a string and produce an XML fragment (it will + * have an attached document). + * + * input will need to be freed on completion. + * + * Whitespace between tags is discarded. + * + */ +extern xmlNodePtr string2xml(const char *input); + + +/* convience "wrapper" functions */ +extern xmlNodePtr find_xml_node(xmlNodePtr cib, const char * node_path); + +extern xmlNodePtr find_entity(xmlNodePtr parent, + const char *node_name, + const char *id, + gboolean siblings); + +extern const char *get_xml_attr(xmlNodePtr parent, + const char *node_name, const char *attr_name, + gboolean error); + +extern xmlNodePtr set_xml_attr(xmlNodePtr parent, + const char *node_name, + const char *attr_name, + const char *attr_value, + gboolean create); + +extern char *dump_xml(xmlNodePtr msg); + +extern char *dump_xml_node(xmlNodePtr msg, gboolean whole_doc); + +#endif