23 #define BEST_EFFORT_STATUS 0 34 dump_xml_for_digest(xmlNodePtr xml)
36 GString *buffer = g_string_sized_new(1024);
39 g_string_append_c(buffer,
' ');
41 g_string_append_c(buffer,
'\n');
57 calculate_xml_digest_v1(xmlNode *
input, gboolean sort, gboolean ignored)
60 GString *buffer = NULL;
70 buffer = dump_xml_for_digest(
input);
72 g_string_free(buffer, TRUE);
75 digest =
crm_md5sum((
const char *) buffer->str);
78 g_string_free(buffer, TRUE);
92 calculate_xml_digest_v2(
const xmlNode *source, gboolean do_filter)
95 GString *buffer = g_string_sized_new(1024);
97 crm_trace(
"Begin digest %s", do_filter?
"filtered":
"");
101 digest =
crm_md5sum((
const char *) buffer->str);
118 g_string_free(buffer, TRUE);
138 return calculate_xml_digest_v1(
input, FALSE, FALSE);
153 return calculate_xml_digest_v1(
input, TRUE, FALSE);
168 gboolean do_filter,
const char *
version)
183 crm_trace(
"Using v1 digest algorithm for %s",
184 pcmk__s(
version,
"unknown feature set"));
185 return calculate_xml_digest_v1(
input, sort, do_filter);
187 crm_trace(
"Using v2 digest algorithm for %s",
188 pcmk__s(
version,
"unknown feature set"));
189 return calculate_xml_digest_v2(
input, do_filter);
204 char *calculated = NULL;
209 if (calculated == NULL) {
210 crm_perror(LOG_ERR,
"Could not calculate digest for comparison");
216 crm_trace(
"Digest comparison passed: %s", calculated);
218 crm_err(
"Digest comparison failed: expected %s, calculated %s",
219 expected, calculated);
236 static const char *filter[] = {
245 if (strcmp(
name, filter[i]) == 0) {
255 int lpc = 0, len = 0;
259 if (buffer == NULL) {
262 len = strlen(buffer);
264 crm_trace(
"Beginning digest of %d bytes", len);
269 sprintf(digest + (2 * lpc),
"%02x", raw_digest[lpc]);
275 crm_err(
"Could not create digest");
#define CRM_CHECK(expr, failure_action)
#define XML_ATTR_UPDATE_ORIG
#define XML_ATTR_UPDATE_CLIENT
#define pcmk__if_tracing(if_action, else_action)
#define XML_ATTR_NUMUPDATES
char * calculate_on_disk_digest(xmlNode *input)
Calculate and return digest of XML tree, suitable for storing on disk.
Exclude certain XML attributes (for calculating digests)
#define XML_ATTR_UPDATE_USER
#define XML_ATTR_GENERATION
void * md5_buffer(const char *buffer, size_t len, void *resblock)
G_GNUC_INTERNAL void pcmk__xml2text(const xmlNode *data, uint32_t options, GString *buffer, int depth)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define crm_trace(fmt, args...)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
Wrappers for and extensions to libxml2.
bool pcmk__xa_filterable(const char *name)
void free_xml(xmlNode *child)
char * calculate_xml_versioned_digest(xmlNode *input, gboolean sort, gboolean do_filter, const char *version)
Calculate and return digest of XML tree.
xmlNode * sorted_xml(xmlNode *input, xmlNode *parent, gboolean recursive)
const char * pcmk__get_tmpdir(void)
bool pcmk__verify_digest(xmlNode *input, const char *expected)
void save_xml_to_file(const xmlNode *xml, const char *desc, const char *filename)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define crm_err(fmt, args...)
#define XML_CIB_ATTR_WRITTEN
int compare_version(const char *version1, const char *version2)
#define XML_ATTR_GENERATION_ADMIN
char * calculate_operation_digest(xmlNode *input, const char *version)
Calculate and return digest of XML operation.
#define crm_log_xml_trace(xml, text)
char * crm_md5sum(const char *buffer)