2015-02-10 13:47:40 -05:00
|
|
|
/* encoding.h
|
|
|
|
**
|
|
|
|
** http transfer encoding library
|
|
|
|
** See RFC2616 section 3.6 for more details.
|
|
|
|
**
|
2018-10-12 06:28:09 -04:00
|
|
|
** Copyright (C) 2015-2018 Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
|
2015-02-10 13:47:40 -05:00
|
|
|
**
|
|
|
|
** This library is free software; you can redistribute it and/or
|
|
|
|
** modify it under the terms of the GNU Library General Public
|
|
|
|
** License as published by the Free Software Foundation; either
|
|
|
|
** version 2 of the License, or (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This library 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
|
|
|
|
** Library General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU Library General Public
|
|
|
|
** License along with this library; if not, write to the
|
|
|
|
** Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
** Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2018-10-12 06:16:06 -04:00
|
|
|
#ifndef _LIBIGLOO__ENCODING_H_
|
|
|
|
#define _LIBIGLOO__ENCODING_H_
|
2015-02-10 13:47:40 -05:00
|
|
|
|
2018-11-02 07:29:00 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-02-10 13:47:40 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
/* known encodings */
|
2018-10-12 07:27:17 -04:00
|
|
|
#define igloo_HTTPP_ENCODING_IDENTITY "identity" /* RFC2616 */
|
|
|
|
#define igloo_HTTPP_ENCODING_CHUNKED "chunked" /* RFC2616 */
|
|
|
|
#define igloo_HTTPP_ENCODING_GZIP "gzip" /* RFC1952 */
|
|
|
|
#define igloo_HTTPP_ENCODING_COMPRESS "compress" /* ??? */
|
|
|
|
#define igloo_HTTPP_ENCODING_DEFLATE "deflate" /* RFC1950, RFC1951 */
|
2015-02-10 13:47:40 -05:00
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
typedef struct igloo_httpp_encoding_tag igloo_httpp_encoding_t;
|
2015-02-10 13:47:40 -05:00
|
|
|
|
|
|
|
typedef struct httpp_meta_tag httpp_meta_t;
|
|
|
|
struct httpp_meta_tag {
|
|
|
|
char *key;
|
|
|
|
void *value;
|
|
|
|
size_t value_len;
|
|
|
|
httpp_meta_t *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* meta data functions */
|
|
|
|
/* meta data is to be used in a encoding-specific way */
|
2018-10-12 06:55:24 -04:00
|
|
|
httpp_meta_t *igloo_httpp_encoding_meta_new(const char *key, const char *value);
|
|
|
|
int igloo_httpp_encoding_meta_free(httpp_meta_t *self);
|
|
|
|
int igloo_httpp_encoding_meta_append(httpp_meta_t **dst, httpp_meta_t *next);
|
2015-02-10 13:47:40 -05:00
|
|
|
|
|
|
|
/* General setup */
|
2018-10-12 07:27:17 -04:00
|
|
|
igloo_httpp_encoding_t *igloo_httpp_encoding_new(const char *encoding);
|
|
|
|
int igloo_httpp_encoding_addref(igloo_httpp_encoding_t *self);
|
|
|
|
int igloo_httpp_encoding_release(igloo_httpp_encoding_t *self);
|
2015-02-10 13:47:40 -05:00
|
|
|
|
|
|
|
/* Read data from backend.
|
|
|
|
* if cb is NULL this will read from the internal buffer.
|
|
|
|
*/
|
2018-10-12 07:27:17 -04:00
|
|
|
ssize_t igloo_httpp_encoding_read(igloo_httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
|
2015-02-10 13:47:40 -05:00
|
|
|
|
2018-04-17 04:59:42 -04:00
|
|
|
/* Check if EOF is reached.
|
|
|
|
* If cb is not NULL this also considers backend state.
|
|
|
|
*/
|
2018-10-12 07:27:17 -04:00
|
|
|
int igloo_httpp_encoding_eof(igloo_httpp_encoding_t *self, int (*cb)(void*), void *userdata);
|
2018-04-17 04:59:42 -04:00
|
|
|
|
2015-02-10 13:47:40 -05:00
|
|
|
/* Read any meta data that is in buffer.
|
|
|
|
* After a call to this function the meta data is released from the
|
|
|
|
* encoding object and the caller is responsible to free it.
|
|
|
|
*/
|
2018-10-12 07:27:17 -04:00
|
|
|
httpp_meta_t *igloo_httpp_encoding_get_meta(igloo_httpp_encoding_t *self);
|
2015-02-10 13:47:40 -05:00
|
|
|
|
|
|
|
/* Write data to backend.
|
|
|
|
* If buf is NULL this will flush buffers.
|
|
|
|
* Depending on encoding flushing buffers may not be safe if not
|
|
|
|
* at end of stream.
|
|
|
|
*/
|
2018-10-12 07:27:17 -04:00
|
|
|
ssize_t igloo_httpp_encoding_write(igloo_httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
|
2015-02-10 13:47:40 -05:00
|
|
|
|
|
|
|
/* Check if we have something to flush. */
|
2018-10-12 07:27:17 -04:00
|
|
|
ssize_t igloo_httpp_encoding_pending(igloo_httpp_encoding_t *self);
|
2015-02-10 13:47:40 -05:00
|
|
|
|
|
|
|
/* Attach meta data to the stream.
|
|
|
|
* this is to be written out as soon as the encoding supports.
|
|
|
|
*/
|
2018-10-12 07:27:17 -04:00
|
|
|
int igloo_httpp_encoding_append_meta(igloo_httpp_encoding_t *self, httpp_meta_t *meta);
|
2015-02-10 13:47:40 -05:00
|
|
|
|
2018-11-02 07:29:00 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-10 13:47:40 -05:00
|
|
|
#endif
|