13 #include <libxml/HTMLtree.h> 20 static const char *stylesheet_default =
21 ".bold { font-weight: bold }\n" 23 ".online { color: green }\n" 24 ".offline { color: red }\n" 25 ".maint { color: blue }\n" 26 ".standby { color: blue }\n" 27 ".health_red { color: red }\n" 28 ".health_yellow { color: GoldenRod }\n" 30 ".rsc-failed { color: red }\n" 31 ".rsc-failure-ignored { color: DarkGreen }\n" 32 ".rsc-managed { color: blue }\n" 33 ".rsc-multiple { color: orange }\n" 34 ".rsc-ok { color: green }\n" 36 ".warning { color: red; font-weight: bold }";
38 static gboolean cgi_output = FALSE;
39 static char *stylesheet_link = NULL;
40 static char *title = NULL;
41 static GSList *extra_headers = NULL;
44 {
"html-cgi", 0, 0, G_OPTION_ARG_NONE, &cgi_output,
45 "Add CGI headers (requires --output-as=html)",
48 {
"html-stylesheet", 0, 0, G_OPTION_ARG_STRING, &stylesheet_link,
49 "Link to an external stylesheet (requires --output-as=html)",
52 {
"html-title", 0, 0, G_OPTION_ARG_STRING, &title,
53 "Specify a page title (requires --output-as=html)",
65 typedef struct private_data_s {
81 xmlFreeNode(priv->root);
82 g_queue_free(priv->parent_q);
83 g_slist_free(priv->errors);
93 if (out->
priv != NULL) {
97 if (out->
priv == NULL) {
104 priv->parent_q = g_queue_new();
107 xmlCreateIntSubset(priv->root->doc, (
pcmkXmlStr)
"html", NULL, NULL);
110 g_queue_push_tail(priv->parent_q, priv->root);
119 add_error_node(gpointer
data, gpointer user_data) {
120 char *str = (
char *)
data;
128 htmlNodePtr head_node = NULL;
129 htmlNodePtr charset_node = NULL;
134 if (priv == NULL || priv->root == NULL) {
138 if (cgi_output && print) {
139 fprintf(out->
dest,
"Content-Type: text/html\n\n");
146 head_node = xmlNewNode(NULL, (
pcmkXmlStr)
"head");
148 if (title != NULL ) {
150 }
else if (out->
request != NULL) {
158 for (
int i = 0; i < g_slist_length(extra_headers); i++) {
159 xmlAddChild(head_node, xmlCopyNode(g_slist_nth_data(extra_headers, i), 1));
170 if (stylesheet_link != NULL) {
173 "href", stylesheet_link,
177 xmlAddPrevSibling(priv->root->children, head_node);
179 if (g_slist_length(priv->errors) > 0) {
181 g_slist_foreach(priv->errors, add_error_node, (gpointer) out);
186 htmlDocDump(out->
dest, priv->root->doc);
189 if (copy_dest != NULL) {
193 g_slist_free_full(extra_headers, (GDestroyNotify) xmlFreeNode);
194 extra_headers = NULL;
201 out->
dest = freopen(NULL,
"w", out->
dest);
210 const char *proc_stdout,
const char *proc_stderr) {
220 if (proc_stdout != NULL) {
224 if (proc_stderr != NULL) {
240 "Author: Andrew Beekhof and " 241 "the Pacemaker project contributors");
257 va_start(ap, format);
258 len = vasprintf(&buf, format, ap);
262 priv->errors = g_slist_append(priv->errors, buf);
273 htmlNodePtr node = NULL;
284 const
char *plural_noun, const
char *format, ...) {
287 xmlNodePtr node = NULL;
296 q_len = g_queue_get_length(priv->parent_q);
301 if (format != NULL) {
306 va_start(ap, format);
307 len = vasprintf(&buf, format, ap);
321 g_queue_push_tail(priv->parent_q, node);
327 htmlNodePtr item_node = NULL;
334 va_start(ap, format);
335 len = vasprintf(&buf, format, ap);
360 g_queue_pop_tail(priv->parent_q);
364 if (g_queue_get_length(priv->parent_q) > 2) {
389 if (retval == NULL) {
394 retval->
request = argv == NULL ? NULL : g_strjoinv(
" ", argv);
396 retval->
init = html_init;
398 retval->
finish = html_finish;
399 retval->
reset = html_reset;
405 retval->
version = html_version;
406 retval->
info = html_info;
407 retval->
err = html_err;
416 retval->
spacer = html_spacer;
425 const char *class_name,
const char *text) {
426 htmlNodePtr node = NULL;
432 if (class_name != NULL) {
445 htmlNodePtr header_node;
452 char *key = va_arg(ap,
char *);
459 value = va_arg(ap,
char *);
463 extra_headers = g_slist_append(extra_headers, header_node);
void(* end_list)(pcmk__output_t *out)
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)
int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
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(*) 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
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)
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)