Sieve / Source / Sieve Protocol Client / SieveClient.m

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
/* Copyright (c) 1010 Sven Weidauer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 
 * Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 */


#import "SieveClient.h"
#import "NSData+Base64Encoding.h"
#import "NSScanner+QuotedString.h"
#import "SieveOperation.h"
#import "SieveClientInternals.h"

// TODO: Verschiedene Empfangs-Routinen aufspalten und vereinheltichen

NSString *const kSieveURLScheme = @"sieve";
NSString * const kSieveErrorDomain = @"SieveErrorDomain";
NSString * const kSieveErrorResponseDictKey = @"SieveErrorResponseDictKey";

static const uint32_t kSieveProtocolType = FOUR_CHAR_CODE( 'SieV' );

@interface SieveClient ()

@property (readwrite, copy) NSString *host;
@property (readwrite, retain) AsyncSocket *socket;
@property (readwrite, retain) SaslConn *sasl;
@property (readwrite, copy) NSString *availableMechanisms;
@property (readwrite, assign) SieveClientStatus status;
@property (readwrite, retain) NSMutableArray *operations;
@property (readwrite, retain) SieveOperation *currentOperation;

- (void) processResponseLine: (NSData *)readData list: (NSMutableArray *) receivedResponses block: (void (^)(NSDictionary *))completionBlock;
- (void) receiveResponse: (void (^)(NSDictionary *))completionBlock;
- (void) authWithUser: (NSString *) userName andPassword: (NSString *) password;

@end

@implementation SieveClient

@synthesize availableMechanisms;
@synthesize host, socket;
@synthesize status;
@synthesize sasl;
@synthesize startTLSIfPossible;
@synthesize delegate;
@synthesize user;
@synthesize operations;
@synthesize currentOperation;

- (NSMutableArray *) operations;
{
    if (nil == operations) {
        operations = [[NSMutableArray alloc] init];
    }
    return operations;
}

- init;
{
    if (nil == [super init]) return nil;
    startTLSIfPossible = YES;
    return self;
}

- (void) dealloc;
{
    [self setHost: nil];

    [socket setDelegate: nil];
    [self setSocket: nil];
    
    [self setSasl: nil];
    
    [super dealloc];
}

#pragma mark -


- (void) receiveCaps: (NSDictionary *) response;
{
    if ([[response objectForKey: @"responseCode"] isEqualToString: @"OK"]) {
        bool readyForAuth = YES;
        for (NSString *line in [response objectForKey: @"response"]) {
            NSScanner *scanner = [NSScanner scannerWithString: line];
            [scanner setCaseSensitive: NO];
            
            NSString *item = nil;
            if ([scanner scanQuotedString: &item]) {
                item = [item lowercaseString];
                
                NSString *rest = @"";
                [scanner scanQuotedString: &rest];
                
                if ([item isEqualToString: @"sasl"]) {
                    [self setAvailableMechanisms: rest];
                    
                } else if ([item isEqualToString: @"starttls"]) {
                    if (startTLSIfPossible && !TLSActive) {
                        [self startTLS]; 
                        readyForAuth = NO;
                        break; // muss nicht weiter bearbeitet werden, nach TLS handshake kommt sowieso neue caps
                    }
                    
                } else if ([item isEqualToString: @"sieve"]) {
                    // TODO: in array splitten und speichern als verfügbare erweiterungen speichern
                    
                } else if ([item isEqualToString: @"notify"]) {
                    // TODO: in array splitten und speichern als verfügbare notify-methoden speichern
                }
            }
        }
        
        if (readyForAuth) {
            [self setStatus: SieveClientConnected];
            if ([delegate respondsToSelector: @selector( sieveClientEstablishedConnection: )]) {
                [delegate sieveClientEstablishedConnection: self];
            }
            [self auth];
        }
    } else {
        // TODO: notify delegate
    }
}

- (void) connectToURL: (NSURL *) url;
{
    NSAssert( [[url scheme] isEqualToString: kSieveURLScheme], @"Accepting only sieve URLs" );
    
    unsigned port = kSieveDefaultPort;
    
    NSNumber *urlPort = [url port];
    if (nil != urlPort) {
        port = [urlPort unsignedIntValue];
    }
    
    [self setUser: [url user]];
    
    [self connectToHost: [url host] port: port];
}

