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");
161 xmlAddPrevSibling(priv->root->children, head_node);
163 if (title != NULL ) {
166 }
else if (out->
request != NULL) {
175 for (GSList *iter = extra_headers; iter != NULL; iter = iter->next) {
188 if (stylesheet_link != NULL) {
191 "href", stylesheet_link,
195 if (g_slist_length(priv->errors) > 0) {
197 g_slist_foreach(priv->errors, add_error_node, (gpointer) out);
202 htmlDocDump(out->
dest, priv->root->doc);
205 if (copy_dest != NULL) {
209 g_slist_free_full(extra_headers, (GDestroyNotify)
free_xml);
210 extra_headers = NULL;
217 out->
dest = freopen(NULL,
"w", out->
dest);
226 const char *proc_stdout,
const char *proc_stderr) {
236 if (proc_stdout != NULL) {
241 if (proc_stderr != NULL) {
256 "Program: Pacemaker");
260 "Author: Andrew Beekhof and " 261 "the Pacemaker project contributors");
279 va_start(ap, format);
280 len = vasprintf(&buf, format, ap);
284 priv->errors = g_slist_append(priv->errors, buf);
295 htmlNodePtr node = NULL;
306 const
char *plural_noun, const
char *format, ...) {
309 xmlNodePtr node = NULL;
318 q_len = g_queue_get_length(priv->parent_q);
323 if (format != NULL) {
328 va_start(ap, format);
329 len = vasprintf(&buf, format, ap);
343 g_queue_push_tail(priv->parent_q, node);
349 htmlNodePtr item_node = NULL;
356 va_start(ap, format);
357 len = vasprintf(&buf, format, ap);
384 g_queue_pop_tail(priv->parent_q);
388 if (g_queue_get_length(priv->parent_q) > 2) {
413 if (retval == NULL) {
420 retval->
init = html_init;
422 retval->
finish = html_finish;
423 retval->
reset = html_reset;
429 retval->
version = html_version;
430 retval->
info = html_info;
432 retval->
err = html_err;
441 retval->
spacer = html_spacer;
450 const char *class_name,
const char *text) {
451 htmlNodePtr node = NULL;
458 if (class_name != NULL) {
497 htmlNodePtr header_node;
504 char *key = va_arg(ap,
char *);
511 value = va_arg(ap,
char *);
515 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__assert(expr)
#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)