-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXMLRPCResponse.m
85 lines (62 loc) · 1.67 KB
/
XMLRPCResponse.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
#import "XMLRPCResponse.h"
#import "XMLRPCEventBasedParser.h"
#import "XMLRPCDataCleaner.h"
@implementation XMLRPCResponse
- (id)initWithData: (NSData *)data {
if (!data) {
return nil;
}
self = [super init];
if (self) {
XMLRPCEventBasedParser *parser = [[XMLRPCEventBasedParser alloc] initWithData: data];
if (!parser) {
[self release];
return nil;
}
myBody = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
myObject = [[parser parse] retain];
if (myObject == nil) {
XMLRPCDataCleaner *cleaner = [[XMLRPCDataCleaner alloc] initWithData: data];
NSData *cleanData = [cleaner cleanData];
[cleaner release];
[parser release];
parser = [[XMLRPCEventBasedParser alloc] initWithData: cleanData];
myBody = [[NSString alloc] initWithData: cleanData encoding: NSUTF8StringEncoding];
myObject = [[parser parse] retain];
}
isFault = [parser isFault];
[parser release];
}
return self;
}
#pragma mark -
- (BOOL)isFault {
return isFault;
}
- (NSNumber *)faultCode {
if (isFault) {
return [myObject objectForKey: @"faultCode"];
}
return nil;
}
- (NSString *)faultString {
if (isFault) {
return [myObject objectForKey: @"faultString"];
}
return nil;
}
#pragma mark -
- (id)object {
return myObject;
}
#pragma mark -
- (NSString *)body {
return myBody;
}
#pragma mark -
- (void)dealloc {
[myBody release];
[myObject release];
[super dealloc];
}
@end