apk-tools/src/apk_io.h

124 lines
4.0 KiB
C
Raw Normal View History

2008-11-07 15:11:08 +00:00
/* apk_io.h - Alpine Package Keeper (APK)
*
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
2008-11-07 15:11:08 +00:00
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
#ifndef APK_IO
#define APK_IO
#include <openssl/evp.h>
2008-11-07 15:11:08 +00:00
#include "apk_defines.h"
#include "apk_blob.h"
#include "apk_hash.h"
struct apk_id_cache {
int root_fd;
unsigned int genid;
struct apk_hash uid_cache;
struct apk_hash gid_cache;
};
2008-11-07 15:11:08 +00:00
struct apk_file_info {
char *name;
char *link_target;
char *uname;
char *gname;
off_t size;
uid_t uid;
gid_t gid;
mode_t mode;
time_t mtime;
dev_t device;
struct apk_checksum csum;
};
2008-11-07 15:11:08 +00:00
struct apk_istream {
ssize_t (*read)(void *stream, void *ptr, size_t size);
2008-11-07 15:11:08 +00:00
void (*close)(void *stream);
};
#define APK_BSTREAM_SINGLE_READ 0x0001
#define APK_BSTREAM_EOF 0x0002
2008-11-07 15:11:08 +00:00
struct apk_bstream {
unsigned int flags;
apk_blob_t (*read)(void *stream, apk_blob_t token);
void (*close)(void *stream, size_t *size);
2008-11-07 15:11:08 +00:00
};
2008-11-28 14:28:54 +00:00
struct apk_ostream {
ssize_t (*write)(void *stream, const void *buf, size_t size);
int (*close)(void *stream);
2008-11-28 14:28:54 +00:00
};
#define APK_MPART_DATA 1 /* data processed so far */
#define APK_MPART_BOUNDARY 2 /* final part of data, before boundary */
#define APK_MPART_END 3 /* signals end of stream */
typedef int (*apk_multipart_cb)(void *ctx, int part, apk_blob_t data);
struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *,
apk_multipart_cb cb, void *ctx);
static inline struct apk_istream *apk_bstream_gunzip(struct apk_bstream *bs)
{
return apk_bstream_gunzip_mpart(bs, NULL, NULL);
}
2008-11-28 14:28:54 +00:00
struct apk_ostream *apk_ostream_gzip(struct apk_ostream *);
struct apk_ostream *apk_ostream_counter(off_t *);
2008-11-27 19:06:45 +00:00
struct apk_istream *apk_istream_from_fd_pid(int fd, pid_t pid, int (*translate_status)(int));
struct apk_istream *apk_istream_from_file(int atfd, const char *file);
struct apk_istream *apk_istream_from_file_gz(int atfd, const char *file);
2008-11-28 13:03:27 +00:00
struct apk_istream *apk_istream_from_url(const char *url);
2009-01-15 10:55:26 +00:00
struct apk_istream *apk_istream_from_url_gz(const char *url);
2008-11-07 15:11:08 +00:00
size_t apk_istream_skip(struct apk_istream *istream, size_t size);
size_t apk_istream_splice(void *stream, int fd, size_t size,
apk_progress_cb cb, void *cb_ctx);
2008-11-07 15:11:08 +00:00
static inline struct apk_istream *apk_istream_from_fd(int fd)
{
return apk_istream_from_fd_pid(fd, 0, NULL);
}
2008-11-07 15:11:08 +00:00
struct apk_bstream *apk_bstream_from_istream(struct apk_istream *istream);
struct apk_bstream *apk_bstream_from_fd_pid(int fd, pid_t pid, int (*translate_status)(int));
struct apk_bstream *apk_bstream_from_file(int atfd, const char *file);
2008-11-28 13:03:27 +00:00
struct apk_bstream *apk_bstream_from_url(const char *url);
struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const char *to);
2008-11-07 15:11:08 +00:00
static inline struct apk_bstream *apk_bstream_from_fd(int fd)
{
return apk_bstream_from_fd_pid(fd, 0, NULL);
}
2008-11-28 14:28:54 +00:00
struct apk_ostream *apk_ostream_to_fd(int fd);
struct apk_ostream *apk_ostream_to_file(int atfd, const char *file, const char *tmpfile, mode_t mode);
struct apk_ostream *apk_ostream_to_file_gz(int atfd, const char *file, const char *tmpfile, mode_t mode);
2009-04-16 14:05:27 +00:00
size_t apk_ostream_write_string(struct apk_ostream *ostream, const char *string);
2008-11-27 19:06:45 +00:00
2008-11-07 15:11:08 +00:00
apk_blob_t apk_blob_from_istream(struct apk_istream *istream, size_t size);
apk_blob_t apk_blob_from_file(int atfd, const char *file);
2008-11-07 15:11:08 +00:00
#define APK_FI_NOFOLLOW 0x80000000
int apk_file_get_info(int atfd, const char *filename, unsigned int flags,
struct apk_file_info *fi);
int apk_move_file(int atfd, const char *from, const char *to);
int apk_url_download(const char *url, int atfd, const char *file);
const char *apk_url_local_file(const char *url);
void apk_id_cache_init(struct apk_id_cache *idc, int root_fd);
void apk_id_cache_free(struct apk_id_cache *idc);
void apk_id_cache_reset(struct apk_id_cache *idc);
uid_t apk_resolve_uid(struct apk_id_cache *idc, const char *username, uid_t default_uid);
uid_t apk_resolve_gid(struct apk_id_cache *idc, const char *groupname, uid_t default_gid);
2008-11-07 15:11:08 +00:00
#endif