From 331ba759e2696dce66c357dbff78c3f1c5cb8670 Mon Sep 17 00:00:00 2001 From: micio Date: Sun, 10 Oct 2010 12:30:49 +0000 Subject: [PATCH] Bazaar/Protect : added Protect Client and Server/Client demo Work in progress, still missing database connections / registering git-svn-id: svn://ultimatepp.org/upp/trunk@2764 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- .../ProtectClientDemo/ProtectClientDemo.cpp | 107 ++++++++++++++++++ bazaar/ProtectClientDemo/ProtectClientDemo.h | 32 ++++++ .../ProtectClientDemo/ProtectClientDemo.lay | 20 ++++ .../ProtectClientDemo/ProtectClientDemo.upp | 15 +++ bazaar/ProtectClientDemo/init | 6 + .../ProtectServerDemo/ProtectServerDemo.upp | 11 ++ bazaar/ProtectServerDemo/main.cpp | 16 +++ 7 files changed, 207 insertions(+) create mode 100644 bazaar/ProtectClientDemo/ProtectClientDemo.cpp create mode 100644 bazaar/ProtectClientDemo/ProtectClientDemo.h create mode 100644 bazaar/ProtectClientDemo/ProtectClientDemo.lay create mode 100644 bazaar/ProtectClientDemo/ProtectClientDemo.upp create mode 100644 bazaar/ProtectClientDemo/init create mode 100644 bazaar/ProtectServerDemo/ProtectServerDemo.upp create mode 100644 bazaar/ProtectServerDemo/main.cpp diff --git a/bazaar/ProtectClientDemo/ProtectClientDemo.cpp b/bazaar/ProtectClientDemo/ProtectClientDemo.cpp new file mode 100644 index 000000000..ce3732016 --- /dev/null +++ b/bazaar/ProtectClientDemo/ProtectClientDemo.cpp @@ -0,0 +1,107 @@ +#include "ProtectClientDemo.h" + +static String DumpSpecial(String s) +{ + String out; + for(const char *p = s.Begin(), *e = s.End(); p < e; p++) + if((byte)*p >= ' ' && *p != '\xFF') + out.Cat(*p); + else { + switch(*p) { + case '\a': out.Cat("[\\a]"); break; + case '\b': out.Cat("[\\b]"); break; + case '\f': out.Cat("[\\f]"); break; + case '\v': out.Cat("[\\v]"); break; + case '\t': out.Cat("[\\t]"); break; + case '\r': out.Cat("[\\r]"); break; + case '\n': out.Cat("[\\n]\n"); break; + default: out.Cat(NFormat("[\\x%02x", (byte)*p)); break; + } + } + return out; +} + +ProtectClientDemo::ProtectClientDemo() +{ + CtrlLayout(*this, "Window title"); + + registerButton <<= THISBACK1(onAction, PROTECT_REGISTER); + connectButton <<= THISBACK1(onAction, PROTECT_CONNECT); + refreshButton <<= THISBACK1(onAction, PROTECT_REFRESH); + disconnectButton <<= THISBACK1(onAction, PROTECT_DISCONNECT); + getKeyButton <<= THISBACK1(onAction, PROTECT_GETKEY); + getInfoButton <<= THISBACK1(onAction, PROTECT_GETLICENSEINFO); + + quitButton <<= Breaker(); + +// urlEdit <<= "www.timberstruct.it/scgi/testing"; + urlEdit <<= "localhost/scgi/testing"; + keyEdit <<= "aabbccddeeff00112233445566778899"; + emailEdit <<= "demo@timberstruct.it"; + licenseIDEdit <<= "21309602655597975"; +} + +ProtectClientDemo::~ProtectClientDemo() +{ +} + +void ProtectClientDemo::onAction(int reason) +{ + // clear response text + responseText <<= ""; + + // setup client url and key + client.SetURL(urlEdit); + client.SetKey(ScanHexString(keyEdit)); + + // builds data vector map + VectorMap userData; + + userData.Add("EMAIL", ~emailEdit); + userData.Add("LICENSEID", ~licenseIDEdit); + + String res; + String key; + switch(reason) + { + case PROTECT_CONNECT : // establish connection to server + if(!client.Connect()) + res += "CONNECT ERROR\n"; + break; + case PROTECT_DISCONNECT : // frees server connection + if(!client.Disconnect()) + res += "DISCONNECT ERROR\n"; + break; + case PROTECT_REFRESH : // refreshes server connection (to restart timeout) + if(!client.Refresh()) + res += "REFRESH ERROR\n"; + break; + case PROTECT_GETKEY : // gets application key + key = client.GetKey(); + if(key == "") + res += "GETKEY ERROR\n"; + else + res += "GOT LICENSE KEY : '" + key + "'\n"; + break; + case PROTECT_REGISTER : // registers app for timed demo + if(!client.Register()) + res += "REGISTER ERROR\n"; + break; + case PROTECT_GETLICENSEINFO : // gets info about license (name, expiration date, app version....) + if(!client.GetLicenseInfo()) + res += "GETLICENSEINFO ERROR\n"; + break; + default: + break; + } + res += "Last server message : " + client.GetLastErrorMsg(); + + responseText <<= res; + +} + +GUI_APP_MAIN +{ + ProtectClientDemo().Run(); +} + diff --git a/bazaar/ProtectClientDemo/ProtectClientDemo.h b/bazaar/ProtectClientDemo/ProtectClientDemo.h new file mode 100644 index 000000000..1d43f9a52 --- /dev/null +++ b/bazaar/ProtectClientDemo/ProtectClientDemo.h @@ -0,0 +1,32 @@ +#ifndef _ProtectClientDemo_ProtectClientDemo_h +#define _ProtectClientDemo_ProtectClientDemo_h + +#include + +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +class ProtectClientDemo : public WithProtectClientDemoLayout +{ + private: + ProtectClient client; + + protected: + + virtual void onAction(int reason); + + public: + typedef ProtectClientDemo CLASSNAME; + + // constructor + ProtectClientDemo(); + + // destructor + ~ProtectClientDemo(); +}; + +#endif diff --git a/bazaar/ProtectClientDemo/ProtectClientDemo.lay b/bazaar/ProtectClientDemo/ProtectClientDemo.lay new file mode 100644 index 000000000..c41c0f709 --- /dev/null +++ b/bazaar/ProtectClientDemo/ProtectClientDemo.lay @@ -0,0 +1,20 @@ +LAYOUT(ProtectClientDemoLayout, 552, 416) + ITEM(LineEdit, responseText, SetEditable(false).SetFrame(NullFrame()).LeftPosZ(4, 544).TopPosZ(136, 276)) + ITEM(EditString, keyEdit, LeftPosZ(116, 432).TopPosZ(32, 19)) + ITEM(Button, quitButton, SetLabel(t_("Quit")).LeftPosZ(480, 68).TopPosZ(84, 20)) + ITEM(Label, dv___3, SetLabel(t_("Communication Key:")).LeftPosZ(4, 108).TopPosZ(32, 20)) + ITEM(EditString, urlEdit, LeftPosZ(116, 432).TopPosZ(8, 19)) + ITEM(Label, dv___5, SetLabel(t_("Server response :")).LeftPosZ(4, 256).TopPosZ(112, 20)) + ITEM(Label, dv___6, SetLabel(t_("Server Url :")).LeftPosZ(4, 108).TopPosZ(8, 20)) + ITEM(EditString, licenseIDEdit, LeftPosZ(344, 204).TopPosZ(56, 19)) + ITEM(Label, dv___8, SetLabel(t_("LicenseID :")).HSizePosZ(272, 212).TopPosZ(56, 20)) + ITEM(Label, dv___9, SetLabel(t_("EMail:")).LeftPosZ(4, 40).TopPosZ(56, 20)) + ITEM(EditString, emailEdit, LeftPosZ(52, 200).TopPosZ(56, 19)) + ITEM(Button, refreshButton, SetLabel(t_("Refresh")).LeftPosZ(156, 68).TopPosZ(84, 20)) + ITEM(Button, disconnectButton, SetLabel(t_("Disconnect")).LeftPosZ(232, 68).TopPosZ(84, 20)) + ITEM(Button, getInfoButton, SetLabel(t_("Get Info")).HSizePosZ(384, 100).TopPosZ(84, 20)) + ITEM(Button, registerButton, SetLabel(t_("Register")).LeftPosZ(4, 68).TopPosZ(84, 20)) + ITEM(Button, getKeyButton, SetLabel(t_("Get Key")).HSizePosZ(308, 176).TopPosZ(84, 20)) + ITEM(Button, connectButton, SetLabel(t_("Connect")).LeftPosZ(80, 68).TopPosZ(84, 20)) +END_LAYOUT + diff --git a/bazaar/ProtectClientDemo/ProtectClientDemo.upp b/bazaar/ProtectClientDemo/ProtectClientDemo.upp new file mode 100644 index 000000000..0ccffe1bf --- /dev/null +++ b/bazaar/ProtectClientDemo/ProtectClientDemo.upp @@ -0,0 +1,15 @@ +description "Web client for Protect web-authentication\377"; + +uses + CtrlLib, + Web, + Protect; + +file + ProtectClientDemo.h, + ProtectClientDemo.cpp, + ProtectClientDemo.lay; + +mainconfig + "" = "GUI"; + diff --git a/bazaar/ProtectClientDemo/init b/bazaar/ProtectClientDemo/init new file mode 100644 index 000000000..1993f5129 --- /dev/null +++ b/bazaar/ProtectClientDemo/init @@ -0,0 +1,6 @@ +#ifndef _ProtectClientDemo_icpp_init_stub +#define _ProtectClientDemo_icpp_init_stub +#include "CtrlLib/init" +#include "Web/init" +#include "Protect/init" +#endif diff --git a/bazaar/ProtectServerDemo/ProtectServerDemo.upp b/bazaar/ProtectServerDemo/ProtectServerDemo.upp new file mode 100644 index 000000000..a729a86a6 --- /dev/null +++ b/bazaar/ProtectServerDemo/ProtectServerDemo.upp @@ -0,0 +1,11 @@ +description "Protect server demo\377"; + +uses + Protect; + +file + main.cpp; + +mainconfig + "" = ""; + diff --git a/bazaar/ProtectServerDemo/main.cpp b/bazaar/ProtectServerDemo/main.cpp new file mode 100644 index 000000000..f54f8ff9e --- /dev/null +++ b/bazaar/ProtectServerDemo/main.cpp @@ -0,0 +1,16 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + ProtectServer server; + + // setup key + server.SetKey(ScanHexString("aabbccddeeff00112233445566778899")); + + // setup cypher + server.SetCypher(new Snow2); + + server.Run(); +}