1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-06-10 03:02:20 +00:00

Add support for out_to_http

This commit is contained in:
Nikolas Garofil 2010-06-04 14:41:12 +02:00
parent 1180733e13
commit 54d4e6518d
8 changed files with 79 additions and 2 deletions

View File

@ -57,6 +57,7 @@ set(CONFIG_FILE "$HOME/.conkyrc" CACHE STRING "Configfile of the user")
set(MAX_USER_TEXT_DEFAULT "16384" CACHE STRING "Default maximum size of config TEXT buffer, i.e. below TEXT line.")
set(DEFAULT_TEXT_BUFFER_SIZE "256" CACHE STRING "Default size used for temporary, static text buffers")
set(MAX_NET_INTERFACES "16" CACHE STRING "Maximum number of network devices")
set(HTTPPORT "10080" CACHE STRING "Port to use for out_to_http")
# Platform specific options
@ -153,4 +154,6 @@ option(BUILD_ICAL "Enable if you want iCalendar (RFC 5545) support" false)
option(BUILD_IRC "Enable if you want IRC support" false)
option(BUILD_HTTP "Enable if you want HTTP support" false)
option(BUILD_ICONV "Enable iconv support" false)

View File

@ -82,6 +82,15 @@ if(BUILD_IRC)
set(conky_libs ${conky_libs} -lircclient)
endif(BUILD_IRC)
if(BUILD_HTTP)
find_file(HTTP_H_ microhttpd.h)
#I'm not using check_include_files because microhttpd.h seems to need a lot of different headers and i'm not sure which...
if(NOT HTTP_H_)
message(FATAL_ERROR "Unable to find libmicrohttpd")
endif(NOT HTTP_H_)
set(conky_libs ${conky_libs} -lmicrohttpd)
endif(BUILD_HTTP)
if(BUILD_BUILTIN_CONFIG)
check_function_exists(fopencookie HAVE_FOPENCOOKIE)
check_function_exists(funopen HAVE_FUNOPEN)

View File

@ -18,6 +18,7 @@
#define MAX_USER_TEXT_DEFAULT @MAX_USER_TEXT_DEFAULT@
#define DEFAULT_TEXT_BUFFER_SIZE @DEFAULT_TEXT_BUFFER_SIZE@
#define MAX_NET_INTERFACES @MAX_NET_INTERFACES@
#define HTTPPORT @HTTPPORT@
#cmakedefine HAVE_SYS_STATFS_H 1
#cmakedefine HAVE_SYS_PARAM_H 1
@ -91,6 +92,8 @@
#cmakedefine BUILD_IRC 1
#cmakedefine BUILD_HTTP 1
#cmakedefine BUILD_ICONV 1
#cmakedefine BUILD_LUA_CAIRO 1

View File

@ -608,6 +608,15 @@
<listitem>Print text to stdout.
<para /></listitem>
</varlistentry>
<varlistentry>
<term>
<command>
<option>out_to_http</option>
</command>
</term>
<listitem>Let conky act as a small http-server serving it's text.
<para /></listitem>
</varlistentry>
<varlistentry>
<term>
<command>

View File

@ -5,7 +5,7 @@
syntax "conky" "(\.*conkyrc.*$|conky.conf)"
## Configuration items
color green "\<(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|lua_shutdown_hook|lua_startup_hook|mail_spool|max_port_monitor_connections|max_text_width|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|mysql_host|mysql_port|mysql_user|mysql_password|mysql_db|net_avg_samples|no_buffers|out_to_console|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|times_in_seconds|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>"
color green "\<(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|lua_shutdown_hook|lua_startup_hook|mail_spool|max_port_monitor_connections|max_text_width|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|mysql_host|mysql_port|mysql_user|mysql_password|mysql_db|net_avg_samples|no_buffers|out_to_console|out_to_http|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|times_in_seconds|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>"
## Configuration item constants
color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>"

View File

