| 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 | |
|---|
| 26 | void generate_crc32_table(void); |
|---|
| 27 | unsigned long calculate_crc32(const char *buffer, int buffer_size); |
|---|
| 28 | unsigned 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__,_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_PUSH_WTYPE(type, value, obj, list) \ |
|---|
| 60 | else if (p__.first == value) { type o; o.obj = p__.second; list.push_back(o); } |
|---|
| 61 | #define MAP_OPTIONS_PUSH(value, list) \ |
|---|
| 62 | else if (p__.first == value) { list.push_back(p__.second); } |
|---|
| 63 | #define MAP_OPTIONS_INSERT(value, list) \ |
|---|
| 64 | else if (p__.first == value) { list.insert(p__.second); } |
|---|
| 65 | #define MAP_OPTIONS_DO(action) \ |
|---|
| 66 | else if (p__.first == value) { action; } |
|---|
| 67 | #define MAP_OPTIONS_STR(value, obj) \ |
|---|
| 68 | else if (p__.first == value) { obj = p__.second; } |
|---|
| 69 | #define MAP_OPTIONS_STR2INT(value, obj) \ |
|---|
| 70 | else if (p__.first == value) { obj = _wtoi(p__.second.c_str()); } |
|---|
| 71 | #define MAP_OPTIONS_STR_AND(value, obj, extra) \ |
|---|
| 72 | else if (p__.first == value) { obj = p__.second; extra;} |
|---|
| 73 | #define MAP_OPTIONS_BOOL_TRUE(value, obj) \ |
|---|
| 74 | else if (p__.first == value) { obj = true; } |
|---|
| 75 | #define MAP_OPTIONS_BOOL_FALSE(value, obj) \ |
|---|
| 76 | else if (p__.first == value) { obj = false; } |
|---|
| 77 | #define MAP_OPTIONS_BOOL_VALUE(value, obj, tStr) \ |
|---|
| 78 | else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; } |
|---|
| 79 | #define MAP_OPTIONS_MODE(value, tStr, obj, oVal) \ |
|---|
| 80 | else if ((p__.first == value)&&(p__.second == tStr)) { obj = oVal; } |
|---|
| 81 | #define MAP_OPTIONS_BOOL_EX(value, obj, tStr, fStr) \ |
|---|
| 82 | else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; } \ |
|---|
| 83 | else if ((p__.first == value)&&(p__.second == fStr)) { obj = false; } |
|---|
| 84 | #define MAP_OPTIONS_MISSING(arg, str) \ |
|---|
| 85 | else { arg = str + p__.first; return NSCAPI::returnUNKNOWN; } |
|---|
| 86 | #define MAP_OPTIONS_FALLBACK(obj) \ |
|---|
| 87 | else { obj = p__.first;} |
|---|
| 88 | #define MAP_OPTIONS_FALLBACK_AND(obj, extra) \ |
|---|
| 89 | else { obj = p__.first; extra;} |
|---|
| 90 | #define MAP_OPTIONS_END() } |
|---|
| 91 | |
|---|
| 92 | #define MAP_OPTIONS_USELESS_IF_LAST(lst) \ |
|---|
| 93 | else if (cit__ == --lst.end()) { NSC_LOG_MESSAGE_STD(_T("Warning: Useless last argument: ") + p__.first); } |
|---|
| 94 | #define MAP_OPTIONS_MISSING_EX(opt, arg, str) \ |
|---|
| 95 | else { arg = str + opt.first; return NSCAPI::returnUNKNOWN; } |
|---|
| 96 | |
|---|
| 97 | #define MAP_OPTIONS_SECONDARY_BEGIN(splt, arg) \ |
|---|
| 98 | else if (p__.first.find(splt) != std::wstring::npos) { \ |
|---|
| 99 | std::pair<std::wstring,std::wstring> arg = strEx::split(p__.first,splt); if (false) {} |
|---|
| 100 | |
|---|
| 101 | #define MAP_OPTIONS_SECONDARY_STR_AND(opt, value, objfirst, objsecond, extra) \ |
|---|
| 102 | else if (opt.first == value) { objfirst = p__.second; objsecond = opt.second; extra;} |
|---|
| 103 | |
|---|
| 104 | #define MAP_OPTIONS_FIRST_CHAR(splt, obj, extra) \ |
|---|
| 105 | else if (p__.first.size() > 1 && p__.first[0] == splt) { \ |
|---|
| 106 | obj = p__.first; extra;} |
|---|
| 107 | |
|---|
| 108 | #define MAP_OPTIONS_SECONDARY_END() } |
|---|