~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2000-2005 SKYRIX Software AG
 
3
 
 
4
  This file is part of SOPE.
 
5
 
 
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
 
9
  later version.
 
10
 
 
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.
 
15
 
 
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
 
19
  02111-1307, USA.
 
20
*/
 
21
 
 
22
#include "NGHttpBodyParser.h"
 
23
#include "NGUrlFormCoder.h"
 
24
#include "common.h"
 
25
 
 
26
@implementation NGFormUrlBodyParser
 
27
 
 
28
- (id)parseBodyOfPart:(id<NGMimePart>)_part data:(NSData *)_data
 
29
  delegate:(id)_d
 
30
{
 
31
  const char *bytes;
 
32
  unsigned   len;
 
33
  id         body;
 
34
 
 
35
  [self debugWithFormat:@"parse part %@ data: %@", _part, _data];
 
36
  
 
37
  len   = [_data length];
 
38
  bytes = [_data bytes];
 
39
  
 
40
  /* cut off spaces at the end */
 
41
  while (len > 0) {
 
42
    if ((bytes[len - 1] == '\r') || (bytes[len - 1] == '\n'))
 
43
      len--;
 
44
    else
 
45
      break;
 
46
  }
 
47
  if (len == 0) return nil;
 
48
  
 
49
  body = NGDecodeUrlFormParameters(bytes, len);
 
50
  return [body autorelease];
 
51
}
 
52
 
 
53
- (BOOL)isDebuggingEnabled {
 
54
  return NO;
 
55
}
 
56
 
 
57
@end /* NGFormUrlBodyParser */
 
58
 
 
59
 
 
60
@implementation NGHttpMultipartFormDataBodyParser
 
61
 
 
62
+ (int)version {
 
63
  return [super version] + 0 /* v2 */;
 
64
}
 
65
+ (void)initialize {
 
66
  NSAssert2([super version] == 2,
 
67
            @"invalid superclass (%@) version %i !",
 
68
            NSStringFromClass([self superclass]), [super version]);
 
69
}
 
70
 
 
71
- (BOOL)parseImmediatlyWithDelegate:(id)_delegate
 
72
  multipart:(id<NGMimePart>)_part data:(NSData *)_data 
 
73
{
 
74
  return YES;
 
75
}
 
76
 
 
77
- (id)parseBodyOfPart:(id<NGMimePart>)_part data:(NSData *)_data
 
78
  delegate:(id)_d
 
79
{
 
80
  NGMimeMultipartBody *body;
 
81
  
 
82
  body = [super parseBodyOfPart:_part data:_data delegate:_d];
 
83
  
 
84
  if ([body isKindOfClass:[NGMimeMultipartBody class]]) {
 
85
    NGMutableHashMap *map;
 
86
    NSArray  *parts;
 
87
    unsigned i, count;
 
88
 
 
89
    parts = [body parts];
 
90
    count = [parts count];
 
91
    
 
92
    if (count == 0) // no form fields ..
 
93
      return nil;
 
94
 
 
95
    map = [NGMutableHashMap hashMapWithCapacity:count];
 
96
    for (i = 0; i < count; i++) {
 
97
      NGMimeContentDispositionHeaderField *disposition = nil;
 
98
      id<NGMimePart> bodyPart;
 
99
      
 
100
      bodyPart = [parts objectAtIndex:i];
 
101
      
 
102
      disposition =
 
103
        [[bodyPart valuesOfHeaderFieldWithName:@"content-disposition"]
 
104
                   nextObject];
 
105
      
 
106
      if (disposition) {
 
107
        NSString *name    = [disposition name];
 
108
        id       partBody = [bodyPart body];
 
109
        
 
110
        if (partBody)
 
111
          [map addObject:partBody forKey:name];
 
112
      }
 
113
      else
 
114
        NSLog(@"ERROR(%s): did not find content disposition in form part %@",
 
115
              __PRETTY_FUNCTION__, bodyPart);
 
116
    }
 
117
    NSLog(@"made map %@", map);
 
118
    return map;
 
119
  }
 
120
  else {
 
121
    NSLog(@"ERROR: form-data parser expected MultipartBody, got %@", body);
 
122
    body = nil;
 
123
  }
 
124
  return body;
 
125
}
 
126
 
 
127
@end /* NGHttpMultipartFormDataBodyParser */