diff options
author | James Meyer <james.meyer@operamail.com> | 2014-08-16 17:49:53 (GMT) |
---|---|---|
committer | James Meyer <james.meyer@operamail.com> | 2014-08-16 17:59:16 (GMT) |
commit | edfc437426e7dd540b35ea7cd436b886e5c46866 (patch) | |
tree | 0ad4f92323d408104d7b073f2999c40b41745341 /abs/extra/cups/cups-dbus-utf8.patch | |
parent | 9b3d5cb2a36836482a2409d54bf183a1af879fe3 (diff) | |
download | linhes_pkgbuild-edfc437426e7dd540b35ea7cd436b886e5c46866.zip linhes_pkgbuild-edfc437426e7dd540b35ea7cd436b886e5c46866.tar.gz linhes_pkgbuild-edfc437426e7dd540b35ea7cd436b886e5c46866.tar.bz2 |
cups: 1.7.0
refs #961
Diffstat (limited to 'abs/extra/cups/cups-dbus-utf8.patch')
-rw-r--r-- | abs/extra/cups/cups-dbus-utf8.patch | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/abs/extra/cups/cups-dbus-utf8.patch b/abs/extra/cups/cups-dbus-utf8.patch new file mode 100644 index 0000000..0bcd4a1 --- /dev/null +++ b/abs/extra/cups/cups-dbus-utf8.patch @@ -0,0 +1,106 @@ +diff -up cups-1.6.1/notifier/dbus.c.dbus-utf8 cups-1.6.1/notifier/dbus.c +--- cups-1.6.1/notifier/dbus.c.dbus-utf8 2012-01-20 19:00:32.000000000 +0000 ++++ cups-1.6.1/notifier/dbus.c 2012-10-31 11:04:47.686973616 +0000 +@@ -31,6 +31,9 @@ + #include <sys/stat.h> + #include <sys/types.h> + #include <unistd.h> ++#include <assert.h> ++#include <locale.h> ++#include <wchar.h> + + #ifdef HAVE_DBUS + # include <dbus/dbus.h> +@@ -157,10 +160,82 @@ enum + * Local functions... + */ + +-static int acquire_lock(int *fd, char *lockfile, size_t locksize); ++static int acquire_lock(int *fd, char *lockfile, size_t locksize); ++static const char *validate_utf8(const char *str); + + + /* ++ * 'validate_utf8()' - Convert to valid UTF-8 ++ */ ++ ++static const char * ++validate_utf8 (const char *str) ++{ ++ static char *buffer = NULL; ++ static size_t buflen = 0; ++ char *p; ++ size_t str_len; ++ unsigned int i; ++ mbstate_t instate, outstate; ++ ++ if (str == NULL) ++ { ++ free (buffer); ++ return (NULL); ++ } ++ ++ /* Is it already valid? */ ++ if (mbstowcs (NULL, str, 0) != (size_t) -1) ++ return str; ++ ++ /* Make sure our buffer is at least as large as the input string */ ++ str_len = strlen (str); ++ if (str_len > buflen) ++ { ++ if (buffer == NULL) ++ /* Set encoding type to UTF-8 the first time we need to */ ++ setlocale (LC_CTYPE, "en_US.UTF-8"); ++ ++ buflen = str_len + 1; ++ buffer = realloc (buffer, buflen); ++ } ++ ++ memset (&instate, '\0', sizeof (mbstate_t)); ++ memset (&outstate, '\0', sizeof (mbstate_t)); ++ p = buffer; ++ i = 0; ++ while (i < str_len) ++ { ++ wchar_t wc; ++ size_t used, written; ++ mbstate_t orig_instate = instate; ++ used = mbrtowc (&wc, str + i, str_len - i, &instate); ++ switch (used) ++ { ++ case (size_t) -2: ++ case (size_t) -1: ++ wc = L'?'; /* so replacement is never longer than original char */ ++ instate = orig_instate; ++ /* fallthru */ ++ case 0: ++ used = 1; ++ } ++ ++ written = wcrtomb (p, wc, &outstate); ++ if (written != -1) ++ { ++ p += written; ++ assert (p - buffer < buflen); ++ } ++ ++ i += used; ++ } ++ ++ *p = '\0'; ++ return buffer; ++} ++ ++/* + * 'main()' - Read events and send DBUS notifications. + */ + +@@ -366,7 +441,7 @@ main(int argc, /* I - Number of comm + attr = ippFindAttribute(msg, "notify-text", IPP_TAG_TEXT); + if (attr) + { +- const char *val = ippGetString(attr, 0, NULL); ++ const char *val = validate_utf8 (ippGetString(attr, 0, NULL)); + if (!dbus_message_iter_append_string(&iter, &val)) + goto bail; + } |