- (void) connectToHost: (NSString *) newHost port: (unsigned) port;
{
    NSAssert( status == SieveClientDisconnected, @"Cannot connect if already connected" );
    
    [[self mutableArrayValueForKey: @"log"] removeAllObjects];
    [self setHost: newHost]; 
    
    [self setSocket: [[[AsyncSocket alloc] initWithDelegate: self] autorelease]];
    [socket connectToHost: host onPort: port error: NULL];
    
    [self receiveResponse: ^(NSDictionary *response) {
        [self receiveCaps: response];
    }];
}

- (void) disconnect;
{
    NSAssert( status != SieveClientDisconnected, @"Already disconnected" );
    
    [self send: @"LOGOUT"];
    [socket disconnect];
}

- (void) startTLS;
{
    [self send: @"STARTTLS" completion: ^(NSDictionary *info) {
        if ([[info objectForKey: @"responseCode"] isEqualToString: @"OK"]) {
            [socket startTLS: nil];
            TLSActive = true;
            [self receiveResponse: ^(NSDictionary *response) {
                [self receiveCaps: response];
            }];
        }
    }];
}

- (void) logLine: (NSString *) line from: (NSString *) source;
{
    [[self mutableArrayValueForKey: @"log"] addObject: [NSDictionary dictionaryWithObjectsAndKeys: line, @"line", source, @"who", nil]];
}

- (void) sendString: (NSString *) line;
{
    NSData *lineData = [[line stringByAppendingString: @"\r\n"] dataUsingEncoding: NSUTF8StringEncoding];
    [socket writeData: lineData withTimeout: -1 tag: 0];
}

- (void) sendData: (NSData *) data
{
    [socket writeData: data withTimeout: -1 tag: 0];
}

- (void) send: (NSString *) line completion: (void (^)(NSDictionary *))completionBlock;
{
    [self logLine: line from: @"Client"];
    [self sendString: line];
    [self receiveResponse: completionBlock];
}

- (void) send: (NSString *) line;
{
    [self send: line completion: nil];
}

- (void) receiveNextLine: (NSMutableArray *) responses block: (void (^)(NSDictionary *))completionBlock;
{
    [socket readDataToData: [AsyncSocket CRLFData] withTimeout: -1 tag: 0 block: ^(NSData * received) {
        [self processResponseLine: received list: responses block: completionBlock];
    }];
}


- (void) readStringFromScanner: (NSScanner *) scanner completion: (void (^)(NSString *)) block;
{
    if ([scanner scanString: @"{" intoString: NULL]) {
        int stringLength = 0;
        [scanner scanInt: &stringLength];
        
        [socket readDataToLength: stringLength + 2 withTimeout: -1 tag: 0 block: ^(NSData *readData){
            NSString *str = [[[NSString alloc] initWithData: readData encoding: NSUTF8StringEncoding] autorelease];
            block( str );
        }];
    } else {
        NSString *result = [[scanner string] substringFromIndex: [scanner scanLocation]];
        block( result );
    }
}

- (void) receiveString: (void (^)(NSString *)) completionBlock;
{
    [socket readDataToData: [AsyncSocket CRLFData] withTimeout: -1 tag: 0 block: ^(NSData * received) {
        NSString *receivedLine = [[[NSString alloc] initWithData: received encoding: NSUTF8StringEncoding] autorelease];
        NSScanner *scanner = [NSScanner scannerWithString: receivedLine];
        [scanner setCaseSensitive: NO];
        [self readStringFromScanner: scanner completion: completionBlock];
    }];
}

