Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | %{ |
michael@0 | 6 | |
michael@0 | 7 | #include "crlgen.h" |
michael@0 | 8 | |
michael@0 | 9 | static SECStatus parserStatus = SECSuccess; |
michael@0 | 10 | static CRLGENGeneratorData *parserData; |
michael@0 | 11 | static PRFileDesc *src; |
michael@0 | 12 | |
michael@0 | 13 | #define YY_INPUT(buf,result,max_size) \ |
michael@0 | 14 | if ( parserStatus != SECFailure) { \ |
michael@0 | 15 | if (((result = PR_Read(src, buf, max_size)) == 0) && \ |
michael@0 | 16 | ferror( yyin )) \ |
michael@0 | 17 | return SECFailure; \ |
michael@0 | 18 | } else { return SECFailure; } |
michael@0 | 19 | |
michael@0 | 20 | |
michael@0 | 21 | %} |
michael@0 | 22 | |
michael@0 | 23 | %a 5000 |
michael@0 | 24 | DIGIT [0-9]+ |
michael@0 | 25 | DIGIT_RANGE [0-9]+-[0-9]+ |
michael@0 | 26 | ID [a-zA-Z][a-zA-Z0-9]* |
michael@0 | 27 | OID [0-9]+\.[\.0-9]+ |
michael@0 | 28 | DATE [0-9]{4}[01][0-9][0-3][0-9][0-2][0-9][0-6][0-9][0-6][0-9] |
michael@0 | 29 | ZDATE [0-9]{4}[01][0-9][0-3][0-9][0-2][0-9][0-6][0-9][0-6][0-9]Z |
michael@0 | 30 | N_SP_STRING [a-zA-Z0-9\:\|\.]+ |
michael@0 | 31 | |
michael@0 | 32 | %% |
michael@0 | 33 | |
michael@0 | 34 | {ZDATE} { |
michael@0 | 35 | parserStatus = crlgen_setNextData(parserData, yytext, CRLGEN_TYPE_ZDATE); |
michael@0 | 36 | if (parserStatus != SECSuccess) |
michael@0 | 37 | return parserStatus; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | {DIGIT} { |
michael@0 | 41 | parserStatus = crlgen_setNextData(parserData, yytext, CRLGEN_TYPE_DIGIT); |
michael@0 | 42 | if (parserStatus != SECSuccess) |
michael@0 | 43 | return parserStatus; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | {DIGIT_RANGE} { |
michael@0 | 47 | parserStatus = crlgen_setNextData(parserData, yytext, CRLGEN_TYPE_DIGIT_RANGE); |
michael@0 | 48 | if (parserStatus != SECSuccess) |
michael@0 | 49 | return parserStatus; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | {OID} { |
michael@0 | 53 | parserStatus = crlgen_setNextData(parserData, yytext, CRLGEN_TYPE_OID); |
michael@0 | 54 | if (parserStatus != SECSuccess) |
michael@0 | 55 | return parserStatus; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | issuer { |
michael@0 | 59 | parserStatus = crlgen_createNewLangStruct(parserData, CRLGEN_ISSUER_CONTEXT); |
michael@0 | 60 | if (parserStatus != SECSuccess) |
michael@0 | 61 | return parserStatus; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | update { |
michael@0 | 65 | parserStatus = crlgen_createNewLangStruct(parserData, CRLGEN_UPDATE_CONTEXT); |
michael@0 | 66 | if (parserStatus != SECSuccess) |
michael@0 | 67 | return parserStatus; |
michael@0 | 68 | } |
michael@0 | 69 | nextupdate { |
michael@0 | 70 | parserStatus = crlgen_createNewLangStruct(parserData, CRLGEN_NEXT_UPDATE_CONTEXT); |
michael@0 | 71 | if (parserStatus != SECSuccess) |
michael@0 | 72 | return parserStatus; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | range { |
michael@0 | 76 | parserStatus = crlgen_createNewLangStruct(parserData, CRLGEN_CHANGE_RANGE_CONTEXT); |
michael@0 | 77 | if (parserStatus != SECSuccess) |
michael@0 | 78 | return parserStatus; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | {ID} { |
michael@0 | 82 | if (strcmp(yytext, "addcert") == 0) { |
michael@0 | 83 | parserStatus = crlgen_createNewLangStruct(parserData, |
michael@0 | 84 | CRLGEN_ADD_CERT_CONTEXT); |
michael@0 | 85 | if (parserStatus != SECSuccess) |
michael@0 | 86 | return parserStatus; |
michael@0 | 87 | } else if (strcmp(yytext, "rmcert") == 0) { |
michael@0 | 88 | parserStatus = crlgen_createNewLangStruct(parserData, |
michael@0 | 89 | CRLGEN_RM_CERT_CONTEXT); |
michael@0 | 90 | if (parserStatus != SECSuccess) |
michael@0 | 91 | return parserStatus; |
michael@0 | 92 | } else if (strcmp(yytext, "addext") == 0) { |
michael@0 | 93 | parserStatus = crlgen_createNewLangStruct(parserData, |
michael@0 | 94 | CRLGEN_ADD_EXTENSION_CONTEXT); |
michael@0 | 95 | if (parserStatus != SECSuccess) |
michael@0 | 96 | return parserStatus; |
michael@0 | 97 | } else { |
michael@0 | 98 | parserStatus = crlgen_setNextData(parserData, yytext, CRLGEN_TYPE_ID); |
michael@0 | 99 | if (parserStatus != SECSuccess) |
michael@0 | 100 | return parserStatus; |
michael@0 | 101 | } |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | "=" |
michael@0 | 105 | |
michael@0 | 106 | \"[^\"]* { |
michael@0 | 107 | if (yytext[yyleng-1] == '\\') { |
michael@0 | 108 | yymore(); |
michael@0 | 109 | } else { |
michael@0 | 110 | register int c; |
michael@0 | 111 | c = input(); |
michael@0 | 112 | if (c != '\"') { |
michael@0 | 113 | printf( "Error: Line ending \" is missing: %c\n", c); |
michael@0 | 114 | unput(c); |
michael@0 | 115 | } else { |
michael@0 | 116 | parserStatus = crlgen_setNextData(parserData, yytext + 1, |
michael@0 | 117 | CRLGEN_TYPE_STRING); |
michael@0 | 118 | if (parserStatus != SECSuccess) |
michael@0 | 119 | return parserStatus; |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | {N_SP_STRING} { |
michael@0 | 125 | parserStatus = crlgen_setNextData(parserData, yytext, CRLGEN_TYPE_STRING); |
michael@0 | 126 | if (parserStatus != SECSuccess) |
michael@0 | 127 | return parserStatus; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | |
michael@0 | 131 | |
michael@0 | 132 | ^#[^\n]* /* eat up one-line comments */ {} |
michael@0 | 133 | |
michael@0 | 134 | [ \t]+ {} |
michael@0 | 135 | |
michael@0 | 136 | (\n|\r\n) { |
michael@0 | 137 | parserStatus = crlgen_updateCrl(parserData); |
michael@0 | 138 | if (parserStatus != SECSuccess) |
michael@0 | 139 | return parserStatus; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | . { |
michael@0 | 143 | fprintf(stderr, "Syntax error at line %d: unknown token %s\n", |
michael@0 | 144 | parserData->parsedLineNum, yytext); |
michael@0 | 145 | return SECFailure; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | %% |
michael@0 | 149 | #include "prlock.h" |
michael@0 | 150 | |
michael@0 | 151 | static PRLock *parserInvocationLock; |
michael@0 | 152 | |
michael@0 | 153 | void CRLGEN_InitCrlGenParserLock() |
michael@0 | 154 | { |
michael@0 | 155 | parserInvocationLock = PR_NewLock(); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | void CRLGEN_DestroyCrlGenParserLock() |
michael@0 | 159 | { |
michael@0 | 160 | PR_DestroyLock(parserInvocationLock); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | |
michael@0 | 164 | SECStatus CRLGEN_StartCrlGen(CRLGENGeneratorData *parserCtlData) |
michael@0 | 165 | { |
michael@0 | 166 | SECStatus rv; |
michael@0 | 167 | |
michael@0 | 168 | PR_Lock(parserInvocationLock); |
michael@0 | 169 | |
michael@0 | 170 | parserStatus = SECSuccess; |
michael@0 | 171 | parserData = parserCtlData; |
michael@0 | 172 | src = parserCtlData->src; |
michael@0 | 173 | |
michael@0 | 174 | rv = yylex(); |
michael@0 | 175 | |
michael@0 | 176 | PR_Unlock(parserInvocationLock); |
michael@0 | 177 | |
michael@0 | 178 | return rv; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | int yywrap() {return 1;} |