X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5dd5f9ec28f304ca377c42fd7f711d6cf12b90e1..5c19dc3ae3bd8e40a9c028b0deddd50ff337692c:/Security/libsecurity_codesigning/lib/antlrplugin.cpp?ds=sidebyside diff --git a/Security/libsecurity_codesigning/lib/antlrplugin.cpp b/Security/libsecurity_codesigning/lib/antlrplugin.cpp deleted file mode 100644 index 0e4dee56..00000000 --- a/Security/libsecurity_codesigning/lib/antlrplugin.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2007,2011-2012 Apple Inc. All Rights Reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ - -#include "antlrplugin.h" -#include "cserror.h" -#include "RequirementLexer.hpp" -#include "RequirementParser.hpp" -#include - - -namespace Security { -namespace CodeSigning { - -namespace Parser = Security_CodeSigning; - - -// -// Lexer input adapters -// -class StdioInputStream : public antlr::InputBuffer { -public: - StdioInputStream(FILE *fp) : mFile(fp) { } - int getChar() { return fgetc(mFile); } - -private: - FILE *mFile; -}; - -class StringInputStream : public antlr::InputBuffer { -public: - StringInputStream(const string &s) : mInput(s), mPos(mInput.begin()) { } - int getChar() { return (mPos == mInput.end()) ? EOF : *mPos++; } - -private: - string mInput; - string::const_iterator mPos; -}; - - -// -// Generic parser driver -// -template -const Result *parse(Source source, Result *(Parser::RequirementParser::*rule)(), std::string &errors) -{ - Input input(source); - Parser::RequirementLexer lexer(input); - Parser::RequirementParser parser(lexer); - try { - const Result *result = (parser.*rule)(); - errors = parser.errors; - if (errors.empty()) - return result; - else - ::free((void *)result); - } catch (const antlr::TokenStreamException &ex) { - errors = ex.toString() + "\n"; - } - return NULL; // signal failure -} - - -// -// Hook up each supported parsing action to the plugin interface -// -static -const Requirement *fileRequirement(FILE *source, string &errors) -{ return parse(source, &Parser::RequirementParser::requirement, errors); } - -static -const Requirement *stringRequirement(string source, string &errors) -{ return parse(source, &Parser::RequirementParser::requirement, errors); } - -static -const Requirements *fileRequirements(FILE *source, string &errors) -{ return parse(source, &Parser::RequirementParser::requirementSet, errors); } - -static -const Requirements *stringRequirements(string source, string &errors) -{ return parse(source, &Parser::RequirementParser::requirementSet, errors); } - -static -const BlobCore *fileGeneric(FILE *source, string &errors) -{ return parse(source, &Parser::RequirementParser::autosense, errors); } - -static -const BlobCore *stringGeneric(string source, string &errors) -{ return parse(source, &Parser::RequirementParser::autosense, errors); } - - -// -// Basic plugin hookup -// -static AntlrPlugin plugin = { - fileRequirement, - fileRequirements, - fileGeneric, - stringRequirement, - stringRequirements, - stringGeneric -}; - -AntlrPlugin *findAntlrPlugin() -{ - return &plugin; -} - - -} // end namespace CodeSigning -} // end namespace Security