LCOV - code coverage report
Current view: top level - bin/default/source3/rpc_server/mdssvc - es_parser.tab.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 334 630 53.0 %
Date: 2024-02-29 22:57:05 Functions: 12 18 66.7 %

          Line data    Source code
       1             : /* A Bison parser, made by GNU Bison 3.8.2.  */
       2             : 
       3             : /* Bison implementation for Yacc-like parsers in C
       4             : 
       5             :    Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
       6             :    Inc.
       7             : 
       8             :    This program is free software: you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation, either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      20             : 
      21             : /* As a special exception, you may create a larger work that contains
      22             :    part or all of the Bison parser skeleton and distribute that work
      23             :    under terms of your choice, so long as that work isn't itself a
      24             :    parser generator using the skeleton or a modified version thereof
      25             :    as a parser skeleton.  Alternatively, if you modify or redistribute
      26             :    the parser skeleton itself, you may (at your option) remove this
      27             :    special exception, which will cause the skeleton and the resulting
      28             :    Bison output files to be licensed under the GNU General Public
      29             :    License without this special exception.
      30             : 
      31             :    This special exception was added by the Free Software Foundation in
      32             :    version 2.2 of Bison.  */
      33             : 
      34             : /* C LALR(1) parser skeleton written by Richard Stallman, by
      35             :    simplifying the original so-called "semantic" parser.  */
      36             : 
      37             : /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
      38             :    especially those whose name start with YY_ or yy_.  They are
      39             :    private implementation details that can be changed or removed.  */
      40             : 
      41             : /* All symbols defined below should begin with yy or YY, to avoid
      42             :    infringing on user name space.  This should be done even for local
      43             :    variables, as they might otherwise be expanded by user macros.
      44             :    There are some unavoidable exceptions within include files to
      45             :    define necessary library symbols; they are noted "INFRINGES ON
      46             :    USER NAME SPACE" below.  */
      47             : 
      48             : /* Identify Bison output, and Bison version.  */
      49             : #define YYBISON 30802
      50             : 
      51             : /* Bison version string.  */
      52             : #define YYBISON_VERSION "3.8.2"
      53             : 
      54             : /* Skeleton name.  */
      55             : #define YYSKELETON_NAME "yacc.c"
      56             : 
      57             : /* Pure parsers.  */
      58             : #define YYPURE 0
      59             : 
      60             : /* Push parsers.  */
      61             : #define YYPUSH 0
      62             : 
      63             : /* Pull parsers.  */
      64             : #define YYPULL 1
      65             : 
      66             : 
      67             : /* Substitute the variable and function names.  */
      68             : #define yyparse         mdsyylparse
      69             : #define yylex           mdsyyllex
      70             : #define yyerror         mdsyylerror
      71             : #define yydebug         mdsyyldebug
      72             : #define yynerrs         mdsyylnerrs
      73             : #define yylval          mdsyyllval
      74             : #define yychar          mdsyylchar
      75             : 
      76             : /* First part of user prologue.  */
      77             : 
      78             :         #include "includes.h"
      79             :         #include "rpc_server/mdssvc/mdssvc.h"
      80             :         #include "rpc_server/mdssvc/mdssvc_es.h"
      81             :         #include "rpc_server/mdssvc/es_parser.tab.h"
      82             :         #include "rpc_server/mdssvc/es_mapping.h"
      83             :         #include "lib/util/smb_strtox.h"
      84             :         #include <jansson.h>
      85             : 
      86             :         /*
      87             :          * allow building with -O3 -Wp,-D_FORTIFY_SOURCE=2
      88             :          *
      89             :          * /tmp/samba-testbase/.../mdssvc/es_parser.y: In function
      90             :          * ‘mdsyylparse’:
      91             :          * es_parser.tab.c:1124:6: error: assuming pointer wraparound
      92             :          * does not occur when comparing P +- C1 with P +- C2
      93             :          * [-Werror=strict-overflow]
      94             :          *
      95             :          * The generated code in es_parser.tab.c looks like this:
      96             :          *
      97             :          *   if (yyss + yystacksize - 1 <= yyssp)
      98             :          */
      99             :         #pragma GCC diagnostic ignored "-Wstrict-overflow"
     100             : 
     101             :         #define YYMALLOC SMB_MALLOC
     102             :         #define YYREALLOC SMB_REALLOC
     103             : 
     104             :         struct yy_buffer_state;
     105             :         typedef struct yy_buffer_state *YY_BUFFER_STATE;
     106             :         int mdsyyllex(void);
     107             :         void mdsyylerror(char const *);
     108             :         void *mdsyylterminate(void);
     109             :         YY_BUFFER_STATE mdsyyl_scan_string(const char *str);
     110             :         void mdsyyl_delete_buffer(YY_BUFFER_STATE buffer);
     111             : 
     112             :         /* forward declarations */
     113             :         static char *isodate_to_sldate(const char *s);
     114             :         static char *map_expr(const struct es_attr_map *attr,
     115             :                               char op,
     116             :                               const char *val1,
     117             :                               const char *val2);
     118             : 
     119             :         /* global vars, eg needed by the lexer */
     120             :         struct es_parser_state {
     121             :                 TALLOC_CTX *frame;
     122             :                 json_t *kmd_map;
     123             :                 json_t *mime_map;
     124             :                 bool ignore_unknown_attribute;
     125             :                 bool ignore_unknown_type;
     126             :                 bool type_error;
     127             :                 YY_BUFFER_STATE s;
     128             :                 const char *result;
     129             :         } *global_es_parser_state;
     130             : 
     131             : 
     132             : # ifndef YY_CAST
     133             : #  ifdef __cplusplus
     134             : #   define YY_CAST(Type, Val) static_cast<Type> (Val)
     135             : #   define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
     136             : #  else
     137             : #   define YY_CAST(Type, Val) ((Type) (Val))
     138             : #   define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
     139             : #  endif
     140             : # endif
     141             : # ifndef YY_NULLPTR
     142             : #  if defined __cplusplus
     143             : #   if 201103L <= __cplusplus
     144             : #    define YY_NULLPTR nullptr
     145             : #   else
     146             : #    define YY_NULLPTR 0
     147             : #   endif
     148             : #  else
     149             : #   define YY_NULLPTR ((void*)0)
     150             : #  endif
     151             : # endif
     152             : 
     153             : #include "es_parser.tab.h"
     154             : /* Symbol kind.  */
     155             : enum yysymbol_kind_t
     156             : {
     157             :   YYSYMBOL_YYEMPTY = -2,
     158             :   YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
     159             :   YYSYMBOL_YYerror = 1,                    /* error  */
     160             :   YYSYMBOL_YYUNDEF = 2,                    /* "invalid token"  */
     161             :   YYSYMBOL_WORD = 3,                       /* WORD  */
     162             :   YYSYMBOL_PHRASE = 4,                     /* PHRASE  */
     163             :   YYSYMBOL_BOOLEAN = 5,                    /* BOOLEAN  */
     164             :   YYSYMBOL_FUNC_INRANGE = 6,               /* FUNC_INRANGE  */
     165             :   YYSYMBOL_DATE_ISO = 7,                   /* DATE_ISO  */
     166             :   YYSYMBOL_OBRACE = 8,                     /* OBRACE  */
     167             :   YYSYMBOL_CBRACE = 9,                     /* CBRACE  */
     168             :   YYSYMBOL_EQUAL = 10,                     /* EQUAL  */
     169             :   YYSYMBOL_UNEQUAL = 11,                   /* UNEQUAL  */
     170             :   YYSYMBOL_GT = 12,                        /* GT  */
     171             :   YYSYMBOL_LT = 13,                        /* LT  */
     172             :   YYSYMBOL_COMMA = 14,                     /* COMMA  */
     173             :   YYSYMBOL_QUOTE = 15,                     /* QUOTE  */
     174             :   YYSYMBOL_OR = 16,                        /* OR  */
     175             :   YYSYMBOL_AND = 17,                       /* AND  */
     176             :   YYSYMBOL_YYACCEPT = 18,                  /* $accept  */
     177             :   YYSYMBOL_input = 19,                     /* input  */
     178             :   YYSYMBOL_line = 20,                      /* line  */
     179             :   YYSYMBOL_expr = 21,                      /* expr  */
     180             :   YYSYMBOL_match = 22,                     /* match  */
     181             :   YYSYMBOL_function = 23,                  /* function  */
     182             :   YYSYMBOL_attribute = 24,                 /* attribute  */
     183             :   YYSYMBOL_value = 25,                     /* value  */
     184             :   YYSYMBOL_isodate = 26                    /* isodate  */
     185             : };
     186             : typedef enum yysymbol_kind_t yysymbol_kind_t;
     187             : 
     188             : 
     189             : 
     190             : 
     191             : #ifdef short
     192             : # undef short
     193             : #endif
     194             : 
     195             : /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
     196             :    <limits.h> and (if available) <stdint.h> are included
     197             :    so that the code can choose integer types of a good width.  */
     198             : 
     199             : #ifndef __PTRDIFF_MAX__
     200             : # include <limits.h> /* INFRINGES ON USER NAME SPACE */
     201             : # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
     202             : #  include <stdint.h> /* INFRINGES ON USER NAME SPACE */
     203             : #  define YY_STDINT_H
     204             : # endif
     205             : #endif
     206             : 
     207             : /* Narrow types that promote to a signed type and that can represent a
     208             :    signed or unsigned integer of at least N bits.  In tables they can
     209             :    save space and decrease cache pressure.  Promoting to a signed type
     210             :    helps avoid bugs in integer arithmetic.  */
     211             : 
     212             : #ifdef __INT_LEAST8_MAX__
     213             : typedef __INT_LEAST8_TYPE__ yytype_int8;
     214             : #elif defined YY_STDINT_H
     215             : typedef int_least8_t yytype_int8;
     216             : #else
     217             : typedef signed char yytype_int8;
     218             : #endif
     219             : 
     220             : #ifdef __INT_LEAST16_MAX__
     221             : typedef __INT_LEAST16_TYPE__ yytype_int16;
     222             : #elif defined YY_STDINT_H
     223             : typedef int_least16_t yytype_int16;
     224             : #else
     225             : typedef short yytype_int16;
     226             : #endif
     227             : 
     228             : /* Work around bug in HP-UX 11.23, which defines these macros
     229             :    incorrectly for preprocessor constants.  This workaround can likely
     230             :    be removed in 2023, as HPE has promised support for HP-UX 11.23
     231             :    (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
     232             :    <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>.  */
     233             : #ifdef __hpux
     234             : # undef UINT_LEAST8_MAX
     235             : # undef UINT_LEAST16_MAX
     236             : # define UINT_LEAST8_MAX 255
     237             : # define UINT_LEAST16_MAX 65535
     238             : #endif
     239             : 
     240             : #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
     241             : typedef __UINT_LEAST8_TYPE__ yytype_uint8;
     242             : #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
     243             :        && UINT_LEAST8_MAX <= INT_MAX)
     244             : typedef uint_least8_t yytype_uint8;
     245             : #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
     246             : typedef unsigned char yytype_uint8;
     247             : #else
     248             : typedef short yytype_uint8;
     249             : #endif
     250             : 
     251             : #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
     252             : typedef __UINT_LEAST16_TYPE__ yytype_uint16;
     253             : #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
     254             :        && UINT_LEAST16_MAX <= INT_MAX)
     255             : typedef uint_least16_t yytype_uint16;
     256             : #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
     257             : typedef unsigned short yytype_uint16;
     258             : #else
     259             : typedef int yytype_uint16;
     260             : #endif
     261             : 
     262             : #ifndef YYPTRDIFF_T
     263             : # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
     264             : #  define YYPTRDIFF_T __PTRDIFF_TYPE__
     265             : #  define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
     266             : # elif defined PTRDIFF_MAX
     267             : #  ifndef ptrdiff_t
     268             : #   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
     269             : #  endif
     270             : #  define YYPTRDIFF_T ptrdiff_t
     271             : #  define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
     272             : # else
     273             : #  define YYPTRDIFF_T long
     274             : #  define YYPTRDIFF_MAXIMUM LONG_MAX
     275             : # endif
     276             : #endif
     277             : 
     278             : #ifndef YYSIZE_T
     279             : # ifdef __SIZE_TYPE__
     280             : #  define YYSIZE_T __SIZE_TYPE__
     281             : # elif defined size_t
     282             : #  define YYSIZE_T size_t
     283             : # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
     284             : #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
     285             : #  define YYSIZE_T size_t
     286             : # else
     287             : #  define YYSIZE_T unsigned
     288             : # endif
     289             : #endif
     290             : 
     291             : #define YYSIZE_MAXIMUM                                  \
     292             :   YY_CAST (YYPTRDIFF_T,                                 \
     293             :            (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1)  \
     294             :             ? YYPTRDIFF_MAXIMUM                         \
     295             :             : YY_CAST (YYSIZE_T, -1)))
     296             : 
     297             : #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
     298             : 
     299             : 
     300             : /* Stored state numbers (used for stacks). */
     301             : typedef yytype_int8 yy_state_t;
     302             : 
     303             : /* State numbers in computations.  */
     304             : typedef int yy_state_fast_t;
     305             : 
     306             : #ifndef YY_
     307             : # if defined YYENABLE_NLS && YYENABLE_NLS
     308             : #  if ENABLE_NLS
     309             : #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
     310             : #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
     311             : #  endif
     312             : # endif
     313             : # ifndef YY_
     314             : #  define YY_(Msgid) Msgid
     315             : # endif
     316             : #endif
     317             : 
     318             : 
     319             : #ifndef YY_ATTRIBUTE_PURE
     320             : # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
     321             : #  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
     322             : # else
     323             : #  define YY_ATTRIBUTE_PURE
     324             : # endif
     325             : #endif
     326             : 
     327             : #ifndef YY_ATTRIBUTE_UNUSED
     328             : # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
     329             : #  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
     330             : # else
     331             : #  define YY_ATTRIBUTE_UNUSED
     332             : # endif
     333             : #endif
     334             : 
     335             : /* Suppress unused-variable warnings by "using" E.  */
     336             : #if ! defined lint || defined __GNUC__
     337             : # define YY_USE(E) ((void) (E))
     338             : #else
     339             : # define YY_USE(E) /* empty */
     340             : #endif
     341             : 
     342             : /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
     343             : #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
     344             : # if __GNUC__ * 100 + __GNUC_MINOR__ < 407
     345             : #  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
     346             :     _Pragma ("GCC diagnostic push")                                     \
     347             :     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
     348             : # else
     349             : #  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
     350             :     _Pragma ("GCC diagnostic push")                                     \
     351             :     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")              \
     352             :     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
     353             : # endif
     354             : # define YY_IGNORE_MAYBE_UNINITIALIZED_END      \
     355             :     _Pragma ("GCC diagnostic pop")
     356             : #else
     357             : # define YY_INITIAL_VALUE(Value) Value
     358             : #endif
     359             : #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
     360             : # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
     361             : # define YY_IGNORE_MAYBE_UNINITIALIZED_END
     362             : #endif
     363             : #ifndef YY_INITIAL_VALUE
     364             : # define YY_INITIAL_VALUE(Value) /* Nothing. */
     365             : #endif
     366             : 
     367             : #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
     368             : # define YY_IGNORE_USELESS_CAST_BEGIN                          \
     369             :     _Pragma ("GCC diagnostic push")                            \
     370             :     _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
     371             : # define YY_IGNORE_USELESS_CAST_END            \
     372             :     _Pragma ("GCC diagnostic pop")
     373             : #endif
     374             : #ifndef YY_IGNORE_USELESS_CAST_BEGIN
     375             : # define YY_IGNORE_USELESS_CAST_BEGIN
     376             : # define YY_IGNORE_USELESS_CAST_END
     377             : #endif
     378             : 
     379             : 
     380             : #define YY_ASSERT(E) ((void) (0 && (E)))
     381             : 
     382             : #if 1
     383             : 
     384             : /* The parser invokes alloca or malloc; define the necessary symbols.  */
     385             : 
     386             : # ifdef YYSTACK_USE_ALLOCA
     387             : #  if YYSTACK_USE_ALLOCA
     388             : #   ifdef __GNUC__
     389             : #    define YYSTACK_ALLOC __builtin_alloca
     390             : #   elif defined __BUILTIN_VA_ARG_INCR
     391             : #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
     392             : #   elif defined _AIX
     393             : #    define YYSTACK_ALLOC __alloca
     394             : #   elif defined _MSC_VER
     395             : #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
     396             : #    define alloca _alloca
     397             : #   else
     398             : #    define YYSTACK_ALLOC alloca
     399             : #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
     400             : #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
     401             :       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
     402             : #     ifndef EXIT_SUCCESS
     403             : #      define EXIT_SUCCESS 0
     404             : #     endif
     405             : #    endif
     406             : #   endif
     407             : #  endif
     408             : # endif
     409             : 
     410             : # ifdef YYSTACK_ALLOC
     411             :    /* Pacify GCC's 'empty if-body' warning.  */
     412             : #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
     413             : #  ifndef YYSTACK_ALLOC_MAXIMUM
     414             :     /* The OS might guarantee only one guard page at the bottom of the stack,
     415             :        and a page size can be as small as 4096 bytes.  So we cannot safely
     416             :        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
     417             :        to allow for a few compiler-allocated temporary stack slots.  */
     418             : #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
     419             : #  endif
     420             : # else
     421             : #  define YYSTACK_ALLOC YYMALLOC
     422             : #  define YYSTACK_FREE YYFREE
     423             : #  ifndef YYSTACK_ALLOC_MAXIMUM
     424             : #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
     425             : #  endif
     426             : #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
     427             :        && ! ((defined YYMALLOC || defined malloc) \
     428             :              && (defined YYFREE || defined free)))
     429             : #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
     430             : #   ifndef EXIT_SUCCESS
     431             : #    define EXIT_SUCCESS 0
     432             : #   endif
     433             : #  endif
     434             : #  ifndef YYMALLOC
     435             : #   define YYMALLOC malloc
     436             : #   if ! defined malloc && ! defined EXIT_SUCCESS
     437             : void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
     438             : #   endif
     439             : #  endif
     440             : #  ifndef YYFREE
     441             : #   define YYFREE free
     442             : #   if ! defined free && ! defined EXIT_SUCCESS
     443             : void free (void *); /* INFRINGES ON USER NAME SPACE */
     444             : #   endif
     445             : #  endif
     446             : # endif
     447             : #endif /* 1 */
     448             : 
     449             : #if (! defined yyoverflow \
     450             :      && (! defined __cplusplus \
     451             :          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
     452             : 
     453             : /* A type that is properly aligned for any stack member.  */
     454             : union yyalloc
     455             : {
     456             :   yy_state_t yyss_alloc;
     457             :   YYSTYPE yyvs_alloc;
     458             : };
     459             : 
     460             : /* The size of the maximum gap between one aligned stack and the next.  */
     461             : # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
     462             : 
     463             : /* The size of an array large to enough to hold all stacks, each with
     464             :    N elements.  */
     465             : # define YYSTACK_BYTES(N) \
     466             :      ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
     467             :       + YYSTACK_GAP_MAXIMUM)
     468             : 
     469             : # define YYCOPY_NEEDED 1
     470             : 
     471             : /* Relocate STACK from its old location to the new one.  The
     472             :    local variables YYSIZE and YYSTACKSIZE give the old and new number of
     473             :    elements in the stack, and YYPTR gives the new location of the
     474             :    stack.  Advance YYPTR to a properly aligned location for the next
     475             :    stack.  */
     476             : # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
     477             :     do                                                                  \
     478             :       {                                                                 \
     479             :         YYPTRDIFF_T yynewbytes;                                         \
     480             :         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
     481             :         Stack = &yyptr->Stack_alloc;                                    \
     482             :         yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
     483             :         yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
     484             :       }                                                                 \
     485             :     while (0)
     486             : 
     487             : #endif
     488             : 
     489             : #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
     490             : /* Copy COUNT objects from SRC to DST.  The source and destination do
     491             :    not overlap.  */
     492             : # ifndef YYCOPY
     493             : #  if defined __GNUC__ && 1 < __GNUC__
     494             : #   define YYCOPY(Dst, Src, Count) \
     495             :       __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
     496             : #  else
     497             : #   define YYCOPY(Dst, Src, Count)              \
     498             :       do                                        \
     499             :         {                                       \
     500             :           YYPTRDIFF_T yyi;                      \
     501             :           for (yyi = 0; yyi < (Count); yyi++)   \
     502             :             (Dst)[yyi] = (Src)[yyi];            \
     503             :         }                                       \
     504             :       while (0)
     505             : #  endif
     506             : # endif
     507             : #endif /* !YYCOPY_NEEDED */
     508             : 
     509             : /* YYFINAL -- State number of the termination state.  */
     510             : #define YYFINAL  2
     511             : /* YYLAST -- Last index in YYTABLE.  */
     512             : #define YYLAST   38
     513             : 
     514             : /* YYNTOKENS -- Number of terminals.  */
     515             : #define YYNTOKENS  18
     516             : /* YYNNTS -- Number of nonterminals.  */
     517             : #define YYNNTS  9
     518             : /* YYNRULES -- Number of rules.  */
     519             : #define YYNRULES  20
     520             : /* YYNSTATES -- Number of states.  */
     521             : #define YYNSTATES  40
     522             : 
     523             : /* YYMAXUTOK -- Last valid token kind.  */
     524             : #define YYMAXUTOK   272
     525             : 
     526             : 
     527             : /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
     528             :    as returned by yylex, with out-of-bounds checking.  */
     529             : #define YYTRANSLATE(YYX)                                \
     530             :   (0 <= (YYX) && (YYX) <= YYMAXUTOK                     \
     531             :    ? YY_CAST (yysymbol_kind_t, yytranslate[YYX])        \
     532             :    : YYSYMBOL_YYUNDEF)
     533             : 
     534             : /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
     535             :    as returned by yylex.  */
     536             : static const yytype_int8 yytranslate[] =
     537             : {
     538             :        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     539             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     540             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     541             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     542             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     543             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     544             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     545             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     546             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     547             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     548             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     549             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     550             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     551             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     552             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     553             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     554             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     555             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     556             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     557             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     558             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     559             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     560             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     561             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     562             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     563             :        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
     564             :        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
     565             :       15,    16,    17
     566             : };
     567             : 
     568             : #if YYDEBUG
     569             : /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
     570             : static const yytype_uint8 yyrline[] =
     571             : {
     572             :        0,   114,   114,   116,   120,   132,   140,   152,   164,   167,
     573             :      180,   187,   194,   201,   208,   211,   216,   225,   237,   240,
     574             :      245
     575             : };
     576             : #endif
     577             : 
     578             : /** Accessing symbol of state STATE.  */
     579             : #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
     580             : 
     581             : #if 1
     582             : /* The user-facing name of the symbol whose (internal) number is
     583             :    YYSYMBOL.  No bounds checking.  */
     584             : static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
     585             : 
     586             : /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
     587             :    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
     588             : static const char *const yytname[] =
     589             : {
     590             :   "\"end of file\"", "error", "\"invalid token\"", "WORD", "PHRASE",
     591             :   "BOOLEAN", "FUNC_INRANGE", "DATE_ISO", "OBRACE", "CBRACE", "EQUAL",
     592             :   "UNEQUAL", "GT", "LT", "COMMA", "QUOTE", "OR", "AND", "$accept", "input",
     593             :   "line", "expr", "match", "function", "attribute", "value", "isodate", YY_NULLPTR
     594             : };
     595             : 
     596             : static const char *
     597           0 : yysymbol_name (yysymbol_kind_t yysymbol)
     598             : {
     599           0 :   return yytname[yysymbol];
     600             : }
     601             : #endif
     602             : 
     603             : #define YYPACT_NINF (-7)
     604             : 
     605             : #define yypact_value_is_default(Yyn) \
     606             :   ((Yyn) == YYPACT_NINF)
     607             : 
     608             : #define YYTABLE_NINF (-1)
     609             : 
     610             : #define yytable_value_is_error(Yyn) \
     611             :   0
     612             : 
     613             : /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
     614             :    STATE-NUM.  */
     615             : static const yytype_int8 yypact[] =
     616             : {
     617             :       -7,     7,    -7,    -7,    -7,    -3,    -2,    -7,     0,    -1,
     618             :       -7,    10,    22,     2,    -2,    -2,    -7,    20,    20,    20,
     619             :       20,    12,    -7,    15,    -7,    -7,     6,    -7,    -7,    -7,
     620             :       -7,    -7,    25,    30,    21,    27,    31,    -7,    28,    -7
     621             : };
     622             : 
     623             : /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
     624             :    Performed when YYTABLE does not specify something else to do.  Zero
     625             :    means the default is an error.  */
     626             : static const yytype_int8 yydefact[] =
     627             : {
     628             :        2,     0,     1,    17,     9,     0,     0,     3,     4,     8,
     629             :       14,     0,     0,     0,     0,     0,    15,     0,     0,     0,
     630             :        0,     0,     5,     7,     6,    18,     0,    10,    19,    11,
     631             :       13,    12,     0,     0,     0,     0,     0,    20,     0,    16
     632             : };
     633             : 
     634             : /* YYPGOTO[NTERM-NUM].  */
     635             : static const yytype_int8 yypgoto[] =
     636             : {
     637             :       -7,    -7,    -7,    -6,    -7,    -7,    26,    11,    -7
     638             : };
     639             : 
     640             : /* YYDEFGOTO[NTERM-NUM].  */
     641             : static const yytype_int8 yydefgoto[] =
     642             : {
     643             :        0,     1,     7,     8,     9,    10,    11,    27,    28
     644             : };
     645             : 
     646             : /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
     647             :    positive, shift that token.  If negative, reduce the rule whose
     648             :    number is the opposite.  If YYTABLE_NINF, syntax error.  */
     649             : static const yytype_int8 yytable[] =
     650             : {
     651             :       13,     3,    16,     4,     5,    12,     6,     2,    23,    24,
     652             :        3,    22,     4,     5,    33,     6,    14,    15,    14,    15,
     653             :       17,    18,    19,    20,    25,     3,    32,    26,    34,    29,
     654             :       30,    31,    15,    35,    38,    36,    37,    39,    21
     655             : };
     656             : 
     657             : static const yytype_int8 yycheck[] =
     658             : {
     659             :        6,     3,     3,     5,     6,     8,     8,     0,    14,    15,
     660             :        3,     9,     5,     6,     8,     8,    16,    17,    16,    17,
     661             :       10,    11,    12,    13,     4,     3,    14,     7,     3,    18,
     662             :       19,    20,    17,     3,     3,    14,     9,     9,    12
     663             : };
     664             : 
     665             : /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
     666             :    state STATE-NUM.  */
     667             : static const yytype_int8 yystos[] =
     668             : {
     669             :        0,    19,     0,     3,     5,     6,     8,    20,    21,    22,
     670             :       23,    24,     8,    21,    16,    17,     3,    10,    11,    12,
     671             :       13,    24,     9,    21,    21,     4,     7,    25,    26,    25,
     672             :       25,    25,    14,     8,     3,     3,    14,     9,     3,     9
     673             : };
     674             : 
     675             : /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.  */
     676             : static const yytype_int8 yyr1[] =
     677             : {
     678             :        0,    18,    19,    19,    20,    21,    21,    21,    21,    21,
     679             :       22,    22,    22,    22,    22,    22,    23,    24,    25,    25,
     680             :       26
     681             : };
     682             : 
     683             : /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.  */
     684             : static const yytype_int8 yyr2[] =
     685             : {
     686             :        0,     2,     0,     2,     1,     3,     3,     3,     1,     1,
     687             :        3,     3,     3,     3,     1,     2,     8,     1,     1,     1,
     688             :        4
     689             : };
     690             : 
     691             : 
     692             : enum { YYENOMEM = -2 };
     693             : 
     694             : #define yyerrok         (yyerrstatus = 0)
     695             : #define yyclearin       (yychar = YYEMPTY)
     696             : 
     697             : #define YYACCEPT        goto yyacceptlab
     698             : #define YYABORT         goto yyabortlab
     699             : #define YYERROR         goto yyerrorlab
     700             : #define YYNOMEM         goto yyexhaustedlab
     701             : 
     702             : 
     703             : #define YYRECOVERING()  (!!yyerrstatus)
     704             : 
     705             : #define YYBACKUP(Token, Value)                                    \
     706             :   do                                                              \
     707             :     if (yychar == YYEMPTY)                                        \
     708             :       {                                                           \
     709             :         yychar = (Token);                                         \
     710             :         yylval = (Value);                                         \
     711             :         YYPOPSTACK (yylen);                                       \
     712             :         yystate = *yyssp;                                         \
     713             :         goto yybackup;                                            \
     714             :       }                                                           \
     715             :     else                                                          \
     716             :       {                                                           \
     717             :         yyerror (YY_("syntax error: cannot back up")); \
     718             :         YYERROR;                                                  \
     719             :       }                                                           \
     720             :   while (0)
     721             : 
     722             : /* Backward compatibility with an undocumented macro.
     723             :    Use YYerror or YYUNDEF. */
     724             : #define YYERRCODE YYUNDEF
     725             : 
     726             : 
     727             : /* Enable debugging if requested.  */
     728             : #if YYDEBUG
     729             : 
     730             : # ifndef YYFPRINTF
     731             : #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
     732             : #  define YYFPRINTF fprintf
     733             : # endif
     734             : 
     735             : # define YYDPRINTF(Args)                        \
     736             : do {                                            \
     737             :   if (yydebug)                                  \
     738             :     YYFPRINTF Args;                             \
     739             : } while (0)
     740             : 
     741             : 
     742             : 
     743             : 
     744             : # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                    \
     745             : do {                                                                      \
     746             :   if (yydebug)                                                            \
     747             :     {                                                                     \
     748             :       YYFPRINTF (stderr, "%s ", Title);                                   \
     749             :       yy_symbol_print (stderr,                                            \
     750             :                   Kind, Value); \
     751             :       YYFPRINTF (stderr, "\n");                                           \
     752             :     }                                                                     \
     753             : } while (0)
     754             : 
     755             : 
     756             : /*-----------------------------------.
     757             : | Print this symbol's value on YYO.  |
     758             : `-----------------------------------*/
     759             : 
     760             : static void
     761             : yy_symbol_value_print (FILE *yyo,
     762             :                        yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
     763             : {
     764             :   FILE *yyoutput = yyo;
     765             :   YY_USE (yyoutput);
     766             :   if (!yyvaluep)
     767             :     return;
     768             :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
     769             :   YY_USE (yykind);
     770             :   YY_IGNORE_MAYBE_UNINITIALIZED_END
     771             : }
     772             : 
     773             : 
     774             : /*---------------------------.
     775             : | Print this symbol on YYO.  |
     776             : `---------------------------*/
     777             : 
     778             : static void
     779             : yy_symbol_print (FILE *yyo,
     780             :                  yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
     781             : {
     782             :   YYFPRINTF (yyo, "%s %s (",
     783             :              yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
     784             : 
     785             :   yy_symbol_value_print (yyo, yykind, yyvaluep);
     786             :   YYFPRINTF (yyo, ")");
     787             : }
     788             : 
     789             : /*------------------------------------------------------------------.
     790             : | yy_stack_print -- Print the state stack from its BOTTOM up to its |
     791             : | TOP (included).                                                   |
     792             : `------------------------------------------------------------------*/
     793             : 
     794             : static void
     795             : yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
     796             : {
     797             :   YYFPRINTF (stderr, "Stack now");
     798             :   for (; yybottom <= yytop; yybottom++)
     799             :     {
     800             :       int yybot = *yybottom;
     801             :       YYFPRINTF (stderr, " %d", yybot);
     802             :     }
     803             :   YYFPRINTF (stderr, "\n");
     804             : }
     805             : 
     806             : # define YY_STACK_PRINT(Bottom, Top)                            \
     807             : do {                                                            \
     808             :   if (yydebug)                                                  \
     809             :     yy_stack_print ((Bottom), (Top));                           \
     810             : } while (0)
     811             : 
     812             : 
     813             : /*------------------------------------------------.
     814             : | Report that the YYRULE is going to be reduced.  |
     815             : `------------------------------------------------*/
     816             : 
     817             : static void
     818             : yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
     819             :                  int yyrule)
     820             : {
     821             :   int yylno = yyrline[yyrule];
     822             :   int yynrhs = yyr2[yyrule];
     823             :   int yyi;
     824             :   YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
     825             :              yyrule - 1, yylno);
     826             :   /* The symbols being reduced.  */
     827             :   for (yyi = 0; yyi < yynrhs; yyi++)
     828             :     {
     829             :       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
     830             :       yy_symbol_print (stderr,
     831             :                        YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
     832             :                        &yyvsp[(yyi + 1) - (yynrhs)]);
     833             :       YYFPRINTF (stderr, "\n");
     834             :     }
     835             : }
     836             : 
     837             : # define YY_REDUCE_PRINT(Rule)          \
     838             : do {                                    \
     839             :   if (yydebug)                          \
     840             :     yy_reduce_print (yyssp, yyvsp, Rule); \
     841             : } while (0)
     842             : 
     843             : /* Nonzero means print parse trace.  It is left uninitialized so that
     844             :    multiple parsers can coexist.  */
     845             : int yydebug;
     846             : #else /* !YYDEBUG */
     847             : # define YYDPRINTF(Args) ((void) 0)
     848             : # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
     849             : # define YY_STACK_PRINT(Bottom, Top)
     850             : # define YY_REDUCE_PRINT(Rule)
     851             : #endif /* !YYDEBUG */
     852             : 
     853             : 
     854             : /* YYINITDEPTH -- initial size of the parser's stacks.  */
     855             : #ifndef YYINITDEPTH
     856             : # define YYINITDEPTH 200
     857             : #endif
     858             : 
     859             : /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
     860             :    if the built-in stack extension method is used).
     861             : 
     862             :    Do not make this value too large; the results are undefined if
     863             :    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
     864             :    evaluated with infinite-precision integer arithmetic.  */
     865             : 
     866             : #ifndef YYMAXDEPTH
     867             : # define YYMAXDEPTH 10000
     868             : #endif
     869             : 
     870             : 
     871             : /* Context of a parse error.  */
     872             : typedef struct
     873             : {
     874             :   yy_state_t *yyssp;
     875             :   yysymbol_kind_t yytoken;
     876             : } yypcontext_t;
     877             : 
     878             : /* Put in YYARG at most YYARGN of the expected tokens given the
     879             :    current YYCTX, and return the number of tokens stored in YYARG.  If
     880             :    YYARG is null, return the number of expected tokens (guaranteed to
     881             :    be less than YYNTOKENS).  Return YYENOMEM on memory exhaustion.
     882             :    Return 0 if there are more than YYARGN expected tokens, yet fill
     883             :    YYARG up to YYARGN. */
     884             : static int
     885           0 : yypcontext_expected_tokens (const yypcontext_t *yyctx,
     886             :                             yysymbol_kind_t yyarg[], int yyargn)
     887             : {
     888             :   /* Actual size of YYARG. */
     889           0 :   int yycount = 0;
     890           0 :   int yyn = yypact[+*yyctx->yyssp];
     891           0 :   if (!yypact_value_is_default (yyn))
     892             :     {
     893             :       /* Start YYX at -YYN if negative to avoid negative indexes in
     894             :          YYCHECK.  In other words, skip the first -YYN actions for
     895             :          this state because they are default actions.  */
     896           0 :       int yyxbegin = yyn < 0 ? -yyn : 0;
     897             :       /* Stay within bounds of both yycheck and yytname.  */
     898           0 :       int yychecklim = YYLAST - yyn + 1;
     899           0 :       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
     900           0 :       int yyx;
     901           0 :       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
     902           0 :         if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYerror
     903           0 :             && !yytable_value_is_error (yytable[yyx + yyn]))
     904             :           {
     905           0 :             if (!yyarg)
     906           0 :               ++yycount;
     907           0 :             else if (yycount == yyargn)
     908           0 :               return 0;
     909             :             else
     910           0 :               yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx);
     911             :           }
     912             :     }
     913           0 :   if (yyarg && yycount == 0 && 0 < yyargn)
     914           0 :     yyarg[0] = YYSYMBOL_YYEMPTY;
     915           0 :   return yycount;
     916             : }
     917             : 
     918             : 
     919             : 
     920             : 
     921             : #ifndef yystrlen
     922             : # if defined __GLIBC__ && defined _STRING_H
     923             : #  define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
     924             : # else
     925             : /* Return the length of YYSTR.  */
     926             : static YYPTRDIFF_T
     927             : yystrlen (const char *yystr)
     928             : {
     929             :   YYPTRDIFF_T yylen;
     930             :   for (yylen = 0; yystr[yylen]; yylen++)
     931             :     continue;
     932             :   return yylen;
     933             : }
     934             : # endif
     935             : #endif
     936             : 
     937             : #ifndef yystpcpy
     938             : # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
     939             : #  define yystpcpy stpcpy
     940             : # else
     941             : /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
     942             :    YYDEST.  */
     943             : static char *
     944             : yystpcpy (char *yydest, const char *yysrc)
     945             : {
     946             :   char *yyd = yydest;
     947             :   const char *yys = yysrc;
     948             : 
     949             :   while ((*yyd++ = *yys++) != '\0')
     950             :     continue;
     951             : 
     952             :   return yyd - 1;
     953             : }
     954             : # endif
     955             : #endif
     956             : 
     957             : #ifndef yytnamerr
     958             : /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
     959             :    quotes and backslashes, so that it's suitable for yyerror.  The
     960             :    heuristic is that double-quoting is unnecessary unless the string
     961             :    contains an apostrophe, a comma, or backslash (other than
     962             :    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
     963             :    null, do not copy; instead, return the length of what the result
     964             :    would have been.  */
     965             : static YYPTRDIFF_T
     966           0 : yytnamerr (char *yyres, const char *yystr)
     967             : {
     968           0 :   if (*yystr == '"')
     969             :     {
     970           0 :       YYPTRDIFF_T yyn = 0;
     971           0 :       char const *yyp = yystr;
     972           0 :       for (;;)
     973           0 :         switch (*++yyp)
     974             :           {
     975           0 :           case '\'':
     976             :           case ',':
     977           0 :             goto do_not_strip_quotes;
     978             : 
     979           0 :           case '\\':
     980           0 :             if (*++yyp != '\\')
     981           0 :               goto do_not_strip_quotes;
     982             :             else
     983           0 :               goto append;
     984             : 
     985           0 :           append:
     986           0 :           default:
     987           0 :             if (yyres)
     988           0 :               yyres[yyn] = *yyp;
     989           0 :             yyn++;
     990           0 :             break;
     991             : 
     992           0 :           case '"':
     993           0 :             if (yyres)
     994           0 :               yyres[yyn] = '\0';
     995           0 :             return yyn;
     996             :           }
     997           0 :     do_not_strip_quotes: ;
     998             :     }
     999             : 
    1000           0 :   if (yyres)
    1001           0 :     return yystpcpy (yyres, yystr) - yyres;
    1002             :   else
    1003           0 :     return yystrlen (yystr);
    1004             : }
    1005             : #endif
    1006             : 
    1007             : 
    1008             : static int
    1009           0 : yy_syntax_error_arguments (const yypcontext_t *yyctx,
    1010             :                            yysymbol_kind_t yyarg[], int yyargn)
    1011             : {
    1012             :   /* Actual size of YYARG. */
    1013           0 :   int yycount = 0;
    1014             :   /* There are many possibilities here to consider:
    1015             :      - If this state is a consistent state with a default action, then
    1016             :        the only way this function was invoked is if the default action
    1017             :        is an error action.  In that case, don't check for expected
    1018             :        tokens because there are none.
    1019             :      - The only way there can be no lookahead present (in yychar) is if
    1020             :        this state is a consistent state with a default action.  Thus,
    1021             :        detecting the absence of a lookahead is sufficient to determine
    1022             :        that there is no unexpected or expected token to report.  In that
    1023             :        case, just report a simple "syntax error".
    1024             :      - Don't assume there isn't a lookahead just because this state is a
    1025             :        consistent state with a default action.  There might have been a
    1026             :        previous inconsistent state, consistent state with a non-default
    1027             :        action, or user semantic action that manipulated yychar.
    1028             :      - Of course, the expected token list depends on states to have
    1029             :        correct lookahead information, and it depends on the parser not
    1030             :        to perform extra reductions after fetching a lookahead from the
    1031             :        scanner and before detecting a syntax error.  Thus, state merging
    1032             :        (from LALR or IELR) and default reductions corrupt the expected
    1033             :        token list.  However, the list is correct for canonical LR with
    1034             :        one exception: it will still contain any token that will not be
    1035             :        accepted due to an error action in a later state.
    1036             :   */
    1037           0 :   if (yyctx->yytoken != YYSYMBOL_YYEMPTY)
    1038             :     {
    1039           0 :       int yyn;
    1040           0 :       if (yyarg)
    1041           0 :         yyarg[yycount] = yyctx->yytoken;
    1042           0 :       ++yycount;
    1043           0 :       yyn = yypcontext_expected_tokens (yyctx,
    1044             :                                         yyarg ? yyarg + 1 : yyarg, yyargn - 1);
    1045           0 :       if (yyn == YYENOMEM)
    1046           0 :         return YYENOMEM;
    1047             :       else
    1048           0 :         yycount += yyn;
    1049             :     }
    1050           0 :   return yycount;
    1051             : }
    1052             : 
    1053             : /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
    1054             :    about the unexpected token YYTOKEN for the state stack whose top is
    1055             :    YYSSP.
    1056             : 
    1057             :    Return 0 if *YYMSG was successfully written.  Return -1 if *YYMSG is
    1058             :    not large enough to hold the message.  In that case, also set
    1059             :    *YYMSG_ALLOC to the required number of bytes.  Return YYENOMEM if the
    1060             :    required number of bytes is too large to store.  */
    1061             : static int
    1062           0 : yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
    1063             :                 const yypcontext_t *yyctx)
    1064             : {
    1065           0 :   enum { YYARGS_MAX = 5 };
    1066             :   /* Internationalized format string. */
    1067           0 :   const char *yyformat = YY_NULLPTR;
    1068             :   /* Arguments of yyformat: reported tokens (one for the "unexpected",
    1069             :      one per "expected"). */
    1070           0 :   yysymbol_kind_t yyarg[YYARGS_MAX];
    1071             :   /* Cumulated lengths of YYARG.  */
    1072           0 :   YYPTRDIFF_T yysize = 0;
    1073             : 
    1074             :   /* Actual size of YYARG. */
    1075           0 :   int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX);
    1076           0 :   if (yycount == YYENOMEM)
    1077           0 :     return YYENOMEM;
    1078             : 
    1079           0 :   switch (yycount)
    1080             :     {
    1081             : #define YYCASE_(N, S)                       \
    1082             :       case N:                               \
    1083             :         yyformat = S;                       \
    1084             :         break
    1085           0 :     default: /* Avoid compiler warnings. */
    1086           0 :       YYCASE_(0, YY_("syntax error"));
    1087           0 :       YYCASE_(1, YY_("syntax error, unexpected %s"));
    1088           0 :       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
    1089           0 :       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
    1090           0 :       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
    1091           0 :       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
    1092             : #undef YYCASE_
    1093             :     }
    1094             : 
    1095             :   /* Compute error message size.  Don't count the "%s"s, but reserve
    1096             :      room for the terminator.  */
    1097           0 :   yysize = yystrlen (yyformat) - 2 * yycount + 1;
    1098             :   {
    1099           0 :     int yyi;
    1100           0 :     for (yyi = 0; yyi < yycount; ++yyi)
    1101             :       {
    1102           0 :         YYPTRDIFF_T yysize1
    1103           0 :           = yysize + yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]]);
    1104           0 :         if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
    1105           0 :           yysize = yysize1;
    1106             :         else
    1107           0 :           return YYENOMEM;
    1108             :       }
    1109             :   }
    1110             : 
    1111           0 :   if (*yymsg_alloc < yysize)
    1112             :     {
    1113           0 :       *yymsg_alloc = 2 * yysize;
    1114           0 :       if (! (yysize <= *yymsg_alloc
    1115             :              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
    1116           0 :         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
    1117           0 :       return -1;
    1118             :     }
    1119             : 
    1120             :   /* Avoid sprintf, as that infringes on the user's name space.
    1121             :      Don't have undefined behavior even if the translation
    1122             :      produced a string with the wrong number of "%s"s.  */
    1123             :   {
    1124           0 :     char *yyp = *yymsg;
    1125           0 :     int yyi = 0;
    1126           0 :     while ((*yyp = *yyformat) != '\0')
    1127           0 :       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
    1128             :         {
    1129           0 :           yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);
    1130           0 :           yyformat += 2;
    1131             :         }
    1132             :       else
    1133             :         {
    1134           0 :           ++yyp;
    1135           0 :           ++yyformat;
    1136             :         }
    1137             :   }
    1138           0 :   return 0;
    1139             : }
    1140             : 
    1141             : 
    1142             : /*-----------------------------------------------.
    1143             : | Release the memory associated to this symbol.  |
    1144             : `-----------------------------------------------*/
    1145             : 
    1146             : static void
    1147           4 : yydestruct (const char *yymsg,
    1148             :             yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
    1149             : {
    1150             :   YY_USE (yyvaluep);
    1151           4 :   if (!yymsg)
    1152           0 :     yymsg = "Deleting";
    1153             :   YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
    1154             : 
    1155             :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    1156             :   YY_USE (yykind);
    1157             :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    1158           4 : }
    1159             : 
    1160             : 
    1161             : /* Lookahead token kind.  */
    1162             : int yychar;
    1163             : 
    1164             : /* The semantic value of the lookahead symbol.  */
    1165             : YYSTYPE yylval;
    1166             : /* Number of syntax errors so far.  */
    1167             : int yynerrs;
    1168             : 
    1169             : 
    1170             : 
    1171             : 
    1172             : /*----------.
    1173             : | yyparse.  |
    1174             : `----------*/
    1175             : 
    1176             : int
    1177          93 : yyparse (void)
    1178             : {
    1179          93 :     yy_state_fast_t yystate = 0;
    1180             :     /* Number of tokens to shift before error messages enabled.  */
    1181          93 :     int yyerrstatus = 0;
    1182             : 
    1183             :     /* Refer to the stacks through separate pointers, to allow yyoverflow
    1184             :        to reallocate them elsewhere.  */
    1185             : 
    1186             :     /* Their size.  */
    1187          93 :     YYPTRDIFF_T yystacksize = YYINITDEPTH;
    1188             : 
    1189             :     /* The state stack: array, bottom, top.  */
    1190          91 :     yy_state_t yyssa[YYINITDEPTH];
    1191          93 :     yy_state_t *yyss = yyssa;
    1192          93 :     yy_state_t *yyssp = yyss;
    1193             : 
    1194             :     /* The semantic value stack: array, bottom, top.  */
    1195          91 :     YYSTYPE yyvsa[YYINITDEPTH];
    1196          93 :     YYSTYPE *yyvs = yyvsa;
    1197          93 :     YYSTYPE *yyvsp = yyvs;
    1198             : 
    1199          91 :   int yyn;
    1200             :   /* The return value of yyparse.  */
    1201          91 :   int yyresult;
    1202             :   /* Lookahead symbol kind.  */
    1203          93 :   yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
    1204             :   /* The variables used to return semantic value and location from the
    1205             :      action routines.  */
    1206          91 :   YYSTYPE yyval;
    1207             : 
    1208             :   /* Buffer for error messages, and its allocated size.  */
    1209          91 :   char yymsgbuf[128];
    1210          93 :   char *yymsg = yymsgbuf;
    1211          93 :   YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
    1212             : 
    1213             : #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
    1214             : 
    1215             :   /* The number of symbols on the RHS of the reduced rule.
    1216             :      Keep to zero when no symbol should be popped.  */
    1217          93 :   int yylen = 0;
    1218             : 
    1219          91 :   YYDPRINTF ((stderr, "Starting parse\n"));
    1220             : 
    1221          93 :   yychar = YYEMPTY; /* Cause a token to be read.  */
    1222             : 
    1223          93 :   goto yysetstate;
    1224             : 
    1225             : 
    1226             : /*------------------------------------------------------------.
    1227             : | yynewstate -- push a new state, which is found in yystate.  |
    1228             : `------------------------------------------------------------*/
    1229        1213 : yynewstate:
    1230             :   /* In all cases, when you get here, the value and location stacks
    1231             :      have just been pushed.  So pushing a state here evens the stacks.  */
    1232        1213 :   yyssp++;
    1233             : 
    1234             : 
    1235             : /*--------------------------------------------------------------------.
    1236             : | yysetstate -- set current state (the top of the stack) to yystate.  |
    1237             : `--------------------------------------------------------------------*/
    1238        1306 : yysetstate:
    1239        1282 :   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
    1240        1282 :   YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
    1241             :   YY_IGNORE_USELESS_CAST_BEGIN
    1242        1306 :   *yyssp = YY_CAST (yy_state_t, yystate);
    1243             :   YY_IGNORE_USELESS_CAST_END
    1244        1282 :   YY_STACK_PRINT (yyss, yyssp);
    1245             : 
    1246        1306 :   if (yyss + yystacksize - 1 <= yyssp)
    1247             : #if !defined yyoverflow && !defined YYSTACK_RELOCATE
    1248             :     YYNOMEM;
    1249             : #else
    1250             :     {
    1251             :       /* Get the current used size of the three stacks, in elements.  */
    1252           0 :       YYPTRDIFF_T yysize = yyssp - yyss + 1;
    1253             : 
    1254             : # if defined yyoverflow
    1255             :       {
    1256             :         /* Give user a chance to reallocate the stack.  Use copies of
    1257             :            these so that the &'s don't force the real ones into
    1258             :            memory.  */
    1259             :         yy_state_t *yyss1 = yyss;
    1260             :         YYSTYPE *yyvs1 = yyvs;
    1261             : 
    1262             :         /* Each stack pointer address is followed by the size of the
    1263             :            data in use in that stack, in bytes.  This used to be a
    1264             :            conditional around just the two extra args, but that might
    1265             :            be undefined if yyoverflow is a macro.  */
    1266             :         yyoverflow (YY_("memory exhausted"),
    1267             :                     &yyss1, yysize * YYSIZEOF (*yyssp),
    1268             :                     &yyvs1, yysize * YYSIZEOF (*yyvsp),
    1269             :                     &yystacksize);
    1270             :         yyss = yyss1;
    1271             :         yyvs = yyvs1;
    1272             :       }
    1273             : # else /* defined YYSTACK_RELOCATE */
    1274             :       /* Extend the stack our own way.  */
    1275           0 :       if (YYMAXDEPTH <= yystacksize)
    1276           0 :         YYNOMEM;
    1277           0 :       yystacksize *= 2;
    1278           0 :       if (YYMAXDEPTH < yystacksize)
    1279           0 :         yystacksize = YYMAXDEPTH;
    1280             : 
    1281             :       {
    1282           0 :         yy_state_t *yyss1 = yyss;
    1283           0 :         union yyalloc *yyptr =
    1284           0 :           YY_CAST (union yyalloc *,
    1285             :                    YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
    1286           0 :         if (! yyptr)
    1287           0 :           YYNOMEM;
    1288           0 :         YYSTACK_RELOCATE (yyss_alloc, yyss);
    1289           0 :         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
    1290             : #  undef YYSTACK_RELOCATE
    1291           0 :         if (yyss1 != yyssa)
    1292           0 :           YYSTACK_FREE (yyss1);
    1293             :       }
    1294             : # endif
    1295             : 
    1296           0 :       yyssp = yyss + yysize - 1;
    1297           0 :       yyvsp = yyvs + yysize - 1;
    1298             : 
    1299             :       YY_IGNORE_USELESS_CAST_BEGIN
    1300           0 :       YYDPRINTF ((stderr, "Stack size increased to %ld\n",
    1301             :                   YY_CAST (long, yystacksize)));
    1302             :       YY_IGNORE_USELESS_CAST_END
    1303             : 
    1304           0 :       if (yyss + yystacksize - 1 <= yyssp)
    1305           0 :         YYABORT;
    1306             :     }
    1307             : #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
    1308             : 
    1309             : 
    1310        1306 :   if (yystate == YYFINAL)
    1311          93 :     YYACCEPT;
    1312             : 
    1313        1213 :   goto yybackup;
    1314             : 
    1315             : 
    1316             : /*-----------.
    1317             : | yybackup.  |
    1318             : `-----------*/
    1319        1213 : yybackup:
    1320             :   /* Do appropriate processing given the current state.  Read a
    1321             :      lookahead token if we need one and don't already have one.  */
    1322             : 
    1323             :   /* First try to decide what to do without reference to lookahead token.  */
    1324        1213 :   yyn = yypact[yystate];
    1325        1213 :   if (yypact_value_is_default (yyn))
    1326         525 :     goto yydefault;
    1327             : 
    1328             :   /* Not known => get a lookahead token if don't already have one.  */
    1329             : 
    1330             :   /* YYCHAR is either empty, or end-of-input, or a valid lookahead.  */
    1331         688 :   if (yychar == YYEMPTY)
    1332             :     {
    1333         466 :       YYDPRINTF ((stderr, "Reading a token\n"));
    1334         474 :       yychar = yylex ();
    1335             :     }
    1336             : 
    1337         688 :   if (yychar <= YYEOF)
    1338             :     {
    1339         287 :       yychar = YYEOF;
    1340         287 :       yytoken = YYSYMBOL_YYEOF;
    1341         281 :       YYDPRINTF ((stderr, "Now at end of input.\n"));
    1342             :     }
    1343         401 :   else if (yychar == YYerror)
    1344             :     {
    1345             :       /* The scanner already issued an error message, process directly
    1346             :          to error recovery.  But do not keep the error token as
    1347             :          lookahead, it is too special and may lead us to an endless
    1348             :          loop in error recovery. */
    1349           0 :       yychar = YYUNDEF;
    1350           0 :       yytoken = YYSYMBOL_YYerror;
    1351           0 :       goto yyerrlab1;
    1352             :     }
    1353             :   else
    1354             :     {
    1355         401 :       yytoken = YYTRANSLATE (yychar);
    1356         676 :       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    1357             :     }
    1358             : 
    1359             :   /* If the proper action on seeing token YYTOKEN is to reduce or to
    1360             :      detect an error, take that action.  */
    1361         688 :   yyn += yytoken;
    1362         688 :   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    1363         214 :     goto yydefault;
    1364         474 :   yyn = yytable[yyn];
    1365         474 :   if (yyn <= 0)
    1366             :     {
    1367           0 :       if (yytable_value_is_error (yyn))
    1368             :         goto yyerrlab;
    1369           0 :       yyn = -yyn;
    1370           0 :       goto yyreduce;
    1371             :     }
    1372             : 
    1373             :   /* Count tokens shifted since error; after three, turn off error
    1374             :      status.  */
    1375         474 :   if (yyerrstatus)
    1376           0 :     yyerrstatus--;
    1377             : 
    1378             :   /* Shift the lookahead token.  */
    1379         466 :   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
    1380         474 :   yystate = yyn;
    1381             :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    1382         474 :   *++yyvsp = yylval;
    1383             :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    1384             : 
    1385             :   /* Discard the shifted token.  */
    1386         474 :   yychar = YYEMPTY;
    1387         474 :   goto yynewstate;
    1388             : 
    1389             : 
    1390             : /*-----------------------------------------------------------.
    1391             : | yydefault -- do the default action for the current state.  |
    1392             : `-----------------------------------------------------------*/
    1393         739 : yydefault:
    1394         739 :   yyn = yydefact[yystate];
    1395         739 :   if (yyn == 0)
    1396           0 :     goto yyerrlab;
    1397         739 :   goto yyreduce;
    1398             : 
    1399             : 
    1400             : /*-----------------------------.
    1401             : | yyreduce -- do a reduction.  |
    1402             : `-----------------------------*/
    1403         739 : yyreduce:
    1404             :   /* yyn is the number of a rule to reduce with.  */
    1405         739 :   yylen = yyr2[yyn];
    1406             : 
    1407             :   /* If YYLEN is nonzero, implement the default value of the action:
    1408             :      '$$ = $1'.
    1409             : 
    1410             :      Otherwise, the following line sets YYVAL to garbage.
    1411             :      This behavior is undocumented and Bison
    1412             :      users should not rely upon it.  Assigning to YYVAL
    1413             :      unconditionally makes the parser a bit smaller, and it avoids a
    1414             :      GCC warning that YYVAL may be used uninitialized.  */
    1415         739 :   yyval = yyvsp[1-yylen];
    1416             : 
    1417             : 
    1418         725 :   YY_REDUCE_PRINT (yyn);
    1419         739 :   switch (yyn)
    1420             :     {
    1421          93 :   case 4: /* line: expr  */
    1422             :      {
    1423          93 :         if ((yyvsp[0].sval) == NULL) {
    1424           0 :                 YYABORT;
    1425             :         }
    1426          93 :         if (global_es_parser_state->type_error) {
    1427           0 :                 YYABORT;
    1428             :         }
    1429          93 :         global_es_parser_state->result = (yyvsp[0].sval);
    1430             : }
    1431          93 :     break;
    1432             : 
    1433           0 :   case 5: /* expr: OBRACE expr CBRACE  */
    1434             :                    {
    1435           0 :         if ((yyvsp[-1].sval) == NULL) {
    1436           0 :                 (yyval.sval) = NULL;
    1437             :         } else {
    1438           0 :                 (yyval.sval) = talloc_asprintf(talloc_tos(), "(%s)", (yyvsp[-1].sval));
    1439           0 :                 if ((yyval.sval) == NULL) YYABORT;
    1440             :         }
    1441             : }
    1442           0 :     break;
    1443             : 
    1444           6 :   case 6: /* expr: expr AND expr  */
    1445             :                 {
    1446           6 :         if ((yyvsp[-2].sval) == NULL && (yyvsp[0].sval) == NULL) {
    1447           0 :                 (yyval.sval) = NULL;
    1448           6 :         } else if ((yyvsp[-2].sval) == NULL) {
    1449           0 :                 (yyval.sval) = (yyvsp[0].sval);
    1450           6 :         } else if ((yyvsp[0].sval) == NULL) {
    1451           0 :                 (yyval.sval) = (yyvsp[-2].sval);
    1452             :         } else {
    1453           2 :                 (yyval.sval) = talloc_asprintf(talloc_tos(), "(%s) AND (%s)", (yyvsp[-2].sval), (yyvsp[0].sval));
    1454           2 :                 if ((yyval.sval) == NULL) YYABORT;
    1455             :         }
    1456             : }
    1457           0 :     break;
    1458             : 
    1459          11 :   case 7: /* expr: expr OR expr  */
    1460             :                {
    1461          11 :         if ((yyvsp[-2].sval) == NULL && (yyvsp[0].sval) == NULL) {
    1462           0 :                 (yyval.sval) = NULL;
    1463          10 :         } else if ((yyvsp[-2].sval) == NULL) {
    1464           1 :                 (yyval.sval) = (yyvsp[0].sval);
    1465           9 :         } else if ((yyvsp[0].sval) == NULL) {
    1466           0 :                 (yyval.sval) = (yyvsp[-2].sval);
    1467             :         } else {
    1468           2 :                 (yyval.sval) = talloc_asprintf(talloc_tos(), "%s OR %s", (yyvsp[-2].sval), (yyvsp[0].sval));
    1469           2 :                 if ((yyval.sval) == NULL) YYABORT;
    1470             :         }
    1471             : }
    1472           0 :     break;
    1473             : 
    1474         110 :   case 8: /* expr: match  */
    1475             :         {
    1476         110 :         (yyval.sval) = (yyvsp[0].sval);
    1477             : }
    1478         110 :     break;
    1479             : 
    1480           0 :   case 9: /* expr: BOOLEAN  */
    1481             :           {
    1482             :         /*
    1483             :          * We can't properly handle these in expressions, fortunately this
    1484             :          * is probably only ever used by OS X as sole element in an
    1485             :          * expression ie "False" (when Finder window selected our share
    1486             :          * but no search string entered yet). Packet traces showed that OS
    1487             :          * X Spotlight server then returns a failure (ie -1) which is what
    1488             :          * we do here too by calling YYABORT.
    1489             :          */
    1490           0 :         YYABORT;
    1491             : }
    1492          88 :     break;
    1493             : 
    1494          90 :   case 10: /* match: attribute EQUAL value  */
    1495             :                       {
    1496          90 :         if ((yyvsp[-2].attr_map) == NULL) {
    1497           0 :                 (yyval.sval) = NULL;
    1498             :         } else {
    1499          84 :                 (yyval.sval) = map_expr((yyvsp[-2].attr_map), '=', (yyvsp[0].sval), NULL);
    1500             :         }
    1501             : }
    1502           2 :     break;
    1503             : 
    1504           7 :   case 11: /* match: attribute UNEQUAL value  */
    1505             :                           {
    1506           7 :         if ((yyvsp[-2].attr_map) == NULL) {
    1507           0 :                 (yyval.sval) = NULL;
    1508             :         } else {
    1509           6 :                 (yyval.sval) = map_expr((yyvsp[-2].attr_map), '!', (yyvsp[0].sval), NULL);
    1510             :         }
    1511             : }
    1512           0 :     break;
    1513             : 
    1514           4 :   case 12: /* match: attribute LT value  */
    1515             :                      {
    1516           4 :         if ((yyvsp[-2].attr_map) == NULL) {
    1517           0 :                 (yyval.sval) = NULL;
    1518             :         } else {
    1519           4 :                 (yyval.sval) = map_expr((yyvsp[-2].attr_map), '<', (yyvsp[0].sval), NULL);
    1520             :         }
    1521             : }
    1522           0 :     break;
    1523             : 
    1524           4 :   case 13: /* match: attribute GT value  */
    1525             :                      {
    1526           4 :         if ((yyvsp[-2].attr_map) == NULL) {
    1527           0 :                 (yyval.sval) = NULL;
    1528             :         } else {
    1529           4 :                 (yyval.sval) = map_expr((yyvsp[-2].attr_map), '>', (yyvsp[0].sval), NULL);
    1530             :         }
    1531             : }
    1532           0 :     break;
    1533             : 
    1534           5 :   case 14: /* match: function  */
    1535             :            {
    1536           5 :         (yyval.sval) = (yyvsp[0].sval);
    1537             : }
    1538           5 :     break;
    1539             : 
    1540           0 :   case 15: /* match: match WORD  */
    1541             :              {
    1542           0 :         (yyval.sval) = (yyvsp[-1].sval);
    1543             : }
    1544           0 :     break;
    1545             : 
    1546           5 :   case 16: /* function: FUNC_INRANGE OBRACE attribute COMMA WORD COMMA WORD CBRACE  */
    1547             :                                                            {
    1548           5 :         if ((yyvsp[-5].attr_map) == NULL) {
    1549           0 :                 (yyval.sval) = NULL;
    1550             :         } else {
    1551           4 :                 (yyval.sval) = map_expr((yyvsp[-5].attr_map), '~', (yyvsp[-3].sval), (yyvsp[-1].sval));
    1552             :         }
    1553             : }
    1554           0 :     break;
    1555             : 
    1556         110 :   case 17: /* attribute: WORD  */
    1557             :      {
    1558         220 :         (yyval.attr_map) = es_map_sl_attr(global_es_parser_state->frame,
    1559         110 :                             global_es_parser_state->kmd_map,
    1560             :                             (yyvsp[0].sval));
    1561         110 :         if ((yyval.attr_map) == NULL &&
    1562           8 :             !global_es_parser_state->ignore_unknown_attribute)
    1563             :         {
    1564           0 :                 YYABORT;
    1565             :         }
    1566             : }
    1567           2 :     break;
    1568             : 
    1569         102 :   case 18: /* value: PHRASE  */
    1570             :        {
    1571         102 :         (yyval.sval) = (yyvsp[0].sval);
    1572             : }
    1573         102 :     break;
    1574             : 
    1575           3 :   case 19: /* value: isodate  */
    1576             :           {
    1577           3 :         (yyval.sval) = (yyvsp[0].sval);
    1578             : }
    1579           3 :     break;
    1580             : 
    1581           3 :   case 20: /* isodate: DATE_ISO OBRACE WORD CBRACE  */
    1582             :                             {
    1583           3 :         (yyval.sval) = isodate_to_sldate((yyvsp[-1].sval));
    1584           3 :         if ((yyval.sval) == NULL) YYABORT;
    1585             : }
    1586           0 :     break;
    1587             : 
    1588             : 
    1589             : 
    1590           4 :       default: break;
    1591             :     }
    1592             :   /* User semantic actions sometimes alter yychar, and that requires
    1593             :      that yytoken be updated with the new translation.  We take the
    1594             :      approach of translating immediately before every use of yytoken.
    1595             :      One alternative is translating here after every semantic action,
    1596             :      but that translation would be missed if the semantic action invokes
    1597             :      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
    1598             :      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
    1599             :      incorrect destructor might then be invoked immediately.  In the
    1600             :      case of YYERROR or YYBACKUP, subsequent parser actions might lead
    1601             :      to an incorrect destructor call or verbose syntax error message
    1602             :      before the lookahead is translated.  */
    1603         725 :   YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
    1604             : 
    1605         739 :   YYPOPSTACK (yylen);
    1606         739 :   yylen = 0;
    1607             : 
    1608         739 :   *++yyvsp = yyval;
    1609             : 
    1610             :   /* Now 'shift' the result of the reduction.  Determine what state
    1611             :      that goes to, based on the state we popped back to and the rule
    1612             :      number reduced by.  */
    1613             :   {
    1614         739 :     const int yylhs = yyr1[yyn] - YYNTOKENS;
    1615         739 :     const int yyi = yypgoto[yylhs] + *yyssp;
    1616         237 :     yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
    1617          37 :                ? yytable[yyi]
    1618         976 :                : yydefgoto[yylhs]);
    1619             :   }
    1620             : 
    1621         739 :   goto yynewstate;
    1622             : 
    1623             : 
    1624             : /*--------------------------------------.
    1625             : | yyerrlab -- here on detecting error.  |
    1626             : `--------------------------------------*/
    1627           0 : yyerrlab:
    1628             :   /* Make sure we have latest lookahead translation.  See comments at
    1629             :      user semantic actions for why this is necessary.  */
    1630           0 :   yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
    1631             :   /* If not already recovering from an error, report this error.  */
    1632           0 :   if (!yyerrstatus)
    1633             :     {
    1634           0 :       ++yynerrs;
    1635             :       {
    1636           0 :         yypcontext_t yyctx
    1637             :           = {yyssp, yytoken};
    1638           0 :         char const *yymsgp = YY_("syntax error");
    1639           0 :         int yysyntax_error_status;
    1640           0 :         yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
    1641           0 :         if (yysyntax_error_status == 0)
    1642           0 :           yymsgp = yymsg;
    1643           0 :         else if (yysyntax_error_status == -1)
    1644             :           {
    1645           0 :             if (yymsg != yymsgbuf)
    1646           0 :               YYSTACK_FREE (yymsg);
    1647           0 :             yymsg = YY_CAST (char *,
    1648             :                              YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
    1649           0 :             if (yymsg)
    1650             :               {
    1651           0 :                 yysyntax_error_status
    1652           0 :                   = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
    1653           0 :                 yymsgp = yymsg;
    1654             :               }
    1655             :             else
    1656             :               {
    1657           0 :                 yymsg = yymsgbuf;
    1658           0 :                 yymsg_alloc = sizeof yymsgbuf;
    1659           0 :                 yysyntax_error_status = YYENOMEM;
    1660             :               }
    1661             :           }
    1662           0 :         yyerror (yymsgp);
    1663           0 :         if (yysyntax_error_status == YYENOMEM)
    1664           0 :           YYNOMEM;
    1665             :       }
    1666             :     }
    1667             : 
    1668           0 :   if (yyerrstatus == 3)
    1669             :     {
    1670             :       /* If just tried and failed to reuse lookahead token after an
    1671             :          error, discard it.  */
    1672             : 
    1673           0 :       if (yychar <= YYEOF)
    1674             :         {
    1675             :           /* Return failure if at end of input.  */
    1676           0 :           if (yychar == YYEOF)
    1677           0 :             YYABORT;
    1678             :         }
    1679             :       else
    1680             :         {
    1681           0 :           yydestruct ("Error: discarding",
    1682             :                       yytoken, &yylval);
    1683           0 :           yychar = YYEMPTY;
    1684             :         }
    1685             :     }
    1686             : 
    1687             :   /* Else will try to reuse lookahead token after shifting the error
    1688             :      token.  */
    1689           0 :   goto yyerrlab1;
    1690             : 
    1691             : 
    1692             : /*---------------------------------------------------.
    1693             : | yyerrorlab -- error raised explicitly by YYERROR.  |
    1694             : `---------------------------------------------------*/
    1695             : yyerrorlab:
    1696             :   /* Pacify compilers when the user code never invokes YYERROR and the
    1697             :      label yyerrorlab therefore never appears in user code.  */
    1698             :   if (0)
    1699             :     YYERROR;
    1700             :   ++yynerrs;
    1701             : 
    1702             :   /* Do not reclaim the symbols of the rule whose action triggered
    1703             :      this YYERROR.  */
    1704             :   YYPOPSTACK (yylen);
    1705             :   yylen = 0;
    1706             :   YY_STACK_PRINT (yyss, yyssp);
    1707             :   yystate = *yyssp;
    1708             :   goto yyerrlab1;
    1709             : 
    1710             : 
    1711             : /*-------------------------------------------------------------.
    1712             : | yyerrlab1 -- common code for both syntax error and YYERROR.  |
    1713             : `-------------------------------------------------------------*/
    1714           0 : yyerrlab1:
    1715           0 :   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
    1716             : 
    1717             :   /* Pop stack until we find a state that shifts the error token.  */
    1718           0 :   for (;;)
    1719             :     {
    1720           0 :       yyn = yypact[yystate];
    1721           0 :       if (!yypact_value_is_default (yyn))
    1722             :         {
    1723           0 :           yyn += YYSYMBOL_YYerror;
    1724           0 :           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
    1725             :             {
    1726           0 :               yyn = yytable[yyn];
    1727           0 :               if (0 < yyn)
    1728           0 :                 break;
    1729             :             }
    1730             :         }
    1731             : 
    1732             :       /* Pop the current state because it cannot handle the error token.  */
    1733           0 :       if (yyssp == yyss)
    1734           0 :         YYABORT;
    1735             : 
    1736             : 
    1737           0 :       yydestruct ("Error: popping",
    1738           0 :                   YY_ACCESSING_SYMBOL (yystate), yyvsp);
    1739           0 :       YYPOPSTACK (1);
    1740           0 :       yystate = *yyssp;
    1741           0 :       YY_STACK_PRINT (yyss, yyssp);
    1742             :     }
    1743             : 
    1744             :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    1745           0 :   *++yyvsp = yylval;
    1746             :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    1747             : 
    1748             : 
    1749             :   /* Shift the error token.  */
    1750           0 :   YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
    1751             : 
    1752           0 :   yystate = yyn;
    1753           0 :   goto yynewstate;
    1754             : 
    1755             : 
    1756             : /*-------------------------------------.
    1757             : | yyacceptlab -- YYACCEPT comes here.  |
    1758             : `-------------------------------------*/
    1759          93 : yyacceptlab:
    1760          93 :   yyresult = 0;
    1761          93 :   goto yyreturnlab;
    1762             : 
    1763             : 
    1764             : /*-----------------------------------.
    1765             : | yyabortlab -- YYABORT comes here.  |
    1766             : `-----------------------------------*/
    1767           0 : yyabortlab:
    1768           0 :   yyresult = 1;
    1769           0 :   goto yyreturnlab;
    1770             : 
    1771             : 
    1772             : /*-----------------------------------------------------------.
    1773             : | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here.  |
    1774             : `-----------------------------------------------------------*/
    1775           0 : yyexhaustedlab:
    1776           0 :   yyerror (YY_("memory exhausted"));
    1777           0 :   yyresult = 2;
    1778           0 :   goto yyreturnlab;
    1779             : 
    1780             : 
    1781             : /*----------------------------------------------------------.
    1782             : | yyreturnlab -- parsing is finished, clean up and return.  |
    1783             : `----------------------------------------------------------*/
    1784          93 : yyreturnlab:
    1785          93 :   if (yychar != YYEMPTY)
    1786             :     {
    1787             :       /* Make sure we have latest lookahead translation.  See comments at
    1788             :          user semantic actions for why this is necessary.  */
    1789          91 :       yytoken = YYTRANSLATE (yychar);
    1790           0 :       yydestruct ("Cleanup: discarding lookahead",
    1791             :                   yytoken, &yylval);
    1792             :     }
    1793             :   /* Do not reclaim the symbols of the rule whose action triggered
    1794             :      this YYABORT or YYACCEPT.  */
    1795          93 :   YYPOPSTACK (yylen);
    1796          91 :   YY_STACK_PRINT (yyss, yyssp);
    1797          97 :   while (yyssp != yyss)
    1798             :     {
    1799           4 :       yydestruct ("Cleanup: popping",
    1800           4 :                   YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
    1801           4 :       YYPOPSTACK (1);
    1802             :     }
    1803             : #ifndef yyoverflow
    1804          93 :   if (yyss != yyssa)
    1805           0 :     YYSTACK_FREE (yyss);
    1806             : #endif
    1807          93 :   if (yymsg != yymsgbuf)
    1808           0 :     YYSTACK_FREE (yymsg);
    1809          93 :   return yyresult;
    1810             : }
    1811             : 
    1812             : 
    1813             : 
    1814             : /*
    1815             :  * Spotlight has two date formats:
    1816             :  * - seconds since 2001-01-01 00:00:00Z
    1817             :  * - as string "$time.iso(%Y-%m-%dT%H:%M:%SZ)"
    1818             :  * This function converts the latter to the former as string, so the parser
    1819             :  * can work on a uniform format.
    1820             :  */
    1821           3 : static char *isodate_to_sldate(const char *isodate)
    1822             : {
    1823           3 :         struct es_parser_state *s = global_es_parser_state;
    1824           3 :         struct tm tm = {};
    1825           3 :         const char *p = NULL;
    1826           3 :         char *tstr = NULL;
    1827           3 :         time_t t;
    1828             : 
    1829           3 :         p = strptime(isodate, "%Y-%m-%dT%H:%M:%SZ", &tm);
    1830           3 :         if (p == NULL) {
    1831           0 :                 DBG_ERR("strptime [%s] failed\n", isodate);
    1832           0 :                 return NULL;
    1833             :         }
    1834             : 
    1835           3 :         t = timegm(&tm);
    1836           3 :         t -= SP_RAW_TIME_OFFSET;
    1837             : 
    1838           3 :         tstr = talloc_asprintf(s->frame, "%jd", (intmax_t)t);
    1839           3 :         if (tstr == NULL) {
    1840           0 :                 return NULL;
    1841             :         }
    1842             : 
    1843           0 :         return tstr;
    1844             : }
    1845             : 
    1846          13 : static char *map_type(const struct es_attr_map *attr,
    1847             :                       char op,
    1848             :                       const char *val)
    1849             : {
    1850          13 :         struct es_parser_state *s = global_es_parser_state;
    1851          13 :         const char *mime_type_list = NULL;
    1852          13 :         char *esc_mime_type_list = NULL;
    1853          13 :         const char *not = NULL;
    1854          13 :         const char *end = NULL;
    1855          13 :         char *es = NULL;
    1856             : 
    1857          13 :         mime_type_list = es_map_sl_type(s->mime_map, val);
    1858          13 :         if (mime_type_list == NULL) {
    1859           5 :                 DBG_DEBUG("Mapping type [%s] failed\n", val);
    1860           5 :                 if (!s->ignore_unknown_type) {
    1861           0 :                         s->type_error = true;
    1862             :                 }
    1863           5 :                 return NULL;
    1864             :         }
    1865             : 
    1866           8 :         esc_mime_type_list = es_escape_str(s->frame,
    1867             :                                            mime_type_list,
    1868             :                                            "* ");
    1869           8 :         if (esc_mime_type_list == NULL) {
    1870           0 :                 return NULL;
    1871             :         }
    1872             : 
    1873           8 :         switch (op) {
    1874           0 :         case '=':
    1875           0 :                 not = "";
    1876           0 :                 end = "";
    1877           0 :                 break;
    1878           0 :         case '!':
    1879           0 :                 not = "(NOT ";
    1880           0 :                 end = ")";
    1881           0 :                 break;
    1882           0 :         default:
    1883           0 :                 DBG_ERR("Mapping type [%s] unexpected op [%c]\n", val, op);
    1884           0 :                 return NULL;
    1885             :         }
    1886          16 :         es = talloc_asprintf(s->frame,
    1887             :                              "%s%s:(%s)%s",
    1888             :                              not,
    1889           8 :                              attr->name,
    1890             :                              esc_mime_type_list,
    1891             :                              end);
    1892           8 :         if (es == NULL) {
    1893           0 :                 return NULL;
    1894             :         }
    1895             : 
    1896           0 :         return es;
    1897             : }
    1898             : 
    1899          24 : static char *map_num(const struct es_attr_map *attr,
    1900             :                      char op,
    1901             :                      const char *val1,
    1902             :                      const char *val2)
    1903             : {
    1904          24 :         struct es_parser_state *s = global_es_parser_state;
    1905          24 :         char *es = NULL;
    1906             : 
    1907          24 :         switch (op) {
    1908           2 :         case '>':
    1909           2 :                 es = talloc_asprintf(s->frame,
    1910             :                                      "%s:{%s TO *}",
    1911           2 :                                      attr->name,
    1912             :                                      val1);
    1913           2 :                 break;
    1914           2 :         case '<':
    1915           2 :                 es = talloc_asprintf(s->frame,
    1916             :                                      "%s:{* TO %s}",
    1917           2 :                                      attr->name,
    1918             :                                      val1);
    1919           2 :                 break;
    1920           2 :         case '~':
    1921           2 :                 es = talloc_asprintf(s->frame,
    1922             :                                      "%s:[%s TO %s]",
    1923           2 :                                      attr->name,
    1924             :                                      val1,
    1925             :                                      val2);
    1926           2 :                 break;
    1927          16 :         case '=':
    1928          16 :                 es = talloc_asprintf(s->frame,
    1929             :                                      "%s:%s",
    1930          16 :                                      attr->name,
    1931             :                                      val1);
    1932          16 :                 break;
    1933           2 :         case '!':
    1934           2 :                 es = talloc_asprintf(s->frame,
    1935             :                                      "(NOT %s:%s)",
    1936           2 :                                      attr->name,
    1937             :                                      val1);
    1938           2 :                 break;
    1939           0 :         default:
    1940           0 :                 DBG_ERR("Mapping num unexpected op [%c]\n", op);
    1941           0 :                 return NULL;
    1942             :         }
    1943          24 :         if (es == NULL) {
    1944           0 :                 return NULL;
    1945             :         }
    1946             : 
    1947           0 :         return es;
    1948             : }
    1949             : 
    1950          15 : static char *map_fts(const struct es_attr_map *attr,
    1951             :                      char op,
    1952             :                      const char *val)
    1953             : {
    1954          15 :         struct es_parser_state *s = global_es_parser_state;
    1955          15 :         const char *not = NULL;
    1956          15 :         const char *end = NULL;
    1957          15 :         char *esval = NULL;
    1958          15 :         char *es = NULL;
    1959             : 
    1960          15 :         esval = es_escape_str(s->frame, val, "*\\\"");
    1961          15 :         if (esval == NULL) {
    1962           0 :                 yyerror("es_escape_str failed");
    1963           0 :                 return NULL;
    1964             :         }
    1965             : 
    1966          15 :         switch (op) {
    1967           2 :         case '=':
    1968           2 :                 not = "";
    1969           2 :                 end = "";
    1970           2 :                 break;
    1971           2 :         case '!':
    1972           2 :                 not = "(NOT ";
    1973           2 :                 end = ")";
    1974           2 :                 break;
    1975           0 :         default:
    1976           0 :                 DBG_ERR("Mapping fts [%s] unexpected op [%c]\n", val, op);
    1977           0 :                 return NULL;
    1978             :         }
    1979          15 :         es = talloc_asprintf(s->frame,
    1980             :                              "%s%s%s",
    1981             :                              not,
    1982             :                              esval,
    1983             :                              end);
    1984          15 :         if (es == NULL) {
    1985           0 :                 return NULL;
    1986             :         }
    1987           2 :         return es;
    1988             : }
    1989             : 
    1990          30 : static char *map_str(const struct es_attr_map *attr,
    1991             :                      char op,
    1992             :                      const char *val)
    1993             : {
    1994          30 :         struct es_parser_state *s = global_es_parser_state;
    1995          30 :         char *esval = NULL;
    1996          30 :         char *es = NULL;
    1997          30 :         const char *not = NULL;
    1998          30 :         const char *end = NULL;
    1999             : 
    2000          30 :         esval = es_escape_str(s->frame, val, "*\\\"");
    2001          30 :         if (esval == NULL) {
    2002           0 :                 yyerror("es_escape_str failed");
    2003           0 :                 return NULL;
    2004             :         }
    2005             : 
    2006          30 :         switch (op) {
    2007           0 :         case '=':
    2008           0 :                 not = "";
    2009           0 :                 end = "";
    2010           0 :                 break;
    2011           0 :         case '!':
    2012           0 :                 not = "(NOT ";
    2013           0 :                 end = ")";
    2014           0 :                 break;
    2015           0 :         default:
    2016           0 :                 DBG_ERR("Mapping string [%s] unexpected op [%c]\n", val, op);
    2017           0 :                 return NULL;
    2018             :         }
    2019             : 
    2020          60 :         es = talloc_asprintf(s->frame,
    2021             :                              "%s%s:%s%s",
    2022             :                              not,
    2023          30 :                              attr->name,
    2024             :                              esval,
    2025             :                              end);
    2026          30 :         if (es == NULL) {
    2027           0 :                 return NULL;
    2028             :         }
    2029           0 :         return es;
    2030             : }
    2031             : 
    2032             : /*
    2033             :  * Convert Spotlight date seconds since 2001-01-01 00:00:00Z
    2034             :  * to a date string in the format %Y-%m-%dT%H:%M:%SZ.
    2035             :  */
    2036          22 : static char *map_sldate_to_esdate(TALLOC_CTX *mem_ctx,
    2037             :                                   const char *sldate)
    2038             : {
    2039          22 :         struct tm *tm = NULL;
    2040          22 :         char *esdate = NULL;
    2041          22 :         char buf[21];
    2042          22 :         size_t len;
    2043          22 :         time_t t;
    2044          22 :         int error;
    2045             : 
    2046          22 :         t = (time_t)smb_strtoull(sldate, NULL, 10, &error, SMB_STR_STANDARD);
    2047          22 :         if (error != 0) {
    2048           0 :                 DBG_ERR("smb_strtoull [%s] failed\n", sldate);
    2049           0 :                 return NULL;
    2050             :         }
    2051          22 :         t += SP_RAW_TIME_OFFSET;
    2052             : 
    2053          22 :         tm = gmtime(&t);
    2054          22 :         if (tm == NULL) {
    2055           0 :                 DBG_ERR("localtime [%s] failed\n", sldate);
    2056           0 :                 return NULL;
    2057             :         }
    2058             : 
    2059          22 :         len = strftime(buf, sizeof(buf),
    2060             :                        "%Y-%m-%dT%H:%M:%SZ", tm);
    2061          22 :         if (len != 20) {
    2062           0 :                 DBG_ERR("strftime [%s] failed\n", sldate);
    2063           0 :                 return NULL;
    2064             :         }
    2065             : 
    2066          22 :         esdate = es_escape_str(mem_ctx, buf, NULL);
    2067          22 :         if (esdate == NULL) {
    2068           0 :                 yyerror("es_escape_str failed");
    2069           0 :                 return NULL;
    2070             :         }
    2071           0 :         return esdate;
    2072             : }
    2073             : 
    2074          20 : static char *map_date(const struct es_attr_map *attr,
    2075             :                       char op,
    2076             :                       const char *sldate1,
    2077             :                       const char *sldate2)
    2078             : {
    2079          20 :         struct es_parser_state *s = global_es_parser_state;
    2080          20 :         char *esdate1 = NULL;
    2081          20 :         char *esdate2 = NULL;
    2082          20 :         char *es = NULL;
    2083             : 
    2084          20 :         if (op == '~' && sldate2 == NULL) {
    2085           0 :                 DBG_ERR("Date range query, but second date is NULL\n");
    2086           0 :                 return NULL;
    2087             :         }
    2088             : 
    2089          20 :         esdate1 = map_sldate_to_esdate(s->frame, sldate1);
    2090          20 :         if (esdate1 == NULL) {
    2091           0 :                 DBG_ERR("map_sldate_to_esdate [%s] failed\n", sldate1);
    2092           0 :                 return NULL;
    2093             :         }
    2094          20 :         if (sldate2 != NULL) {
    2095           2 :                 esdate2 = map_sldate_to_esdate(s->frame, sldate2);
    2096           2 :                 if (esdate2 == NULL) {
    2097           0 :                         DBG_ERR("map_sldate_to_esdate [%s] failed\n", sldate2);
    2098           0 :                         return NULL;
    2099             :                 }
    2100             :         }
    2101             : 
    2102          20 :         switch (op) {
    2103           2 :         case '>':
    2104           2 :                 es = talloc_asprintf(s->frame,
    2105             :                                      "%s:{%s TO *}",
    2106           2 :                                      attr->name,
    2107             :                                      esdate1);
    2108           2 :                 break;
    2109           2 :         case '<':
    2110           2 :                 es = talloc_asprintf(s->frame,
    2111             :                                      "%s:{* TO %s}",
    2112           2 :                                      attr->name,
    2113             :                                      esdate1);
    2114           2 :                 break;
    2115           2 :         case '~':
    2116           2 :                 es = talloc_asprintf(s->frame,
    2117             :                                      "%s:[%s TO %s]",
    2118           2 :                                      attr->name,
    2119             :                                      esdate1,
    2120             :                                      esdate2);
    2121           2 :                 break;
    2122          12 :         case '=':
    2123          12 :                 es = talloc_asprintf(s->frame,
    2124             :                                      "%s:%s",
    2125          12 :                                      attr->name,
    2126             :                                      esdate1);
    2127          12 :                 break;
    2128           2 :         case '!':
    2129           2 :                 es = talloc_asprintf(s->frame,
    2130             :                                      "(NOT %s:%s)",
    2131           2 :                                      attr->name,
    2132             :                                      esdate1);
    2133           2 :                 break;
    2134             :         }
    2135          20 :         if (es == NULL) {
    2136           0 :                 return NULL;
    2137             :         }
    2138           0 :         return es;
    2139             : }
    2140             : 
    2141         102 : static char *map_expr(const struct es_attr_map *attr,
    2142             :                       char op,
    2143             :                       const char *val1,
    2144             :                       const char *val2)
    2145             : {
    2146         102 :         char *es = NULL;
    2147             : 
    2148         102 :         switch (attr->type) {
    2149          13 :         case ssmt_type:
    2150          13 :                 es = map_type(attr, op, val1);
    2151          13 :                 break;
    2152          24 :         case ssmt_num:
    2153          24 :                 es = map_num(attr, op, val1, val2);
    2154          24 :                 break;
    2155          15 :         case ssmt_fts:
    2156          15 :                 es = map_fts(attr, op, val1);
    2157          15 :                 break;
    2158          30 :         case ssmt_str:
    2159          30 :                 es = map_str(attr, op, val1);
    2160          30 :                 break;
    2161          20 :         case ssmt_date:
    2162          20 :                 es = map_date(attr, op, val1, val2);
    2163          20 :                 break;
    2164           0 :         default:
    2165           0 :                 break;
    2166             :         }
    2167         102 :         if (es == NULL) {
    2168           5 :                 DBG_DEBUG("Mapping [%s %c %s (%s)] failed\n",
    2169             :                           attr->name, op, val1, val2 ? val2 : "");
    2170           5 :                 return NULL;
    2171             :         }
    2172             : 
    2173           2 :         return es;
    2174             : }
    2175             : 
    2176           0 : void mdsyylerror(const char *str)
    2177             : {
    2178           0 :         DBG_ERR("Parser failed: %s\n", str);
    2179           0 : }
    2180             : 
    2181          93 : int mdsyylwrap(void)
    2182             : {
    2183          93 :         return 1;
    2184             : }
    2185             : 
    2186             : /**
    2187             :  * Map a Spotlight RAW query string to a ES query string
    2188             :  **/
    2189          93 : bool map_spotlight_to_es_query(TALLOC_CTX *mem_ctx,
    2190             :                                json_t *mappings,
    2191             :                                const char *path_scope,
    2192             :                                const char *query_string,
    2193             :                                char **_es_query)
    2194             : {
    2195         186 :         struct es_parser_state s = {
    2196          93 :                 .frame = talloc_stackframe(),
    2197             :         };
    2198          91 :         int result;
    2199          93 :         char *es_query = NULL;
    2200             : 
    2201          93 :         s.kmd_map = json_object_get(mappings, "attribute_mappings");
    2202          93 :         if (s.kmd_map == NULL) {
    2203           0 :                 DBG_ERR("Failed to load attribute_mappings from JSON\n");
    2204           0 :                 return false;
    2205             :         }
    2206          93 :         s.mime_map = json_object_get(mappings, "mime_mappings");
    2207          93 :         if (s.mime_map == NULL) {
    2208           0 :                 DBG_ERR("Failed to load mime_mappings from JSON\n");
    2209           0 :                 return false;
    2210             :         }
    2211             : 
    2212          93 :         s.s = mdsyyl_scan_string(query_string);
    2213          93 :         if (s.s == NULL) {
    2214           0 :                 DBG_WARNING("Failed to parse [%s]\n", query_string);
    2215           0 :                 TALLOC_FREE(s.frame);
    2216           0 :                 return false;
    2217             :         }
    2218             : 
    2219          93 :         s.ignore_unknown_attribute = lp_parm_bool(GLOBAL_SECTION_SNUM,
    2220             :                                                   "elasticsearch",
    2221             :                                                   "ignore unknown attribute",
    2222             :                                                   false);
    2223          93 :         s.ignore_unknown_type = lp_parm_bool(GLOBAL_SECTION_SNUM,
    2224             :                                              "elasticsearch",
    2225             :                                              "ignore unknown type",
    2226             :                                              false);
    2227             : 
    2228          93 :         global_es_parser_state = &s;
    2229          93 :         result = mdsyylparse();
    2230          93 :         global_es_parser_state = NULL;
    2231          93 :         mdsyyl_delete_buffer(s.s);
    2232             : 
    2233          93 :         if (result != 0) {
    2234           0 :                 TALLOC_FREE(s.frame);
    2235           0 :                 return false;
    2236             :         }
    2237             : 
    2238          93 :         es_query = talloc_asprintf(mem_ctx,
    2239             :                                    "(%s) AND path.real.fulltext:\\\"%s\\\"",
    2240             :                                    s.result, path_scope);
    2241          93 :         TALLOC_FREE(s.frame);
    2242          93 :         if (es_query == NULL) {
    2243           0 :                 return false;
    2244             :         }
    2245             : 
    2246          93 :         *_es_query = es_query;
    2247          93 :         return true;
    2248             : }

Generated by: LCOV version 1.14