README.OpenSource
README.md
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
README_zh.md
1# 三方开源软件CUPS
2## CUPS简介
3CUPS(Common Unix Printing System)是一种开源打印系统,现在由OpenPrinting组织维护。CUPS主要功能包括打印队列管理、打印驱动程序管理、网络打印支持等。CUPS支持多种打印协议,包括IPP(Internet Printing Protocol)、LPD(Line Printer Daemon Protocol)、AppSocket等。
4
5CUPS支持以下类型的打印机:
6- AirPrint和IPP Everywhere认证的打印机;
7- 带打印机应用程序的网络和USB打印机;
8- 基于PPD(PostScript Printer Definition)打印驱动程序的网络和本地(USB)打印机。
9
10您也可以通过[CUPS官网主页](https://github.com/OpenPrinting/cups)了解更多关于CUPS项目的信息。
11
12## 引入背景简述
13OpenHarmony南向生态发展过程中,需要对存量市场的打印机进行兼容。使用CUPS打印系统能直接对接市场上大部分的打印机,也减少了打印机驱动适配OpenHarmony系统的难度。
14
15## 目录结构
16```
17- LICENSE 版权文件
18- OAT.xml OAT.xml过滤配置文件
19- README.OpenSource 项目README.OpenSource文件
20- README.md 英文说明
21- README_zh.md 中文说明
22- backport-CVE-2022-26691.patch CVE修复补丁
23- backport-CVE-2023-32324.patch CVE修复补丁
24- backport-CVE-2023-34241.patch CVE修复补丁
25- cups-2.4.0-source.tar.gz cups2.4.0源码压缩tar包
26- backport-xxx.patch 上游更新补丁列表
27- cups-xxx.patch 上游更新补丁列表
28- cups.spec 上游更新记录说明
29- cups.yaml 上游yaml文件
30- cups_single_file.patch 适配OpenHarmony编译补丁文件
31- pthread_cancel.patch 适配OpenHarmony编译补丁文件
32- install.sh 适配OpenHarmony编译sh脚本文件
33- generate_mime_convs.py 适配OpenHarmony编译python脚本文件
34```
35
36## 如何使用
37### 1、头文件引入
38```c
39#include <cups/cups-private.h>
40```
41### 2、添加编译依赖
42在您的 bundle.json 文件 添加
43```json
44"deps": {
45 "third_part": [
46 "cups"
47 ]
48}
49```
50在您的BUILD.gn需要的地方添加依赖
51```json
52deps += [ "//third_party/cups:cups" ]
53```
54### 3、接口使用示例
55```c
56// 使用CUPS接口查询打印机能力示例
57ipp_t *request; /* IPP Request */
58ipp_t *response; /* IPP response */
59http_t *http = NULL;
60char scheme[HTTP_MAX_URI]; // 协议类型
61char username[HTTP_MAX_URI]; // 请求用户名
62char host[HTTP_MAX_URI]; // 打印机ip
63int port; // 打印机端口
64// 声明需要查询哪些打印机能力,此处为所有
65static const char * const pattrs[] = {
66 "all"
67};
68
69// 使用打印机ip和端口连接打印机
70http = httpConnect2(host, port, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, TIME_OUT, NULL);
71if (http == nullptr) {
72 return;
73}
74// 构造获取打印机能力的request
75request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
76// 指定请求uri
77ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printerUri.c_str());
78// 指定请求的用户
79ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
80// 指定请求哪些打印机属性
81ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes",
82(int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
83// 调用CUPS接口发送ipp请求
84response = cupsDoRequest(http, request, "/");
85// 处理请求结果
86if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) {
87 ippDelete(response);
88 return;
89}
90// 关闭http
91httpClose(http);
92```
93
94### 相关仓
95[third_party_cups-filters](https://gitee.com/openharmony/third_party_cups-filters)
96
97[print_print_fwk](https://gitee.com/openharmony/print_print_fwk)
98
99### 参与贡献
100[如何贡献](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/参与贡献.md)
101
102[Commit message规范](https://gitee.com/openharmony/device_qemu/wikis/Commit%20message%E8%A7%84%E8%8C%83)
103
104