2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <XmlRpc/XmlRpcMethodCall.h>
24 #include <XmlRpc/XmlRpcCoder.h>
27 @interface XmlRpcMethodCall(PrivateMethodes)
28 - (NSString *)_encodeXmlRpcMethodCall;
31 @implementation XmlRpcMethodCall
33 - (id)initWithXmlRpcString:(NSString *)_string {
35 XmlRpcMethodCall *baseCall;
37 if ([_string length] == 0) {
42 coder = [[XmlRpcDecoder alloc] initForReadingWithString:_string];
43 baseCall = [coder decodeMethodCall];
46 if (baseCall == nil) {
51 self = [self initWithMethodName:[baseCall methodName]
52 parameters:[baseCall parameters]];
56 - (id)initWithXmlRpcData:(NSData *)_xmlRpcData {
58 XmlRpcMethodCall *baseCall;
60 if ([_xmlRpcData length] == 0) {
65 coder = [[XmlRpcDecoder alloc] initForReadingWithData:_xmlRpcData];
66 baseCall = [coder decodeMethodCall];
69 if (baseCall == nil) {
74 self = [self initWithMethodName:[baseCall methodName]
75 parameters:[baseCall parameters]];
80 - (id)initWithMethodName:(NSString *)_name parameters:(NSArray *)_params {
81 if ((self = [super init])) {
82 self->methodName = [_name copy];
83 [self setParameters:_params];
89 [self->methodName release];
90 [self->parameters release];
96 - (void)setMethodName:(NSString *)_name {
97 [self->methodName autorelease];
98 self->methodName = [_name copy];
100 - (NSString *)methodName {
101 return self->methodName;
104 - (void)setParameters:(NSArray *)_params {
105 if (self->parameters != _params) {
109 [self->parameters autorelease];
112 shallow copy parameters, it is implemented here 'by-hand', since
113 skyrix-xml is not dependend on EOControl
115 cc = [_params count];
116 objects = calloc(cc + 1, sizeof(id));
118 for (i = 0; i < cc; i++)
119 objects[i] = [_params objectAtIndex:i];
120 self->parameters = [[NSArray alloc] initWithObjects:objects count:cc];
121 if (objects) free(objects);
124 - (NSArray *)parameters {
125 return self->parameters;
128 - (NSString *)xmlRpcString {
129 return [self _encodeXmlRpcMethodCall];
134 - (NSString *)description {
137 s = [NSMutableString stringWithFormat:@"<0x%08X[%@]: ",
138 self, NSStringFromClass([self class])];
139 [s appendFormat:@"method=%@", [self methodName]];
140 [s appendFormat:@" #paras=%d", [self->parameters count]];
141 [s appendString:@">"];
145 @end /* XmlRpcMethodCall */
148 @implementation XmlRpcMethodCall(PrivateMethodes)
150 - (NSString *)_encodeXmlRpcMethodCall {
151 NSMutableString *str;
152 XmlRpcEncoder *coder;
155 NSAssert1(self->methodName, @"%s, methodName is not allowed to be nil!",
156 __PRETTY_FUNCTION__);
159 str = [NSMutableString stringWithCapacity:512];
160 coder = [[XmlRpcEncoder alloc] initForWritingWithMutableString:str];
161 [coder encodeMethodCall:self];
163 [coder release]; coder = nil;
168 @end /* XmlRpcMethodCall(PrivateMethodes) */