ctdb-server: Remove duplicate logic
[samba4-gss.git] / source3 / rpc_server / mdssvc / es_lexer.l
blob4be42259f9c4f6be84822cf09b85f5f2201e9dcc
1 /*
2    Unix SMB/CIFS implementation.
3    Main metadata server / Spotlight routines / Elasticsearch backend
5    Copyright (C) Ralph Boehme                   2019
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "rpc_server/mdssvc/es_parser.tab.h"
25 #define YY_NO_INPUT
26 #define mdsyylalloc SMB_MALLOC
27 #define mdsyylrealloc SMB_REALLOC
29 static char *strip_quote(const char *phrase);
32 %option nounput noyyalloc noyyrealloc prefix="mdsyyl"
34 ASC     [a-zA-Z0-9_\*\:\-\.]
35 U       [\x80-\xbf]
36 U2      [\xc2-\xdf]
37 U3      [\xe0-\xef]
38 U4      [\xf0-\xf4]
39 SPECIAL [\!\#\$\%\&\'\(\)\+\,\.\/\;\<\=\>\?\@\[\]\^\`\{\}\|\~\\]
40 ESCHAR  [\"\*]
41 BLANK   [ \t\n]
43 UANY    {ASC}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
44 UONLY   {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
45 UPHRASE {UANY}|{SPECIAL}|{BLANK}|\\{ESCHAR}
48 InRange           return FUNC_INRANGE;
49 \$time\.iso       return DATE_ISO;
50 false             {mdsyyllval.bval = false; return BOOLEAN;}
51 true              {mdsyyllval.bval = true; return BOOLEAN;}
52 \"                return QUOTE;
53 \(                return OBRACE;
54 \)                return CBRACE;
55 \&\&              return AND;
56 \|\|              return OR;
57 \=\=              return EQUAL;
58 \!\=              return UNEQUAL;
59 \=                return EQUAL;
60 \<                return LT;
61 \>                return GT;
62 \,                return COMMA;
63 {UANY}+           {mdsyyllval.sval = talloc_strdup(talloc_tos(), yytext); return WORD;}
64 \"{UPHRASE}+\"    {mdsyyllval.sval = strip_quote(yytext); return PHRASE;}
65 {BLANK}           /* ignore */
68 static char *strip_quote(const char *phrase)
70         size_t phrase_len = 0;
71         char *stripped_phrase = NULL;
73         if (phrase == NULL) {
74                 return NULL;
75         }
77         phrase_len = strlen(phrase);
78         if (phrase_len < 2 ||
79             phrase[0] != '\"' ||
80             phrase[phrase_len - 1] != '\"')
81         {
82                 return talloc_strdup(talloc_tos(), phrase);
83         }
85         phrase++;
87         stripped_phrase = talloc_strndup(talloc_tos(), phrase, phrase_len - 2);
88         if (stripped_phrase == NULL) {
89                 return NULL;
90         }
91         return stripped_phrase;