starting some test client code, minor changes
This commit is contained in:
parent
ef1f25e9b3
commit
8cf07b67ae
|
@ -1,4 +1,8 @@
|
|||
a.out
|
||||
db
|
||||
*.swp
|
||||
|
||||
*.o
|
||||
*.d
|
||||
dump
|
||||
client
|
||||
server
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# POS
|
||||
|
||||
CXX = g++
|
||||
CXX = @g++
|
||||
ifndef NDEBUG
|
||||
CXXFLAGS = -g -O0 -Wall -I/users/m4burns/thrift/include/thrift -I. -Igen-cpp
|
||||
else
|
||||
|
@ -17,12 +17,13 @@ DEPS = $(patsubst %.c,%.d,$(CPPDEPS))
|
|||
|
||||
SERVER = server
|
||||
CLIENT = client
|
||||
DUMP = dump
|
||||
|
||||
##################################################################
|
||||
|
||||
.PHONY : all clean
|
||||
|
||||
all : $(SERVER) $(CLIENT)
|
||||
all : $(SERVER) $(CLIENT) $(DUMP)
|
||||
|
||||
%.d : %.cpp
|
||||
$(CXX) -MM $(CXXFLAGS) $^ > $@
|
||||
|
@ -46,6 +47,9 @@ $(SERVER) : $(OBJECTS) gen-cpp/Pos_server.skeleton.o
|
|||
$(CLIENT) : $(OBJECTS) client.o
|
||||
$(CXX) $(CXXFLAGS) $(OBJECTS) client.o -o $@ $(LDFLAGS)
|
||||
|
||||
$(DUMP) : $(OBJECTS) dump.o
|
||||
$(CXX) $(CXXFLAGS) $(OBJECTS) dump.o -o $@ $(LDFLAGS)
|
||||
|
||||
#################################################################
|
||||
|
||||
clean :
|
||||
|
|
|
@ -17,23 +17,75 @@ using namespace pos;
|
|||
using namespace boost;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
|
||||
shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
||||
if (argc != 2) {
|
||||
cout << "Usage: client <host>\n";
|
||||
exit(1);
|
||||
}
|
||||
shared_ptr<TTransport> socket(new TSocket(argv[1], 9090));
|
||||
shared_ptr<TTransport> transport(new TFramedTransport(socket));
|
||||
shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
||||
PosClient client(protocol);
|
||||
|
||||
try {
|
||||
transport->open();
|
||||
|
||||
client.ping();
|
||||
std::string s;
|
||||
client.getSalt(s);
|
||||
cout << (s = SHA1Hash(s + "balls").toHex()) << "\n";
|
||||
cout << s << " " << client.associateHashWithName(s, "dongs dongs dongs", "m4burns") << "\n";
|
||||
} catch(TException & e) {
|
||||
std::cerr << e.what() << "\n";
|
||||
}
|
||||
|
||||
string s;
|
||||
while(1) {
|
||||
uint32_t in;
|
||||
std::cout << "(0) Exit\n(1) Add card to member\n(2) Register new product\n(3) Buy a product\n(4) Deposit money\n(5) Print balance\n> ";
|
||||
std::cin >> in;
|
||||
switch(in) {
|
||||
case 0: exit(0);
|
||||
case 1: {
|
||||
string user, card;
|
||||
cout << "Username: ";
|
||||
cin >> user;
|
||||
cout << "Swipe card: ";
|
||||
getline(cin,s);
|
||||
getline(cin,card);
|
||||
client.getSalt(s);
|
||||
s = SHA1Hash(s+"balls").toHex();
|
||||
client.associateHashWithName(s, card, user);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
string user;
|
||||
int32_t delta;
|
||||
cout << "Username: ";
|
||||
cin >> user;
|
||||
cout << "Amount to change balance by: ";
|
||||
cin >> delta;
|
||||
client.getSalt(s);
|
||||
s = SHA1Hash(s+"balls").toHex();
|
||||
client.doTransactionOnHash(s, user, delta);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
string user;
|
||||
cout << "Username: ";
|
||||
cin >> user;
|
||||
cout << "$" << client.getNameAccountBalance(user) << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (uint32_t i =0; i < 5000; i++) {
|
||||
std::string s;
|
||||
client.getSalt(s);
|
||||
s = SHA1Hash(s + "balls").toHex();
|
||||
client.doTransactionOnName(s, "j3parker", 1);
|
||||
}
|
||||
|
||||
|
||||
cout << "j3parker balance: " << client.getNameAccountBalance("j3parker") << "\n";
|
||||
cout << "m4burns balance: " << client.getNameAccountBalance("m4burns") << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ std::string DbIf::getSalt() {
|
|||
fclose(rand_in);
|
||||
|
||||
// zero-terminated strings suck
|
||||
for(int i=0;i<salt_size;++i)
|
||||
for(unsigned int i=0;i<salt_size;++i)
|
||||
if(bfr[i] == 0)
|
||||
bfr[i] = 1;
|
||||
bfr[salt_size-1] = 0;
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <protocol/TBinaryProtocol.h>
|
||||
#include <transport/TSocket.h>
|
||||
#include <transport/TTransportUtils.h>
|
||||
#include "Pos.h"
|
||||
#include "sha1.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace apache::thrift;
|
||||
using namespace apache::thrift::protocol;
|
||||
using namespace apache::thrift::transport;
|
||||
|
||||
using namespace pos;
|
||||
|
||||
using namespace boost;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "Usage: dump <host>\n";
|
||||
exit(1);
|
||||
}
|
||||
shared_ptr<TTransport> socket(new TSocket(argv[1], 9090));
|
||||
shared_ptr<TTransport> transport(new TFramedTransport(socket));
|
||||
shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
||||
PosClient client(protocol);
|
||||
|
||||
try {
|
||||
transport->open();
|
||||
} catch(TException & e) {
|
||||
std::cerr << e.what() << "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
vector<string> data;
|
||||
client.toString(data);
|
||||
for (uint32_t i = 0; i < data.size(); i++) {
|
||||
cout << data[i] << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
|
|||
*/
|
||||
if (lenW) {
|
||||
int left = 64 - lenW;
|
||||
if (len < left)
|
||||
if (len < (unsigned long)left)
|
||||
left = len;
|
||||
memcpy(lenW + (char *)ctx->W, data, left);
|
||||
lenW = (lenW + left) & 63;
|
||||
|
|
|
@ -12,6 +12,7 @@ std::string NameServer::get_name (uint32_t id) {
|
|||
return "???";
|
||||
}
|
||||
cache[pwd->pw_name] = id;
|
||||
std::cerr << "Did reverse LDAP lookup on " << pwd->pw_name << "\n";
|
||||
return pwd->pw_name;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue