Changeset 1916

Show
Ignore:
Timestamp:
09/19/04 19:18:14 (4 years ago)
Author:
timothy
Message:

MVFileTransfer is now a class cluster awaiting SILC SFTP file transfer support.
* Still use MVUploadFileTransfer and MVDownloadFileTransfer like normal.
* IRC's DCC transfers are handled by MVIRCUploadFileTransfer and MVIRCDownloadFileTransfer now.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Chat Core.xcode/project.pbxproj

    r1880 r1916  
    350350                                1C5A1A2506F8F4A000A51F10, 
    351351                                1C5A230A06FA4F2800A51F10, 
     352                                1C74433D06FE3AB3009AA696, 
    352353                        ); 
    353354                        isa = PBXSourcesBuildPhase; 
     
    483484                1C6C83A00632186900698F55 = { 
    484485                        fileRef = F52BA284037C13C201A35792; 
     486                        isa = PBXBuildFile; 
     487                        settings = { 
     488                        }; 
     489                }; 
     490                1C74433A06FE3AB3009AA696 = { 
     491                        fileEncoding = 4; 
     492                        isa = PBXFileReference; 
     493                        lastKnownFileType = sourcecode.c.h; 
     494                        path = MVIRCFileTransfer.h; 
     495                        refType = 4; 
     496                        sourceTree = "<group>"; 
     497                }; 
     498                1C74433B06FE3AB3009AA696 = { 
     499                        fileEncoding = 4; 
     500                        isa = PBXFileReference; 
     501                        lastKnownFileType = sourcecode.c.objc; 
     502                        path = MVIRCFileTransfer.m; 
     503                        refType = 4; 
     504                        sourceTree = "<group>"; 
     505                }; 
     506                1C74433D06FE3AB3009AA696 = { 
     507                        fileRef = 1C74433B06FE3AB3009AA696; 
    485508                        isa = PBXBuildFile; 
    486509                        settings = { 
     
    33233346                                1C943AAA063C260800618CD9, 
    33243347                                1C943AA9063C260800618CD9, 
     3348                                1C74433B06FE3AB3009AA696, 
     3349                                1C74433A06FE3AB3009AA696, 
    33253350                                1C2EF7EC0427A40B00000102, 
    33263351                                1C2EF7EB0427A40B00000102, 
  • trunk/Colloquy.xcode/project.pbxproj

    r1880 r1916  
    13281328                        refType = 2; 
    13291329                        sourceTree = SOURCE_ROOT; 
     1330                }; 
     1331                1C74459106FE5842009AA696 = { 
     1332                        fileEncoding = 4; 
     1333                        isa = PBXFileReference; 
     1334                        lastKnownFileType = sourcecode.c.h; 
     1335                        path = MVIRCFileTransfer.h; 
     1336                        refType = 4; 
     1337                        sourceTree = "<group>"; 
     1338                }; 
     1339                1C74459206FE5842009AA696 = { 
     1340                        fileEncoding = 4; 
     1341                        isa = PBXFileReference; 
     1342                        lastKnownFileType = sourcecode.c.objc; 
     1343                        path = MVIRCFileTransfer.m; 
     1344                        refType = 4; 
     1345                        sourceTree = "<group>"; 
    13301346                }; 
    13311347                1C746A95050CF86B000001C8 = { 
     
    45164532                                1C8CF8E2066530D60080A2F5, 
    45174533                                1C8CF8E1066530D60080A2F5, 
     4534                                1C74459206FE5842009AA696, 
     4535                                1C74459106FE5842009AA696, 
    45184536                                1C2EF7EC0427A40B00000102, 
    45194537                                1C2EF7EB0427A40B00000102, 
  • trunk/MVFileTransfer.h

    r1823 r1916  
    2525 
    2626@interface MVFileTransfer : NSObject { 
    27         void *_dcc; /* FILE_DCC_REC */ 
     27@protected 
    2828        unsigned long long _finalSize; 
    2929        unsigned long long _transfered; 
     
    4141+ (NSRange) fileTransferPortRange; 
    4242 
    43 + (void) updateExternalIPAddress; 
    44  
    45 - (id) initWithDCCFileRecord:(void *) record fromConnection:(MVChatConnection *) connection; 
     43- (id) initWithUser:(NSString *) user fromConnection:(MVChatConnection *) connection; 
    4644 
    4745- (BOOL) isUpload; 
     
    6967 
    7068@interface MVUploadFileTransfer : MVFileTransfer { 
    71         int _transferQueue; 
     69@protected 
    7270        NSString *_source; 
    7371} 
     
    8078 
    8179@interface MVDownloadFileTransfer : MVFileTransfer { 
     80@protected 
    8281        NSString *_destination; 
    8382        NSString *_originalFileName; 
  • trunk/MVFileTransfer.m

    r1862 r1916  
    11#import "MVFileTransfer.h" 
     2#import "MVIRCFileTransfer.h" 
    23#import "MVChatConnection.h" 
    34#import "NSNotificationAdditions.h" 
    4  
    5 #define MODULE_NAME "MVFileTransfer" 
    6  
    7 #import "common.h" 
    8 #import "core.h" 
    9 #import "signals.h" 
    10 #import "settings.h" 
    11 #import "servers.h" 
    12 #import "irc.h" 
    13 #import "config.h" 
    14 #import "dcc.h" 
    15 #import "dcc-get.h" 
    16 #import "dcc-send.h" 
    17 #import "dcc-queue.h" 
    18 #import "dcc-file.h" 
    195 
    206NSString *MVDownloadFileTransferOfferNotification = @"MVDownloadFileTransferOfferNotification"; 
     
    2511NSString *MVFileTransferErrorDomain = @"MVFileTransferErrorDomain"; 
    2612 
    27 extern NSRecursiveLock *MVIRCChatConnectionThreadLock; 
    28  
    29 void dcc_send_resume( GET_DCC_REC *dcc ); 
    30 void dcc_queue_send_next( int queue ); 
    31  
    32 typedef struct { 
    33         MVFileTransfer *transfer; 
    34 } MVFileTransferModuleData; 
    35  
    36 #pragma mark - 
    37  
    3813@interface MVFileTransfer (MVFileTransferPrivate) 
    39 + (id) _transferForDCCFileRecord:(FILE_DCC_REC *) record; 
    40 - (FILE_DCC_REC *) _DCCFileRecord; 
    41 - (void) _setDCCFileRecord:(FILE_DCC_REC *) record; 
    4214- (void) _setConnection:(MVChatConnection *) connection; 
    4315- (void) _setStatus:(MVFileTransferStatus) status; 
    44 - (void) _destroying; 
    45 @end 
    46  
    47 #pragma mark - 
    48  
    49 @interface MVChatConnection (MVChatConnectionPrivate) 
    50 - (SERVER_REC *) _irssiConnection; 
    51 @end 
    52  
    53 #pragma mark - 
    54  
    55 static void MVFileTransferConnected( FILE_DCC_REC *dcc ) { 
    56         MVFileTransfer *self = [MVFileTransfer _transferForDCCFileRecord:dcc]; 
    57         if( ! self ) return; 
    58  
    59         [self _setStatus:MVFileTransferNormalStatus]; 
    60  
    61         NSNotification *note = [NSNotification notificationWithName:MVFileTransferStartedNotification object:self];              
    62         [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; 
    63 
    64  
    65 static void MVFileTransferDestroyed( FILE_DCC_REC *dcc ) { 
    66         MVFileTransfer *self = [MVFileTransfer _transferForDCCFileRecord:dcc]; 
    67         if( ! self ) return; 
    68  
    69         if( [self status] == MVFileTransferNormalStatus ) { 
    70                 [self _setStatus:MVFileTransferDoneStatus]; 
    71                 NSNotification *note = [NSNotification notificationWithName:MVFileTransferFinishedNotification object:self];             
    72                 [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; 
    73         } 
    74  
    75         [MVIRCChatConnectionThreadLock unlock]; // prevents a deadlock, since waitUntilDone is required. threads synced 
    76  
    77         [self performSelectorOnMainThread:@selector( _destroying ) withObject:nil waitUntilDone:YES]; 
    78  
    79         [MVIRCChatConnectionThreadLock lock]; // lock back up like nothing happened 
    80 
    81  
    82 static void MVFileTransferClosed( FILE_DCC_REC *dcc ) { 
    83         MVFileTransfer *self = [MVFileTransfer _transferForDCCFileRecord:dcc]; 
    84         if( ! self ) return; 
    85  
    86         if( dcc -> size != dcc -> transfd ) { 
    87                 NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"The file transfer terminated unexpectedly.", NSLocalizedDescriptionKey, nil]; 
    88                 NSError *error = [NSError errorWithDomain:MVFileTransferErrorDomain code:MVFileTransferUnexpectedlyEndedError userInfo:info]; 
    89                 [self performSelectorOnMainThread:@selector( _postError: ) withObject:error waitUntilDone:NO]; 
    90         } else { 
    91                 [self _setStatus:MVFileTransferDoneStatus]; 
    92                 NSNotification *note = [NSNotification notificationWithName:MVFileTransferFinishedNotification object:self];             
    93                 [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; 
    94         } 
    95 
    96  
    97 static void MVFileTransferErrorConnect( FILE_DCC_REC *dcc ) { 
    98         MVFileTransfer *self = [MVFileTransfer _transferForDCCFileRecord:dcc]; 
    99         if( ! self ) return; 
    100  
    101         NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"The file transfer connection could not be made.", NSLocalizedDescriptionKey, nil]; 
    102         NSError *error = [NSError errorWithDomain:MVFileTransferErrorDomain code:MVFileTransferConnectionError userInfo:info]; 
    103         [self performSelectorOnMainThread:@selector( _postError: ) withObject:error waitUntilDone:NO]; 
    104 
    105  
    106 static void MVFileTransferErrorFileCreate( FILE_DCC_REC *dcc, char *filename ) { 
    107         MVFileTransfer *self = [MVFileTransfer _transferForDCCFileRecord:dcc]; 
    108         if( ! self ) return; 
    109  
    110         NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"The file %@ could not be created, please make sure you have write permissions in the %@ folder.", NSLocalizedDescriptionKey, nil]; 
    111         NSError *error = [NSError errorWithDomain:MVFileTransferErrorDomain code:MVFileTransferFileCreationError userInfo:info]; 
    112         [self performSelectorOnMainThread:@selector( _postError: ) withObject:error waitUntilDone:NO]; 
    113 
    114  
    115 static void MVFileTransferErrorFileOpen( FILE_DCC_REC *dcc, char *filename, int errno ) { 
    116         MVFileTransfer *self = [MVFileTransfer _transferForDCCFileRecord:dcc]; 
    117         if( ! self ) return; 
    118  
    119         NSError *ferror = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]; 
    120         NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"The file %@ could not be opened, please make sure you have read permissions for this file.", NSLocalizedDescriptionKey, ferror, @"NSUnderlyingErrorKey", nil]; 
    121         NSError *error = [NSError errorWithDomain:MVFileTransferErrorDomain code:MVFileTransferFileOpenError userInfo:info]; 
    122         [self performSelectorOnMainThread:@selector( _postError: ) withObject:error waitUntilDone:NO]; 
    123 
    124  
    125 static void MVFileTransferErrorSendExists( FILE_DCC_REC *dcc, char *nick, char *filename ) { 
    126         MVFileTransfer *self = [MVFileTransfer _transferForDCCFileRecord:dcc]; 
    127         if( ! self ) return; 
    128  
    129         NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"The file %@ is already being offerend to %@.", NSLocalizedDescriptionKey, nil]; 
    130         NSError *error = [NSError errorWithDomain:MVFileTransferErrorDomain code:MVFileTransferAlreadyExistsError userInfo:info]; 
    131         [self performSelectorOnMainThread:@selector( _postError: ) withObject:error waitUntilDone:NO]; 
    132 
     16- (void) _postError:(NSError *) error; 
     17@end 
    13318 
    13419#pragma mark - 
    13520 
    13621@implementation MVFileTransfer 
    137 + (void) initialize { 
    138         [super initialize]; 
    139         static BOOL tooLate = NO; 
    140         if( ! tooLate ) { 
    141                 [MVIRCChatConnectionThreadLock lock]; 
    142                 signal_add_last( "dcc connected", (SIGNAL_FUNC) MVFileTransferConnected ); 
    143                 signal_add_last( "dcc destroyed", (SIGNAL_FUNC) MVFileTransferDestroyed ); 
    144                 signal_add_last( "dcc closed", (SIGNAL_FUNC) MVFileTransferClosed ); 
    145                 signal_add_last( "dcc error connect", (SIGNAL_FUNC) MVFileTransferErrorConnect ); 
    146                 signal_add_last( "dcc error file create", (SIGNAL_FUNC) MVFileTransferErrorFileCreate ); 
    147                 signal_add_last( "dcc error file open", (SIGNAL_FUNC) MVFileTransferErrorFileOpen ); 
    148                 signal_add_last( "dcc error send exists", (SIGNAL_FUNC) MVFileTransferErrorSendExists ); 
    149                 [MVIRCChatConnectionThreadLock unlock]; 
    150                 tooLate = YES; 
    151         } 
    152 } 
    153  
    154 #pragma mark - 
    155  
    15622+ (void) setFileTransferPortRange:(NSRange) range { 
    157         unsigned short min = (unsigned short)range.location; 
    158         unsigned short max = (unsigned short)(range.location + range.length); 
    159         [MVIRCChatConnectionThreadLock lock]; 
    160         settings_set_str( "dcc_port", [[NSString stringWithFormat:@"%uh %uh", min, max] UTF8String] ); 
    161         [MVIRCChatConnectionThreadLock unlock]; 
    16223} 
    16324 
    16425+ (NSRange) fileTransferPortRange { 
    165         [MVIRCChatConnectionThreadLock lock]; 
    166         const char *range = settings_get_str( "dcc_port" ); 
    167         [MVIRCChatConnectionThreadLock unlock]; 
    168  
    169         unsigned short min = 1024; 
    170         unsigned short max = 1048; 
    171  
    172         if( range && strlen( range ) ) { 
    173                 min = strtoul( range, NULL, 10 ); 
    174                 char *temp = strchr( range, ' ' ); 
    175                 if( ! temp ) temp = strchr( range, '-' ); 
    176  
    177                 if( ! temp ) max = min; 
    178                 else { 
    179                         max = strtoul( temp + 1, NULL, 10 ); 
    180                         if( ! max ) max = min; 
    181                 } 
    182  
    183                 if( max < min ) { 
    184                         unsigned int t = min; 
    185                         min = max; 
    186                         max = t; 
    187                 } 
    188         } 
    189  
    190         return NSMakeRange( (unsigned int) min, (unsigned int)( max - min ) ); 
    191 
    192  
    193 #pragma mark - 
    194  
    195 + (void) updateExternalIPAddress { 
    196         NSURL *url = [NSURL URLWithString:@"http://colloquy.info/ip.php"]; 
    197         NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:3.]; 
    198         NSMutableData *result = [[[NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL] mutableCopy] autorelease]; 
    199         [result appendBytes:"\0" length:1]; 
    200         if( [result length] ) { 
    201                 [MVIRCChatConnectionThreadLock lock]; 
    202                 settings_set_str( "dcc_own_ip", [result bytes] ); 
    203                 [MVIRCChatConnectionThreadLock unlock]; 
    204         } 
    205 
    206  
    207 #pragma mark - 
    208  
    209 - (id) initWithDCCFileRecord:(void *) record fromConnection:(MVChatConnection *) connection { 
     26        return NSMakeRange( 1024, ( 65535 - 1024 ) ); 
     27
     28 
     29#pragma mark - 
     30 
     31- (id) initWithUser:(NSString *) user fromConnection:(MVChatConnection *) connection { 
    21032        if( ( self = [super init] ) ) { 
    211                 _dcc = NULL; 
    21233                _connection = nil; 
    213                 [self _setDCCFileRecord:record]; 
    21434                [self _setConnection:connection]; 
    21535                _status = MVFileTransferHoldingStatus; 
     
    21838                _startDate = nil; 
    21939                _host = nil; 
    220                 _user = nil
     40                _user = [user copy]
    22141                _port = 0; 
    22242                _startOffset = 0; 
     
    22747 
    22848- (void) dealloc { 
    229         [self _setDCCFileRecord:NULL]; 
    230  
    23149        [_startDate release]; 
    23250        [_host release]; 
     
    25169 
    25270- (BOOL) isPassive { 
    253         if( ! [self _DCCFileRecord] ) return _passive; 
    254         [MVIRCChatConnectionThreadLock lock]; 
    255         _passive = dcc_is_passive( [self _DCCFileRecord] ); 
    256         [MVIRCChatConnectionThreadLock unlock]; 
    257         return _passive; 
     71// subclass if needed 
     72        return NO; 
    25873} 
    25974 
     
    26984 
    27085- (unsigned long long) finalSize { 
    271         if( ! [self _DCCFileRecord] ) return _finalSize; 
    272         [MVIRCChatConnectionThreadLock lock]; 
    273         _finalSize = [self _DCCFileRecord] -> size; 
    274         [MVIRCChatConnectionThreadLock unlock]; 
    27586        return _finalSize; 
    27687} 
    27788 
    27889- (unsigned long long) transfered { 
    279         if( ! [self _DCCFileRecord] ) return _transfered; 
    280         [MVIRCChatConnectionThreadLock lock]; 
    281         _transfered = [self _DCCFileRecord] -> transfd; 
    282         [MVIRCChatConnectionThreadLock unlock]; 
    28390        return _transfered; 
    28491} 
     
    28794 
    28895- (NSDate *) startDate { 
    289         if( _startDate || ! [self _DCCFileRecord] ) return _startDate; 
    290         [MVIRCChatConnectionThreadLock lock]; 
    291         if( [self _DCCFileRecord] -> starttime ) 
    292                 _startDate = [[NSDate dateWithTimeIntervalSince1970:[self _DCCFileRecord] -> starttime] retain]; 
    293         [MVIRCChatConnectionThreadLock unlock]; 
    29496        return _startDate; 
    29597} 
    29698 
    29799- (unsigned long long) startOffset { 
    298         if( ! [self _DCCFileRecord] ) return _startOffset; 
    299         [MVIRCChatConnectionThreadLock lock]; 
    300         _startOffset = [self _DCCFileRecord] -> skipped; 
    301         [MVIRCChatConnectionThreadLock unlock]; 
    302100        return _startOffset; 
    303101} 
     
    306104 
    307105- (NSHost *) host { 
    308         if( _host || ! [self _DCCFileRecord] ) return _host; 
    309         [MVIRCChatConnectionThreadLock lock]; 
    310         _host = [[NSHost hostWithAddress:[NSString stringWithUTF8String:[self _DCCFileRecord] -> addrstr]] retain]; 
    311         [MVIRCChatConnectionThreadLock unlock]; 
    312106        return _host; 
    313107} 
    314108 
    315109- (unsigned short) port { 
    316         if( _port || ! [self _DCCFileRecord] ) return _port; 
    317         [MVIRCChatConnectionThreadLock lock]; 
    318         _port = [self _DCCFileRecord] -> port; 
    319         [MVIRCChatConnectionThreadLock unlock]; 
    320110        return _port; 
    321111} 
     
    328118 
    329119- (NSString *) user { 
    330         if( _user || ! [self _DCCFileRecord] ) return _user; 
    331         [MVIRCChatConnectionThreadLock lock]; 
    332         _user = [[[self connection] stringWithEncodedBytes:[self _DCCFileRecord] -> nick] retain]; 
    333         [MVIRCChatConnectionThreadLock unlock]; 
    334120        return _user; 
    335121} 
     
    338124 
    339125- (void) cancel { 
    340         if( ! [self _DCCFileRecord] ) return; 
    341         [MVIRCChatConnectionThreadLock lock]; 
    342         dcc_close( (DCC_REC *)[self _DCCFileRecord] ); 
    343         [MVIRCChatConnectionThreadLock unlock]; 
    344         [self _setStatus:MVFileTransferStoppedStatus]; 
     126// subclass, don't call super 
     127        [self doesNotRecognizeSelector:_cmd]; 
    345128} 
    346129@end 
     
    349132 
    350133@implementation MVFileTransfer (MVFileTransferPrivate) 
    351 + (id) _transferForDCCFileRecord:(FILE_DCC_REC *) record { 
    352         if( ! record ) return nil; 
    353  
    354         MVFileTransferModuleData *data = MODULE_DATA( record ); 
    355         if( data ) return data -> transfer; 
    356  
    357         return nil; 
    358 } 
    359  
    360 - (FILE_DCC_REC *) _DCCFileRecord { 
    361         return _dcc; 
    362 } 
    363  
    364 - (void) _setDCCFileRecord:(FILE_DCC_REC *) record { 
    365         [MVIRCChatConnectionThreadLock lock]; 
    366  
    367         if( _dcc ) { 
    368                 MVFileTransferModuleData *data = MODULE_DATA( (FILE_DCC_REC *)_dcc ); 
    369                 if( data ) data -> transfer = nil; 
    370                 g_free_not_null( data ); 
    371         } 
    372  
    373         _dcc = record; 
    374  
    375         if( record ) { 
    376                 MVFileTransferModuleData *data = g_new0( MVFileTransferModuleData, 1 ); 
    377                 data -> transfer = self; 
    378                 MODULE_DATA_SET( ((DCC_REC *)record), data ); 
    379         } 
    380  
    381         [MVIRCChatConnectionThreadLock unlock]; 
    382 } 
    383  
    384134- (void) _setConnection:(MVChatConnection *) connection { 
    385135        [_connection autorelease]; 
     
    391141} 
    392142 
    393 - (void) _destroying { 
    394         _passive = [self isPassive]; 
    395         _finalSize = [self finalSize]; 
    396         _transfered = [self transfered]; 
    397         _port = [self port]; 
    398         _startOffset = [self startOffset]; 
    399  
    400         // load the variables simply by calling the accessor 
    401         [self startDate]; 
    402         [self host]; 
    403         [self user]; 
    404  
    405         [self _setDCCFileRecord:NULL]; 
    406 } 
    407  
    408143- (void) _postError:(NSError *) error { 
    409144        [self _setStatus:MVFileTransferErrorStatus]; 
     
    421156@implementation MVUploadFileTransfer 
    422157+ (id) transferWithSourceFile:(NSString *) path toUser:(NSString *) nickname onConnection:(MVChatConnection *) connection passively:(BOOL) passive { 
    423         [super updateExternalIPAddress]; 
    424  
    425         [MVIRCChatConnectionThreadLock lock]; 
    426  
    427         int queue = dcc_queue_new(); 
    428         NSString *source = [[path stringByStandardizingPath] copy]; 
    429  
    430         char *tag = [connection _irssiConnection] -> tag; 
    431  
    432         if( ! passive ) dcc_queue_add( queue, DCC_QUEUE_NORMAL, [nickname UTF8String], [source fileSystemRepresentation], tag, NULL ); 
    433         else dcc_queue_add_passive( queue, DCC_QUEUE_NORMAL, [nickname UTF8String], [source fileSystemRepresentation], tag, NULL ); 
    434  
    435         dcc_queue_send_next( queue ); 
    436  
    437         DCC_REC *dcc = dcc_find_request( DCC_SEND_TYPE, [nickname UTF8String], [[source lastPathComponent] fileSystemRepresentation] ); 
    438  
    439         MVUploadFileTransfer *ret = [[[MVUploadFileTransfer alloc] initWithDCCFileRecord:dcc fromConnection:connection] autorelease]; 
    440         ret -> _source = [[source stringByStandardizingPath] copy]; 
    441         ret -> _transferQueue = queue; 
    442  
    443         [MVIRCChatConnectionThreadLock unlock]; 
    444  
    445         return ret; 
     158        if( [connection type] == MVChatConnectionIRCType ) { 
     159                return [MVIRCUploadFileTransfer transferWithSourceFile:path toUser:nickname onConnection:connection passively:passive]; 
     160        } 
     161 
     162        return nil; 
     163
     164 
     165#pragma mark - 
     166 
     167- (id) initWithUser:(NSString *) user fromConnection:(MVChatConnection *) connection { 
     168        if( ( self = [super initWithUser:user fromConnection:connection] ) ) { 
     169                _source = nil; 
     170        } 
     171         
     172        return self; 
     173
     174 
     175- (void) dealloc { 
     176        [_source release];       
     177        _source = nil;   
     178        [super dealloc]; 
    446179} 
    447180 
     
    461194#pragma mark - 
    462195 
    463 static void MVDownloadFileTransferSpecifyPath( GET_DCC_REC *dcc ) { 
    464         MVDownloadFileTransfer *self = [MVDownloadFileTransfer _transferForDCCFileRecord:(FILE_DCC_REC *)dcc]; 
    465         if( ! self ) return; 
    466         g_free_not_null( dcc -> file ); 
    467         dcc -> file = g_strdup( [[self destination] fileSystemRepresentation] ); 
    468 } 
    469  
    470 #pragma mark - 
    471  
    472 @interface MVDownloadFileTransfer (MVDownloadFileTransferPrivate) 
    473 - (GET_DCC_REC *) _DCCFileRecord; 
    474 @end 
    475  
    476 #pragma mark - 
    477  
    478196@implementation MVDownloadFileTransfer 
    479 + (void) initialize { 
    480         [super initialize]; 
    481         static BOOL tooLate = NO; 
    482         if( ! tooLate ) { 
    483                 [MVIRCChatConnectionThreadLock lock]; 
    484                 signal_add_last( "dcc get receive", (SIGNAL_FUNC) MVDownloadFileTransferSpecifyPath ); 
    485                 [MVIRCChatConnectionThreadLock unlock]; 
    486                 tooLate = YES; 
    487         } 
    488 
    489  
    490 #pragma mark - 
    491  
    492 - (BOOL) isDownload { 
    493         return YES; 
    494 
    495  
    496 #pragma mark - 
    497  
    498 - (id) initWithDCCFileRecord:(void *) record fromConnection:(MVChatConnection *) connection { 
    499         if( ( self = [super initWithDCCFileRecord:record fromConnection:connection] ) ) { 
     197- (id) initWithUser:(NSString *) user fromConnection:(MVChatConnection *) connection { 
     198        if( ( self = [super initWithUser:user fromConnection:connection] ) ) { 
    500199                _destination = nil; 
    501200                _originalFileName = nil; 
     
    520219        [_destination autorelease]; 
    521220        _destination = [[path stringByStandardizingPath] copy]; 
    522  
    523         if( ! [self _DCCFileRecord] ) return; 
    524         [MVIRCChatConnectionThreadLock lock]; 
    525         [self _DCCFileRecord] -> get_type = ( rename ? DCC_GET_RENAME : DCC_GET_OVERWRITE ); 
    526         [MVIRCChatConnectionThreadLock unlock]; 
     221        // subclass if needed, call super 
    527222} 
    528223 
     
    534229 
    535230- (NSString *) originalFileName { 
    536         if( _originalFileName || ! [self _DCCFileRecord] ) return _originalFileName; 
    537         [MVIRCChatConnectionThreadLock lock]; 
    538         _originalFileName = [[[self connection] stringWithEncodedBytes:[self _DCCFileRecord] -> arg] retain]; 
    539         [MVIRCChatConnectionThreadLock unlock]; 
    540231        return _originalFileName; 
    541232} 
     
    543234#pragma mark - 
    544235 
     236- (BOOL) isDownload { 
     237        return YES; 
     238} 
     239 
     240#pragma mark - 
     241 
    545242- (void) reject { 
    546         if( ! [self _DCCFileRecord] ) return; 
    547         [MVIRCChatConnectionThreadLock lock]; 
    548         dcc_reject( (DCC_REC *)[self _DCCFileRecord], [self _DCCFileRecord] -> server ); 
    549         [MVIRCChatConnectionThreadLock unlock]; 
     243// subclass, don't call super 
     244        [self doesNotRecognizeSelector:_cmd]; 
    550245} 
    551246 
     
    557252 
    558253- (void) acceptByResumingIfPossible:(BOOL) resume { 
    559         if( ! [self _DCCFileRecord] ) return; 
    560  
    561         if( ! [[NSFileManager defaultManager] isReadableFileAtPath:[self destination]] ) 
    562                 resume = NO; 
    563  
    564         [MVIRCChatConnectionThreadLock lock]; 
    565  
    566         if( resume ) dcc_send_resume( [self _DCCFileRecord] ); 
    567         else if( dcc_is_passive( [self _DCCFileRecord] ) ) dcc_get_passive( [self _DCCFileRecord] ); 
    568         else dcc_get_connect( [self _DCCFileRecord] ); 
    569  
    570         [MVIRCChatConnectionThreadLock unlock]; 
    571 
    572 @end 
    573  
    574 #pragma mark - 
    575  
    576 @implementation MVDownloadFileTransfer (MVDownloadFileTransferPrivate) 
    577 - (GET_DCC_REC *) _DCCFileRecord { 
    578         return (GET_DCC_REC *)[super _DCCFileRecord]; 
    579 
    580  
    581 - (void) _destroying { 
    582         [self originalFileName]; 
    583         [super _destroying]; 
    584 
    585 @end 
     254// subclass, don't call super 
     255        [self doesNotRecognizeSelector:_cmd]; 
     256
     257@end 
  • trunk/MVFileTransferController.h

    r1823 r1916  
    11NSString *MVPrettyFileSize( unsigned long long size ); 
    22NSString *MVReadableTime( NSTimeInterval date, BOOL longFormat ); 
     3 
     4@class MVFileTransfer; 
    35 
    46@interface MVFileTransferController : NSWindowController { 
     
    2123 
    2224- (void) downloadFileAtURL:(NSURL *) url toLocalFile:(NSString *) path; 
    23 - (void) addFileTransfer:(id) trtansfer; 
     25- (void) addFileTransfer:(id) transfer; 
    2426 
    2527- (IBAction) stopSelectedTransfer:(id) sender; 
  • trunk/MVIRCChatConnection.m

    r1913 r1916  
    33#import "MVChatConnection.h" 
    44#import "MVIRCChatConnection.h" 
    5 #import "MVFileTransfer.h" 
     5#import "MVIRCFileTransfer.h" 
    66#import "MVChatPluginManager.h" 
    77#import "MVChatScriptPlugin.h" 
     
    818818        if( ! self ) return; 
    819819        if( IS_DCC_GET( dcc ) ) { 
    820                 MVDownloadFileTransfer *transfer = [[[MVDownloadFileTransfer alloc] initWithDCCFileRecord:dcc fromConnection:self] autorelease]; 
     820                MVIRCDownloadFileTransfer *transfer = [[[MVIRCDownloadFileTransfer alloc] initWithDCCFileRecord:dcc fromConnection:self] autorelease]; 
    821821                NSNotification *note = [NSNotification notificationWithName:MVDownloadFileTransferOfferNotification object:transfer];            
    822822                [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note];