mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-09 03:24:59 -06:00
Bazaar/IPNServerTest : demo for IPNServer package
git-svn-id: svn://ultimatepp.org/upp/trunk@4585 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
ef2d7d8bf2
commit
630ea702b1
3 changed files with 112 additions and 0 deletions
97
bazaar/IPNServerTest/IPNServerTest.cpp
Normal file
97
bazaar/IPNServerTest/IPNServerTest.cpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <IPNServer/IPNServer.h>
|
||||
|
||||
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<String, String> 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();
|
||||
}
|
||||
11
bazaar/IPNServerTest/IPNServerTest.upp
Normal file
11
bazaar/IPNServerTest/IPNServerTest.upp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
description "Instant Payement Notification server for PayPal\377";
|
||||
|
||||
uses
|
||||
IPNServer;
|
||||
|
||||
file
|
||||
IPNServerTest.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "MT";
|
||||
|
||||
4
bazaar/IPNServerTest/init
Normal file
4
bazaar/IPNServerTest/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _IPNServerTest_icpp_init_stub
|
||||
#define _IPNServerTest_icpp_init_stub
|
||||
#include "IPNServer/init"
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue