13 #include <libxml/HTMLtree.h> 21 static const char *stylesheet_default =
22 ".bold { font-weight: bold }\n" 24 ".online { color: green }\n" 25 ".offline { color: red }\n" 26 ".maint { color: blue }\n" 27 ".standby { color: blue }\n" 28 ".health_red { color: red }\n" 29 ".health_yellow { color: GoldenRod }\n" 31 ".rsc-failed { color: red }\n" 32 ".rsc-failure-ignored { color: DarkGreen }\n" 33 ".rsc-managed { color: blue }\n" 34 ".rsc-multiple { color: orange }\n" 35 ".rsc-ok { color: green }\n" 37 ".warning { color: red; font-weight: bold }";
39 static gboolean cgi_output = FALSE;
40 static char *stylesheet_link = NULL;
41 static char *title = NULL;
42 static GSList *extra_headers = NULL;
45 {
"html-cgi", 0, 0, G_OPTION_ARG_NONE, &cgi_output,
46 "Add CGI headers (requires --output-as=html)",
49 {
"html-stylesheet", 0, 0, G_OPTION_ARG_STRING, &stylesheet_link,
50 "Link to an external stylesheet (requires --output-as=html)",
53 {
"html-title", 0, 0, G_OPTION_ARG_STRING, &title,
54 "Specify a page title (requires --output-as=html)",
66 typedef struct private_data_s {
78 if (out == NULL || out->
priv == NULL) {
84 xmlFreeNode(priv->root);
85 g_queue_free(priv->parent_q);
86 g_slist_free(priv->errors);
98 if (out->
priv != NULL) {
102 if (out->
priv == NULL) {
109 priv->parent_q = g_queue_new();
112 xmlCreateIntSubset(priv->root->doc, (
pcmkXmlStr)
"html", NULL, NULL);
115 g_queue_push_tail(priv->parent_q, priv->root);
124 add_error_node(gpointer
data, gpointer user_data) {
125 char *str = (
char *)
data;
133 htmlNodePtr head_node = NULL;
134 htmlNodePtr charset_node = NULL;
143 if (priv == NULL || priv->root == NULL) {
147 if (cgi_output && print) {
148 fprintf(out->
dest,
"Content-Type: text/html\n\n");
155 head_node = xmlNewDocRawNode(NULL, NULL, (
pcmkXmlStr)
"head", NULL);
157 if (title != NULL ) {
159 }
else if (out->
request != NULL) {
167 for (
int i = 0; i < g_slist_length(extra_headers); i++) {
168 xmlAddChild(head_node, xmlCopyNode(g_slist_nth_data(extra_headers, i), 1));
179 if (stylesheet_link != NULL) {
182 "href", stylesheet_link,
186 xmlAddPrevSibling(priv->root->children, head_node);
188 if (g_slist_length(priv->errors) > 0) {
190 g_slist_foreach(priv->errors, add_error_node, (gpointer) out);
195 htmlDocDump(out->
dest, priv->root->doc);
198 if (copy_dest != NULL) {
202 g_slist_free_full(extra_headers, (GDestroyNotify) xmlFreeNode);
203 extra_headers = NULL;
210 out->
dest = freopen(NULL,
"w", out->
dest);
219 const char *proc_stdout,
const char *proc_stderr) {
229 if (proc_stdout != NULL) {
233 if (proc_stderr != NULL) {
249 "Author: Andrew Beekhof and " 250 "the Pacemaker project contributors");
266 va_start(ap, format);
267 len = vasprintf(&buf, format, ap);
271 priv->errors = g_slist_append(priv->errors, buf);
282 htmlNodePtr node = NULL;
293 const
char *plural_noun, const
char *format, ...) {
296 xmlNodePtr node = NULL;
305 q_len = g_queue_get_length(priv->parent_q);
310 if (format != NULL) {
315 va_start(ap, format);
316 len = vasprintf(&buf, format, ap);
330 g_queue_push_tail(priv->parent_q, node);
336 htmlNodePtr item_node = NULL;
343 va_start(ap, format);
344 len = vasprintf(&buf, format, ap);
369 g_queue_pop_tail(priv->parent_q);
373 if (g_queue_get_length(priv->parent_q) > 2) {
398 if (retval == NULL) {
405 retval->
init = html_init;
407 retval->
finish = html_finish;
408 retval->
reset = html_reset;
414 retval->
version = html_version;
415 retval->
info = html_info;
417 retval->
err = html_err;
426 retval->
spacer = html_spacer;
435 const char *class_name,
const char *text) {
436 htmlNodePtr node = NULL;
443 if (class_name != NULL) {
456 htmlNodePtr header_node;
461 header_node = xmlNewDocRawNode(NULL, NULL, (
pcmkXmlStr)
name, NULL);
463 char *key = va_arg(ap,
char *);
470 value = va_arg(ap,
char *);
474 extra_headers = g_slist_append(extra_headers, header_node);
void(* end_list)(pcmk__output_t *out)
#define CRM_CHECK(expr, failure_action)
void void void void void pcmk__text_prompt(const char *prompt, bool echo, char **dest)
int(* message)(pcmk__output_t *out, const char *message_id,...)
const char * fmt_name
The name of this output formatter.
bool(* is_quiet)(pcmk__output_t *out)
void(* spacer)(pcmk__output_t *out)
xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name,...) G_GNUC_NULL_TERMINATED
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
enum crm_exit_e crm_exit_t
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define PACEMAKER_VERSION
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
void(* prompt)(const char *prompt, bool echo, char **dest)
GOptionEntry pcmk__html_output_entries[]
void * priv
Implementation-specific private data.
xmlNode * copy_xml(xmlNode *src_node)
void pcmk__html_add_header(const char *name,...)
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
xmlNode * pcmk_create_xml_text_node(xmlNode *parent, const char *name, const char *content)
pcmk__output_t * pcmk__mk_html_output(char **argv)
struct private_data_s private_data_t
void(* free_priv)(pcmk__output_t *out)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
bool(* init)(pcmk__output_t *out)
int(*) int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Wrappers for and extensions to libxml2.
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
xmlNodePtr pcmk__output_create_xml_node(pcmk__output_t *out, const char *name,...) G_GNUC_NULL_TERMINATED
int(*) int(* transient)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
void pcmk__xe_set_props(xmlNodePtr node,...) G_GNUC_NULL_TERMINATED
FILE * dest
Where output should be written.
const xmlChar * pcmkXmlStr
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3
xmlNodePtr pcmk__output_create_html_node(pcmk__output_t *out, const char *element_name, const char *id, const char *class_name, const char *text)
gchar * request
A copy of the request that generated this output.
This structure contains everything that makes up a single output formatter.
void(* version)(pcmk__output_t *out, bool extended)
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
void(* reset)(pcmk__output_t *out)
void(* progress)(pcmk__output_t *out, bool end)
gchar * pcmk__quote_cmdline(gchar **argv)
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)