• 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 
102 /*
103  * Logs printer capabilities
104  */
105 extern void debuglist_printerCapabilities(printer_capabilities_t *capabilities);
106 
107 /*
108  * Logs printer status
109  */
110 extern void debuglist_printerStatus(printer_state_dyn_t *printer_state_dyn);
111 
112 /*
113  * Logs an IPP attribute
114  */
115 extern void print_attr(ipp_attribute_t *attr);
116 
117 /*
118  * Returns index of the supported media size, else returns -1
119  */
120 extern int ipp_find_media_size(const char *ipp_media_keyword, media_size_t *media_size);
121 
122 /*
123  * Returns the PWG name of a media size given it's enumeration
124  */
125 extern const char *mapDFMediaToIPPKeyword(media_size_t media_size);
126 
127 /*
128  * Gets the requested resource from a printer
129  */
130 extern void getResourceFromURI(const char *uri, char *resource, int resourcelen);
131 
132 /*
133  * Set up a new CUPS connection. All parameters for connection should be in 'info' structure.
134  * The printer_uri is copied into the 'printer_uri' parameter.
135  *
136  * Returns (non-NULL) http session on success.
137  */
138 http_t *ipp_cups_connect(const wprint_connect_info_t *info, char *printer_uri,
139         unsigned int uriLength);
140 
141 /*
142  * Executes a CUPS request with the given ipp request structure
143  */
144 ipp_t *ipp_doCupsRequest(http_t *http, ipp_t *request, char *http_resource, char *printer_uri);
145 
146 #define IPP_PREFIX "ipp"
147 #define IPPS_PREFIX "ipps"
148 #define DEFAULT_IPP_URI_RESOURCE "/ipp/print"
149 
150 #ifdef __cplusplus
151 }
152 #endif // __cplusplus
153 
154 #endif // !_IPP_HELPER_H_
155