- (void) processResponseLine: (NSData *)readData list: (NSMutableArray *) receivedResponses block: (void (^)(NSDictionary *))completionBlock;
{
    NSString *receivedLine = [[[NSString alloc] initWithData: readData encoding: NSUTF8StringEncoding] autorelease];

    NSScanner *scanner = [NSScanner scannerWithString: receivedLine];
    [scanner setCaseSensitive: NO];

    NSString *responseString = nil;
    if ([scanner scanString: @"OK" intoString: &responseString] || [scanner scanString: @"NO" intoString: &responseString] || [scanner scanString: @"BYE" intoString: &responseString]) {
        [self logLine: receivedLine from: @"Server"];
        
        NSString *extraInfo = nil;

        if ([scanner scanString: @"(" intoString: NULL]) {
            [scanner scanUpToString: @")" intoString: &extraInfo];
            [scanner scanString: @")" intoString: NULL];
        }
        
        [self readStringFromScanner: scanner completion: ^(NSString *userInfo) {
            if (completionBlock != nil) {
                NSMutableDictionary *completeResponse = [NSMutableDictionary dictionary];
                [completeResponse setObject:responseString forKey:@"responseCode"];
                if (extraInfo) [completeResponse setObject:extraInfo forKey:@"extraInfo"];
                if (userInfo) [completeResponse setObject: userInfo forKey: @"userInfo"];
                if ([receivedResponses count] > 0) {
                    [completeResponse setObject: receivedResponses forKey: @"response"];
                }
                completionBlock( completeResponse );
            }
            
        }];
        
    } else {
        [self readStringFromScanner: scanner completion: ^(NSString * line) {
            [receivedResponses addObject: line];
            [self receiveNextLine: receivedResponses block: (void (^)(NSDictionary *))completionBlock];
        }];
    }
}

- (void) receiveResponse: (void (^)(NSDictionary *))completionBlock;
{
    NSMutableArray *receivedResponses = [NSMutableArray array];

    [self receiveNextLine: receivedResponses block: completionBlock];
}

- (void) authStep: (NSString *) receivedString;
{
    NSScanner *scanner = [NSScanner scannerWithString: receivedString];
    
    if ([scanner scanString: @"OK " intoString: NULL]) {
        [self logLine: receivedString from: @"Server"];
        NSData *lastData = nil;
        
        if ([scanner scanString: @"(SASL" intoString: NULL]) {
            NSString *rest = @"";
            if ([scanner scanQuotedString: &rest]) lastData = [rest base64DecodedData];
        }
        
        if (lastData || (status != SieveClientAuthenticated)) {
            SaslConnStatus rc = [sasl finishWithServerData: lastData];
            if (rc == SaslConnSuccess) {
                [self setStatus: SieveClientAuthenticated];
            }
        }
        
        if (status == SieveClientAuthenticated) {
            NSAssert( ![sasl needsToEncodeData], @"Sieve security layers are not supported." );
            [self setSasl: nil];
            
            if ([delegate respondsToSelector: @selector( sieveClientSucceededAuth: )]) {
                [delegate sieveClientSucceededAuth: self];
            }
            [self startNextOperation];
        }
        
    } else if ([scanner scanString: @"NO " intoString: NULL]) {
        [self logLine: receivedString from: @"Server"];
        [self setStatus: SieveClientConnected];
        [delegate sieveClient: self needsCredentials: nil];
        
    } else if ([scanner scanString: @"BYE " intoString: NULL]) {
        [self logLine: receivedString from: @"Server"];
        [socket disconnect];
        // TODO: Notify delegate that connection was dropped
        
    } else {
        NSString *rest = @"";
        if ([scanner scanQuotedString: &rest]) receivedString = rest;
        
        NSData *data = [receivedString base64DecodedData];

        NSData *outData = nil;
        SaslConnStatus rc = [sasl continueWithServerData: data clientOut: &outData];
        
        if (rc == SaslConnFailed) {
            // Abort the auth by sending "*"
            [self sendString: @"\"*\""];
            [self receiveResponse: nil];
            [self disconnect];
            // TODO: Notify delegate that connection was dropped
            
        } else {
            if (rc == SaslConnSuccess) [self setStatus: SieveClientAuthenticated];
            
            NSString *authCommand = @"\"\"";
            if (nil != outData) authCommand = [NSString stringWithFormat: @"\"%@\"", [outData base64EncodedString]];

            [self sendString: authCommand];
            [self receiveString: ^( NSString *receivedString ) {
                [self authStep: receivedString];
            }];
        }
    }
    
}

- (void) continueAuthWithCredentials: (NSURLCredential *) creds;
{
    if ([creds persistence] == NSURLCredentialPersistencePermanent) {
        NSData *serverData = [host dataUsingEncoding: NSUTF8StringEncoding];
        NSData *userData = [[creds user] dataUsingEncoding: NSUTF8StringEncoding];
        NSData *passwordData = [[creds password] dataUsingEncoding: NSUTF8StringEncoding];
        SecKeychainAddInternetPassword( NULL, [serverData length], [serverData bytes], 0, NULL, 
                                       [userData length], [userData bytes], 0, NULL, [socket connectedPort], 
                                       kSieveProtocolType, kSecAuthenticationTypeDefault, 
                                       [passwordData length], [passwordData bytes], NULL );
    }
    [self authWithUser: [creds user] andPassword: [creds password]];
}

