chiark / gitweb /
journal: fix export of messages containing newlines
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 31 Mar 2014 12:57:28 +0000 (08:57 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 5 Apr 2014 04:42:01 +0000 (00:42 -0400)
In "export" format, newlines are significant, and messages containing
newlines must be exported as "binary".

src/shared/logs-show.c
src/shared/utf8.c
src/shared/utf8.h

index 9d14933bc11c0439e4cf697bb32f221b3d6eb675..b0b66f64fcd63edb17586d0d2859471b5b265d78 100644 (file)
@@ -547,7 +547,9 @@ static int output_export(
                     startswith(data, "_BOOT_ID="))
                         continue;
 
-                if (!utf8_is_printable(data, length)) {
+                if (utf8_is_printable_newline(data, length, false))
+                        fwrite(data, length, 1, f);
+                else {
                         const char *c;
                         uint64_t le64;
 
@@ -562,8 +564,7 @@ static int output_export(
                         le64 = htole64(length - (c - (const char*) data) - 1);
                         fwrite(&le64, sizeof(le64), 1, f);
                         fwrite(c + 1, length - (c - (const char*) data) - 1, 1, f);
-                } else
-                        fwrite(data, length, 1, f);
+                }
 
                 fputc('\n', f);
         }
index 0b524d8a9041eae0348382cdf47159f7c2f8d0b3..c559c13678d62b7cd275f05721febe73b5205924 100644 (file)
@@ -136,7 +136,7 @@ int utf8_encoded_to_unichar(const char *str) {
         return unichar;
 }
 
-bool utf8_is_printable(const char* str, size_t length) {
+bool utf8_is_printable_newline(const char* str, size_t length, bool newline) {
         const uint8_t *p;
 
         assert(str);
@@ -145,7 +145,8 @@ bool utf8_is_printable(const char* str, size_t length) {
                 int encoded_len = utf8_encoded_valid_unichar((const char *)p);
                 int val = utf8_encoded_to_unichar((const char*)p);
 
-                if (encoded_len < 0 || val < 0 || is_unicode_control(val))
+                if (encoded_len < 0 || val < 0 || is_unicode_control(val) ||
+                    (!newline && val == '\n'))
                         return false;
 
                 length -= encoded_len;
index c0eb73a21d32ea5a483fea51fa39ff6de96ddc4d..c087995930eb0a75f2c7473829d45df97f5f9ff1 100644 (file)
@@ -31,7 +31,10 @@ const char *utf8_is_valid(const char *s) _pure_;
 char *ascii_is_valid(const char *s) _pure_;
 char *utf8_escape_invalid(const char *s);
 
-bool utf8_is_printable(const char* str, size_t length) _pure_;
+bool utf8_is_printable_newline(const char* str, size_t length, bool newline) _pure_;
+_pure_ static inline bool utf8_is_printable(const char* str, size_t length) {
+        return utf8_is_printable_newline(str, length, true);
+}
 
 char *utf16_to_utf8(const void *s, size_t length);