mirror of
https://github.com/akuker/RASCSI.git
synced 2026-04-25 14:26:28 +00:00
Added rascsi filter to limit logging to a particular device (#978)
* Support for ID and LUN parameter for the -L option in rascsi * Added DeviceLogger class * Removed dupiicate code * Fixed SonarQube issues * Added unit tests, improved code sharing * Fixed regression (#979)
This commit is contained in:
@@ -29,7 +29,6 @@
|
||||
// With STOP PRINT printing can be cancelled before SYNCHRONIZE BUFFER was sent.
|
||||
//
|
||||
|
||||
#include "shared/log.h"
|
||||
#include "shared/rascsi_exceptions.h"
|
||||
#include "scsi_command_util.h"
|
||||
#include "scsi_printer.h"
|
||||
@@ -41,6 +40,11 @@ using namespace filesystem;
|
||||
using namespace scsi_defs;
|
||||
using namespace scsi_command_util;
|
||||
|
||||
SCSIPrinter::SCSIPrinter(int lun) : PrimaryDevice(SCLP, lun)
|
||||
{
|
||||
SupportsParams(true);
|
||||
}
|
||||
|
||||
bool SCSIPrinter::Init(const unordered_map<string, string>& params)
|
||||
{
|
||||
PrimaryDevice::Init(params);
|
||||
@@ -57,7 +61,7 @@ bool SCSIPrinter::Init(const unordered_map<string, string>& params)
|
||||
AddCommand(scsi_command::eCmdSendDiagnostic, [this] { SendDiagnostic(); });
|
||||
|
||||
if (GetParam("cmd").find("%f") == string::npos) {
|
||||
LOGERROR("Missing filename specifier %%f")
|
||||
GetLogger().Trace("Missing filename specifier %f");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,7 +69,6 @@ bool SCSIPrinter::Init(const unordered_map<string, string>& params)
|
||||
file_template = temp_directory_path(error); //NOSONAR Publicly writable directory is fine here
|
||||
file_template += PRINTER_FILE_PATTERN;
|
||||
|
||||
SupportsParams(true);
|
||||
SetReady(true);
|
||||
|
||||
return true;
|
||||
@@ -86,11 +89,11 @@ void SCSIPrinter::Print()
|
||||
{
|
||||
const uint32_t length = GetInt24(GetController()->GetCmd(), 2);
|
||||
|
||||
LOGTRACE("Receiving %d byte(s) to be printed", length)
|
||||
GetLogger().Trace("Receiving " + to_string(length) + " byte(s) to be printed");
|
||||
|
||||
if (length > GetController()->GetBuffer().size()) {
|
||||
LOGERROR("%s", ("Transfer buffer overflow: Buffer size is " + to_string(GetController()->GetBuffer().size()) +
|
||||
" bytes, " + to_string(length) + " bytes expected").c_str())
|
||||
GetLogger().Error("Transfer buffer overflow: Buffer size is " + to_string(GetController()->GetBuffer().size()) +
|
||||
" bytes, " + to_string(length) + " bytes expected");
|
||||
|
||||
throw scsi_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_CDB);
|
||||
}
|
||||
@@ -104,7 +107,7 @@ void SCSIPrinter::Print()
|
||||
void SCSIPrinter::SynchronizeBuffer()
|
||||
{
|
||||
if (!out.is_open()) {
|
||||
LOGWARN("Nothing to print")
|
||||
GetLogger().Warn("Nothing to print");
|
||||
|
||||
throw scsi_exception(sense_key::ABORTED_COMMAND);
|
||||
}
|
||||
@@ -116,12 +119,12 @@ void SCSIPrinter::SynchronizeBuffer()
|
||||
|
||||
error_code error;
|
||||
|
||||
LOGTRACE("Printing file '%s' with %s byte(s)", filename.c_str(), to_string(file_size(path(filename), error)).c_str())
|
||||
GetLogger().Trace("Printing file '" + filename + "' with " + to_string(file_size(path(filename), error)) + " byte(s)");
|
||||
|
||||
LOGDEBUG("Executing '%s'", cmd.c_str())
|
||||
GetLogger().Debug("Executing '" + cmd + "'");
|
||||
|
||||
if (system(cmd.c_str())) {
|
||||
LOGERROR("Printing file '%s' failed, the printing system might not be configured", filename.c_str())
|
||||
GetLogger().Error("Printing file '" + filename + "' failed, the printing system might not be configured");
|
||||
|
||||
Cleanup();
|
||||
|
||||
@@ -142,7 +145,7 @@ bool SCSIPrinter::WriteByteSequence(vector<uint8_t>& buf, uint32_t length)
|
||||
// There is no C++ API that generates a file with a unique name
|
||||
const int fd = mkstemp(f.data());
|
||||
if (fd == -1) {
|
||||
LOGERROR("Can't create printer output file for pattern '%s': %s", filename.c_str(), strerror(errno))
|
||||
GetLogger().Error("Can't create printer output file for pattern '" + filename + "': " + strerror(errno));
|
||||
return false;
|
||||
}
|
||||
close(fd);
|
||||
@@ -154,10 +157,10 @@ bool SCSIPrinter::WriteByteSequence(vector<uint8_t>& buf, uint32_t length)
|
||||
throw scsi_exception(sense_key::ABORTED_COMMAND);
|
||||
}
|
||||
|
||||
LOGTRACE("Created printer output file '%s'", filename.c_str())
|
||||
GetLogger().Trace("Created printer output file '" + filename + "'");
|
||||
}
|
||||
|
||||
LOGTRACE("Appending %d byte(s) to printer output file '%s'", length, filename.c_str())
|
||||
GetLogger().Trace("Appending " + to_string(length) + " byte(s) to printer output file ''" + filename + "'");
|
||||
|
||||
out.write((const char*)buf.data(), length);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user