-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGWSService.m
executable file
·2435 lines (2216 loc) · 57.4 KB
/
GWSService.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Copyright (C) 2008 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <[email protected]>
Date: January 2008
This file is part of the WebServices Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
$Date: 2007-09-24 14:19:12 +0100 (Mon, 24 Sep 2007) $ $Revision: 25500 $
*/
#import <Foundation/Foundation.h>
#import "GWSPrivate.h"
#import <Performance/GSThreadPool.h>
static NSRecursiveLock *queueLock = nil;
static unsigned perHostPool = 20;
static unsigned perHostQMax = 200;
static unsigned shared = 200;
static unsigned pool = 200;
static unsigned qMax = 2000;
static unsigned activeCount = 0;
static GSThreadPool *workThreads = nil;
static NSMutableDictionary *active = nil;
static NSMutableDictionary *queues = nil;
static NSMutableArray *queued = nil;
static NSMutableDictionary *perHostReserve = nil;
#if defined(GNUSTEP)
#import <GNUstepBase/NSURL+GNUstepBase.h>
static NSLock *handleLock = nil;
static NSMutableDictionary *handles = nil;
static unsigned activeHandleCount = 0;
static unsigned cachedHandleCount = 0;
static unsigned peakHandleCount = 0;
#endif
static NSString *
cacheKey(NSURL *host)
{
NSString *k;
if (host)
{
NSString *s = [[host scheme] lowercaseString];
NSString *h = [[host host] lowercaseString];
NSNumber *p = [host port];
if (nil == p)
{
if ([s isEqualToString: @"http"])
{
p = [NSNumber numberWithInt: 80];
}
else if ([s isEqualToString: @"https"])
{
p = [NSNumber numberWithInt: 443];
}
}
k = [NSString stringWithFormat: @"%@://%@:%@", s, h, p];
}
else
{
k = nil;
}
return k;
}
#define IOTHREADS 8
static BOOL useIOThreads = NO;
static NSThread *ioThreads[IOTHREADS] = { 0 };
static NSUInteger ioRequests[IOTHREADS] = { 0 };
#if defined(GNUSTEP)
static BOOL requestDebug = NO;
#endif
static inline void
threadAdd(NSThread **t)
{
unsigned index = IOTHREADS;
NSUInteger offset = NSNotFound;
NSUInteger count = NSNotFound;
NSThread *best = nil;
while (index-- > 0)
{
if (ioRequests[index] < count)
{
best = ioThreads[index];
count = ioRequests[index];
offset = index;
}
}
ioRequests[offset]++; // Record that we have added to this thread.
*t = best;
}
static inline void
threadRem(NSThread **t)
{
unsigned index = IOTHREADS;
while (index-- > 0)
{
if (ioThreads[index] == *t)
{
ioRequests[index]--; // Record that we have removed from this thread.
}
}
*t = nil;
}
/* Return YES if there is an available slot to send a request to the
* specified host, NO otherwise.
* The global lock must be locked before this is called.
*/
static BOOL
available(NSString *host)
{
if (activeCount >= pool)
{
return NO;
}
if (nil != host)
{
unsigned inUse = [[active objectForKey: host] count];
if (activeCount < shared)
{
/* There are shared connections available ... we can have one
* as long as the number of connections for this host has not
* been reached.
*/
if (inUse < perHostPool)
{
return YES;
}
}
else if (0 == inUse && [[perHostReserve objectForKey: host] intValue] > 0)
{
/* No shared connections, but we can use the one reserved for
* this host because there are none in use.
*/
return YES;
}
}
return NO;
}
/* To support client side SSL certificate authentication we use the old
* NSURLHandle stuff with GNUstep extensions. We use the _connection
* ivar to hold the handle in this case.
*/
#define handle ((NSURLHandle*)_connection)
#if defined(GNUSTEP)
@interface NSURLHandle (Debug)
- (int) setDebug: (int)flag;
- (void) setReturnAll: (BOOL)flag;
@end
@interface NSURLRequest (Debug)
- (int) setDebug: (int)flag;
@end
#endif
@implementation GWSService (Private)
+ (void) _never: (NSTimer*)t
{
return;
}
+ (void) _run: (NSString*)host
{
NSMutableArray *a = nil;
NSUInteger index;
NSUInteger count;
[queueLock lock];
if (activeCount < pool && [queued count] > 0)
{
if (available(host) == YES)
{
NSArray *q = [queues objectForKey: host];
count = [q count];
for (index = 0; index < count; index++)
{
GWSService *svc = [q objectAtIndex: index];
if (svc->_request != nil)
{
/* Found a service which is ready to send ...
*/
[svc _activate];
if (nil == a)
{
a = [[NSMutableArray alloc] initWithCapacity: 100];
}
[a addObject: svc];
break;
}
}
}
for (index = 0; activeCount < pool && index < [queued count]; index++)
{
GWSService *svc = [queued objectAtIndex: index];
if (svc->_request != nil)
{
if (available(cacheKey(svc->_connectionURL)) == YES)
{
[svc _activate];
if (nil == a)
{
a = [[NSMutableArray alloc] initWithCapacity: 100];
}
[a addObject: svc];
}
}
}
}
[queueLock unlock];
count = [a count];
if (count > 0)
{
for (index = 0; index < count; index++)
{
GWSService *svc = [a objectAtIndex: index];
if (YES == useIOThreads)
{
threadAdd(&svc->_ioThread);
}
else
{
svc->_ioThread = svc->_queueThread;
}
[svc performSelector: @selector(_start)
onThread: svc->_ioThread
withObject: nil
waitUntilDone: NO];
}
}
[a release];
}
+ (void) _runThread
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSDate *forever = [NSDate distantFuture];
[NSTimer scheduledTimerWithTimeInterval: [forever timeIntervalSinceNow]
target: self
selector: @selector(_never:)
userInfo: nil
repeats: NO];
[[NSRunLoop currentRunLoop] run];
[pool release];
}
/* NB. This must be called with the global lock already locked.
*/
- (void) _activate
{
NSString *host;
NSMutableArray *hostQueue;
/* Add self to active list.
* Keep the count of active requests up to date.
*/
host = cacheKey(_connectionURL);
hostQueue = [active objectForKey: host];
if (hostQueue == nil)
{
hostQueue = [NSMutableArray new];
[active setObject: hostQueue forKey: host];
[hostQueue release];
}
[hostQueue addObject: self];
activeCount++;
/* The next two lines will do nothing if the receiver was not
* queued before activation. We need them for the case where
* we were queued and are now being activated.
* Removal from the queue is done *after* addition to the
* active list to ensure that the receiver is not deallocated.
*/
[[queues objectForKey: host] removeObjectIdenticalTo: self];
[queued removeObjectIdenticalTo: self];
}
- (BOOL) _beginMethod: (NSString*)method
operation: (NSString**)operation
port: (GWSPort**)port
{
/* Perhaps the values are being set directly ... if so, we trust them
*/
if (operation && *operation && port && *port)
{
NSString *o = [*operation retain];
GWSPort *p = [*port retain];
[_operation release];
_operation = o;
[_port release];
_port = p;
return YES;
}
if (nil != _operation)
{
[_operation autorelease];
_operation = nil;
}
if (nil != _port)
{
[_port autorelease];
_port = nil;
}
if (nil == _document)
{
_operation = [method retain];
}
else
{
NSRange r;
NSString *portName;
NSEnumerator *enumerator;
GWSElement *elem;
GWSPortType *portType;
GWSBinding *binding;
GWSPort *found;
/* As this is not a standalone service, we must set up information from
* the parsed WSDL document.
*/
/* Look through the ports declared in this service for one with an
* operation uniquely matching the method. Get details by looking up
* bindings, since we can't actually use a port/operation if there
* is no binding for it.
*/
found = nil;
portName = nil;
enumerator = [_ports objectEnumerator];
while ((_port = [enumerator nextObject]) != nil)
{
binding = [_port binding];
portType = [binding type];
if (portType != nil)
{
elem = [[portType operations] objectForKey: method];
if (elem != nil)
{
if (nil == portName)
{
portName = [portType name]; // matched
found = _port;
}
else
{
found = nil; // not unique
_port = nil;
break;
}
}
}
}
if (nil != found)
{
_operation = [method copy];
_port = [found retain];
}
else if (1 == (r = [method rangeOfString: @"."]).length)
{
/* No unique operation ... but our method name uses dot
* syntax to specify port and operation.
*/
portName = [method substringToIndex: r.location];
_operation = [method substringFromIndex: NSMaxRange(r)];
[_operation retain];
/* Look through the ports declared in this service for one matching
* the port name and operation name. Get details by looking up
* bindings, since we can't actually use a port/operation if there
* is no binding for it.
*/
enumerator = [_ports objectEnumerator];
while ((_port = [enumerator nextObject]) != nil)
{
binding = [_port binding];
portType = [binding type];
if (portType != nil)
{
elem = [[portType operations] objectForKey: _operation];
if (elem != nil && [portName isEqual: [portType name]])
{
break; // matched
}
}
}
[_port retain];
}
if (nil == _port)
{
[self _clean];
[self _setProblem: [NSString stringWithFormat:
@"Unable to find unique operation or port.operation matching '%@'",
method]];
return NO;
}
}
if (operation != 0)
{
*operation = _operation;
}
if (port != 0)
{
*port = _port;
}
return YES;
}
- (void) _clean
{
[_timeout release];
_timeout = nil;
[_prepMethod release];
_prepMethod = nil;
[_prepParameters release];
_prepParameters = nil;
[_prepOrder release];
_prepOrder = nil;
[_queueThread release];
_queueThread = nil;
[_operation release];
_operation = nil;
[_parameters release];
_parameters = nil;
[_port release];
_port = nil;
[_request release];
_request = nil;
}
- (void) _clearConnection
{
if (_connection)
{
id obj = _connection;
_connection = nil;
#if defined(GNUSTEP)
if ([obj isKindOfClass: [NSURLHandle class]])
{
/* Caching of handles; because runtime reconfiguration of
* pool sizes may occur we make sure we do not cache a handle
* if we already have enough cached handles for the current
* maximum number of concurrent connections.
*/
[handleLock lock];
activeHandleCount--;
if (cachedHandleCount < pool)
{
NSString *k = cacheKey(_connectionURL);
if (k)
{
NSMutableArray *h = [handles objectForKey: k];
if ([h count] < perHostPool)
{
if (nil == h)
{
h = [NSMutableArray array];
[handles setObject: h forKey: k];
}
[h addObject: obj];
cachedHandleCount++;
}
}
}
[handleLock unlock];
}
#endif
[obj release];
}
}
- (void) _completed
{
/* We can safely call this more than once, since we do nothing unless
* a request is actually in progress.
*/
if (nil == _queueThread)
{
return;
}
/* Check that this is running in the thread which queued it.
*/
if ([NSThread currentThread] != _queueThread)
{
[self performSelector: @selector(_completed)
onThread: _queueThread
withObject: nil
waitUntilDone: NO];
}
else
{
NSString *host = cacheKey(_connectionURL);
NSMutableArray *a;
NSUInteger index;
[_timer invalidate];
DESTROY(_timer);
if ([self debug] == YES)
{
if (_request != nil)
{
[_result setObject: _request forKey: GWSRequestDataKey];
}
if (_response != nil)
{
[_result setObject: _response forKey: GWSResponseDataKey];
}
}
[self _clean];
/* Make communication resources available (we are no longer using
* the connection/session to the remote system).
*/
[self _clearConnection];
/* Retain self and host in case the delegate changes the URL
* or releases us (or removing self from active list would
* cause deallocation).
*/
[[self retain] autorelease];
/* Now make sure the receiver is no longer active.
* This must be done before informing the delegate of
* completion, in case the delegate wants to schedule
* another request to the same host.
*/
[queueLock lock];
a = [active objectForKey: host];
index = [a indexOfObjectIdenticalTo: self];
if (index == NSNotFound)
{
/* Must have timed out while still in local queue.
*/
[[queues objectForKey: host] removeObjectIdenticalTo: self];
[queued removeObjectIdenticalTo: self];
}
else
{
[a removeObjectAtIndex: index];
activeCount--;
}
[queueLock unlock];
[GWSService _run: host]; // start any queued requests for host
if ([_delegate respondsToSelector: @selector(completedRPC:)])
{
[_delegate completedRPC: self];
}
}
}
- (void) _completedIO
{
/* Must be called in locked region and when _ioThread is not nil!
* Once I/O has been completed, we can't time out ... the RPC has
* either failed or succeeded.
*/
_completedIO = YES;
threadRem(&_ioThread);
[_timer invalidate];
DESTROY(_timer);
}
- (BOOL) _enqueue
{
NSString *host = cacheKey(_connectionURL);
BOOL result = NO;
if (nil != host)
{
NSMutableArray *hostQueue;
NSInteger used;
[queueLock lock];
result = YES;
hostQueue = [queues objectForKey: host];
used = (NSInteger)[hostQueue count];
if ([queued count] >= qMax)
{
result = NO; // Too many queued in total.
}
else if (used >= (NSInteger)perHostQMax)
{
result = NO; // Too many queued for an individual host.
}
if (NO == result && used < [[perHostReserve objectForKey: host] intValue])
{
result = YES; // Reserved space for this host was not filled.
}
if (YES == result)
{
if (hostQueue == nil)
{
hostQueue = [NSMutableArray new];
[queues setObject: hostQueue forKey: host];
[hostQueue release];
}
if (YES == _prioritised)
{
unsigned count;
unsigned index;
count = [hostQueue count];
for (index = 0; index < count; index++)
{
GWSService *tmp = [hostQueue objectAtIndex: index];
if (tmp->_prioritised == NO)
{
break;
}
}
[hostQueue insertObject: self atIndex: index];
count = [queued count];
for (index = 0; index < count; index++)
{
GWSService *tmp = [queued objectAtIndex: index];
if (tmp->_prioritised == NO)
{
break;
}
}
[queued insertObject: self atIndex: index];
}
else
{
[hostQueue addObject: self];
[queued addObject: self];
}
_stage = RPCQueued;
}
[queueLock unlock];
}
return result;
}
- (id) _initWithName: (NSString*)name document: (GWSDocument*)document
{
if ((self = [super init]) != nil)
{
GWSElement *elem;
_lock = [NSRecursiveLock new];
#if !defined(GNUSTEP)
_newAPI = YES;
#endif
_SOAPAction = @"\"\"";
_debug = [[NSUserDefaults standardUserDefaults] boolForKey: @"GWSDebug"];
_name = [name copy];
_document = document;
elem = [_document initializing];
elem = [elem firstChild];
if ([[elem name] isEqualToString: @"documentation"] == YES)
{
_documentation = [elem retain];
elem = [elem sibling];
[_documentation remove];
}
while (elem != nil && [[elem name] isEqualToString: @"port"] == YES)
{
GWSElement *used = nil;
NSString *name;
NSString *binding;
name = [[elem attributes] objectForKey: @"name"];
binding = [[elem attributes] objectForKey: @"binding"];
if (name == nil)
{
NSLog(@"Port without a name in WSDL!");
}
else if (binding == nil)
{
NSLog(@"Port named '%@' without a binding in WSDL!", name);
}
else if ([_document bindingWithName: binding create: NO] == nil)
{
NSLog(@"Port named '%@' with binding '%@' in service but "
@"not in bindings", name, binding);
}
else
{
GWSPort *port;
port = [[GWSPort alloc] _initWithName: name
document: _document
from: elem];
if (_ports == nil)
{
_ports = [NSMutableDictionary new];
}
if (port != nil)
{
[_ports setObject: port forKey: [port name]];
[port release];
}
used = elem;
}
elem = [elem sibling];
[used remove];
}
while (elem != nil)
{
NSString *problem;
problem = [_document _validate: elem in: self];
if (problem != nil)
{
NSLog(@"Bad service extensibility: %@", problem);
}
if (_extensibility == nil)
{
_extensibility = [NSMutableArray new];
}
[_extensibility addObject: elem];
elem = [elem sibling];
[[_extensibility lastObject] remove];
}
}
return self;
}
/* Method to be run from thread pool in order to prepare request data
* to be sent.
*/
- (void) _prepare
{
static NSData *empty = nil;
int stage;
NSData *req;
NSString *pm;
NSDictionary *pp;
NSArray *po;
if (nil == empty)
{
empty = [NSData new];
}
[_lock lock];
stage = _stage;
_stage = RPCPreparing;
pm = _prepMethod;
_prepMethod = nil;
pp = _prepParameters;
_prepParameters = nil;
po = _prepOrder;
_prepOrder = nil;
NS_DURING
{
if (_parameters != nil)
{
NSLog(@"Problem preparing RPC for %@: Earlier operation"
@" still in progress", self);
req = nil;
}
else
{
if ([_delegate respondsToSelector:
@selector(webService:buildRequest:parameters:order:)] == YES)
{
req = [_delegate webService: self
buildRequest: pm
parameters: pp
order: po];
}
else
{
req = nil;
}
if (nil == req)
{
req = [self buildRequest: pm
parameters: pp
order: po];
}
if ([_delegate respondsToSelector:
@selector(webService:willSendRequest:)] == YES)
{
req = [_delegate webService: self willSendRequest: req];
}
}
}
NS_HANDLER
{
NSLog(@"Problem preparing RPC for %@: %@", self, localException);
req = nil;
}
NS_ENDHANDLER
[_lock unlock];
[pm release];
[pp release];
[po release];
/* We can't send a nil request ... so we use an empty data object
* instead if necessary.
*/
if (nil == req)
{
req = empty;
}
/* We must use a lock around the changes we actually make so that a
* call to _run: in another thread won't pick this one up prematurely.
*/
[queueLock lock];
_request = [req retain];
_stage = stage;
[queueLock unlock];
}
- (void) _prepareAndRun
{
[self _prepare];
/* Make sure that this is de-queued and run if possible.
*/
[GWSService _run: cacheKey(_connectionURL)];
}
/* Only ever called after I/O has completed and the timer has been stopped.
*/
- (void) _received
{
if (_result != nil && [_result objectForKey: GWSErrorKey] != nil)
{
return; // Already failed (eg timeout part way through reading).
}
if (_code != 200 && [_coder isKindOfClass: [GWSXMLRPCCoder class]] == YES)
{
NSString *str;
str = [NSString stringWithFormat: @"HTTP status %03d", _code];
[self _setProblem: str];
}
else if (_code != 204 && [_response length] == 0)
{
NSString *str;
/* Unless we got a 204 response, we expect to have a body to parse.
*/
if (_code == 200)
{
str = [NSString stringWithFormat: @"HTTP status 200 but no body"];
}
else
{
str = [NSString stringWithFormat: @"HTTP status %03d", _code];
}
[self _setProblem: str];
}
else
{
/* OK ... parse the body ... which should contain some sort of data
* unless we had a 204 response (some services may accept an empty
* response, even though xmlrpc and soap do not).
*/
NS_DURING
{
NSMutableDictionary *res = nil;
if ([_delegate respondsToSelector:
@selector(webService:handleResponse:)] == YES)
{
res = [_delegate webService: self handleResponse: _response];
}
if (nil == res)
{
if ([_delegate respondsToSelector:
@selector(webService:willHandleResponse:)] == YES)
{
NSData *data;
data = [_delegate webService: self
willHandleResponse: _response];
if (data != _response)
{
[_response release];
_response = [data mutableCopy];
}
}
res = [_coder parseMessage: _response];
}
_result = [res retain];
}
NS_HANDLER
{
id reason = [localException reason];
id keys[1];
keys[0] = GWSFaultKey;
_result = [[NSMutableDictionary alloc] initWithObjects: &reason
forKeys: keys
count: 1];
}
NS_ENDHANDLER
}
[self _completed];
}
- (void) _remove
{
_document = nil;
}
- (void) _setProblem: (NSString*)s
{
if (_result == nil)
{
_result = [NSMutableDictionary new];
}
[_result setObject: s forKey: GWSErrorKey];
}
- (NSString*) _setupFrom: (GWSElement*)element in: (id)section
{
NSString *n;
n = [element namespace];
if ([n length] == 0)
{
/* No namespace recorded directly in the element ...
* See if the document has a namespace for the element's prefix.
*/
n = [element prefix];
if (n == nil)
{
n = @"";
}
n = [_document namespaceForPrefix: n];
}
if (n != nil)
{
GWSExtensibility *e = [_document extensibilityForNamespace: n];
if (e != nil)
{
return [e validate: element for: _document in: section setup: self];
}
}
return nil;
}
- (void) _start
{
NSData *toSend;
NSString *method;
[_lock lock];
if (YES == _cancelled)
{
threadRem(&_ioThread);
[_timer invalidate];
DESTROY(_timer);
[_lock unlock];
[self _completed];
return;
}
_stage = RPCActive;
toSend = [_request retain];