13 #include <libxml/HTMLtree.h>
20 static const char *stylesheet_default =
21 ".bold { font-weight: bold }\n"
22 ".maint { color: blue }\n"
23 ".offline { color: red }\n"
24 ".online { color: green }\n"
25 ".rsc-failed { color: red }\n"
26 ".rsc-failure-ignored { color: yellow }\n"
27 ".rsc-managed { color: yellow }\n"
28 ".rsc-multiple { color: orange }\n"
29 ".rsc-ok { color: green }\n"
30 ".standby { color: orange }\n"
31 ".warning { color: red, font-weight: bold }";
33 static gboolean cgi_output = FALSE;
34 static char *stylesheet_link = NULL;
35 static char *title = NULL;
36 static GSList *extra_headers = NULL;
39 {
"html-cgi", 0, 0, G_OPTION_ARG_NONE, &cgi_output,
40 "Add CGI headers (requires --output-as=html)",
43 {
"html-stylesheet", 0, 0, G_OPTION_ARG_STRING, &stylesheet_link,
44 "Link to an external stylesheet (requires --output-as=html)",
47 {
"html-title", 0, 0, G_OPTION_ARG_STRING, &title,
48 "Specify a page title (requires --output-as=html)",
60 typedef struct private_data_s {
76 xmlFreeNode(priv->root);
77 g_queue_free(priv->parent_q);
78 g_slist_free(priv->errors);
88 if (out->
priv != NULL) {
92 if (out->
priv == NULL) {
99 priv->parent_q = g_queue_new();
102 xmlCreateIntSubset(priv->root->doc, (
pcmkXmlStr)
"html", NULL, NULL);
105 g_queue_push_tail(priv->parent_q, priv->root);
114 add_error_node(gpointer
data, gpointer user_data) {
115 char *str = (
char *) data;
123 htmlNodePtr head_node = NULL;
124 htmlNodePtr charset_node = NULL;
129 if (priv == NULL || priv->root == NULL) {
133 if (cgi_output && print) {
134 fprintf(out->
dest,
"Content-Type: text/html\n\n");
141 head_node = xmlNewNode(NULL, (
pcmkXmlStr)
"head");
143 if (title != NULL ) {
145 }
else if (out->
request != NULL) {
153 for (
int i = 0; i < g_slist_length(extra_headers); i++) {
154 xmlAddChild(head_node, xmlCopyNode(g_slist_nth_data(extra_headers, i), 1));
165 if (stylesheet_link != NULL) {
168 "href", stylesheet_link,
172 xmlAddPrevSibling(priv->root->children, head_node);
174 if (g_slist_length(priv->errors) > 0) {
176 g_slist_foreach(priv->errors, add_error_node, (gpointer) out);
181 htmlDocDump(out->
dest, priv->root->doc);
184 if (copy_dest != NULL) {
188 g_slist_free_full(extra_headers, (GDestroyNotify) xmlFreeNode);
189 extra_headers = NULL;
196 out->
dest = freopen(NULL,
"w", out->
dest);
205 const char *proc_stdout,
const char *proc_stderr) {
215 if (proc_stdout != NULL) {
219 if (proc_stderr != NULL) {
250 va_start(ap, format);
251 len = vasprintf(&buf, format, ap);
255 priv->errors = g_slist_append(priv->errors, buf);
266 htmlNodePtr node = NULL;
277 const
char *plural_noun, const
char *format, ...) {
280 xmlNodePtr node = NULL;
289 q_len = g_queue_get_length(priv->parent_q);
294 if (format != NULL) {
299 va_start(ap, format);
300 len = vasprintf(&buf, format, ap);
314 g_queue_push_tail(priv->parent_q, node);
320 htmlNodePtr item_node = NULL;
327 va_start(ap, format);
328 len = vasprintf(&buf, format, ap);
353 g_queue_pop_tail(priv->parent_q);
357 if (g_queue_get_length(priv->parent_q) > 2) {
382 if (retval == NULL) {
387 retval->
request = argv == NULL ? NULL : g_strjoinv(
" ", argv);
389 retval->
init = html_init;
391 retval->
finish = html_finish;
392 retval->
reset = html_reset;
398 retval->
version = html_version;
399 retval->
info = html_info;
400 retval->
err = html_err;
409 retval->
spacer = html_spacer;
418 const char *class_name,
const char *text) {
419 htmlNodePtr node = NULL;
425 if (class_name != NULL) {
438 htmlNodePtr header_node;
443 header_node = xmlNewNode(NULL, (
pcmkXmlStr) name);
445 char *key = va_arg(ap,
char *);
452 value = va_arg(ap,
char *);
456 extra_headers = g_slist_append(extra_headers, header_node);
bool(* init)(pcmk__output_t *out)
xmlNodePtr pcmk__output_create_xml_node(pcmk__output_t *out, const char *name,...)
void void void void void pcmk__text_prompt(const char *prompt, bool echo, char **dest)
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
const char * fmt_name
The name of this output formatter.
void(* reset)(pcmk__output_t *out)
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)
pcmk__output_t * pcmk__mk_html_output(char **argv)
int(* message)(pcmk__output_t *out, const char *message_id,...)
void pcmk__xe_set_props(xmlNodePtr node,...)
enum crm_exit_e crm_exit_t
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
xmlNodePtr pcmk__output_create_html_node(pcmk__output_t *out, const char *element_name, const char *id, const char *class_name, const char *text)
#define PACEMAKER_VERSION
GOptionEntry pcmk__html_output_entries[]
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
void * priv
Implementation-specific private data.
xmlNode * copy_xml(xmlNode *src_node)
bool(* is_quiet)(pcmk__output_t *out)
void(* end_list)(pcmk__output_t *out)
void pcmk__html_add_header(const char *name,...)
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
xmlNode * pcmk_create_xml_text_node(xmlNode *parent, const char *name, const char *content)
struct private_data_s private_data_t
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
void(* spacer)(pcmk__output_t *out)
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
void(* progress)(pcmk__output_t *out, bool end)
FILE * dest
Where output should be written.
const xmlChar * pcmkXmlStr
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
void(* free_priv)(pcmk__output_t *out)
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(* prompt)(const char *prompt, bool echo, char **dest)
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name,...)
int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3