mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 08:26:27 +00:00
Patch to port GSXMLRPC to MacOSX
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20902 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3e4ebaab23
commit
8f2b0c8bd2
4 changed files with 155 additions and 4 deletions
|
@ -1,3 +1,7 @@
|
|||
2005-03-12 Sungjin Chun <chuns@embian.com>
|
||||
|
||||
* Source/Additions/GSXML.m: Port to MacOS-X
|
||||
|
||||
2005-03-11 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSPropertyList.m: Handle null object passed to OAppend()
|
||||
|
|
|
@ -450,7 +450,13 @@
|
|||
@interface GSXMLRPC : NSObject <NSURLHandleClient>
|
||||
{
|
||||
@private
|
||||
#ifdef GNUSTEP
|
||||
NSURLHandle *handle;
|
||||
#else
|
||||
NSString *connectionURL;
|
||||
NSURLConnection *connection;
|
||||
NSMutableData *response;
|
||||
#endif
|
||||
NSTimer *timer;
|
||||
id result;
|
||||
id delegate; // Not retained.
|
||||
|
@ -605,7 +611,7 @@
|
|||
*/
|
||||
- (void) timeout: (NSTimer*)t;
|
||||
|
||||
|
||||
#ifdef GNUSTEP
|
||||
/** Allows GSXMLRPC to act as a client of NSURLHandle. Internal use only. */
|
||||
- (void) URLHandle: (NSURLHandle*)sender
|
||||
resourceDataDidBecomeAvailable: (NSData*)newData;
|
||||
|
@ -618,6 +624,7 @@
|
|||
- (void) URLHandleResourceDidCancelLoading: (NSURLHandle*)sender;
|
||||
/** Allows GSXMLRPC to act as a client of NSURLHandle. Internal use only. */
|
||||
- (void) URLHandleResourceDidFinishLoading: (NSURLHandle*)sender;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -2532,9 +2532,16 @@ loadEntityFunction(const unsigned char *url, const unsigned char *eid,
|
|||
range: r];
|
||||
}
|
||||
|
||||
#ifdef GNUSTEP
|
||||
found = [NSBundle pathForLibraryResource: name
|
||||
ofType: @"dtd"
|
||||
inDirectory: @"DTDs"];
|
||||
#else
|
||||
found = [[NSBundle bundleForClass:NSClassFromString(@"GSXMLNode")]
|
||||
pathForResource:name
|
||||
ofType:@"dtd"
|
||||
inDirectory:@"DTDs"];
|
||||
#endif
|
||||
if (found == nil)
|
||||
{
|
||||
NSLog(@"unable to find GNUstep DTD - '%@' for '%s'", name, eid);
|
||||
|
@ -4832,9 +4839,20 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
{
|
||||
[self timeout: nil]; // Treat as immediate timeout.
|
||||
}
|
||||
#ifdef GNUSTEP
|
||||
[handle removeClient: self];
|
||||
#endif
|
||||
DESTROY(result);
|
||||
#ifdef GNUSTEP
|
||||
DESTROY(handle);
|
||||
#else
|
||||
if (connection)
|
||||
{
|
||||
[connection release];
|
||||
}
|
||||
[response release];
|
||||
[connectionURL release];
|
||||
#endif
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -4857,8 +4875,9 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
{
|
||||
NS_DURING
|
||||
{
|
||||
#ifdef GNUSTEP
|
||||
NSURL *u = [NSURL URLWithString: url];
|
||||
|
||||
|
||||
handle = RETAIN([u URLHandleUsingCache: NO]);
|
||||
if (cert != nil && pKey != nil && pwd != nil)
|
||||
{
|
||||
|
@ -4868,6 +4887,11 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
[handle writeProperty: pwd forKey: GSHTTPPropertyPasswordKey];
|
||||
}
|
||||
[handle addClient: self];
|
||||
#else
|
||||
connectionURL = [url copy];
|
||||
connection = nil;
|
||||
response = [[NSMutableData alloc] init];
|
||||
#endif
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
|
@ -4980,7 +5004,7 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
return method;
|
||||
}
|
||||
|
||||
- (NSDictionary*) parseResponse: (NSData*) response
|
||||
- (NSDictionary*) parseResponse: (NSData*)response
|
||||
params: (NSMutableArray*)params
|
||||
{
|
||||
GSXPathContext *ctx = nil;
|
||||
|
@ -5015,7 +5039,7 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
|
||||
NS_DURING
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if ([ns count] > 0)
|
||||
{
|
||||
|
@ -5076,10 +5100,12 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
|
||||
ASSIGN(result, @"unable to send");
|
||||
|
||||
#ifdef GNUSTEP
|
||||
if (handle == nil)
|
||||
{
|
||||
return NO; // Not initialised to send.
|
||||
}
|
||||
#endif
|
||||
if (timer != nil)
|
||||
{
|
||||
return NO; // Send already in progress.
|
||||
|
@ -5097,20 +5123,40 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
userInfo: nil
|
||||
repeats: NO];
|
||||
|
||||
#ifdef GNUSTEP
|
||||
[handle writeProperty: @"POST" forKey: GSHTTPPropertyMethodKey];
|
||||
[handle writeProperty: @"GSXMLRPC/1.0.0" forKey: @"User-Agent"];
|
||||
[handle writeProperty: @"text/xml" forKey: @"Content-Type"];
|
||||
[handle writeData: data];
|
||||
[handle loadInBackground];
|
||||
#else
|
||||
{
|
||||
NSMutableURLRequest *request;
|
||||
|
||||
request = [NSMutableURLRequest alloc];
|
||||
request = [tequest initWithURL: [NSURL URLWithString: connectionURL]];
|
||||
[request setCachePolicy: NSURLRequestReloadIgnoringCacheData];
|
||||
[request setHTTPMethod: @"POST"];
|
||||
[request setValue: @"GSXMLRPC/1.0.0" forHTTPHeaderField: @"User-Agent"];
|
||||
[request setValue: @"text/xml" forHTTPHeaderField: @"Content-Type"];
|
||||
[request setHTTPBody: data];
|
||||
|
||||
connection = [NSURLConnection alloc];
|
||||
connection = [connection initWithRequest: request delegate: self];
|
||||
[request release];
|
||||
}
|
||||
#endif
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) setDebug: (BOOL)flag
|
||||
{
|
||||
#ifdef GNUSTEP
|
||||
if ([handle respondsToSelector: _cmd] == YES)
|
||||
{
|
||||
[(id)handle setDebug: flag];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void) setDelegate: (id)aDelegate
|
||||
|
@ -5122,9 +5168,14 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
{
|
||||
[timer invalidate];
|
||||
timer = nil;
|
||||
#ifdef GNUSTEP
|
||||
[handle cancelLoadInBackground];
|
||||
#else
|
||||
[connection cancel];
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef GNUSTEP
|
||||
|
||||
- (void) URLHandle: (NSURLHandle*)sender
|
||||
resourceDataDidBecomeAvailable: (NSData*)newData
|
||||
|
@ -5204,6 +5255,91 @@ static void indentation(unsigned level, NSMutableString *str)
|
|||
}
|
||||
}
|
||||
|
||||
#else /* !GNUSTEP */
|
||||
|
||||
- (void) connection: (NSURLConnection*)connection
|
||||
didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge*)challenge
|
||||
{
|
||||
/* DO NOTHING */
|
||||
}
|
||||
|
||||
- (void) connection: (NSURLConnection*)connection
|
||||
didFailWithError: (NSError*)error
|
||||
{
|
||||
ASSIGN(result, [error localizedDescription]);
|
||||
[timer invalidate];
|
||||
timer = nil;
|
||||
if ([delegate respondsToSelector: @selector(completedXMLRPC:)])
|
||||
{
|
||||
[delegate completedXMLRPC: self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) connection: (NSURLConnection*)connection
|
||||
didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge*)challenge
|
||||
{
|
||||
}
|
||||
|
||||
- (void) connection: (NSURLConnection*)connection didReceiveData: (NSData*)data
|
||||
{
|
||||
[response appendData: data];
|
||||
}
|
||||
|
||||
- (void) connection: (NSURLConnection*)connection
|
||||
didReceiveResponse: (NSURLResponse*)response
|
||||
{
|
||||
/* DO NOTHING */
|
||||
}
|
||||
|
||||
- (NSCachedURLResponse*) connection: (NSURLConnection*)connection
|
||||
willCacheResponse: (NSCachedURLResponse*)cachedResponse
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSURLRequest*) connection: (NSURLConnection*)connection
|
||||
willSendRequest: (NSURLRequest*)request
|
||||
redirectResponse: (NSURLResponse*)redirectResponse
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(void) connectionDidFinishLoading: (NSURLConnection*)connection
|
||||
{
|
||||
NSMutableArray *params = [NSMutableArray array];
|
||||
id fault = nil;
|
||||
int code;
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
fault = [self parseResponse: response params: params];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
fault = [localException reason];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
if (fault == nil)
|
||||
{
|
||||
ASSIGNCOPY(result, params);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSIGNCOPY(result, fault);
|
||||
}
|
||||
|
||||
[timer invalidate];
|
||||
timer = nil;
|
||||
|
||||
if ([delegate respondsToSelector: @selector(completedXMLRPC:)])
|
||||
{
|
||||
[delegate completedXMLRPC: self];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSXMLRPC (Delegate)
|
||||
|
|
|
@ -518,7 +518,11 @@ GSEncodingFromLocale(const char *clocale)
|
|||
NSBundle *gbundle;
|
||||
NSString *table;
|
||||
|
||||
#ifdef GNUSTEP
|
||||
gbundle = [NSBundle bundleForLibrary: @"gnustep-base"];
|
||||
#else
|
||||
gbundle = [NSBundle bundleForClass: NSClassFromString(@"GSXMLNode")];
|
||||
#endif
|
||||
table = [gbundle pathForResource: @"Locale"
|
||||
ofType: @"encodings"
|
||||
inDirectory: @"Languages"];
|
||||
|
|
Loading…
Reference in a new issue