diff -uNrp zabbix-1.8.19.bk/include/db.h zabbix-1.8.19/include/db.h
--- zabbix-1.8.19.bk/include/db.h	2013-12-09 18:22:14.000000000 +0900
+++ zabbix-1.8.19/include/db.h	2013-12-13 09:15:18.260750635 +0900
@@ -80,72 +80,73 @@ typedef enum {
 #define ZBX_DB_CONNECT_EXIT	1
 #define ZBX_DB_CONNECT_ONCE	2
 
+#define utf8_buf_size(a)		((a) * 4 + 1)
 /* Trigger related defines */
-#define TRIGGER_DESCRIPTION_LEN		1020
-#define TRIGGER_DESCRIPTION_LEN_MAX	TRIGGER_DESCRIPTION_LEN+1
+#define TRIGGER_DESCRIPTION_LEN		255
+#define TRIGGER_DESCRIPTION_LEN_MAX	utf8_buf_size(TRIGGER_DESCRIPTION_LEN)
 #define TRIGGER_EXPRESSION_LEN		255
-#define TRIGGER_EXPRESSION_LEN_MAX	TRIGGER_EXPRESSION_LEN+1
+#define TRIGGER_EXPRESSION_LEN_MAX	utf8_buf_size(TRIGGER_EXPRESSION_LEN)
 #define TRIGGER_ERROR_LEN		128
-#define TRIGGER_ERROR_LEN_MAX		TRIGGER_ERROR_LEN+1
+#define TRIGGER_ERROR_LEN_MAX		utf8_buf_size(TRIGGER_ERROR_LEN)
 
 #define HOST_HOST_LEN			MAX_ZBX_HOSTNAME_LEN
-#define HOST_HOST_LEN_MAX		HOST_HOST_LEN+1
+#define HOST_HOST_LEN_MAX		utf8_buf_size(HOST_HOST_LEN)
 #define HOST_DNS_LEN			64
-#define HOST_DNS_LEN_MAX		HOST_DNS_LEN+1
+#define HOST_DNS_LEN_MAX		utf8_buf_size(HOST_DNS_LEN)
 #define HOST_IP_LEN			39
-#define HOST_IP_LEN_MAX			HOST_IP_LEN+1
+#define HOST_IP_LEN_MAX			utf8_buf_size(HOST_IP_LEN)
 #define HOST_ADDR_LEN			64	/* MAX(HOST_DNS_LEN,HOST_IP_LEN) */
-#define HOST_ADDR_LEN_MAX		HOST_ADDR_LEN+1
+#define HOST_ADDR_LEN_MAX		utf8_buf_size(HOST_ADDR_LEN)
 #define HOST_ERROR_LEN			128
-#define HOST_ERROR_LEN_MAX		HOST_ERROR_LEN+1
+#define HOST_ERROR_LEN_MAX		utf8_buf_size(HOST_ERROR_LEN)
 #define HOST_IPMI_USERNAME_LEN		16
-#define HOST_IPMI_USERNAME_LEN_MAX	HOST_IPMI_USERNAME_LEN+1
+#define HOST_IPMI_USERNAME_LEN_MAX	utf8_buf_size(HOST_IPMI_USERNAME_LEN)
 #define HOST_IPMI_PASSWORD_LEN		20
-#define HOST_IPMI_PASSWORD_LEN_MAX	HOST_IPMI_PASSWORD_LEN+1
+#define HOST_IPMI_PASSWORD_LEN_MAX	utf8_buf_size(HOST_IPMI_PASSWORD_LEN)
 
-#define ITEM_KEY_LEN			1020
-#define ITEM_KEY_LEN_MAX		ITEM_KEY_LEN+1
+#define ITEM_KEY_LEN			255
+#define ITEM_KEY_LEN_MAX		utf8_buf_size(ITEM_KEY_LEN)
 #define ITEM_SNMP_COMMUNITY_LEN		64
-#define ITEM_SNMP_COMMUNITY_LEN_MAX	ITEM_SNMP_COMMUNITY_LEN+1
+#define ITEM_SNMP_COMMUNITY_LEN_MAX	utf8_buf_size(ITEM_SNMP_COMMUNITY_LEN)
 #define ITEM_SNMP_OID_LEN		255
-#define ITEM_SNMP_OID_LEN_MAX		ITEM_SNMP_OID_LEN+1
+#define ITEM_SNMP_OID_LEN_MAX		utf8_buf_size(ITEM_SNMP_OID_LEN)
 #define ITEM_LASTVALUE_LEN		255
-#define ITEM_LASTVALUE_LEN_MAX		ITEM_LASTVALUE_LEN+1
+#define ITEM_LASTVALUE_LEN_MAX		utf8_buf_size(ITEM_LASTVALUE_LEN)
 #define ITEM_ERROR_LEN			128
-#define ITEM_ERROR_LEN_MAX		ITEM_ERROR_LEN+1
+#define ITEM_ERROR_LEN_MAX		utf8_buf_size(ITEM_ERROR_LEN)
 #define ITEM_TRAPPER_HOSTS_LEN		255
-#define ITEM_TRAPPER_HOSTS_LEN_MAX	ITEM_TRAPPER_HOSTS_LEN+1
+#define ITEM_TRAPPER_HOSTS_LEN_MAX	utf8_buf_size(ITEM_TRAPPER_HOSTS_LEN)
 #define ITEM_UNITS_LEN			10
-#define ITEM_UNITS_LEN_MAX		ITEM_UNITS_LEN+1
+#define ITEM_UNITS_LEN_MAX		utf8_buf_size(ITEM_UNITS_LEN)
 #define ITEM_SNMPV3_SECURITYNAME_LEN		64
-#define ITEM_SNMPV3_SECURITYNAME_LEN_MAX	ITEM_SNMPV3_SECURITYNAME_LEN+1
+#define ITEM_SNMPV3_SECURITYNAME_LEN_MAX	utf8_buf_size(ITEM_SNMPV3_SECURITYNAME_LEN)
 #define ITEM_SNMPV3_AUTHPASSPHRASE_LEN		64
-#define ITEM_SNMPV3_AUTHPASSPHRASE_LEN_MAX	ITEM_SNMPV3_AUTHPASSPHRASE_LEN+1
+#define ITEM_SNMPV3_AUTHPASSPHRASE_LEN_MAX	utf8_buf_size(ITEM_SNMPV3_AUTHPASSPHRASE_LEN)
 #define ITEM_SNMPV3_PRIVPASSPHRASE_LEN		64
-#define ITEM_SNMPV3_PRIVPASSPHRASE_LEN_MAX	ITEM_SNMPV3_PRIVPASSPHRASE_LEN+1
+#define ITEM_SNMPV3_PRIVPASSPHRASE_LEN_MAX	utf8_buf_size(ITEM_SNMPV3_PRIVPASSPHRASE_LEN)
 #define ITEM_FORMULA_LEN		255
-#define ITEM_FORMULA_LEN_MAX		ITEM_FORMULA_LEN+1
+#define ITEM_FORMULA_LEN_MAX		utf8_buf_size(ITEM_FORMULA_LEN)
 #define ITEM_LOGTIMEFMT_LEN		64
-#define ITEM_LOGTIMEFMT_LEN_MAX		ITEM_LOGTIMEFMT_LEN+1
+#define ITEM_LOGTIMEFMT_LEN_MAX		utf8_buf_size(ITEM_LOGTIMEFMT_LEN)
 #define ITEM_DELAY_FLEX_LEN		255
-#define ITEM_DELAY_FLEX_LEN_MAX		ITEM_DELAY_FLEX_LEN+1
+#define ITEM_DELAY_FLEX_LEN_MAX		utf8_buf_size(ITEM_DELAY_FLEX_LEN)
 #define ITEM_IPMI_SENSOR_LEN		128
-#define ITEM_IPMI_SENSOR_LEN_MAX	ITEM_IPMI_SENSOR_LEN+1
+#define ITEM_IPMI_SENSOR_LEN_MAX	utf8_buf_size(ITEM_IPMI_SENSOR_LEN)
 #define ITEM_PARAMS_LEN			2048
 #define ITEM_PARAMS_LEN_MAX		ITEM_PARAMS_LEN+1
 #define ITEM_USERNAME_LEN		64
-#define ITEM_USERNAME_LEN_MAX		ITEM_USERNAME_LEN+1
+#define ITEM_USERNAME_LEN_MAX		utf8_buf_size(ITEM_USERNAME_LEN)
 #define ITEM_PASSWORD_LEN		64
-#define ITEM_PASSWORD_LEN_MAX		ITEM_PASSWORD_LEN+1
+#define ITEM_PASSWORD_LEN_MAX		utf8_buf_size(ITEM_PASSWORD_LEN)
 #define ITEM_PUBLICKEY_LEN		64
-#define ITEM_PUBLICKEY_LEN_MAX		ITEM_PUBLICKEY_LEN+1
+#define ITEM_PUBLICKEY_LEN_MAX		utf8_buf_size(ITEM_PUBLICKEY_LEN)
 #define ITEM_PRIVATEKEY_LEN		64
-#define ITEM_PRIVATEKEY_LEN_MAX		ITEM_PRIVATEKEY_LEN+1
+#define ITEM_PRIVATEKEY_LEN_MAX		utf8_buf_size(ITEM_PRIVATEKEY_LEN)
 
 #define FUNCTION_FUNCTION_LEN		12
-#define FUNCTION_FUNCTION_LEN_MAX	FUNCTION_FUNCTION_LEN+1
+#define FUNCTION_FUNCTION_LEN_MAX	utf8_buf_size(FUNCTION_FUNCTION_LEN)
 #define FUNCTION_PARAMETER_LEN		255
-#define FUNCTION_PARAMETER_LEN_MAX	FUNCTION_PARAMETER_LEN+1
+#define FUNCTION_PARAMETER_LEN_MAX	utf8_buf_size(FUNCTION_PARAMETER_LEN)
 
 #define HISTORY_STR_VALUE_LEN		255
 #ifdef HAVE_IBM_DB2
@@ -157,46 +158,46 @@ typedef enum {
 #endif
 
 #define HISTORY_LOG_SOURCE_LEN		64
-#define HISTORY_LOG_SOURCE_LEN_MAX	HISTORY_LOG_SOURCE_LEN+1
+#define HISTORY_LOG_SOURCE_LEN_MAX	utf8_buf_size(HISTORY_LOG_SOURCE_LEN)
 
 #define ALERT_SENDTO_LEN		100
-#define ALERT_SENDTO_LEN_MAX		ALERT_SENDTO_LEN+1
+#define ALERT_SENDTO_LEN_MAX		utf8_buf_size(ALERT_SENDTO_LEN)
 #define ALERT_SUBJECT_LEN		255
-#define ALERT_SUBJECT_LEN_MAX		ALERT_SUBJECT_LEN+1
+#define ALERT_SUBJECT_LEN_MAX		utf8_buf_size(ALERT_SUBJECT_LEN)
 #define ALERT_ERROR_LEN			128
-#define ALERT_ERROR_LEN_MAX		ALERT_ERROR_LEN+1
+#define ALERT_ERROR_LEN_MAX		utf8_buf_size(ALERT_ERROR_LEN)
 
 #define GRAPH_ITEM_COLOR_LEN		6
-#define GRAPH_ITEM_COLOR_LEN_MAX	GRAPH_ITEM_COLOR_LEN+1
+#define GRAPH_ITEM_COLOR_LEN_MAX	utf8_buf_size(GRAPH_ITEM_COLOR_LEN)
 
 #define DHOST_IP_LEN			39
-#define DHOST_IP_LEN_MAX		DHOST_IP_LEN+1
+#define DHOST_IP_LEN_MAX		utf8_buf_size(DHOST_IP_LEN)
 
 #define DSERVICE_KEY_LEN		255
-#define DSERVICE_KEY_LEN_MAX		DSERVICE_KEY_LEN+1
+#define DSERVICE_KEY_LEN_MAX		utf8_buf_size(DSERVICE_KEY_LEN)
 #define DSERVICE_VALUE_LEN		255
-#define DSERVICE_VALUE_LEN_MAX		DSERVICE_VALUE_LEN+1
+#define DSERVICE_VALUE_LEN_MAX		utf8_buf_size(DSERVICE_VALUE_LEN)
 
 #define HTTPTEST_HTTP_USER_LEN		64
-#define HTTPTEST_HTTP_USER_LEN_MAX	HTTPTEST_HTTP_USER_LEN+1
+#define HTTPTEST_HTTP_USER_LEN_MAX	utf8_buf_size(HTTPTEST_HTTP_USER_LEN)
 #define HTTPTEST_HTTP_PASSWORD_LEN	64
-#define HTTPTEST_HTTP_PASSWORD_LEN_MAX	HTTPTEST_HTTP_PASSWORD_LEN+1
+#define HTTPTEST_HTTP_PASSWORD_LEN_MAX	utf8_buf_size(HTTPTEST_HTTP_PASSWORD_LEN)
 
 #define PROXY_DHISTORY_IP_LEN		39
-#define PROXY_DHISTORY_IP_LEN_MAX	PROXY_DHISTORY_IP_LEN+1
+#define PROXY_DHISTORY_IP_LEN_MAX	utf8_buf_size(PROXY_DHISTORY_IP_LEN)
 #define PROXY_DHISTORY_KEY_LEN		255
-#define PROXY_DHISTORY_KEY_LEN_MAX	PROXY_DHISTORY_KEY_LEN+1
+#define PROXY_DHISTORY_KEY_LEN_MAX	utf8_buf_size(PROXY_DHISTORY_KEY_LEN)
 #define PROXY_DHISTORY_VALUE_LEN	255
-#define PROXY_DHISTORY_VALUE_LEN_MAX	PROXY_DHISTORY_VALUE_LEN+1
+#define PROXY_DHISTORY_VALUE_LEN_MAX	utf8_buf_size(PROXY_DHISTORY_VALUE_LEN)
 
 #define HTTPTEST_ERROR_LEN		255
-#define HTTPTEST_ERROR_LEN_MAX		HTTPTEST_ERROR_LEN+1
+#define HTTPTEST_ERROR_LEN_MAX		utf8_buf_size(HTTPTEST_ERROR_LEN)
 
 #define HTTPSTEP_STATUS_LEN		255
-#define HTTPSTEP_STATUS_LEN_MAX		HTTPSTEP_STATUS_LEN+1
+#define HTTPSTEP_STATUS_LEN_MAX		utf8_buf_size(HTTPSTEP_STATUS_LEN)
 
 #define HTTPSTEP_REQUIRED_LEN		255
-#define HTTPSTEP_REQUIRED_LEN_MAX	HTTPSTEP_REQUIRED_LEN+1
+#define HTTPSTEP_REQUIRED_LEN_MAX	utf8_buf_size(HTTPSTEP_REQUIRED_LEN)
 
 #define ZBX_SQL_ITEM_FIELDS	"i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.type,h.useip,"	\
 				"h.ip,i.history,i.lastvalue,i.prevvalue,i.hostid,i.value_type,i.delta,"	\
