1/*
2  Copyright (C) 2000-2005 SKYRIX Software AG
3
4  This file is part of SOPE.
5
6  SOPE 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  SOPE 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 SOPE; 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
22#include "NGLdapGlobalID.h"
23#include "NSString+DN.h"
24#import <EOControl/EOControl.h>
25#include "common.h"
26
27@implementation NGLdapGlobalID
28
29- (id)initWithHost:(NSString *)_host port:(int)_port dn:(NSString *)_dn {
30  self->host = [_host copy];
31  self->port = _port;
32  self->dn   = [[[_dn dnComponents] componentsJoinedByString:@","] copy];
33  return self;
34}
35
36- (void)dealloc {
37  [self->host release];
38  [self->dn   release];
39  [super dealloc];
40}
41
42/* accessors */
43
44- (NSString *)host {
45  return self->host;
46}
47- (NSString *)dn {
48  return self->dn;
49}
50- (int)port {
51  return self->port;
52}
53
54/* equality */
55
56- (NSUInteger)hash {
57  return [self->dn hash] + [self->host hash];
58}
59
60- (BOOL)isEqual:(id)_other {
61  NGLdapGlobalID *ooid;
62
63  if ([_other class] != [self class])
64    return NO;
65
66  ooid = _other;
67
68  if ((ooid->dn == self->dn) &&
69      (ooid->host == self->host) &&
70      (ooid->port == self->port))
71    return YES;
72
73  if (![ooid->dn isEqualToString:self->dn])
74    return NO;
75  if (ooid->port != self->port)
76    return NO;
77  if (![ooid->host isEqualToString:self->host])
78    return NO;
79
80  return YES;
81}
82
83/* description */
84
85- (NSString *)stringValue {
86  return [NSString stringWithFormat:@"%@:%i/%@",
87                     self->host, self->port, self->dn];
88}
89
90- (NSString *)description {
91  NSMutableString *s;
92  NSString *d;
93
94  s = [[NSMutableString alloc] init];
95  [s appendFormat:@"<0x%p[%@]: ", self, NSStringFromClass([self class])];
96  [s appendFormat:@" host=%@", self->host];
97  [s appendFormat:@" port=%i", self->port];
98  [s appendFormat:@" dn=%@", self->dn];
99  [s appendString:@">"];
100
101  d = [s copy];
102  [s release];
103  return [d autorelease];
104}
105
106@end /* NGLdapGlobalID */
107