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