Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Grigorjev <git-no-reply@zabbix.com>2006-07-12 13:14:46 +0400
committerEugene Grigorjev <git-no-reply@zabbix.com>2006-07-12 13:14:46 +0400
commit3c44ccda3b18ac5ed983c2bf163439bb70f5c1e5 (patch)
treed62c05933f09bebc50d4c9c9dfa61f657ab03e54 /include
parent525dcd4757f8356cfad70e233cbc6e0dd29bc34e (diff)
zabbix-1.2_dev integration
Diffstat (limited to 'include')
-rwxr-xr-xinclude/alias.h40
-rw-r--r--include/base64.h26
-rw-r--r--include/cfg.h15
-rw-r--r--include/common.h184
-rwxr-xr-xinclude/daemon.h49
-rwxr-xr-xinclude/gnuregex.h501
-rw-r--r--include/log.h7
-rwxr-xr-xinclude/mutexs.h44
-rwxr-xr-xinclude/perfmon.h58
-rw-r--r--include/pid.h7
-rwxr-xr-xinclude/service.h55
-rw-r--r--include/sysinc.h64
-rw-r--r--include/sysinfo.h8
-rwxr-xr-xinclude/threads.h68
-rwxr-xr-xinclude/zbxgetopt.h102
-rwxr-xr-xinclude/zbxplugin.h61
-rwxr-xr-xinclude/zbxsecurity.h27
-rwxr-xr-xinclude/zbxsock.h72
-rwxr-xr-xinclude/zbxtypes.h57
19 files changed, 1319 insertions, 126 deletions
diff --git a/include/alias.h b/include/alias.h
new file mode 100755
index 00000000000..d3b91214ba0
--- /dev/null
+++ b/include/alias.h
@@ -0,0 +1,40 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ALIAS_H
+#define ZABBIX_ALIAS_H
+
+#define MAX_ALIAS_NAME 120
+
+struct zbx_alias
+{
+ struct zbx_alias *next;
+ char name[MAX_ALIAS_NAME];
+ char *value;
+};
+
+typedef struct zbx_alias ALIAS;
+
+int add_alias(const char *name, const char *value);
+int add_alias_from_config(char *value);
+void alias_list_free(void);
+void alias_expand(const char *orig, char *expanded, int exp_buf_len);
+
+
+#endif /* ZABBIX_ALIAS_H */
diff --git a/include/base64.h b/include/base64.h
new file mode 100644
index 00000000000..b7e43d244dc
--- /dev/null
+++ b/include/base64.h
@@ -0,0 +1,26 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_BASE64_H
+#define ZABBIX_BASE64_H
+
+void str_base64_encode(char *p_str, char *p_b64str, int in_size);
+void str_base64_decode(char *p_b64str, char *p_str, int *p_out_size);
+
+#endif /* ZABBIX_BASE64_H */
diff --git a/include/cfg.h b/include/cfg.h
index f46682cb38f..3b4635da3df 100644
--- a/include/cfg.h
+++ b/include/cfg.h
@@ -26,6 +26,21 @@
#define PARM_OPT 0
#define PARM_MAND 1
+//
+// Application flags
+//
+
+#define AF_STANDALONE 0x0001
+#define AF_USE_EVENT_LOG 0x0002
+#define AF_LOG_UNRESOLVED_SYMBOLS 0x0004
+
+extern int CONFIG_ZABBIX_FORKS;
+extern char *CONFIG_FILE;
+
+extern char *CONFIG_LOG_FILE;
+extern char CONFIG_ALLOW_ROOT_PERMISSION;
+extern int CONFIG_TIMEOUT;
+
struct cfg_line
{
char *parameter;
diff --git a/include/common.h b/include/common.h
index 8208b756e1c..4ecaaf1f369 100644
--- a/include/common.h
+++ b/include/common.h
@@ -22,87 +22,14 @@
#include "sysinc.h"
+#include "zbxtypes.h"
+
#if defined(WIN32)
+
# pragma warning (disable: 4100)
-# define zbx_uint64_t __int64
-# define ZBX_FS_UI64 "%llu"
-
-//#undef _DEBUG
-# ifdef _DEBUG
-# define LOG_DEBUG_INFO(type, msg) \
- WriteLog(MSG_DEBUG_INFO,EVENTLOG_ERROR_TYPE, "d"type , GetCurrentThreadId(), msg)
-//# define ENABLE_CHECK_MEMOTY
-//# define ENABLE_FUNC_CALL
-# else
-# define LOG_DEBUG_INFO(a, b) ((void)0)
-# endif
-
-
-# if defined(ENABLE_FUNC_CALL)
-# define LOG_FUNC_CALL(msg) \
- WriteLog(MSG_DEBUG_INFO,EVENTLOG_ERROR_TYPE, "ds" , GetCurrentThreadId(), msg)
-# else
-# define LOG_FUNC_CALL(a) ((void)0)
-# endif
-
-# if defined(ENABLE_CHECK_MEMOTY)
-# include "crtdbg.h"
-
-# define REINIT_CHECK_MEMORY(a) \
- _CrtMemCheckpoint(& ## a ## oldMemState)
-
-# define INIT_CHECK_MEMORY(a) \
- char a ## DumpMessage[0xFFFF]; \
- _CrtMemState a ## oldMemState, a ## newMemState, a ## diffMemState; \
- REINIT_CHECK_MEMORY(a)
-
-# define CHECK_MEMORY(a, fncname, msg) \
- _CrtMemCheckpoint(& ## a ## newMemState); \
- if(_CrtMemDifference(& ## a ## diffMemState, & ## a ## oldMemState, & ## a ## newMemState)) \
- { \
- sprintf(a ## DumpMessage, \
- "%s\n" \
- "free: %10li bytes in %10li blocks\n" \
- "normal:%10li bytes in %10li blocks\n" \
- "CRT: %10li bytes in %10li blocks\n" \
- "ignore:%10li bytes in %10li blocks\n" \
- "client:%10li bytes in %10li blocks\n" \
- "max: %10li bytes in %10li blocks", \
- \
- fncname ": (" #a ") Memory changed! (" msg ")\n", \
- \
- (long) a ## diffMemState.lSizes[_FREE_BLOCK], \
- (long) a ## diffMemState.lCounts[_FREE_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_NORMAL_BLOCK], \
- (long) a ## diffMemState.lCounts[_NORMAL_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_CRT_BLOCK], \
- (long) a ## diffMemState.lCounts[_CRT_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_IGNORE_BLOCK], \
- (long) a ## diffMemState.lCounts[_IGNORE_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_CLIENT_BLOCK], \
- (long) a ## diffMemState.lCounts[_CLIENT_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_MAX_BLOCKS], \
- (long) a ## diffMemState.lCounts[_MAX_BLOCKS]); \
- LOG_DEBUG_INFO("s", a ## DumpMessage); \
- }
-# else
-# define INIT_CHECK_MEMORY(a) ((void)0)
-# define CHECK_MEMORY(a, fncname, msg) ((void)0)
-# endif
-#else
-# define zbx_uint64_t uint64_t
-# if __WORDSIZE == 64
-# define ZBX_FS_UI64 "%lu"
-# else
-# define ZBX_FS_UI64 "%llu"
-# endif
-#endif
+#endif /* WIN32 */
+
#ifndef HAVE_GETOPT_LONG
struct option {
@@ -112,14 +39,14 @@
int val;
};
# define getopt_long(argc, argv, optstring, longopts, longindex) getopt(argc, argv, optstring)
-#endif
+#endif /* ndef HAVE_GETOPT_LONG */
#define ZBX_UNUSED(a) ((void)0)(a)
#define ZBX_FS_DBL "%f"
-#define ZABBIX_REVDATE "1 July 2006"
-#define ZABBIX_VERSION "1.1.1"
+#define ZABBIX_REVDATE "12 July 2006"
+#define ZABBIX_VERSION "1.2.1"
#define MAX_LOG_FILE_LEN (1024*1024)
@@ -130,14 +57,6 @@
#define TIMEOUT_ERROR (-4)
#define AGENT_ERROR (-5)
-#define MAXFD 64
-
-/* show debug info to stderr */
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m)
-#define SDI(m) FDI("%s", m)
-#define IDI(i) FDI("%i", i)
-
-
/*
#define ZBX_POLLER
*/
@@ -277,7 +196,7 @@
#define SERVICE_ALGORITHM_MAX 1
#define SERVICE_ALGORITHM_MIN 2
-#define AGENTD_FORKS 5
+#define ZABBIX_FORKS 5
#define TRAPPERD_FORKS 5
#define POLLER_FORKS 11
@@ -304,7 +223,11 @@
#endif
/* Secure string copy */
-#define strscpy(x,y) { strncpy(x,y,sizeof(x)); x[sizeof(x)-1]=0; }
+#define strsncpy(x,y,size) { strncpy(x,y,size); x[size-1]='\0'; }
+#define strscpy(x,y) strsncpy(x,y,sizeof(x))
+
+#define zbx_free(ptr) { if(ptr){ free(ptr); ptr = NULL; } }
+#define zbx_fclose(f) { if(f){ fclose(f); f = NULL; } }
/* list structure as item of agent return vaile */
#define ZBX_LIST_ITEM struct zbx_list_item_s
@@ -339,6 +262,8 @@ AGENT_RESULT {
#define AR_TEXT 32
+/* SET RESULT */
+
#define SET_DBL_RESULT(res, val) \
{ \
(res)->type |= AR_DOUBLE; \
@@ -369,31 +294,48 @@ AGENT_RESULT {
(res)->msg = (char*)(val); \
}
-#define UNSET_DBL_RESULT(res) \
- { \
- (res)->type &= ~AR_DOUBLE; \
+/* UNSER RESULT */
+
+#define UNSET_DBL_RESULT(res) \
+ { \
+ (res)->type &= ~AR_DOUBLE; \
+ (res)->dbl = (double)(0); \
}
-#define UNSET_UI64_RESULT(res) \
- { \
- (res)->type &= ~AR_UINT64; \
+#define UNSET_UI64_RESULT(res) \
+ { \
+ (res)->type &= ~AR_UINT64; \
+ (res)->ui64 = (zbx_uint64_t)(0); \
}
-#define UNSET_STR_RESULT(res) \
- { \
- (res)->type &= ~AR_STRING; \
+#define UNSET_STR_RESULT(res) \
+ { \
+ if((res)->type & AR_STRING){ \
+ free((res)->str); \
+ (res)->str = NULL; \
+ (res)->type &= ~AR_STRING; \
+ } \
}
-#define UNSET_TEXT_RESULT(res) \
- { \
- (res)->type &= ~AR_TEXT; \
+#define UNSET_TEXT_RESULT(res) \
+ { \
+ if((res)->type & AR_TEXT){ \
+ free((res)->text); \
+ (res)->text = NULL; \
+ (res)->type &= ~AR_TEXT; \
+ } \
}
-#define UNSET_MSG_RESULT(res) \
- { \
- (res)->type &= ~AR_MESSAGE; \
+#define UNSET_MSG_RESULT(res) \
+ { \
+ if((res)->type & AR_MESSAGE){ \
+ free((res)->msg); \
+ (res)->msg = NULL; \
+ (res)->type &= ~AR_MESSAGE; \
+ } \
}
+
extern char *progname;
extern char title_message[];
extern char usage_message[];
@@ -403,16 +345,20 @@ void help();
void usage();
void version();
-#define ZBX_TASK_START 0
-#define ZBX_TASK_SHOW_HELP 1
-#define ZBX_TASK_SHOW_VERSION 2
-#define ZBX_TASK_PRINT_SUPPORTED 3
-#define ZBX_TASK_TEST_METRIC 4
-#define ZBX_TASK_SHOW_USAGE 5
-
/* MAX Length of base64 data */
#define ZBX_MAX_B64_LEN 16*1024
+#define ZBX_TASK_START 0
+#define ZBX_TASK_SHOW_HELP 1
+#define ZBX_TASK_SHOW_VERSION 2
+#define ZBX_TASK_PRINT_SUPPORTED 3
+#define ZBX_TASK_TEST_METRIC 4
+#define ZBX_TASK_SHOW_USAGE 5
+#define ZBX_TASK_INSTALL_SERVICE 6
+#define ZBX_TASK_UNINSTALL_SERVICE 7
+#define ZBX_TASK_START_SERVICE 8
+#define ZBX_TASK_STOP_SERVICE 9
+
void init_result(AGENT_RESULT *result);
int copy_result(AGENT_RESULT *src, AGENT_RESULT *dist);
void free_result(AGENT_RESULT *result);
@@ -430,6 +376,10 @@ void delete_reol(char *c);
int get_param(const char *param, int num, char *buf, int maxlen);
int num_param(const char *param);
int calculate_item_nextcheck(int delay, int now);
+void zbx_setproctitle(const char *fmt, ...);
+double zbx_getseconds(void);
+void zbx_error(const char *fmt, ...);
+void zbx_snprintf(char* str, size_t count, const char *fmt, ...);
int set_result_type(AGENT_RESULT *result, int value_type, char *c);
@@ -442,16 +392,16 @@ int comms_parse_response(char *xml,char *host,char *key, char *data, char *lastl
int parse_command(const char *command, char *cmd, int cmd_max_len, char *param, int param_max_len);
-/* Base64 functions */
-void str_base64_encode(char *p_str, char *p_b64str, int in_size);
-void str_base64_decode(char *p_b64str, char *p_str, int *p_out_size);
-
/* Regular expressions */
char *zbx_regexp_match(const char *string, const char *pattern, int *len);
/* Misc functions */
int cmp_double(double a,double b);
+void zbx_on_exit();
+
int SYSTEM_LOCALTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
+int MAIN_ZABBIX_ENTRY(void);
+
#endif
diff --git a/include/daemon.h b/include/daemon.h
new file mode 100755
index 00000000000..ed961c6669a
--- /dev/null
+++ b/include/daemon.h
@@ -0,0 +1,49 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+
+#ifndef ZABBIX_DAEMON_H
+#define ZABBIX_DAEMON_H
+
+#if defined(WIN32)
+# error "This module allowed only for Linux OS"
+#endif
+
+#define USE_PID_FILE (1)
+
+extern char *APP_PID_FILE;
+
+#include "threads.h"
+
+#define MAXFD 64
+
+void child_signal_handler(int sig);
+
+int daemon_start(int allow_root);
+void daemon_stop(void);
+
+void init_main_process(void);
+
+/* ask for application closing status - NOT needed for linux forks */
+#define ZBX_IS_RUNNING (1)
+
+/* tall all threads what application must be closed - NOT needed for linux forks */
+#define ZBX_DO_EXIT()
+
+#endif /* ZABBIX_DAEMON_H */
diff --git a/include/gnuregex.h b/include/gnuregex.h
new file mode 100755
index 00000000000..0e5709353f2
--- /dev/null
+++ b/include/gnuregex.h
@@ -0,0 +1,501 @@
+/* Definitions for data structures and routines for the regular
+ expression library, version 0.12.
+
+ Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#ifndef __REGEXP_LIBRARY_H__
+#define __REGEXP_LIBRARY_H__
+
+/* Allow the use in C++ code. */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* POSIX says that <sys/types.h> must be included (by the caller) before
+ <regex.h>. */
+
+#ifdef VMS
+/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
+ should be there. */
+#include <stddef.h>
+#endif
+
+
+/* The following bits are used to determine the regexp syntax we
+ recognize. The set/not-set meanings are chosen so that Emacs syntax
+ remains the value 0. The bits are given in alphabetical order, and
+ the definitions shifted by one from the previous bit; thus, when we
+ add or remove a bit, only one other definition need change. */
+typedef unsigned reg_syntax_t;
+
+/* If this bit is not set, then \ inside a bracket expression is literal.
+ If set, then such a \ quotes the following character. */
+#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
+
+/* If this bit is not set, then + and ? are operators, and \+ and \? are
+ literals.
+ If set, then \+ and \? are operators and + and ? are literals. */
+#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
+
+/* If this bit is set, then character classes are supported. They are:
+ [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
+ [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
+ If not set, then character classes are not supported. */
+#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
+
+/* If this bit is set, then ^ and $ are always anchors (outside bracket
+ expressions, of course).
+ If this bit is not set, then it depends:
+ ^ is an anchor if it is at the beginning of a regular
+ expression or after an open-group or an alternation operator;
+ $ is an anchor if it is at the end of a regular expression, or
+ before a close-group or an alternation operator.
+
+ This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
+ POSIX draft 11.2 says that * etc. in leading positions is undefined.
+ We already implemented a previous draft which made those constructs
+ invalid, though, so we haven't changed the code back. */
+#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
+
+/* If this bit is set, then special characters are always special
+ regardless of where they are in the pattern.
+ If this bit is not set, then special characters are special only in
+ some contexts; otherwise they are ordinary. Specifically,
+ * + ? and intervals are only special when not after the beginning,
+ open-group, or alternation operator. */
+#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
+
+/* If this bit is set, then *, +, ?, and { cannot be first in an re or
+ immediately after an alternation or begin-group operator. */
+#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
+
+/* If this bit is set, then . matches newline.
+ If not set, then it doesn't. */
+#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
+
+/* If this bit is set, then . doesn't match NUL.
+ If not set, then it does. */
+#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
+
+/* If this bit is set, nonmatching lists [^...] do not match newline.
+ If not set, they do. */
+#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
+
+/* If this bit is set, either \{...\} or {...} defines an
+ interval, depending on RE_NO_BK_BRACES.
+ If not set, \{, \}, {, and } are literals. */
+#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
+
+/* If this bit is set, +, ? and | aren't recognized as operators.
+ If not set, they are. */
+#define RE_LIMITED_OPS (RE_INTERVALS << 1)
+
+/* If this bit is set, newline is an alternation operator.
+ If not set, newline is literal. */
+#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
+
+/* If this bit is set, then `{...}' defines an interval, and \{ and \}
+ are literals.
+ If not set, then `\{...\}' defines an interval. */
+#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
+
+/* If this bit is set, (...) defines a group, and \( and \) are literals.
+ If not set, \(...\) defines a group, and ( and ) are literals. */
+#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
+
+/* If this bit is set, then \<digit> matches <digit>.
+ If not set, then \<digit> is a back-reference. */
+#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
+
+/* If this bit is set, then | is an alternation operator, and \| is literal.
+ If not set, then \| is an alternation operator, and | is literal. */
+#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
+
+/* If this bit is set, then an ending range point collating higher
+ than the starting range point, as in [z-a], is invalid.
+ If not set, then when ending range point collates higher than the
+ starting range point, the range is ignored. */
+#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
+
+/* If this bit is set, then an unmatched ) is ordinary.
+ If not set, then an unmatched ) is invalid. */
+#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
+
+/* This global variable defines the particular regexp syntax to use (for
+ some interfaces). When a regexp is compiled, the syntax used is
+ stored in the pattern buffer, so changing this does not affect
+ already-compiled regexps. */
+extern reg_syntax_t re_syntax_options;
+
+/* Define combinations of the above bits for the standard possibilities.
+ (The [[[ comments delimit what gets put into the Texinfo file, so
+ don't delete them!) */
+/* [[[begin syntaxes]]] */
+#define RE_SYNTAX_EMACS 0
+
+#define RE_SYNTAX_AWK \
+ (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
+ | RE_UNMATCHED_RIGHT_PAREN_ORD)
+
+#define RE_SYNTAX_POSIX_AWK \
+ (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
+
+#define RE_SYNTAX_GREP \
+ (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
+ | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
+ | RE_NEWLINE_ALT)
+
+#define RE_SYNTAX_EGREP \
+ (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
+ | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
+ | RE_NO_BK_VBAR)
+
+#define RE_SYNTAX_POSIX_EGREP \
+ (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
+
+/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
+#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
+
+#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
+
+/* Syntax bits common to both basic and extended POSIX regex syntax. */
+#define _RE_SYNTAX_POSIX_COMMON \
+ (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
+ | RE_INTERVALS | RE_NO_EMPTY_RANGES)
+
+#define RE_SYNTAX_POSIX_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
+
+/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
+ RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
+ isn't minimal, since other operators, such as \`, aren't disabled. */
+#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
+
+#define RE_SYNTAX_POSIX_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
+ | RE_UNMATCHED_RIGHT_PAREN_ORD)
+
+/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
+ replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
+#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
+/* [[[end syntaxes]]] */
+
+/* Maximum number of duplicates an interval can allow. Some systems
+ (erroneously) define this in other header files, but we want our
+ value, so remove any previous define. */
+#ifdef RE_DUP_MAX
+#undef RE_DUP_MAX
+#endif
+#ifndef RE_DUP_MAX
+# define RE_DUP_MAX ((1 << 15) - 1)
+#endif
+
+
+/* POSIX `cflags' bits (i.e., information for `regcomp'). */
+
+/* If this bit is set, then use extended regular expression syntax.
+ If not set, then use basic regular expression syntax. */
+#define REG_EXTENDED 1
+
+/* If this bit is set, then ignore case when matching.
+ If not set, then case is significant. */
+#define REG_ICASE (REG_EXTENDED << 1)
+
+/* If this bit is set, then anchors do not match at newline
+ characters in the string.
+ If not set, then anchors do match at newlines. */
+#define REG_NEWLINE (REG_ICASE << 1)
+
+/* If this bit is set, then report only success or fail in regexec.
+ If not set, then returns differ between not matching and errors. */
+#define REG_NOSUB (REG_NEWLINE << 1)
+
+
+/* POSIX `eflags' bits (i.e., information for regexec). */
+
+/* If this bit is set, then the beginning-of-line operator doesn't match
+ the beginning of the string (presumably because it's not the
+ beginning of a line).
+ If not set, then the beginning-of-line operator does match the
+ beginning of the string. */
+#define REG_NOTBOL 1
+
+/* Like REG_NOTBOL, except for the end-of-line. */
+#define REG_NOTEOL (1 << 1)
+
+
+/* If any error codes are removed, changed, or added, update the
+ `re_error_msg' table in regex.c. */
+typedef enum
+{
+ REG_NOERROR = 0, /* Success. */
+ REG_NOMATCH, /* Didn't find a match (for regexec). */
+
+ /* POSIX regcomp return error codes. (In the order listed in the
+ standard.) */
+ REG_BADPAT, /* Invalid pattern. */
+ REG_ECOLLATE, /* Not implemented. */
+ REG_ECTYPE, /* Invalid character class name. */
+ REG_EESCAPE, /* Trailing backslash. */
+ REG_ESUBREG, /* Invalid back reference. */
+ REG_EBRACK, /* Unmatched left bracket. */
+ REG_EPAREN, /* Parenthesis imbalance. */
+ REG_EBRACE, /* Unmatched \{. */
+ REG_BADBR, /* Invalid contents of \{\}. */
+ REG_ERANGE, /* Invalid range end. */
+ REG_ESPACE, /* Ran out of memory. */
+ REG_BADRPT, /* No preceding re for repetition op. */
+
+ /* Error codes we've added. */
+ REG_EEND, /* Premature end. */
+ REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
+ REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
+} reg_errcode_t;
+
+/* This data structure represents a compiled pattern. Before calling
+ the pattern compiler, the fields `buffer', `allocated', `fastmap',
+ `translate', and `no_sub' can be set. After the pattern has been
+ compiled, the `re_nsub' field is available. All other fields are
+ private to the regex routines. */
+
+struct re_pattern_buffer
+{
+/* [[[begin pattern_buffer]]] */
+ /* Space that holds the compiled pattern. It is declared as
+ `unsigned char *' because its elements are
+ sometimes used as array indexes. */
+ unsigned char *buffer;
+
+ /* Number of bytes to which `buffer' points. */
+ unsigned long allocated;
+
+ /* Number of bytes actually used in `buffer'. */
+ unsigned long used;
+
+ /* Syntax setting with which the pattern was compiled. */
+ reg_syntax_t syntax;
+
+ /* Pointer to a fastmap, if any, otherwise zero. re_search uses
+ the fastmap, if there is one, to skip over impossible
+ starting points for matches. */
+ char *fastmap;
+
+ /* Either a translate table to apply to all characters before
+ comparing them, or zero for no translation. The translation
+ is applied to a pattern when it is compiled and to a string
+ when it is matched. */
+ char *translate;
+
+ /* Number of subexpressions found by the compiler. */
+ size_t re_nsub;
+
+ /* Zero if this pattern cannot match the empty string, one else.
+ Well, in truth it's used only in `re_search_2', to see
+ whether or not we should use the fastmap, so we don't set
+ this absolutely perfectly; see `re_compile_fastmap' (the
+ `duplicate' case). */
+ unsigned can_be_null : 1;
+
+ /* If REGS_UNALLOCATED, allocate space in the `regs' structure
+ for `max (RE_NREGS, re_nsub + 1)' groups.
+ If REGS_REALLOCATE, reallocate space if necessary.
+ If REGS_FIXED, use what's there. */
+#define REGS_UNALLOCATED 0
+#define REGS_REALLOCATE 1
+#define REGS_FIXED 2
+ unsigned regs_allocated : 2;
+
+ /* Set to zero when `regex_compile' compiles a pattern; set to one
+ by `re_compile_fastmap' if it updates the fastmap. */
+ unsigned fastmap_accurate : 1;
+
+ /* If set, `re_match_2' does not return information about
+ subexpressions. */
+ unsigned no_sub : 1;
+
+ /* If set, a beginning-of-line anchor doesn't match at the
+ beginning of the string. */
+ unsigned not_bol : 1;
+
+ /* Similarly for an end-of-line anchor. */
+ unsigned not_eol : 1;
+
+ /* If true, an anchor at a newline matches. */
+ unsigned newline_anchor : 1;
+
+/* [[[end pattern_buffer]]] */
+};
+
+typedef struct re_pattern_buffer regex_t;
+
+
+/* search.c (search_buffer) in Emacs needs this one opcode value. It is
+ defined both in `regex.c' and here. */
+#define RE_EXACTN_VALUE 1
+
+/* Type for byte offsets within the string. POSIX mandates this. */
+typedef int regoff_t;
+
+
+/* This is the structure we store register match data in. See
+ regex.texinfo for a full description of what registers match. */
+struct re_registers
+{
+ unsigned num_regs;
+ regoff_t *start;
+ regoff_t *end;
+};
+
+
+/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
+ `re_match_2' returns information about at least this many registers
+ the first time a `regs' structure is passed. */
+#ifndef RE_NREGS
+#define RE_NREGS 30
+#endif
+
+
+/* POSIX specification for registers. Aside from the different names than
+ `re_registers', POSIX uses an array of structures, instead of a
+ structure of arrays. */
+typedef struct
+{
+ regoff_t rm_so; /* Byte offset from string's start to substring's start. */
+ regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
+} regmatch_t;
+
+/* Declarations for routines. */
+
+/* To avoid duplicating every routine declaration -- once with a
+ prototype (if we are ANSI), and once without (if we aren't) -- we
+ use the following macro to declare argument types. This
+ unfortunately clutters up the declarations a bit, but I think it's
+ worth it. */
+
+#if __STDC__
+
+#define _RE_ARGS(args) args
+
+#else /* not __STDC__ */
+
+#define _RE_ARGS(args) ()
+
+#endif /* not __STDC__ */
+
+/* Sets the current default syntax to SYNTAX, and return the old syntax.
+ You can also simply assign to the `re_syntax_options' variable. */
+extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
+
+/* Compile the regular expression PATTERN, with length LENGTH
+ and syntax given by the global `re_syntax_options', into the buffer
+ BUFFER. Return NULL if successful, and an error string if not. */
+extern const char *re_compile_pattern
+ _RE_ARGS ((const char *pattern, int length,
+ struct re_pattern_buffer *buffer));
+
+
+/* Compile a fastmap for the compiled pattern in BUFFER; used to
+ accelerate searches. Return 0 if successful and -2 if was an
+ internal error. */
+extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
+
+
+/* Search in the string STRING (with length LENGTH) for the pattern
+ compiled into BUFFER. Start searching at position START, for RANGE
+ characters. Return the starting position of the match, -1 for no
+ match, or -2 for an internal error. Also return register
+ information in REGS (if REGS and BUFFER->no_sub are nonzero). */
+extern int re_search
+ _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
+ int length, int start, int range, struct re_registers *regs));
+
+
+/* Like `re_search', but search in the concatenation of STRING1 and
+ STRING2. Also, stop searching at index START + STOP. */
+extern int re_search_2
+ _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
+ int length1, const char *string2, int length2,
+ int start, int range, struct re_registers *regs, int stop));
+
+
+/* Like `re_search', but return how many characters in STRING the regexp
+ in BUFFER matched, starting at position START. */
+extern int re_match
+ _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
+ int length, int start, struct re_registers *regs));
+
+
+/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
+extern int re_match_2
+ _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
+ int length1, const char *string2, int length2,
+ int start, struct re_registers *regs, int stop));
+
+
+/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
+ ENDS. Subsequent matches using BUFFER and REGS will use this memory
+ for recording register information. STARTS and ENDS must be
+ allocated with malloc, and must each be at least `NUM_REGS * sizeof
+ (regoff_t)' bytes long.
+
+ If NUM_REGS == 0, then subsequent matches should allocate their own
+ register data.
+
+ Unless this function is called, the first search or match using
+ PATTERN_BUFFER will allocate its own register data, without
+ freeing the old data. */
+extern void re_set_registers
+ _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
+ unsigned num_regs, regoff_t *starts, regoff_t *ends));
+
+/* 4.2 bsd compatibility. */
+extern char *re_comp _RE_ARGS ((const char *));
+extern int re_exec _RE_ARGS ((const char *));
+
+/* POSIX compatibility. */
+extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags));
+extern int regexec
+ _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch,
+ regmatch_t pmatch[], int eflags));
+extern size_t regerror
+ _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf,
+ size_t errbuf_size));
+extern void regfree _RE_ARGS ((regex_t *preg));
+
+#ifdef __cplusplus
+}
+#endif /* C++ */
+
+#endif /* not __REGEXP_LIBRARY_H__ */
+
+/*
+Local variables:
+make-backup-files: t
+version-control: t
+trim-versions-without-asking: nil
+End:
+*/
diff --git a/include/log.h b/include/log.h
index 441e092982b..31e6ae6d0e0 100644
--- a/include/log.h
+++ b/include/log.h
@@ -24,7 +24,8 @@
#define LOG_LEVEL_CRIT 1
#define LOG_LEVEL_ERR 2
#define LOG_LEVEL_WARNING 3
-#define LOG_LEVEL_DEBUG 4
+#define LOG_LEVEL_INFORMATION 4
+#define LOG_LEVEL_DEBUG 5
#define LOG_TYPE_UNDEFINED 0
#define LOG_TYPE_SYSLOG 1
@@ -33,6 +34,10 @@
/* Type - 0 (syslog), 1 - file */
int zabbix_open_log(int type,int level, const char *filename);
void zabbix_log(int level, const char *fmt, ...);
+void zabbix_close_log(void);
void zabbix_set_log_level(int level);
+char *strerror_from_system(unsigned long error);
+char *strerror_from_module(unsigned long error, const char *module);
+
#endif
diff --git a/include/mutexs.h b/include/mutexs.h
new file mode 100755
index 00000000000..3f9f82e7459
--- /dev/null
+++ b/include/mutexs.h
@@ -0,0 +1,44 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_MUTEXS_H
+#define ZABBIX_MUTEXS_H
+
+#if defined(WIN32)
+
+ #define ZBX_MUTEX HANDLE
+ #define ZBX_MUTEX_ERROR (0)
+ #define ZBX_MUTEX_OK (1)
+
+#else /* not WIN32 */
+
+
+ #define ZBX_MUTEX int
+
+ #define ZBX_MUTEX_ERROR (-1)
+ #define ZBX_MUTEX_OK (1)
+
+#endif /* WIN32 */
+
+int zbx_mutex_create(ZBX_MUTEX *mutex, char *name);
+int zbx_mutex_lock(ZBX_MUTEX *mutex);
+int zbx_mutex_unlock(ZBX_MUTEX *mutex);
+int zbx_mutex_destroy(ZBX_MUTEX *mutex);
+
+#endif /* ZABBIX_MUTEXS_H */
diff --git a/include/perfmon.h b/include/perfmon.h
new file mode 100755
index 00000000000..32cb6248bc1
--- /dev/null
+++ b/include/perfmon.h
@@ -0,0 +1,58 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_PERFMON_H
+#define ZABBIX_PERFMON_H
+
+#if !defined(WIN32)
+# error "This module allowed only for Windows OS"
+#endif
+
+//
+// Performance Counter Indexes
+//
+
+#define PCI_SYSTEM (2)
+#define PCI_PROCESSOR (238)
+#define PCI_PROCESSOR_TIME (6)
+#define PCI_PROCESSOR_QUEUE_LENGTH (44)
+#define PCI_SYSTEM_UP_TIME (674)
+
+//
+// Performance Countername structure
+//
+
+#define MAX_PERFCOUNTER_NAME_LEN (108) /* old naming <MAX_COUNTER_NAME> */
+
+struct perfcounter
+{
+ struct perfcounter *next;
+ DWORD pdhIndex;
+ char name[MAX_PERFCOUNTER_NAME_LEN]; /* must be caracter array! if you want to rewrite */
+ /* to dinacal memory allocation CHECK for usage */
+ /* of sizeof function */
+};
+
+typedef struct perfcounter PERFCOUNTER;
+
+extern PERFCOUNTER *PerfCounterList;
+
+char *GetCounterName(DWORD index);
+
+#endif /* ZABBIX_PERFMON_H */
diff --git a/include/pid.h b/include/pid.h
index a39a66c946f..5895610b18d 100644
--- a/include/pid.h
+++ b/include/pid.h
@@ -20,6 +20,11 @@
#ifndef ZABBIX_PID_H
#define ZABBIX_PID_H
-int create_pid_file(const char *pidfile);
+#if defined(WIN32)
+# error "This module allowed only for Linux OS"
+#endif
+
+int create_pid_file(const char *pidfile);
+void drop_pid_file(const char *pidfile);
#endif
diff --git a/include/service.h b/include/service.h
new file mode 100755
index 00000000000..7b0225f6996
--- /dev/null
+++ b/include/service.h
@@ -0,0 +1,55 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_SERVICE_H
+#define ZABBIX_SERVICE_H
+
+#if !defined(WIN32)
+# error "This module allowed only for Windows OS"
+#endif
+
+#include "threads.h"
+
+extern ZBX_THREAD_HANDLE *threads;
+
+#define ZABBIX_SERVICE_NAME "ZabbixAgentdW32"
+#define ZABBIX_EVENT_SOURCE "ZABBIX Win32 Agent"
+
+void service_start(void);
+
+int ZabbixCreateService(char *execName);
+int ZabbixRemoveService(void);
+int ZabbixStartService(void);
+int ZabbixStopService(void);
+
+
+/* APPLICATION running status */
+/* requred for closing application from service */
+extern int application_is_runned;
+
+#define ZBX_APP_STOPPED 1
+#define ZBX_APP_RUNNED 1
+
+/* ask for running application of closing status */
+#define ZBX_IS_RUNNING (ZBX_APP_RUNNED == application_is_runned)
+
+/* ask for application closing status */
+#define ZBX_DO_EXIT() (application_is_runned = ZBX_APP_STOPPED)
+
+#endif /* ZABBIX_SERVICE_H */
diff --git a/include/sysinc.h b/include/sysinc.h
index 33900010325..d39cb75e733 100644
--- a/include/sysinc.h
+++ b/include/sysinc.h
@@ -20,9 +20,7 @@
#ifndef ZABBIX_SYSINC_H
#define ZABBIX_SYSINC_H
-#if !defined(WIN32)
-# include "config.h"
-#endif
+#include "config.h"
#include <stdio.h>
#include <stdlib.h>
@@ -35,6 +33,34 @@
# include <errno.h>
#endif
+#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+# include <process.h>
+#endif
+
+#ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif
+
+#ifdef HAVE_CONIO_H
+# include <conio.h>
+#endif
+
+#ifdef HAVE_PDH_H
+# include <pdh.h>
+#endif
+
+#ifdef HAVE_PSAPI_H
+# include <psapi.h>
+#endif
+
+#ifdef HAVE_STDARG_H
+# include <stdarg.h>
+#endif
+
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
@@ -99,6 +125,10 @@
# include <netdb.h>
#endif
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
@@ -137,6 +167,10 @@
# include <sys/pstat.h>
#endif
+#ifdef HAVE_PTHREAD_H
+# include <pthread.h>
+#endif
+
#ifdef HAVE_SYS_DK_H
# include <sys/dk.h>
#endif
@@ -197,6 +231,10 @@
# include <sys/vmmeter.h>
#endif
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
+
#ifdef HAVE_NLIST_H
# include <nlist.h>
#endif
@@ -228,6 +266,26 @@
# endif
#endif
+#ifdef HAVE_SYS_IPC_H
+# include <sys/ipc.h>
+#endif
+
+#ifdef HAVE_SYS_SEM_H
+# include <sys/sem.h>
+#endif
+
+#ifdef HAVE_SYS_SHM_H
+# include <sys/shm.h>
+#endif
+
+#ifdef HAVE_MATH_H
+# include <math.h>
+#endif
+
+#ifdef HAVE_REGEX_H
+# include <regex.h>
+#endif
+
#ifdef HAVE_VM_VM_PARAM_H
# include <vm/vm_param.h>
#endif
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 54b73ffec1b..f1751b1bed6 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -29,15 +29,15 @@ extern int CONFIG_ENABLE_REMOTE_COMMANDS;
#define SYSINFO_RET_FAIL 1
#define SYSINFO_RET_TIMEOUT 2
-#define ZBX_METRIC struct zbx_metric_type
-ZBX_METRIC
+typedef struct zbx_metric_type
{
char *key;
unsigned flags;
int (*function)();
char *main_param;
char *test_param;
-};
+} ZBX_METRIC;
+
/* flags for command */
#define CF_USEUPARAM 1 /* use user param */
@@ -116,7 +116,7 @@ int CHECK_DNS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
int RUN_COMMAND(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
/* internal system functions */
-int EXECUTE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
+int EXECUTE_INT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
diff --git a/include/threads.h b/include/threads.h
new file mode 100755
index 00000000000..6bed36def71
--- /dev/null
+++ b/include/threads.h
@@ -0,0 +1,68 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_THREADS_H
+#define ZABBIX_THREADS_H
+
+#include "common.h"
+
+#if defined(WIN32)
+
+ #define ZBX_THREAD_ERROR (0)
+
+ #define ZBX_THREAD_HANDLE HANDLE
+
+ #define ZBX_THREAD_ENTRY_POINTER(pointer_name) \
+ unsigned (__stdcall * pointer_name )(void *)
+
+ #define ZBX_THREAD_ENTRY(entry_name, arg_name) \
+ unsigned __stdcall entry_name (void * arg_name)
+
+ #define zbx_tread_exit(status) \
+ _endthreadex((unsigned int)(status)); \
+ return ((unsigned)(status))
+
+ #define zbx_sleep(sec) Sleep(((DWORD)(sec))*((DWORD)1000))
+
+#else /* not WIN32 */
+
+ #define ZBX_THREAD_ERROR (-1)
+
+ #define ZBX_THREAD_HANDLE pid_t
+
+ #define ZBX_THREAD_ENTRY_POINTER(pointer_name) \
+ unsigned (* pointer_name )(void *)
+
+ #define ZBX_THREAD_ENTRY(entry_name, arg_name) \
+ unsigned entry_name (void * arg_name )
+
+ #define zbx_tread_exit(status) \
+ exit((int)(status)); \
+ return ((unsigned)(status))
+
+ #define zbx_sleep(sec) sleep((sec))
+
+#endif /* WIN32 */
+
+ZBX_THREAD_HANDLE zbx_thread_start(ZBX_THREAD_ENTRY_POINTER(handler), void *args);
+int zbx_thread_wait(ZBX_THREAD_HANDLE thread);
+/* zbx_tread_exit(status) // declared as define !!! */
+long int zbx_get_thread_id(void);
+
+#endif /* ZABBIX_THREADS_H */
diff --git a/include/zbxgetopt.h b/include/zbxgetopt.h
new file mode 100755
index 00000000000..68d9e691c44
--- /dev/null
+++ b/include/zbxgetopt.h
@@ -0,0 +1,102 @@
+/* Declarations for getopt.
+ Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#ifndef ZBX_GETOPT_H
+#define ZBX_GETOPT_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+extern char *zbx_optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns EOF, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, `optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+extern int zbx_optind;
+
+/* Callers store zero here to inhibit the error message `getopt' prints
+ for unrecognized options. */
+
+extern int zbx_opterr;
+
+/* Set to an option character which was unrecognized. */
+
+extern int zbx_optopt;
+
+/* Describe the long-named options requested by the application.
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+ of `struct option' terminated by an element containing a name which is
+ zero.
+
+ The field `has_arg' is:
+ no_argument (or 0) if the option does not take an argument,
+ required_argument (or 1) if the option requires an argument,
+ optional_argument (or 2) if the option takes an optional argument.
+
+ If the field `flag' is not NULL, it points to a variable that is set
+ to the value given in the field `val' when the option is found, but
+ left unchanged if the option is not found.
+
+ To have a long-named option do something other than set an `int' to
+ a compiled-in constant, such as set a value from `optarg', set the
+ option's `flag' field to zero and its `val' field to a nonzero
+ value (the equivalent single-letter option character, if there is
+ one). For long options that have a zero `flag' field, `getopt'
+ returns the contents of the `val' field. */
+
+struct zbx_option
+{
+ const char *name;
+ /* has_arg can't be an enum because some compilers complain about
+ type mismatches in all the code that assumes it is an int. */
+ int has_arg;
+ int *flag;
+ int val;
+};
+
+/* Names for the values of the `has_arg' field of `struct option'. */
+
+#define zbx_no_argument 0
+#define zbx_required_argument 1
+#define zbx_optional_argument 2
+#define zbx_exact_argument 0x10 /* no abbrev. */
+
+int zbx_getopt(int argc, char **argv, const char *optstring);
+int zbx_getopt_long(int argc, char **argv, const char *options,
+ const struct zbx_option *long_options, int *opt_index);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ZBX_GETOPT_H */
diff --git a/include/zbxplugin.h b/include/zbxplugin.h
new file mode 100755
index 00000000000..dc7ea3420ba
--- /dev/null
+++ b/include/zbxplugin.h
@@ -0,0 +1,61 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ZBXPLUGIN_H
+#define ZABBIX_ZBXPLUGIN_H
+
+#ifdef WIN32
+
+# define __zabbix_api __cdecl
+typedef HMODULE ZBX_MODULE;
+
+#else /* not WIN32 */
+
+# define __zabbix_api
+typedef void* ZBX_MODULE;
+
+#endif /* WIN32 */
+
+#define MAX_CMDNAME 256
+
+typedef struct
+{
+ char name[MAX_CMDNAME];
+ int (__zabbix_api * handler_float)(char *,double *); /* Handler if return value is floating point numeric */
+ int (__zabbix_api * handler_string)(char *,char **); /* Handler if return value is string */
+} ZBX_PLUGIN_ARGS;
+
+struct zbx_plugin_list
+{
+ struct zbx_plugin_list *next; // Pointer to next element in a chain
+
+ ZBX_MODULE hModule; // DLL module handle
+ int runned;
+ int (__zabbix_api * init)(char *,ZBX_PLUGIN_ARGS **);
+ void (__zabbix_api * shutdown)(void);
+ ZBX_PLUGIN_ARGS *args; // List of subagent's commands
+};
+
+typedef struct zbx_plugin_list ZBX_PLUGIN_LIST;
+
+extern ZBX_PLUGIN_LIST *PluginsList;
+
+int add_plugin(char *args);
+
+#endif /* ZABBIX_ZBXPLUGIN_H */
diff --git a/include/zbxsecurity.h b/include/zbxsecurity.h
new file mode 100755
index 00000000000..66e54e7c831
--- /dev/null
+++ b/include/zbxsecurity.h
@@ -0,0 +1,27 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ZBXSECURITY_H
+#define ZABBIX_ZBXSECURITY_H
+
+#include "zbxsock.h"
+
+int check_security(ZBX_SOCKET sock, char *ip_list, int allow_if_empty);
+
+#endif /* ZABBIX_ZBXSECURITY_H */
diff --git a/include/zbxsock.h b/include/zbxsock.h
new file mode 100755
index 00000000000..52b4834ce44
--- /dev/null
+++ b/include/zbxsock.h
@@ -0,0 +1,72 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ZBXSOCK_H
+#define ZABBIX_ZBXSOCK_H
+
+
+#if !defined(INVALID_SOCKET)
+# define INVALID_SOCKET (-1)
+#endif /* INVALID_SOCKET */
+
+#if !defined(SOCKET_ERROR)
+# define SOCKET_ERROR (-1)
+#endif /* SOCKET_ERROR */
+
+#if !defined (EINTR)
+# define EINTR WSAETIMEDOUT
+#endif /* EINTR */
+
+#if !defined(EHOSTUNREACH)
+# define EHOSTUNREACH WSAEHOSTUNREACH
+#endif /* EHOSTUNREACH */
+
+#if !defined(ECONNRESET)
+# define ECONNRESET WSAECONNRESET
+#endif /* ECONNRESET */
+
+#if !defined(SOMAXCONN)
+# define SOMAXCONN 1024
+#endif /* SOMAXCONN */
+
+#if defined(SOCKET)
+
+ typedef SOCKET ZBX_SOCKET;
+
+#else /* not SOCKET */
+
+ typedef int ZBX_SOCKET;
+
+#endif /* SOCKET */
+
+typedef struct sockaddr_in ZBX_SOCKADDR;
+
+int zbx_sock_read(ZBX_SOCKET sock, void *buf, int buflen, int timeout);
+int zbx_sock_write(ZBX_SOCKET sock, void *buf, int buflen);
+
+#if defined (WIN32)
+# define zbx_sock_close(sock) closesocket(sock)
+# define zbx_sock_last_error() WSAGetLastError()
+#else /* not WIN32 */
+# define zbx_sock_close(sock) close(sock)
+# define zbx_sock_last_error() errno
+#endif /* WIN32 */
+
+
+#endif /* ZABBIX_ZBXSOCK_H */
diff --git a/include/zbxtypes.h b/include/zbxtypes.h
new file mode 100755
index 00000000000..ee94bf8f811
--- /dev/null
+++ b/include/zbxtypes.h
@@ -0,0 +1,57 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_TYPES_H
+#define ZABBIX_TYPES_H
+
+#if defined(WIN32)
+
+# define zbx_uint64_t __int64
+# define ZBX_FS_UI64 "%llu"
+
+# define zbx_pid_t int
+
+# define stat _stat
+# define snprintf _snprintf
+# define vsnprintf _vsnprintf
+
+# define alloca _alloca
+
+#ifndef uint32_t
+# define uint32_t __int32
+#endif /* uint32_t */
+
+#else /* WIN32 */
+
+# define zbx_uint64_t uint64_t
+# if __WORDSIZE == 64
+# define ZBX_FS_UI64 "%lu"
+# else /* __WORDSIZE == 64 */
+# define ZBX_FS_UI64 "%llu"
+# endif /* __WORDSIZE == 64 */
+
+# define zbx_pid_t pid_t
+
+#endif /* WIN32 */
+
+#ifndef S_ISREG
+# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
+#endif
+
+#endif