source: nscp/include/utils.h @ f085f9b

0.4.00.4.10.4.2
Last change on this file since f085f9b was f33c12f, checked in by Michael Medin <michael@…>, 18 months ago
  • Changed so Client interfaces no longer use "simple" interface meaning correct targets are now propagated (ie. calling NRPE -> NSCA will get correct host set automatically) (havent tested this yet, but now it builds at least, will test to night)
  • Property mode set to 100644
File size: 6.6 KB
Line 
1/**************************************************************************
2*   Copyright (C) 2004-2007 by Michael Medin <michael@medin.name>         *
3*                                                                         *
4*   This code is part of NSClient++ - http://trac.nakednuns.org/nscp      *
5*                                                                         *
6*   This program is free software; you can redistribute it and/or modify  *
7*   it under the terms of the GNU General Public License as published by  *
8*   the Free Software Foundation; either version 2 of the License, or     *
9*   (at your option) any later version.                                   *
10*                                                                         *
11*   This program is distributed in the hope that it will be useful,       *
12*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14*   GNU General Public License for more details.                          *
15*                                                                         *
16*   You should have received a copy of the GNU General Public License     *
17*   along with this program; if not, write to the                         *
18*   Free Software Foundation, Inc.,                                       *
19*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20***************************************************************************/
21#pragma once
22
23#include <string>
24#include <strEx.h>
25
26void generate_crc32_table(void);
27unsigned long calculate_crc32(const char *buffer, int buffer_size);
28unsigned long calculate_crc32(const unsigned char *buffer, int buffer_size);
29
30
31#define MAP_OPTIONS_BEGIN(args) \
32        for (std::list<std::wstring>::const_iterator cit__=args.begin();cit__!=args.end();++cit__) { \
33        std::pair<std::wstring,std::wstring> p__ = strEx::split(*cit__,std::wstring(_T("="))); if (false) {}
34
35#define MAP_OPTIONS_SHOWALL(obj) \
36                        else if (p__.first == SHOW_ALL) { if (p__.second == _T("long")) obj.show = checkHolders::showLong; else obj.show = checkHolders::showShort; } \
37                        else if (p__.first == SHOW_FAIL) { obj.show = checkHolders::showProblems; }
38
39#define MAP_OPTIONS_DISK_ALL(obj, postfix, pfUpper, pfLower) \
40                        else if (p__.first == _T("MaxWarn") pfUpper) { obj.warn.max_.upper = p__.second; } \
41                        else if (p__.first == _T("MaxCrit") pfUpper) { obj.crit.max_.upper = p__.second; } \
42                        else if (p__.first == _T("MinWarn") pfUpper) { obj.warn.min_.upper = p__.second; } \
43                        else if (p__.first == _T("MinCrit") pfUpper) { obj.crit.min_.upper = p__.second; } \
44                        else if (p__.first == _T("MaxWarn") pfLower) { obj.warn.max_.lower = p__.second; } \
45                        else if (p__.first == _T("MaxCrit") pfLower) { obj.crit.max_.lower = p__.second; } \
46                        else if (p__.first == _T("MinWarn") pfLower) { obj.warn.min_.lower = p__.second; } \
47                        else if (p__.first == _T("MinCrit") pfLower) { obj.crit.min_.lower = p__.second; } \
48                        else if (p__.first == _T("MaxWarn") postfix) { obj.warn.max_.lower = p__.second; } \
49                        else if (p__.first == _T("MaxCrit") postfix) { obj.crit.max_.lower = p__.second; } \
50                        else if (p__.first == _T("MinWarn") postfix) { obj.warn.min_.upper = p__.second; } \
51                        else if (p__.first == _T("MinCrit") postfix) { obj.crit.min_.upper = p__.second; }
52
53#define MAP_OPTIONS_NUMERIC_ALL(obj, postfix) \
54                        else if (p__.first == (_T("MaxWarn") postfix)) { obj.warn.max_ = p__.second; } \
55                        else if (p__.first == (_T("MaxCrit") postfix)) { obj.crit.max_ = p__.second; } \
56                        else if (p__.first == (_T("MinWarn") postfix)) { obj.warn.min_ = p__.second; } \
57                        else if (p__.first == (_T("MinCrit") postfix)) { obj.crit.min_ = p__.second; }
58
59#define MAP_OPTIONS_EXACT_NUMERIC_ALL(obj, postfix) \
60                        else if (p__.first == (_T("warn") postfix)) { obj.warn = p__.second; } \
61                        else if (p__.first == (_T("crit") postfix)) { obj.crit = p__.second; } \
62
63#define MAP_OPTIONS_EXACT_NUMERIC_ALL_MULTI(obj, postfix) \
64                        else if (p__.first == (_T("warn") postfix)) { obj.set_warn_bound(p__.second); } \
65                        else if (p__.first == (_T("crit") postfix)) { obj.set_crit_bound(p__.second); } \
66
67#define MAP_OPTIONS_PUSH_WTYPE(type, value, obj, list) \
68                        else if (p__.first == value) { type o; o.obj = p__.second; list.push_back(o); }
69#define MAP_OPTIONS_PUSH(value, list) \
70                        else if (p__.first == value) { list.push_back(p__.second); }
71#define MAP_OPTIONS_INSERT(value, list) \
72                        else if (p__.first == value) { list.insert(p__.second); }
73#define MAP_OPTIONS_DO(action) \
74                        else if (p__.first == value) { action; }
75#define MAP_OPTIONS_STR(value, obj) \
76                        else if (p__.first == value) { obj = p__.second; }
77#define MAP_OPTIONS_DOUBLE(value, obj) \
78                        else if (p__.first == value) { obj = strEx::stod(p__.second); }
79
80#define MAP_OPTIONS_STR2INT(value, obj) \
81                        else if (p__.first == value) { obj = _wtoi(p__.second.c_str()); }
82#define MAP_OPTIONS_STR_AND(value, obj, extra) \
83                        else if (p__.first == value) { obj = p__.second; extra;}
84#define MAP_OPTIONS_BOOL_TRUE(value, obj) \
85                        else if (p__.first == value) { obj = true; }
86#define MAP_OPTIONS_BOOL_FALSE(value, obj) \
87                        else if (p__.first == value) { obj = false; }
88#define MAP_OPTIONS_BOOL_VALUE(value, obj, tStr) \
89                        else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; }
90#define MAP_OPTIONS_MODE(value, tStr, obj, oVal) \
91                        else if ((p__.first == value)&&(p__.second == tStr)) { obj = oVal; }
92#define MAP_OPTIONS_BOOL_EX(value, obj, tStr, fStr) \
93                        else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; } \
94                        else if ((p__.first == value)&&(p__.second == fStr)) { obj = false; }
95#define MAP_OPTIONS_MISSING(arg, str) \
96                        else { arg = str + p__.first; return NSCAPI::returnUNKNOWN; }
97#define MAP_OPTIONS_FALLBACK(obj) \
98                        else { obj = p__.first;}
99#define MAP_OPTIONS_FALLBACK_AND(obj, extra) \
100                        else { obj = p__.first; extra;}
101#define MAP_OPTIONS_END() }
102
103#define MAP_OPTIONS_USELESS_IF_LAST(lst) \
104                        else if (cit__ == --lst.end()) { NSC_LOG_MESSAGE_STD(_T("Warning: Useless last argument: ") + p__.first); }
105#define MAP_OPTIONS_MISSING_EX(opt, arg, str) \
106                else { arg = str + opt.first; return NSCAPI::returnUNKNOWN; }
107
108#define MAP_OPTIONS_SECONDARY_BEGIN(splt, arg) \
109        else if (p__.first.find(splt) != std::wstring::npos) { \
110        std::pair<std::wstring,std::wstring> arg = strEx::split(p__.first,std::wstring(splt)); if (false) {}
111
112#define MAP_OPTIONS_SECONDARY_STR_AND(opt, value, objfirst, objsecond, extra) \
113                        else if (opt.first == value) { objfirst = p__.second; objsecond = opt.second; extra;}
114
115#define MAP_OPTIONS_FIRST_CHAR(splt, obj, extra) \
116        else if (p__.first.size() > 1 && p__.first[0] == splt) { \
117                        obj = p__.first; extra;}
118
119#define MAP_OPTIONS_SECONDARY_END() }
Note: See TracBrowser for help on using the repository browser.