- (void) cancelAuth;
{
    // TODO: Disconnect socket
}

- (void) authWithUser: (NSString *) userName andPassword: (NSString *) password;
{
    NSAssert( status == SieveClientConnected, @"Wrong status" );
    [self setStatus: SieveClientAuthenticating];
    
    [self setSasl:[[[SaslConn alloc] initWithService: kSieveURLScheme server: host socket: socket flags: SaslConnSuccessData] autorelease]];
    
    [self setUser: userName];
    [sasl setAuthName: userName];
    [sasl setPassword: password];

    NSData *outData = nil;
    SaslConnStatus rc = [sasl startWithMechanisms: availableMechanisms clientOut: &outData];
    if (rc != SaslConnFailed) {
        if (SaslConnSuccess == rc) [self setStatus: SieveClientAuthenticated];
        
        NSString *authCommand = [NSString stringWithFormat: @"AUTHENTICATE \"%@\"", [sasl mechanism]];
        [self logLine: authCommand from: @"Client"];
        
        if (outData) {
            NSString *encodedData = [outData base64EncodedString];
            authCommand = [authCommand stringByAppendingFormat: @" \"%@\"", encodedData];
        }
        
        [self sendString: authCommand];
        [self receiveString: ^( NSString *receivedString ) {
            [self authStep: receivedString];
        }];
    } else {
        [self disconnect];
        // TODO: Notify delegate that connection was dropped
    }
}

- (void) auth;
{
    NSString *userName = [self user];
    NSString *password = nil;

    if (!triedKeychain) {
        NSData *serverName = [host dataUsingEncoding: NSUTF8StringEncoding];
        UInt32 passwordLength = 0;
        void *passwordData = NULL;
        SecKeychainItemRef item = NULL;
        
        const char *userNameString = NULL;
        unsigned userNameLength = 0;
        
        if (nil != userName) {
            NSData *userNameData = [userName dataUsingEncoding: NSUTF8StringEncoding];
            userNameString = [userNameData bytes];
            userNameLength = [userNameData length];
        }
        
        OSStatus result = SecKeychainFindInternetPassword( NULL, [serverName length], [serverName bytes], 0, NULL,
                                        userNameLength, userNameString, 0, NULL, [socket connectedPort], 
                                        kSieveProtocolType, kSecAuthenticationTypeDefault, 
                                        &passwordLength, &passwordData, &item );
        
        if (errSecSuccess == result) {
            NSData *data = [NSData dataWithBytesNoCopy: passwordData length: passwordLength freeWhenDone: NO];
            password = [[[NSString alloc] initWithData: data encoding:NSUTF8StringEncoding] autorelease];
            
            if (nil == userName) {
                SecKeychainAttribute nameAttribute = {
                    kSecAccountItemAttr, 0, NULL
                };
                SecKeychainAttributeList attrList = {
                    1, &nameAttribute
                };
                result = SecKeychainItemCopyContent( item, NULL, &attrList, NULL, NULL );
                if (result == errSecSuccess) {
                    data = [NSData dataWithBytesNoCopy: nameAttribute.data length: nameAttribute.length freeWhenDone:NO];
                    userName = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
                    SecKeychainItemFreeContent( &attrList, NULL );
                } 
            }
            
            SecKeychainItemFreeContent( NULL, passwordData );
        }
        
        triedKeychain = YES;
    }
    
    if (nil != password && nil != userName) {
        [self authWithUser: userName andPassword: password ];
    } else {
        NSURLCredential *partialCred = [NSURLCredential credentialWithUser: userName password: password persistence: NSURLCredentialPersistenceNone];
        [delegate sieveClient: self needsCredentials: partialCred];
    }
}

- (void) startNextOperation;
{
    if ([operations count] > 0) {
        [self setCurrentOperation: [operations objectAtIndex: 0]];
        [operations removeObjectAtIndex: 0];
        [currentOperation start];
    } else {
        [self setCurrentOperation: nil];
    }
}

