]> err.no Git - sope/blob - sope-appserver/NGObjWeb/NGHttp/NGHttpRequest.m
increased element nesting depth
[sope] / sope-appserver / NGObjWeb / NGHttp / NGHttpRequest.m
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 "NGHttpRequest.h"
23 #include "common.h"
24 #include "NGUrlFormCoder.h"
25
26 NSString *methodNames[] = {
27   @"<unknown HTTP method>",
28   @"OPTIONS",
29   @"GET",
30   @"HEAD",
31   @"POST",
32   @"PUT",
33   @"PATCH",
34   @"COPY",
35   @"MOVE",
36   @"DELETE",
37   @"LINK",
38   @"UNLINK",
39   @"TRACE",
40   @"WRAPPED",
41   @"CONNECT",
42   @"PROPFIND",
43   @"PROPPATCH",
44   @"MKCOL",
45   @"LOCK",
46   @"UNLOCK",
47   /* Exchange Ext Methods */
48   @"SEARCH", 
49   @"SUBSCRIBE",
50   @"UNSUBSCRIBE",
51   @"NOTIFY",
52   @"POLL",
53   /* Exchange Bulk Methods */
54   @"BCOPY",
55   @"BDELETE",
56   @"BMOVE",
57   @"BPROPFIND",
58   @"BPROPPATCH",
59   nil
60 };
61
62 @interface NGHttpMessage(PrivateMethods)
63 - (id)initWithHeader:(NGHashMap *)_header version:(NSString *)_version;
64 @end
65
66 @implementation NGHttpRequest
67
68 - (id)initWithMethod:(NSString *)_methodName uri:(NSString *)_uri
69   header:(NGHashMap *)_header version:(NSString *)_version
70 {
71   if ((self = [super initWithHeader:_header version:_version])) {
72     self->method = NGHttpMethodFromString(_methodName);
73     self->uri    = [_uri copyWithZone:[self zone]];
74   }
75   return self;
76 }
77 - (id)initWithHeader:(NGHashMap *)_header version:(NSString *)_version {
78   return [self initWithMethod:@"GET" uri:@"/" header:_header version:_version];
79 }
80
81 - (void)dealloc {
82   [self->uri           release];
83   [self->uriParameters release];
84   [super dealloc];
85 }
86
87 /* accessors */
88
89 - (NGHttpMethod)method {
90   return self->method;
91 }
92 - (NSString *)methodName {
93   return (self->method < NGHttpMethod_last) ? methodNames[self->method] : nil;
94 }
95
96 - (NSString *)path {
97   return self->uri;
98 }
99
100 - (NSString *)uri {
101   return self->uri;
102 }
103
104 - (NGHashMap *)uriParameters { // parameters in x-www-form-urlencoded encoding
105   if (self->uriParameters == nil) {
106     const char *cstr = [self->uri cString];
107     const char *pos  = index(cstr, '?');
108
109     if (pos) {
110       pos++;
111       self->uriParameters = NGDecodeUrlFormParameters(pos, strlen(pos));
112     }
113   }
114   return self->uriParameters;
115 }
116
117 /* debugging */
118
119 - (BOOL)isDebuggingEnabled {
120   return NO;
121 }
122
123 /* description */
124
125 - (NSString *)description {
126   return [NSString stringWithFormat:
127                      @"<HttpRequest: method=%@ uri=%@ header=%@ body=%@>",
128                      [self methodName],
129                      [self uri],
130                      self->header,
131                      self->body];
132 }
133
134 @end /* NGHttpRequest */
135
136 NGHttpMethod NGHttpMethodFromString(NSString *_value) {
137   int i = 0;
138
139   for (i = 1; i < NGHttpMethod_last; i++) {
140     NSString *name = methodNames[i];
141
142     if ([name isEqualToString:_value])
143       return i;
144   }
145   return 0;
146 }