[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: classic ui: add configurable http charset support (default utf-8) within the cgis #1002

git at icinga.org git at icinga.org
Wed Jan 5 15:18:30 CET 2011


Module: icinga-core
Branch: mfriedrich/core
Commit: 82c07167e482d0936f18f2763a342b78af0b618e
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=82c07167e482d0936f18f2763a342b78af0b618e

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed Jan  5 15:17:06 2011 +0100

classic ui: add configurable http charset support (default utf-8) within the cgis #1002

partly reworked into current Icinga CGIs (Ricardo rewrote
header parts into cgiutils.c only), thanks to PLD Linux
repositories for their path.

fixes #1002

---

 Changelog                |    1 +
 cgi/cgiutils.c           |   20 ++++++++++++++++----
 include/cgiutils.h       |    5 +++++
 sample-config/cgi.cfg.in |    7 +++++++
 4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/Changelog b/Changelog
index f35d04a..3d1dfc9 100644
--- a/Changelog
+++ b/Changelog
@@ -19,6 +19,7 @@ ENHANCEMENTS
 * classic ui: change color of unknown/unreachable state to more warm signalling purple #1029
 * classic ui: move "add service/host comment" to the command box on extinfo.cgi, abandon remove all in favor of multiple comment delete #837
 * classic ui: add trend timeperiod feature to locate the next problem (Carsten Emde) #1074
+* classic ui: add configurable http charset support (default utf-8) within the cgis #1002
 
 * core: add support for same host service dependencies with servicegroups (Mathieu Gagné) #928
 * core: allow eventbroker modules to override sending notifications (Matthieu Kermagoret) #1057
diff --git a/cgi/cgiutils.c b/cgi/cgiutils.c
index 7c4427b..bc01bc5 100644
--- a/cgi/cgiutils.c
+++ b/cgi/cgiutils.c
@@ -57,6 +57,8 @@ char            *statuswrl_include=NULL;
 
 char            *illegal_output_chars=NULL;
 
+char            *http_charset=NULL;
+
 char            *notes_url_target=NULL;
 char            *action_url_target=NULL;
 
@@ -241,6 +243,9 @@ void reset_cgi_vars(void){
 	host_unreachable_sound=NULL;
 	normal_sound=NULL;
 
+	my_free(http_charset);
+	http_charset = strdup(DEFAULT_HTTP_CHARSET);
+
 	statusmap_background_image=NULL;
 	color_transparency_index_r=255;
 	color_transparency_index_g=255;
@@ -480,6 +485,9 @@ int read_cgi_config_file(char *filename){
 		else if(!strcmp(var,"illegal_macro_output_chars"))
 			illegal_output_chars=strdup(val);
 
+		else if(!strcmp(var,"http_charset"))
+			http_charset=strdup(val);
+
 		else if(!strcmp(var,"notes_url_target"))
 			notes_url_target=strdup(val);
 
@@ -903,7 +911,7 @@ void document_header(int cgi_id, int use_stylesheet){
 
 	if(content_type==WML_CONTENT){
                 /* used by cmd.cgi */
-		printf("Content-type: text/vnd.wap.wml\r\n\r\n");
+		printf("Content-type: text/vnd.wap.wml; charset=\"%s\"\r\n\r\n", http_charset);
 
 		printf("<?xml version=\"1.0\"?>\n");
 		printf("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
@@ -934,7 +942,7 @@ void document_header(int cgi_id, int use_stylesheet){
 	}
 	if(cgi_id==STATUSWML_CGI_ID) {
 
-		printf("Content-type: text/vnd.wap.wml\r\n\r\n");
+		printf("Content-type: text/vnd.wap.wml; charset=\"%s\"\r\n\r\n", http_charset);
 
 		printf("<?xml version=\"1.0\"?>\n");
 		printf("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
@@ -953,12 +961,12 @@ void document_header(int cgi_id, int use_stylesheet){
 	}
 
 	if(content_type==CSV_CONTENT) {
-		printf("Content-type: text/plain\r\n\r\n");
+		printf("Content-type: text/plain; charset=\"%s\"\r\n\r\n", http_charset);
 		return;
 	}
 
 	// send HTML CONTENT
-	printf("Content-type: text/html\r\n\r\n");
+	printf("Content-type: text/html; charset=\"%s\"\r\n\r\n", http_charset);
 
 	if(embedded==TRUE)
 		return;
@@ -1590,6 +1598,10 @@ char * html_encode(char *input, int escape_newlines){
 				}
 		        }
 
+		/* high bit chars don't get encoded, so we won't be breaking utf8 characters */
+		else if ((unsigned char)input[x] >= 0x7f)
+			encoded_html_string[y++]=input[x];
+
 		/* for simplicity, all other chars represented by their numeric value */
 		else{
 			if(escape_html_tags==FALSE)
diff --git a/include/cgiutils.h b/include/cgiutils.h
index 6df00d1..6d6cce9 100644
--- a/include/cgiutils.h
+++ b/include/cgiutils.h
@@ -467,6 +467,11 @@ extern "C" {
 #define LIFO_ERROR_DATA		3
 
 
+/************************** HTTP CHARSET ****************************/
+
+#define DEFAULT_HTTP_CHARSET "utf-8"
+
+
 /************************** BUFFER  ***************************************/
 
 #define MAX_MESSAGE_BUFFER              4096
diff --git a/sample-config/cgi.cfg.in b/sample-config/cgi.cfg.in
index edd24b5..0a0eb36 100644
--- a/sample-config/cgi.cfg.in
+++ b/sample-config/cgi.cfg.in
@@ -51,6 +51,13 @@ url_stylesheets_path=@htmurl@/stylesheets
 
 
 
+# HTTP CHARSET
+# This defines charset that is sent with HTTP headers.
+
+http_charset=utf-8
+
+
+
 # CONTEXT-SENSITIVE HELP
 # This option determines whether or not a context-sensitive
 # help icon will be displayed for most of the CGIs.





More information about the icinga-checkins mailing list