#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin_local.h"
using namespace ERUCES;
using namespace std;
string generateHiddenLink( string strServerName, long lPort, string strUsername, string strPassword );
int main()
{
string strServer = "localhost";
long nPort = 5050;
string strUser = "ls";
string strPswd = "password";
try
{
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strUser);
ctx->setPasswd(strPswd);
ctx->setMode(2);
conn->open(strServer, nPort, *ctx.operator->());
cout << "Connected to " << strServer << " as " << strUser
<< " at port " << nPort << endl;
TEAdminLocal adminlocal;
adminlocal.attachConnection(conn.operator->());
TEObjectContainer container;
_TESTD string strHL = generateHiddenLink( strServer, nPort, strUser, strPswd );
cout << "Hiddenlink: " << strHL << endl;
TESTR2UINT data1(_TESTD make_pair(strHL, -1));
container.add(&data1);
strHL = generateHiddenLink( strServer, nPort, strUser, strPswd );
cout << "Hiddenlink: " << strHL << endl;
TESTR2UINT data2(_TESTD make_pair(strHL, -1));
container.add(&data2);
adminlocal.getStatus(container, true);
cout << "Hiddenlink status were got." << endl;
uint32_t nStatus = static_cast<const TESTR2UINT*>(container[0])->getValue().second;
cout << "Status = " << nStatus << endl;
nStatus = static_cast<const TESTR2UINT*>(container[1])->getValue().second;
cout << "Status = " << nStatus << endl;
adminlocal.detachConnection();
conn->close();
cout << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}
string generateHiddenLink( string strServerName, long lPort, string strUsername, string strPassword )
{
string strHiddenLink = "";
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
conn->open(strServerName, lPort, strUsername, strPassword);
cout << "Connected to " << strServerName << " at " << lPort
<< " as " << strUsername << "\n" << endl;
TEAgentMatrix matrix;
string str1_1 = "test string (1, 1)";
matrix.setElement(1, 1, str1_1);
matrix.attachConnection(conn.operator->());
matrix.encrypt();
matrix.detachConnection();
matrix.setEncodeMode(true);
matrix.getHiddenLink(1, strHiddenLink);
conn->close();
cout << "Disconnected from " << strServerName << endl;
return strHiddenLink;
}