@@ -500,10 +500,51 @@ static int save_attributes(struct booth_config *conf, struct ticket_config *tk,
500
500
tk_log_error ("crm_ticket xml output empty" );
501
501
return - EINVAL ;
502
502
}
503
- if (xmlStrcmp (n -> name , (const xmlChar * )"ticket_state" )) {
503
+
504
+ if (xmlStrcmp (n -> name , (const xmlChar * ) PCMK_XE_PACEMAKER_RESULT ) == 0 ) {
505
+ xmlNode * tickets_node = NULL ;
506
+ xmlNode * ticket_node = NULL ;
507
+
508
+ /* This is XML from a libpacemaker API call. Move the node pointer to
509
+ * the ticket element containing the attributes we want to copy.
510
+ */
511
+
512
+ /* Look for a child node named <tickets>. */
513
+ for (xmlNode * child = n -> children ; child != NULL ; child = child -> next ) {
514
+ if (xmlStrcmp (child -> name , (const xmlChar * ) PCMK_XE_TICKETS ) == 0 ) {
515
+ tickets_node = child ;
516
+ break ;
517
+ }
518
+ }
519
+
520
+ if (tickets_node == NULL ) {
521
+ tk_log_error ("API result does not match expected" );
522
+ return - EINVAL ;
523
+ }
524
+
525
+ /* Under that should be a single <ticket> node containing the attributes
526
+ * we want to copy. libpacemaker should only return one node because we
527
+ * asked for a specific ticket, but just to be safe...
528
+ */
529
+ for (xmlNode * child = tickets_node -> children ; child != NULL ; child = child -> next ) {
530
+ if (xmlStrcmp (child -> name , (const xmlChar * ) PCMK_XE_TICKET ) == 0 ) {
531
+ ticket_node = child ;
532
+ break ;
533
+ }
534
+ }
535
+
536
+ if (ticket_node == NULL ) {
537
+ tk_log_error ("API result does not match expected" );
538
+ return - EINVAL ;
539
+ }
540
+
541
+ n = ticket_node ;
542
+ } else if (xmlStrcmp (n -> name , (const xmlChar * ) "ticket_state" ) != 0 ) {
543
+ /* This isn't any XML we expect */
504
544
tk_log_error ("crm_ticket xml root element not ticket_state" );
505
545
return - EINVAL ;
506
- }
546
+ }
547
+
507
548
for (attr = n -> properties ; attr ; attr = attr -> next ) {
508
549
v = xmlGetProp (n , attr -> name );
509
550
for (atp = attr_handlers ; atp -> name ; atp ++ ) {
@@ -528,6 +569,26 @@ static int save_attributes(struct booth_config *conf, struct ticket_config *tk,
528
569
}
529
570
530
571
572
+ #ifdef LIBPACEMAKER
573
+ static int pcmk_load_ticket (struct ticket_config * tk )
574
+ {
575
+ xmlNode * xml = NULL ;
576
+ int rv ;
577
+
578
+ rv = pcmk_ticket_state (& xml , tk -> name );
579
+
580
+ if (rv == pcmk_rc_ok ) {
581
+ rv = save_attributes (tk , xml -> doc );
582
+ } else {
583
+ log_error ("pcmk_load_ticket: %s" , pcmk_rc_str (rv ));
584
+ rv = -1 ;
585
+ }
586
+
587
+ xmlFreeNode (xml );
588
+ return rv ;
589
+ }
590
+ #else
591
+
531
592
#define CHUNK_SIZE 256
532
593
533
594
static int read_ticket_state (struct booth_config * conf , struct ticket_config * tk ,
@@ -634,6 +695,7 @@ static int pcmk_load_ticket(struct booth_config *conf, struct ticket_config *tk)
634
695
}
635
696
return rv | pipe_rv ;
636
697
}
698
+ #endif
637
699
638
700
639
701
struct ticket_handler pcmk_handler = {
0 commit comments