Home | History | Annotate | Download | only in ipphelper
      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 #define DEFAULT_IPP_TIMEOUT 15.0
     32 
     33 #ifdef __cplusplus
     34 extern "C" {
     35 #endif // __cplusplus
     36 
     37 /*
     38  * Strcture of supported IPP versions
     39  */
     40 typedef struct ipp_version_supported_s {
     41     unsigned char supportsIpp10;
     42     unsigned char supportsIpp11;
     43     unsigned char supportsIpp20;
     44 } ipp_version_supported_t;
     45 
     46 /*
     47  * Enumeration of IPP version states
     48  */
     49 typedef enum {
     50     NEW_REQUEST_SEQUENCE,
     51     IPP_VERSION_RESOLVED,
     52     IPP_VERSION_UNSUPPORTED,
     53 } ipp_version_state;
     54 
     55 #define IPP_SERVICE_ERROR_MAX_RETRIES 3
     56 #define IPP_BAD_REQUEST_MAX_RETRIES 2
     57 #define IPP_INTERNAL_ERROR_MAX_RETRIES 1
     58 
     59 extern const ifc_wprint_t *ipp_wprint_ifc;
     60 
     61 #define PAGE_STATUS_MAX 200
     62 
     63 /*
     64  * Structure for supported media sizes
     65  */
     66 typedef struct media_supported_s {
     67     // All supported media sizes
     68     media_size_t media_size[PAGE_STATUS_MAX];
     69 
     70     // Index to entry in keyword trans table.
     71     int idxKeywordTranTable[PAGE_STATUS_MAX];
     72 } media_supported_t;
     73 
     74 /*
     75  * Returns the status of a given printer
     76  */
     77 extern ipp_status_t get_PrinterState(http_t *http, char *printer_uri,
     78         printer_state_dyn_t *printer_state_dyn, ipp_pstate_t *printer_state);
     79 
     80 /*
     81  * Outputs printer state reasons int printer_state
     82  */
     83 extern void get_PrinterStateReason(ipp_t *response, ipp_pstate_t *printer_state,
     84         printer_state_dyn_t *printer_state_dyn);
     85 
     86 /*
     87  * Parses printer attributes from the IPP response and copies them to capabilities
     88  */
     89 extern void parse_printerAttributes(ipp_t *response, printer_capabilities_t *capabilities);
     90 
     91 /*
     92  * Sets IPP version
     93  */
     94 extern status_t set_ipp_version(ipp_t *, char *, http_t *, ipp_version_state);
     95 
     96 /*
     97  * Parses supported media from the IPP response and copies the list into capabilities
     98  */
     99 extern void parse_getMediaSupported(ipp_t *response, media_supported_t *media_supported,
    100         printer_capabilities_t *capabilities);
    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 DEFAULT_IPP_URI_RESOURCE "/ipp/print"
    148 
    149 #ifdef __cplusplus
    150 }
    151 #endif // __cplusplus
    152 
    153 #endif // !_IPP_HELPER_H_