001 /****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one *
003 * or more contributor license agreements. See the NOTICE file *
004 * distributed with this work for additional information *
005 * regarding copyright ownership. The ASF licenses this file *
006 * to you under the Apache License, Version 2.0 (the *
007 * "License"); you may not use this file except in compliance *
008 * with the License. You may obtain a copy of the License at *
009 * *
010 * http://www.apache.org/licenses/LICENSE-2.0 *
011 * *
012 * Unless required by applicable law or agreed to in writing, *
013 * software distributed under the License is distributed on an *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015 * KIND, either express or implied. See the License for the *
016 * specific language governing permissions and limitations *
017 * under the License. *
018 ****************************************************************/
019
020 package org.apache.james.jspf.core;
021
022 /**
023 * This constants are used by Terms to define their matching rules.
024 */
025 public interface SPFTermsRegexps {
026
027
028 final String ALPHA_PATTERN = "[a-zA-Z]";
029
030 final String MACRO_LETTER_PATTERN_EXP = "[rctlsodipvhRCTLSODIPVH]";
031
032 final String MACRO_LETTER_PATTERN = "[lsodipvhLSODIPVH]";
033
034 final String TRANSFORMERS_REGEX = "\\d*[r]?";
035
036 final String DELEMITER_REGEX = "[\\.\\-\\+,/_\\=]";
037
038 final String MACRO_LETTERS_REGEX = MACRO_LETTER_PATTERN_EXP + TRANSFORMERS_REGEX + DELEMITER_REGEX + "*";
039
040 final String MACRO_EXPAND_REGEX = "\\%(?:\\{"
041 + MACRO_LETTERS_REGEX + "\\}|\\%|\\_|\\-)";
042
043 final String MACRO_LITERAL_REGEX = "[\\x21-\\x24\\x26-\\x7e]";
044
045 /**
046 * This is used by the MacroExpander
047 */
048 final String MACRO_STRING_REGEX_TOKEN = MACRO_EXPAND_REGEX
049 + "|" + MACRO_LITERAL_REGEX + "{1}";
050
051
052 /**
053 * ABNF: macro-string = *( macro-expand / macro-literal )
054 */
055 final String MACRO_STRING_REGEX = "(?:" + MACRO_STRING_REGEX_TOKEN +")*";
056
057 final String ALPHA_DIGIT_PATTERN = "[a-zA-Z0-9]";
058
059 /**
060 * ABNF: toplabel = ( *alphanum ALPHA *alphanum ) / ( 1*alphanum "-" *(
061 * alphanum / "-" ) alphanum ) ; LDH rule plus additional TLD restrictions ;
062 * (see [RFC3696], Section 2)
063 */
064 final String TOP_LABEL_REGEX = "(?:"
065 + ALPHA_DIGIT_PATTERN + "*" + SPFTermsRegexps.ALPHA_PATTERN
066 + "{1}" + ALPHA_DIGIT_PATTERN + "*|(?:"
067 + ALPHA_DIGIT_PATTERN + "+" + "\\-" + "(?:"
068 + ALPHA_DIGIT_PATTERN + "|\\-)*"
069 + ALPHA_DIGIT_PATTERN + "))";
070
071 /**
072 * ABNF: domain-end = ( "." toplabel [ "." ] ) / macro-expand
073 */
074 final String DOMAIN_END_REGEX = "(?:\\." + TOP_LABEL_REGEX
075 + "\\.?" + "|" + SPFTermsRegexps.MACRO_EXPAND_REGEX + ")";
076
077 /**
078 * ABNF: domain-spec = macro-string domain-end
079 */
080 final String DOMAIN_SPEC_REGEX = "("
081 + SPFTermsRegexps.MACRO_STRING_REGEX + DOMAIN_END_REGEX + ")";
082
083 /**
084 * Spring MACRO_STRING from DOMAIN_END (domain end starts with .)
085 */
086 final String DOMAIN_SPEC_REGEX_R = "("
087 + SPFTermsRegexps.MACRO_STRING_REGEX + ")(" + DOMAIN_END_REGEX + ")";
088
089
090 }