Skip to content

Commit

Permalink
Add identify command
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Feb 3, 2024
1 parent 44df94e commit c55750c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/ippmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class IppMsg
MemberName = 0x4A
};

IppMsg() = delete;
IppMsg() = default;
IppMsg(Bytestream& msg);
IppMsg(uint16_t opOrStatus, IppAttrs opAttrs, IppAttrs jobAttrs=IppAttrs(),
uint8_t majVsn=1, uint8_t minVsn=1, IppAttrs printerAttrs=IppAttrs());
Expand Down Expand Up @@ -93,10 +93,10 @@ class IppMsg
void encodeAttribute(Bytestream& msg, std::string name, IppAttr attr, bool subCollection=false) const;
void encodeValue(Bytestream& msg, uint8_t tag, IppValue val) const;

uint16_t _opOrStatus;
uint16_t _opOrStatus = 0;

uint8_t _majVsn;
uint8_t _minVsn;
uint8_t _majVsn = 1;
uint8_t _minVsn = 1;

IppAttrs _opAttrs;
std::list<IppAttrs> _jobAttrs;
Expand Down
29 changes: 26 additions & 3 deletions lib/ippprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,34 @@ IppPrinter::IppPrinter(std::string addr) : _addr(addr)
}

Error IppPrinter::refresh()
{
IppMsg resp;
Error error = _doRequest(IppMsg::GetPrinterAttrs, resp);
_printerAttrs = resp.getPrinterAttrs();
return error;
}

bool IppPrinter::identifySupported()
{
return _printerAttrs.has("identify-actions-supported");
}

Error IppPrinter::identify()
{
if(!identifySupported())
{
return Error("Identify not supported.");
}
IppMsg resp;
Error error = _doRequest(IppMsg::IdentifyPrinter, resp);
return error;
}

Error IppPrinter::_doRequest(IppMsg::Operation op, IppMsg& resp)
{
Error error;
IppAttrs getPrinterAttrsJobAttrs = IppMsg::baseOpAttrs(_addr);
IppMsg getPrinterAttrsMsg(IppMsg::GetPrinterAttrs, getPrinterAttrsJobAttrs);
IppMsg getPrinterAttrsMsg(op, getPrinterAttrsJobAttrs);

CurlIppPoster getPrinterAttrsReq(_addr, getPrinterAttrsMsg.encode(), _ignoreSslErrors, _verbose);
Bytestream getPrinterAttrsResult;
Expand All @@ -19,8 +43,7 @@ Error IppPrinter::refresh()
{
try
{
IppMsg getPrinterAttrsResp(getPrinterAttrsResult);
_printerAttrs = getPrinterAttrsResp.getPrinterAttrs();
resp = IppMsg(getPrinterAttrsResult);
}
catch(const std::exception& e)
{
Expand Down
5 changes: 5 additions & 0 deletions lib/ippprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class IppPrinter
return IppPrintJob(_printerAttrs);
}

bool identifySupported();
Error identify();

private:
Error _doRequest(IppMsg::Operation op, IppMsg& resp);

std::string _addr;
bool _verbose = false;
bool _ignoreSslErrors = true;
Expand Down
11 changes: 11 additions & 0 deletions utils/ippclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ int main(int argc, char** argv)

SubArgGet args({{"get-attrs", {{&helpOpt, &verboseOpt},
{&addrArg}}},
{"identify", {{&helpOpt, &verboseOpt},
{&addrArg}}},
{"print", {{&helpOpt, &verboseOpt, &forceOpt, &oneStageOpt,
&pagesOpt, &copiesOpt, &collatedCopiesOpt, &paperSizeOpt,
&resolutionOpt, &resolutionXOpt, &resolutionYOpt,
Expand Down Expand Up @@ -202,6 +204,15 @@ int main(int argc, char** argv)
{
std::cout << printer.attributes();
}
else if(args.subCommand() == "identify")
{
error = printer.identify();
if(error)
{
std::cerr << "Identify failed: " << error.value() << std::endl;
return 1;
}
}
else if(args.subCommand() == "print")
{
IppPrintJob ip = printer.createJob();
Expand Down

0 comments on commit c55750c

Please sign in to comment.