- (void) addOperation: (SieveOperation *) operation;
{
    [[self operations] addObject: operation];
    if (nil == currentOperation && status == SieveClientAuthenticated) [self startNextOperation];
}

- (void) putScript: (NSString *) script withName: (NSString *) name delegate: (id) newDelegate userInfo: (void *) userInfo;
{
    [self addOperation: [[[SievePutScriptOperation alloc] initWithScript: script name:name forClient:self delegate:newDelegate userInfo: userInfo] autorelease]];
}

- (void) putScript: (NSString *) script withName: (NSString *) name;
{
    [self putScript: script withName: name delegate: delegate userInfo: NULL];
}

- (void) setActiveScript: (NSString *) scriptName delegate: (id) newDelegate userInfo: (void *) userInfo;
{
    [self addOperation: [[[SieveSetActiveOperation alloc] initWithScript: scriptName forClient: self delegate:newDelegate userInfo: userInfo] autorelease]];
}

- (void) setActiveScript: (NSString *) scriptName;
{
    [self setActiveScript: scriptName delegate: delegate userInfo: NULL];
}

- (void) renameScript: (NSString *) oldName to: (NSString *) newName delegate: (id) newDelegate userInfo: (void *) userInfo;
{
    [self addOperation: [[[SieveRenameScriptOperation alloc] initWithOldName: oldName newName: newName forClient: self delegate:newDelegate userInfo: userInfo] autorelease]];
}

- (void) renameScript: (NSString *) oldName to: (NSString *) newName;
{
    [self renameScript: oldName to: newName delegate: delegate userInfo: NULL];
}

- (void) deleteScript: (NSString *) scriptName delegate: (id) newDelegate userInfo: (void *) userInfo;
{
    [self addOperation: [[[SieveDeleteScriptOperation alloc] initWithScript: scriptName forClient: self delegate:newDelegate userInfo: userInfo] autorelease]];
}

- (void) deleteScript: (NSString *) scriptName;
{
    [self deleteScript: scriptName delegate: delegate userInfo: NULL];
}

- (void) listScriptsWithDelegate: (id) newDelegate userInfo: (void *) userInfo;
{
    [self addOperation: [[[SieveListScriptsOperation alloc] initForClient: self delegate: newDelegate userInfo: userInfo] autorelease]];
}

- (void) listScripts;
{
    [self listScriptsWithDelegate: delegate userInfo: NULL];
}

- (void) getScript: (NSString *) scriptName delegate: (id) newDelegate userInfo: (void *) userInfo;
{
    [self addOperation: [[[SieveGetScriptOperation alloc] initWithScript: scriptName forClient:self delegate:newDelegate userInfo: userInfo] autorelease]];
}

- (void) getScript: (NSString *) scriptName;
{
    [self getScript: scriptName delegate: delegate userInfo: NULL];
}

#pragma mark -
#pragma mark Logging

- (NSArray *)log {
    if (!log) {
        log = [[NSMutableArray alloc] init];
    }
    return [[log retain] autorelease];
}

- (unsigned)countOfLog {
    if (!log) {
        log = [[NSMutableArray alloc] init];
    }
    return [log count];
}

- (id)objectInLogAtIndex:(unsigned)theIndex {
    if (!log) {
        log = [[NSMutableArray alloc] init];
    }
    return [log objectAtIndex:theIndex];
}

- (void)getLog:(id *)objsPtr range:(NSRange)range {
    if (!log) {
        log = [[NSMutableArray alloc] init];
    }
    [log getObjects:objsPtr range:range];
}

- (void)insertObject:(id)obj inLogAtIndex:(unsigned)theIndex {
    if (!log) {
        log = [[NSMutableArray alloc] init];
    }
    [log insertObject:obj atIndex:theIndex];
}

- (void)removeObjectFromLogAtIndex:(unsigned)theIndex {
    if (!log) {
        log = [[NSMutableArray alloc] init];
    }
    [log removeObjectAtIndex:theIndex];
}

- (void)replaceObjectInLogAtIndex:(unsigned)theIndex withObject:(id)obj {
    if (!log) {
        log = [[NSMutableArray alloc] init];
    }
    [log replaceObjectAtIndex:theIndex withObject:obj];
}

@end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.