]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/lib/RequirementParser.cpp
Security-57740.51.3.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / lib / RequirementParser.cpp
1 /* $ANTLR 2.7.7 (20121221): "requirements.grammar" -> "RequirementParser.cpp"$ */
2 #include "RequirementParser.hpp"
3 #include <antlr/NoViableAltException.hpp>
4 #include <antlr/SemanticException.hpp>
5 #include <antlr/ASTFactory.hpp>
6
7 #include "requirement.h"
8 #include "reqmaker.h"
9 #include "csutilities.h"
10 #include <security_utilities/cfutilities.h>
11 #include <security_utilities/hashing.h>
12 #include <security_cdsa_utilities/cssmdata.h> // OID coding
13 using namespace CodeSigning;
14 typedef Requirement::Maker Maker;
15
16 ANTLR_BEGIN_NAMESPACE(Security_CodeSigning)
17
18 //
19 // Collect error messages.
20 // Note that the immediate caller takes the absence of collected error messages
21 // to indicate compilation success.
22 //
23 void RequirementParser::reportError(const antlr::RecognitionException &ex)
24 {
25 errors += ex.toString() + "\n";
26 }
27
28 void RequirementParser::reportError(const std::string &s)
29 {
30 errors += s + "\n";
31 }
32
33
34 //
35 // Parser helper functions
36 //
37 string RequirementParser::hexString(const string &s)
38 {
39 if (s.size() % 2)
40 throw antlr::SemanticException("odd number of digits");
41 const char *p = s.data();
42 string result;
43 for (unsigned n = 0; n < s.length(); n += 2) {
44 char c;
45 sscanf(p+n, "%2hhx", &c);
46 result.push_back(c);
47 }
48 return result;
49 }
50
51 void RequirementParser::hashString(const string &s, SHA1::Digest hash)
52 {
53 if (s.size() != 2 * SHA1::digestLength)
54 throw antlr::SemanticException("invalid hash length");
55 memcpy(hash, hexString(s).data(), SHA1::digestLength);
56 }
57
58 static const char *matchPrefix(const string &key, const char *prefix)
59 {
60 size_t pLength = strlen(prefix);
61 if (!key.compare(0, pLength, prefix, 0, pLength))
62 return key.c_str() + pLength;
63 else
64 return NULL;
65 }
66
67 void RequirementParser::certMatchOperation(Maker &maker, int32_t slot, string key)
68 {
69 if (matchPrefix(key, "subject.")) {
70 maker.put(opCertField);
71 maker.put(slot);
72 maker.put(key);
73 } else if (const char *oids = matchPrefix(key, "field.")) {
74 maker.put(opCertGeneric);
75 maker.put(slot);
76 CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
77 maker.putData(oid.data(), oid.length());
78 } else if (const char *oids = matchPrefix(key, "extension.")) {
79 maker.put(opCertGeneric);
80 maker.put(slot);
81 CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
82 maker.putData(oid.data(), oid.length());
83 } else if (const char *oids = matchPrefix(key, "policy.")) {
84 maker.put(opCertPolicy);
85 maker.put(slot);
86 CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
87 maker.putData(oid.data(), oid.length());
88 } else {
89 throw antlr::SemanticException(key + ": unrecognized certificate field");
90 }
91 }
92
93 RequirementParser::RequirementParser(antlr::TokenBuffer& tokenBuf, int k)
94 : antlr::LLkParser(tokenBuf,k)
95 {
96 }
97
98 RequirementParser::RequirementParser(antlr::TokenBuffer& tokenBuf)
99 : antlr::LLkParser(tokenBuf,2)
100 {
101 }
102
103 RequirementParser::RequirementParser(antlr::TokenStream& lexer, int k)
104 : antlr::LLkParser(lexer,k)
105 {
106 }
107
108 RequirementParser::RequirementParser(antlr::TokenStream& lexer)
109 : antlr::LLkParser(lexer,2)
110 {
111 }
112
113 RequirementParser::RequirementParser(const antlr::ParserSharedInputState& state)
114 : antlr::LLkParser(state,2)
115 {
116 }
117
118 BlobCore * RequirementParser::autosense() {
119 BlobCore *result = NULL;
120
121 try { // for error handling
122 switch ( LA(1)) {
123 case LPAREN:
124 case NOT:
125 case LITERAL_always:
126 case LITERAL_true:
127 case LITERAL_never:
128 case LITERAL_false:
129 case LITERAL_identifier:
130 case LITERAL_cdhash:
131 case LITERAL_platform:
132 case LITERAL_anchor:
133 case LITERAL_certificate:
134 case LITERAL_cert:
135 case LITERAL_info:
136 case LITERAL_entitlement:
137 {
138 result=requirement();
139 break;
140 }
141 case LITERAL_guest:
142 case LITERAL_host:
143 case LITERAL_designated:
144 case LITERAL_library:
145 case LITERAL_plugin:
146 case INTEGER:
147 {
148 result=requirementSet();
149 break;
150 }
151 default:
152 {
153 throw antlr::NoViableAltException(LT(1), getFilename());
154 }
155 }
156 }
157 catch (antlr::RecognitionException& ex) {
158 reportError(ex);
159 recover(ex,_tokenSet_0);
160 }
161 return result;
162 }
163
164 Requirement * RequirementParser::requirement() {
165 Requirement *result = NULL;
166
167 try { // for error handling
168 result=requirementElement();
169 match(antlr::Token::EOF_TYPE);
170 }
171 catch (antlr::RecognitionException& ex) {
172 reportError(ex);
173 recover(ex,_tokenSet_0);
174 }
175 return result;
176 }
177
178 Requirements * RequirementParser::requirementSet() {
179 Requirements *result = NULL;
180 Requirements::Maker maker;
181
182 try { // for error handling
183 { // ( ... )+
184 int _cnt4=0;
185 for (;;) {
186 if ((_tokenSet_1.member(LA(1)))) {
187 uint32_t t; Requirement *req;
188 t=requirementType();
189 match(ARROW);
190 req=requirementElement();
191 maker.add(t, req);
192 }
193 else {
194 if ( _cnt4>=1 ) { goto _loop4; } else {throw antlr::NoViableAltException(LT(1), getFilename());}
195 }
196
197 _cnt4++;
198 }
199 _loop4:;
200 } // ( ... )+
201 result = errors.empty() ? maker() : NULL;
202 match(antlr::Token::EOF_TYPE);
203 }
204 catch (antlr::RecognitionException& ex) {
205 reportError(ex);
206 recover(ex,_tokenSet_0);
207 }
208 return result;
209 }
210
211 uint32_t RequirementParser::requirementType() {
212 uint32_t type = kSecInvalidRequirementType;
213
214 try { // for error handling
215 switch ( LA(1)) {
216 case LITERAL_guest:
217 {
218 match(LITERAL_guest);
219 type = kSecGuestRequirementType;
220 break;
221 }
222 case LITERAL_host:
223 {
224 match(LITERAL_host);
225 type = kSecHostRequirementType;
226 break;
227 }
228 case LITERAL_designated:
229 {
230 match(LITERAL_designated);
231 type = kSecDesignatedRequirementType;
232 break;
233 }
234 case LITERAL_library:
235 {
236 match(LITERAL_library);
237 type = kSecLibraryRequirementType;
238 break;
239 }
240 case LITERAL_plugin:
241 {
242 match(LITERAL_plugin);
243 type = kSecPluginRequirementType;
244 break;
245 }
246 case INTEGER:
247 {
248 type=integer();
249 break;
250 }
251 default:
252 {
253 throw antlr::NoViableAltException(LT(1), getFilename());
254 }
255 }
256 }
257 catch (antlr::RecognitionException& ex) {
258 reportError(ex);
259 recover(ex,_tokenSet_2);
260 }
261 return type;
262 }
263
264 Requirement * RequirementParser::requirementElement() {
265 Requirement *result = NULL;
266 Requirement::Maker maker;
267
268 try { // for error handling
269 expr(maker);
270 result = maker();
271 { // ( ... )*
272 for (;;) {
273 if ((LA(1) == SEMI)) {
274 fluff();
275 }
276 else {
277 goto _loop9;
278 }
279
280 }
281 _loop9:;
282 } // ( ... )*
283 }
284 catch (antlr::RecognitionException& ex) {
285 reportError(ex);
286 recover(ex,_tokenSet_3);
287 }
288 return result;
289 }
290
291 int32_t RequirementParser::integer() {
292 int32_t result;
293 antlr::RefToken s = antlr::nullToken;
294
295 try { // for error handling
296 s = LT(1);
297 match(INTEGER);
298 result = int32_t(atol(s->getText().c_str()));
299 }
300 catch (antlr::RecognitionException& ex) {
301 reportError(ex);
302 recover(ex,_tokenSet_4);
303 }
304 return result;
305 }
306
307 void RequirementParser::expr(
308 Maker &maker
309 ) {
310 Maker::Label label(maker);
311
312 try { // for error handling
313 term(maker);
314 { // ( ... )*
315 for (;;) {
316 if ((LA(1) == LITERAL_or)) {
317 match(LITERAL_or);
318 maker.insert<ExprOp>(label) = opOr;
319 term(maker);
320 }
321 else {
322 goto _loop12;
323 }
324
325 }
326 _loop12:;
327 } // ( ... )*
328 }
329 catch (antlr::RecognitionException& ex) {
330 reportError(ex);
331 recover(ex,_tokenSet_5);
332 }
333 }
334
335 void RequirementParser::fluff() {
336
337 try { // for error handling
338 match(SEMI);
339 }
340 catch (antlr::RecognitionException& ex) {
341 reportError(ex);
342 recover(ex,_tokenSet_6);
343 }
344 }
345
346 void RequirementParser::term(
347 Maker &maker
348 ) {
349 Maker::Label label(maker);
350
351 try { // for error handling
352 primary(maker);
353 { // ( ... )*
354 for (;;) {
355 if ((LA(1) == LITERAL_and)) {
356 match(LITERAL_and);
357 maker.insert<ExprOp>(label) = opAnd;
358 primary(maker);
359 }
360 else {
361 goto _loop15;
362 }
363
364 }
365 _loop15:;
366 } // ( ... )*
367 }
368 catch (antlr::RecognitionException& ex) {
369 reportError(ex);
370 recover(ex,_tokenSet_7);
371 }
372 }
373
374 void RequirementParser::primary(
375 Maker &maker
376 ) {
377
378 try { // for error handling
379 switch ( LA(1)) {
380 case NOT:
381 {
382 match(NOT);
383 maker.put(opNot);
384 primary(maker);
385 break;
386 }
387 case LITERAL_always:
388 case LITERAL_true:
389 {
390 {
391 switch ( LA(1)) {
392 case LITERAL_always:
393 {
394 match(LITERAL_always);
395 break;
396 }
397 case LITERAL_true:
398 {
399 match(LITERAL_true);
400 break;
401 }
402 default:
403 {
404 throw antlr::NoViableAltException(LT(1), getFilename());
405 }
406 }
407 }
408 maker.put(opTrue);
409 break;
410 }
411 case LITERAL_never:
412 case LITERAL_false:
413 {
414 {
415 switch ( LA(1)) {
416 case LITERAL_never:
417 {
418 match(LITERAL_never);
419 break;
420 }
421 case LITERAL_false:
422 {
423 match(LITERAL_false);
424 break;
425 }
426 default:
427 {
428 throw antlr::NoViableAltException(LT(1), getFilename());
429 }
430 }
431 }
432 maker.put(opFalse);
433 break;
434 }
435 case LITERAL_anchor:
436 case LITERAL_certificate:
437 case LITERAL_cert:
438 {
439 certspec(maker);
440 break;
441 }
442 case LITERAL_info:
443 {
444 infospec(maker);
445 break;
446 }
447 case LITERAL_entitlement:
448 {
449 entitlementspec(maker);
450 break;
451 }
452 case LITERAL_identifier:
453 {
454 match(LITERAL_identifier);
455 string code;
456 eql();
457 code=identifierString();
458 maker.ident(code);
459 break;
460 }
461 case LITERAL_cdhash:
462 {
463 match(LITERAL_cdhash);
464 SHA1::Digest digest;
465 eql();
466 hash(digest);
467 maker.cdhash(digest);
468 break;
469 }
470 case LITERAL_platform:
471 {
472 match(LITERAL_platform);
473 int32_t ident;
474 eql();
475 ident=integer();
476 maker.platform(ident);
477 break;
478 }
479 default:
480 if ((LA(1) == LPAREN) && (_tokenSet_8.member(LA(2)))) {
481 match(LPAREN);
482 expr(maker);
483 match(RPAREN);
484 }
485 else if ((LA(1) == LPAREN) && (LA(2) == DOTKEY || LA(2) == STRING)) {
486 match(LPAREN);
487 string name;
488 name=identifierString();
489 match(RPAREN);
490 maker.put(opNamedCode); maker.put(name);
491 }
492 else {
493 throw antlr::NoViableAltException(LT(1), getFilename());
494 }
495 }
496 }
497 catch (antlr::RecognitionException& ex) {
498 reportError(ex);
499 recover(ex,_tokenSet_9);
500 }
501 }
502
503 void RequirementParser::certspec(
504 Maker &maker
505 ) {
506
507 try { // for error handling
508 if ((LA(1) == LITERAL_anchor) && (LA(2) == LITERAL_apple)) {
509 match(LITERAL_anchor);
510 match(LITERAL_apple);
511 appleanchor(maker);
512 }
513 else if ((LA(1) == LITERAL_anchor) && (LA(2) == LITERAL_generic)) {
514 match(LITERAL_anchor);
515 match(LITERAL_generic);
516 match(LITERAL_apple);
517 maker.put(opAppleGenericAnchor);
518 }
519 else if ((LA(1) == LITERAL_anchor || LA(1) == LITERAL_certificate || LA(1) == LITERAL_cert) && (LA(2) == LITERAL_trusted)) {
520 {
521 switch ( LA(1)) {
522 case LITERAL_certificate:
523 {
524 match(LITERAL_certificate);
525 break;
526 }
527 case LITERAL_cert:
528 {
529 match(LITERAL_cert);
530 break;
531 }
532 case LITERAL_anchor:
533 {
534 match(LITERAL_anchor);
535 break;
536 }
537 default:
538 {
539 throw antlr::NoViableAltException(LT(1), getFilename());
540 }
541 }
542 }
543 match(LITERAL_trusted);
544 maker.trustedAnchor();
545 }
546 else if ((LA(1) == LITERAL_certificate || LA(1) == LITERAL_cert) && (_tokenSet_10.member(LA(2)))) {
547 {
548 switch ( LA(1)) {
549 case LITERAL_certificate:
550 {
551 match(LITERAL_certificate);
552 break;
553 }
554 case LITERAL_cert:
555 {
556 match(LITERAL_cert);
557 break;
558 }
559 default:
560 {
561 throw antlr::NoViableAltException(LT(1), getFilename());
562 }
563 }
564 }
565 int32_t slot;
566 slot=certSlot();
567 {
568 switch ( LA(1)) {
569 case EQL:
570 case EQQL:
571 case LBRACK:
572 case HASHCONSTANT:
573 case DOTKEY:
574 case STRING:
575 case PATHNAME:
576 {
577 certslotspec(maker, slot);
578 break;
579 }
580 case LITERAL_trusted:
581 {
582 match(LITERAL_trusted);
583 maker.trustedAnchor(slot);
584 break;
585 }
586 default:
587 {
588 throw antlr::NoViableAltException(LT(1), getFilename());
589 }
590 }
591 }
592 }
593 else if ((LA(1) == LITERAL_anchor) && (_tokenSet_11.member(LA(2)))) {
594 match(LITERAL_anchor);
595 certslotspec(maker, Requirement::anchorCert);
596 }
597 else {
598 throw antlr::NoViableAltException(LT(1), getFilename());
599 }
600
601 }
602 catch (antlr::RecognitionException& ex) {
603 reportError(ex);
604 recover(ex,_tokenSet_9);
605 }
606 }
607
608 void RequirementParser::infospec(
609 Maker &maker
610 ) {
611 string key;
612
613 try { // for error handling
614 match(LITERAL_info);
615 key=bracketKey();
616 maker.put(opInfoKeyField); maker.put(key);
617 match_suffix(maker);
618 }
619 catch (antlr::RecognitionException& ex) {
620 reportError(ex);
621 recover(ex,_tokenSet_9);
622 }
623 }
624
625 void RequirementParser::entitlementspec(
626 Maker &maker
627 ) {
628 string key;
629
630 try { // for error handling
631 match(LITERAL_entitlement);
632 key=bracketKey();
633 maker.put(opEntitlementField); maker.put(key);
634 match_suffix(maker);
635 }
636 catch (antlr::RecognitionException& ex) {
637 reportError(ex);
638 recover(ex,_tokenSet_9);
639 }
640 }
641
642 void RequirementParser::eql() {
643
644 try { // for error handling
645 switch ( LA(1)) {
646 case EQL:
647 {
648 match(EQL);
649 break;
650 }
651 case EQQL:
652 {
653 match(EQQL);
654 break;
655 }
656 case HASHCONSTANT:
657 case DOTKEY:
658 case STRING:
659 case PATHNAME:
660 case INTEGER:
661 {
662 empty();
663 break;
664 }
665 default:
666 {
667 throw antlr::NoViableAltException(LT(1), getFilename());
668 }
669 }
670 }
671 catch (antlr::RecognitionException& ex) {
672 reportError(ex);
673 recover(ex,_tokenSet_12);
674 }
675 }
676
677 string RequirementParser::identifierString() {
678 string result;
679 antlr::RefToken dk = antlr::nullToken;
680 antlr::RefToken s = antlr::nullToken;
681
682 try { // for error handling
683 switch ( LA(1)) {
684 case DOTKEY:
685 {
686 dk = LT(1);
687 match(DOTKEY);
688 result = dk->getText();
689 break;
690 }
691 case STRING:
692 {
693 s = LT(1);
694 match(STRING);
695 result = s->getText();
696 break;
697 }
698 default:
699 {
700 throw antlr::NoViableAltException(LT(1), getFilename());
701 }
702 }
703 }
704 catch (antlr::RecognitionException& ex) {
705 reportError(ex);
706 recover(ex,_tokenSet_9);
707 }
708 return result;
709 }
710
711 void RequirementParser::hash(
712 SHA1::Digest digest
713 ) {
714 antlr::RefToken hash = antlr::nullToken;
715
716 try { // for error handling
717 hash = LT(1);
718 match(HASHCONSTANT);
719 hashString(hash->getText(), digest);
720 }
721 catch (antlr::RecognitionException& ex) {
722 reportError(ex);
723 recover(ex,_tokenSet_9);
724 }
725 }
726
727 void RequirementParser::appleanchor(
728 Maker &maker
729 ) {
730
731 try { // for error handling
732 switch ( LA(1)) {
733 case antlr::Token::EOF_TYPE:
734 case LITERAL_guest:
735 case LITERAL_host:
736 case LITERAL_designated:
737 case LITERAL_library:
738 case LITERAL_plugin:
739 case LITERAL_or:
740 case LITERAL_and:
741 case RPAREN:
742 case INTEGER:
743 case SEMI:
744 {
745 empty();
746 maker.put(opAppleAnchor);
747 break;
748 }
749 case LITERAL_generic:
750 {
751 match(LITERAL_generic);
752 maker.put(opAppleGenericAnchor);
753 break;
754 }
755 case DOTKEY:
756 case STRING:
757 {
758 string name;
759 name=identifierString();
760 maker.put(opNamedAnchor); maker.put(name);
761 break;
762 }
763 default:
764 {
765 throw antlr::NoViableAltException(LT(1), getFilename());
766 }
767 }
768 }
769 catch (antlr::RecognitionException& ex) {
770 reportError(ex);
771 recover(ex,_tokenSet_9);
772 }
773 }
774
775 int32_t RequirementParser::certSlot() {
776 int32_t slot = 0;
777
778 try { // for error handling
779 switch ( LA(1)) {
780 case INTEGER:
781 {
782 slot=integer();
783 break;
784 }
785 case NEG:
786 {
787 match(NEG);
788 slot=integer();
789 slot = -slot;
790 break;
791 }
792 case LITERAL_leaf:
793 {
794 match(LITERAL_leaf);
795 slot = Requirement::leafCert;
796 break;
797 }
798 case LITERAL_root:
799 {
800 match(LITERAL_root);
801 slot = Requirement::anchorCert;
802 break;
803 }
804 default:
805 {
806 throw antlr::NoViableAltException(LT(1), getFilename());
807 }
808 }
809 }
810 catch (antlr::RecognitionException& ex) {
811 reportError(ex);
812 recover(ex,_tokenSet_13);
813 }
814 return slot;
815 }
816
817 void RequirementParser::certslotspec(
818 Maker &maker, int32_t slot
819 ) {
820 string key;
821
822 try { // for error handling
823 switch ( LA(1)) {
824 case EQL:
825 case EQQL:
826 case HASHCONSTANT:
827 case DOTKEY:
828 case STRING:
829 case PATHNAME:
830 {
831 eql();
832 SHA1::Digest digest;
833 certificateDigest(digest);
834 maker.anchor(slot, digest);
835 break;
836 }
837 case LBRACK:
838 {
839 key=bracketKey();
840 certMatchOperation(maker, slot, key);
841 match_suffix(maker);
842 break;
843 }
844 default:
845 {
846 throw antlr::NoViableAltException(LT(1), getFilename());
847 }
848 }
849 }
850 catch (antlr::RecognitionException& ex) {
851 reportError(ex);
852 recover(ex,_tokenSet_9);
853 }
854 }
855
856 void RequirementParser::empty() {
857
858 try { // for error handling
859 }
860 catch (antlr::RecognitionException& ex) {
861 reportError(ex);
862 recover(ex,_tokenSet_14);
863 }
864 }
865
866 void RequirementParser::certificateDigest(
867 SHA1::Digest digest
868 ) {
869
870 try { // for error handling
871 switch ( LA(1)) {
872 case HASHCONSTANT:
873 {
874 hash(digest);
875 break;
876 }
877 case DOTKEY:
878 case STRING:
879 case PATHNAME:
880 {
881 string path;
882 path=pathstring();
883 if (CFRef<CFDataRef> certData = cfLoadFile(path))
884 hashOfCertificate(CFDataGetBytePtr(certData), CFDataGetLength(certData), digest);
885 else
886 throw antlr::SemanticException(path + ": not found");
887
888 break;
889 }
890 default:
891 {
892 throw antlr::NoViableAltException(LT(1), getFilename());
893 }
894 }
895 }
896 catch (antlr::RecognitionException& ex) {
897 reportError(ex);
898 recover(ex,_tokenSet_9);
899 }
900 }
901
902 string RequirementParser::bracketKey() {
903 string key;
904
905 try { // for error handling
906 match(LBRACK);
907 key=stringvalue();
908 match(RBRACK);
909 }
910 catch (antlr::RecognitionException& ex) {
911 reportError(ex);
912 recover(ex,_tokenSet_15);
913 }
914 return key;
915 }
916
917 void RequirementParser::match_suffix(
918 Maker &maker
919 ) {
920
921 try { // for error handling
922 switch ( LA(1)) {
923 case antlr::Token::EOF_TYPE:
924 case LITERAL_guest:
925 case LITERAL_host:
926 case LITERAL_designated:
927 case LITERAL_library:
928 case LITERAL_plugin:
929 case LITERAL_or:
930 case LITERAL_and:
931 case RPAREN:
932 case LITERAL_exists:
933 case INTEGER:
934 case SEMI:
935 {
936 empty();
937 {
938 switch ( LA(1)) {
939 case LITERAL_exists:
940 {
941 match(LITERAL_exists);
942 break;
943 }
944 case antlr::Token::EOF_TYPE:
945 case LITERAL_guest:
946 case LITERAL_host:
947 case LITERAL_designated:
948 case LITERAL_library:
949 case LITERAL_plugin:
950 case LITERAL_or:
951 case LITERAL_and:
952 case RPAREN:
953 case INTEGER:
954 case SEMI:
955 {
956 break;
957 }
958 default:
959 {
960 throw antlr::NoViableAltException(LT(1), getFilename());
961 }
962 }
963 }
964 maker.put(matchExists);
965 break;
966 }
967 case EQL:
968 case EQQL:
969 {
970 {
971 switch ( LA(1)) {
972 case EQL:
973 {
974 match(EQL);
975 break;
976 }
977 case EQQL:
978 {
979 match(EQQL);
980 break;
981 }
982 default:
983 {
984 throw antlr::NoViableAltException(LT(1), getFilename());
985 }
986 }
987 }
988 MatchOperation mop = matchEqual; string value;
989 {
990 switch ( LA(1)) {
991 case STAR:
992 {
993 match(STAR);
994 mop = matchEndsWith;
995 break;
996 }
997 case HEXCONSTANT:
998 case DOTKEY:
999 case STRING:
1000 {
1001 break;
1002 }
1003 default:
1004 {
1005 throw antlr::NoViableAltException(LT(1), getFilename());
1006 }
1007 }
1008 }
1009 value=datavalue();
1010 {
1011 switch ( LA(1)) {
1012 case STAR:
1013 {
1014 match(STAR);
1015 mop = (mop == matchEndsWith) ? matchContains : matchBeginsWith;
1016 break;
1017 }
1018 case antlr::Token::EOF_TYPE:
1019 case LITERAL_guest:
1020 case LITERAL_host:
1021 case LITERAL_designated:
1022 case LITERAL_library:
1023 case LITERAL_plugin:
1024 case LITERAL_or:
1025 case LITERAL_and:
1026 case RPAREN:
1027 case INTEGER:
1028 case SEMI:
1029 {
1030 break;
1031 }
1032 default:
1033 {
1034 throw antlr::NoViableAltException(LT(1), getFilename());
1035 }
1036 }
1037 }
1038 maker.put(mop); maker.put(value);
1039 break;
1040 }
1041 case SUBS:
1042 {
1043 match(SUBS);
1044 string value;
1045 value=datavalue();
1046 maker.put(matchContains); maker.put(value);
1047 break;
1048 }
1049 case LESS:
1050 {
1051 match(LESS);
1052 string value;
1053 value=datavalue();
1054 maker.put(matchLessThan); maker.put(value);
1055 break;
1056 }
1057 case GT:
1058 {
1059 match(GT);
1060 string value;
1061 value=datavalue();
1062 maker.put(matchGreaterThan); maker.put(value);
1063 break;
1064 }
1065 case LE:
1066 {
1067 match(LE);
1068 string value;
1069 value=datavalue();
1070 maker.put(matchLessEqual); maker.put(value);
1071 break;
1072 }
1073 case GE:
1074 {
1075 match(GE);
1076 string value;
1077 value=datavalue();
1078 maker.put(matchGreaterEqual); maker.put(value);
1079 break;
1080 }
1081 default:
1082 {
1083 throw antlr::NoViableAltException(LT(1), getFilename());
1084 }
1085 }
1086 }
1087 catch (antlr::RecognitionException& ex) {
1088 reportError(ex);
1089 recover(ex,_tokenSet_9);
1090 }
1091 }
1092
1093 string RequirementParser::datavalue() {
1094 string result;
1095 antlr::RefToken hex = antlr::nullToken;
1096
1097 try { // for error handling
1098 switch ( LA(1)) {
1099 case DOTKEY:
1100 case STRING:
1101 {
1102 result=stringvalue();
1103 break;
1104 }
1105 case HEXCONSTANT:
1106 {
1107 hex = LT(1);
1108 match(HEXCONSTANT);
1109 result = hexString(hex->getText());
1110 break;
1111 }
1112 default:
1113 {
1114 throw antlr::NoViableAltException(LT(1), getFilename());
1115 }
1116 }
1117 }
1118 catch (antlr::RecognitionException& ex) {
1119 reportError(ex);
1120 recover(ex,_tokenSet_16);
1121 }
1122 return result;
1123 }
1124
1125 string RequirementParser::stringvalue() {
1126 string result;
1127 antlr::RefToken dk = antlr::nullToken;
1128 antlr::RefToken s = antlr::nullToken;
1129
1130 try { // for error handling
1131 switch ( LA(1)) {
1132 case DOTKEY:
1133 {
1134 dk = LT(1);
1135 match(DOTKEY);
1136 result = dk->getText();
1137 break;
1138 }
1139 case STRING:
1140 {
1141 s = LT(1);
1142 match(STRING);
1143 result = s->getText();
1144 break;
1145 }
1146 default:
1147 {
1148 throw antlr::NoViableAltException(LT(1), getFilename());
1149 }
1150 }
1151 }
1152 catch (antlr::RecognitionException& ex) {
1153 reportError(ex);
1154 recover(ex,_tokenSet_17);
1155 }
1156 return result;
1157 }
1158
1159 string RequirementParser::pathstring() {
1160 string result;
1161 antlr::RefToken dk = antlr::nullToken;
1162 antlr::RefToken s = antlr::nullToken;
1163 antlr::RefToken pn = antlr::nullToken;
1164
1165 try { // for error handling
1166 switch ( LA(1)) {
1167 case DOTKEY:
1168 {
1169 dk = LT(1);
1170 match(DOTKEY);
1171 result = dk->getText();
1172 break;
1173 }
1174 case STRING:
1175 {
1176 s = LT(1);
1177 match(STRING);
1178 result = s->getText();
1179 break;
1180 }
1181 case PATHNAME:
1182 {
1183 pn = LT(1);
1184 match(PATHNAME);
1185 result = pn->getText();
1186 break;
1187 }
1188 default:
1189 {
1190 throw antlr::NoViableAltException(LT(1), getFilename());
1191 }
1192 }
1193 }
1194 catch (antlr::RecognitionException& ex) {
1195 reportError(ex);
1196 recover(ex,_tokenSet_9);
1197 }
1198 return result;
1199 }
1200
1201 void RequirementParser::initializeASTFactory( antlr::ASTFactory& )
1202 {
1203 }
1204 const char* RequirementParser::tokenNames[] = {
1205 "<0>",
1206 "EOF",
1207 "<2>",
1208 "NULL_TREE_LOOKAHEAD",
1209 "ARROW",
1210 "\"guest\"",
1211 "\"host\"",
1212 "\"designated\"",
1213 "\"library\"",
1214 "\"plugin\"",
1215 "\"or\"",
1216 "\"and\"",
1217 "LPAREN",
1218 "RPAREN",
1219 "NOT",
1220 "\"always\"",
1221 "\"true\"",
1222 "\"never\"",
1223 "\"false\"",
1224 "\"identifier\"",
1225 "\"cdhash\"",
1226 "\"platform\"",
1227 "\"anchor\"",
1228 "\"apple\"",
1229 "\"generic\"",
1230 "\"certificate\"",
1231 "\"cert\"",
1232 "\"trusted\"",
1233 "\"info\"",
1234 "\"entitlement\"",
1235 "\"exists\"",
1236 "EQL",
1237 "EQQL",
1238 "STAR",
1239 "SUBS",
1240 "LESS",
1241 "GT",
1242 "LE",
1243 "GE",
1244 "LBRACK",
1245 "RBRACK",
1246 "NEG",
1247 "\"leaf\"",
1248 "\"root\"",
1249 "HASHCONSTANT",
1250 "HEXCONSTANT",
1251 "DOTKEY",
1252 "STRING",
1253 "PATHNAME",
1254 "INTEGER",
1255 "SEMI",
1256 "IDENT",
1257 "HEX",
1258 "COMMA",
1259 "WS",
1260 "SHELLCOMMENT",
1261 "C_COMMENT",
1262 "CPP_COMMENT",
1263 0
1264 };
1265
1266 const unsigned long RequirementParser::_tokenSet_0_data_[] = { 2UL, 0UL, 0UL, 0UL };
1267 // EOF
1268 const antlr::BitSet RequirementParser::_tokenSet_0(_tokenSet_0_data_,4);
1269 const unsigned long RequirementParser::_tokenSet_1_data_[] = { 992UL, 131072UL, 0UL, 0UL };
1270 // "guest" "host" "designated" "library" "plugin" INTEGER
1271 const antlr::BitSet RequirementParser::_tokenSet_1(_tokenSet_1_data_,4);
1272 const unsigned long RequirementParser::_tokenSet_2_data_[] = { 16UL, 0UL, 0UL, 0UL };
1273 // ARROW
1274 const antlr::BitSet RequirementParser::_tokenSet_2(_tokenSet_2_data_,4);
1275 const unsigned long RequirementParser::_tokenSet_3_data_[] = { 994UL, 131072UL, 0UL, 0UL };
1276 // EOF "guest" "host" "designated" "library" "plugin" INTEGER
1277 const antlr::BitSet RequirementParser::_tokenSet_3(_tokenSet_3_data_,4);
1278 const unsigned long RequirementParser::_tokenSet_4_data_[] = { 2281713650UL, 512129UL, 0UL, 0UL };
1279 // EOF ARROW "guest" "host" "designated" "library" "plugin" "or" "and"
1280 // RPAREN "trusted" EQL EQQL LBRACK HASHCONSTANT DOTKEY STRING PATHNAME
1281 // INTEGER SEMI
1282 const antlr::BitSet RequirementParser::_tokenSet_4(_tokenSet_4_data_,4);
1283 const unsigned long RequirementParser::_tokenSet_5_data_[] = { 9186UL, 393216UL, 0UL, 0UL };
1284 // EOF "guest" "host" "designated" "library" "plugin" RPAREN INTEGER SEMI
1285 const antlr::BitSet RequirementParser::_tokenSet_5(_tokenSet_5_data_,4);
1286 const unsigned long RequirementParser::_tokenSet_6_data_[] = { 994UL, 393216UL, 0UL, 0UL };
1287 // EOF "guest" "host" "designated" "library" "plugin" INTEGER SEMI
1288 const antlr::BitSet RequirementParser::_tokenSet_6(_tokenSet_6_data_,4);
1289 const unsigned long RequirementParser::_tokenSet_7_data_[] = { 10210UL, 393216UL, 0UL, 0UL };
1290 // EOF "guest" "host" "designated" "library" "plugin" "or" RPAREN INTEGER
1291 // SEMI
1292 const antlr::BitSet RequirementParser::_tokenSet_7(_tokenSet_7_data_,4);
1293 const unsigned long RequirementParser::_tokenSet_8_data_[] = { 914345984UL, 0UL, 0UL, 0UL };
1294 // LPAREN NOT "always" "true" "never" "false" "identifier" "cdhash" "platform"
1295 // "anchor" "certificate" "cert" "info" "entitlement"
1296 const antlr::BitSet RequirementParser::_tokenSet_8(_tokenSet_8_data_,4);
1297 const unsigned long RequirementParser::_tokenSet_9_data_[] = { 12258UL, 393216UL, 0UL, 0UL };
1298 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1299 // INTEGER SEMI
1300 const antlr::BitSet RequirementParser::_tokenSet_9(_tokenSet_9_data_,4);
1301 const unsigned long RequirementParser::_tokenSet_10_data_[] = { 0UL, 134656UL, 0UL, 0UL };
1302 // NEG "leaf" "root" INTEGER
1303 const antlr::BitSet RequirementParser::_tokenSet_10(_tokenSet_10_data_,4);
1304 const unsigned long RequirementParser::_tokenSet_11_data_[] = { 2147483648UL, 118913UL, 0UL, 0UL };
1305 // EQL EQQL LBRACK HASHCONSTANT DOTKEY STRING PATHNAME
1306 const antlr::BitSet RequirementParser::_tokenSet_11(_tokenSet_11_data_,4);
1307 const unsigned long RequirementParser::_tokenSet_12_data_[] = { 0UL, 249856UL, 0UL, 0UL };
1308 // HASHCONSTANT DOTKEY STRING PATHNAME INTEGER
1309 const antlr::BitSet RequirementParser::_tokenSet_12(_tokenSet_12_data_,4);
1310 const unsigned long RequirementParser::_tokenSet_13_data_[] = { 2281701376UL, 118913UL, 0UL, 0UL };
1311 // "trusted" EQL EQQL LBRACK HASHCONSTANT DOTKEY STRING PATHNAME
1312 const antlr::BitSet RequirementParser::_tokenSet_13(_tokenSet_13_data_,4);
1313 const unsigned long RequirementParser::_tokenSet_14_data_[] = { 1073754082UL, 512000UL, 0UL, 0UL };
1314 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1315 // "exists" HASHCONSTANT DOTKEY STRING PATHNAME INTEGER SEMI
1316 const antlr::BitSet RequirementParser::_tokenSet_14(_tokenSet_14_data_,4);
1317 const unsigned long RequirementParser::_tokenSet_15_data_[] = { 3221237730UL, 393341UL, 0UL, 0UL };
1318 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1319 // "exists" EQL EQQL SUBS LESS GT LE GE INTEGER SEMI
1320 const antlr::BitSet RequirementParser::_tokenSet_15(_tokenSet_15_data_,4);
1321 const unsigned long RequirementParser::_tokenSet_16_data_[] = { 12258UL, 393218UL, 0UL, 0UL };
1322 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1323 // STAR INTEGER SEMI
1324 const antlr::BitSet RequirementParser::_tokenSet_16(_tokenSet_16_data_,4);
1325 const unsigned long RequirementParser::_tokenSet_17_data_[] = { 12258UL, 393474UL, 0UL, 0UL };
1326 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1327 // STAR RBRACK INTEGER SEMI
1328 const antlr::BitSet RequirementParser::_tokenSet_17(_tokenSet_17_data_,4);
1329
1330
1331 ANTLR_END_NAMESPACE