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-xxx.patch CVE修复补丁 23- cups-x.x.x-source.tar.gz cups源码压缩tar包 24- backport-xxx.patch 上游更新补丁列表 25- cups-xxx.patch 上游更新补丁列表 26- cups.spec 上游更新记录说明 27- cups.yaml 上游yaml文件 28- ohos-xxx.patch 适配OpenHarmony编译补丁文件 29- cups_single_file.patch 适配OpenHarmony编译补丁文件 30- pthread_cancel.patch 适配OpenHarmony编译补丁文件 31- install.sh 适配OpenHarmony编译sh脚本文件 32- generate_mime_convs.py 适配OpenHarmony编译python脚本文件 33``` 34 35## 如何使用 36### 1、头文件引入 37```c 38#include <cups/cups-private.h> 39``` 40### 2、添加编译依赖 41在您的 bundle.json 文件 添加 42```json 43"deps": { 44 "third_party": [ 45 "cups" 46 ] 47} 48``` 49在您的BUILD.gn需要的地方添加依赖 50```json 51deps += [ "//third_party/cups:cups" ] 52``` 53### 3、接口使用示例 54```c 55// 使用CUPS接口查询打印机能力示例 56ipp_t *request; /* IPP Request */ 57ipp_t *response; /* IPP response */ 58http_t *http = NULL; 59char scheme[HTTP_MAX_URI]; // 协议类型 60char username[HTTP_MAX_URI]; // 请求用户名 61char host[HTTP_MAX_URI]; // 打印机ip 62int port; // 打印机端口 63// 声明需要查询哪些打印机能力,此处为所有 64static const char * const pattrs[] = { 65 "all" 66}; 67 68// 使用打印机ip和端口连接打印机 69http = httpConnect2(host, port, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, TIME_OUT, NULL); 70if (http == nullptr) { 71 return; 72} 73// 构造获取打印机能力的request 74request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES); 75// 指定请求uri 76ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printerUri.c_str()); 77// 指定请求的用户 78ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); 79// 指定请求哪些打印机属性 80ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", 81(int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs); 82// 调用CUPS接口发送ipp请求 83response = cupsDoRequest(http, request, "/"); 84// 处理请求结果 85if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) { 86 ippDelete(response); 87 return; 88} 89// 关闭http 90httpClose(http); 91``` 92 93### 相关仓 94[third_party_cups-filters](https://gitee.com/openharmony/third_party_cups-filters) 95 96[print_print_fwk](https://gitee.com/openharmony/print_print_fwk) 97 98### 参与贡献 99[如何贡献](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/参与贡献.md) 100 101[Commit message规范](https://gitee.com/openharmony/device_qemu/wikis/Commit%20message%E8%A7%84%E8%8C%83) 102 103