implement support for multiline responses

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28251 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-04-26 13:45:47 +00:00
parent f8a3d4fe5d
commit 0acc1506cd
2 changed files with 42 additions and 3 deletions

View file

@ -1,3 +1,8 @@
2009-04-26 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSFTPURLHandle.m: Implement full support for multiline
responses. Fix for bug #26348
2009-04-26 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSTimeZone.h:

View file

@ -485,6 +485,7 @@ NSString * const GSTelnetTextKey = @"GSTelnetTextKey";
NSFileHandle *dHandle;
NSURL *url;
NSData *wData;
NSString *term;
enum {
idle,
cConnect, // Establishing control connection
@ -553,6 +554,7 @@ static NSLock *urlLock = nil;
}
RELEASE(url);
RELEASE(wData);
RELEASE(term);
[super dealloc];
}
@ -598,14 +600,46 @@ static NSLock *urlLock = nil;
text = [info objectForKey: GSTelnetTextKey];
// NSLog(@"Ctl: %@", text);
/*
* Find first reply line which is not a continuation of another.
/* Find first reply line which is not a continuation of another.
*/
enumerator = [text objectEnumerator];
while ((line = [enumerator nextObject]) != nil)
{
if ([line length] > 4 && [line characterAtIndex: 3] != '-')
if (term == nil)
{
if ([line length] > 4)
{
char buf[4];
buf[0] = (char)[line characterAtIndex: 0];
buf[1] = (char)[line characterAtIndex: 1];
buf[2] = (char)[line characterAtIndex: 2];
buf[3] = (char)[line characterAtIndex: 3];
if (isdigit(buf[0]) && isdigit(buf[1]) && isdigit(buf[2]))
{
if (buf[3] == '-')
{
/* Got start of a multiline block ...
* set the terminator we need to look for.
*/
buf[3] = ' ';
term = [[NSString alloc]
initWithCString: buf length: 4];
}
else if (buf[3] == ' ')
{
/* Found single line response.
*/
break;
}
}
}
}
else if ([line hasPrefix: term] == YES)
{
/* Found end of a multiline response.
*/
DESTROY(term);
break;
}
}