Reformatting.

This commit is contained in:
2019-08-23 13:27:30 +01:00
parent 03dba21ad4
commit 01dad2ee0a
42 changed files with 859 additions and 987 deletions

View File

@@ -18,27 +18,26 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Streams.hpp"
#include "IO.hpp"
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <cstdio>
#include <fcntl.h>
#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
using namespace std;
#ifdef DEBUG_STREAMS
FILE* initHTML(FILE *fPtr, const string &title);
void closeHTML(FILE *fPtr);
FILE* initHTML(FILE* fPtr, const string& title);
void closeHTML(FILE* fPtr);
#endif
shared_ptr<int> getHostDescriptor()
{
shared_ptr<int> getHostDescriptor() {
static shared_ptr<int> descriptor{};
descriptor.reset(new int{ open(HID_DEV, O_RDWR | O_NONBLOCK | O_APPEND) }, [](int* fd){
close(*fd);
delete fd;
descriptor.reset(new int{ open(HID_DEV, O_RDWR | O_NONBLOCK | O_APPEND) }, [](int* fd) {
close(*fd);
delete fd;
});
if (*descriptor == -1)
@@ -48,12 +47,12 @@ shared_ptr<int> getHostDescriptor()
}
#ifdef DEBUG_STREAMS
shared_ptr<FILE> getComHostStream()
{
static shared_ptr<FILE> stream{ fopen((cacheDirectory + "comhost.txt").c_str(), "wb"), [](FILE *f){
clog << "Closing comhost stream" << endl;
fclose(f);
} };
shared_ptr<FILE> getComHostStream() {
static shared_ptr<FILE> stream{ fopen((cacheDirectory + "comhost.txt").c_str(), "wb"),
[](FILE* f) {
clog << "Closing comhost stream" << endl;
fclose(f);
} };
if (!stream)
clog << "Stream is unavailable" << endl;
@@ -61,12 +60,14 @@ shared_ptr<FILE> getComHostStream()
return stream;
}
shared_ptr<FILE> getHostPacketStream()
{
static shared_ptr<FILE> stream{ initHTML(fopen((cacheDirectory + "hostpackets.html").c_str(), "wb"), "Host Packets"), [](FILE *f){
clog << "Closing hostPackets stream" << endl;
closeHTML(f);
} };
shared_ptr<FILE> getHostPacketStream() {
static shared_ptr<FILE> stream{
initHTML(fopen((cacheDirectory + "hostpackets.html").c_str(), "wb"), "Host Packets"),
[](FILE* f) {
clog << "Closing hostPackets stream" << endl;
closeHTML(f);
}
};
if (!stream)
clog << "Stream is unavailable" << endl;
@@ -74,12 +75,14 @@ shared_ptr<FILE> getHostPacketStream()
return stream;
}
shared_ptr<FILE> getHostAPDUStream()
{
static shared_ptr<FILE> stream{ initHTML(fopen((cacheDirectory + "hostAPDU.html").c_str(), "wb"), "Host APDU"), [](FILE *f){
clog << "Closing host APDU stream" << endl;
closeHTML(f);
} };
shared_ptr<FILE> getHostAPDUStream() {
static shared_ptr<FILE> stream{
initHTML(fopen((cacheDirectory + "hostAPDU.html").c_str(), "wb"), "Host APDU"),
[](FILE* f) {
clog << "Closing host APDU stream" << endl;
closeHTML(f);
}
};
if (!stream)
clog << "Stream is unavailable" << endl;
@@ -87,12 +90,12 @@ shared_ptr<FILE> getHostAPDUStream()
return stream;
}
shared_ptr<FILE> getComDevStream()
{
static shared_ptr<FILE> stream{ fopen((cacheDirectory + "comdev.txt").c_str(), "wb"), [](FILE *f){
clog << "Closing comdev stream" << endl;
fclose(f);
} };
shared_ptr<FILE> getComDevStream() {
static shared_ptr<FILE> stream{ fopen((cacheDirectory + "comdev.txt").c_str(), "wb"),
[](FILE* f) {
clog << "Closing comdev stream" << endl;
fclose(f);
} };
if (!stream)
clog << "Stream is unavailable" << endl;
@@ -100,12 +103,14 @@ shared_ptr<FILE> getComDevStream()
return stream;
}
shared_ptr<FILE> getDevPacketStream()
{
static shared_ptr<FILE> stream{ initHTML(fopen((cacheDirectory + "devpackets.html").c_str(), "wb"), "Dev Packets"), [](FILE *f){
clog << "Closing devPackets stream" << endl;
closeHTML(f);
} };
shared_ptr<FILE> getDevPacketStream() {
static shared_ptr<FILE> stream{
initHTML(fopen((cacheDirectory + "devpackets.html").c_str(), "wb"), "Dev Packets"),
[](FILE* f) {
clog << "Closing devPackets stream" << endl;
closeHTML(f);
}
};
if (!stream)
clog << "Stream is unavailable" << endl;
@@ -113,12 +118,13 @@ shared_ptr<FILE> getDevPacketStream()
return stream;
}
shared_ptr<FILE> getDevAPDUStream()
{
static shared_ptr<FILE> stream{ initHTML(fopen((cacheDirectory + "devAPDU.html").c_str(), "wb"), "Dev APDU"), [](FILE *f){
clog << "Closing dev APDU stream" << endl;
closeHTML(f);
} };
shared_ptr<FILE> getDevAPDUStream() {
static shared_ptr<FILE> stream{ initHTML(fopen((cacheDirectory + "devAPDU.html").c_str(), "wb"),
"Dev APDU"),
[](FILE* f) {
clog << "Closing dev APDU stream" << endl;
closeHTML(f);
} };
if (!stream)
clog << "Stream is unavailable" << endl;
@@ -126,54 +132,54 @@ shared_ptr<FILE> getDevAPDUStream()
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());
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)
{
void closeHTML(FILE* fPtr) {
fprintf(fPtr, "\t</body>\n"
"</html>");
"</html>");
fclose(fPtr);
}
#endif