1 /*****************************************************************************
3 * Library for check_tcp
6 * Copyright (c) 1999-2013 Monitoring Plugins Development Team
10 * This file contains utilities for check_tcp. These are tested by libtap
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 *****************************************************************************/
30 #include "utils_tcp.h"
32 #define VERBOSE(message) \
34 if (flags & NP_MATCH_VERBOSE) \
39 np_expect_match(char *status
, char **server_expect
, int expect_count
, int flags
)
41 int i
, match
= 0, partial
= 0;
43 for (i
= 0; i
< expect_count
; i
++) {
44 if (flags
& NP_MATCH_VERBOSE
)
45 printf("looking for [%s] %s [%s]\n", server_expect
[i
],
46 (flags
& NP_MATCH_EXACT
) ?
47 "in beginning of" : "anywhere in",
50 if (flags
& NP_MATCH_EXACT
) {
51 if (strncmp(status
, server_expect
[i
], strlen(server_expect
[i
])) == 0) {
55 } else if (strncmp(status
, server_expect
[i
], strlen(status
)) == 0) {
56 VERBOSE("found a substring");
60 } else if (strstr(status
, server_expect
[i
]) != NULL
) {
65 VERBOSE("couldn't find it");
68 if ((flags
& NP_MATCH_ALL
&& match
== expect_count
) ||
69 (!(flags
& NP_MATCH_ALL
) && match
>= 1))
70 return NP_MATCH_SUCCESS
;
71 else if (partial
> 0 || !(flags
& NP_MATCH_EXACT
))
72 return NP_MATCH_RETRY
;
74 return NP_MATCH_FAILURE
;