Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / apps / JAWS2 / HTTP_10_Write.cpp
bloba0ff4f9631c7c023b52a8a9ff6a00168f90213fc
1 #include "JAWS/JAWS.h"
2 #include "JAWS/IO.h"
3 #include "JAWS/IO_Handler.h"
4 #include "JAWS/Policy.h"
6 #include "HTTP_10.h"
8 #include "HTTP_10_Request.h"
11 // --------------- WRITE TASK ----------------------
13 JAWS_HTTP_10_Write_Task::JAWS_HTTP_10_Write_Task ()
17 JAWS_HTTP_10_Write_Task::~JAWS_HTTP_10_Write_Task ()
21 int
22 JAWS_HTTP_10_Write_Task::handle_put (JAWS_Data_Block *data, ACE_Time_Value *)
24 JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put");
26 JAWS_IO_Handler *handler = data->io_handler ();
28 JAWS_Dispatch_Policy *policy = this->policy ();
29 if (policy == 0) policy = data->policy ();
31 JAWS_IO *io = policy->io ();
33 JAWS_HTTP_10_Request *info = static_cast<JAWS_HTTP_10_Request *> (data->payload ());
35 if (info->status () == (int) JAWS_HTTP_10_Request::STATUS_QUIT)
37 data->payload (0);
38 delete info;
39 return -3;
42 #if 0
43 ACE_DEBUG ((LM_DEBUG, " (%t) request %s::%s::%s parsed\n",
44 (info->method () ? info->method () : "-"),
45 (info->uri () ? info->uri () : "="),
46 (info->version () ? info->version () : "HTTP/0.9")));
47 #endif
49 if (info->type () != (int) JAWS_HTTP_10_Request::GET)
50 info->set_status (JAWS_HTTP_10_Request::STATUS_NOT_IMPLEMENTED);
52 if (info->type () == (int) JAWS_HTTP_10_Request::QUIT)
53 info->set_status (JAWS_HTTP_10_Request::STATUS_QUIT);
55 if (info->status () != (int) JAWS_HTTP_10_Request::STATUS_OK)
57 JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ! STATUS OK");
59 char msg[] =
60 "<html><head><title>HTTP/1.0 500 Internal Server Error</title>"
61 "<body><h1>Server Error</h1>HTTP/1.0 500 Internal Server Error"
62 "</body></html>";
64 io->send_error_message (handler, msg, sizeof (msg));
65 switch (handler->status ())
67 case JAWS_IO_Handler::WRITE_OK:
68 case JAWS_IO_Handler::WRITE_OK_A:
69 if (info->status () == (int) JAWS_HTTP_10_Request::STATUS_QUIT)
71 data->payload (0);
72 delete info;
73 return -3;
76 data->payload (0);
77 delete info;
78 return 0;
80 case JAWS_IO_Handler::WRITE_ERROR:
81 case JAWS_IO_Handler::WRITE_ERROR_A:
82 data->payload (0);
83 delete info;
84 return -1;
86 default:
87 return 2;
90 return 2;
92 else
94 if (ACE_OS::strcmp (info->version (), "HTTP/0.9") == 0)
95 io->transmit_file (handler,
96 info->path (),
97 "",
99 "",
101 else
102 io->transmit_file (handler,
103 info->path (),
104 "HTTP/1.0 200 Ok\r\n\r\n",
109 switch (handler->status ())
111 case JAWS_IO_Handler::TRANSMIT_OK_A:
113 JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, OK_A");
114 data->payload (0);
115 delete info;
116 return 1;
119 case JAWS_IO_Handler::TRANSMIT_OK:
121 JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, OK");
122 data->payload (0);
123 delete info;
124 return 0;
126 case JAWS_IO_Handler::TRANSMIT_ERROR:
128 JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ERROR");
129 data->payload (0);
130 delete info;
131 return 0;
133 case JAWS_IO_Handler::TRANSMIT_ERROR_A:
135 JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ERROR_A");
136 data->payload (0);
137 delete info;
138 return 1;
140 default:
142 JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, DEFAULT");
143 data->payload (0);
144 delete info;
145 return 1;
151 data->payload (0);
152 delete info;
153 return -1;