From 630ea702b1e112fdc0c09f513e176846a9658695 Mon Sep 17 00:00:00 2001 From: micio Date: Mon, 13 Feb 2012 10:46:47 +0000 Subject: [PATCH] Bazaar/IPNServerTest : demo for IPNServer package git-svn-id: svn://ultimatepp.org/upp/trunk@4585 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/IPNServerTest/IPNServerTest.cpp | 97 ++++++++++++++++++++++++++ bazaar/IPNServerTest/IPNServerTest.upp | 11 +++ bazaar/IPNServerTest/init | 4 ++ 3 files changed, 112 insertions(+) create mode 100644 bazaar/IPNServerTest/IPNServerTest.cpp create mode 100644 bazaar/IPNServerTest/IPNServerTest.upp create mode 100644 bazaar/IPNServerTest/init diff --git a/bazaar/IPNServerTest/IPNServerTest.cpp b/bazaar/IPNServerTest/IPNServerTest.cpp new file mode 100644 index 000000000..d6ecc22a3 --- /dev/null +++ b/bazaar/IPNServerTest/IPNServerTest.cpp @@ -0,0 +1,97 @@ +#include + +using namespace Upp; + +// comment following one to have the server running as a daemon (UNIX ONLY BY NOW... +#define DEBUGME + +#ifdef PLATFORM_POSIX +#ifndef DEBUGME +static bool Daemonize(void) +{ + pid_t pid, sid; + + // already a daemon + if ( getppid() == 1 ) + return true; + + // Fork off the parent process + pid = fork(); + if (pid < 0) + return false; + + // If we got a good PID, then we can exit the parent process. + if (pid > 0) + _exit(0); + + // At this point we are executing as the child process + + // Change the file mode mask + umask(0); + + // Create a new SID for the child process + sid = setsid(); + if (sid < 0) + return false; + + // Change the current working directory. This prevents the current + // directory from being locked; hence not being able to remove it. + if ((chdir("/")) < 0) + return false; + + // Redirect standard files to a log file (NULL for input) + String logPath = "/var/log/TimberStruct/"; + RealizePath(logPath); + freopen("/dev/null", "r", stdin); + freopen(AppendFileName(logPath, "out.log"), "w", stdout); + freopen(AppendFileName(logPath, "err.log"), "w", stderr); + return true; +} +#endif +#endif + +void OnVerified(VectorMap data) +{ + Cout() << "DUMP OF TRANSACTION DATA:\n\n"; + for(int i = 0; i < data.GetCount(); i++) + Cout() << data.GetKey(i) << "=" << data[i] << "\n"; +} + +void OnInvalid(void) +{ + Cout() << "'INVALID' ANSWER FROM PayPal SERVER\n\n"; +} + +CONSOLE_APP_MAIN +{ +#ifdef PLATFORM_POSIX +#ifndef DEBUGME + // daemonize me + if(!Daemonize()) + { + Cerr() << "Error making me a daemon!\n"; + exit(1); + } +#endif +#endif + + // create server object -- beware of port, it must match + // SCGI port setup on your server + IPNServer server(8789); + + // setup paypal confirmation server and port + // (here the sandbox testing one, change for real usage !) + server + .SetPayServer("www.sandbox.paypal.com") + .SetPayPort(443) + ; + + // setup handlers for VERIFIED and INVALID paypal messages + server + .SetVerifiedHandler(STDBACK(OnVerified)) + .SetInvalidHandler(STDBACK(OnInvalid)) + ; + + // runs server -- TO DO : make it multithreaded + server.Run(); +} diff --git a/bazaar/IPNServerTest/IPNServerTest.upp b/bazaar/IPNServerTest/IPNServerTest.upp new file mode 100644 index 000000000..44aeb573c --- /dev/null +++ b/bazaar/IPNServerTest/IPNServerTest.upp @@ -0,0 +1,11 @@ +description "Instant Payement Notification server for PayPal\377"; + +uses + IPNServer; + +file + IPNServerTest.cpp; + +mainconfig + "" = "MT"; + diff --git a/bazaar/IPNServerTest/init b/bazaar/IPNServerTest/init new file mode 100644 index 000000000..afd9be7b3 --- /dev/null +++ b/bazaar/IPNServerTest/init @@ -0,0 +1,4 @@ +#ifndef _IPNServerTest_icpp_init_stub +#define _IPNServerTest_icpp_init_stub +#include "IPNServer/init" +#endif