if (fd >= 0) {
#if ENABLE_ZLIB
if (config.epg_compress) {
- r = tvh_write(fd, "\xff\xffGZIP00\x00\x00\x00\x00", 12);
- if (!r)
- r = tvh_gzip_deflate_fd(fd, sb->sb_data, sb->sb_ptr, &size, 3) < 0;
- if (!r && size > UINT_MAX)
- r = 1;
- if (!r) {
- r = lseek(fd, 8, SEEK_SET) != (off_t)8;
- if (!r) {
- uint8_t data2[4];
- data2[0] = (sb->sb_ptr >> 24) & 0xff;
- data2[1] = (sb->sb_ptr >> 16) & 0xff;
- data2[2] = (sb->sb_ptr >> 8) & 0xff;
- data2[3] = (sb->sb_ptr & 0xff);
- r = tvh_write(fd, data2, 4);
- }
- }
+ r = tvh_gzip_deflate_fd_header(fd, sb->sb_data, sb->sb_ptr, 3) < 0;
} else
#endif
r = tvh_write(fd, sb->sb_data, sb->sb_ptr);
#include <dirent.h>
#include "htsmsg.h"
+#include "htsmsg_binary.h"
#include "htsmsg_json.h"
#include "settings.h"
#include "tvheadend.h"
va_list ap;
htsbuf_queue_t hq;
htsbuf_data_t *hd;
- int ok, r;
+ int ok, r, pack;
+ void *msgdata;
+ size_t msglen;
if(settingspath == NULL)
return;
}
/* Store data */
+#if ENABLE_ZLIB
+ pack = strstr(path, "/muxes/") != NULL && /* ugly, redesign API */
+ strstr(path, "/networks/") != NULL &&
+ strstr(path, "/input/") != NULL;
+#else
+ pack = 0;
+#endif
ok = 1;
- htsbuf_queue_init(&hq, 0);
- htsmsg_json_serialize(record, &hq, 1);
- TAILQ_FOREACH(hd, &hq.hq_q, hd_link)
- if(tvh_write(fd, hd->hd_data + hd->hd_data_off, hd->hd_data_len)) {
- tvhlog(LOG_ALERT, "settings", "Failed to write file \"%s\" - %s",
- tmppath, strerror(errno));
- ok = 0;
- break;
+
+ if (!pack) {
+ htsbuf_queue_init(&hq, 0);
+ htsmsg_json_serialize(record, &hq, 1);
+ TAILQ_FOREACH(hd, &hq.hq_q, hd_link)
+ if(tvh_write(fd, hd->hd_data + hd->hd_data_off, hd->hd_data_len)) {
+ tvhlog(LOG_ALERT, "settings", "Failed to write file \"%s\" - %s",
+ tmppath, strerror(errno));
+ ok = 0;
+ break;
+ }
+ htsbuf_queue_flush(&hq);
+ } else {
+#if ENABLE_ZLIB
+ r = htsmsg_binary_serialize(record, &msgdata, &msglen, 0x10000);
+ if (!r) {
+ r = tvh_gzip_deflate_fd_header(fd, msgdata, msglen, 3);
+ if (r)
+ ok = 0;
}
+#endif
+ }
close(fd);
- htsbuf_queue_flush(&hq);
/* Move */
if(ok) {
{
ssize_t n, size;
char *mem;
+ uint8_t *unpacked;
fb_file *fp;
htsmsg_t *r = NULL;
+ uint32_t orig;
/* Open */
if (!(fp = fb_open(filename, 1, 0))) return NULL;
if (n >= 0) mem[n] = 0;
/* Decode */
- if(n == size)
- r = htsmsg_json_deserialize(mem);
+ if(n == size) {
+ if (size > 12 && memcmp(mem, "\xff\xffGZIP00", 8) == 0) {
+#if ENABLE_ZLIB
+ orig = (mem[8] << 24) | (mem[9] << 16) | (mem[10] << 8) | mem[11];
+ if (orig > 0) {
+ unpacked = tvh_gzip_inflate((uint8_t *)mem + 12, size - 12, orig);
+ if (unpacked) {
+ r = htsmsg_binary_deserialize(unpacked, orig, NULL);
+ free(unpacked);
+ }
+ }
+#endif
+ } else {
+ r = htsmsg_json_deserialize(mem);
+ }
+ }
/* Close */
fb_close(fp);
uint8_t *tvh_gzip_inflate ( const uint8_t *data, size_t size, size_t orig );
uint8_t *tvh_gzip_deflate ( const uint8_t *data, size_t orig, size_t *size );
int tvh_gzip_deflate_fd ( int fd, const uint8_t *data, size_t orig, size_t *size, int speed );
+int tvh_gzip_deflate_fd_header ( int fd, const uint8_t *data, size_t orig, int speed );
#endif
/* URL decoding */
return r;
}
+
+int tvh_gzip_deflate_fd_header ( int fd, const uint8_t *data, size_t orig, int speed )
+{
+ uint8_t data2[4];
+ size_t size;
+ int r;
+
+ r = tvh_write(fd, "\xff\xffGZIP00\x00\x00\x00\x00", 12);
+ if (r)
+ return 1;
+ r = tvh_gzip_deflate_fd(fd, data, orig, &size, 3) < 0;
+ if (r || size > UINT_MAX)
+ return 1;
+ r = lseek(fd, 8, SEEK_SET) != (off_t)8;
+ if (r)
+ return 1;
+ data2[0] = (orig >> 24) & 0xff;
+ data2[1] = (orig >> 16) & 0xff;
+ data2[2] = (orig >> 8) & 0xff;
+ data2[3] = (orig & 0xff);
+ return tvh_write(fd, data2, 4);
+}