From 2d6ee34d80229c72b87c36336241ddcc9eae0562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= Date: Tue, 29 Oct 2024 10:23:34 +0200 Subject: [PATCH] Move buf_ declarations to a separate, installed .h file https://github.com/cyrusimap/cyrus-imapd/pull/5108 because sieve_intefrace.h depends on struct buf declaration and sieve_interface.h is installed. -- install libconfig.h, imap/message_guid.h -- charset.h (installed): do not depend on util.h and thus on config.h --- Makefile.am | 13 ++++--- imap/message.h | 4 ++- lib/buf.h | 76 +++++++++++++++++++++++++++++++++++++++++ lib/charset.h | 2 +- lib/util.h | 69 +------------------------------------ sieve/sieve_interface.h | 2 +- 6 files changed, 90 insertions(+), 76 deletions(-) create mode 100644 lib/buf.h diff --git a/Makefile.am b/Makefile.am index e9b6a9b2d44..c7f44a85f4e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -766,6 +766,7 @@ include_HEADERS = \ lib/bitvector.h \ lib/bloom.h \ lib/bsearch.h \ + lib/buf.h \ lib/bufarray.h \ lib/charset.h \ lib/chartable.h \ @@ -785,6 +786,7 @@ include_HEADERS = \ lib/imparse.h \ lib/iostat.h \ lib/iptostring.h \ + lib/libconfig.h \ lib/libcyr_cfg.h \ lib/lsort.h \ lib/map.h \ @@ -808,23 +810,25 @@ include_HEADERS = \ lib/tok.h \ lib/vparse.h \ lib/wildmat.h \ - lib/xmalloc.h + lib/xmalloc.h \ + lib/xsha1.h nodist_include_HEADERS = \ lib/imapopts.h -nobase_include_HEADERS = sieve/sieve_interface.h +nobase_include_HEADERS = \ + imap/message_guid.h \ + sieve/sieve_interface.h + nobase_nodist_include_HEADERS = sieve/sieve_err.h noinst_HEADERS += \ lib/byteorder.h \ lib/gai.h \ - lib/libconfig.h \ lib/md5.h \ lib/prot.h \ lib/ptrarray.h \ lib/util.h \ - lib/xsha1.h \ lib/xstrlcat.h \ lib/xstrlcpy.h \ lib/xstrnchr.h @@ -1049,7 +1053,6 @@ imap_libcyrus_imap_la_SOURCES = \ imap/mboxname.c \ imap/mboxname.h \ imap/message_guid.c \ - imap/message_guid.h \ imap/message.c \ imap/message.h \ imap/message_priv.h \ diff --git a/imap/message.h b/imap/message.h index dfbba61798c..56eed56b76c 100644 --- a/imap/message.h +++ b/imap/message.h @@ -45,10 +45,12 @@ #include +#include "arrayu64.h" +#include "buf.h" #include "prot.h" #include "mailbox.h" +#include "imap/message_guid.h" #include "strarray.h" -#include "util.h" #include "charset.h" /* (draft standard) MIME tspecials */ diff --git a/lib/buf.h b/lib/buf.h new file mode 100644 index 00000000000..75de8fc2e2e --- /dev/null +++ b/lib/buf.h @@ -0,0 +1,76 @@ +#ifndef CYRUS_BUF_H +#define CYRUS_BUF_H + +/* Examine the name of a file, and return a single character + * (as an int) that can be used as the name of a hash + * directory. Caller is responsible for skipping any prefix + * of the name. + */ +int dir_hash_c(const char *name, int full); + +#include +#define BUF_MMAP (1<<1) +typedef unsigned long long int modseq_t; + +struct buf { + char *s; + size_t len; + size_t alloc; + unsigned flags; +}; +#define BUF_INITIALIZER { NULL, 0, 0, 0 } + +#define buf_new() ((struct buf *) xzmalloc(sizeof(struct buf))) +#define buf_destroy(b) do { buf_free((b)); free((b)); } while (0) +#define buf_ensure(b, n) do { if ((b)->alloc < (b)->len + (n)) _buf_ensure((b), (n)); } while (0) +#define buf_putc(b, c) do { buf_ensure((b), 1); (b)->s[(b)->len++] = (c); } while (0) + +void _buf_ensure(struct buf *buf, size_t len); +const char *buf_cstring(const struct buf *buf); +const char *buf_cstringnull(const struct buf *buf); +const char *buf_cstringnull_ifempty(const struct buf *buf); +const char *buf_cstring_or_empty(const struct buf *buf); +char *buf_newcstring(struct buf *buf); +char *buf_release(struct buf *buf); +char *buf_releasenull(struct buf *buf); +void buf_getmap(struct buf *buf, const char **base, size_t *len); +size_t buf_len(const struct buf *buf); +const char *buf_base(const struct buf *buf); +void buf_reset(struct buf *buf); +void buf_setcstr(struct buf *buf, const char *str); +void buf_setmap(struct buf *buf, const char *base, size_t len); +void buf_copy(struct buf *dst, const struct buf *src); +void buf_append(struct buf *dst, const struct buf *src); +void buf_appendcstr(struct buf *buf, const char *str); +void buf_appendoverlap(struct buf *buf, const char *str); +void buf_appendmap(struct buf *buf, const char *base, size_t len); +void buf_cowappendmap(struct buf *buf, const char *base, unsigned int len); +void buf_cowappendfree(struct buf *buf, char *base, unsigned int len); +void buf_insert(struct buf *dst, unsigned int off, const struct buf *src); +void buf_insertcstr(struct buf *buf, unsigned int off, const char *str); +void buf_insertmap(struct buf *buf, unsigned int off, const char *base, int len); +void buf_printf(struct buf *buf, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); +void buf_replace_buf(struct buf *buf, size_t offset, size_t length, + const struct buf *replace); +int buf_replace_all(struct buf *buf, const char *match, + const char *replace); +int buf_replace_char(struct buf *buf, char match, char replace); +void buf_remove(struct buf *buf, unsigned int off, unsigned int len); +int buf_cmp(const struct buf *, const struct buf *); +int buf_findchar(const struct buf *, unsigned int off, int c); +int buf_findline(const struct buf *buf, const char *line); +void buf_init_ro(struct buf *buf, const char *base, size_t len); +void buf_initm(struct buf *buf, char *base, int len); +void buf_initmcstr(struct buf *buf, char *str); +void buf_init_ro_cstr(struct buf *buf, const char *str); +void buf_refresh_mmap(struct buf *buf, int onceonly, int fd, + const char *fname, size_t size, const char *mboxname); +void buf_free(struct buf *buf); +void buf_move(struct buf *dst, struct buf *src); +const char *buf_lcase(struct buf *buf); +const char *buf_ucase(struct buf *buf); +const char *buf_tocrlf(struct buf *buf); +void buf_trim(struct buf *buf); + +#endif /* CYRUS_BUF_H */ diff --git a/lib/charset.h b/lib/charset.h index 1fd009c21df..aa9628f8a39 100644 --- a/lib/charset.h +++ b/lib/charset.h @@ -65,7 +65,7 @@ /* RFC 5322, 2.1.1 */ #define MIME_MAX_HEADER_LENGTH 78 -#include "util.h" +#include "buf.h" #include "xsha1.h" #define charset_base64_len_unpadded(n) \ diff --git a/lib/util.h b/lib/util.h index 1f336d4bec1..d081161a4bc 100644 --- a/lib/util.h +++ b/lib/util.h @@ -65,6 +65,7 @@ #define STDERR_FILENO 2 /* Standard error output. */ #endif +#include "buf.h" #include "xmalloc.h" /* version string printable in gdb tracking */ @@ -106,7 +107,6 @@ typedef unsigned short bit32; #endif typedef unsigned long long int bit64; -typedef unsigned long long int modseq_t; #define MODSEQ_FMT "%llu" #define atomodseq_t(s) strtoull(s, NULL, 10) char *modseqtoa(modseq_t modseq); @@ -191,12 +191,6 @@ int strcmpnull(const char *a, const char *b); extern keyvalue *kv_bsearch (const char *key, keyvalue *kv, int nelem, int (*cmpf)(const char *s1, const char *s2)); -/* Examine the name of a file, and return a single character - * (as an int) that can be used as the name of a hash - * directory. Caller is responsible for skipping any prefix - * of the name. - */ -extern int dir_hash_c(const char *name, int full); /* * Like dir_hash_c() but builds the result as a single-byte * C string in the provided buffer, and returns the buffer, @@ -279,79 +273,18 @@ extern int64_t now_ms(void); extern clock_t sclock(void); -#define BUF_MMAP (1<<1) - -struct buf { - char *s; - size_t len; - size_t alloc; - unsigned flags; -}; -#define BUF_INITIALIZER { NULL, 0, 0, 0 } - -#define buf_new() ((struct buf *) xzmalloc(sizeof(struct buf))) -#define buf_destroy(b) do { buf_free((b)); free((b)); } while (0) -#define buf_ensure(b, n) do { if ((b)->alloc < (b)->len + (n)) _buf_ensure((b), (n)); } while (0) -#define buf_putc(b, c) do { buf_ensure((b), 1); (b)->s[(b)->len++] = (c); } while (0) - -void _buf_ensure(struct buf *buf, size_t len); -const char *buf_cstring(const struct buf *buf); -const char *buf_cstringnull(const struct buf *buf); -const char *buf_cstringnull_ifempty(const struct buf *buf); -char *buf_release(struct buf *buf); -char *buf_newcstring(struct buf *buf); -char *buf_releasenull(struct buf *buf); -void buf_getmap(struct buf *buf, const char **base, size_t *len); int buf_getline(struct buf *buf, FILE *fp); -size_t buf_len(const struct buf *buf); -const char *buf_base(const struct buf *buf); -void buf_reset(struct buf *buf); void buf_truncate(struct buf *buf, ssize_t len); -void buf_setcstr(struct buf *buf, const char *str); -void buf_setmap(struct buf *buf, const char *base, size_t len); -void buf_copy(struct buf *dst, const struct buf *src); -void buf_append(struct buf *dst, const struct buf *src); -void buf_appendcstr(struct buf *buf, const char *str); -void buf_appendoverlap(struct buf *buf, const char *str); void buf_appendbit32(struct buf *buf, bit32 num); void buf_appendbit64(struct buf *buf, bit64 num); -void buf_appendmap(struct buf *buf, const char *base, size_t len); -void buf_cowappendmap(struct buf *buf, const char *base, unsigned int len); -void buf_cowappendfree(struct buf *buf, char *base, unsigned int len); -void buf_insert(struct buf *dst, unsigned int off, const struct buf *src); -void buf_insertcstr(struct buf *buf, unsigned int off, const char *str); -void buf_insertmap(struct buf *buf, unsigned int off, const char *base, int len); void buf_vprintf(struct buf *buf, const char *fmt, va_list args) __attribute__((format(printf, 2, 0))); -void buf_printf(struct buf *buf, const char *fmt, ...) - __attribute__((format(printf, 2, 3))); -void buf_replace_buf(struct buf *buf, size_t offset, size_t length, - const struct buf *replace); -int buf_replace_all(struct buf *buf, const char *match, - const char *replace); -int buf_replace_char(struct buf *buf, char match, char replace); #ifdef ENABLE_REGEX int buf_replace_all_re(struct buf *buf, const regex_t *, const char *replace); int buf_replace_one_re(struct buf *buf, const regex_t *, const char *replace); #endif -void buf_remove(struct buf *buf, unsigned int off, unsigned int len); -int buf_cmp(const struct buf *, const struct buf *); -int buf_findchar(const struct buf *, unsigned int off, int c); -int buf_findline(const struct buf *buf, const char *line); -void buf_init_ro(struct buf *buf, const char *base, size_t len); -void buf_initm(struct buf *buf, char *base, int len); -void buf_initmcstr(struct buf *buf, char *str); -void buf_init_ro_cstr(struct buf *buf, const char *str); -void buf_refresh_mmap(struct buf *buf, int onceonly, int fd, - const char *fname, size_t size, const char *mboxname); -void buf_free(struct buf *buf); -void buf_move(struct buf *dst, struct buf *src); -const char *buf_lcase(struct buf *buf); -const char *buf_ucase(struct buf *buf); -const char *buf_tocrlf(struct buf *buf); -void buf_trim(struct buf *buf); /* * Given a list of strings, terminated by (char *)NULL, diff --git a/sieve/sieve_interface.h b/sieve/sieve_interface.h index 62736896bf0..b2abe18b859 100644 --- a/sieve/sieve_interface.h +++ b/sieve/sieve_interface.h @@ -51,8 +51,8 @@ #define SIEVE_OK (0) #include "arrayu64.h" +#include "buf.h" #include "strarray.h" -#include "util.h" #include "sieve/sieve_err.h" /* external sieve types */