diff --git a/src/ippmsg.cpp b/src/ippmsg.cpp index b0d6f93..bd6164b 100644 --- a/src/ippmsg.cpp +++ b/src/ippmsg.cpp @@ -1,16 +1,15 @@ #include "ippmsg.h" -#define MAJ_VSN 1 -#define MIN_VSN 1 - quint32 IppMsg::_reqid=1; IppMsg::IppMsg() { } -IppMsg::IppMsg(QJsonObject opAttrs, QJsonObject jobAttrs) +IppMsg::IppMsg(QJsonObject opAttrs, QJsonObject jobAttrs, quint8 majVsn, quint8 minVsn) { + _majVsn = majVsn; + _minVsn = minVsn; _opAttrs = opAttrs; _jobAttrs = QJsonArray {jobAttrs}; } @@ -25,11 +24,9 @@ IppMsg::IppMsg(QNetworkReply* resp) QByteArray tmp = resp->readAll(); Bytestream bts(tmp.constData(), tmp.length()); - quint8 majVsn; - quint8 minVsn; quint32 reqId; - bts >> majVsn >> minVsn >> _status >> reqId; + bts >> _majVsn >> _minVsn >> _status >> reqId; QJsonObject attrs; IppMsg::IppTag currentAttrType = IppTag::EndAttrs; @@ -295,7 +292,7 @@ QByteArray IppMsg::encode(Operation op) { Bytestream ipp; - ipp << quint8(MAJ_VSN) << quint8(MIN_VSN); + ipp << _majVsn << _minVsn; ipp << quint16(op); ipp << _reqid++; diff --git a/src/ippmsg.h b/src/ippmsg.h index 21f2c8e..8d7d9fc 100644 --- a/src/ippmsg.h +++ b/src/ippmsg.h @@ -67,7 +67,7 @@ public: explicit IppMsg(); explicit IppMsg(QNetworkReply* resp); - IppMsg(QJsonObject opAttrs, QJsonObject jobAttrs = QJsonObject()); + IppMsg(QJsonObject opAttrs, QJsonObject jobAttrs=QJsonObject(), quint8 majVsn=1, quint8 minVsn=1); IppMsg(const IppMsg& other) = default; ~IppMsg(); @@ -87,6 +87,9 @@ private: QString consume_attribute(QJsonObject& attrs, Bytestream& data); Bytestream encode_attr(quint8 tag, QString name, QJsonValueRef value); + quint8 _majVsn; + quint8 _minVsn; + QJsonObject _opAttrs; QJsonArray _jobAttrs; QJsonObject _printerAttrs; diff --git a/src/ippprinter.cpp b/src/ippprinter.cpp index c5e588a..3daa313 100644 --- a/src/ippprinter.cpp +++ b/src/ippprinter.cpp @@ -405,7 +405,7 @@ void IppPrinter::print(QJsonObject attrs, QString filename, qDebug() << "Final job attributes:" << attrs; - IppMsg job = IppMsg(o, attrs); + IppMsg job = mk_msg(o, attrs); QByteArray contents = job.encode(IppMsg::PrintJob); // Always convert images to get resizing if((mimeType == documentFormat) && !mimeType.contains("image")) @@ -541,3 +541,14 @@ QJsonValue IppPrinter::getAttrOrDefault(QJsonObject jobAttrs, QString name) return _attrs[name+"-default"].toObject()["value"]; } } + +IppMsg IppPrinter::mk_msg(QJsonObject opAttrs, QJsonObject jobAttrs) +{ + if(_attrs.contains("ipp-versions-supported") && + _attrs["ipp-versions-supported"].toObject()["value"].toArray().contains("2.0")) + { + qDebug() << "TWO-POINT-ZERO"; + return IppMsg(opAttrs, jobAttrs, 2, 0); + } + return IppMsg(opAttrs, jobAttrs); +} diff --git a/src/ippprinter.h b/src/ippprinter.h index 7ee6c57..8c9f6a6 100644 --- a/src/ippprinter.h +++ b/src/ippprinter.h @@ -79,6 +79,8 @@ private: QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name); + IppMsg mk_msg(QJsonObject opAttrs, QJsonObject jobAttrs=QJsonObject()); + QNetworkAccessManager* _nam; QNetworkAccessManager* _jobs_nam; QNetworkAccessManager* _job_cancel_nam;