Code

fix a variety of compiler warnings about qualifier discards and other pedantic stuff
[nagiosplug.git] / plugins / utils.h
1 /* header file for nagios plugins utils.c */
3 /* this file should be included in all plugins */
5 /* The purpose of this package is to provide safer alternantives to C
6 functions that might otherwise be vulnerable to hacking. This
7 currently includes a standard suite of validation routines to be sure
8 that an string argument acually converts to its intended type and a
9 suite of string handling routine that do their own memory management
10 in order to resist overflow attacks. In addition, a few functions are
11 provided to standardize version and error reporting accross the entire
12 suite of plugins. */
14 /* Standardize version information, termination */
16 void support (void);
17 char *clean_revstring (const char *revstring);
18 void print_revision (const char *, const char *);
19 void die (int result, const char *fmt, ...) __attribute__((noreturn));
21 /* Handle timeouts */
23 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
24 extern unsigned int timeout_interval;
25 RETSIGTYPE timeout_alarm_handler (int);
26 #else
27 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
28 extern RETSIGTYPE timeout_alarm_handler (int);
29 #endif
31 time_t start_time, end_time;
33 /* Test input types */
35 int is_integer (char *);
36 int is_intpos (char *);
37 int is_intneg (char *);
38 int is_intnonneg (char *);
39 int is_intpercent (char *);
41 int is_numeric (char *);
42 int is_positive (char *);
43 int is_negative (char *);
44 int is_nonnegative (char *);
45 int is_percentage (char *);
47 int is_option (char *);
49 /* generalized timer that will do milliseconds if available */
50 #ifndef HAVE_STRUCT_TIMEVAL
51 struct timeval {
52         long tv_sec;        /* seconds */
53         long tv_usec;  /* microseconds */
54 };
55 #endif
57 #ifndef HAVE_GETTIMEOFDAY
58 int gettimeofday(struct timeval *tv, struct timezone *tz);
59 #endif
61 double delta_time (struct timeval tv);
63 /* Handle strings safely */
65 void strip (char *buffer);
66 char *strscpy (char *dest, const char *src);
67 char *strnl (char *str);
68 char *strpcpy (char *dest, const char *src, const char *str);
69 char *strpcat (char *dest, const char *src, const char *str);
71 int max_state (int a, int b);
73 void usage (char *msg) __attribute__((noreturn));
74 void usage2(char *msg, char *arg) __attribute__((noreturn));
75 void usage3(char *msg, int arg) __attribute__((noreturn));
77 const char *state_text (int result);
79 #define max(a,b) (((a)>(b))?(a):(b))
81 /* The idea here is that, although not every plugin will use all of these, 
82    most will or should.  Therefore, for consistency, these very common 
83    options should have only these meanings throughout the overall suite */
85 #define STD_LONG_OPTS \
86 {"version",no_argument,0,'V'},\
87 {"verbose",no_argument,0,'v'},\
88 {"help",no_argument,0,'h'},\
89 {"timeout",required_argument,0,'t'},\
90 {"critical",required_argument,0,'c'},\
91 {"warning",required_argument,0,'w'},\
92 {"hostname",required_argument,0,'H'}
94 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
95 \t<%s>\n\n"
97 #define UT_HLP_VRS "\
98        %s (-h | --help) for detailed help\n\
99        %s (-V | --version) for version information\n"
101 #define UT_HELP_VRSN "\
102 \nOptions:\n\
103  -h, --help\n\
104     Print detailed help screen\n\
105  -V, --version\n\
106     Print version information\n"
108 #define UT_HOST_PORT "\
109  -H, --hostname=ADDRESS\n\
110     Host name or IP Address\n\
111  -%c, --port=INTEGER\n\
112     Port number (default: %s)\n"
114 #define UT_IPv46 "\
115  -4, --use-ipv4\n\
116     Use IPv4 connection\n\
117  -6, --use-ipv6\n\
118     Use IPv6 connection\n"
120 #define UT_VERBOSE "\
121  -v, --verbose\n\
122     Show details for command-line debugging (Nagios may truncate output)\n"
124 #define UT_WARN_CRIT "\
125  -w, --warning=DOUBLE\n\
126     Response time to result in warning status (seconds)\n\
127  -c, --critical=DOUBLE\n\
128     Response time to result in critical status (seconds)\n"
130 #define UT_TIMEOUT "\
131  -t, --timeout=INTEGER\n\
132     Seconds before connection times out (default: %d)\n"
134 #define UT_SUPPORT "\n\
135 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
136 regarding use of this software. To submit patches or suggest improvements,\n\
137 send email to nagiosplug-devel@lists.sourceforge.net\n"
139 #define UT_NOWARRANTY "\
140 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
141 copies of the plugins under the terms of the GNU General Public License.\n\
142 For more information about these matters, see the file named COPYING.\n"