mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
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:
parent
86b495890e
commit
331ba759e2
7 changed files with 207 additions and 0 deletions
107
bazaar/ProtectClientDemo/ProtectClientDemo.cpp
Normal file
107
bazaar/ProtectClientDemo/ProtectClientDemo.cpp
Normal 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();
|
||||
}
|
||||
|
||||
32
bazaar/ProtectClientDemo/ProtectClientDemo.h
Normal file
32
bazaar/ProtectClientDemo/ProtectClientDemo.h
Normal 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
|
||||
20
bazaar/ProtectClientDemo/ProtectClientDemo.lay
Normal file
20
bazaar/ProtectClientDemo/ProtectClientDemo.lay
Normal 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
|
||||
|
||||
15
bazaar/ProtectClientDemo/ProtectClientDemo.upp
Normal file
15
bazaar/ProtectClientDemo/ProtectClientDemo.upp
Normal 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";
|
||||
|
||||
6
bazaar/ProtectClientDemo/init
Normal file
6
bazaar/ProtectClientDemo/init
Normal 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
|
||||
11
bazaar/ProtectServerDemo/ProtectServerDemo.upp
Normal file
11
bazaar/ProtectServerDemo/ProtectServerDemo.upp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
description "Protect server demo\377";
|
||||
|
||||
uses
|
||||
Protect;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
16
bazaar/ProtectServerDemo/main.cpp
Normal file
16
bazaar/ProtectServerDemo/main.cpp
Normal 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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue