]> err.no Git - sope/blob - Recycler/ApacheWO/ApacheWO+RequestHandler.m
fixed several mistakes in the Xcode project template.
[sope] / Recycler / ApacheWO / ApacheWO+RequestHandler.m
1 // $Id: ApacheWO+RequestHandler.m,v 1.1 2004/06/08 11:06:00 helge Exp $
2
3 #include "ApacheWO.h"
4 #include "AWODirectoryConfig.h"
5 #include "ApacheResourceManager.h"
6 #include "WORequest+Apache.h"
7 #include "WOResponse+Apache.h"
8 #include "common.h"
9 #include <NGObjWeb/WOApplication.h>
10 #include <NGObjWeb/WORequestHandler.h>
11 #include <ApacheAPI/ApacheAPI.h>
12
13 /*
14   implements a WORequestHandler "dispatcher"
15   
16   All WORequestHandler classes are registered in the ApacheHandlers.plist
17   with the single dispatchRequest: selector. This method creates an object
18   of the request handler class and let it dispatch the request.
19 */
20
21 @implementation ApacheWO(RequestHandler)
22
23 - (int)dispatchRequest:(ApacheRequest *)_rq
24   usingHandlerNamed:(NSString *)_hname
25   inApplication:(WOApplication *)_app
26 {
27   WORequestHandler *handler;
28   WORequest  *woRequest;
29   WOResponse *woResponse;
30   int        result;
31   
32   if ((handler = [_app requestHandlerForKey:_hname]) == nil) {
33     [self logWithFormat:@"did not find request handler for key '%@'", 
34             _hname];
35     return ApacheDeclineRequest;
36   }
37   
38   woRequest = [[[WORequest alloc] initWithApacheRequest:_rq] autorelease];
39   
40   woResponse = [_app dispatchRequest:woRequest usingHandler:handler];
41   
42   /* send response */
43   
44   if (woResponse)
45     result = [woResponse sendResponseUsingApacheRequest:_rq];
46   else
47     result = 500;
48
49   return result;
50 }
51
52 - (int)dispatchRequestHandler:(ApacheRequest *)_rq {
53   NSAutoreleasePool  *pool;
54   AWODirectoryConfig *cfg;
55   WOApplication    *app;
56   int result;
57   
58   if (_rq == NULL)
59     return ApacheDeclineRequest;
60   
61   pool = [[NSAutoreleasePool alloc] init];
62   
63   /* get directory specific info (app, request-handler) ! */
64   
65   cfg = [self configForDirectory:_rq];
66   
67   if ((app = [cfg application]) == nil) {
68     [self logWithFormat:@"missing app .."];
69     goto done;
70   }
71   
72   result = [self dispatchRequest:_rq
73                  usingHandlerNamed:[_rq handler]
74                  inApplication:app];
75   
76  done:
77   RELEASE(pool);
78   
79   /* say we are done ... */
80   return result;
81 }
82
83 @end /* ApacheWO(WoxPageHandler) */