2
Copyright (C) 2000-2005 SKYRIX Software AG
4
This file is part of SOPE.
6
SOPE 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
SOPE 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 SOPE; see the file COPYING. If not, write to the
18
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22
#include "NGHttpBodyParser.h"
23
#include "NGUrlFormCoder.h"
26
@implementation NGFormUrlBodyParser
28
- (id)parseBodyOfPart:(id<NGMimePart>)_part data:(NSData *)_data
35
[self debugWithFormat:@"parse part %@ data: %@", _part, _data];
38
bytes = [_data bytes];
40
/* cut off spaces at the end */
42
if ((bytes[len - 1] == '\r') || (bytes[len - 1] == '\n'))
47
if (len == 0) return nil;
49
body = NGDecodeUrlFormParameters(bytes, len);
50
return [body autorelease];
53
- (BOOL)isDebuggingEnabled {
57
@end /* NGFormUrlBodyParser */
60
@implementation NGHttpMultipartFormDataBodyParser
63
return [super version] + 0 /* v2 */;
66
NSAssert2([super version] == 2,
67
@"invalid superclass (%@) version %i !",
68
NSStringFromClass([self superclass]), [super version]);
71
- (BOOL)parseImmediatlyWithDelegate:(id)_delegate
72
multipart:(id<NGMimePart>)_part data:(NSData *)_data
77
- (id)parseBodyOfPart:(id<NGMimePart>)_part data:(NSData *)_data
80
NGMimeMultipartBody *body;
82
body = [super parseBodyOfPart:_part data:_data delegate:_d];
84
if ([body isKindOfClass:[NGMimeMultipartBody class]]) {
85
NGMutableHashMap *map;
90
count = [parts count];
92
if (count == 0) // no form fields ..
95
map = [NGMutableHashMap hashMapWithCapacity:count];
96
for (i = 0; i < count; i++) {
97
NGMimeContentDispositionHeaderField *disposition = nil;
98
id<NGMimePart> bodyPart;
100
bodyPart = [parts objectAtIndex:i];
103
[[bodyPart valuesOfHeaderFieldWithName:@"content-disposition"]
107
NSString *name = [disposition name];
108
id partBody = [bodyPart body];
111
[map addObject:partBody forKey:name];
114
NSLog(@"ERROR(%s): did not find content disposition in form part %@",
115
__PRETTY_FUNCTION__, bodyPart);
117
NSLog(@"made map %@", map);
121
NSLog(@"ERROR: form-data parser expected MultipartBody, got %@", body);
127
@end /* NGHttpMultipartFormDataBodyParser */