Changeset 3510

Show
Ignore:
Timestamp:
01/18/06 18:52:56 (3 years ago)
Author:
morris
Message:

New error handling

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCConnection.h

    r3509 r3510  
    133133 
    134134#define WCConnectionReceivedMessage             @"WCConnectionReceivedMessage" 
     135#define WCConnectionReceivedError               @"WCConnectionReceivedError" 
    135136#define WCConnectionSentCommand                 @"WCConnectionSentCommand" 
    136137 
    137138#define WCArgumentsKey                                  @"WCArgumentsKey" 
    138 #define WCIdentifierKey                                 @"WCIdentifierKey" 
    139 #define WCSenderKey                                             @"WCSenderKey" 
     139#define WCMessageKey                                    @"WCMessageKey" 
  • WiredClient/trunk/WCConnection.m

    r3509 r3510  
    308308        int                             error; 
    309309 
    310         error = [[[notification userInfo] objectForKey:WCIdentifierKey] intValue]; 
     310        error = [[[notification userInfo] objectForKey:WCMessageKey] intValue]; 
    311311        message = [[[notification userInfo] objectForKey:WCArgumentsKey] safeObjectAtIndex:0]; 
    312312 
     
    815815        userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 
    816816                fields,                                                         WCArgumentsKey, 
    817                 [NSNumber numberWithInt:message],       WCIdentifierKey, 
     817                [NSNumber numberWithInt:message],       WCMessageKey, 
    818818                NULL]; 
    819819 
  • WiredClient/trunk/WCConnectionController.m

    r3503 r3510  
    106106        } 
    107107 
    108                if([self respondsToSelector:@selector(serverConnectionShouldUnhide:)]) { 
     108        if([self respondsToSelector:@selector(serverConnectionShouldUnhide:)]) { 
    109109                [_connection addObserver:self 
    110110                                                selector:@selector(serverConnectionShouldUnhide:) 
    111111                                                        name:WCServerConnectionShouldUnhide]; 
    112112        } 
    113  
    114 /*      [[self connection] addObserver:self 
    115                                                   selector:@selector(connectionHasAttached:) 
    116                                                           name:WCConnectionHasAttached]; 
    117  
    118         [[self connection] addObserver:self 
    119                                                   selector:@selector(connectionHasReattached:) 
    120                                                           name:WCConnectionHasReattached]; 
    121          
    122         [[self connection] addObserver:self 
    123                                                   selector:@selector(connectionHasClosed:) 
    124                                                           name:WCConnectionHasClosed]; 
    125  
    126         [[self connection] addObserver:self 
    127                                                   selector:@selector(connectionShouldTerminate:) 
    128                                                           name:WCConnectionShouldTerminate]; 
    129  
    130         [[self connection] addObserver:self 
    131                                                   selector:@selector(connectionShouldHide:) 
    132                                                           name:WCConnectionShouldHide]; 
    133  
    134         [[self connection] addObserver:self 
    135                                                   selector:@selector(connectionShouldUnhide:) 
    136                                                           name:WCConnectionShouldUnhide]; 
    137          
    138         [[self connection] addObserver:self 
    139                                                   selector:@selector(connectionServerInfoDidChange:) 
    140                                                           name:WCConnectionServerInfoDidChange]; 
    141  
    142         [[self connection] addObserver:self 
    143                                                   selector:@selector(connectionPrivilegesDidChange:) 
    144                                                           name:WCConnectionPrivilegesDidChange];*/ 
    145113 
    146114        return self; 
  • WiredClient/trunk/WCError.h

    r3413 r3510  
    2727 */ 
    2828 
    29 enum WCErrorType { 
    30         WCErrorNone, 
    31         WCErrorUndefined, 
    32         WCErrorInternal, 
    33         WCSystemErrorUndefined, 
    34         WCSystemErrorNoMemory, 
    35         WCSystemErrorConnectionRefused, 
    36         WCSSLErrorUndefined, 
    37         WCAddressErrorUndefined, 
    38         WCAddressErrorResolveFailed, 
    39         WCHostErrorUndefined, 
    40         WCHostErrorResolveFailed, 
    41         WCServerErrorUndefined, 
    42         WCServerErrorCommandFailed, 
    43         WCServerErrorCommandNotRecognized, 
    44         WCServerErrorCommandNotImplemented, 
    45         WCServerErrorSyntaxError, 
    46         WCServerErrorLoginFailed, 
    47         WCServerErrorBanned, 
    48         WCServerErrorClientNotFound, 
    49         WCServerErrorAccountNotFound, 
    50         WCServerErrorAccountExists, 
    51         WCServerErrorCannotBeDisconnected, 
    52         WCServerErrorPermissionDenied, 
    53         WCServerErrorFileNotFound, 
    54         WCServerErrorFileExists, 
    55         WCServerErrorChecksumMismatch, 
    56         WCServerErrorQueueLimitExceeded, 
    57         WCApplicationErrorUndefined, 
    58         WCApplicationErrorServerDisconnected, 
    59         WCApplicationErrorOpenFailed, 
    60         WCApplicationErrorCreateFailed, 
    61         WCApplicationErrorFileExists, 
    62         WCApplicationErrorFolderExists, 
    63         WCApplicationErrorChecksumMismatch, 
    64         WCApplicationErrorTransferExists, 
    65         WCApplicationErrorTransferFailed, 
    66         WCApplicationErrorCannotDownload, 
    67         WCApplicationErrorCannotUpload, 
    68         WCApplicationErrorCannotUploadAnywhere, 
    69         WCApplicationErrorCannotCreateFolders, 
    70         WCApplicationErrorCannotDeleteFiles, 
    71         WCApplicationErrorCannotDeleteFolders, 
    72         WCApplicationErrorCannotEditAccounts, 
    73         WCApplicationErrorProtocolMismatch 
     29enum { 
     30        foo, 
     31/*      WCWiredClientServerDisconnected, 
     32        WCWiredClientOpenFailed, 
     33        WCWiredClientCreateFailed, 
     34        WCWiredClientFileExists, 
     35        WCWiredClientFolderExists, 
     36        WCWiredClientChecksumMismatch, 
     37        WCWiredClientTransferExists, 
     38        WCWiredClientTransferFailed, 
     39        WCWiredClientCannotDownload, 
     40        WCWiredClientCannotUpload, 
     41        WCWiredClientCannotUploadAnywhere, 
     42        WCWiredClientCannotCreateFolders, 
     43        WCWiredClientCannotDeleteFiles, 
     44        WCWiredClientCannotDeleteFolders, 
     45        WCWiredClientCannotEditAccounts, 
     46        WCWiredClientProtocolMismatch,*/ 
    7447}; 
    75 typedef enum WCErrorType                        WCErrorType; 
    7648 
    7749 
    78 @interface WCError : WIObject { 
    79         NSRecursiveLock                                 *_lock; 
    80         NSMutableDictionary                             *_errors; 
    81         NSMutableDictionary                             *_messages; 
    82         NSMutableDictionary                             *_arguments; 
    83         NSMutableDictionary                             *_connections; 
    84 
     50@interface WCError : WIError 
    8551 
    86  
    87 + (WCError *)error; 
    88  
    89 - (void)setError:(WCErrorType)error; 
    90 - (WCErrorType)error; 
    91 - (void)setArgument:(NSString *)argument; 
    92 - (NSString *)argument; 
    93 - (void)setMessage:(NSString *)message; 
    94 - (NSString *)message; 
    95  
    96 + (void)setWithError:(WCErrorType)value; 
    97 + (void)setWithWiredError:(int)value; 
    98 + (void)setWithErrno:(int)value; 
    99 + (void)setWithSSLError; 
    100 + (void)setWithAddressError:(int)value; 
    101 + (void)setWithHostError:(int)value; 
    102 + (void)setArgument:(NSString *)argument; 
    103 + (void)setMessage:(NSString *)message; 
    104  
    105 + (void)show; 
    106 + (void)showInWindow:(NSWindow *)window; 
    107 - (void)showInWindow:(NSWindow *)window; 
     52#define WCWiredClientErrorDomain        @"WCWiredClientErrorDomain" 
     53#define WCWiredErrorDomain                      @"WCWiredErrorDomain" 
    10854 
    10955@end 
  • WiredClient/trunk/WCError.m

    r3509 r3510  
    2727 */ 
    2828 
    29 #import "WCMain.h" 
    30  
    3129@implementation WCError 
    3230 
    33 + (WCError *)error { 
    34         static id       sharedError; 
    35  
    36         if(!sharedError) 
    37                 sharedError = [[WCError alloc] init]; 
    38  
    39         return sharedError; 
     31- (NSString *)localizedDescription { 
     32        if([[self domain] isEqualToString:WCWiredClientErrorDomain]) { 
     33        } 
     34        else if([[self domain] isEqualToString:WCWiredErrorDomain]) { 
     35                switch([self code]) { 
     36                        case 500: 
     37                                return NSLS(@"Server Error", @"Wired Protocol error 500 title"); 
     38                                break; 
     39 
     40                        case 501: 
     41                                return NSLS(@"Server Error", @"Wired Protocol error 501 title"); 
     42                                break; 
     43 
     44                        case 502: 
     45                                return NSLS(@"Server Error", @"Wired Protocol error 502 title"); 
     46                                break; 
     47 
     48                        case 503: 
     49                                return NSLS(@"Server Error", @"Wired Protocol error 503 title"); 
     50                                break; 
     51 
     52                        case 510: 
     53                                return NSLS(@"Login Failed", @"Wired Protocol error 510 title"); 
     54                                break; 
     55 
     56                        case 511: 
     57                                return NSLS(@"Banned", @"Wired Protocol error 511 title"); 
     58                                break; 
     59 
     60                        case 512: 
     61                                return NSLS(@"Client Not Found", @"Wired Protocol error 512 title"); 
     62                                break; 
     63 
     64                        case 513: 
     65                                return NSLS(@"Account Not found", @"Wired Protocol error 513 title"); 
     66                                break; 
     67 
     68                        case 514: 
     69                                return NSLS(@"Account Exists", @"Wired Protocol error 514 title"); 
     70                                break; 
     71 
     72                        case 515: 
     73                                return NSLS(@"Cannot Be Disconnected", @"Wired Protocol error 515 title"); 
     74                                break; 
     75 
     76                        case 516: 
     77                                return NSLS(@"Permission Denied", @"Wired Protocol error 516 title"); 
     78                                break; 
     79 
     80                        case 520: 
     81                                return NSLS(@"File or Folder Not Found", @"Wired Protocol error 520 title"); 
     82                                break; 
     83 
     84                        case 521: 
     85                                return NSLS(@"File or Folder Exists", @"Wired Protocol error 521 title"); 
     86                                break; 
     87 
     88                        case 522: 
     89                                return NSLS(@"Checksum Mismatch", @"Wired Protocol error 522 title"); 
     90                                break; 
     91 
     92                        case 523: 
     93                                return NSLS(@"Queue Limit Exceeded", @"Wired Protocol error 523 title"); 
     94                                break; 
     95                         
     96                        default: 
     97                                return NSLS(@"Server Error", @"Wired Protocol unknown error title"); 
     98                                break; 
     99                } 
     100        } 
     101         
     102        return [super localizedDescription]; 
    40103} 
    41104 
    42105 
    43106 
    44 - (id)init { 
    45         self = [super init]; 
    46  
    47         _lock = [[NSRecursiveLock alloc] init]; 
    48         _errors = [[NSMutableDictionary alloc] init]; 
    49         _messages = [[NSMutableDictionary alloc] init]; 
    50         _arguments = [[NSMutableDictionary alloc] init]; 
    51         _connections = [[NSMutableDictionary alloc] init]; 
     107- (NSString *)localizedFailureReason { 
     108        NSString                *argument; 
    52109         
    53         // --- subscribe to these 
    54 /*      [[WCMain main] addObserver:self 
    55                                           selector:@selector(connectionHasAttached:) 
    56                                                   name:WCConnectionHasAttached]; 
    57  
    58         [[WCMain main] addObserver:self 
    59                                           selector:@selector(connectionShouldTerminate:) 
    60                                                   name:WCConnectionShouldTerminate];*/ 
    61          
    62         return self; 
     110        argument = [[self userInfo] objectForKey:WIArgumentErrorKey]; 
     111 
     112        if([[self domain] isEqualToString:WCWiredClientErrorDomain]) { 
     113/*              case WCWiredClientServerDisconnected: 
     114                        return NSLS(@"Server Disconnected", @"WCWiredClientServerDisconnected title"); 
     115                        return NSLS(@"The server has unexpectedly disconnected.", @"Server disconnected error dialog description"); 
     116                        break; 
     117 
     118                case WCWiredClientOpenFailed: 
     119                        return NSLS(@"Open Failed", @"Error"); 
     120                        return [NSSWF:NSLS(@"Could not open the file \"%@\".", @"Error (path)"), 
     121                                [self argument]]; 
     122                        break; 
     123 
     124                case WCWiredClientCreateFailed: 
     125                        return NSLS(@"Create Failed", @"Error"); 
     126                        return [NSSWF:NSLS(@"Could not create the file \"%@\".", @"Error (path)"), 
     127                                [self argument]]; 
     128                        break; 
     129 
     130                case WCWiredClientFileExists: 
     131                        return NSLS(@"File Exists", @"Error"); 
     132                        return [NSSWF:NSLS(@"The file \"%@\" already exists.", @"Error (path)"), 
     133                                [self argument]]; 
     134                        break; 
     135 
     136                case WCWiredClientFolderExists: 
     137                        return NSLS(@"Folder Exists", @"Error"); 
     138                        return [NSSWF:NSLS(@"The folder \"%@\" already exists.", @"Error (path)"), 
     139                                [self argument]]; 
     140                        break; 
     141 
     142                case WCWiredClientChecksumMismatch: 
     143                        return NSLS(@"Checksum Mismatch", @"Error"); 
     144                        return [NSSWF:NSLS(@"Could not resume transfer of \"%@\", the checksums do not match.", @"Error (path)"), 
     145                                [self argument]]; 
     146                        break; 
     147 
     148                case WCWiredClientTransferExists: 
     149                        return NSLS(@"Transfer Exists", @"Error"); 
     150                        return [NSSWF:NSLS(@"You are already transferring \"%@\".", @"Error (path)"), 
     151                                [self argument]]; 
     152                        break; 
     153 
     154                case WCWiredClientTransferFailed: 
     155                        return NSLS(@"Transfer Failed", @"Error"); 
     156                        return [NSSWF:NSLS(@"The transfer of \"%@\" failed.", @"Error (path)"), 
     157                                [self argument]]; 
     158                        break; 
     159 
     160                case WCWiredClientCannotDownload: 
     161                        return NSLS(@"Cannot Download", @"Error"); 
     162                        return NSLS(@"You do not have sufficient privileges to download files.", @"Error"); 
     163                        break; 
     164 
     165                case WCWiredClientCannotUpload: 
     166                        return NSLS(@"Cannot Upload", @"Error"); 
     167                        return NSLS(@"You do not have sufficient privileges to upload files.", @"Error"); 
     168                        break; 
     169 
     170                case WCWiredClientCannotUploadAnywhere: 
     171                        return NSLS(@"Cannot Upload Anywhere", @"Error"); 
     172                        return NSLS(@"You can only upload in Upload and Drop Box folders.", @"Error"); 
     173                        break; 
     174 
     175                case WCWiredClientCannotCreateFolders: 
     176                        return NSLS(@"Cannot Create Folders", "Error"); 
     177                        return NSLS(@"You do not have sufficient privileges to create folders on the server.", "Error"); 
     178                        break; 
     179 
     180                case WCWiredClientCannotDeleteFiles: 
     181                        return NSLS(@"Cannot Delete", "Error"); 
     182                        return NSLS(@"You do not have sufficient privileges to delete files.", "Error"); 
     183                        break; 
     184 
     185                case WCWiredClientCannotDeleteFolders: 
     186                        return NSLS(@"Cannot Delete", "Error"); 
     187                        return NSLS(@"You do not have sufficient privileges to delete folders.", "Error"); 
     188                        break; 
     189 
     190                case WCWiredClientCannotEditAccounts: 
     191                        return NSLS(@"Cannot Edit Accounts", "Error"); 
     192                        return NSLS(@"You do not have sufficient privileges to edit accounts.", "Error"); 
     193                        break; 
     194 
     195                case WCWiredClientProtocolMismatch: 
     196                        return NSLS(@"Protocol Mismatch", "Error"); 
     197                        return NSLS(@"This server uses a newer protocol version than this client supports. Protocol errors may occur during the connection.", "Error"); 
     198                        break; 
     199                 
     200                default: 
     201                        break;*/ 
     202        } 
     203        else if([[self domain] isEqualToString:WCWiredErrorDomain]) { 
     204                switch([self code]) { 
     205                        case 500: 
     206                                return NSLS(@"The server failed to process a command. The server administrator can check the log for more information.", @"Wired Protocol error 500 description"); 
     207                                break; 
     208 
     209                        case 501: 
     210                                return NSLS(@"The server did not recognize a command. This is probably because of an protocol incompatibility between the client and the server.", @"Wired Protocol error 501 description"); 
     211                                break; 
     212 
     213                        case 502: 
     214                                return NSLS(@"The server has not implemented a command. This is probably because of an protocol incompatibility between the client and the server.", @"Wired Protocol error 502 description"); 
     215                                break; 
     216 
     217                        case 503: 
     218                                return NSLS(@"The server could not parse a command. This is probably because of an protocol incompatibility between the client and the server.", @"Wired Protocol error 503 description"); 
     219                                break; 
     220 
     221                        case 510: 
     222                                return NSLS(@"Could not login, the user name and/or password you supplied was rejected.", @"Wired Protocol error 510 description"); 
     223                                break; 
     224 
     225                        case 511: 
     226                                return NSLS(@"Could not login, you are banned from this server.", @"Wired Protocol error 511 description"); 
     227                                break; 
     228 
     229                        case 512: 
     230                                return NSLS(@"Could not find the client you referred to. Perhaps that client left before the command could be completed.", @"Wired Protocol error 512 description"); 
     231                                break; 
     232 
     233                        case 513: 
     234                                return NSLS(@"Could not find the account you referred to. Perhaps someone deleted it.", @"Wired Protocol error 513 description"); 
     235                                break; 
     236 
     237                        case 514: 
     238                                return NSLS(@"The account you tried to create already exists on the server.", @"Wired Protocol error 514 description"); 
     239                                break; 
     240 
     241                        case 515: 
     242                                return NSLS(@"The client you tried to disconnect is protected.", @"Wired Protocol error 515 description"); 
     243                                break; 
     244 
     245                        case 516: 
     246                                return NSLS(@"The command could not be completed due to insufficient privileges.", @"Wired Protocol error 516 description"); 
     247                                break; 
     248 
     249                        case 520: 
     250                                return NSLS(@"Could not find the file or folder you referred to. Perhaps someone deleted it.", @"Wired Protocol error 520 description"); 
     251                                break; 
     252 
     253                        case 521: 
     254                                return NSLS(@"Could not create the file or directory, it already exists.", @"Wired Protocol error 521 description"); 
     255                                break; 
     256 
     257                        case 522: 
     258                                return NSLS(@"Could not start an upload, the checksums do not match.", @"Wired Protocol error 522 description"); 
     259                                break; 
     260 
     261                        case 523: 
     262                                return NSLS(@"Could not start a transfer, the limit has been exceeded.", @"Wired Protocol error 523 description"); 
     263                                break; 
     264                         
     265                        default: 
     266                                return [NSSWF:NSLS(@"An unknown server error occured. The message we got back was: \"%d %@\".", @"Wired Protocol unknown error description (code, message)"), 
     267                                        [self code], argument]; 
     268                                break; 
     269                } 
     270        } 
     271 
     272        return [[self superclass] instancesRespondToSelector:_cmd] ? [(id) super localizedFailureReason] : NULL; 
    63273} 
    64274 
    65  
    66  
    67 #pragma mark - 
    68  
    69 - (void)connectionHasAttached:(NSNotification *)notification { 
    70         [_lock lock]; 
    71         [_connections setObject:[notification object] forKey:[[WIThread currentThread] threadIdentifier]]; 
    72         [_lock unlock]; 
    73 } 
    74  
    75  
    76  
    77 - (void)connectionShouldTerminate:(NSNotification *)notificiation { 
    78         [_lock lock]; 
    79         [_connections removeObjectForKey:[[WIThread currentThread] threadIdentifier]]; 
    80         [_lock unlock]; 
    81 } 
    82  
    83  
    84  
    85 #pragma mark - 
    86  
    87 - (void)setError:(WCErrorType)error { 
    88         [_lock lock]; 
    89         [_errors setObject:[NSNumber numberWithInt:error] forKey:[[WIThread currentThread] threadIdentifier]]; 
    90         [_lock unlock]; 
    91 } 
    92  
    93  
    94  
    95 - (WCErrorType)error { 
    96         WCErrorType             error; 
    97  
    98         [_lock lock]; 
    99         error = [[_errors objectForKey:[[WIThread currentThread] threadIdentifier]] intValue]; 
    100         [_lock unlock]; 
    101  
    102         return error; 
    103 } 
    104  
    105  
    106  
    107 - (void)setArgument:(NSString *)argument { 
    108         [_lock lock]; 
    109         [_arguments setObject:argument forKey:[[WIThread currentThread] threadIdentifier]]; 
    110         [_lock unlock]; 
    111 } 
    112  
    113  
    114  
    115 - (NSString *)argument { 
    116         NSString                *argument; 
    117  
    118         [_lock lock]; 
    119         argument = [_arguments objectForKey:[[WIThread currentThread] threadIdentifier]]; 
    120         [_lock unlock]; 
    121  
    122         return argument; 
    123 } 
    124  
    125  
    126  
    127 - (void)setMessage:(NSString *)message { 
    128         [_lock lock]; 
    129         [_messages setObject:message forKey:[[WIThread currentThread] threadIdentifier]]; 
    130         [_lock unlock]; 
    131 } 
    132  
    133  
    134  
    135 - (NSString *)message { 
    136         NSString                *message; 
    137  
    138         [_lock lock]; 
    139         message = [_messages objectForKey:[[WIThread currentThread] threadIdentifier]]; 
    140         [_lock unlock]; 
    141  
    142         return message; 
    143 } 
    144  
    145  
    146  
    147 #pragma mark - 
    148  
    149 + (void)setWithError:(WCErrorType)value { 
    150         [[self error] setError:value]; 
    151 } 
    152  
    153  
    154  
    155 + (void)setWithWiredError:(int)value { 
    156         WCErrorType             error; 
    157  
    158         // --- translate wired error 
    159         switch(value) { 
    160                 case 500: 
    161                         error = WCServerErrorCommandFailed; 
    162                         break; 
    163  
    164                 case 501: 
    165                         error = WCServerErrorCommandNotRecognized; 
    166                         break; 
    167  
    168                 case 502: 
    169                         error = WCServerErrorCommandNotImplemented; 
    170                         break; 
    171  
    172                 case 503: 
    173                         error = WCServerErrorSyntaxError; 
    174                         break; 
    175  
    176                 case 510: 
    177                         error = WCServerErrorLoginFailed; 
    178                         break; 
    179  
    180                 case 511: 
    181                         error = WCServerErrorBanned; 
    182                         break; 
    183  
    184                 case 512: 
    185                         error = WCServerErrorClientNotFound; 
    186                         break; 
    187  
    188                 case 513: 
    189                         error = WCServerErrorAccountNotFound; 
    190                         break; 
    191  
    192                 case 514: 
    193                         error = WCServerErrorAccountExists; 
    194                         break; 
    195  
    196                 case 515: 
    197                         error = WCServerErrorCannotBeDisconnected; 
    198                         break; 
    199  
    200                 case 516: 
    201                         error = WCServerErrorPermissionDenied; 
    202                         break; 
    203  
    204                 case 520: 
    205                         error = WCServerErrorFileNotFound; 
    206                         break; 
    207  
    208                 case 521: 
    209                         error = WCServerErrorFileExists; 
    210                         break; 
    211  
    212                 case 522: 
    213                         error = WCServerErrorChecksumMismatch; 
    214                         break; 
    215  
    216                 case 523: 
    217                         error = WCServerErrorQueueLimitExceeded; 
    218                         break; 
    219  
    220                 default: 
    221                         error = WCServerErrorUndefined; 
    222                         break; 
    223         } 
    224  
    225         [[self error] setError:error]; 
    226 } 
    227  
    228  
    229  
    230 + (void)setWithErrno:(int)value { 
    231         WCErrorType             error; 
    232  
    233         // --- translate system error 
    234         switch(value) { 
    235                 case ENOMEM: 
    236                         error = WCSystemErrorNoMemory; 
    237                         break; 
    238  
    239                 case ECONNREFUSED: 
    240                         error = WCSystemErrorConnectionRefused; 
    241                         break; 
    242  
    243                 default: 
    244                         error = WCSystemErrorUndefined; 
    245                         break; 
    246         } 
    247  
    248         [[self error] setError:error]; 
    249         [[self error] setMessage:[NSString stringWithCString:strerror(value)]]; 
    250 } 
    251  
    252  
    253  
    254 + (void)setWithSSLError { 
    255         WCErrorType             error; 
    256         unsigned long   value; 
    257  
    258         // --- translate SSL error 
    259         value = ERR_get_error(); 
    260  
    261         switch(value) { 
    262                 case 0: 
    263                         [WCError setWithErrno:errno]; 
    264                         return; 
    265                         break; 
    266  
    267                 default: 
    268                         error = WCSSLErrorUndefined; 
    269                         break; 
    270         } 
    271  
    272         [[self error] setError:error]; 
    273         [[self error] setMessage:[NSString stringWithCString:ERR_reason_error_string(value)]]; 
    274 } 
    275  
    276  
    277  
    278 + (void)setWithAddressError:(int)value { 
    279         WCErrorType             error; 
    280  
    281         // --- translate address error 
    282         switch(value) { 
    283                 case EAI_ADDRFAMILY: 
    284                 case EAI_BADFLAGS: 
    285                 case EAI_FAMILY: 
    286                 case EAI_NONAME: 
    287                 case EAI_SERVICE: 
    288                 case EAI_SOCKTYPE: 
    289                         error = WCErrorInternal; 
    290                         break; 
    291  
    292                 case EAI_AGAIN: 
    293                 case EAI_FAIL: 
    294                 case EAI_NODATA: 
    295                         error = WCAddressErrorResolveFailed; 
    296                         break; 
    297  
    298                 case EAI_MEMORY: 
    299                         error = WCSystemErrorNoMemory; 
    300                         break; 
    301  
    302                 case EAI_SYSTEM: 
    303                         [WCError setWithError:errno]; 
    304                         return; 
    305                         break; 
    306  
    307                 default: 
    308                         error = WCAddressErrorUndefined; 
    309                         break; 
    310         } 
    311  
    312         [[self error] setError:error]; 
    313         [[self error] setMessage:[NSString stringWithCString:gai_strerror(value)]]; 
    314 } 
    315  
    316  
    317  
    318 + (void)setWithHostError:(int)value { 
    319         WCErrorType                     error; 
    320  
    321         // --- translate host error 
    322         switch(value) { 
    323                 case HOST_NOT_FOUND: 
    324                 case TRY_AGAIN: 
    325                 case NO_RECOVERY: 
    326                 case NO_DATA: 
    327                         error = WCHostErrorResolveFailed; 
    328                         break; 
    329  
    330                 default: 
    331                         error = WCHostErrorUndefined; 
    332                         break; 
    333         } 
    334  
    335         [[self error] setError:error]; 
    336         [[self error] setMessage:[NSString stringWithCString:hstrerror(value)]]; 
    337 } 
    338  
    339  
    340  
    341 + (void)setArgument:(NSString *)argument { 
    342         [[self error] setArgument:argument]; 
    343 } 
    344  
    345  
    346  
    347 + (void)setMessage:(NSString *)message { 
    348         [[self error] setMessage:message]; 
    349 } 
    350  
    351  
    352  
    353 #pragma mark - 
    354  
    355 + (void)show { 
    356         [[self error] showInWindow:NULL]; 
    357 } 
    358  
    359  
    360  
    361  
    362 + (void)showInWindow:(NSWindow *)window { 
    363         [[self error] showInWindow:window]; 
    364 } 
    365  
    366  
    367  
    368 - (void)showInWindow:(NSWindow *)window { 
    369         NSString                        *title, *description; 
    370         WCServerConnection      *connection; 
    371  
    372         switch([self error]) { 
    373                 // --- system errors 
    374                 case WCSystemErrorUndefined: 
    375                         title = NSLS(@"System Error", @"Error"); 
    376                         description = [NSSWF:NSLS(@"Got the following system error: %@.", @"Error (error)"), 
    377                                 [self message]]; 
    378                         break; 
    379  
    380                 case WCSystemErrorConnectionRefused: 
    381                         title = NSLS(@"Connection Refused", @"Error"); 
    382                         description = [NSSWF:NSLS(@"Could not connect to \"%@\".", @"Error (host)"), 
    383                                 [self argument]]; 
    384                         break; 
    385  
    386                 // --- SSL errors 
    387                 case WCSSLErrorUndefined: 
    388                         title = NSLS(@"SSL Error", @"Error"); 
    389                         description = [NSSWF:NSLS(@"Got the following SSL error: %@.", @"Error (error)"), 
    390                                 [self message]]; 
    391                         break; 
    392  
    393                 // --- address/host errors 
    394                 case WCAddressErrorUndefined: 
    395                 case WCHostErrorUndefined: 
    396                         title = NSLS(@"Resolve Failed", @"Error"); 
    397                         description = [NSSWF:NSLS(@"Could not resolve \"%@\". Got the following system error: %@.", @"Error (host, error)"), 
    398                                 [self argument], 
    399                                 [self message]]; 
    400                         break; 
    401  
    402                 case WCAddressErrorResolveFailed: 
    403                 case WCHostErrorResolveFailed: 
    404                         title = NSLS(@"Resolve Failed", @"Error"); 
    405                         description = [NSSWF:NSLS(@"Could not resolve \"%@\".", @"Error (host)"), 
    406                                 [self argument]]; 
    407                         break; 
    408  
    409                 // --- server errors 
    410                 case WCServerErrorUndefined: 
    411                         title = NSLS(@"Server Error", @"Error"); 
    412                         description = [NSSWF:NSLS(@"Got the following server error: %@.", @"Error (error)"), 
    413                                 [self message]]; 
    414                         break; 
    415  
    416                 case WCServerErrorCommandFailed: 
    417                 case WCServerErrorCommandNotImplemented: 
    418                         title = NSLS(@"Server Error", @"Error"); 
    419                         description = NSLS(@"An internal server error occured. Please contact the server administrator.", @"Error"); 
    420                         break; 
    421  
    422                 case WCServerErrorLoginFailed: 
    423                         title = NSLS(@"Login Failed", @"Error"); 
    424                         description = NSLS(@"Could not login, the user name and/or password you supplied was incorrect.", @"Error"); 
    425                         break; 
    426  
    427                 case WCServerErrorBanned: 
    428                         title = NSLS(@"Banned", @"Error"); 
    429                         description = NSLS(@"Could not login, you are banned from this server.", @"Error"); 
    430                         break; 
    431  
    432                 case WCServerErrorClientNotFound: 
    433                         title = NSLS(@"Client Not Found", @"Error"); 
    434                         description = NSLS(@"Could not find the client you referred to. Perhaps that client left before the command could be completed.", @"Error"); 
    435                         break; 
    436  
    437                 case WCServerErrorAccountNotFound: 
    438                         title = NSLS(@"Account Not found", @"Error"); 
    439                         description = NSLS(@"Could not find the account you referred to. Perhaps someone deleted it.", @"Error"); 
    440                         break; 
    441  
    442                 case WCServerErrorAccountExists: 
    443                         title = NSLS(@"Account Exists", @"Error"); 
    444                         description = NSLS(@"The account you tried to create already exists on the server.", @"Error"); 
    445                         break; 
    446  
    447                 case WCServerErrorCannotBeDisconnected: 
    448                         title = NSLS(@"Cannot Be Disconnected", @"Error"); 
    449                         description = NSLS(@"The client you tried to disconnect is proteceted. You cannot disconnect that client.", @"Error"); 
    450                         break