1 /* @(#) $Id: ./src/util/ossec-regex.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
14 /* This tool will clear the project statistics */
19 #define ARGV0 "ossec-regex"
25 printf("\nOSSEC HIDS %s: ossec-regex pattern\n", ARGV0);
31 int main(int argc, char **argv)
35 char msg[OS_MAXSTR +1];
36 memset(msg, '\0', OS_MAXSTR +1);
51 if(strcmp(argv[1], "-h") == 0)
57 os_strdup(argv[1], pattern);
58 if(!OSRegex_Compile(pattern, ®ex, 0))
60 printf("pattern does not compile with OSRegex_Compile\n");
63 if(!OSMatch_Compile(pattern, &matcher, 0))
65 printf("pattern does not compile with OSMatch_Compile\n");
70 while((fgets(msg, OS_MAXSTR, stdin)) != NULL)
72 /* Removing new line. */
73 if(msg[strlen(msg) -1] == '\n')
74 msg[strlen(msg) -1] = '\0';
76 /* Make sure we ignore blank lines. */
77 if(strlen(msg) < 2) { continue; }
79 if(OSRegex_Execute(msg, ®ex))
80 printf("+OSRegex_Execute: %s\n",msg);
83 printf("-OSRegex_Execute: \n");
86 if(OS_Regex(pattern, msg))
87 printf("+OS_Regex : %s\n", msg);
90 printf("-OS_Regex: \n");
93 if(OSMatch_Execute(msg, strlen(msg), &matcher))
94 printf("+OSMatch_Compile: %s\n", msg);
96 if(OS_Match2(pattern, msg))
97 printf("+OS_Match2 : %s\n", msg);