CPPSERV


Home Projects Jobs Clientele Contact

cppserv


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add reset test functionality



From: Sergey Jukov <sergey@total-knowledge.com>

---
 ChangeLog           |    3 +++
 Makefile.adon       |    2 +-
 engine.xml          |    1 +
 reset/Makefile.adon |    3 +++
 reset/reset.cpp     |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++
 reset/reset.h       |   44 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 108 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e0d6509..b306a23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+Sergey Jukov <sergey@total-knowledge.com>            Tue, 19 Sep 2006 13:00:00 -0800
+- Add reset servlet test scripts
+
 Sergey Jukov <sergey@total-knowledge.com>            Mon, 18 Sep 2006 15:50:00 -0800
 - Add attributes servlet test scripts
 
diff --git a/Makefile.adon b/Makefile.adon
index b477c92..c6d485f 100644
--- a/Makefile.adon
+++ b/Makefile.adon
@@ -1,2 +1,2 @@
-ADON_SUBDIRS := csp-store hello attributes utils fileupload redirect cookies session headers sharedata params BooksODBC database index
+ADON_SUBDIRS := csp-store hello attributes reset utils fileupload redirect cookies session headers sharedata params BooksODBC database index
 EXTRA_DIST := README engine.xml
diff --git a/engine.xml b/engine.xml
index 5105f49..cf474b6 100644
--- a/engine.xml
+++ b/engine.xml
@@ -6,6 +6,7 @@
     <servlet name="IndexServlet" dso="./debug/index/IndexServlet.so"/>
     <servlet name="HelloServlet" dso="./debug/hello/HelloServlet.so"/>
     <servlet name="AttributesServlet" dso="./debug/attributes/AttributesServlet.so"/>
+    <servlet name="ResetServlet" dso="./debug/reset/ResetServlet.so"/>
     <servlet name="FileUploadServlet" dso="./debug/fileupload/FileUploadServlet.so"/>
     <servlet name="RedirectServlet" dso="./debug/redirect/RedirectServlet.so"/>
     <servlet name="CookiesServlet" dso="./debug/cookies/CookiesServlet.so"/>
diff --git a/reset/Makefile.adon b/reset/Makefile.adon
new file mode 100644
index 0000000..1f990c9
--- /dev/null
+++ b/reset/Makefile.adon
@@ -0,0 +1,3 @@
+noinst_LTLIBRARIES := ResetServlet
+ResetServlet_SOURCES := reset.cpp
+noinst_HEADERS:=reset.h
diff --git a/reset/reset.cpp b/reset/reset.cpp
new file mode 100644
index 0000000..8e55b4f
--- /dev/null
+++ b/reset/reset.cpp
@@ -0,0 +1,56 @@
+/***************************************************************************
+ *   Copyright (C) 2004-2006 by Ilya A. Volynets-Evenbakh                  *
+ *   ilya@total-knowledge.com                                              *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+#include "reset.h"
+#include "servlet/ServletResponse.h"
+
+void ResetServlet::service(servlet::HttpServletRequest& req, servlet::HttpServletResponse& resp)
+{
+	std::ostream &out=resp.getOutputStream();
+	std::auto_ptr<servlet::HttpServletRequest::cookielist_t> cookies=req.getCookies();
+	servlet::HttpServletRequest::cookielist_t::iterator it=cookies->find("TestResetCookie");
+        std::string reset=req.getParameter("reset");
+        servlet::Cookie cookie("TestResetCookie","bla-bla");
+	cookie.setMaxAge(3600);
+	resp.addCookie(cookie);
+        if(reset!="false") {
+	        resp.reset();
+	}
+	renderHeader(out);
+	if(it==cookies->end()) {
+		out<<"TestResetCookie is not set because of work of reset().<br>";
+		out<<"<a href=\""<<req.getRequestURI()<<"?reset=false\">Turn off reset</a>\n";
+	} else {
+	        out<<"Reset is turned off.<br>";
+	        out<<"TestResetCookie = "<<it->second->getValue()<<" is set\n";
+	}
+	renderFooter(out);
+}
+
+void ResetServlet::renderHeader(std::ostream& out)
+{
+	out<<"<html>\n <head>\n  <title>Sample Reset Servlet for CPPSERV</title>\n </head>\n <body>";
+}
+
+void ResetServlet::renderFooter(std::ostream& out)
+{
+	out<<"\n </body>\n</html>";
+}
+
+EXPORT_SERVLET(ResetServlet)
diff --git a/reset/reset.h b/reset/reset.h
new file mode 100644
index 0000000..54ba129
--- /dev/null
+++ b/reset/reset.h
@@ -0,0 +1,44 @@
+/***************************************************************************
+ *   Copyright (C) 2004-2006 by Ilya A. Volynets-Evenbakh                  *
+ *   ilya@total-knowledge.com                                              *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+#ifndef TESTSERVLET2_H
+#define TESTSERVLET2_H
+
+#include <servlet/HttpServlet.h>
+#include <servlet/HttpServletRequest.h>
+#include <servlet/HttpServletResponse.h>
+#include <iostream>
+
+/**
+This servlet demonstrates work of reset() function. Cookie TestResetCookie
+will be set only if reset() is turned off. To start testing over, remove the
+cookie from your browser manually.
+
+@author Ilya A. Volynets-Evenbakh
+*/
+class ResetServlet : public servlet::HttpServlet
+{
+private:
+	void renderHeader(std::ostream&);
+	void renderFooter(std::ostream&);
+public:
+	virtual void service(servlet::HttpServletRequest& req, servlet::HttpServletResponse& resp);
+};
+
+#endif
-- 
1.4.2


Authoright © Total Knowledge: 2001-2008