2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
22 #include <XmlRpc/XmlRpcMethodCall.h>
23 #include <XmlRpc/XmlRpcCoder.h>
26 @interface XmlRpcMethodCall(PrivateMethodes)
27 - (NSString *)_encodeXmlRpcMethodCall;
30 @implementation XmlRpcMethodCall
32 - (id)initWithXmlRpcString:(NSString *)_string {
34 XmlRpcMethodCall *baseCall;
36 if ([_string length] == 0) {
41 coder = [[XmlRpcDecoder alloc] initForReadingWithString:_string];
42 baseCall = [coder decodeMethodCall];
45 if (baseCall == nil) {
50 self = [self initWithMethodName:[baseCall methodName]
51 parameters:[baseCall parameters]];
55 - (id)initWithXmlRpcData:(NSData *)_xmlRpcData {
57 XmlRpcMethodCall *baseCall;
59 if ([_xmlRpcData length] == 0) {
64 coder = [[XmlRpcDecoder alloc] initForReadingWithData:_xmlRpcData];
65 baseCall = [coder decodeMethodCall];
68 if (baseCall == nil) {
73 self = [self initWithMethodName:[baseCall methodName]
74 parameters:[baseCall parameters]];
79 - (id)initWithMethodName:(NSString *)_name parameters:(NSArray *)_params {
80 if ((self = [super init])) {
81 self->methodName = [_name copy];
82 [self setParameters:_params];
88 [self->methodName release];
89 [self->parameters release];
95 - (void)setMethodName:(NSString *)_name {
96 [self->methodName autorelease];
97 self->methodName = [_name copy];
99 - (NSString *)methodName {
100 return self->methodName;
103 - (void)setParameters:(NSArray *)_params {
104 if (self->parameters != _params) {
108 [self->parameters autorelease];
111 shallow copy parameters, it is implemented here 'by-hand', since
112 skyrix-xml is not dependend on EOControl
114 cc = [_params count];
115 objects = calloc(cc + 1, sizeof(id));
117 for (i = 0; i < cc; i++)
118 objects[i] = [_params objectAtIndex:i];
119 self->parameters = [[NSArray alloc] initWithObjects:objects count:cc];
120 if (objects) free(objects);
123 - (NSArray *)parameters {
124 return self->parameters;
127 - (NSString *)xmlRpcString {
128 return [self _encodeXmlRpcMethodCall];
133 - (NSString *)description {
136 s = [NSMutableString stringWithFormat:@"<0x%08X[%@]: ",
137 self, NSStringFromClass([self class])];
138 [s appendFormat:@"method=%@", [self methodName]];
139 [s appendFormat:@" #paras=%d", [self->parameters count]];
140 [s appendString:@">"];
144 @end /* XmlRpcMethodCall */
147 @implementation XmlRpcMethodCall(PrivateMethodes)
149 - (NSString *)_encodeXmlRpcMethodCall {
150 NSMutableString *str;
151 XmlRpcEncoder *coder;
154 NSAssert1(self->methodName, @"%s, methodName is not allowed to be nil!",
155 __PRETTY_FUNCTION__);
158 str = [NSMutableString stringWithCapacity:512];
159 coder = [[XmlRpcEncoder alloc] initForWritingWithMutableString:str];
160 [coder encodeMethodCall:self];
162 [coder release]; coder = nil;
167 @end /* XmlRpcMethodCall(PrivateMethodes) */