json server for js

This commit is contained in:
Owen Smith 2012-11-20 19:57:32 -05:00
parent 9991143fc6
commit 352dfbda3a
2 changed files with 28 additions and 11 deletions

View File

@ -54,12 +54,22 @@ int main(int argc, char** argv) {
getline(cin,s);
getline(cin,card);
client.getSalt(s);
s = SHA1Hash(s+"balls").toHex();
s = SHA1Hash(s+"PSK").toHex();
client.associateHashWithName(s, card, user);
break;
}
case 2: {
cout << "Not implemented.\n";
uint64_t upc;
cout << "UPC: ";
cin >> upc;
int32_t price;
cout << "price: ";
cin >> price;
client.getSalt(s);
s = SHA1Hash(s+"PSK").toHex();
client.setUPCPrice(s, upc, price);
break;
}
case 3: {
@ -79,10 +89,10 @@ int main(int argc, char** argv) {
break;
}
client.getSalt(s);
s = SHA1Hash(s+"balls").toHex();
s = SHA1Hash(s+"PSK").toHex();
client.doTransactionOnName(s, user, -price);
client.getSalt(s);
s = SHA1Hash(s+"balls").toHex();
s = SHA1Hash(s+"PSK").toHex();
client.doStockChange(s, upc, -1);
balance = client.getNameAccountBalance(user);
cout << "\tNew balance is " << (double)balance/100.0f << ".\n";
@ -96,7 +106,7 @@ int main(int argc, char** argv) {
cout << "Amount to change balance by in dollars: ";
cin >> delta;
client.getSalt(s);
s = SHA1Hash(s+"balls").toHex();
s = SHA1Hash(s+"PSK").toHex();
client.doTransactionOnName(s, user, (int)(100.0*delta));
break;
}
@ -115,7 +125,7 @@ int main(int argc, char** argv) {
cout << "Price: ";
cin >> f;
client.getSalt(s);
s = SHA1Hash(s+"balls").toHex();
s = SHA1Hash(s+"PSK").toHex();
client.setUPCPrice(s, upc, (int32_t)(f*100.0));
break;
}
@ -128,7 +138,7 @@ int main(int argc, char** argv) {
for (uint32_t i =0; i < 5000; i++) {
std::string s;
client.getSalt(s);
s = SHA1Hash(s + "balls").toHex();
s = SHA1Hash(s + "PSK").toHex();
client.doTransactionOnName(s, "j3parker", 1);
}

View File

@ -3,11 +3,13 @@
#include "PosBookie.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TNonblockingServer.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/THttpServer.h>
#include "Pos.h"
#include <thrift/protocol/TJSONProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
@ -67,7 +69,7 @@ class PosBookieHandler : virtual public PosBookieIf {
}
E_PURCHASE_STATUS::type purchaseItems(const std::string& auth, const std::string& dataToHash, const std::vector<int64_t> & upcs) {
if(saltStore->consumeKey(auth)) {
if(saltStore->consumeKey(auth)) {
try {
int32_t total_price = 0;
std::vector<int64_t>::const_iterator i;
@ -76,7 +78,7 @@ class PosBookieHandler : virtual public PosBookieIf {
}
int32_t accountBalance = this->client->getHashAccountBalance(dataToHash);
if(accountBalance < total_price) {
if(accountBalance > total_price) {
this->client->doTransactionOnHash(this->getAuthString(), dataToHash, total_price * -1);
return E_PURCHASE_STATUS::EPS_SUCCESS;
}
@ -132,9 +134,14 @@ int main(int argc, char **argv) {
shared_ptr<PosBookieHandler> handler(new PosBookieHandler((char*)server_host, server_port, saltStore));
shared_ptr<TProcessor> processor(new PosBookieProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(listen_port));
shared_ptr<TTransportFactory> transportFactory(new THttpServerTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TJSONProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
TNonblockingServer server(processor, listen_port);
server.serve();
delete saltStore;
return 0;
}