Implemented authentication.
Near feature complete.
This commit is contained in:
88
Streams.cpp
88
Streams.cpp
@@ -3,6 +3,9 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
FILE* initHTML(FILE *fPtr, const string &title);
|
||||
void closeHTML(FILE *fPtr);
|
||||
|
||||
shared_ptr<FILE> getHostStream()
|
||||
{
|
||||
static shared_ptr<FILE> stream{ fopen("/dev/hidg0", "ab+"), [](FILE *f){
|
||||
@@ -30,9 +33,22 @@ shared_ptr<FILE> getComHostStream()
|
||||
|
||||
shared_ptr<FILE> getHostPacketStream()
|
||||
{
|
||||
static shared_ptr<FILE> stream{ fopen("hostpackets.txt", "wb"), [](FILE *f){
|
||||
static shared_ptr<FILE> stream{ initHTML(fopen("hostpackets.html", "wb"), "Host Packets"), [](FILE *f){
|
||||
clog << "Closing hostPackets stream" << endl;
|
||||
fclose(f);
|
||||
closeHTML(f);
|
||||
} };
|
||||
|
||||
if (!stream)
|
||||
clog << "Stream is unavailable" << endl;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
shared_ptr<FILE> getHostAPDUStream()
|
||||
{
|
||||
static shared_ptr<FILE> stream{ initHTML(fopen("hostAPDU.html", "wb"), "Host APDU"), [](FILE *f){
|
||||
clog << "Closing host APDU stream" << endl;
|
||||
closeHTML(f);
|
||||
} };
|
||||
|
||||
if (!stream)
|
||||
@@ -56,9 +72,9 @@ shared_ptr<FILE> getComDevStream()
|
||||
|
||||
shared_ptr<FILE> getDevPacketStream()
|
||||
{
|
||||
static shared_ptr<FILE> stream{ fopen("devpackets.txt", "wb"), [](FILE *f){
|
||||
static shared_ptr<FILE> stream{ initHTML(fopen("devpackets.html", "wb"), "Dev Packets"), [](FILE *f){
|
||||
clog << "Closing devPackets stream" << endl;
|
||||
fclose(f);
|
||||
closeHTML(f);
|
||||
} };
|
||||
|
||||
if (!stream)
|
||||
@@ -66,3 +82,67 @@ shared_ptr<FILE> getDevPacketStream()
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
shared_ptr<FILE> getDevAPDUStream()
|
||||
{
|
||||
static shared_ptr<FILE> stream{ initHTML(fopen("devAPDU.html", "wb"), "Dev APDU"), [](FILE *f){
|
||||
clog << "Closing dev APDU stream" << endl;
|
||||
closeHTML(f);
|
||||
} };
|
||||
|
||||
if (!stream)
|
||||
clog << "Stream is unavailable" << endl;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
FILE* initHTML(FILE *fPtr, const string &title)
|
||||
{
|
||||
fprintf(fPtr, "<html>\n"
|
||||
"\t<head>\n"
|
||||
"\t\t<title>%s</title>\n"
|
||||
"\t\t<style>\n"
|
||||
"\t\t\ttable {\n"
|
||||
"\t\t\t\tdisplay: table;\n"
|
||||
"\t\t\t\twidth: 100%;\n"
|
||||
"\t\t\t\tborder-collapse: collapse;\n"
|
||||
"\t\t\t\tbox-sizing: border-box;\n"
|
||||
"\t\t\t}\n"
|
||||
"\n"
|
||||
"\t\t\tth.data {\n"
|
||||
"\t\t\t\ttext-align: left;\n"
|
||||
"\t\t\t}\n"
|
||||
"\n"
|
||||
"\t\t\ttd {\n"
|
||||
"\t\t\t\tfont-family: \"Courier New\", Courier, monospace;\n"
|
||||
"\t\t\t\twhite-space: pre;\n"
|
||||
"\t\t\t}\n"
|
||||
"\n"
|
||||
"\t\t\ttd.data {\n"
|
||||
"\t\t\t\toverflow: hidden;\n"
|
||||
"\t\t\t\ttext-overflow: ellipsis;\n"
|
||||
"\t\t\t\tmax-width:1px;\n"
|
||||
"\t\t\t\twidth:100%;\n"
|
||||
"\t\t\t}\n"
|
||||
"\n"
|
||||
"\t\t\ttd.data:hover {\n"
|
||||
"\t\t\t\twhite-space: pre-wrap;\n"
|
||||
"\t\t\t}\n"
|
||||
"\n"
|
||||
"\t\t\ttable, th, td {\n"
|
||||
"\t\t\t\tborder: 1px solid black;\n"
|
||||
"\t\t\t}\n"
|
||||
"\t\t</style>\n"
|
||||
"\t</head>\n"
|
||||
"\n"
|
||||
"\t<body>", title.c_str());
|
||||
|
||||
return fPtr;
|
||||
}
|
||||
|
||||
void closeHTML(FILE *fPtr)
|
||||
{
|
||||
fprintf(fPtr, "\t</body>\n"
|
||||
"</html>");
|
||||
fclose(fPtr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user