]> err.no Git - sope/blob - sope-ldap/NGLdap/EOQualifier+LDAP.m
fixed some FHS issues
[sope] / sope-ldap / NGLdap / EOQualifier+LDAP.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "EOQualifier+LDAP.h"
24 #include "common.h"
25
26 #if NeXT_RUNTIME
27 #define sel_eq(sel1, sel2) ((sel1)) == ((sel2))
28 #endif
29
30 @interface EOQualifier(LDAPPrivates)
31
32 - (void)addToLDAPFilterString:(NSMutableString *)_s inContext:(id)_ctx;
33
34 @end
35
36 @implementation EOQualifier(LDAP)
37
38 - (id)initWithLDAPFilterString:(NSString *)_filter {
39   return nil;
40 }
41
42 - (void)addToLDAPFilterString:(NSMutableString *)_s inContext:(id)_ctx {
43   [self doesNotRecognizeSelector:_cmd]; // subclass
44 }
45
46 - (NSString *)ldapFilterString {
47   NSMutableString *s;
48   NSString *is;
49
50   s = [[NSMutableString alloc] initWithCapacity:100];
51   [self addToLDAPFilterString:s inContext:nil];
52   is = [s copy];
53   [s release];
54   return [is autorelease];
55 }
56
57 @end /* EOQualifier(LDAP) */
58
59 @implementation EOAndQualifier(LDAP)
60
61 - (void)addToLDAPFilterString:(NSMutableString *)_s inContext:(id)_ctx {
62   unsigned i, cnt;
63   NSArray  *array;
64
65   array = [self qualifiers];
66   cnt   = [array count];
67   
68   [_s appendString:@"(&"];
69   
70   for (i = 0; i < cnt; i++) {
71     EOQualifier *sq;
72
73     sq = [array objectAtIndex:i];
74     [sq addToLDAPFilterString:_s inContext:_ctx];
75   }
76   
77   [_s appendString:@")"];
78 }
79
80 @end /* EOAndQualifier(LDAP) */
81
82 @implementation EOOrQualifier(LDAP)
83
84 - (void)addToLDAPFilterString:(NSMutableString *)_s inContext:(id)_ctx {
85   unsigned i, cnt;
86   NSArray  *array;
87
88   array = [self qualifiers];
89   cnt   = [array count];
90   
91   [_s appendString:@"(|"];
92   
93   for (i = 0; i < cnt; i++) {
94     EOQualifier *sq;
95
96     sq = [array objectAtIndex:i];
97     [sq addToLDAPFilterString:_s inContext:_ctx];
98   }
99   
100   [_s appendString:@")"];
101 }
102
103 @end /* EOOrQualifier(LDAP) */
104
105 @implementation EONotQualifier(LDAP)
106
107 - (void)addToLDAPFilterString:(NSMutableString *)_s inContext:(id)_ctx {
108   [_s appendString:@"(!"];
109   [[self qualifier] addToLDAPFilterString:_s inContext:_ctx];
110   [_s appendString:@")"];
111 }
112
113 @end /* EONotQualifier(LDAP) */
114
115 @implementation EOKeyValueQualifier(LDAP)
116
117 - (void)addToLDAPFilterString:(NSMutableString *)_s inContext:(id)_ctx {
118   // TODO: patterns are treated like regular strings or the reverse?
119   SEL sel;
120
121   sel = [self selector];
122
123   if (sel_eq(sel,  EOQualifierOperatorNotEqual))
124     [_s appendString:@"(!"];
125   
126   [_s appendString:@"("];
127   [_s appendString:[self key]];
128
129   if (sel_eq(sel,  EOQualifierOperatorEqual))
130     [_s appendString:@"="];
131   else if (sel_eq(sel,  EOQualifierOperatorNotEqual))
132     [_s appendString:@"="];
133   else if (sel_eq(sel,  EOQualifierOperatorLessThan))
134     [_s appendString:@"<"];
135   else if (sel_eq(sel,  EOQualifierOperatorGreaterThan))
136     [_s appendString:@">"];
137   else if (sel_eq(sel,  EOQualifierOperatorLessThanOrEqualTo))
138     [_s appendString:@"<="];
139   else if (sel_eq(sel,  EOQualifierOperatorGreaterThanOrEqualTo))
140     [_s appendString:@">="];
141   else if (sel_eq(sel,  EOQualifierOperatorContains))
142     [_s appendString:@"=*"];
143   else if (sel_eq(sel,  EOQualifierOperatorLike))
144     [_s appendString:@"="];
145   else if (sel_eq(sel,  EOQualifierOperatorCaseInsensitiveLike))
146     [_s appendString:@"="];
147   else {
148     NSLog(@"UNKNOWN operator: %@", NSStringFromSelector([self selector]));
149     [_s appendString:@"="];
150   }
151
152   [_s appendString:[[self value] description]];
153   [_s appendString:@")"];
154   
155   if (sel_eq(sel,  EOQualifierOperatorNotEqual))
156     [_s appendString:@")"];
157 }
158
159 @end /* EOKeyValueQualifier(LDAP) */
160
161 @implementation EOKeyComparisonQualifier(LDAP)
162
163 - (void)addToLDAPFilterString:(NSMutableString *)_s inContext:(id)_ctx {
164   /* ldap supports no comparison operations on keys */
165   SEL sel;
166
167   sel = [self selector];
168
169   if (sel_eq(sel,  EOQualifierOperatorNotEqual))
170     [_s appendString:@"(!"];
171   
172   [_s appendString:@"("];
173   [_s appendString:[self leftKey]];
174
175   if (sel_eq(sel,  EOQualifierOperatorEqual))
176     [_s appendString:@"="];
177   else if (sel_eq(sel,  EOQualifierOperatorNotEqual))
178     [_s appendString:@"="];
179   else if (sel_eq(sel,  EOQualifierOperatorLessThan))
180     [_s appendString:@"<"];
181   else if (sel_eq(sel,  EOQualifierOperatorGreaterThan))
182     [_s appendString:@">"];
183   else if (sel_eq(sel,  EOQualifierOperatorLessThanOrEqualTo))
184     [_s appendString:@"<="];
185   else if (sel_eq(sel,  EOQualifierOperatorGreaterThanOrEqualTo))
186     [_s appendString:@">="];
187   else if (sel_eq(sel,  EOQualifierOperatorContains))
188     [_s appendString:@"=*"];
189   else if (sel_eq(sel,  EOQualifierOperatorLike))
190     [_s appendString:@"="];
191   else if (sel_eq(sel,  EOQualifierOperatorCaseInsensitiveLike))
192     [_s appendString:@"="];
193   else {
194     NSLog(@"UNKNOWN operator: %@", NSStringFromSelector([self selector]));
195     [_s appendString:@"="];
196   }
197
198   [_s appendString:[self rightKey]];
199   [_s appendString:@")"];
200   
201   if (sel_eq(sel,  EOQualifierOperatorNotEqual))
202     [_s appendString:@")"];
203 }
204
205 @end /* EOKeyComparisonQualifier(LDAP) */