1 /* $OSSEC, os_match_execute.c, v0.1, 2006/04/18, Daniel B. Cid$ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
18 #include "os_regex_internal.h"
21 /** Internal matching **/
22 int _OS_Match(const char *pattern, const char *str, size_t str_len, size_t size)
25 const char *pt = pattern;
30 size = str_len - size;
32 /* Look to match the first pattern */
36 if(charmap[(uchar)str[i]] == *pt)
46 else if(*pt != charmap[(uchar)str[j]])
63 /** Internal matching **/
64 int _os_strncmp(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, size_t size)
66 if(strncasecmp(pattern, str, size) == 0)
72 /** Internal matching **/
73 int _os_strcmp(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size)
75 if(strcasecmp(pattern, str) == 0)
81 int _os_strmatch(__attribute__((unused)) const char *pattern, __attribute__((unused)) const char *str,
82 __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size)
87 int _os_strstr(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size)
89 if(strstr(str, pattern) != NULL)
97 /** Internal matching **/
98 int _os_strcmp_last(const char *pattern, const char *str, size_t str_len, size_t size)
100 /* Size of the string must be bigger */
104 if(strcasecmp(pattern, str + (str_len - size)) == 0)
111 /** int OSMatch_Execute(char *str, int str_len, OSMatch *reg) v0.1
112 * Compare an already compiled pattern with
114 * Returns 1 on success or 0 on error.
115 * The error code is set on reg->error.
117 int OSMatch_Execute(const char *str, size_t str_len, OSMatch *reg)
121 /* The string can't be NULL */
124 reg->error = OS_REGEX_STR_NULL;
129 /* Looping on all sub patterns */
130 while(reg->patterns[i])
132 if(reg->match_fp[i](reg->patterns[i],
135 reg->size[i]) == TRUE)