SRCS = $(SRCS-1)
I18N-C = $(SRCS-1)
+SRCS-ZLIB = \
+ src/zlib.c
+SRCS-${CONFIG_ZLIB} += $(SRCS-ZLIB)
+
SRCS-UPNP = \
src/upnp.c
SRCS-${CONFIG_UPNP} += $(SRCS-UPNP)
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#if ENABLE_ZLIB
-#define ZLIB_CONST 1
-#include <zlib.h>
-#ifndef z_const
-#define z_const
-#endif
-#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
};
};
-/* **************************************************************************
- * Compression/Decompression
- * *************************************************************************/
-
-#if ENABLE_ZLIB
-uint8_t *gzip_inflate ( const uint8_t *data, size_t size, size_t orig )
-{
- int err;
- z_stream zstr;
- uint8_t *bufout;
-
- /* Setup buffers */
- bufout = malloc(orig);
-
- /* Setup zlib */
- memset(&zstr, 0, sizeof(zstr));
- inflateInit2(&zstr, MAX_WBITS + 16 /* gzip */);
- zstr.avail_in = size;
- zstr.next_in = (z_const uint8_t *)data;
- zstr.avail_out = orig;
- zstr.next_out = bufout;
-
- /* Decompress */
- err = inflate(&zstr, Z_NO_FLUSH);
- if ( err != Z_STREAM_END || zstr.avail_out != 0 ) {
- free(bufout);
- bufout = NULL;
- }
- inflateEnd(&zstr);
-
- return bufout;
-}
-#endif
-
-#if ENABLE_ZLIB
-uint8_t *gzip_deflate ( const uint8_t *data, size_t orig, size_t *size )
-{
- int err;
- z_stream zstr;
- uint8_t *bufout;
-
- /* Setup buffers */
- bufout = malloc(orig);
-
- /* Setup zlib */
- memset(&zstr, 0, sizeof(zstr));
- err = deflateInit2(&zstr, Z_BEST_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16 /* gzip */, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
- zstr.avail_in = orig;
- zstr.next_in = (z_const uint8_t *)data;
- zstr.avail_out = orig;
- zstr.next_out = bufout;
-
- /* Compress */
- while (1) {
- err = deflate(&zstr, Z_FINISH);
-
- /* Need more space */
- if (err == Z_OK && zstr.avail_out == 0) {
- bufout = realloc(bufout, zstr.total_out * 2);
- zstr.avail_out = zstr.total_out;
- zstr.next_out = bufout + zstr.total_out;
- continue;
- }
-
- /* Error */
- if ( (err != Z_STREAM_END && err != Z_OK) || zstr.total_out == 0 ) {
- free(bufout);
- bufout = NULL;
- } else {
- *size = zstr.total_out;
- }
- break;
- }
- deflateEnd(&zstr);
-
- return bufout;
-}
-#endif
-
/* **************************************************************************
* Miscellanous
* *************************************************************************/
#if (ENABLE_ZLIB && ENABLE_BUNDLE)
ret->gzip = 0;
ret->size = fb->f.orig;
- ret->buf = gzip_inflate(fb->f.data, fb->f.size, fb->f.orig);
+ ret->buf = tvh_gzip_inflate(fb->f.data, fb->f.size, fb->f.orig);
if (!ret->buf) {
free(ret);
ret = NULL;
if (ret->type == FB_BUNDLE) {
const uint8_t *data;
data = ret->b.root->f.data;
- ret->buf = gzip_deflate(data, ret->size, &ret->size);
+ ret->buf = tvh_gzip_deflate(data, ret->size, &ret->size);
} else {
uint8_t *data = malloc(ret->size);
ssize_t c = fread(data, 1, ret->size, ret->d.cur);
if (c == ret->size)
- ret->buf = gzip_deflate(data, ret->size, &ret->size);
+ ret->buf = tvh_gzip_deflate(data, ret->size, &ret->size);
fclose(ret->d.cur);
ret->d.cur = NULL;
free(data);
/* Miscellaneous */
int fb_stat ( const char *path, struct filebundle_stat *st );
-#if ENABLE_ZLIB
-uint8_t *gzip_deflate ( const uint8_t *data, size_t orig, size_t *size );
-uint8_t *gzip_inflate ( const uint8_t *data, size_t size, size_t orig );
-#endif
/* Directory processing wrappers */
fb_dir *fb_opendir ( const char *path );
#include "tvheadend.h"
#include "tcp.h"
#include "http.h"
-#include "filebundle.h"
#include "access.h"
#include "notify.h"
#include "channels.h"
#if ENABLE_ZLIB
if (http_encoding_valid(hc, "gzip") && encoding == NULL && size > 256) {
uint8_t *data2 = (uint8_t *)htsbuf_to_string(&hc->hc_reply);
- data = gzip_deflate(data2, size, &size);
+ data = tvh_gzip_deflate(data2, size, &size);
free(data2);
encoding = "gzip";
}
char *regexp_escape ( const char *str );
+#if ENABLE_ZLIB
+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 );
+#endif
+
/* URL decoding */
char to_hex(char code);
char *url_encode(const char *str);
--- /dev/null
+/*
+ * TV headend - zlib integration
+ * Copyright (C) 2012 Adam Sutton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tvheadend.h"
+
+#define ZLIB_CONST 1
+#include <zlib.h>
+#ifndef z_const
+#define z_const
+#endif
+
+/* **************************************************************************
+ * Compression/Decompression
+ * *************************************************************************/
+
+uint8_t *tvh_gzip_inflate ( const uint8_t *data, size_t size, size_t orig )
+{
+ int err;
+ z_stream zstr;
+ uint8_t *bufout;
+
+ /* Setup buffers */
+ bufout = malloc(orig);
+
+ /* Setup zlib */
+ memset(&zstr, 0, sizeof(zstr));
+ inflateInit2(&zstr, MAX_WBITS + 16 /* gzip */);
+ zstr.avail_in = size;
+ zstr.next_in = (z_const uint8_t *)data;
+ zstr.avail_out = orig;
+ zstr.next_out = bufout;
+
+ /* Decompress */
+ err = inflate(&zstr, Z_NO_FLUSH);
+ if ( err != Z_STREAM_END || zstr.avail_out != 0 ) {
+ free(bufout);
+ bufout = NULL;
+ }
+ inflateEnd(&zstr);
+
+ return bufout;
+}
+
+uint8_t *tvh_gzip_deflate ( const uint8_t *data, size_t orig, size_t *size )
+{
+ int err;
+ z_stream zstr;
+ uint8_t *bufout;
+
+ /* Setup buffers */
+ bufout = malloc(orig);
+
+ /* Setup zlib */
+ memset(&zstr, 0, sizeof(zstr));
+ err = deflateInit2(&zstr, Z_BEST_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16 /* gzip */, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
+ zstr.avail_in = orig;
+ zstr.next_in = (z_const uint8_t *)data;
+ zstr.avail_out = orig;
+ zstr.next_out = bufout;
+
+ /* Compress */
+ while (1) {
+ err = deflate(&zstr, Z_FINISH);
+
+ /* Need more space */
+ if (err == Z_OK && zstr.avail_out == 0) {
+ bufout = realloc(bufout, zstr.total_out * 2);
+ zstr.avail_out = zstr.total_out;
+ zstr.next_out = bufout + zstr.total_out;
+ continue;
+ }
+
+ /* Error */
+ if ( (err != Z_STREAM_END && err != Z_OK) || zstr.total_out == 0 ) {
+ free(bufout);
+ bufout = NULL;
+ } else {
+ *size = zstr.total_out;
+ }
+ break;
+ }
+ deflateEnd(&zstr);
+
+ return bufout;
+}