| 1 |
/* $Id$ */ |
|---|
| 2 |
|
|---|
| 3 |
/* |
|---|
| 4 |
* Copyright (c) 2003-2007 Axel Andersson |
|---|
| 5 |
* All rights reserved. |
|---|
| 6 |
* |
|---|
| 7 |
* Redistribution and use in source and binary forms, with or without |
|---|
| 8 |
* modification, are permitted provided that the following conditions |
|---|
| 9 |
* are met: |
|---|
| 10 |
* 1. Redistributions of source code must retain the above copyright |
|---|
| 11 |
* notice, this list of conditions and the following disclaimer. |
|---|
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 13 |
* notice, this list of conditions and the following disclaimer in the |
|---|
| 14 |
* documentation and/or other materials provided with the distribution. |
|---|
| 15 |
* |
|---|
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 18 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 19 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|---|
| 20 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|---|
| 21 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|---|
| 22 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|---|
| 24 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|---|
| 25 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|---|
| 26 |
* POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 |
*/ |
|---|
| 28 |
|
|---|
| 29 |
#import "WCAccount.h" |
|---|
| 30 |
|
|---|
| 31 |
@interface WCAccount(Private) |
|---|
| 32 |
|
|---|
| 33 |
- (id)_initWithType:(WCAccountType)type; |
|---|
| 34 |
|
|---|
| 35 |
- (void)_setPrivileges:(NSArray *)privileges; |
|---|
| 36 |
- (void)_setName:(NSString *)name; |
|---|
| 37 |
- (void)_setPassword:(NSString *)password; |
|---|
| 38 |
- (void)_setGroup:(NSString *)group; |
|---|
| 39 |
|
|---|
| 40 |
@end |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
@implementation WCAccount(Private) |
|---|
| 44 |
|
|---|
| 45 |
- (id)_initWithType:(WCAccountType)type { |
|---|
| 46 |
self = [super init]; |
|---|
| 47 |
|
|---|
| 48 |
_type = type; |
|---|
| 49 |
|
|---|
| 50 |
return self; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
#pragma mark - |
|---|
| 56 |
|
|---|
| 57 |
- (void)_setPrivileges:(NSArray *)privileges { |
|---|
| 58 |
[privileges retain]; |
|---|
| 59 |
[_privileges release]; |
|---|
| 60 |
|
|---|
| 61 |
_privileges = privileges; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
- (void)_setName:(NSString *)name { |
|---|
| 67 |
[name retain]; |
|---|
| 68 |
[_name release]; |
|---|
| 69 |
|
|---|
| 70 |
_name = name; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
- (void)_setPassword:(NSString *)password { |
|---|
| 76 |
[password retain]; |
|---|
| 77 |
[_password release]; |
|---|
| 78 |
|
|---|
| 79 |
_password = password; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
- (void)_setGroup:(NSString *)group { |
|---|
| 85 |
[group retain]; |
|---|
| 86 |
[_group release]; |
|---|
| 87 |
|
|---|
| 88 |
_group = group; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
@end |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
@implementation WCAccount |
|---|
| 95 |
|
|---|
| 96 |
+ (id)userAccountWithPrivilegesArguments:(NSArray *)arguments { |
|---|
| 97 |
WCAccount *account; |
|---|
| 98 |
|
|---|
| 99 |
account = [[self alloc] _initWithType:WCAccountUser]; |
|---|
| 100 |
[account _setPrivileges:arguments]; |
|---|
| 101 |
|
|---|
| 102 |
return [account autorelease]; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
+ (id)userAccountWithAccountsArguments:(NSArray *)arguments { |
|---|
| 108 |
WCAccount *account; |
|---|
| 109 |
|
|---|
| 110 |
account = [[self alloc] _initWithType:WCAccountUser]; |
|---|
| 111 |
[account _setName:[arguments safeObjectAtIndex:0]]; |
|---|
| 112 |
|
|---|
| 113 |
return [account autorelease]; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
+ (id)groupAccountWithAccountsArguments:(NSArray *)arguments { |
|---|
| 119 |
WCAccount *account; |
|---|
| 120 |
|
|---|
| 121 |
account = [[self alloc] _initWithType:WCAccountGroup]; |
|---|
| 122 |
[account _setName:[arguments safeObjectAtIndex:0]]; |
|---|
| 123 |
|
|---|
| 124 |
return [account autorelease]; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
+ (id)userAccountWithAccountArguments:(NSArray *)arguments { |
|---|
| 130 |
WCAccount *account; |
|---|
| 131 |
|
|---|
| 132 |
account = [[self alloc] _initWithType:WCAccountUser]; |
|---|
| 133 |
[account _setName:[arguments safeObjectAtIndex:0]]; |
|---|
| 134 |
[account _setPassword:[arguments safeObjectAtIndex:1]]; |
|---|
| 135 |
[account _setGroup:[arguments safeObjectAtIndex:2]]; |
|---|
| 136 |
[account _setPrivileges:[arguments subarrayWithRange:NSMakeRange(3, [arguments count] - 3)]]; |
|---|
| 137 |
|
|---|
| 138 |
return [account autorelease]; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
+ (id)groupAccountWithAccountArguments:(NSArray *)arguments { |
|---|
| 144 |
WCAccount *account; |
|---|
| 145 |
|
|---|
| 146 |
account = [[self alloc] _initWithType:WCAccountGroup]; |
|---|
| 147 |
[account _setName:[arguments safeObjectAtIndex:0]]; |
|---|
| 148 |
[account _setPrivileges:[arguments subarrayWithRange:NSMakeRange(1, [arguments count] - 1)]]; |
|---|
| 149 |
|
|---|
| 150 |
return [account autorelease]; |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
- (void)dealloc { |
|---|
| 156 |
[_name release]; |
|---|
| 157 |
[_password release]; |
|---|
| 158 |
[_group release]; |
|---|
| 159 |
[_privileges release]; |
|---|
| 160 |
|
|---|
| 161 |
[super dealloc]; |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
#pragma mark - |
|---|
| 167 |
|
|---|
| 168 |
- (id)initWithCoder:(NSCoder *)coder { |
|---|
| 169 |
self = [super init]; |
|---|
| 170 |
|
|---|
| 171 |
WIDecode(coder, _type); |
|---|
| 172 |
WIDecode(coder, _name); |
|---|
| 173 |
WIDecode(coder, _privileges); |
|---|
| 174 |
|
|---|
| 175 |
return self; |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
- (void)encodeWithCoder:(NSCoder *)coder { |
|---|
| 181 |
WIEncode(coder, _type); |
|---|
| 182 |
WIEncode(coder, _name); |
|---|
| 183 |
WIEncode(coder, _privileges); |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
#pragma mark - |
|---|
| 189 |
|
|---|
| 190 |
- (NSString *)description { |
|---|
| 191 |
return [NSSWF:@"<%@ %p>{name = %@}", |
|---|
| 192 |
[self className], |
|---|
| 193 |
self, |
|---|
| 194 |
[self name]]; |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
#pragma mark - |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
- (WCAccountType)type { |
|---|
| 203 |
return _type; |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
#pragma mark - |
|---|
| 209 |
|
|---|
| 210 |
- (NSString *)name { |
|---|
| 211 |
return _name; |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
- (NSString *)group { |
|---|
| 217 |
return _group; |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
- (NSString *)password { |
|---|
| 223 |
return _password; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
- (BOOL)getUserInfo { |
|---|
| 229 |
return [[_privileges safeObjectAtIndex:0] isEqualToString:@"1"]; |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
- (BOOL)broadcast { |
|---|
| 235 |
return [[_privileges safeObjectAtIndex:1] isEqualToString:@"1"]; |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
- (BOOL)postNews { |
|---|
| 241 |
return [[_privileges safeObjectAtIndex:2] isEqualToString:@"1"]; |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
- (BOOL)clearNews { |
|---|
| 247 |
return [[_privileges safeObjectAtIndex:3] isEqualToString:@"1"]; |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
- (BOOL)download { |
|---|
| 253 |
return [[_privileges safeObjectAtIndex:4] isEqualToString:@"1"]; |
|---|
| 254 |
} |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
- (BOOL)upload { |
|---|
| 259 |
return [[_privileges safeObjectAtIndex:5] isEqualToString:@"1"]; |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
- (BOOL)uploadAnywhere { |
|---|
| 265 |
return [[_privileges safeObjectAtIndex:6] isEqualToString:@"1"]; |
|---|
| 266 |
} |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
- (BOOL)createFolders { |
|---|
| 271 |
return [[_privileges safeObjectAtIndex:7] isEqualToString:@"1"]; |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
- (BOOL)alterFiles { |
|---|
| 277 |
return [[_privileges safeObjectAtIndex:8] isEqualToString:@"1"]; |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
- (BOOL)deleteFiles { |
|---|
| 283 |
return [[_privileges safeObjectAtIndex:9] isEqualToString:@"1"]; |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
- (BOOL)viewDropBoxes { |
|---|
| 289 |
return [[_privileges safeObjectAtIndex:10] isEqualToString:@"1"]; |
|---|
| 290 |
} |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
- (BOOL)createAccounts { |
|---|
| 295 |
return [[_privileges safeObjectAtIndex:11] isEqualToString:@"1"]; |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
- (BOOL)editAccounts { |
|---|
| 301 |
return [[_privileges safeObjectAtIndex:12] isEqualToString:@"1"]; |
|---|
| 302 |
} |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
- (BOOL)deleteAccounts { |
|---|
| 307 |
return [[_privileges safeObjectAtIndex:13] isEqualToString:@"1"]; |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
- (BOOL)elevatePrivileges { |
|---|
| 313 |
return [[_privileges safeObjectAtIndex:14] isEqualToString:@"1"]; |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
- (BOOL)kickUsers { |
|---|
| 319 |
return [[_privileges safeObjectAtIndex:15] isEqualToString:@"1"]; |
|---|
| 320 |
} |
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
- (BOOL)banUsers { |
|---|
| 325 |
return [[_privileges safeObjectAtIndex:16] isEqualToString:@"1"]; |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
- (BOOL)cannotBeKicked { |
|---|
| 331 |
return [[_privileges safeObjectAtIndex:17] isEqualToString:@"1"]; |
|---|
| 332 |
} |
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
- (NSUInteger)downloadSpeedLimit { |
|---|
| 337 |
return [[_privileges safeObjectAtIndex:18] unsignedIntValue]; |
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
- (NSUInteger)uploadSpeedLimit { |
|---|
| 343 |
return [[_privileges safeObjectAtIndex:19] unsignedIntValue]; |
|---|
| 344 |
} |
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
- (NSUInteger)downloadLimit { |
|---|
| 349 |
return [[_privileges safeObjectAtIndex:20] unsignedIntValue]; |
|---|
| 350 |
} |
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
- (NSUInteger)uploadLimit { |
|---|
| 355 |
return [[_privileges safeObjectAtIndex:21] unsignedIntValue]; |
|---|
| 356 |
} |
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
- (BOOL)setTopic { |
|---|
| 361 |
return [[_privileges safeObjectAtIndex:22] isEqualToString:@"1"]; |
|---|
| 362 |
} |
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
#pragma mark - |
|---|
| 367 |
|
|---|
| 368 |
- (NSComparisonResult)compareName:(WCAccount *)account { |
|---|
| 369 |
return [[self name] compare:[account name] options:NSCaseInsensitiveSearch]; |
|---|
| 370 |
} |
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
- (NSComparisonResult)compareType:(WCAccount *)account { |
|---|
| 375 |
if([self type] == WCAccountUser && [account type] == WCAccountGroup) |
|---|
| 376 |
return NSOrderedAscending; |
|---|
| 377 |
else if([self type] == WCAccountGroup && [account type] == WCAccountUser) |
|---|
| 378 |
return NSOrderedDescending; |
|---|
| 379 |
|
|---|
| 380 |
return [self compareName:account]; |
|---|
| 381 |
} |
|---|
| 382 |
|
|---|
| 383 |
@end |
|---|