summaryrefslogtreecommitdiff
path: root/modules/printbackends
diff options
context:
space:
mode:
authorMatthias Clasen <matthiasc@src.gnome.org>2007-01-03 20:34:00 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2007-01-03 20:34:00 +0000
commit5490174708db1e51784875162bad96e1740a69af (patch)
tree34aa71f800c11982c048bdbe59d6ed5ffe43580f /modules/printbackends
parent5349f6dd8d3cd8c3ed47df8a2c35749ae30c7ecd (diff)
downloadgtk+-5490174708db1e51784875162bad96e1740a69af.tar.gz
Cleanups
svn path=/trunk/; revision=17036
Diffstat (limited to 'modules/printbackends')
-rw-r--r--modules/printbackends/cups/gtkcupsutils.c146
-rw-r--r--modules/printbackends/cups/gtkprintbackendcups.c35
2 files changed, 103 insertions, 78 deletions
diff --git a/modules/printbackends/cups/gtkcupsutils.c b/modules/printbackends/cups/gtkcupsutils.c
index db790c89d5..eb5442c2a3 100644
--- a/modules/printbackends/cups/gtkcupsutils.c
+++ b/modules/printbackends/cups/gtkcupsutils.c
@@ -1,7 +1,7 @@
/* GTK - The GIMP Toolkit
* gtkcupsutils.h: Statemachine implementation of POST and GET
* cup calls which can be used to create a non-blocking cups API
- * Copyright (C) 2003, Red Hat, Inc.
+ * Copyright (C) 2006, 2007 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -118,7 +118,7 @@ gtk_cups_request_new (http_t *connection,
if (server)
request->server = g_strdup (server);
else
- request->server = g_strdup (cupsServer());
+ request->server = g_strdup (cupsServer ());
if (resource)
@@ -134,7 +134,9 @@ gtk_cups_request_new (http_t *connection,
else
{
request->http = NULL;
- request->http = httpConnectEncrypt (request->server, ippPort(), cupsEncryption());
+ request->http = httpConnectEncrypt (request->server,
+ ippPort (),
+ cupsEncryption ());
if (request->http)
httpBlocking (request->http, 0);
@@ -147,7 +149,7 @@ gtk_cups_request_new (http_t *connection,
request->attempts = 0;
request->data_io = data_io;
- request->ipp_request = ippNew();
+ request->ipp_request = ippNew ();
request->ipp_request->request.op.operation_id = operation_id;
request->ipp_request->request.op.request_id = 1;
@@ -163,7 +165,7 @@ gtk_cups_request_new (http_t *connection,
gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name",
- NULL, cupsUser());
+ NULL, cupsUser ());
cupsLangFree (language);
@@ -185,8 +187,10 @@ void
gtk_cups_request_free (GtkCupsRequest *request)
{
if (request->own_http)
- if (request->http)
- httpClose (request->http);
+ {
+ if (request->http)
+ httpClose (request->http);
+ }
if (request->ipp_request)
ippDelete (request->ipp_request);
@@ -203,9 +207,9 @@ gboolean
gtk_cups_request_read_write (GtkCupsRequest *request)
{
if (request->type == GTK_CUPS_POST)
- post_states[request->state](request);
+ post_states[request->state] (request);
else if (request->type == GTK_CUPS_GET)
- get_states[request->state](request);
+ get_states[request->state] (request);
if (request->attempts > _GTK_CUPS_MAX_ATTEMPTS &&
request->state != GTK_CUPS_REQUEST_DONE)
@@ -221,9 +225,7 @@ gtk_cups_request_read_write (GtkCupsRequest *request)
return TRUE;
}
else
- {
- return FALSE;
- }
+ return FALSE;
}
GtkCupsPollState
@@ -328,14 +330,14 @@ _find_option_tag (const gchar *option)
result = IPP_TAG_ZERO;
lower_bound = 0;
- upper_bound = num_options = (int)(sizeof(ipp_options) / sizeof(ipp_options[0])) - 1;
+ upper_bound = num_options = (int) G_N_ELEMENTS (ipp_options) - 1;
while (1)
{
int match;
current_option = (int) (((upper_bound - lower_bound) / 2) + lower_bound);
- match = strcasecmp(option, ipp_options[current_option].name);
+ match = strcasecmp (option, ipp_options[current_option].name);
if (match == 0)
{
result = ipp_options[current_option].value_tag;
@@ -376,8 +378,8 @@ gtk_cups_request_encode_option (GtkCupsRequest *request,
{
ipp_tag_t option_tag;
- g_assert (option != NULL);
- g_assert (value != NULL);
+ g_return_if_fail (option != NULL);
+ g_return_if_fail (value != NULL);
option_tag = _find_option_tag (option);
@@ -405,16 +407,18 @@ gtk_cups_request_encode_option (GtkCupsRequest *request,
case IPP_TAG_BOOLEAN:
{
char b;
- b = 0;
- if (!strcasecmp(value, "true") ||
- !strcasecmp(value, "on") ||
- !strcasecmp(value, "yes"))
+
+ if (strcasecmp (value, "true") == 0 ||
+ strcasecmp (value, "on") == 0 ||
+ strcasecmp (value, "yes") == 0)
b = 1;
-
- ippAddBoolean(request->ipp_request,
- IPP_TAG_JOB,
- option,
- b);
+ else
+ b = 0;
+
+ ippAddBoolean (request->ipp_request,
+ IPP_TAG_JOB,
+ option,
+ b);
break;
}
@@ -431,12 +435,12 @@ gtk_cups_request_encode_option (GtkCupsRequest *request,
s = (char *)value;
}
else
- lower = strtol(value, &s, 0);
+ lower = strtol (value, &s, 0);
if (*s == '-')
{
if (s[1])
- upper = strtol(s + 1, NULL, 0);
+ upper = strtol (s + 1, NULL, 0);
else
upper = 2147483647;
}
@@ -459,14 +463,14 @@ gtk_cups_request_encode_option (GtkCupsRequest *request,
int yres;
ipp_res_t units;
- xres = strtol(value, &s, 0);
+ xres = strtol (value, &s, 0);
if (*s == 'x')
- yres = strtol(s + 1, &s, 0);
+ yres = strtol (s + 1, &s, 0);
else
yres = xres;
- if (strcasecmp(s, "dpc") == 0)
+ if (strcasecmp (s, "dpc") == 0)
units = IPP_RES_PER_CM;
else
units = IPP_RES_PER_INCH;
@@ -569,7 +573,9 @@ _connect (GtkCupsRequest *request)
if (request->http == NULL)
{
- request->http = httpConnectEncrypt (request->server, ippPort(), cupsEncryption());
+ request->http = httpConnectEncrypt (request->server,
+ ippPort (),
+ cupsEncryption ());
if (request->http == NULL)
request->attempts++;
@@ -604,23 +610,21 @@ _post_send (GtkCupsRequest *request)
if (request->data_io != NULL)
{
fstat (g_io_channel_unix_get_fd (request->data_io), &data_info);
- sprintf (length, "%lu", (unsigned long)ippLength(request->ipp_request) + data_info.st_size);
+ sprintf (length, "%lu", (unsigned long) ippLength (request->ipp_request) + data_info.st_size);
}
else
- {
- sprintf (length, "%lu", (unsigned long)ippLength(request->ipp_request));
- }
+ sprintf (length, "%lu", (unsigned long) ippLength (request->ipp_request));
- httpClearFields(request->http);
- httpSetField(request->http, HTTP_FIELD_CONTENT_LENGTH, length);
- httpSetField(request->http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");
+ httpClearFields (request->http);
+ httpSetField (request->http, HTTP_FIELD_CONTENT_LENGTH, length);
+ httpSetField (request->http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");
#ifdef HAVE_HTTP_AUTHSTRING
- httpSetField(request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
+ httpSetField (request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
#endif
- if (httpPost(request->http, request->resource))
+ if (httpPost (request->http, request->resource))
{
- if (httpReconnect(request->http))
+ if (httpReconnect (request->http))
{
request->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
@@ -648,14 +652,16 @@ _post_write_request (GtkCupsRequest *request)
request->poll_state = GTK_CUPS_HTTP_WRITE;
- ipp_status = ippWrite(request->http, request->ipp_request);
+ ipp_status = ippWrite (request->http, request->ipp_request);
if (ipp_status == IPP_ERROR)
{
request->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
- gtk_cups_result_set_error (request->result, "%s",ippErrorString (cupsLastError ()));
+ gtk_cups_result_set_error (request->result,
+ "%s",
+ ippErrorString (cupsLastError ()));
return;
}
@@ -684,7 +690,7 @@ _post_write_data (GtkCupsRequest *request)
request->poll_state = GTK_CUPS_HTTP_WRITE;
if (httpCheck (request->http))
- http_status = httpUpdate(request->http);
+ http_status = httpUpdate (request->http);
else
http_status = request->last_status;
@@ -711,7 +717,9 @@ _post_write_data (GtkCupsRequest *request)
request->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
- gtk_cups_result_set_error (request->result, "Error reading from cache file: %s", error->message);
+ gtk_cups_result_set_error (request->result,
+ "Error reading from cache file: %s",
+ error->message);
g_error_free (error);
return;
@@ -727,15 +735,21 @@ _post_write_data (GtkCupsRequest *request)
#if HAVE_CUPS_API_1_2
- if (httpWrite2(request->http, buffer, bytes) < bytes)
+ if (httpWrite2 (request->http, buffer, bytes) < bytes)
#else
- if (httpWrite(request->http, buffer, (int) bytes) < bytes)
+ if (httpWrite (request->http, buffer, (int) bytes) < bytes)
#endif /* HAVE_CUPS_API_1_2 */
{
+ int http_errno;
+
+ http_errno = httpError (request->http);
+
request->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
- gtk_cups_result_set_error (request->result, "Error writting to socket in Post %s", strerror (httpError (request->http)));
+ gtk_cups_result_set_error (request->result,
+ "Error writing to socket in Post %s",
+ g_strerror (http_errno));
return;
}
}
@@ -803,7 +817,7 @@ _post_check (GtkCupsRequest *request)
httpReconnect (request->http);
/* Upgrade with encryption... */
- httpEncryption(request->http, HTTP_ENCRYPT_REQUIRED);
+ httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
request->attempts++;
goto again;
@@ -820,16 +834,18 @@ _post_check (GtkCupsRequest *request)
else
{
request->state = GTK_CUPS_POST_DONE;
- gtk_cups_result_set_error (request->result, "HTTP Error in POST %s", strerror (http_errno));
+ gtk_cups_result_set_error (request->result,
+ "HTTP Error in POST %s",
+ g_strerror (http_errno));
request->poll_state = GTK_CUPS_HTTP_IDLE;
- httpFlush(request->http);
+ httpFlush (request->http);
return;
}
request->poll_state = GTK_CUPS_HTTP_IDLE;
- httpFlush(request->http);
+ httpFlush (request->http);
request->last_status = HTTP_CONTINUE;
httpClose (request->http);
@@ -869,7 +885,8 @@ _post_read_response (GtkCupsRequest *request)
if (ipp_status == IPP_ERROR)
{
- gtk_cups_result_set_error (request->result, "%s", ippErrorString (cupsLastError()));
+ gtk_cups_result_set_error (request->result, "%s",
+ ippErrorString (cupsLastError ()));
ippDelete (request->result->ipp_response);
request->result->ipp_response = NULL;
@@ -894,21 +911,22 @@ _get_send (GtkCupsRequest *request)
if (request->data_io == NULL)
{
- gtk_cups_result_set_error (request->result, "Get requires an open io channel");
+ gtk_cups_result_set_error (request->result,
+ "Get requires an open io channel");
request->state = GTK_CUPS_GET_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
return;
}
- httpClearFields(request->http);
+ httpClearFields (request->http);
#ifdef HAVE_HTTP_AUTHSTRING
- httpSetField(request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
+ httpSetField (request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
#endif
- if (httpGet(request->http, request->resource))
+ if (httpGet (request->http, request->resource))
{
- if (httpReconnect(request->http))
+ if (httpReconnect (request->http))
{
request->state = GTK_CUPS_GET_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
@@ -965,7 +983,7 @@ _get_check (GtkCupsRequest *request)
httpReconnect (request->http);
/* Upgrade with encryption... */
- httpEncryption(request->http, HTTP_ENCRYPT_REQUIRED);
+ httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
request->attempts++;
goto again;
@@ -982,9 +1000,11 @@ _get_check (GtkCupsRequest *request)
else
{
request->state = GTK_CUPS_GET_DONE;
- gtk_cups_result_set_error (request->result, "HTTP Error in GET %s", strerror (http_errno));
+ gtk_cups_result_set_error (request->result,
+ "HTTP Error in GET %s",
+ g_strerror (http_errno));
request->poll_state = GTK_CUPS_HTTP_IDLE;
- httpFlush(request->http);
+ httpFlush (request->http);
return;
}
@@ -1030,9 +1050,9 @@ _get_read_data (GtkCupsRequest *request)
request->poll_state = GTK_CUPS_HTTP_READ;
#if HAVE_CUPS_API_1_2
- bytes = httpRead2(request->http, buffer, sizeof(buffer));
+ bytes = httpRead2 (request->http, buffer, sizeof (buffer));
#else
- bytes = httpRead(request->http, buffer, sizeof(buffer));
+ bytes = httpRead (request->http, buffer, sizeof (buffer));
#endif /* HAVE_CUPS_API_1_2 */
GTK_NOTE (PRINTING,
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
index 0002bd3403..631bca2603 100644
--- a/modules/printbackends/cups/gtkprintbackendcups.c
+++ b/modules/printbackends/cups/gtkprintbackendcups.c
@@ -1,7 +1,7 @@
/* GTK - The GIMP Toolkit
* gtkprintbackendcups.h: Default implementation of GtkPrintBackend
* for the Common Unix Print System (CUPS)
- * Copyright (C) 2003, Red Hat, Inc.
+ * Copyright (C) 2006, 2007 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -419,13 +419,15 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend,
NULL,
cups_printer->device_uri);
- gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION,
+ IPP_TAG_URI, "printer-uri",
NULL, cups_printer->printer_uri);
title = gtk_print_job_get_title (job);
if (title)
- gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
- title);
+ gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION,
+ IPP_TAG_NAME, "job-name",
+ NULL, title);
gtk_print_settings_foreach (settings, add_cups_options, request);
@@ -868,7 +870,7 @@ static void
cups_request_job_info (CupsJobPollData *data)
{
GtkCupsRequest *request;
- gchar *printer_uri;
+ gchar *job_uri;
request = gtk_cups_request_new (NULL,
GTK_CUPS_POST,
@@ -877,10 +879,10 @@ cups_request_job_info (CupsJobPollData *data)
NULL,
NULL);
- printer_uri = g_strdup_printf ("ipp://localhost/jobs/%d", data->job_id);
+ job_uri = g_strdup_printf ("ipp://localhost/jobs/%d", data->job_id);
gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "job-uri", NULL, printer_uri);
- g_free (printer_uri);
+ "job-uri", NULL, job_uri);
+ g_free (job_uri);
cups_request_execute (data->print_backend,
request,
@@ -959,7 +961,8 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
if (gtk_cups_result_is_error (result))
{
- g_warning ("Error getting printer list: %s", gtk_cups_result_get_error_string (result));
+ g_warning ("Error getting printer list: %s",
+ gtk_cups_result_get_error_string (result));
goto done;
}
@@ -992,13 +995,13 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
member_uris = NULL;
while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
{
- if (!strcmp (attr->name, "printer-name") &&
+ if (strcmp (attr->name, "printer-name") == 0 &&
attr->value_tag == IPP_TAG_NAME)
printer_name = attr->values[0].string.text;
- else if (!strcmp (attr->name, "printer-uri-supported") &&
+ else if (strcmp (attr->name, "printer-uri-supported") == 0 &&
attr->value_tag == IPP_TAG_URI)
printer_uri = attr->values[0].string.text;
- else if (!strcmp (attr->name, "member-uris") &&
+ else if (strcmp (attr->name, "member-uris") == 0 &&
attr->value_tag == IPP_TAG_URI)
member_uris = attr->values[0].string.text;
else
@@ -1071,14 +1074,14 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
resource);
#endif
- if (!strncmp (resource, "/printers/", 10))
+ if (strncmp (resource, "/printers/", 10) == 0)
{
cups_printer->ppd_name = g_strdup (resource + 10);
GTK_NOTE (PRINTING,
g_print ("CUPS Backend: Setting ppd name '%s' for printer/class '%s'\n", cups_printer->ppd_name, printer_name));
}
- gethostname (uri, sizeof(uri));
+ gethostname (uri, sizeof (uri));
if (strcasecmp (uri, hostname) == 0)
strcpy (hostname, "localhost");
@@ -1115,7 +1118,6 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
/* The ref is held by GtkPrintBackend, in add_printer() */
g_object_unref (printer);
-
if (attr == NULL)
break;
@@ -1153,6 +1155,7 @@ cups_request_printer_list (GtkPrintBackendCups *cups_backend)
return TRUE;
g_object_ref (cups_backend);
+
GDK_THREADS_LEAVE ();
cups_backend->list_printers_pending = TRUE;
@@ -1173,7 +1176,9 @@ cups_request_printer_list (GtkPrintBackendCups *cups_backend)
(GtkPrintCupsResponseCallbackFunc) cups_request_printer_list_cb,
request,
NULL);
+
GDK_THREADS_ENTER ();
+
g_object_unref (cups_backend);
return TRUE;