|
Bastien Nocera |
ad8c9b |
From fdf7b75f5fc8a9726db6756bcddff6aa74b42ba0 Mon Sep 17 00:00:00 2001
|
|
Bastien Nocera |
ad8c9b |
From: Till Kamppeter <till.kamppeter@gmail.com>
|
|
Bastien Nocera |
ad8c9b |
Date: Thu, 27 Aug 2009 09:07:49 +0200
|
|
Bastien Nocera |
ad8c9b |
Subject: [PATCH] Make discovery mode of bluetooth CUPS backend work with CUPS 1.4.0
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
The new CUPS 1.4.x does device discovery only for a given time frame
|
|
Bastien Nocera |
ad8c9b |
requested by the client (printer setup tool, "lpinfo" command). CUPS's
|
|
Bastien Nocera |
ad8c9b |
default for CUPS-1.3.x-ish requests without timeout specification
|
|
Bastien Nocera |
ad8c9b |
seems to be 10 seconds. CUPS starts all backends at once in the
|
|
Bastien Nocera |
ad8c9b |
beginning (in parallel) and kills every backend which remains running
|
|
Bastien Nocera |
ad8c9b |
at the end of the timeout. It accepts output from the backends
|
|
Bastien Nocera |
ad8c9b |
whenever it occurs not only when the backend finishes, so a backend
|
|
Bastien Nocera |
ad8c9b |
can search for printers infinitely long if it outputs every found
|
|
Bastien Nocera |
ad8c9b |
device immediately. Then all printers found during CUPS' timeout are
|
|
Bastien Nocera |
ad8c9b |
taken into account.
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
The bluetooth backend of 4.48 asks the Bluetooth daemon for printers
|
|
Bastien Nocera |
ad8c9b |
and collects results for 10 seconds and after that it outputs
|
|
Bastien Nocera |
ad8c9b |
them. This takes a total of 10.5 sec and so CUPS kills the backend
|
|
Bastien Nocera |
ad8c9b |
right before it answers (at least with the 10-second default timeout),
|
|
Bastien Nocera |
ad8c9b |
resulting in Bluetooth printers never being discovered by CUPS.
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
This change fixes it by making each new printer added to the list
|
|
Bastien Nocera |
ad8c9b |
being output immediately. Note that the list structure cannot be
|
|
Bastien Nocera |
ad8c9b |
removed from cups/main.c as otherwise we would get duplicate
|
|
Bastien Nocera |
ad8c9b |
listings. Also important is the addition of unbuffered output on
|
|
Bastien Nocera |
ad8c9b |
stdout.
|
|
Bastien Nocera |
ad8c9b |
---
|
|
Bastien Nocera |
ad8c9b |
ChangeLog | 2 +
|
|
Bastien Nocera |
ad8c9b |
cups/main.c | 63 +++++++++++++++++++++++-----------------------------------
|
|
Bastien Nocera |
ad8c9b |
2 files changed, 27 insertions(+), 38 deletions(-)
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
diff --git a/ChangeLog b/ChangeLog
|
|
Bastien Nocera |
ad8c9b |
index d06f494..6c170f6 100644
|
|
Bastien Nocera |
ad8c9b |
--- a/ChangeLog
|
|
Bastien Nocera |
ad8c9b |
+++ b/ChangeLog
|
|
Bastien Nocera |
ad8c9b |
@@ -1,3 +1,5 @@
|
|
Bastien Nocera |
ad8c9b |
+ver 4.51:
|
|
Bastien Nocera |
ad8c9b |
+ Make discovery mode of bluetooth CUPS backend work with CUPS 1.4.0.
|
|
Bastien Nocera |
ad8c9b |
ver 4.50:
|
|
Bastien Nocera |
ad8c9b |
Fix issue with missing manual pages in distribution.
|
|
Bastien Nocera |
ad8c9b |
Fix issue with the configuration and state directories.
|
|
Bastien Nocera |
ad8c9b |
diff --git a/cups/main.c b/cups/main.c
|
|
Bastien Nocera |
ad8c9b |
index da757b0..1bbc78c 100644
|
|
Bastien Nocera |
ad8c9b |
--- a/cups/main.c
|
|
Bastien Nocera |
ad8c9b |
+++ b/cups/main.c
|
|
Bastien Nocera |
ad8c9b |
@@ -185,6 +185,27 @@ static char *device_get_ieee1284_id(const char *adapter, const char *device)
|
|
Bastien Nocera |
ad8c9b |
return id;
|
|
Bastien Nocera |
ad8c9b |
}
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
+static void print_printer_details(const char *name, const char *bdaddr, const char *id)
|
|
Bastien Nocera |
ad8c9b |
+{
|
|
Bastien Nocera |
ad8c9b |
+ char *uri, *escaped;
|
|
Bastien Nocera |
ad8c9b |
+
|
|
Bastien Nocera |
ad8c9b |
+ escaped = g_strdelimit(g_strdup(name), "\"", '\'');
|
|
Bastien Nocera |
ad8c9b |
+ uri = g_strdup_printf("bluetooth://%c%c%c%c%c%c%c%c%c%c%c%c",
|
|
Bastien Nocera |
ad8c9b |
+ bdaddr[0], bdaddr[1],
|
|
Bastien Nocera |
ad8c9b |
+ bdaddr[3], bdaddr[4],
|
|
Bastien Nocera |
ad8c9b |
+ bdaddr[6], bdaddr[7],
|
|
Bastien Nocera |
ad8c9b |
+ bdaddr[9], bdaddr[10],
|
|
Bastien Nocera |
ad8c9b |
+ bdaddr[12], bdaddr[13],
|
|
Bastien Nocera |
ad8c9b |
+ bdaddr[15], bdaddr[16]);
|
|
Bastien Nocera |
ad8c9b |
+ printf("direct %s \"%s\" \"%s (Bluetooth)\"", uri, escaped, escaped);
|
|
Bastien Nocera |
ad8c9b |
+ if (id != NULL)
|
|
Bastien Nocera |
ad8c9b |
+ printf(" \"%s\"\n", id);
|
|
Bastien Nocera |
ad8c9b |
+ else
|
|
Bastien Nocera |
ad8c9b |
+ printf("\n");
|
|
Bastien Nocera |
ad8c9b |
+ g_free(escaped);
|
|
Bastien Nocera |
ad8c9b |
+ g_free(uri);
|
|
Bastien Nocera |
ad8c9b |
+}
|
|
Bastien Nocera |
ad8c9b |
+
|
|
Bastien Nocera |
ad8c9b |
static void add_device_to_list(const char *name, const char *bdaddr, const char *id)
|
|
Bastien Nocera |
ad8c9b |
{
|
|
Bastien Nocera |
ad8c9b |
struct cups_device *device;
|
|
Bastien Nocera |
ad8c9b |
@@ -212,27 +233,7 @@ static void add_device_to_list(const char *name, const char *bdaddr, const char
|
|
Bastien Nocera |
ad8c9b |
device->id = g_strdup(id);
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
device_list = g_slist_prepend(device_list, device);
|
|
Bastien Nocera |
ad8c9b |
-}
|
|
Bastien Nocera |
ad8c9b |
-
|
|
Bastien Nocera |
ad8c9b |
-static void print_printer_details(const char *name, const char *bdaddr, const char *id)
|
|
Bastien Nocera |
ad8c9b |
-{
|
|
Bastien Nocera |
ad8c9b |
- char *uri, *escaped;
|
|
Bastien Nocera |
ad8c9b |
-
|
|
Bastien Nocera |
ad8c9b |
- escaped = g_strdelimit(g_strdup(name), "\"", '\'');
|
|
Bastien Nocera |
ad8c9b |
- uri = g_strdup_printf("bluetooth://%c%c%c%c%c%c%c%c%c%c%c%c",
|
|
Bastien Nocera |
ad8c9b |
- bdaddr[0], bdaddr[1],
|
|
Bastien Nocera |
ad8c9b |
- bdaddr[3], bdaddr[4],
|
|
Bastien Nocera |
ad8c9b |
- bdaddr[6], bdaddr[7],
|
|
Bastien Nocera |
ad8c9b |
- bdaddr[9], bdaddr[10],
|
|
Bastien Nocera |
ad8c9b |
- bdaddr[12], bdaddr[13],
|
|
Bastien Nocera |
ad8c9b |
- bdaddr[15], bdaddr[16]);
|
|
Bastien Nocera |
ad8c9b |
- printf("direct %s \"%s\" \"%s (Bluetooth)\"", uri, escaped, escaped);
|
|
Bastien Nocera |
ad8c9b |
- if (id != NULL)
|
|
Bastien Nocera |
ad8c9b |
- printf(" \"%s\"\n", id);
|
|
Bastien Nocera |
ad8c9b |
- else
|
|
Bastien Nocera |
ad8c9b |
- printf("\n");
|
|
Bastien Nocera |
ad8c9b |
- g_free(escaped);
|
|
Bastien Nocera |
ad8c9b |
- g_free(uri);
|
|
Bastien Nocera |
ad8c9b |
+ print_printer_details(device->name, device->bdaddr, device->id);
|
|
Bastien Nocera |
ad8c9b |
}
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
static gboolean parse_device_properties(DBusMessageIter *reply_iter, char **name, char **bdaddr)
|
|
Bastien Nocera |
ad8c9b |
@@ -384,23 +385,6 @@ static void remote_device_found(const char *adapter, const char *bdaddr, const c
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
static void discovery_completed(void)
|
|
Bastien Nocera |
ad8c9b |
{
|
|
Bastien Nocera |
ad8c9b |
- GSList *l;
|
|
Bastien Nocera |
ad8c9b |
-
|
|
Bastien Nocera |
ad8c9b |
- for (l = device_list; l != NULL; l = l->next) {
|
|
Bastien Nocera |
ad8c9b |
- struct cups_device *device = (struct cups_device *) l->data;
|
|
Bastien Nocera |
ad8c9b |
-
|
|
Bastien Nocera |
ad8c9b |
- if (device->name == NULL)
|
|
Bastien Nocera |
ad8c9b |
- device->name = g_strdelimit(g_strdup(device->bdaddr), ":", '-');
|
|
Bastien Nocera |
ad8c9b |
- /* Give another try to getting an ID for the device */
|
|
Bastien Nocera |
ad8c9b |
- if (device->id == NULL)
|
|
Bastien Nocera |
ad8c9b |
- remote_device_found(NULL, device->bdaddr, device->name);
|
|
Bastien Nocera |
ad8c9b |
- print_printer_details(device->name, device->bdaddr, device->id);
|
|
Bastien Nocera |
ad8c9b |
- g_free(device->name);
|
|
Bastien Nocera |
ad8c9b |
- g_free(device->bdaddr);
|
|
Bastien Nocera |
ad8c9b |
- g_free(device->id);
|
|
Bastien Nocera |
ad8c9b |
- g_free(device);
|
|
Bastien Nocera |
ad8c9b |
- }
|
|
Bastien Nocera |
ad8c9b |
-
|
|
Bastien Nocera |
ad8c9b |
g_slist_free(device_list);
|
|
Bastien Nocera |
ad8c9b |
device_list = NULL;
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
@@ -638,6 +622,9 @@ int main(int argc, char *argv[])
|
|
Bastien Nocera |
ad8c9b |
/* Make sure status messages are not buffered */
|
|
Bastien Nocera |
ad8c9b |
setbuf(stderr, NULL);
|
|
Bastien Nocera |
ad8c9b |
|
|
Bastien Nocera |
ad8c9b |
+ /* Make sure output is not buffered */
|
|
Bastien Nocera |
ad8c9b |
+ setbuf(stdout, NULL);
|
|
Bastien Nocera |
ad8c9b |
+
|
|
Bastien Nocera |
ad8c9b |
/* Ignore SIGPIPE signals */
|
|
Bastien Nocera |
ad8c9b |
#ifdef HAVE_SIGSET
|
|
Bastien Nocera |
ad8c9b |
sigset(SIGPIPE, SIG_IGN);
|
|
Bastien Nocera |
ad8c9b |
--
|
|
Bastien Nocera |
ad8c9b |
1.6.3.3
|
|
Bastien Nocera |
ad8c9b |
|