cannot delete printer Signed-off-by:baozewei@huawei.com

Signed-off-by: b30052170 <baozewei@huawei.com>
This commit is contained in:
b30052170 2024-09-25 09:46:11 +08:00
parent 3aa0425490
commit 89eead7c0f
3 changed files with 5 additions and 51 deletions

View File

@ -97,8 +97,6 @@ public:
int32_t QueryPrinterAttrList(const std::string &printerName, const std::vector<std::string> &keyList,
std::vector<std::string> &valueList);
int32_t QueryPrinterInfoByPrinterId(const std::string& printerId, PrinterInfo &info);
int32_t DeletePrinterFromCups(const std::string &printerUri, const std::string &printerName,
const std::string &printerMake);
int32_t DiscoverUsbPrinters(std::vector<PrinterInfo> &printers);
int32_t QueryPrinterCapabilityFromPPD(const std::string &name, PrinterCapability &printerCaps);

View File

@ -558,51 +558,6 @@ int32_t PrintCupsClient::AddPrinterToCupsWithPpd(const std::string &printerUri,
return E_PRINT_NONE;
}
int32_t PrintCupsClient::DeletePrinterFromCups(const std::string &printerUri, const std::string &printerName,
const std::string &printerMake)
{
PRINT_HILOGD("PrintCupsClient DeletePrinterFromCups start, printerMake: %{public}s", printerMake.c_str());
ipp_t *request;
char uri[HTTP_MAX_URI] = {0};
std::vector<string> ppds;
std::string ppd = DEFAULT_PPD_NAME;
std::string standardName = PrintUtil::StandardizePrinterName(printerName);
ippSetPort(CUPS_SEVER_PORT);
QueryPPDInformation(printerMake.c_str(), ppds);
if (!ppds.empty()) {
ppd = ppds[0];
std::string serverBin = CUPS_ROOT_DIR + "/serverbin";
mode_t permissions = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH;
ChangeFilterPermission(serverBin, permissions);
}
PRINT_HILOGI("ppd driver: %{public}s", ppd.c_str());
if (!IsPrinterExist(printerUri.c_str(), standardName.c_str(), ppd.c_str())) {
PRINT_HILOGI("printer has not added");
return E_PRINT_NONE;
}
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
}
request = ippNewRequest(IPP_OP_CUPS_DELETE_PRINTER);
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s",
standardName.c_str());
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", NULL, standardName.c_str());
ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, printerUri.c_str());
ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "ppd-name", NULL, ppd.c_str());
PRINT_HILOGD("IPP_OP_CUPS_DELETE_PRINTER cupsDoRequest");
ippDelete(printAbility_->DoRequest(NULL, request, "/admin/"));
if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) {
PRINT_HILOGE("delete error: %s", cupsLastErrorString());
return E_PRINT_SERVER_FAILURE;
}
PRINT_HILOGI("delete success");
return E_PRINT_NONE;
}
int32_t PrintCupsClient::DeleteCupsPrinter(const char *printerName)
{
ipp_t *request;

View File

@ -2804,8 +2804,9 @@ int32_t PrintServiceAbility::DeletePrinterFromCups(
PRINT_HILOGD("DeletePrinterFromCups started.");
std::lock_guard<std::recursive_mutex> lock(apiMutex_);
#ifdef CUPS_ENABLE
std::string standardName = PrintUtil::StandardizePrinterName(printerName);
auto ret =
DelayedSingleton<PrintCupsClient>::GetInstance()->DeletePrinterFromCups(printerUri, printerName, printerMake);
DelayedSingleton<PrintCupsClient>::GetInstance()->DeleteCupsPrinter(standardName.c_str());
if (ret != E_PRINT_NONE) {
PRINT_HILOGW("DeletePrinterFromCups error = %{public}d.", ret);
return ret;
@ -3204,10 +3205,10 @@ bool PrintServiceAbility::RemoveVendorPrinterFromCups(const std::string &globalV
return false;
}
#ifdef CUPS_ENABLE
auto ret = DelayedSingleton<PrintCupsClient>::GetInstance()->DeletePrinterFromCups(cupsPrinter.uri,
cupsPrinter.name, cupsPrinter.maker);
std::string standardName = PrintUtil::StandardizePrinterName(cupsPrinter.name);
auto ret = DelayedSingleton<PrintCupsClient>::GetInstance()->DeleteCupsPrinter(standardName.c_str());
if (ret != E_PRINT_NONE) {
PRINT_HILOGW("DeletePrinterFromCups error = %{public}d.", ret);
PRINT_HILOGW("DeleteCupsPrinter error = %{public}d.", ret);
return false;
}
#endif // CUPS_ENABLE