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(xmlNode *source, gboolean do_filter)
95 GString *buffer = g_string_sized_new(1024);
97 static struct qb_log_callsite *digest_cs = NULL;
99 crm_trace(
"Begin digest %s", do_filter?
"filtered":
"");
103 digest =
crm_md5sum((
const char *) buffer->str);
105 if (digest_cs == NULL) {
106 digest_cs = qb_log_callsite_get(__func__, __FILE__,
"cib-digest",
LOG_TRACE, __LINE__,
109 if (digest_cs && digest_cs->targets) {
121 g_string_free(buffer, TRUE);
141 return calculate_xml_digest_v1(
input, FALSE, FALSE);
156 return calculate_xml_digest_v1(
input, TRUE, FALSE);
171 gboolean do_filter,
const char *
version)
186 crm_trace(
"Using v1 digest algorithm for %s",
187 pcmk__s(
version,
"unknown feature set"));
188 return calculate_xml_digest_v1(
input, sort, do_filter);
190 crm_trace(
"Using v2 digest algorithm for %s",
191 pcmk__s(
version,
"unknown feature set"));
192 return calculate_xml_digest_v2(
input, do_filter);
207 char *calculated = NULL;
212 if (calculated == NULL) {
213 crm_perror(LOG_ERR,
"Could not calculate digest for comparison");
219 crm_trace(
"Digest comparison passed: %s", calculated);
221 crm_err(
"Digest comparison failed: expected %s, calculated %s",
222 expected, calculated);
239 static const char *filter[] = {
248 if (strcmp(
name, filter[i]) == 0) {
258 int lpc = 0, len = 0;
262 if (buffer == NULL) {
265 len = strlen(buffer);
267 crm_trace(
"Beginning digest of %d bytes", len);
272 sprintf(digest + (2 * lpc),
"%02x", raw_digest[lpc]);
278 crm_err(
"Could not create digest");
#define CRM_CHECK(expr, failure_action)
#define XML_ATTR_UPDATE_ORIG
#define XML_ATTR_UPDATE_CLIENT
#define XML_ATTR_NUMUPDATES
char * calculate_on_disk_digest(xmlNode *input)
Calculate and return digest of XML tree, suitable for storing on disk.
#define XML_ATTR_UPDATE_USER
unsigned int crm_trace_nonlog
#define XML_ATTR_GENERATION
G_GNUC_INTERNAL void pcmk__xml2text(xmlNodePtr data, int options, GString *buffer, int depth)
void * md5_buffer(const char *buffer, size_t len, void *resblock)
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)
#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.
void save_xml_to_file(xmlNode *xml, const char *desc, const char *filename)
#define crm_log_xml_trace(xml, text)
char * crm_md5sum(const char *buffer)