/[cvs]/api/Classes/Program/WebServer/Header.cpp
ViewVC logotype

Annotation of /api/Classes/Program/WebServer/Header.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sun Jul 1 20:47:58 2001 UTC (23 years ago) by bearsoft
Branch point for: lazy, MAIN
Initial revision

1 bearsoft 1.1 #include "Header.h"
2     #include "../../System/System.h"
3     #include "../../DateTime/DateTime.h"
4     #include "../../System/SystemDefine.h"
5    
6     Header::Header(ConfigInput *iConfigInput)
7     {
8     configInput=iConfigInput;
9     protocolType = new String();
10     filePath = new String();
11     filePathWithoutRootPath = new String();
12     rootPath = new String();
13     stringInput = new StringInput();
14     }
15    
16     Header::~Header()
17     {
18     if (protocolType!=null)
19     {
20     delete protocolType;
21     }
22    
23     if (filePath!=null)
24     {
25     delete filePath;
26     }
27    
28     if (filePathWithoutRootPath!=null)
29     {
30     delete filePathWithoutRootPath;
31     }
32    
33     if (rootPath!=null)
34     {
35     delete rootPath;
36     }
37    
38     if (stringInput!=null)
39     {
40     delete stringInput;
41     }
42     }
43    
44     bool Header::makeAndSendHeaderWithStringData(String &string)
45     {
46     bool connectionStatus=true;
47    
48     String status="200 OK";
49     String contentType="text/html";
50    
51     String dateInfo="Date: ";
52     String serverInfo="Server: ";
53     String serverName=configInput->getData("server","name");
54     String contentTypeInfo="Content-Type: ";
55     String contentLengthInfo="Content-Length: ";
56     String acceptRanges="Accept-Ranges: bytes";
57     String connection="Connection: close";
58     String lProtocolType=protocolType;
59     String contentLength=string.length;
60    
61     String header=lProtocolType + " " + status + NewRow() + dateInfo + DateTime(datetime_) + NewRow() + serverInfo + serverName + NewRow() + acceptRanges + NewRow() + contentLengthInfo + contentLength + NewRow() + connection + NewRow() + contentTypeInfo + contentType + NewRow() + NewRow() ;
62     // System::println(header);
63    
64     if (header.socketSend(socket)!=connectionOkey)
65     {
66     connectionStatus=false;
67     }
68    
69     if (connectionStatus)
70     {
71     if (string.socketSend(socket)!=connectionOkey)
72     {
73     connectionStatus=false;
74     }
75     }
76    
77     return connectionStatus;
78     }
79    
80     bool Header::makeAndSendHeaderWithMessageForbidden()
81     {
82     bool connectionStatus=true;
83    
84     String status="403 Forbidden";
85     String statusMessage=" ";
86    
87     statusMessage.readFile(configInput->getData("error","forbidden"));
88    
89     if (statusMessage.isNull())
90     {
91     statusMessage.setString("403 Forbidden");
92     }
93    
94     String contentType="text/html";
95     String dateInfo="Date: ";
96     String serverInfo="Server: ";
97     String serverName=configInput->getData("server","name");
98     String contentTypeInfo="Content-Type: ";
99     // String contentLengthInfo="Content-Length: ";
100     // String acceptRanges="Accept-Ranges: bytes";
101     String connection="Connection: close";
102     String lProtocolType=protocolType;
103     // String contentLength=statusMessage.length;
104    
105     String header=lProtocolType + " " + status + NewRow() + dateInfo + DateTime(datetime_) + NewRow() + serverInfo + serverName + NewRow() + connection + NewRow() + contentTypeInfo + contentType + NewRow() + NewRow() ;
106     // System::println(header);
107    
108     if (header.socketSend(socket)!=connectionOkey)
109     {
110     connectionStatus=false;
111     }
112    
113     if (connectionStatus)
114     {
115     if (statusMessage.socketSend(socket)!=connectionOkey)
116     {
117     connectionStatus=false;
118     }
119     }
120    
121     return connectionStatus;
122     }
123    
124     bool Header::makeAndSendHeaderWithMessageNotFound()
125     {
126     bool connectionStatus=true;
127    
128     String status="404 Not Found";
129    
130     String statusMessage=" ";
131    
132     statusMessage.readFile(configInput->getData("error","notFound"));
133    
134     if (statusMessage.isNull())
135     {
136     statusMessage.setString("404 Not Found");
137     }
138    
139     String contentType="text/html";
140     String dateInfo="Date: ";
141     String serverInfo="Server: ";
142     String serverName=configInput->getData("server","name");
143     String contentTypeInfo="Content-Type: ";
144     // String contentLengthInfo="Content-Length: ";
145     // String acceptRanges="Accept-Ranges: bytes";
146     String connection="Connection: close";
147     String lProtocolType=protocolType;
148     // String contentLength=statusMessage.length;
149    
150     String header=lProtocolType + " " + status + NewRow() + dateInfo + DateTime(datetime_) + NewRow() + serverInfo + serverName + NewRow() + connection + NewRow() + contentTypeInfo + contentType + NewRow() + NewRow() ;
151     // System::println(header);
152    
153     if (header.socketSend(socket)!=connectionOkey)
154     {
155     connectionStatus=false;
156     }
157    
158     if (connectionStatus)
159     {
160     if (statusMessage.socketSend(socket)!=connectionOkey)
161     {
162     connectionStatus=false;
163     }
164     }
165    
166     return connectionStatus;
167     }
168    
169     bool Header::makeAndSendHeaderErrorMessage(String &status)
170     {
171     bool connectionStatus=true;
172    
173     String contentType="text/html";
174     String dateInfo="Date: ";
175     String serverInfo="Server: ";
176     String serverName=configInput->getData("server","name");
177     String contentTypeInfo="Content-Type: ";
178     // String contentLengthInfo="Content-Length: ";
179     // String acceptRanges="Accept-Ranges: bytes";
180     String connection="Connection: close";
181     String lProtocolType=protocolType;
182     // String contentLength=status.length;
183    
184     String header=lProtocolType + " " + status + NewRow() + dateInfo + DateTime(datetime_) + NewRow() + serverInfo + serverName + NewRow() + connection + NewRow() + contentTypeInfo + contentType + NewRow() + NewRow() ;
185    
186     // System::println(header);
187    
188     if (header.socketSend(socket)!=connectionOkey)
189     {
190     connectionStatus=false;
191     }
192    
193     if (connectionStatus)
194     {
195     if (status.socketSend(socket)!=connectionOkey)
196     {
197     connectionStatus=false;
198     }
199     }
200    
201     return connectionStatus;
202     }
203    
204    
205     bool Header::makeAndSendHeaderWithBinaryData(BinaryInput *binaryInput, String &contentType)
206     {
207     bool connectionStatus=true;
208    
209     String status="200 OK";
210    
211     String dateInfo="Date: ";
212     String serverInfo="Server: ";
213     String serverName=configInput->getData("server","name");
214     String contentTypeInfo="Content-Type: ";
215     String contentLengthInfo="Content-Length: ";
216     String acceptRanges="Accept-Ranges: bytes";
217     String connection="Connection: close";
218     String lProtocolType=protocolType;
219     String contentLength=binaryInput->getInternBufferSize();
220    
221     String header=lProtocolType + " " + status + NewRow() + dateInfo + DateTime(datetime_) + NewRow() + serverInfo + serverName + NewRow() + acceptRanges + NewRow() + contentLengthInfo + contentLength + NewRow() + connection + NewRow() + contentTypeInfo + contentType + NewRow() + NewRow() ;
222     // System::println(header);
223    
224     if (header.socketSend(socket)!=connectionOkey)
225     {
226     connectionStatus=false;
227     }
228    
229    
230     if (connectionStatus)
231     {
232     if (binaryInput->socketSend(socket)!=connectionOkey)
233     {
234     connectionStatus=false;
235     }
236     }
237    
238     return connectionStatus;
239     }
240    

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26