Changeset 6301
- Timestamp:
- 11/03/08 17:55:02 (2 months ago)
- Files:
-
- trunk/WiredClient/WCChat.h (modified) (1 diff)
- trunk/WiredClient/WCChat.m (modified) (4 diffs)
- trunk/WiredClient/WCConnection.h (modified) (1 diff)
- trunk/WiredClient/WCMessages.m (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/WiredClient/WCChat.h
r5319 r6301 92 92 93 93 94 + (NSString *)outputForShellCommand:(NSString *)command; 95 94 96 - (id)initChatWithConnection:(WCServerConnection *)connection windowNibName:(NSString *)windowNibName name:(NSString *)name; 95 97 trunk/WiredClient/WCChat.m
r5319 r6301 406 406 } 407 407 else if([command isEqualToString:@"/exec"] && [argument length] > 0) { 408 NSTask *task;409 NSPipe *pipe;410 NSFileHandle *fileHandle;411 NSDictionary *environment;412 NSData *data;413 408 NSString *output; 414 double timeout = 10.0; 415 416 pipe = [NSPipe pipe]; 417 fileHandle = [pipe fileHandleForReading]; 418 419 environment = [NSDictionary dictionaryWithObjectsAndKeys: 420 @"/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin", 421 @"PATH", 422 NULL]; 423 424 task = [[NSTask alloc] init]; 425 [task setLaunchPath:@"/bin/sh"]; 426 [task setArguments:[NSArray arrayWithObjects:@"-c", argument, NULL]]; 427 [task setStandardOutput:pipe]; 428 [task setStandardError:pipe]; 429 [task setEnvironment:environment]; 430 [task launch]; 431 432 while([task isRunning]) { 433 sleep(1); 434 timeout -= 1.0; 435 436 if(timeout <= 0.0) { 437 [task terminate]; 438 439 break; 440 } 441 } 442 443 data = [fileHandle readDataToEndOfFile]; 444 output = [NSString stringWithData:data encoding:NSUTF8StringEncoding]; 409 410 output = [[self class] outputForShellCommand:argument]; 445 411 446 412 if(output && [output length] > 0) { … … 451 417 withArgument:[NSSWF:@"%u", [self chatID]] 452 418 withArgument:output]; 453 454 [[WCStats stats] addUnsignedLongLong:[output length] forKey:WCStatsChat];455 419 } 456 457 [task release];458 420 459 421 return YES; … … 494 456 return YES; 495 457 } 496 #ifndef RELEASE497 else if([command isEqualToString:@"/dump"]) {498 [[self connection] sendCommand:WCDumpCommand];499 500 return YES;501 }502 #endif503 458 else if([command isEqualToString:@"/ping"]) { 504 459 if(!_receivingPings) { … … 601 556 602 557 @implementation WCChat 558 559 + (NSString *)outputForShellCommand:(NSString *)command { 560 NSTask *task; 561 NSPipe *pipe; 562 NSFileHandle *fileHandle; 563 NSDictionary *environment; 564 NSData *data; 565 double timeout = 5.0; 566 567 pipe = [NSPipe pipe]; 568 fileHandle = [pipe fileHandleForReading]; 569 570 environment = [NSDictionary dictionaryWithObject:@"/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" 571 forKey:@"PATH"]; 572 573 task = [[[NSTask alloc] init] autorelease]; 574 [task setLaunchPath:@"/bin/sh"]; 575 [task setArguments:[NSArray arrayWithObjects:@"-c", command, NULL]]; 576 [task setStandardOutput:pipe]; 577 [task setStandardError:pipe]; 578 [task setEnvironment:environment]; 579 [task launch]; 580 581 while([task isRunning]) { 582 usleep(100000); 583 timeout -= 0.1; 584 585 if(timeout <= 0.0) { 586 [task terminate]; 587 588 break; 589 } 590 } 591 592 data = [fileHandle readDataToEndOfFile]; 593 594 return [NSString stringWithData:data encoding:NSUTF8StringEncoding]; 595 } 596 597 598 599 #pragma mark - 603 600 604 601 + (id)allocWithZone:(NSZone *)zone { trunk/WiredClient/WCConnection.h
r5743 r6301 58 58 #define WCDeleteUserCommand @"DELETEUSER" 59 59 #define WCDeleteGroupCommand @"DELETEGROUP" 60 #define WCDumpCommand @"DUMP"61 60 #define WCEditUserCommand @"EDITUSER" 62 61 #define WCEditGroupCommand @"EDITGROUP" trunk/WiredClient/WCMessages.m
r6255 r6301 57 57 58 58 - (void)_showDialogForMessage:(WCMessage *)message; 59 - (NSString *)_stringForMessageString:(NSString *)string; 59 60 60 61 - (void)_update; … … 150 151 151 152 153 - (NSString *)_stringForMessageString:(NSString *)string { 154 NSString *command, *argument; 155 NSRange range; 156 157 range = [string rangeOfString:@" "]; 158 159 if(range.location == NSNotFound) { 160 command = string; 161 argument = @""; 162 } else { 163 command = [string substringToIndex:range.location]; 164 argument = [string substringFromIndex:range.location + 1]; 165 } 166 167 if([command isEqualToString:@"/exec"] && [argument length] > 0) 168 return [WCChat outputForShellCommand:argument]; 169 else if([command isEqualToString:@"/stats"]) 170 return [[WCStats stats] stringValue]; 171 172 return string; 173 } 174 175 176 152 177 #pragma mark - 153 178 … … 901 926 - (void)broadcastSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo { 902 927 if(returnCode == NSAlertDefaultReturn) 903 [[self connection] sendCommand:WCBroadcastCommand withArgument:[ _broadcastTextView string]];928 [[self connection] sendCommand:WCBroadcastCommand withArgument:[self _stringForMessageString:[_broadcastTextView string]]]; 904 929 905 930 [_broadcastPanel close]; … … 947 972 } 948 973 949 message = [WCMessage messageToUser:_messageUser string:[[[_replyTextView string] copy] autorelease] conversation:conversation];974 message = [WCMessage messageToUser:_messageUser string:[[[_replyTextView string] copy] autorelease] conversation:conversation]; 950 975 951 976 [_allMessages addObject:message]; … … 953 978 [[self connection] sendCommand:WCMessageCommand 954 979 withArgument:[NSSWF:@"%u", [message userID]] 955 withArgument:[ message message]];980 withArgument:[self _stringForMessageString:[message message]]]; 956 981 957 982 [[WCStats stats] addUnsignedInt:1 forKey:WCStatsMessagesSent];
