diff options
Diffstat (limited to 'lib/utils_tcp.c')
-rw-r--r-- | lib/utils_tcp.c | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c index cf67b116..497a1701 100644 --- a/lib/utils_tcp.c +++ b/lib/utils_tcp.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Library for check_tcp | 3 | * Library for check_tcp |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2007 Nagios Plugins Development Team | 6 | * Copyright (c) 1999-2013 Nagios Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
@@ -29,29 +29,44 @@ | |||
29 | #include "common.h" | 29 | #include "common.h" |
30 | #include "utils_tcp.h" | 30 | #include "utils_tcp.h" |
31 | 31 | ||
32 | int | 32 | #define VERBOSE(message) \ |
33 | do { \ | ||
34 | if (flags & NP_MATCH_VERBOSE) \ | ||
35 | puts(message); \ | ||
36 | } while (0) | ||
37 | |||
38 | enum np_match_result | ||
33 | np_expect_match(char* status, char** server_expect, int expect_count, int flags) | 39 | np_expect_match(char* status, char** server_expect, int expect_count, int flags) |
34 | { | 40 | { |
35 | int match = 0; | 41 | int i, match = 0, partial = 0; |
36 | int i; | ||
37 | for (i = 0; i < expect_count; i++) { | 42 | for (i = 0; i < expect_count; i++) { |
38 | if (flags & NP_MATCH_VERBOSE) | 43 | if (flags & NP_MATCH_VERBOSE) |
39 | printf ("looking for [%s] %s [%s]\n", server_expect[i], | 44 | printf ("looking for [%s] %s [%s]\n", server_expect[i], |
40 | (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", | 45 | (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", |
41 | status); | 46 | status); |
42 | 47 | ||
43 | if ((flags & NP_MATCH_EXACT && | 48 | if (flags & NP_MATCH_EXACT) { |
44 | !strncmp(status, server_expect[i], strlen(server_expect[i]))) || | 49 | if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) { |
45 | (!(flags & NP_MATCH_EXACT) && strstr(status, server_expect[i]))) | 50 | VERBOSE("found it"); |
46 | { | 51 | match++; |
47 | if(flags & NP_MATCH_VERBOSE) puts("found it"); | 52 | continue; |
48 | match += 1; | 53 | } else if (strncmp(status, server_expect[i], strlen(status)) == 0) { |
49 | } else | 54 | VERBOSE("found a substring"); |
50 | if(flags & NP_MATCH_VERBOSE) puts("couldn't find it"); | 55 | partial++; |
56 | continue; | ||
57 | } | ||
58 | } else if (strstr(status, server_expect[i]) != NULL) { | ||
59 | VERBOSE("found it"); | ||
60 | match++; | ||
61 | continue; | ||
62 | } | ||
63 | VERBOSE("couldn't find it"); | ||
51 | } | 64 | } |
52 | if ((flags & NP_MATCH_ALL && match == expect_count) || | 65 | if ((flags & NP_MATCH_ALL && match == expect_count) || |
53 | (!(flags & NP_MATCH_ALL) && match >= 1)) { | 66 | (!(flags & NP_MATCH_ALL) && match >= 1)) |
54 | return TRUE; | 67 | return NP_MATCH_SUCCESS; |
55 | } else | 68 | else if (partial > 0 || !(flags & NP_MATCH_EXACT)) |
56 | return FALSE; | 69 | return NP_MATCH_RETRY; |
70 | else | ||
71 | return NP_MATCH_FAILURE; | ||
57 | } | 72 | } |