From bc085054220d80e9308fe5f4c2260e7ccc06e7e3 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 2 May 2004 03:36:18 +0000 Subject: Add Bluetooth backend for CUPS --- cups/spp.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 cups/spp.c (limited to 'cups/spp.c') diff --git a/cups/spp.c b/cups/spp.c new file mode 100644 index 00000000..ec8fcdd5 --- /dev/null +++ b/cups/spp.c @@ -0,0 +1,103 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2003-2004 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS + * SOFTWARE IS DISCLAIMED. + * + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include +#include + +int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) +{ + struct sockaddr_rc addr; + unsigned char buf[2048]; + int i, sk, len; + + if ((sk = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { + perror("ERROR: Can't create socket"); + return 1; + } + + addr.rc_family = AF_BLUETOOTH; + bacpy(&addr.rc_bdaddr, src); + addr.rc_channel = 0; + + if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + perror("ERROR: Can't bind socket"); + close(sk); + return 1; + } + + addr.rc_family = AF_BLUETOOTH; + bacpy(&addr.rc_bdaddr, dst); + addr.rc_channel = channel; + + if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + perror("ERROR: Can't connect to device"); + close(sk); + return 1; + } + + /* Ignore SIGTERM signals if printing from stdin */ + if (fd == 0) { +#ifdef HAVE_SIGSET + sigset(SIGTERM, SIG_IGN); +#elif defined(HAVE_SIGACTION) + memset(&action, 0, sizeof(action)); + sigemptyset(&action.sa_mask); + action.sa_handler = SIG_IGN; + sigaction(SIGTERM, &action, NULL); +#else + signal(SIGTERM, SIG_IGN); +#endif /* HAVE_SIGSET */ + } + + for (i = 0; i < copies; i++) { + + if (fd != 0) { + fprintf(stderr, "PAGE: 1 1\n"); + lseek(fd, 0, SEEK_SET); + } + + while ((len = read(fd, buf, sizeof(buf))) > 0) { + write(sk, buf, len); + } + + } + + close(sk); + + return 0; +} -- cgit From 632a9432774ff3a0c6e556e8f32a565b38890767 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 29 Oct 2005 22:36:31 +0000 Subject: Big cleanup of CVS relics --- cups/spp.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'cups/spp.c') diff --git a/cups/spp.c b/cups/spp.c index ec8fcdd5..3f3f1431 100644 --- a/cups/spp.c +++ b/cups/spp.c @@ -2,28 +2,23 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2003-2004 Marcel Holtmann + * Copyright (C) 2003-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY - * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, - * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS - * SOFTWARE IS DISCLAIMED. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * - * $Id$ */ #ifdef HAVE_CONFIG_H -- cgit From f2e48c44a7e4c9ee31b8ce2e302186f6047cfeab Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 3 Jan 2006 13:28:56 +0000 Subject: Update copyright information --- cups/spp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cups/spp.c') diff --git a/cups/spp.c b/cups/spp.c index 3f3f1431..968cd61e 100644 --- a/cups/spp.c +++ b/cups/spp.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2003-2005 Marcel Holtmann + * Copyright (C) 2003-2006 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From b102348e988e4abc5d579ce13c067ce2c885aaf7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 26 Jul 2006 13:32:44 +0000 Subject: Fix declared with attribute warn_unused_result errors --- cups/spp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cups/spp.c') diff --git a/cups/spp.c b/cups/spp.c index 968cd61e..0350280b 100644 --- a/cups/spp.c +++ b/cups/spp.c @@ -38,7 +38,7 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) { struct sockaddr_rc addr; unsigned char buf[2048]; - int i, sk, len; + int i, sk, err, len; if ((sk = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { perror("ERROR: Can't create socket"); @@ -87,7 +87,7 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) } while ((len = read(fd, buf, sizeof(buf))) > 0) { - write(sk, buf, len); + err = write(sk, buf, len); } } -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- cups/spp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cups/spp.c') diff --git a/cups/spp.c b/cups/spp.c index 0350280b..993bca2a 100644 --- a/cups/spp.c +++ b/cups/spp.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2003-2006 Marcel Holtmann + * Copyright (C) 2003-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 69f9e21b46e2827a24cad0436d52a47fdd4ee36a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 6 Mar 2008 10:46:26 +0000 Subject: Fix CUPS error and state reporting --- cups/spp.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'cups/spp.c') diff --git a/cups/spp.c b/cups/spp.c index 993bca2a..8bb9c1dc 100644 --- a/cups/spp.c +++ b/cups/spp.c @@ -65,6 +65,8 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) return 1; } + fputs("STATE: -connecting-to-device\n", stderr); + /* Ignore SIGTERM signals if printing from stdin */ if (fd == 0) { #ifdef HAVE_SIGSET @@ -88,6 +90,11 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) while ((len = read(fd, buf, sizeof(buf))) > 0) { err = write(sk, buf, len); + if (err < 0) { + perror("ERROR: Error writing to device"); + close(sk); + return 1; + } } } -- cgit From a71ed7ebdf0599e0a019c9087669a62e026109a2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 14 Mar 2008 14:21:01 +0000 Subject: Add CLASS support and retry on unavailable printers --- cups/spp.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'cups/spp.c') diff --git a/cups/spp.c b/cups/spp.c index 8bb9c1dc..cd9bfd58 100644 --- a/cups/spp.c +++ b/cups/spp.c @@ -34,7 +34,9 @@ #include #include -int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) +#include "cups.h" + +int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies, const char *cups_class) { struct sockaddr_rc addr; unsigned char buf[2048]; @@ -42,7 +44,10 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) if ((sk = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { perror("ERROR: Can't create socket"); - return 1; + if (cups_class) + return CUPS_BACKEND_FAILED; + else + return CUPS_BACKEND_RETRY; } addr.rc_family = AF_BLUETOOTH; @@ -52,7 +57,10 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { perror("ERROR: Can't bind socket"); close(sk); - return 1; + if (cups_class) + return CUPS_BACKEND_FAILED; + else + return CUPS_BACKEND_RETRY; } addr.rc_family = AF_BLUETOOTH; @@ -62,7 +70,10 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { perror("ERROR: Can't connect to device"); close(sk); - return 1; + if (cups_class) + return CUPS_BACKEND_FAILED; + else + return CUPS_BACKEND_RETRY; } fputs("STATE: -connecting-to-device\n", stderr); @@ -93,7 +104,7 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) if (err < 0) { perror("ERROR: Error writing to device"); close(sk); - return 1; + return CUPS_BACKEND_FAILED; } } @@ -101,5 +112,5 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) close(sk); - return 0; + return CUPS_BACKEND_OK; } -- cgit