2
* Copyright (C) 2017 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#include <cups/cups.h>
18
#include <cups/http.h>
24
#include <QStringList>
26
/* From https://bugzilla.novell.com/show_bug.cgi?id=447444#c5
27
* We need to define a maximum length for strings to avoid cups
28
* thinking there are multiple lines.
30
#define CPH_STR_MAXLEN 512
32
/* This code is only a shim for systems not running the daemon provided by
33
cups-pk-helper. Once provided on all platforms, this code should be replaced
34
by proper dbus bindings, and subsequently be set on fire. */
36
/* TODO: rename to CupsPkHelperShim to emphasize its transient nature.
37
FIXME: set m_internalStatus to mutable and make most of the "is..." methods
43
explicit CupsPkHelper();
46
bool printerClassSetInfo(const QString &name, const QString &info);
47
bool printerClassSetOption(const QString &name, const QString &option,
48
const QStringList &values);
49
ppd_file_t* getPpdFile(const QString &name, const QString &instance) const;
50
cups_dest_t* getDest(const QString &name, const QString &instance) const;
52
QString getLastError() const;
62
bool sendNewPrinterClassRequest(const QString &printerName,
66
const QString &value);
67
static void addPrinterUri(ipp_t *request, const QString &name);
68
static void addRequestingUsername(ipp_t *request, const QString &username);
69
static const QString getResource(const CphResource &resource);
70
static bool isPrinterNameValid(const QString &name);
71
static void addClassUri(ipp_t *request, const QString &name);
72
static bool isStringValid(const QString &string,
73
const bool checkNull = false,
74
const int maxLength = 512);
75
static bool isStringPrintable(const QString &string, const bool checkNull,
78
QString preparePpdForOptions(const QString &ppdfile,
79
cups_option_t *options,
81
bool printerIsClass(const QString &name);
82
void setInternalStatus(const QString &status);
83
bool postRequest(ipp_t *request, const QString &file,
84
const CphResource &resource);
85
bool sendRequest(ipp_t *request, const CphResource &resource);
86
bool handleReply(ipp_t *reply);
87
bool isReplyOk(ipp_t *reply, bool deleteIfReplyNotOk);
88
void setErrorFromReply(ipp_t *reply);
91
ipp_status_t m_lastStatus = IPP_OK;
92
mutable QString m_internalStatus = QString::null;