backport bugfixes from trunk

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/base-1_13_0@24096 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-11-15 17:19:45 +00:00
parent 9421d3bdb2
commit be0ddb7458
12 changed files with 484 additions and 177 deletions

View file

@ -1,3 +1,18 @@
2006-11-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSCalendarDate.m:
* Source/NSPropertyList.m:
* Source/GSHTTPURLHandle.m:
* Source/NSString.m:
* Source/NSDecimalNumber.m:
* Source/Additions/GSXML.m:
* Source/Additions/GSMime.m:
* Source/NSConnection.m:
* Source/NSIndexSet.m:
* Tools/AGSHtml.m:
* Tools/autogsdoc.m:
Backport bugfixes from trunk
2006-08-28 Adam Fedor <fedor@gnu.org>
* Version 1.13.0

View file

@ -2312,12 +2312,13 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info);
}
dst = decodeWord(dst, src, tmp, encoding);
tmp++;
src = tmp;
if (*tmp != '=')
{
NSLog(@"Bad encoded word - encoded word terminator missing");
dst = beg; // Don't append to string.
break;
}
src = tmp;
if (dst > beg)
{
s = [NSStringClass allocWithZone: NSDefaultMallocZone()];
@ -3603,8 +3604,9 @@ static NSCharacterSet *tokenSet = nil;
NSIntMapValueCallBacks, 0);
/*
* These mappings were obtained from
* These mappings were obtained primarily from
* http://www.iana.org/assignments/character-sets
* with additions determined empirically.
*
* We should ideally have all the aliases for each
* encoding we support, but I just did the aliases
@ -3622,6 +3624,8 @@ static NSCharacterSet *tokenSet = nil;
(void*)NSASCIIStringEncoding);
NSMapInsert(charsets, (void*)@"iso_646.irv:1991",
(void*)NSASCIIStringEncoding);
NSMapInsert(charsets, (void*)@"iso_646.991-irv",
(void*)NSASCIIStringEncoding);
NSMapInsert(charsets, (void*)@"ascii",
(void*)NSASCIIStringEncoding);
NSMapInsert(charsets, (void*)@"iso646-us",
@ -3640,12 +3644,16 @@ static NSCharacterSet *tokenSet = nil;
// All the latin1 mappings from IANA
NSMapInsert(charsets, (void*)@"iso-8859-1:1987",
(void*)NSISOLatin1StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-1:1987",
(void*)NSISOLatin1StringEncoding);
NSMapInsert(charsets, (void*)@"iso-ir-100",
(void*)NSISOLatin1StringEncoding);
NSMapInsert(charsets, (void*)@"iso_8859-1",
(void*)NSISOLatin1StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-1",
(void*)NSISOLatin1StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-1",
(void*)NSISOLatin1StringEncoding);
NSMapInsert(charsets, (void*)@"latin1",
(void*)NSISOLatin1StringEncoding);
NSMapInsert(charsets, (void*)@"l1",
@ -3657,52 +3665,124 @@ static NSCharacterSet *tokenSet = nil;
NSMapInsert(charsets, (void*)@"csisolatin1",
(void*)NSISOLatin1StringEncoding);
// A couple of telecoms charsets
NSMapInsert(charsets, (void*)@"ia5",
(void*)NSASCIIStringEncoding);
NSMapInsert(charsets, (void*)@"gsm0338",
(void*)NSGSM0338StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-2",
(void*)NSISOLatin2StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-2",
(void*)NSISOLatin2StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-3",
(void*)NSISOLatin3StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-3",
(void*)NSISOLatin3StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-4",
(void*)NSISOLatin4StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-4",
(void*)NSISOLatin4StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-5",
(void*)NSISOCyrillicStringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-5",
(void*)NSISOCyrillicStringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-6",
(void*)NSISOArabicStringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-6",
(void*)NSISOArabicStringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-7",
(void*)NSISOGreekStringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-7",
(void*)NSISOGreekStringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-8",
(void*)NSISOHebrewStringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-8",
(void*)NSISOHebrewStringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-9",
(void*)NSISOLatin5StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-9",
(void*)NSISOLatin5StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-10",
(void*)NSISOLatin6StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-10",
(void*)NSISOLatin6StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-11",
(void*)NSISOThaiStringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-11",
(void*)NSISOThaiStringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-13",
(void*)NSISOLatin7StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-13",
(void*)NSISOLatin7StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-14",
(void*)NSISOLatin8StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-14",
(void*)NSISOLatin8StringEncoding);
NSMapInsert(charsets, (void*)@"iso-8859-15",
(void*)NSISOLatin9StringEncoding);
NSMapInsert(charsets, (void*)@"iso8859-15",
(void*)NSISOLatin9StringEncoding);
NSMapInsert(charsets, (void*)@"microsoft-symbol",
(void*)NSSymbolStringEncoding);
NSMapInsert(charsets, (void*)@"windows-symbol",
(void*)NSSymbolStringEncoding);
NSMapInsert(charsets, (void*)@"microsoft-cp1250",
(void*)NSWindowsCP1250StringEncoding);
NSMapInsert(charsets, (void*)@"windows-1250",
(void*)NSWindowsCP1250StringEncoding);
NSMapInsert(charsets, (void*)@"microsoft-cp1251",
(void*)NSWindowsCP1251StringEncoding);
NSMapInsert(charsets, (void*)@"windows-1251",
(void*)NSWindowsCP1251StringEncoding);
NSMapInsert(charsets, (void*)@"microsoft-cp1252",
(void*)NSWindowsCP1252StringEncoding);
NSMapInsert(charsets, (void*)@"windows-1252",
(void*)NSWindowsCP1252StringEncoding);
NSMapInsert(charsets, (void*)@"microsoft-cp1253",
(void*)NSWindowsCP1253StringEncoding);
NSMapInsert(charsets, (void*)@"windows-1253",
(void*)NSWindowsCP1253StringEncoding);
NSMapInsert(charsets, (void*)@"microsoft-cp1254",
(void*)NSWindowsCP1254StringEncoding);
NSMapInsert(charsets, (void*)@"windows-1254",
(void*)NSWindowsCP1254StringEncoding);
NSMapInsert(charsets, (void*)@"iso-10646-ucs-2",
(void*)NSUnicodeStringEncoding);
NSMapInsert(charsets, (void*)@"iso10646-ucs-2",
(void*)NSUnicodeStringEncoding);
NSMapInsert(charsets, (void*)@"utf-16",
(void*)NSUnicodeStringEncoding);
NSMapInsert(charsets, (void*)@"utf16",
(void*)NSUnicodeStringEncoding);
NSMapInsert(charsets, (void*)@"iso-10646-1",
(void*)NSUnicodeStringEncoding);
NSMapInsert(charsets, (void*)@"iso10646-1",
(void*)NSUnicodeStringEncoding);
NSMapInsert(charsets, (void*)@"big5",
(void*)NSBIG5StringEncoding);
NSMapInsert(charsets, (void*)@"jisx0201.1976",
(void*)NSShiftJISStringEncoding);
NSMapInsert(charsets, (void*)@"shift_JIS",
(void*)NSShiftJISStringEncoding);
NSMapInsert(charsets, (void*)@"utf-7",
(void*)NSUTF7StringEncoding);
NSMapInsert(charsets, (void*)@"utf7",
(void*)NSUTF7StringEncoding);
NSMapInsert(charsets, (void*)@"utf-8",
(void*)NSUTF8StringEncoding);
NSMapInsert(charsets, (void*)@"utf8",
(void*)NSUTF8StringEncoding);
NSMapInsert(charsets, (void*)@"apple-roman",
(void*)NSMacOSRomanStringEncoding);
NSMapInsert(charsets, (void*)@"koi8-r",
(void*)NSKOI8RStringEncoding);
NSMapInsert(charsets, (void*)@"gb2312.1980",
(void*)NSGB2312StringEncoding);
NSMapInsert(charsets, (void*)@"ksc5601.1987",
(void*)NSKoreanEUCStringEncoding);
NSMapInsert(charsets, (void*)@"ksc5601.1997",
(void*)NSKoreanEUCStringEncoding);
}
if (encodings == 0)
{
@ -3740,6 +3820,8 @@ static NSCharacterSet *tokenSet = nil;
(void*)@"iso-8859-9");
NSMapInsert(encodings, (void*)NSISOLatin6StringEncoding,
(void*)@"iso-8859-10");
NSMapInsert(encodings, (void*)NSISOThaiStringEncoding,
(void*)@"iso-8859-11");
NSMapInsert(encodings, (void*)NSISOLatin7StringEncoding,
(void*)@"iso-8859-13");
NSMapInsert(encodings, (void*)NSISOLatin8StringEncoding,
@ -3766,6 +3848,16 @@ static NSCharacterSet *tokenSet = nil;
(void*)@"utf-7");
NSMapInsert(encodings, (void*)NSUTF8StringEncoding,
(void*)@"utf-8");
NSMapInsert(encodings, (void*)NSGSM0338StringEncoding,
(void*)@"gsm0338");
NSMapInsert(encodings, (void*)NSMacOSRomanStringEncoding,
(void*)@"apple-roman");
NSMapInsert(encodings, (void*)NSKOI8RStringEncoding,
(void*)@"koi8-r");
NSMapInsert(encodings, (void*)NSGB2312StringEncoding,
(void*)@"gb2312.1980");
NSMapInsert(encodings, (void*)NSKoreanEUCStringEncoding,
(void*)@"ksc5601.1987");
}
}
}

View file

@ -122,14 +122,12 @@ UTF8Str(const unsigned char *bytes)
inline static NSString*
UTF8StrLen(const unsigned char *bytes, unsigned length)
{
unsigned char *buf = NSZoneMalloc(NSDefaultMallocZone(), length+1);
NSString *str;
memcpy(buf, bytes, length);
buf[length] = '\0';
str = UTF8Str(buf);
NSZoneFree(NSDefaultMallocZone(), buf);
return str;
str = [[NSString_class alloc] initWithBytes: bytes
length: length
encoding: NSUTF8StringEncoding];
return AUTORELEASE(str);
}
static BOOL cacheDone = NO;
@ -2407,12 +2405,17 @@ static NSString *endMarker = @"At end of incremental parse";
*/
#define HANDLER ((GSSAXHandler*)(((xmlParserCtxtPtr)ctx)->_private))
#ifdef GNUSTEP
static NSString *applePList
= @"file://localhost/System/Library/DTDs/PropertyList.dtd";
#endif
static xmlParserInputPtr
loadEntityFunction(void *ctx,
const unsigned char *eid, const unsigned char *url)
{
extern xmlParserInputPtr xmlNewInputFromFile();
NSString *file;
NSString *file = nil;
xmlParserInputPtr ret = 0;
NSString *entityId;
NSString *location;
@ -2422,10 +2425,10 @@ loadEntityFunction(void *ctx,
unsigned index;
NSCAssert(ctx, @"No Context");
if (eid == 0 || url == 0)
if (url == 0)
return 0;
entityId = UTF8Str(eid);
entityId = (eid != 0) ? (id)UTF8Str(eid) : nil;
location = UTF8Str(url);
components = [location pathComponents];
local = [NSMutableString string];
@ -2450,13 +2453,31 @@ loadEntityFunction(void *ctx,
options: NSLiteralSearch
range: NSMakeRange(0, [local length])];
/*
* Now ask the SAXHandler callback for the name of a local file
*/
file = [HANDLER loadEntity: entityId at: location];
#ifdef GNUSTEP
if ([location isEqual: applePList] == YES)
{
file = [location substringFromIndex: 6];
if ([[NSFileManager defaultManager] fileExistsAtPath: file] == NO)
{
location = [NSBundle pathForLibraryResource: @"plist-0_9"
ofType: @"dtd"
inDirectory: @"DTDs"];
entityId = @"-//GNUstep//DTD plist 0.9//EN";
file = nil;
}
}
#endif
if (file == nil)
{
file = [GSXMLParser loadEntity: entityId at: location];
/*
* Now ask the SAXHandler callback for the name of a local file
*/
file = [HANDLER loadEntity: entityId at: location];
if (file == nil)
{
file = [GSXMLParser loadEntity: entityId at: location];
}
}
if (file == nil)
@ -2521,10 +2542,10 @@ loadEntityFunction(void *ctx,
ofType: @"dtd"
inDirectory: @"DTDs"];
#else
found = [[NSBundle bundleForClass:NSClassFromString(@"GSXMLNode")]
pathForResource:name
ofType:@"dtd"
inDirectory:@"DTDs"];
found = [[NSBundle bundleForClass: NSClassFromString(@"GSXMLNode")]
pathForResource: name
ofType: @"dtd"
inDirectory: @"DTDs"];
#endif
if (found == nil)
{
@ -2550,6 +2571,26 @@ loadEntityFunction(void *ctx,
ofType: @""
inDirectory: @"DTDs"];
}
if (file == nil)
{
NSURL *aURL;
aURL = [NSURL URLWithString: location];
if ([aURL isFileURL] == YES)
{
file = [aURL path];
}
else
{
NSData *data = [aURL resourceDataUsingCache: NO];
if ([data length] > 0)
{
file = [@"/tmp" stringByAppendingPathComponent: local];
[data writeToFile: local atomically: NO];
}
}
}
}
}
@ -3277,10 +3318,9 @@ fatalErrorFunction(void *ctx, const unsigned char *msg, ...)
xmlSAXVersion(LIB, 2); // Set SAX2
LIB->startElementNs = (void*) startElementNsFunction;
LIB->endElementNs = (void*) endElementNsFunction;
#else
#endif
LIB->startElement = (void*) startElementFunction;
LIB->endElement = (void*) endElementFunction;
#endif
LIB->internalSubset = (void*) internalSubsetFunction;
LIB->externalSubset = (void*) externalSubsetFunction;
LIB->isStandalone = (void*) isStandaloneFunction;
@ -3399,10 +3439,9 @@ fatalErrorFunction(void *ctx, const unsigned char *msg, ...)
xmlSAXVersion(LIB, 2); // Set SAX2
SETCB(startElementNs, startElement:prefix:href:attributes:);
SETCB(endElementNs, endElement:prefix:href:);
#else
#endif
SETCB(startElement, startElement:attributes:);
SETCB(endElement, endElement:);
#endif
SETCB(internalSubset, internalSubset:externalID:systemID:);
SETCB(externalSubset, externalSubset:externalID:systemID:);
SETCB(isStandalone, isStandalone);
@ -4100,7 +4139,7 @@ static BOOL warned = NO; if (warned == NO) { warned = YES; NSLog(@"WARNING, use
unichar c = from[i];
if ((c >= 0x20 && c <= 0xd7ff)
|| c == 0x9 || c == 0xd || c == 0xd
|| c == 0x9 || c == 0xd || c == 0xa
|| (c >= 0xe000 && c <= 0xfffd))
{
switch (c)
@ -4158,7 +4197,7 @@ static BOOL warned = NO; if (warned == NO) { warned = YES; NSLog(@"WARNING, use
unichar c = from[i];
if ((c >= 0x20 && c <= 0xd7ff)
|| c == 0x9 || c == 0xd || c == 0xd
|| c == 0x9 || c == 0xd || c == 0xa
|| (c >= 0xe000 && c <= 0xfffd))
{
switch (c)

View file

@ -25,26 +25,27 @@
#include "config.h"
#include "Foundation/NSArray.h"
#include "Foundation/NSString.h"
#include "Foundation/NSException.h"
#include "Foundation/NSValue.h"
#include "Foundation/NSByteOrder.h"
#include "Foundation/NSData.h"
#include "Foundation/NSDebug.h"
#include "Foundation/NSException.h"
#include "Foundation/NSFileHandle.h"
#include "Foundation/NSHost.h"
#include "Foundation/NSLock.h"
#include "Foundation/NSMapTable.h"
#include "Foundation/NSNotification.h"
#include "Foundation/NSPathUtilities.h"
#include "Foundation/NSProcessInfo.h"
#include "Foundation/NSRunLoop.h"
#include "Foundation/NSString.h"
#include "Foundation/NSURL.h"
#include "Foundation/NSURLHandle.h"
#include "Foundation/NSNotification.h"
#include "Foundation/NSRunLoop.h"
#include "Foundation/NSByteOrder.h"
#include "Foundation/NSLock.h"
#include "Foundation/NSFileHandle.h"
#include "Foundation/NSDebug.h"
#include "Foundation/NSHost.h"
#include "Foundation/NSProcessInfo.h"
#include "Foundation/NSPathUtilities.h"
#include "Foundation/NSMapTable.h"
#include "Foundation/NSValue.h"
#include "GNUstepBase/GSMime.h"
#include "GNUstepBase/GSLock.h"
#include "NSCallBacks.h"
#include "GSURLPrivate.h"
#include "GSPrivate.h"
#include <string.h>
#ifdef HAVE_UNISTD_H
@ -55,6 +56,9 @@
#ifdef HAVE_SYS_FCNTL_H
#include <sys/fcntl.h> // For O_WRONLY, etc
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h> // For MSG_PEEK, etc
#endif
/*
* Implement map keys for strings with case insensitive comparisons,
@ -81,7 +85,7 @@ typedef void (*NSMT_retain_func_t)(NSMapTable *, const void *);
typedef void (*NSMT_release_func_t)(NSMapTable *, void *);
typedef NSString *(*NSMT_describe_func_t)(NSMapTable *, const void *);
const NSMapTableKeyCallBacks writeKeyCallBacks =
static const NSMapTableKeyCallBacks writeKeyCallBacks =
{
(NSMT_hash_func_t) _non_retained_id_hash,
(NSMT_is_equal_func_t) _non_retained_id_is_equal,
@ -310,7 +314,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
/*
* We might be in an idle state with an outstandng read on the
* We might be in an idle state with an outstanding read on the
* socket, keeping the connection alive, but waiting for the
* remote end to drop it.
*/
@ -512,6 +516,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
NSDictionary *dict = [not userInfo];
NSData *d;
NSRange r;
unsigned readCount;
BOOL complete = NO;
RETAIN(self);
@ -519,6 +524,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
if (debug) NSLog(@"%@ %s", NSStringFromSelector(_cmd), keepalive?"K":"");
d = [dict objectForKey: NSFileHandleNotificationDataItem];
if (debug == YES) debugRead(self, d);
readCount = [d length];
if (connectionState == idle)
{
@ -613,7 +619,6 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
{
NSURLProtectionSpace *space;
NSString *ac;
NSURLCredential *cred;
GSHTTPAuthentication *authentication;
NSString *method;
NSString *a;
@ -621,25 +626,33 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
ac = [ah value];
space = [GSHTTPAuthentication
protectionSpaceForAuthentication: ac requestURL: url];
if (space != nil)
{
NSURLCredential *cred;
/*
* Create credential from user and password
* stored in the URL.
*/
cred = [[NSURLCredential alloc]
initWithUser: [url user]
password: [url password]
persistence: NSURLCredentialPersistenceForSession];
/*
* Create credential from user and password
* stored in the URL.
*/
cred = [[NSURLCredential alloc]
initWithUser: [url user]
password: [url password]
persistence: NSURLCredentialPersistenceForSession];
/*
* Get the digest object and ask it for a header
* to use for authorisation.
*/
authentication = [GSHTTPAuthentication
authenticationWithCredential: cred
inProtectionSpace: space];
/*
* Get the digest object and ask it for a header
* to use for authorisation.
*/
authentication = [GSHTTPAuthentication
authenticationWithCredential: cred
inProtectionSpace: space];
RELEASE(cred);
RELEASE(cred);
}
else
{
authentication = nil;
}
method = [request objectForKey: GSHTTPPropertyMethodKey];
if (method == nil)
@ -655,8 +668,8 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
}
a = [authentication authorizationForAuthentication: ac
method: method
path: [url path]];
method: method
path: [url path]];
if (a != nil)
{
[self writeProperty: a forKey: @"Authorization"];
@ -705,8 +718,23 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
loadComplete: NO];
}
}
if (sock != nil
&& (connectionState == reading || connectionState == idle))
if (complete == NO && readCount == 0)
{
/* The read failed ... dropped, but parsing is not complete.
* The request was sent, so we can't know whether it was
* lost in the network or the remote end received it and
* the response was lost.
*/
if (debug == YES)
{
NSLog(@"HTTP response not received - %@", parser);
}
[self endLoadInBackground];
[self backgroundLoadDidFailWithReason: @"Response parse failed"];
}
if (sock != nil && connectionState == reading)
{
if ([sock readInProgress] == NO)
{
@ -995,6 +1023,8 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
[sock closeFile];
DESTROY(sock);
connectionState = idle;
if (debug)
NSLog(@"%@ restart on new connection", NSStringFromSelector(_cmd));
[self _tryLoadInBackground: u];
return;
}
@ -1134,6 +1164,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
[dat setLength: 0];
RELEASE(document);
RELEASE(parser);
[pageInfo removeAllObjects];
parser = [GSMimeParser new];
document = RETAIN([parser mimeDocument]);
@ -1172,6 +1203,51 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
port = @"80";
}
if (sock != nil)
{
/* An existing socket with keepalive may have been closed by the other
* end. The portable way to detect it is to run the runloop once to
* allow us to be sent a notification about end-of-file.
* On unix systems (google told me it is not reliable on windows) we can
* simply peek on the file descriptor for a much more efficient check.
*/
#if defined(__MINGW__)
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSRunLoop *loop = [NSRunLoop currentRunLoop];
NSFileHandle *test = RETAIN(sock);
[nc addObserver: self
selector: @selector(bgdTunnelRead:)
name: NSFileHandleReadCompletionNotification
object: test];
if ([test readInProgress] == NO)
{
[test readInBackgroundAndNotify];
}
[loop acceptInputForMode: NSDefaultRunLoopMode
beforeDate: nil];
[nc removeObserver: self
name: NSFileHandleReadCompletionNotification
object: test];
RELEASE(test);
#else
int fd = [sock fileDescriptor];
if (fd >= 0)
{
extern int errno;
int result;
unsigned char c;
result = recv(fd, &c, 1, MSG_PEEK | MSG_DONTWAIT);
if (result == 0 || (result < 0 && errno != EAGAIN && errno != EINTR))
{
DESTROY(sock);
}
}
#endif
}
if (sock == nil)
{
keepalive = NO; // New connection
@ -1260,7 +1336,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
* Tell superclass that the load failed - let it do housekeeping.
*/
[self backgroundLoadDidFailWithReason:
[NSString stringWithFormat: @"Unable to connect to %@:%@ ... %s",
[NSString stringWithFormat: @"Unable to connect to %@:%@ ... %@",
host, port, GSLastErrorStr(errno)]];
return;
}
@ -1285,7 +1361,11 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
name: NSFileHandleReadCompletionNotification
object: sock];
keepalive = YES; // Reusing a connection.
/* Reusing a connection. Set flag to say that it has been kept
* alive and we don't know if the other end has dropped it
* until we write to it and read some response.
*/
keepalive = YES;
method = [request objectForKey: GSHTTPPropertyMethodKey];
if (method == nil)
{

View file

@ -30,20 +30,22 @@
#include "config.h"
#include <math.h>
#include "Foundation/NSObjCRuntime.h"
#include "Foundation/NSArray.h"
#include "Foundation/NSAutoreleasePool.h"
#include "Foundation/NSCalendarDate.h"
#include "Foundation/NSCoder.h"
#include "Foundation/NSData.h"
#include "Foundation/NSDate.h"
#include "Foundation/NSCalendarDate.h"
#include "Foundation/NSTimeZone.h"
#include "Foundation/NSArray.h"
#include "Foundation/NSString.h"
#include "Foundation/NSCoder.h"
#include "Foundation/NSException.h"
#include "Foundation/NSUserDefaults.h"
#include "Foundation/NSAutoreleasePool.h"
#include "Foundation/NSDebug.h"
#include "Foundation/NSException.h"
#include "Foundation/NSObjCRuntime.h"
#include "Foundation/NSString.h"
#include "Foundation/NSTimeZone.h"
#include "Foundation/NSUserDefaults.h"
#include "GNUstepBase/GSObjCRuntime.h"
#include "GSPrivate.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@ -51,7 +53,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "GSPrivate.h"
@class GSTimeZone;
@interface GSTimeZone : NSObject // Help the compiler
@ -147,7 +148,7 @@ abbrev(NSTimeZone *tz, NSDate *d)
}
static inline unsigned int
lastDayOfGregorianMonth(int month, int year)
lastDayOfGregorianMonth(unsigned month, unsigned year)
{
switch (month)
{
@ -165,12 +166,20 @@ lastDayOfGregorianMonth(int month, int year)
}
}
static inline int
absoluteGregorianDay(int day, int month, int year)
static inline unsigned
absoluteGregorianDay(unsigned day, unsigned month, unsigned year)
{
while (--month > 0)
day = day + lastDayOfGregorianMonth(month, year);
year--;
if (month > 1)
{
while (--month > 0)
{
day = day + lastDayOfGregorianMonth(month, year);
}
}
if (year > 0)
{
year--;
}
return
(day // days this year
+ 365 * year // days in previous years ignoring leap days
@ -216,7 +225,7 @@ gregorianDateFromAbsolute(int abs, int *day, int *month, int *year)
* since the reference date.
*/
static NSTimeInterval
GSTime(int day, int month, int year, int hour, int minute, int second, int mil)
GSTime(unsigned day, unsigned month, unsigned year, unsigned hour, unsigned minute, unsigned second, unsigned mil)
{
NSTimeInterval a;
@ -478,10 +487,11 @@ GSTimeNow(void)
* read up to the specified number of characters, terminating at a non-digit
* except for leading whitespace characters.
*/
static inline int getDigits(const char *from, char *to, int limit)
static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
{
int i = 0;
int j = 0;
BOOL foundDigit = NO;
while (i < limit)
@ -505,6 +515,10 @@ static inline int getDigits(const char *from, char *to, int limit)
i++;
}
to[j] = '\0';
if (j == 0)
{
*error = YES; // No digits read
}
return i;
}
@ -520,6 +534,8 @@ static inline int getDigits(const char *from, char *to, int limit)
* Initializes an NSCalendarDate using the specified description and format
* string interpreted in the given locale.<br />
* If description does not match fmt exactly, this method returns nil.<br />
* Excess characters in the description (after the format is matched)
* are ignored.<br />
* Format specifiers are -
* <list>
* <item>
@ -606,6 +622,16 @@ static inline int getDigits(const char *from, char *to, int limit)
* If no second is specified in the format, 0 is assumed.<br />
* If no millisecond is specified in the format, 0 is assumed.<br />
* If no timezone is specified in the format, the local timezone is assumed.
* <p>NB. Where the format calls for a numeric value and the string contains
* fewer digits than expected, the value will be accepted and left padded
* with zeros to the expected size.<br />
* For instance, the '%z' format implies four digits (two for the hour
* offset and two for the digit offset) and if the string contains '01'
* it will be treated as '0001' ie. a timezone offset of 1 minute.<br />
* Similarly, the '%F' format implies three digits, so a value of '1'
* would be treated as '001' or 1 millisecond, not a tenth of a second
* (as you might assume as '%F' is usually used after a decimal separator).
* </p>
*/
- (id) initWithString: (NSString*)description
calendarFormat: (NSString*)fmt
@ -782,7 +808,7 @@ static inline int getDigits(const char *from, char *to, int limit)
// last digit to work.
//
while (formatIdx < formatLen)
while (error == NO && formatIdx < formatLen)
{
if (format[formatIdx] != '%')
{
@ -832,6 +858,14 @@ static inline int getDigits(const char *from, char *to, int limit)
}
sourceIdx++;
}
else
{
error = YES;
NSDebugMLog(
@"Expected literal '%%' but got end of string parsing"
@"'%@' using '%@'", source[sourceIdx],
description, fmt);
}
break;
case 'a':
@ -1006,38 +1040,38 @@ static inline int getDigits(const char *from, char *to, int limit)
case 'd': // fall through
case 'e':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
day = atoi(tmpStr);
had |= hadD;
break;
case 'F':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3, &error);
milliseconds = atoi(tmpStr);
break;
case 'I': // fall through
twelveHrClock = YES;
case 'H':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
hour = atoi(tmpStr);
had |= hadh;
break;
case 'j':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3, &error);
day = atoi(tmpStr);
had |= hadD;
break;
case 'm':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
month = atoi(tmpStr);
had |= hadM;
break;
case 'M':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
min = atoi(tmpStr);
had |= hadm;
break;
@ -1056,7 +1090,7 @@ static inline int getDigits(const char *from, char *to, int limit)
NSString *currAMPM;
NSArray *amPMNames;
currAMPM = [NSString stringWithCString: tmpStr];
currAMPM = [NSString stringWithUTF8String: tmpStr];
amPMNames = [locale objectForKey: NSAMPMDesignation];
/*
@ -1072,13 +1106,13 @@ static inline int getDigits(const char *from, char *to, int limit)
break;
case 'S':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
sec = atoi(tmpStr);
had |= hads;
break;
case 'w':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 1);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 1, &error);
dayOfWeek = atoi(tmpStr);
had |= hadw;
break;
@ -1086,7 +1120,7 @@ static inline int getDigits(const char *from, char *to, int limit)
case 'W': // Fall through
weekStartsMonday = 1;
case 'U':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 1);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 1, &error);
julianWeeks = atoi(tmpStr);
break;
@ -1097,7 +1131,7 @@ static inline int getDigits(const char *from, char *to, int limit)
// break;
case 'y':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
year = atoi(tmpStr);
if (year >= 70)
{
@ -1111,7 +1145,7 @@ static inline int getDigits(const char *from, char *to, int limit)
break;
case 'Y':
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 4);
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 4, &error);
year = atoi(tmpStr);
had |= hadY;
break;
@ -1131,7 +1165,7 @@ static inline int getDigits(const char *from, char *to, int limit)
sign = -1;
sourceIdx++;
}
found = getDigits(&source[sourceIdx], tmpStr, 4);
found = getDigits(&source[sourceIdx], tmpStr, 4, &error);
if (found > 0)
{
sourceIdx += found;
@ -1162,7 +1196,7 @@ static inline int getDigits(const char *from, char *to, int limit)
tmpStr[tmpIdx - sourceIdx] = '\0';
sourceIdx += tmpIdx - sourceIdx;
{
NSString *z = [NSString stringWithCString: tmpStr];
NSString *z = [NSString stringWithUTF8String: tmpStr];
/* Abbreviations aren't one-to-one with time zone names
so just look for the zone named after the abbreviation,
@ -1171,15 +1205,21 @@ static inline int getDigits(const char *from, char *to, int limit)
if (tz == nil)
{
tz = [NSTimeZone timeZoneWithAbbreviation: z];
if (tz == nil)
{
error = YES;
NSDebugMLog(@"Time zone '%@' not found", z);
}
}
}
break;
default:
[NSException raise: NSInvalidArgumentException
format: @"Invalid NSCalendar date, "
@"specifier %c not recognized in format %@",
format[formatIdx], fmt];
error = YES;
NSLog(@"Invalid NSCalendar date, "
@"specifier %c not recognized in format %@",
format[formatIdx], fmt);
break;
}
}
formatIdx++;
@ -2369,13 +2409,15 @@ static void Grow(DescriptionInfo *info, unsigned size)
NSTimeInterval newOffset;
int i, year, month, day, hour, minute, second, mil;
oldOffset = offset(_time_zone, self);
/*
* Break into components in GMT time zone.
/* Apply timezone offset to _seconds_since_ref from GMT to local time,
* then break into components in local time zone.
*/
GSBreakTime(_seconds_since_ref, &year, &month, &day, &hour, &minute,
&second, &mil);
oldOffset = offset(_time_zone, self);
s = _seconds_since_ref + oldOffset;
GSBreakTime(s, &year, &month, &day, &hour, &minute, &second, &mil);
/* Apply required offsets to get new local time.
*/
while (years != 0 || months != 0 || days != 0
|| hours != 0 || minutes != 0 || seconds != 0)
{
@ -2464,9 +2506,11 @@ static void Grow(DescriptionInfo *info, unsigned size)
}
/*
* Reassemble in GMT time zone.
* Reassemble and apply original timezone offset to get
* _seconds_since_ref back to GMT.
*/
s = GSTime(day, month, year, hour, minute, second, mil);
s -= oldOffset;
c = [NSCalendarDate alloc];
c->_calendar_format = cformat;
c->_time_zone = RETAIN([self timeZone]);

View file

@ -540,7 +540,7 @@ static NSLock *cached_proxies_gate = nil;
if (connection_table_gate == nil)
{
connection_table_gate = [GSLazyLock new];
connection_table_gate = [GSLazyRecursiveLock new];
}
if (cached_proxies_gate == nil)
{
@ -701,6 +701,7 @@ static NSLock *cached_proxies_gate = nil;
{
if (debug_connection)
NSLog(@"deallocating %@", self);
[self gcFinalize];
[super dealloc];
}
@ -1279,19 +1280,24 @@ static NSLock *cached_proxies_gate = nil;
- (void) release
{
/*
* If this would cause the connection to be deallocated then we
* must perform all necessary work (done in [-gcFinalize]).
* We bracket the code with a retain and release so that any
* retain/release pairs in the code won't cause recursion.
/* We lock the connection table while checking, to prevent
* another thread from grabbing this connection while we are
* checking it.
* If we are going to deallocate the object, we first remove
* it from the table so that no other thread will find it
* and try to use it while it is being deallocated.
*/
if ([self retainCount] == 1)
M_LOCK(connection_table_gate);
if (NSDecrementExtraRefCountWasZero(self))
{
[super retain];
[self gcFinalize];
[super release];
NSHashRemove(connection_table, self);
M_UNLOCK(connection_table_gate);
[self dealloc];
}
else
{
M_UNLOCK(connection_table_gate);
}
[super release];
}
/**

View file

@ -19,15 +19,19 @@
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
<title>NSDecimalNumber class reference</title>
$Date$ $Revision$
*/
#include "Foundation/NSException.h"
#include "Foundation/NSCoder.h"
#include "Foundation/NSDecimal.h"
#include "Foundation/NSDecimalNumber.h"
#include "Foundation/NSException.h"
#include "Foundation/NSPortCoder.h"
#include "GSPrivate.h"
// shared default behavior for NSDecimalNumber class
@ -260,7 +264,7 @@ static NSDecimalNumber *one;
- (id) initWithString: (NSString*)numberValue
{
return [self initWithString: numberValue
locale: GSUserDefaultsDictionaryRepresentation()];
locale: GSUserDefaultsDictionaryRepresentation()];
}
- (id) initWithString: (NSString*)numberValue
@ -662,6 +666,32 @@ static NSDecimalNumber *one;
return [[isa defaultBehavior] scale];
}
- (Class) classForCoder
{
return [NSDecimalNumber class];
}
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
{
if ([aCoder isByref] == NO)
return self;
return [super replacementObjectForPortCoder: aCoder];
}
- (void) encodeWithCoder: (NSCoder*)coder
{
NSString *s = [self descriptionWithLocale: nil];
[coder encodeObject: s];
}
- (id) initWithCoder: (NSCoder*)coder
{
NSString *s = [coder decodeObject];
return [self initWithString: s locale: nil];
}
@end
@implementation NSNumber (NSDecimalNumber)

View file

@ -18,7 +18,8 @@
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
@ -672,9 +673,16 @@ static unsigned posForIndex(GSIArray array, unsigned index)
{
break;
}
r.length += (NSMaxRange(aRange) - NSMaxRange(r));
GSIArrayRemoveItemAtIndex(_array, pos--);
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos);
if (NSMaxRange(r) >= NSMaxRange(aRange))
{
GSIArrayRemoveItemAtIndex(_array, pos--);
}
else
{
r.length += (NSMaxRange(aRange) - NSMaxRange(r));
GSIArrayRemoveItemAtIndex(_array, pos--);
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos);
}
}
/*

View file

@ -1635,7 +1635,8 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
else if (x == NSPropertyListGNUstepFormat)
{
[dest appendBytes: "<*I" length: 3];
PString([obj stringValue], dest);
[dest appendData:
[[obj stringValue] dataUsingEncoding: NSASCIIStringEncoding]];
[dest appendBytes: ">" length: 1];
}
else
@ -1654,7 +1655,8 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
else if (x == NSPropertyListGNUstepFormat)
{
[dest appendBytes: "<*R" length: 3];
PString([obj stringValue], dest);
[dest appendData:
[[obj stringValue] dataUsingEncoding: NSASCIIStringEncoding]];
[dest appendBytes: ">" length: 1];
}
else

View file

@ -1328,8 +1328,20 @@ handle_printf_atsign (FILE *stream,
* Constructs a new ASCII string which is a representation of the receiver
* in which characters are escaped where necessary in order to produce a
* legal URL.<br />
* The original string is converted to bytes using the specified encoding
* and then those bytes are escaped unless they correspond to 'legal'
* ASCII characters. The byte values escaped are any below 32 and any
* above 126 as well as 32 (space), 34 ("), 35 (#), 37 (%), 60 (&lt;),
* 62 (&gt;), 91 ([), 92 (\), 93 (]), 94 (^), 96 (~), 123 ({), 124 (|),
* and 125 (}).<br />
* Returns nil if the receiver cannot be represented using the specified
* encoding.
* encoding.<br />
* NB. This behavior is MacOS-X (4.2) compatible, and it should be noted
* that it does <em>not</em> produce a string suitable for use as a field
* value in a url-encoded form as it does <strong>not</strong> escape the
* '+', '=' and '&amp;' characters used in such forms. If you need to
* add a string as a form field value (or name) you must add percent
* escapes for those characters yourself.
*/
- (NSString*) stringByAddingPercentEscapesUsingEncoding: (NSStringEncoding)e
{
@ -1351,46 +1363,19 @@ handle_printf_atsign (FILE *stream,
unsigned int hi;
unsigned int lo;
switch (c)
if (c <= 32 || c > 126 || c == 34 || c == 35 || c == 37
|| c == 60 || c == 62 || c == 91 || c == 92 || c == 93
|| c == 94 || c == 96 || c == 123 || c == 124 || c == 125)
{
case ',':
case ';':
case '"':
case '\'':
case '&':
case '=':
case '(':
case ')':
case '<':
case '>':
case '?':
case '#':
case '{':
case '}':
case '%':
case ' ':
case '+':
dst[dpos++] = '%';
hi = (c & 0xf0) >> 4;
dst[dpos++] = (hi > 9) ? 'A' + hi - 10 : '0' + hi;
lo = (c & 0x0f);
dst[dpos++] = (lo > 9) ? 'A' + lo - 10 : '0' + lo;
break;
default:
if (c < ' ' || c > 127)
{
dst[dpos++] = '%';
hi = (c & 0xf0) >> 4;
dst[dpos++] = (hi > 9) ? 'A' + hi - 10 : '0' + hi;
lo = (c & 0x0f);
dst[dpos++] = (lo > 9) ? 'A' + lo - 10 : '0' + lo;
}
else
{
dst[dpos++] = c;
}
break;
dst[dpos++] = '%';
hi = (c & 0xf0) >> 4;
dst[dpos++] = (hi > 9) ? 'A' + hi - 10 : '0' + hi;
lo = (c & 0x0f);
dst[dpos++] = (lo > 9) ? 'A' + lo - 10 : '0' + lo;
}
else
{
dst[dpos++] = c;
}
}
[d setLength: dpos];

View file

@ -2493,8 +2493,11 @@ static NSString *mainFont = nil;
{
[buf appendString: @", "];
[buf appendString: project];
[buf appendString: @" "];
[buf appendString: gvadd];
if ([gvadd isEqualToString: @"0.0.0"] == NO)
{
[buf appendString: @" "];
[buf appendString: gvadd];
}
if ([gvdep length] > 0)
{
[buf appendString: @" deprecated at "];
@ -2502,7 +2505,7 @@ static NSString *mainFont = nil;
}
if ([gvrem length] > 0)
{
[buf appendString: @" removed at "];
[buf appendString: @" deprecated for removal at "];
[buf appendString: gvrem];
}
}
@ -2515,8 +2518,11 @@ static NSString *mainFont = nil;
[buf appendString: @"<div class=\"availability\">\n"];
[buf appendString: @"<b>Availability:</b> "];
[buf appendString: project];
[buf appendString: @" "];
[buf appendString: gvadd];
if ([gvadd isEqualToString: @"0.0.0"] == NO)
{
[buf appendString: @" "];
[buf appendString: gvadd];
}
if ([gvdep length] > 0)
{
[buf appendString: @" deprecated at "];
@ -2525,7 +2531,7 @@ static NSString *mainFont = nil;
[buf appendString: @"<br />\n"];
if ([gvrem length] > 0)
{
[buf appendString: @" removed at "];
[buf appendString: @" deprecated for removal at "];
[buf appendString: gvrem];
}
[buf appendString:@"</div>\n"];

View file

@ -546,8 +546,8 @@
</p>
<example>
&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 1.0.1//EN"
"http://www.gnustep.org/gsdoc-1_0_1.xml"&gt;
&lt;!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 1.0.3//EN"
"http://www.gnustep.org/gsdoc-1_0_3.xml"&gt;
&lt;gsdoc base="index"&gt;
&lt;head&gt;
&lt;title&gt;My project reference&lt;/title&gt;
@ -1774,7 +1774,7 @@ main(int argc, char **argv, char **env)
// skeleton for table of contents files
[tocSkel setString: @"<?xml version=\"1.0\"?>\n"
@"<!DOCTYPE gsdoc PUBLIC \"-//GNUstep//DTD gsdoc 1.0.1//EN\" \"http://www.gnustep.org/gsdoc-1_0_1.xml\">\n"
@"<!DOCTYPE gsdoc PUBLIC \"-//GNUstep//DTD gsdoc 1.0.3//EN\" \"http://www.gnustep.org/gsdoc-1_0_3.xml\">\n"
@"<gsdoc base=\"[typeU]\" stylesheeturl=\"gsdoc_contents\">\n"
@" <head>\n"
@" <title>[typeU]</title>\n"
@ -1880,7 +1880,7 @@ main(int argc, char **argv, char **env)
@"named %@ in the documentation output directory.\n"
@"Then include this file in the arguments to autogsdoc.\n\n", prjFile);
[prjFileContents setString: @"<?xml version=\"1.0\"?>\n"
@"<!DOCTYPE gsdoc PUBLIC \"-//GNUstep//DTD gsdoc 1.0.1//EN\" \"http://www.gnustep.org/gsdoc-1_0_1.xml\">\n"
@"<!DOCTYPE gsdoc PUBLIC \"-//GNUstep//DTD gsdoc 1.0.3//EN\" \"http://www.gnustep.org/gsdoc-1_0_3.xml\">\n"
@"<gsdoc base=\"[prjName]\">\n"
@" <head>\n"
@" <title>The [prjName] Project</title>\n"