]> err.no Git - sope/blob - Recycler/ApacheWO/ApacheWOTransaction.m
use %p for pointer formats
[sope] / Recycler / ApacheWO / ApacheWOTransaction.m
1 // $Id: ApacheWOTransaction.m,v 1.1 2004/06/08 11:06:00 helge Exp $
2
3 #include "ApacheWOTransaction.h"
4 #include "common.h"
5
6 #include "AWODirectoryConfig.h"
7 #include "AWOServerConfig.h"
8 #include "ApacheResourceManager.h"
9 #include "WORequest+Apache.h"
10 #include "WOResponse+Apache.h"
11 #include <ApacheAPI/ApacheRequest.h>
12 #include <NGObjWeb/WORequest.h>
13 #include <NGObjWeb/WOResponse.h>
14 #include <NGObjWeb/WOApplication.h>
15
16 @implementation ApacheWOTransaction
17
18 - (id)initWithApacheRequest:(ApacheRequest *)_rq
19   config:(AWODirectoryConfig *)_cfg 
20   serverConfig:(AWOServerConfig *)_srvcfg
21 {
22   if (_rq == nil) {
23     RELEASE(self);
24     return nil;
25   }
26   self->config       = RETAIN(_cfg);
27   self->serverConfig = RETAIN(_srvcfg);
28   self->request      = RETAIN(_rq);
29   
30   if ((self->woRequest = [[WORequest alloc] initWithApacheRequest:_rq])==nil) {
31     NSLog(@"%s: could not create WO request ...", __PRETTY_FUNCTION__);
32     RELEASE(self);
33     return nil;
34   }
35   
36   if ((self->application = [[_cfg application] retain]) == nil) {
37     NSLog(@"%s: no app is configured ...", __PRETTY_FUNCTION__);
38     RELEASE(self);
39     return nil;
40   }
41   
42   self->resourceManager =
43     [[ApacheResourceManager alloc] initWithApacheRequest:_rq config:_cfg];
44   
45   if (self->resourceManager == nil) {
46     NSLog(@"%s: could not create resource manager ...", __PRETTY_FUNCTION__);
47     RELEASE(self);
48     return nil;
49   }
50   
51   return self;
52 }
53
54 - (void)dealloc {
55   RELEASE(self->resourceManager);
56   RELEASE(self->woRequest);
57   RELEASE(self->woResponse);
58   RELEASE(self->application);
59   RELEASE(self->serverConfig);
60   RELEASE(self->config);
61   RELEASE(self->request);
62   [super dealloc];
63 }
64
65 /* accessors */
66
67 - (WOApplication *)application {
68   return [self->config application];
69 }
70 - (WORequest *)request {
71   return self->woRequest;
72 }
73 - (WOResponse *)response {
74   return self->woResponse;
75 }
76
77 - (ApacheRequest *)apacheRequest {
78   return self->request;
79 }
80
81 /* activation */
82
83 - (void)activate {
84   [self->application activateApplication];
85   // should use stack ??
86   [self->application setResourceManager:self->resourceManager];
87 }
88 - (void)deactivate {
89   [self->application setResourceManager:nil];
90   [self->application deactivateApplication];
91 }
92
93 /* dispatch */
94
95 - (int)dispatchUsingHandler:(WORequestHandler *)_handler {
96   WOResponse *response;
97   
98   response = [self->application
99                   dispatchRequest:self->woRequest
100                   usingHandler:_handler];
101   return [response sendResponseUsingApacheRequest:self->request];
102 }
103
104 /* description */
105
106 - (NSString *)description {
107   NSMutableString *ms;
108   
109   ms = [NSMutableString stringWithCapacity:64];
110   [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
111   [ms appendFormat:@" uri=%@", [[self request] uri]];
112   [ms appendString:@">"];
113   return ms;
114 }
115
116 @end /* ApacheWOTransaction */