2 * Copyright (C) 2006 John (J5) Palmieri <johnp@redhat.com>
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.
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.
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.
20 #ifndef __GTK_CUPS_UTILS_H__
21 #define __GTK_CUPS_UTILS_H__
24 #include <cups/cups.h>
25 #include <cups/language.h>
26 #include <cups/http.h>
31 typedef struct _GtkCupsRequest GtkCupsRequest;
32 typedef struct _GtkCupsResult GtkCupsResult;
33 typedef struct _GtkCupsConnectionTest GtkCupsConnectionTest;
41 GTK_CUPS_ERROR_GENERAL
52 * Direction we should be polling the http socket on.
53 * We are either reading or writting at each state.
54 * This makes it easy for mainloops to connect to poll.
65 GTK_CUPS_CONNECTION_AVAILABLE,
66 GTK_CUPS_CONNECTION_NOT_AVAILABLE,
67 GTK_CUPS_CONNECTION_IN_PROGRESS
68 } GtkCupsConnectionState;
72 GTK_CUPS_PASSWORD_NONE,
73 GTK_CUPS_PASSWORD_REQUESTED,
74 GTK_CUPS_PASSWORD_HAS,
75 GTK_CUPS_PASSWORD_APPLIED,
76 GTK_CUPS_PASSWORD_NOT_VALID
77 } GtkCupsPasswordState;
79 struct _GtkCupsRequest
81 GtkCupsRequestType type;
84 http_status_t last_status;
92 GtkCupsResult *result;
95 GtkCupsPollState poll_state;
101 gint need_password : 1;
102 gint need_auth_info : 1;
103 gchar **auth_info_required;
105 GtkCupsPasswordState password_state;
108 struct _GtkCupsConnectionTest
110 #ifdef HAVE_CUPS_API_1_2
111 GtkCupsConnectionState at_init;
112 http_addrlist_t *addrlist;
113 http_addrlist_t *current_addr;
114 http_addrlist_t *last_wrong_addr;
119 #define GTK_CUPS_REQUEST_START 0
120 #define GTK_CUPS_REQUEST_DONE 500
125 GTK_CUPS_POST_CONNECT = GTK_CUPS_REQUEST_START,
127 GTK_CUPS_POST_WRITE_REQUEST,
128 GTK_CUPS_POST_WRITE_DATA,
131 GTK_CUPS_POST_READ_RESPONSE,
132 GTK_CUPS_POST_DONE = GTK_CUPS_REQUEST_DONE
138 GTK_CUPS_GET_CONNECT = GTK_CUPS_REQUEST_START,
142 GTK_CUPS_GET_READ_DATA,
143 GTK_CUPS_GET_DONE = GTK_CUPS_REQUEST_DONE
146 GtkCupsRequest * gtk_cups_request_new_with_username (http_t *connection,
147 GtkCupsRequestType req_type,
151 const char *resource,
152 const char *username);
153 GtkCupsRequest * gtk_cups_request_new (http_t *connection,
154 GtkCupsRequestType req_type,
158 const char *resource);
159 void gtk_cups_request_ipp_add_string (GtkCupsRequest *request,
165 void gtk_cups_request_ipp_add_strings (GtkCupsRequest *request,
171 const char * const *values);
172 const char * gtk_cups_request_ipp_get_string (GtkCupsRequest *request,
175 gboolean gtk_cups_request_read_write (GtkCupsRequest *request);
176 GtkCupsPollState gtk_cups_request_get_poll_state (GtkCupsRequest *request);
177 void gtk_cups_request_free (GtkCupsRequest *request);
178 GtkCupsResult * gtk_cups_request_get_result (GtkCupsRequest *request);
179 gboolean gtk_cups_request_is_done (GtkCupsRequest *request);
180 void gtk_cups_request_encode_option (GtkCupsRequest *request,
183 gboolean gtk_cups_result_is_error (GtkCupsResult *result);
184 ipp_t * gtk_cups_result_get_response (GtkCupsResult *result);
185 GtkCupsErrorType gtk_cups_result_get_error_type (GtkCupsResult *result);
186 int gtk_cups_result_get_error_status (GtkCupsResult *result);
187 int gtk_cups_result_get_error_code (GtkCupsResult *result);
188 const char * gtk_cups_result_get_error_string (GtkCupsResult *result);
189 GtkCupsConnectionTest * gtk_cups_connection_test_new (const char *server);
190 GtkCupsConnectionState gtk_cups_connection_test_get_state (GtkCupsConnectionTest *test);
191 void gtk_cups_connection_test_free (GtkCupsConnectionTest *test);