• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  * Copyright (C) 2016 Mopria Alliance, Inc.
4  * Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef _IPP_HELPER_H_
20 #define _IPP_HELPER_H_
21 
22 #include "lib_wprint.h"
23 #include "ifc_printer_capabilities.h"
24 #include "ippstatus_capabilities.h"
25 #include "ippstatus.h"
26 #include "ifc_status_monitor.h"
27 #include "http.h"
28 #include "ipp.h"
29 #include "ifc_wprint.h"
30 
31 /* Default timeout for most operations */
32 #define DEFAULT_IPP_TIMEOUT (15 * 1000)
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif // __cplusplus
37 
38 /*
39  * Strcture of supported IPP versions
40  */
41 typedef struct ipp_version_supported_s {
42     unsigned char supportsIpp10;
43     unsigned char supportsIpp11;
44     unsigned char supportsIpp20;
45 } ipp_version_supported_t;
46 
47 /*
48  * Enumeration of IPP version states
49  */
50 typedef enum {
51     NEW_REQUEST_SEQUENCE,
52     IPP_VERSION_RESOLVED,
53     IPP_VERSION_UNSUPPORTED,
54 } ipp_version_state;
55 
56 #define IPP_SERVICE_ERROR_MAX_RETRIES 3
57 #define IPP_BAD_REQUEST_MAX_RETRIES 2
58 #define IPP_INTERNAL_ERROR_MAX_RETRIES 1
59 
60 extern const ifc_wprint_t *ipp_wprint_ifc;
61 
62 #define PAGE_STATUS_MAX 200
63 
64 /*
65  * Structure for supported media sizes
66  */
67 typedef struct media_supported_s {
68     // All supported media sizes
69     media_size_t media_size[PAGE_STATUS_MAX];
70 
71     // Index to entry in keyword trans table.
72     int idxKeywordTranTable[PAGE_STATUS_MAX];
73 } media_supported_t;
74 
75 /*
76  * Returns the status of a given printer
77  */
78 extern ipp_status_t get_PrinterState(http_t *http, char *printer_uri,
79         printer_state_dyn_t *printer_state_dyn, ipp_pstate_t *printer_state);
80 
81 /*
82  * Outputs printer state reasons int printer_state
83  */
84 extern void get_PrinterStateReason(ipp_t *response, ipp_pstate_t *printer_state,
85         printer_state_dyn_t *printer_state_dyn);
86 
87 /*
88  * Parses printer attributes from the IPP response and copies them to capabilities
89  */
90 extern void parse_printerAttributes(ipp_t *response, printer_capabilities_t *capabilities);
91 
92 /*
93  * Sets IPP version
94  */
95 extern status_t set_ipp_version(ipp_t *, char *, http_t *, ipp_version_state);
96 
97 /*
98  * Parses supported media from the IPP response and copies the list into capabilities
99  */
100 extern void parse_getMediaSupported(ipp_t *response, media_supported_t *media_supported,
101         printer_capabilities_t *capabilities);
102 
103 /*
104  * Logs printer capabilities
105  */
106 extern void debuglist_printerCapabilities(printer_capabilities_t *capabilities);
107 
108 /*
109  * Logs printer status
110  */
111 extern void debuglist_printerStatus(printer_state_dyn_t *printer_state_dyn);
112 
113 /*
114  * Logs an IPP attribute
115  */
116 extern void print_attr(ipp_attribute_t *attr);
117 
118 /*
119  * Returns index of the supported media size, else returns -1
120  */
121 extern int ipp_find_media_size(const char *ipp_media_keyword, media_size_t *media_size);
122 
123 /*
124  * Returns the PWG name of a media size given it's enumeration
125  */
126 extern const char *mapDFMediaToIPPKeyword(media_size_t media_size);
127 
128 /*
129  * Gets the requested resource from a printer
130  */
131 extern void getResourceFromURI(const char *uri, char *resource, int resourcelen);
132 
133 /*
134  * Set up a new CUPS connection. All parameters for connection should be in 'info' structure.
135  * The printer_uri is copied into the 'printer_uri' parameter.
136  *
137  * Returns (non-NULL) http session on success.
138  */
139 http_t *ipp_cups_connect(const wprint_connect_info_t *info, char *printer_uri,
140         unsigned int uriLength);
141 
142 /*
143  * Executes a CUPS request with the given ipp request structure
144  */
145 ipp_t *ipp_doCupsRequest(http_t *http, ipp_t *request, char *http_resource, char *printer_uri);
146 
147 #define IPP_PREFIX "ipp"
148 #define IPPS_PREFIX "ipps"
149 #define DEFAULT_IPP_URI_RESOURCE "/ipp/print"
150 
151 #ifdef __cplusplus
152 }
153 #endif // __cplusplus
154 
155 #endif // !_IPP_HELPER_H_
156