summaryrefslogtreecommitdiffstats
path: root/lib/utils_tcp.c
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-09-12 15:42:10 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-09-12 15:42:10 (GMT)
commit662997251d4fc43f4155784f9e7df827f193305e (patch)
tree0a9ad5c5607598da0eb6b6d71fa8c47ca44186fb /lib/utils_tcp.c
parentca9ce71576ddf78cc54fe3b6f0428cdfea72e9df (diff)
downloadmonitoring-plugins-662997251d4fc43f4155784f9e7df827f193305e.tar.gz
Improve interface of np_expect_match() function
Replace the three boolean parameters of lib/utils_tcp.c's np_expect_match() function with a single "flags" parameter.
Diffstat (limited to 'lib/utils_tcp.c')
-rw-r--r--lib/utils_tcp.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c
index 8589ce6..cf67b11 100644
--- a/lib/utils_tcp.c
+++ b/lib/utils_tcp.c
@@ -30,26 +30,27 @@
30#include "utils_tcp.h" 30#include "utils_tcp.h"
31 31
32int 32int
33np_expect_match(char* status, char** server_expect, int expect_count, int all, int exact_match, int verbose) 33np_expect_match(char* status, char** server_expect, int expect_count, int flags)
34{ 34{
35 int match = 0; 35 int match = 0;
36 int i; 36 int i;
37 for (i = 0; i < expect_count; i++) { 37 for (i = 0; i < expect_count; i++) {
38 if (verbose) 38 if (flags & NP_MATCH_VERBOSE)
39 printf ("looking for [%s] %s [%s]\n", server_expect[i], 39 printf ("looking for [%s] %s [%s]\n", server_expect[i],
40 (exact_match) ? "in beginning of" : "anywhere in", 40 (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in",
41 status); 41 status);
42 42
43 if ((exact_match && !strncmp(status, server_expect[i], strlen(server_expect[i]))) || 43 if ((flags & NP_MATCH_EXACT &&
44 (! exact_match && strstr(status, server_expect[i]))) 44 !strncmp(status, server_expect[i], strlen(server_expect[i]))) ||
45 (!(flags & NP_MATCH_EXACT) && strstr(status, server_expect[i])))
45 { 46 {
46 if(verbose) puts("found it"); 47 if(flags & NP_MATCH_VERBOSE) puts("found it");
47 match += 1; 48 match += 1;
48 } else 49 } else
49 if(verbose) puts("couldn't find it"); 50 if(flags & NP_MATCH_VERBOSE) puts("couldn't find it");
50 } 51 }
51 if ((all == TRUE && match == expect_count) || 52 if ((flags & NP_MATCH_ALL && match == expect_count) ||
52 (! all && match >= 1)) { 53 (!(flags & NP_MATCH_ALL) && match >= 1)) {
53 return TRUE; 54 return TRUE;
54 } else 55 } else
55 return FALSE; 56 return FALSE;