]> Pileus Git - ~andy/gtk/blob - modules/printbackends/cups/gtkcupsutils.h
Bug 424207 – printing hangs on unreachable cups server
[~andy/gtk] / modules / printbackends / cups / gtkcupsutils.h
1 /* gtkcupsutils.h 
2  * Copyright (C) 2006 John (J5) Palmieri <johnp@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19  
20 #ifndef __GTK_CUPS_UTILS_H__
21 #define __GTK_CUPS_UTILS_H__
22
23 #include <glib.h>
24 #include <cups/cups.h>
25 #include <cups/language.h>
26 #include <cups/http.h>
27 #include <cups/ipp.h>
28
29 G_BEGIN_DECLS
30
31 typedef struct _GtkCupsRequest        GtkCupsRequest;
32 typedef struct _GtkCupsResult         GtkCupsResult;
33 typedef struct _GtkCupsConnectionTest GtkCupsConnectionTest;
34
35 typedef enum
36 {
37   GTK_CUPS_ERROR_HTTP,
38   GTK_CUPS_ERROR_IPP,
39   GTK_CUPS_ERROR_IO,
40   GTK_CUPS_ERROR_GENERAL
41 } GtkCupsErrorType;
42
43 typedef enum
44 {
45   GTK_CUPS_POST,
46   GTK_CUPS_GET
47 } GtkCupsRequestType;
48
49
50 /** 
51  * Direction we should be polling the http socket on.
52  * We are either reading or writting at each state.
53  * This makes it easy for mainloops to connect to poll.
54  */
55 typedef enum
56 {
57   GTK_CUPS_HTTP_IDLE,
58   GTK_CUPS_HTTP_READ,
59   GTK_CUPS_HTTP_WRITE
60 } GtkCupsPollState;
61
62
63 struct _GtkCupsRequest 
64 {
65   GtkCupsRequestType type;
66
67   http_t *http;
68   http_status_t last_status;
69   ipp_t *ipp_request;
70
71   gchar *server;
72   gchar *resource;
73   GIOChannel *data_io;
74   gint attempts;
75
76   GtkCupsResult *result;
77
78   gint state;
79   GtkCupsPollState poll_state;
80
81   gint own_http : 1; 
82 };
83
84 struct _GtkCupsConnectionTest
85 {
86   http_addrlist_t *addrlist;
87   http_addrlist_t *current_addr;
88   gboolean         success_at_init;
89   gint             socket;
90 };
91
92 #define GTK_CUPS_REQUEST_START 0
93 #define GTK_CUPS_REQUEST_DONE 500
94
95 /* POST states */
96 enum 
97 {
98   GTK_CUPS_POST_CONNECT = GTK_CUPS_REQUEST_START,
99   GTK_CUPS_POST_SEND,
100   GTK_CUPS_POST_WRITE_REQUEST,
101   GTK_CUPS_POST_WRITE_DATA,
102   GTK_CUPS_POST_CHECK,
103   GTK_CUPS_POST_READ_RESPONSE,
104   GTK_CUPS_POST_DONE = GTK_CUPS_REQUEST_DONE
105 };
106
107 /* GET states */
108 enum
109 {
110   GTK_CUPS_GET_CONNECT = GTK_CUPS_REQUEST_START,
111   GTK_CUPS_GET_SEND,
112   GTK_CUPS_GET_CHECK,
113   GTK_CUPS_GET_READ_DATA,
114   GTK_CUPS_GET_DONE = GTK_CUPS_REQUEST_DONE
115 };
116
117 GtkCupsRequest        * gtk_cups_request_new                         (http_t             *connection,
118                                                                       GtkCupsRequestType  req_type,
119                                                                       gint                operation_id,
120                                                                       GIOChannel         *data_io,
121                                                                       const char         *server,
122                                                                       const char         *resource);
123 void                    gtk_cups_request_ipp_add_string              (GtkCupsRequest     *request,
124                                                                       ipp_tag_t           group,
125                                                                       ipp_tag_t           tag,
126                                                                       const char         *name,
127                                                                       const char         *charset,
128                                                                       const char         *value);
129 void                    gtk_cups_request_ipp_add_strings             (GtkCupsRequest     *request,
130                                                                       ipp_tag_t           group,
131                                                                       ipp_tag_t           tag,
132                                                                       const char         *name,
133                                                                       int                 num_values,
134                                                                       const char         *charset,
135                                                                       const char * const *values);
136 gboolean                gtk_cups_request_read_write                  (GtkCupsRequest     *request);
137 GtkCupsPollState        gtk_cups_request_get_poll_state              (GtkCupsRequest     *request);
138 void                    gtk_cups_request_free                        (GtkCupsRequest     *request);
139 GtkCupsResult         * gtk_cups_request_get_result                  (GtkCupsRequest     *request);
140 gboolean                gtk_cups_request_is_done                     (GtkCupsRequest     *request);
141 void                    gtk_cups_request_encode_option               (GtkCupsRequest     *request,
142                                                                       const gchar        *option,
143                                                                       const gchar        *value);
144 gboolean                gtk_cups_result_is_error                     (GtkCupsResult      *result);
145 ipp_t                 * gtk_cups_result_get_response                 (GtkCupsResult      *result);
146 GtkCupsErrorType        gtk_cups_result_get_error_type               (GtkCupsResult      *result);
147 int                     gtk_cups_result_get_error_status             (GtkCupsResult      *result);
148 int                     gtk_cups_result_get_error_code               (GtkCupsResult      *result);
149 const char            * gtk_cups_result_get_error_string             (GtkCupsResult      *result);
150 GtkCupsConnectionTest * gtk_cups_connection_test_new                 (const char            *server);
151 gboolean                gtk_cups_connection_test_is_server_available (GtkCupsConnectionTest *test);
152 void                    gtk_cups_connection_test_free                (GtkCupsConnectionTest *test);
153
154 G_END_DECLS
155 #endif