13 #include <libxml/HTMLtree.h> 21 static const char *stylesheet_default =
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) {
89 g_queue_free(priv->parent_q);
90 g_slist_free_full(priv->errors, free);
102 if (out->
priv != NULL) {
106 if (out->
priv == NULL) {
113 priv->parent_q = g_queue_new();
116 xmlCreateIntSubset(priv->root->doc, (
pcmkXmlStr)
"html", NULL, NULL);
119 g_queue_push_tail(priv->parent_q, priv->root);
128 add_error_node(gpointer
data, gpointer user_data) {
129 char *str = (
char *)
data;
137 htmlNodePtr head_node = NULL;
138 htmlNodePtr charset_node = NULL;
139 xmlNode *child_node = NULL;
148 if (priv == NULL || priv->root == NULL) {
152 if (cgi_output && print) {
153 fprintf(out->
dest,
"Content-Type: text/html\n\n");
160 head_node = xmlNewDocRawNode(NULL, NULL, (
pcmkXmlStr)
"head", NULL);
162 if (title != NULL ) {
165 }
else if (out->
request != NULL) {
174 for (
int i = 0; i < g_slist_length(extra_headers); i++) {
175 xmlAddChild(head_node, xmlCopyNode(g_slist_nth_data(extra_headers, i), 1));
187 if (stylesheet_link != NULL) {
190 "href", stylesheet_link,
194 xmlAddPrevSibling(priv->root->children, head_node);
196 if (g_slist_length(priv->errors) > 0) {
198 g_slist_foreach(priv->errors, add_error_node, (gpointer) out);
203 htmlDocDump(out->
dest, priv->root->doc);
206 if (copy_dest != NULL) {
210 g_slist_free_full(extra_headers, (GDestroyNotify) xmlFreeNode);
211 extra_headers = NULL;
218 out->
dest = freopen(NULL,
"w", out->
dest);
227 const char *proc_stdout,
const char *proc_stderr) {
237 if (proc_stdout != NULL) {
242 if (proc_stderr != NULL) {
257 "Program: Pacemaker");
261 "Author: Andrew Beekhof and " 262 "the Pacemaker project contributors");
280 va_start(ap, format);
281 len = vasprintf(&buf, format, ap);
285 priv->errors = g_slist_append(priv->errors, buf);
296 htmlNodePtr node = NULL;
307 const
char *plural_noun, const
char *format, ...) {
310 xmlNodePtr node = NULL;
319 q_len = g_queue_get_length(priv->parent_q);
324 if (format != NULL) {
329 va_start(ap, format);
330 len = vasprintf(&buf, format, ap);
344 g_queue_push_tail(priv->parent_q, node);
350 htmlNodePtr item_node = NULL;
357 va_start(ap, format);
358 len = vasprintf(&buf, format, ap);
385 g_queue_pop_tail(priv->parent_q);
389 if (g_queue_get_length(priv->parent_q) > 2) {
414 if (retval == NULL) {
421 retval->
init = html_init;
423 retval->
finish = html_finish;
424 retval->
reset = html_reset;
430 retval->
version = html_version;
431 retval->
info = html_info;
433 retval->
err = html_err;
442 retval->
spacer = html_spacer;
451 const char *class_name,
const char *text) {
452 htmlNodePtr node = NULL;
459 if (class_name != NULL) {
498 htmlNodePtr header_node;
503 header_node = xmlNewDocRawNode(NULL, NULL, (
pcmkXmlStr)
name, NULL);
505 char *key = va_arg(ap,
char *);
512 value = va_arg(ap,
char *);
516 extra_headers = g_slist_append(extra_headers, header_node);
void(* end_list)(pcmk__output_t *out)
#define CRM_CHECK(expr, failure_action)
#define PCMK__VALUE_RSC_OK
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
xmlNode * pcmk__html_create(xmlNode *parent, const char *name, const char *id, const char *class)
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,...)
#define PCMK__VALUE_RSC_MULTIPLE
const char * fmt_name
The name of this output formatter.
#define PCMK_VALUE_STANDBY
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 pcmk__xe_set_content(xmlNode *node, const char *format,...) G_GNUC_PRINTF(2
void(* prompt)(const char *prompt, bool echo, char **dest)
GOptionEntry pcmk__html_output_entries[]
#define PCMK__VALUE_RSC_FAILURE_IGNORED
void * priv
Implementation-specific private data.
void pcmk__html_add_header(const char *name,...)
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
#define PCMK__VALUE_WARNING
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
#define PCMK__VALUE_RSC_FAILED
#define PCMK__VALUE_OUTPUT
Wrappers for and extensions to libxml2.
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
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 free_xml(xmlNode *child)
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
#define PCMK__VALUE_HEALTH_RED
#define PCMK_VALUE_ONLINE
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
#define PCMK__VALUE_HEALTH_YELLOW
#define PCMK__VALUE_RSC_MANAGED
#define PCMK__VALUE_MAINT
void(* reset)(pcmk__output_t *out)
void(* progress)(pcmk__output_t *out, bool end)
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
gchar * pcmk__quote_cmdline(gchar **argv)
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
#define PCMK_VALUE_OFFLINE
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)