• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# CUPS
2## Introduction
3OpenPrinting CUPS is the most current version of CUPS, a standards-based, open source printing system for Linux® and other Unix®-like operating systems. CUPS supports printing to:
4- AirPrint™ and IPP Everywhere™ printers,
5- Network and local (USB) printers with Printer Applications, and
6- Network and local (USB) printers with (legacy) PPD-based printer drivers.
7
8You can also learn more about the CUPS project through [the official website](https://github.com/OpenPrinting/cups)
9
10## Background Brief
11In the process of OpenHarmony's southward ecological development, it is necessary to be compatible with printers in the stock market. The use of CUPS printing system can directly connect with most printers in the market, which also reduces the difficulty for printer manufacturers to adapt to OpenHarmony.
12
13## How to use
14### 1、Header file import
15```c
16#include <cups/cups-private.h>
17```
18### 2、Add Compilation Dependency
19Add in the bundle. json file
20```json
21"deps": {
22  "third_part": [
23    "cups"
24  ]
25}
26```
27Add dependencies where needed in BUILD.gn
28
29```json
30deps += [ "//third_party/cups:cups" ]
31```
32### 3、Example of interface usage
33```c
34// Example of using CUPS interface to query printer capabilities
35ipp_t *request; /* IPP Request */
36ipp_t *response; /* IPP response */
37http_t *http = NULL;
38char scheme[HTTP_MAX_URI]; // Protocol
39char username[HTTP_MAX_URI];
40char host[HTTP_MAX_URI];
41int port;
42// Declare which printer capabilities need to be queried, here are all
43static const char * const pattrs[] = {
44    "all"
45};
46
47// Connect to printer
48http = httpConnect2(host, port, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, TIME_OUT, NULL);
49if (http == nullptr) {
50    return;
51}
52request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
53ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printerUri.c_str());
54ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
55ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes",
56(int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
57response = cupsDoRequest(http, request, "/");
58// parse response
59if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) {
60    ippDelete(response);
61    return;
62}
63// close http
64httpClose(http);
65```
66
67#### Repositories Involved
68[third_party_cups-filters](https://gitee.com/openharmony/third_party_cups-filters)
69
70[print_print_fwk](https://gitee.com/openharmony/print_print_fwk)
71
72#### Contribution
73[How to involve](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/参与贡献.md)
74
75[Commit message spec](https://gitee.com/openharmony/device_qemu/wikis/Commit%20message%E8%A7%84%E8%8C%83)
76
77