00001
00002
00003
00004
00005
00006
00013
00014
00015
00016 #ifndef _LDAPFILTERPARSER_
00017 #define _LDAPFILTERPARSER_
00018
00019 #include <string>
00020 #include <stack>
00021 #include <vector>
00022
00023 namespace edg {
00024 namespace workload {
00025 namespace common {
00026 namespace ldif2classad {
00027
00031 struct token_t
00032 {
00033 enum type_t { none,
00034 filtercomp,
00035 attributetype,
00036 attributevalue,
00037 filtertype,
00038 bracket_open,
00039 bracket_close,
00040 simple_string,
00041 extended_string
00042 };
00043 token_t::token_t() { type = none; }
00044 token_t::token_t(token_t::type_t t, const std::string& v) {
00045 type = t;
00046 value = v;
00047 }
00048
00049 type_t type;
00050 std::string value;
00051 };
00052
00057 class LDAPFilterTokenizer
00058 {
00059 public:
00060
00061 enum filtercomp_t { AND = '&', OR = '|', NOT = '!' };
00062 enum filtertype_t { LIKE = '~', EQUAL = '=', LESS = '<', GREATER = '>'};
00063
00064 LDAPFilterTokenizer(const std::string& s);
00065 bool get_token(token_t& type);
00066 bool eof() const { return ( ipos == std::string::npos || ipos >= ifilter.length() ); }
00067 void break_on_reserved(bool v) { BORflag = v; }
00068
00069 private:
00070 std::string purify(const std::string& s) const;
00071
00072 private:
00073 std::string ifilter;
00074 size_t ipos;
00075 bool BORflag;
00076 };
00077
00082 class LDAPFilterParser
00083 {
00084 public:
00085 LDAPFilterParser() { }
00086 bool parse(const std::string& filter, std::string& p, std::vector<std::string>* = NULL);
00087 private:
00088 std::string make_expression( std::vector<std::string>* = NULL );
00089 bool parse_expression( std::vector<std::string>* = NULL );
00090
00091 private:
00092 std::stack<token_t> filtercomps;
00093 std::stack<std::string> parsedterms;
00094 };
00095
00096 }
00097 }
00098 }
00099 }
00100
00101
00102 #endif