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
This commit is contained in:
micio 2010-10-10 12:30:49 +00:00
parent 86b495890e
commit 331ba759e2
7 changed files with 207 additions and 0 deletions

View file

@ -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<String, Value> 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();
}

View file

@ -0,0 +1,32 @@
#ifndef _ProtectClientDemo_ProtectClientDemo_h
#define _ProtectClientDemo_ProtectClientDemo_h
#include <CtrlLib/CtrlLib.h>
#include <Protect/ProtectClient.h>
using namespace Upp;
#define LAYOUTFILE <ProtectClientDemo/ProtectClientDemo.lay>
#include <CtrlCore/lay.h>
class ProtectClientDemo : public WithProtectClientDemoLayout<TopWindow>
{
private:
ProtectClient client;
protected:
virtual void onAction(int reason);
public:
typedef ProtectClientDemo CLASSNAME;
// constructor
ProtectClientDemo();
// destructor
~ProtectClientDemo();
};
#endif

View file

@ -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

View file

@ -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";

View file

@ -0,0 +1,6 @@
#ifndef _ProtectClientDemo_icpp_init_stub
#define _ProtectClientDemo_icpp_init_stub
#include "CtrlLib/init"
#include "Web/init"
#include "Protect/init"
#endif

View file

@ -0,0 +1,11 @@
description "Protect server demo\377";
uses
Protect;
file
main.cpp;
mainconfig
"" = "";

View file

@ -0,0 +1,16 @@
#include <Protect/ProtectServer.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
ProtectServer server;
// setup key
server.SetKey(ScanHexString("aabbccddeeff00112233445566778899"));
// setup cypher
server.SetCypher(new Snow2);
server.Run();
}