1/*
2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23#ifndef _KEXTFIND_TABLES_H_
24#define _KEXTFIND_TABLES_H_
25
26#include <CoreFoundation/CoreFoundation.h>
27#include <getopt.h>
28#include "QEQuery.h"
29#include "kext_tools_util.h"
30
31/*******************************************************************************
32* This data structure associated query keywords with the parsing and evaluation
33* function callbacks used by the query engine. Some callbacks handle several
34* keywords because of similar arguments or evaluation logic.
35*
36* See kextfind_query.[hc] for the definitions of these things.
37*******************************************************************************/
38struct querySetup {
39    CFStringRef longName;
40    CFStringRef shortName;
41    QEQueryParseCallback parseCallback;
42    QEQueryEvaluationCallback evalCallback;
43};
44
45/*******************************************************************************
46* Command-line options (as opposed to query predicate keywords).
47* This data is used by getopt_long_only().
48*******************************************************************************/
49/* Would like a way to automatically combine these into the optstring.
50 */
51#define kOptNameHelp                    "help"
52#define kOptNameCaseInsensitive         "case-insensitive"
53#define kOptNameNulTerminate            "nul"
54#define kOptNameSearchItem              "search-item"
55#define kOptNameSubstring               "substring"
56#define kOptNameDefaultArch             "set-arch"
57
58#ifdef EXTRA_INFO
59// I think there will be better ways to do this after getting some airtime
60#define kOptNameExtraInfo               "extra-info"
61#endif
62
63#define kOptNameRelativePaths           "relative-paths"
64#define kOptNameNoPaths                 "no-paths"
65
66// Currently unused, although code does reference them
67// Things are picky by default for now.
68#define kOptNameMeek                    "meek"
69#define kOptNamePicky                   "picky"
70
71#define kOPT_CHARS  "0ef:his"
72
73enum {
74    kOptSystemExtensions = 'e',
75    kOptCaseInsensitive = 'i',
76    kOptNulTerminate = '0',
77    kOptSearchItem = 'f',
78    kOptSubstring = 's',
79};
80
81/* Options with no single-letter variant.  */
82// Do not use -1, that's getopt() end-of-args return value
83// and can cause confusion
84enum {
85    kLongOptQueryPredicate = -2,
86#ifdef EXTRA_INFO
87    kLongOptExtraInfo = -3,
88#endif
89    kLongOptRelativePaths = -4,
90    kLongOptNoPaths = -5,
91    kLongOptMeek = -6,
92    kLongOptPicky = -7,
93    kLongOptReport = -8,
94    kLongOptDefaultArch = -9,
95};
96
97/*******************************************************************************
98* The structure of info needed by getopt_long_only().
99*******************************************************************************/
100extern struct option opt_info[];
101extern int           longopt;
102
103/*******************************************************************************
104* A list of predicate names, synonyms, and parse/eval callbacks for the
105* query engine.
106*******************************************************************************/
107extern struct querySetup queryCallbackList[];
108extern struct querySetup reportCallbackList[];
109
110
111/*******************************************************************************
112*
113*******************************************************************************/
114#define QUERY_PREDICATES  \
115    { &kPredNameProperty[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
116    { &kPredNamePropertyExists[1],         no_argument, &longopt, kLongOptQueryPredicate },  \
117    \
118    { &kPredNameMatchProperty[1],          no_argument, &longopt, kLongOptQueryPredicate },  \
119    { &kPredNameMatchPropertyExists[1],    no_argument, &longopt, kLongOptQueryPredicate },  \
120    \
121    { &kPredNameLoaded[1],                 no_argument, &longopt, kLongOptQueryPredicate },  \
122    { &kPredNameValid[1],                  no_argument, &longopt, kLongOptQueryPredicate },  \
123    { &kPredNameAuthentic[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
124    { &kPredNameDependenciesMet[1],        no_argument, &longopt, kLongOptQueryPredicate },  \
125    { &kPredNameLoadable[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
126    { &kPredNameWarnings[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
127    { &kPredNameIsLibrary[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
128    \
129    { &kQEQueryTokenAnd[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
130    { &kQEQueryTokenOr[1],                 no_argument, &longopt, kLongOptQueryPredicate },  \
131    { &kQEQueryTokenNot[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
132    \
133    { &kPredNameVersion[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
134    { &kPredNameCompatibleWithVersion[1],  no_argument, &longopt, kLongOptQueryPredicate },  \
135    { &kPredNameIntegrity[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
136    \
137    { &kPredNameHasPlugins[1],             no_argument, &longopt, kLongOptQueryPredicate },  \
138    { &kPredNameIsPlugin[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
139    { &kPredNameHasDebugProperties[1],     no_argument, &longopt, kLongOptQueryPredicate },  \
140    \
141    { &kPredNameArch[1],                   no_argument, &longopt, kLongOptQueryPredicate },  \
142    { &kPredNameArchExact[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
143    { &kPredNameExecutable[1],             no_argument, &longopt, kLongOptQueryPredicate },  \
144    { &kPredNameNoExecutable[1],           no_argument, &longopt, kLongOptQueryPredicate },  \
145    { &kPredNameDefinesSymbol[1],          no_argument, &longopt, kLongOptQueryPredicate },  \
146    { &kPredNameReferencesSymbol[1],       no_argument, &longopt, kLongOptQueryPredicate },  \
147    \
148    { &kPredNameDuplicate[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
149    \
150    { &kPredNameInvalid[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
151    { &kPredNameInauthentic[1],            no_argument, &longopt, kLongOptQueryPredicate },  \
152    { &kPredNameDependenciesMissing[1],    no_argument, &longopt, kLongOptQueryPredicate },  \
153    { &kPredNameNonloadable[1],            no_argument, &longopt, kLongOptQueryPredicate },  \
154    \
155    { &kPredNameBundleID[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
156    { &kPredNameBundleName[1],             no_argument, &longopt, kLongOptQueryPredicate },  \
157    \
158    { &kPredNameRoot[1],                   no_argument, &longopt, kLongOptQueryPredicate },  \
159    { &kPredNameConsole[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
160    { &kPredNameLocalRoot[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
161    { &kPredNameNetworkRoot[1],            no_argument, &longopt, kLongOptQueryPredicate },  \
162    { &kPredNameSafeBoot[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
163    \
164    { &kPredCharProperty[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
165    { &kPredCharPropertyExists[1],         no_argument, &longopt, kLongOptQueryPredicate },  \
166    \
167    { &kPredCharMatchProperty[1],          no_argument, &longopt, kLongOptQueryPredicate },  \
168    { &kPredCharMatchPropertyExists[1],    no_argument, &longopt, kLongOptQueryPredicate },  \
169    \
170    { &kPredCharValid[1],                  no_argument, &longopt, kLongOptQueryPredicate },  \
171    { &kPredCharAuthentic[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
172    { &kPredCharDependenciesMet[1],        no_argument, &longopt, kLongOptQueryPredicate },  \
173    { &kPredCharLoadable[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
174    { &kPredCharWarnings[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
175    \
176    { &kQEQueryTokenAnd[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
177    { &kQEQueryTokenOr[1],                 no_argument, &longopt, kLongOptQueryPredicate },  \
178    { &kQEQueryTokenNot[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
179    \
180    { &kPredCharVersion[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
181    \
182    { &kPredCharArchExact[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
183    { &kPredCharExecutable[1],             no_argument, &longopt, kLongOptQueryPredicate },  \
184    { &kPredCharNoExecutable[1],           no_argument, &longopt, kLongOptQueryPredicate },  \
185    { &kPredCharDefinesSymbol[1],          no_argument, &longopt, kLongOptQueryPredicate },  \
186    { &kPredCharReferencesSymbol[1],       no_argument, &longopt, kLongOptQueryPredicate },  \
187    \
188    { &kPredCharDuplicate[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
189    \
190    { &kPredCharInvalid[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
191    { &kPredCharInauthentic[1],            no_argument, &longopt, kLongOptQueryPredicate },  \
192    { &kPredCharDependenciesMissing[1],    no_argument, &longopt, kLongOptQueryPredicate },  \
193    { &kPredCharNonloadable[1],            no_argument, &longopt, kLongOptQueryPredicate },  \
194    \
195    { &kPredCharBundleID[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
196    \
197    { &kPredCharRoot[1],                   no_argument, &longopt, kLongOptQueryPredicate },  \
198    { &kPredCharConsole[1],                no_argument, &longopt, kLongOptQueryPredicate },  \
199    { &kPredCharLocalRoot[1],              no_argument, &longopt, kLongOptQueryPredicate },  \
200    { &kPredCharNetworkRoot[1],            no_argument, &longopt, kLongOptQueryPredicate },  \
201    { &kPredCharSafeBoot[1],               no_argument, &longopt, kLongOptQueryPredicate },  \
202
203  #define QUERY_COMMANDS  \
204    { &kPredNameEcho[1],                   no_argument, &longopt, kLongOptQueryPredicate },  \
205    { &kPredNamePrint[1],                  no_argument, &longopt, kLongOptQueryPredicate },  \
206    { &kPredNamePrintDiagnostics[1],       no_argument, &longopt, kLongOptQueryPredicate },  \
207    { &kPredNamePrintProperty[1],          no_argument, &longopt, kLongOptQueryPredicate },  \
208    { &kPredNamePrintMatchProperty[1],     no_argument, &longopt, kLongOptQueryPredicate },  \
209    { &kPredNamePrintArches[1],            no_argument, &longopt, kLongOptQueryPredicate },  \
210    { &kPredNamePrintDependencies[1],      no_argument, &longopt, kLongOptQueryPredicate },  \
211    { &kPredNamePrintDependents[1],        no_argument, &longopt, kLongOptQueryPredicate },  \
212    { &kPredNamePrintIntegrity[1],         no_argument, &longopt, kLongOptQueryPredicate },  \
213    { &kPredNamePrintPlugins[1],           no_argument, &longopt, kLongOptQueryPredicate },  \
214    { &kPredNamePrintInfoDictionary[1],    no_argument, &longopt, kLongOptQueryPredicate },  \
215    { &kPredNamePrintExecutable[1],        no_argument, &longopt, kLongOptQueryPredicate },  \
216    \
217    { &kPredNameExec[1],                   no_argument, &longopt, kLongOptQueryPredicate },  \
218    { &kPredCharPrintDiagnostics[1],       no_argument, &longopt, kLongOptQueryPredicate },  \
219    { &kPredCharPrintProperty[1],          no_argument, &longopt, kLongOptQueryPredicate },  \
220    { &kPredCharPrintMatchProperty[1],     no_argument, &longopt, kLongOptQueryPredicate },  \
221    { &kPredCharPrintArches[1],            no_argument, &longopt, kLongOptQueryPredicate },  \
222    { &kPredCharPrintInfoDictionary[1],    no_argument, &longopt, kLongOptQueryPredicate },  \
223    { &kPredCharPrintExecutable[1],        no_argument, &longopt, kLongOptQueryPredicate },
224
225
226#endif /* _KEXTFIND_TABLES_H_ */
227