DCL 3.7.4
Loading...
Searching...
No Matches
reqdump.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef __WINNT__
4#include <process.h>
5#define getpid _getpid
6#else
7#include <unistd.h>
8#endif
9
10#include <time.h>
11
12#include <dcl/Numeric.h>
13#include <dcl/MD5.h>
14#include <dcl/Files.h>
15
16#include "reqdump.h"
17
18#if __DCL_HAVE_THIS_FILE__
19#undef __THIS_FILE__
20static const char_t __THIS_FILE__[] = __T("dcl/hsa/reqdump.cpp");
21#endif
22
23__DCL_BEGIN_NAMESPACE
24
25HTTP_SERVLET_INSTANCE(ReqDumpServlet, L"Show HTTP Request Information")
26
28
32{
33 ctx.setContentType(L"text/plain; charset=utf-8");
34
35 String strSessionID = ctx.__cookieMap[L"session_id"];
36 if (strSessionID.isEmpty()) {
37 StringBuilder sb = ctx.remoteAddr();
38 sb += String::valueOf(ctx.remotePort());
39 sb += String::valueOf(time(NULL));
40 strSessionID = MD5::final(sb);
41
42 HttpSetCookie cookie(
43 L"session_id",
44 strSessionID,
45 0, // time(NULL) + 3600,
46 L"/"
47 );
48 ctx.addHeader(cookie);
49 }
50
51 __DCL_TRACE1(L"session_id[%ls]\n", strSessionID.data());
52
53 Writer& out = ctx.writer();
54
55 out << L"PID : " << getpid() << L"\n";
56 out << L"moduleName : " << __moduleName << L"\n";
57
58 out << L"BEGIN CONTEXT INFO\n";
59 out << L"remoteAddr [" << ctx.remoteAddr() << L"]\n";
60 out << L"remotePort [" << ctx.remotePort() << L"]\n";
61 out << L"method [" << ctx.method() << L"]\n";
62 out << L"remoteMethodNo [" << ctx.methodNo() << L"]\n";
63 out << L"path [" << ctx.path() << L"]\n";
64 out << L"queryString [" << ctx.queryString() << L"]\n";
65 out << L"contentType [" << ctx.contentType() << L"]\n";
66 out << L"contentLength [" << ctx.contentLength() << L"]\n";
67 out << L"END CONTEXT INFO\n\n";
68 out << L"BEGIN CGI VARIABLES\n"
69 << ctx.getCgiVariable((const wchar_t*)NULL)
70 << L"END CGI VARIABLES\n\n";
71 out << L"BEGIN REQUEST HTTP HEADERS\n"
72 << ctx.getHttpHeader((const wchar_t*)NULL)
73 << L"END REQUEST HTTP HEADERS\n\n";
74 out << L"BEGIN COOKIES\n";
75 if (!ctx.__cookieMap.isEmpty()) {
76 for(ListedStringToStringMap::Iterator it = ctx.__cookieMap.begin();
77 it != ctx.__cookieMap.end(); it++) {
78 out << (*it).key << L":" << (*it).value << L"\n";
79 }
80 }
81 out << L"END COOKIES\n\n";
82
83 out << L"BEGIN QUERY_STRING\n";
84 if (!ctx.__queryMap.isEmpty()) {
85 for(ListedStringToStringArrayMap::Iterator it = ctx.__queryMap.begin();
86 it != ctx.__queryMap.end(); it++) {
87 out << (*it).key << L":";
88 StringArray& v = (*it).value;
89 for(size_t i = 0; i < v.size(); i++) {
90 if (i > 0)
91 out << L", ";
92 out << v[i];
93 }
94 out << L"\n";
95 }
96 }
97 out << L"END QUERY_STRING\n\n";
98
99 out << L"BEGIN FORM_DATA\n";
100 if (!ctx.__formMap.isEmpty()) {
101 for(ListedStringToStringArrayMap::Iterator it = ctx.__formMap.begin();
102 it != ctx.__formMap.end(); it++) {
103 out << (*it).key << L":";
104 StringArray& v = (*it).value;
105 for(size_t i = 0; i < v.size(); i++) {
106 if (i > 0)
107 out << L", ";
108 out << v[i];
109 }
110 out << L"\n";
111 }
112 }
113 out << L"END FORM_DATA\n\n";
114
115 out << L"BEGIN FILES\n";
116 if (!ctx.__formFileMap.isEmpty()) {
117 for(size_t i = 0; i < ctx.__formFileMap.size(); i++) {
118 StoredHttpFormData::FileInfoArray& v = ctx.__formFileMap[i];
119 out << v.name() << L":";
120 for(size_t j = 0; j < v.size(); j++) {
121 StoredHttpFormData::FileInfo& info = v[j];
122 out << L"\n\tfilename: " << info.filename
123 << L"\n\tfilesize: " << info.fileSize
124 << L"\n\tContent-Type: " << info.contentType
125 << L"\n\tContent-Transfer-Encoding: " << info.transferEncoding
126 << L"\n\ttemp filename: " << info.tempFilename
127 << L"\n";
128
129 Files::rename(info.tempFilename, info.tempFilename + L"-renamed");
130 }
131 }
132 }
133 out << L"END FILES\n\n";
134
135/*
136 if (ctx.contentLength()) {
137 FileOutputStream o(
138 File::filename(Files::dirname(__strFileName), "postdump.txt"),
139 File::modeBinary | File::modeTruncate
140 );
141
142 size_t n = ctx.contentLength();
143 ByteBuffer buf(2048);
144 while((buf.nDataSize = ctx.read(buf.pData, buf.nBufferSize))) {
145 o.write(buf.pData, buf.nDataSize);
146// out.write(buf.pData, buf.nDataSize);
147 }
148 }
149*/
150}
151
152__DCL_END_NAMESPACE
153
154#ifdef __WINNT_NEW_DELETE_OVERRIDE
155#undef new
156__WINNT_NEW_DELETE_OVERRIDE
157#endif
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:312
wchar_t char_t
Definition Config.h:247
#define __DCL_THROWS1(e)
Definition Config.h:152
#define HTTP_SERVLET_INSTANCE(ServletClass, Description)
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:399
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:245
#define __T(str)
Definition Object.h:60
static void rename(const String &_oldpath, const String &_newpath) __DCL_THROWS1(IOException *)
Definition Files.cpp:67
virtual void onService(HttpServletContextEx &ctx)=0__DCL_THROWS1(Exception *)
String final()
Definition MD5.cpp:80