diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-01-27 10:47:25 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-01-27 10:47:52 +0900 |
commit | ef9b26ed48ff777f0ac2e84e92aa54a382d2b37e (patch) | |
tree | 13a008c6165a5ce4bd06a3b1dd53df91c8b01485 /notifier | |
parent | 4daab3758f62250691d3994850ddd3a7faf80d5e (diff) | |
download | cups-ef9b26ed48ff777f0ac2e84e92aa54a382d2b37e.tar.gz cups-ef9b26ed48ff777f0ac2e84e92aa54a382d2b37e.tar.bz2 cups-ef9b26ed48ff777f0ac2e84e92aa54a382d2b37e.zip |
Imported Upstream version 2.1.2upstream/2.1.2
Change-Id: Ia36f5862c3fcaa1f053ad69ed961e1fb9043e20b
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'notifier')
-rw-r--r-- | notifier/Dependencies | 24 | ||||
-rw-r--r-- | notifier/Makefile | 9 | ||||
-rw-r--r-- | notifier/dbus.c | 91 | ||||
-rw-r--r-- | notifier/mailto.c | 4 | ||||
-rw-r--r-- | notifier/rss.c | 44 | ||||
-rw-r--r-- | notifier/testnotify.c | 4 |
6 files changed, 105 insertions, 71 deletions
diff --git a/notifier/Dependencies b/notifier/Dependencies index f5a26a4..d844f9d 100644 --- a/notifier/Dependencies +++ b/notifier/Dependencies @@ -1,20 +1,22 @@ dbus.o: dbus.c ../cups/cups.h ../cups/file.h ../cups/versioning.h \ ../cups/ipp.h ../cups/http.h ../cups/array.h ../cups/language.h \ - ../cups/string-private.h ../config.h + ../cups/pwg.h ../cups/string-private.h ../config.h mailto.o: mailto.c ../cups/cups-private.h ../cups/string-private.h \ ../config.h ../cups/debug-private.h ../cups/versioning.h \ - ../cups/ipp-private.h ../cups/ipp.h ../cups/http.h ../cups/array.h \ - ../cups/http-private.h ../cups/md5-private.h \ - ../cups/language-private.h ../cups/transcode.h ../cups/language.h \ - ../cups/pwg-private.h ../cups/cups.h ../cups/file.h \ + ../cups/array-private.h ../cups/array.h ../cups/ipp-private.h \ + ../cups/ipp.h ../cups/http.h ../cups/http-private.h ../cups/language.h \ + ../cups/md5-private.h ../cups/language-private.h ../cups/transcode.h \ + ../cups/pwg-private.h ../cups/cups.h ../cups/file.h ../cups/pwg.h \ ../cups/ppd-private.h ../cups/ppd.h ../cups/thread-private.h rss.o: rss.c ../cups/cups.h ../cups/file.h ../cups/versioning.h \ ../cups/ipp.h ../cups/http.h ../cups/array.h ../cups/language.h \ - ../cups/string-private.h ../config.h ../cups/ipp-private.h + ../cups/pwg.h ../cups/string-private.h ../config.h \ + ../cups/ipp-private.h testnotify.o: testnotify.c ../cups/cups-private.h \ ../cups/string-private.h ../config.h ../cups/debug-private.h \ - ../cups/versioning.h ../cups/ipp-private.h ../cups/ipp.h \ - ../cups/http.h ../cups/array.h ../cups/http-private.h \ - ../cups/md5-private.h ../cups/language-private.h ../cups/transcode.h \ - ../cups/language.h ../cups/pwg-private.h ../cups/cups.h ../cups/file.h \ - ../cups/ppd-private.h ../cups/ppd.h ../cups/thread-private.h + ../cups/versioning.h ../cups/array-private.h ../cups/array.h \ + ../cups/ipp-private.h ../cups/ipp.h ../cups/http.h \ + ../cups/http-private.h ../cups/language.h ../cups/md5-private.h \ + ../cups/language-private.h ../cups/transcode.h ../cups/pwg-private.h \ + ../cups/cups.h ../cups/file.h ../cups/pwg.h ../cups/ppd-private.h \ + ../cups/ppd.h ../cups/thread-private.h diff --git a/notifier/Makefile b/notifier/Makefile index df7a188..3206dd0 100644 --- a/notifier/Makefile +++ b/notifier/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile 11173 2013-07-23 12:31:34Z msweet $" +# "$Id: Makefile 10996 2013-05-29 11:51:34Z msweet $" # # Notifier makefile for CUPS. # @@ -77,7 +77,10 @@ install-exec: done if test "x$(SYMROOT)" != "x"; then \ $(INSTALL_DIR) $(SYMROOT); \ - cp $(NOTIFIERS) $(SYMROOT); \ + for file in $(NOTIFIERS); do \ + cp $$file $(SYMROOT); \ + dsymutil $(SYMROOT)/$$file; \ + done \ fi @@ -158,5 +161,5 @@ include Dependencies # -# End of "$Id: Makefile 11173 2013-07-23 12:31:34Z msweet $". +# End of "$Id: Makefile 10996 2013-05-29 11:51:34Z msweet $". # diff --git a/notifier/dbus.c b/notifier/dbus.c index 08449d3..2a01f24 100644 --- a/notifier/dbus.c +++ b/notifier/dbus.c @@ -1,23 +1,18 @@ /* - * "$Id: dbus.c 11173 2013-07-23 12:31:34Z msweet $" + * "$Id: dbus.c 11594 2014-02-14 20:09:01Z msweet $" * - * D-Bus notifier for CUPS. + * D-Bus notifier for CUPS. * - * Copyright 2008-2011 by Apple Inc. - * Copyright (C) 2011 Red Hat, Inc. - * Copyright (C) 2007 Tim Waugh <twaugh@redhat.com> - * Copyright 1997-2005 by Easy Software Products. + * Copyright 2008-2014 by Apple Inc. + * Copyright (C) 2011, 2013 Red Hat, Inc. + * Copyright (C) 2007 Tim Waugh <twaugh@redhat.com> + * Copyright 1997-2005 by Easy Software Products. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". - * - * Contents: - * - * main() - Read events and send DBUS notifications. - * acquire_lock() - Acquire a lock so we only have a single notifier running. + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ /* @@ -154,10 +149,18 @@ enum /* + * Global variables... + */ + +static char lock_filename[1024]; /* Lock filename */ + + +/* * Local functions... */ static int acquire_lock(int *fd, char *lockfile, size_t locksize); +static void release_lock(void); /* @@ -176,8 +179,6 @@ main(int argc, /* I - Number of command-line args */ DBusMessage *message; /* Message to send */ DBusMessageIter iter; /* Iterator for message data */ int lock_fd = -1; /* Lock file descriptor */ - char lock_filename[1024]; - /* Lock filename */ /* @@ -416,7 +417,7 @@ main(int argc, /* I - Number of command-line args */ attr = ippFindAttribute(msg, "printer-state", IPP_TAG_ENUM); if (attr) { - dbus_uint32_t val = ippGetInteger(attr, 0); + dbus_uint32_t val = (dbus_uint32_t)ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else @@ -445,7 +446,7 @@ main(int argc, /* I - Number of command-line args */ if (i) *p++ = ','; - strcpy(p, ippGetString(attr, i, NULL)); + strlcpy(p, ippGetString(attr, i, NULL), reasons_length - (size_t)(p - printer_reasons)); p += strlen(p); } if (!dbus_message_iter_append_string(&iter, &printer_reasons)) @@ -464,7 +465,7 @@ main(int argc, /* I - Number of command-line args */ IPP_TAG_BOOLEAN); if (attr) { - dbus_bool_t val = ippGetBoolean(attr, 0); + dbus_bool_t val = (dbus_bool_t)ippGetBoolean(attr, 0); dbus_message_iter_append_boolean(&iter, &val); } else @@ -484,7 +485,7 @@ main(int argc, /* I - Number of command-line args */ attr = ippFindAttribute(msg, "notify-job-id", IPP_TAG_INTEGER); if (attr) { - dbus_uint32_t val = ippGetInteger(attr, 0); + dbus_uint32_t val = (dbus_uint32_t)ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else @@ -494,7 +495,7 @@ main(int argc, /* I - Number of command-line args */ attr = ippFindAttribute(msg, "job-state", IPP_TAG_ENUM); if (attr) { - dbus_uint32_t val = ippGetInteger(attr, 0); + dbus_uint32_t val = (dbus_uint32_t)ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else @@ -517,7 +518,7 @@ main(int argc, /* I - Number of command-line args */ if (i) *p++ = ','; - strcpy(p, ippGetString(attr, i, NULL)); + strlcpy(p, ippGetString(attr, i, NULL), reasons_length - (size_t)(p - job_reasons)); p += strlen(p); } if (!dbus_message_iter_append_string(&iter, &job_reasons)) @@ -542,7 +543,7 @@ main(int argc, /* I - Number of command-line args */ IPP_TAG_INTEGER); if (attr) { - dbus_uint32_t val = ippGetInteger(attr, 0); + dbus_uint32_t val = (dbus_uint32_t)ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else @@ -576,7 +577,7 @@ main(int argc, /* I - Number of command-line args */ if (lock_fd >= 0) { close(lock_fd); - unlink(lock_filename); + release_lock(); } return (0); @@ -584,6 +585,27 @@ main(int argc, /* I - Number of command-line args */ /* + * 'release_lock()' - Release the singleton lock. + */ + +static void +release_lock(void) +{ + unlink(lock_filename); +} + + +/* + * 'handle_sigterm()' - Handle SIGTERM signal. + */ +static void +handle_sigterm(int signum) +{ + release_lock(); + _exit(0); +} + +/* * 'acquire_lock()' - Acquire a lock so we only have a single notifier running. */ @@ -592,7 +614,8 @@ acquire_lock(int *fd, /* O - Lock file descriptor */ char *lockfile, /* I - Lock filename buffer */ size_t locksize) /* I - Size of filename buffer */ { - const char *tmpdir; /* Temporary directory */ + const char *tmpdir; /* Temporary directory */ + struct sigaction action; /* POSIX sigaction data */ /* @@ -610,8 +633,16 @@ acquire_lock(int *fd, /* O - Lock file descriptor */ if ((*fd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0) return (-1); - else - return (0); + + /* + * Set a SIGTERM handler to make sure we release the lock if the + * scheduler decides to stop us. + */ + memset(&action, 0, sizeof(action)); + action.sa_handler = handle_sigterm; + sigaction(SIGTERM, &action, NULL); + + return (0); } #else /* !HAVE_DBUS */ int @@ -623,5 +654,5 @@ main(void) /* - * End of "$Id: dbus.c 11173 2013-07-23 12:31:34Z msweet $". + * End of "$Id: dbus.c 11594 2014-02-14 20:09:01Z msweet $". */ diff --git a/notifier/mailto.c b/notifier/mailto.c index fce6aec..724e12b 100644 --- a/notifier/mailto.c +++ b/notifier/mailto.c @@ -1,5 +1,5 @@ /* - * "$Id: mailto.c 11173 2013-07-23 12:31:34Z msweet $" + * "$Id: mailto.c 10996 2013-05-29 11:51:34Z msweet $" * * "mailto" notifier for CUPS. * @@ -642,5 +642,5 @@ print_attributes(ipp_t *ipp, /* I - IPP request */ /* - * End of "$Id: mailto.c 11173 2013-07-23 12:31:34Z msweet $". + * End of "$Id: mailto.c 10996 2013-05-29 11:51:34Z msweet $". */ diff --git a/notifier/rss.c b/notifier/rss.c index 1489847..f2a0402 100644 --- a/notifier/rss.c +++ b/notifier/rss.c @@ -1,27 +1,16 @@ /* - * "$Id: rss.c 11173 2013-07-23 12:31:34Z msweet $" + * "$Id: rss.c 12945 2015-10-26 19:46:02Z msweet $" * - * RSS notifier for CUPS. + * RSS notifier for CUPS. * - * Copyright 2007-2012 by Apple Inc. - * Copyright 2007 by Easy Software Products. + * Copyright 2007-2015 by Apple Inc. + * Copyright 2007 by Easy Software Products. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". - * - * Contents: - * - * main() - Main entry for the test notifier. - * compare_rss() - Compare two messages. - * delete_message() - Free all memory used by a message. - * load_rss() - Load an existing RSS feed file. - * new_message() - Create a new RSS message. - * password_cb() - Return the cached password. - * save_rss() - Save messages to a RSS file. - * xml_escape() - Copy a string, escaping &, <, and > as needed. + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ /* @@ -29,6 +18,7 @@ */ #include <cups/cups.h> +#include <sys/stat.h> #include <cups/language.h> #include <cups/string-private.h> #include <cups/array.h> @@ -629,6 +619,8 @@ save_rss(cups_array_t *rss, /* I - RSS messages */ return (0); } + fchmod(fileno(fp), 0644); + fputs("<?xml version=\"1.0\"?>\n", fp); fputs("<rss version=\"2.0\">\n", fp); fputs(" <channel>\n", fp); @@ -649,15 +641,21 @@ save_rss(cups_array_t *rss, /* I - RSS messages */ msg; msg = (_cups_rss_t *)cupsArrayPrev(rss)) { + char *subject = xml_escape(msg->subject); + char *text = xml_escape(msg->text); + fputs(" <item>\n", fp); - fprintf(fp, " <title>%s</title>\n", msg->subject); - fprintf(fp, " <description>%s</description>\n", msg->text); + fprintf(fp, " <title>%s</title>\n", subject); + fprintf(fp, " <description>%s</description>\n", text); if (msg->link_url) fprintf(fp, " <link>%s</link>\n", msg->link_url); fprintf(fp, " <pubDate>%s</pubDate>\n", httpGetDateString2(msg->event_time, date, sizeof(date))); fprintf(fp, " <guid>%d</guid>\n", msg->sequence_number); fputs(" </item>\n", fp); + + free(subject); + free(text); } fputs(" </channel>\n", fp); @@ -737,5 +735,5 @@ xml_escape(const char *s) /* I - String to escape */ /* - * End of "$Id: rss.c 11173 2013-07-23 12:31:34Z msweet $". + * End of "$Id: rss.c 12945 2015-10-26 19:46:02Z msweet $". */ diff --git a/notifier/testnotify.c b/notifier/testnotify.c index 3186b6f..67441ce 100644 --- a/notifier/testnotify.c +++ b/notifier/testnotify.c @@ -1,5 +1,5 @@ /* - * "$Id: testnotify.c 11173 2013-07-23 12:31:34Z msweet $" + * "$Id: testnotify.c 10996 2013-05-29 11:51:34Z msweet $" * * Test notifier for CUPS. * @@ -123,5 +123,5 @@ print_attributes(ipp_t *ipp, /* I - IPP request */ /* - * End of "$Id: testnotify.c 11173 2013-07-23 12:31:34Z msweet $". + * End of "$Id: testnotify.c 10996 2013-05-29 11:51:34Z msweet $". */ |