]> err.no Git - sope/blob - Recycler/ApacheWO/WORequest+Apache.m
fixed several mistakes in the Xcode project template.
[sope] / Recycler / ApacheWO / WORequest+Apache.m
1 // $Id: WORequest+Apache.m,v 1.1 2004/06/08 11:06:00 helge Exp $
2
3 #include "WORequest+Apache.h"
4 #include <ApacheAPI/ApacheRequest.h>
5 #include <ApacheAPI/ApacheTable.h>
6 #include <ApacheAPI/ApacheConnection.h>
7 #include "common.h"
8
9 @interface WORequest(ApachePrivates)
10
11 - (NSData *)readDataFromApacheRequest:(ApacheRequest *)_rq;
12
13 @end
14
15 @implementation WORequest(Apache)
16
17 - (id)initWithApacheRequest:(ApacheRequest *)_rq {
18   NSMutableDictionary *headers;
19   NSAutoreleasePool *pool;
20   NSString     *httpVersion = nil;
21   NSData       *contentData;
22   NSDictionary *ui;
23   NGHashMap    *form;
24   
25   if (_rq == nil) {
26     RELEASE(self);
27     return nil;
28   }
29   
30   pool = [[NSAutoreleasePool alloc] init];
31   headers = [[NSMutableDictionary alloc] initWithCapacity:32];
32   
33   /* the values need to be parsed ! */
34   {
35     ApacheTable  *hin;
36     NSEnumerator *keys;
37     NSString     *key;
38     
39     hin = [_rq headersIn];
40     keys = [hin keyEnumerator];
41     while ((key = [keys nextObject])) {
42       NSString *value;
43       
44       if ((value = [hin objectForKey:key]) == nil) {
45         [self logWithFormat:@"got no value for key '%@' ..", key];
46         continue;
47       }
48       
49       /* NGObjWeb expects all keys to be lowercase .. */
50       key = [key lowercaseString];
51       [headers setObject:value forKey:key];
52     }
53   }
54   
55   /* setup "special" headers */
56   {
57     ApacheConnection *con = [_rq connection];
58     NSString *tmp;
59     
60     if ((tmp = [headers objectForKey:@"host"])) {
61       tmp = [@"http://" stringByAppendingString:tmp];
62       [headers setObject:tmp forKey:@"x-webobjects-server-url"];
63     }
64     if ([(tmp = [con remoteHost]) length] > 0)
65       [headers setObject:tmp forKey:@"x-webobjects-remote-host"];
66     if ([(tmp = [con user]) length] > 0)
67       [headers setObject:tmp forKey:@"x-webobjects-remote-user"];
68     if ([(tmp = [con authorizationType]) length] > 0)
69       [headers setObject:tmp forKey:@"x-webobjects-auth-type"];
70   }
71   
72   /* content, this is to be done ... (libapr ?, hm) */
73   contentData = [self readDataFromApacheRequest:_rq];
74   
75   /* userinfo */
76   
77   ui = [NSDictionary dictionaryWithObject:_rq forKey:@"ApacheRequest"];
78   
79   /* form values */
80   
81   {
82     const char *cstr = [[_rq unparsedURI] cString];
83     const char *pos  = index(cstr, '?');
84     
85     if (pos) {
86       pos++;
87       form = NGDecodeUrlFormParameters(pos, strlen(pos));
88     }
89     else
90       form = nil;
91   }
92   
93   /* construct */
94   
95   self = [self initWithMethod:[_rq method]
96                uri:[_rq uri]
97                httpVersion:httpVersion
98                headers:headers
99                content:contentData
100                userInfo:ui];
101   ASSIGN(self->formContent, form);
102   
103   RELEASE(headers);
104   RELEASE(pool);
105   return self;
106 }
107
108 - (NSData *)readDataFromApacheRequest:(ApacheRequest *)_rq {
109 #warning read request content if available ...
110   return nil;
111 }
112
113 - (ApacheRequest *)apacheRequest {
114   return [[self userInfo] objectForKey:@"ApacheRequest"];
115 }
116
117 @end /* WORequest(Apache) */