1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
// $Id$
#include "JAWS/JAWS.h"
#include "JAWS/IO.h"
#include "JAWS/IO_Handler.h"
#include "JAWS/Policy.h"
#include "HTTP_10.h"
#include "HTTP_10_Request.h"
ACE_RCSID(PROTOTYPE, HTTP_10_Write, "$Id$")
// --------------- WRITE TASK ----------------------
JAWS_HTTP_10_Write_Task::JAWS_HTTP_10_Write_Task (void)
{
}
JAWS_HTTP_10_Write_Task::~JAWS_HTTP_10_Write_Task (void)
{
}
int
JAWS_HTTP_10_Write_Task::handle_put (JAWS_Data_Block *data, ACE_Time_Value *)
{
JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put");
JAWS_IO_Handler *handler = data->io_handler ();
JAWS_Dispatch_Policy *policy = this->policy ();
if (policy == 0) policy = data->policy ();
JAWS_IO *io = policy->io ();
JAWS_HTTP_10_Request *info = static_cast<JAWS_HTTP_10_Request *> (data->payload ());
if (info->status () == (int) JAWS_HTTP_10_Request::STATUS_QUIT)
{
data->payload (0);
delete info;
return -3;
}
#if 0
ACE_DEBUG ((LM_DEBUG, " (%t) request %s::%s::%s parsed\n",
(info->method () ? info->method () : "-"),
(info->uri () ? info->uri () : "="),
(info->version () ? info->version () : "HTTP/0.9")));
#endif
if (info->type () != (int) JAWS_HTTP_10_Request::GET)
info->set_status (JAWS_HTTP_10_Request::STATUS_NOT_IMPLEMENTED);
if (info->type () == (int) JAWS_HTTP_10_Request::QUIT)
info->set_status (JAWS_HTTP_10_Request::STATUS_QUIT);
if (info->status () != (int) JAWS_HTTP_10_Request::STATUS_OK)
{
JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ! STATUS OK");
char msg[] =
"<html><head><title>HTTP/1.0 500 Internal Server Error</title>"
"<body><h1>Server Error</h1>HTTP/1.0 500 Internal Server Error"
"</body></html>";
io->send_error_message (handler, msg, sizeof (msg));
switch (handler->status ())
{
case JAWS_IO_Handler::WRITE_OK:
case JAWS_IO_Handler::WRITE_OK_A:
if (info->status () == (int) JAWS_HTTP_10_Request::STATUS_QUIT)
{
data->payload (0);
delete info;
return -3;
}
data->payload (0);
delete info;
return 0;
case JAWS_IO_Handler::WRITE_ERROR:
case JAWS_IO_Handler::WRITE_ERROR_A:
data->payload (0);
delete info;
return -1;
default:
return 2;
}
return 2;
}
else
{
if (ACE_OS::strcmp (info->version (), "HTTP/0.9") == 0)
io->transmit_file (handler,
info->path (),
"",
0,
"",
0);
else
io->transmit_file (handler,
info->path (),
"HTTP/1.0 200 Ok\r\n\r\n",
19,
"",
0);
switch (handler->status ())
{
case JAWS_IO_Handler::TRANSMIT_OK_A:
{
JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, OK_A");
data->payload (0);
delete info;
return 1;
}
case JAWS_IO_Handler::TRANSMIT_OK:
{
JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, OK");
data->payload (0);
delete info;
return 0;
}
case JAWS_IO_Handler::TRANSMIT_ERROR:
{
JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ERROR");
data->payload (0);
delete info;
return 0;
}
case JAWS_IO_Handler::TRANSMIT_ERROR_A:
{
JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ERROR_A");
data->payload (0);
delete info;
return 1;
}
default:
{
JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, DEFAULT");
data->payload (0);
delete info;
return 1;
}
}
}
data->payload (0);
delete info;
return -1;
}
|