diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 16:16:14 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 16:16:14 +0200 |
commit | ff7305bdfe2f682857ba888c70aec2fc7cee798e (patch) | |
tree | b5b3bdcf41d42d525906b6e8d82cdf143e74ec5d /lib/utils_tcp.c | |
parent | f07f96c3cfaeb30f95eb1898d6cc58b200e70831 (diff) | |
parent | 601a48a63e745817cf2a4c7f3ca526e393dd3fb8 (diff) | |
download | monitoring-plugins-ff7305bdfe2f682857ba888c70aec2fc7cee798e.tar.gz |
Merge branch 'master' into refactor/check_apt
Diffstat (limited to 'lib/utils_tcp.c')
-rw-r--r-- | lib/utils_tcp.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c index daae1d54..a82d5a3f 100644 --- a/lib/utils_tcp.c +++ b/lib/utils_tcp.c | |||
@@ -26,28 +26,35 @@ | |||
26 | * | 26 | * |
27 | *****************************************************************************/ | 27 | *****************************************************************************/ |
28 | 28 | ||
29 | #include "common.h" | 29 | #include "../config.h" |
30 | #include "utils_tcp.h" | 30 | #include "utils_tcp.h" |
31 | #include <stdio.h> | ||
32 | #include <string.h> | ||
31 | 33 | ||
32 | #define VERBOSE(message) \ | 34 | #define VERBOSE(message) \ |
33 | do { \ | 35 | do { \ |
34 | if (flags & NP_MATCH_VERBOSE) \ | 36 | if (flags & NP_MATCH_VERBOSE) \ |
35 | puts(message); \ | 37 | puts(message); \ |
36 | } while (0) | 38 | } while (0) |
37 | 39 | ||
38 | enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count, int flags) { | 40 | enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count, |
39 | int i, match = 0, partial = 0; | 41 | int flags) { |
40 | 42 | int match = 0; | |
41 | for (i = 0; i < expect_count; i++) { | 43 | int partial = 0; |
42 | if (flags & NP_MATCH_VERBOSE) | 44 | for (int i = 0; i < expect_count; i++) { |
43 | printf("looking for [%s] %s [%s]\n", server_expect[i], (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status); | 45 | if (flags & NP_MATCH_VERBOSE) { |
46 | printf("looking for [%s] %s [%s]\n", server_expect[i], | ||
47 | (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status); | ||
48 | } | ||
44 | 49 | ||
45 | if (flags & NP_MATCH_EXACT) { | 50 | if (flags & NP_MATCH_EXACT) { |
46 | if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) { | 51 | if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) { |
47 | VERBOSE("found it"); | 52 | VERBOSE("found it"); |
48 | match++; | 53 | match++; |
49 | continue; | 54 | continue; |
50 | } else if (strncmp(status, server_expect[i], strlen(status)) == 0) { | 55 | } |
56 | |||
57 | if (strncmp(status, server_expect[i], strlen(status)) == 0) { | ||
51 | VERBOSE("found a substring"); | 58 | VERBOSE("found a substring"); |
52 | partial++; | 59 | partial++; |
53 | continue; | 60 | continue; |
@@ -60,10 +67,12 @@ enum np_match_result np_expect_match(char *status, char **server_expect, int exp | |||
60 | VERBOSE("couldn't find it"); | 67 | VERBOSE("couldn't find it"); |
61 | } | 68 | } |
62 | 69 | ||
63 | if ((flags & NP_MATCH_ALL && match == expect_count) || (!(flags & NP_MATCH_ALL) && match >= 1)) | 70 | if ((flags & NP_MATCH_ALL && match == expect_count) || |
71 | (!(flags & NP_MATCH_ALL) && match >= 1)) { | ||
64 | return NP_MATCH_SUCCESS; | 72 | return NP_MATCH_SUCCESS; |
65 | else if (partial > 0 || !(flags & NP_MATCH_EXACT)) | 73 | } |
74 | if (partial > 0 || !(flags & NP_MATCH_EXACT)) { | ||
66 | return NP_MATCH_RETRY; | 75 | return NP_MATCH_RETRY; |
67 | else | 76 | } |
68 | return NP_MATCH_FAILURE; | 77 | return NP_MATCH_FAILURE; |
69 | } | 78 | } |