@ -12,7 +12,7 @@ endif
syn region ConkyrcComment start=/^\s*#/ end=/$/
syn keyword ConkyrcSetting alignment append_file background border_inner_margin border_outer_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades extra_newline font format_human_readable gap_x gap_y if_up_strictness imap imlib_cache_flush_interval imlib_cache_size lua_draw_hook_post lua_draw_hook_pre lua_load lua_shutdown_hook lua_startup_hook mail_spool max_port_monitor_connections max_text_width max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval mysql_host mysql_port mysql_user mysql_password mysql_db net_avg_samples no_buffers out_to_console out_to_ncurses out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size times_in_seconds top_cpu_separate top_name_width total_run_times update_interval update_interval_on_battery uppercase use_spacer use_xft xftalpha xftfont
syn keyword ConkyrcSetting alignment append_file background border_inner_margin border_outer_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades extra_newline font format_human_readable gap_x gap_y if_up_strictness imap imlib_cache_flush_interval imlib_cache_size lua_draw_hook_post lua_draw_hook_pre lua_load lua_shutdown_hook lua_startup_hook mail_spool max_port_monitor_connections max_text_width max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval mysql_host mysql_port mysql_user mysql_password mysql_db net_avg_samples no_buffers out_to_console out_to_http out_to_ncurses out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size times_in_seconds top_cpu_separate top_name_width total_run_times update_interval update_interval_on_battery uppercase use_spacer use_xft xftalpha xftfont
syn keyword ConkyrcConstant
\ above

View File

@ -111,6 +111,9 @@
#elif defined(__OpenBSD__)
#include "openbsd.h"
#endif
#ifdef BUILD_HTTP
#include <microhttpd.h>
#endif
#if defined(__FreeBSD_kernel__)
#include <bsd/bsd.h>
@ -228,6 +231,9 @@ static void print_version(void)
#ifdef BUILD_PORT_MONITORS
" * portmon\n"
#endif /* BUILD_PORT_MONITORS */
#ifdef BUILD_HTTP
" * HTTP\n"
#endif
#ifdef BUILD_IRC
" * IRC\n"
#endif
@ -358,6 +364,19 @@ static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
char *append_file = NULL; FILE *append_fpointer = NULL;
#ifdef BUILD_HTTP
std::string webpage;
struct MHD_Daemon *httpd;
int sendanswer(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) {
struct MHD_Response *response = MHD_create_response_from_data(webpage.length(), (void*) webpage.c_str(), MHD_NO, MHD_NO);
int ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
MHD_destroy_response(response);
if(cls || url || method || version || upload_data || upload_data_size || con_cls) {} //make compiler happy
return ret;
}
#endif
#ifdef BUILD_X11
static int show_graph_scale;
@ -1189,6 +1208,12 @@ static void draw_string(const char *s)
if ((output_methods & TO_NCURSES) && draw_mode == FG) {
printw("%s", s_with_newlines);
}
#endif
#ifdef BUILD_HTTP
if ((output_methods & TO_HTTP) && draw_mode == FG) {
webpage.append(s_with_newlines);
webpage.append("<br />");
}
#endif
free(s_with_newlines);
memset(tmpstring1, 0, text_buffer_size);
@ -1754,6 +1779,13 @@ static int draw_line(char *s, int special_index)
static void draw_text(void)
{
#ifdef BUILD_HTTP
#define WEBPAGE_START "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\" /><title>Conky</title></head><body><p>"
#define WEBPAGE_END "</p></body></html>"
if (output_methods & TO_HTTP) {
webpage = WEBPAGE_START;
}
#endif
#ifdef BUILD_X11
#ifdef BUILD_LUA
llua_draw_pre_hook();
@ -1792,6 +1824,11 @@ static void draw_text(void)
#if defined(BUILD_LUA) && defined(BUILD_X11)
llua_draw_post_hook();
#endif /* BUILD_LUA */
#ifdef BUILD_HTTP
if (output_methods & TO_HTTP) {
webpage.append(WEBPAGE_END);
}
#endif
}
static void draw_stuff(void)
@ -2437,6 +2474,11 @@ void clean_up_without_threads(void *memtofree1, void* memtofree2) {
if(output_methods & TO_NCURSES) {
endwin();
}
#endif
#ifdef BUILD_HTTP
if(output_methods & TO_HTTP) {
MHD_stop_daemon(httpd);
}
#endif
conftree_empty(currentconffile);
currentconffile = NULL;
@ -3255,6 +3297,14 @@ char load_config_file(const char *f)
if(string_to_bool(value))
output_methods |= TO_STDERR;
}
#ifdef BUILD_HTTP
CONF("out_to_http") {
if(string_to_bool(value)) {
output_methods |= TO_HTTP;
httpd = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, HTTPPORT, NULL, NULL, &sendanswer, NULL, MHD_OPTION_END);
}
}
#endif
#ifdef BUILD_NCURSES
CONF("out_to_ncurses") {
if(string_to_bool(value)) {

View File

@ -338,6 +338,9 @@ extern std::string current_config;
#ifdef BUILD_NCURSES
#define TO_NCURSES 32
#endif /* BUILD_NCURSES */
#ifdef BUILD_HTTP
#define TO_HTTP 64
#endif
enum x_initialiser_state {
NO = 0,
YES = 1,