Browse Source

fix lots of sign conversion warnings

... by making a lot of objects unsigned, and some signed.
casts which lose precision and change the sign in one go (ssize_t and
time_t to uint on LP64) are made explicit as well.
1.4
Oswald Buddenhagen 5 years ago
parent
commit
e2d3b4d55b
  1. 22
      src/common.h
  2. 21
      src/config.c
  3. 2
      src/config.h
  4. 4
      src/driver.c
  5. 12
      src/driver.h
  6. 95
      src/drv_imap.c
  7. 95
      src/drv_maildir.c
  8. 16
      src/drv_proxy.c
  9. 9
      src/main.c
  10. 58
      src/socket.c
  11. 18
      src/socket.h
  12. 47
      src/sync.c
  13. 2
      src/sync.h
  14. 52
      src/util.c

22
src/common.h

@ -41,7 +41,7 @@ typedef unsigned long ulong;
#define stringify(x) stringify__(x) #define stringify(x) stringify__(x)
#define shifted_bit(in, from, to) \ #define shifted_bit(in, from, to) \
(((uint)(in) / (from > to ? from / to : 1) * (to > from ? to / from : 1)) & to) ((int)(((uint)(in) / (from > to ? from / to : 1) * (to > from ? to / from : 1)) & to))
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
# define ATTR_UNUSED __attribute__((unused)) # define ATTR_UNUSED __attribute__((unused))
@ -112,7 +112,7 @@ extern int Pid;
extern char Hostname[256]; extern char Hostname[256];
extern const char *Home; extern const char *Home;
extern int BufferLimit; extern uint BufferLimit;
extern int new_total[2], new_done[2]; extern int new_total[2], new_done[2];
extern int flags_total[2], flags_done[2]; extern int flags_total[2], flags_done[2];
@ -139,7 +139,7 @@ typedef struct string_list {
char string[1]; char string[1];
} ATTR_PACKED(void *) string_list_t; } ATTR_PACKED(void *) string_list_t;
void add_string_list_n( string_list_t **list, const char *str, int len ); void add_string_list_n( string_list_t **list, const char *str, uint len );
void add_string_list( string_list_t **list, const char *str ); void add_string_list( string_list_t **list, const char *str );
void free_string_list( string_list_t *list ); void free_string_list( string_list_t *list );
@ -150,9 +150,9 @@ void *memrchr( const void *s, int c, size_t n );
size_t strnlen( const char *str, size_t maxlen ); size_t strnlen( const char *str, size_t maxlen );
#endif #endif
int starts_with( const char *str, int strl, const char *cmp, int cmpl ); int starts_with( const char *str, int strl, const char *cmp, uint cmpl );
int starts_with_upper( const char *str, int strl, const char *cmp, int cmpl ); int starts_with_upper( const char *str, int strl, const char *cmp, uint cmpl );
int equals( const char *str, int strl, const char *cmp, int cmpl ); int equals( const char *str, int strl, const char *cmp, uint cmpl );
#ifndef HAVE_TIMEGM #ifndef HAVE_TIMEGM
time_t timegm( struct tm *tm ); time_t timegm( struct tm *tm );
@ -170,16 +170,16 @@ void ATTR_NORETURN oob( void );
char *expand_strdup( const char *s ); char *expand_strdup( const char *s );
int map_name( const char *arg, char **result, int reserve, const char *in, const char *out ); int map_name( const char *arg, char **result, uint reserve, const char *in, const char *out );
#define DEFINE_ARRAY_TYPE(T) \ #define DEFINE_ARRAY_TYPE(T) \
typedef struct { \ typedef struct { \
T *data; \ T *data; \
int size; \ uint size; \
} ATTR_PACKED(T *) T##_array_t; \ } ATTR_PACKED(T *) T##_array_t; \
typedef struct { \ typedef struct { \
T##_array_t array; \ T##_array_t array; \
int alloc; \ uint alloc; \
} ATTR_PACKED(T *) T##_array_alloc_t; \ } ATTR_PACKED(T *) T##_array_alloc_t; \
static INLINE T *T##_array_append( T##_array_alloc_t *arr ) \ static INLINE T *T##_array_append( T##_array_alloc_t *arr ) \
{ \ { \
@ -205,7 +205,7 @@ int find_uint_array( const uint_array_t array, uint value );
void arc4_init( void ); void arc4_init( void );
uchar arc4_getbyte( void ); uchar arc4_getbyte( void );
int bucketsForSize( int size ); uint bucketsForSize( uint size );
typedef struct list_head { typedef struct list_head {
struct list_head *next, *prev; struct list_head *next, *prev;
@ -216,7 +216,7 @@ typedef struct notifier {
void (*cb)( int what, void *aux ); void (*cb)( int what, void *aux );
void *aux; void *aux;
#ifdef HAVE_SYS_POLL_H #ifdef HAVE_SYS_POLL_H
int index; uint index;
#else #else
int fd; int fd;
short events; short events;

21
src/config.c

@ -121,13 +121,13 @@ parse_int( conffile_t *cfile )
return ret; return ret;
} }
int uint
parse_size( conffile_t *cfile ) parse_size( conffile_t *cfile )
{ {
char *p; char *p;
int ret; uint ret;
ret = strtol (cfile->val, &p, 10); ret = strtoul( cfile->val, &p, 10 );
if (*p == 'k' || *p == 'K') if (*p == 'k' || *p == 'K')
ret *= 1024, p++; ret *= 1024, p++;
else if (*p == 'm' || *p == 'M') else if (*p == 'm' || *p == 'M')
@ -319,7 +319,8 @@ load_config( const char *where, int pseudo )
group_conf_t *group, **groupapp = &groups; group_conf_t *group, **groupapp = &groups;
string_list_t *chanlist, **chanlistapp; string_list_t *chanlist, **chanlistapp;
char *arg, *p; char *arg, *p;
int len, cops, gcops, max_size, ms, i; uint len, max_size;
int cops, gcops, ms, i;
char path[_POSIX_PATH_MAX]; char path[_POSIX_PATH_MAX];
char buf[1024]; char buf[1024];
@ -354,7 +355,7 @@ load_config( const char *where, int pseudo )
if (drivers[i]->parse_store( &cfile, &store )) { if (drivers[i]->parse_store( &cfile, &store )) {
if (store) { if (store) {
if (!store->max_size) if (!store->max_size)
store->max_size = INT_MAX; store->max_size = UINT_MAX;
if (!store->flat_delim) if (!store->flat_delim)
store->flat_delim = ""; store->flat_delim = "";
*storeapp = store; *storeapp = store;
@ -371,7 +372,7 @@ load_config( const char *where, int pseudo )
channel->expire_unread = global_conf.expire_unread; channel->expire_unread = global_conf.expire_unread;
channel->use_internal_date = global_conf.use_internal_date; channel->use_internal_date = global_conf.use_internal_date;
cops = 0; cops = 0;
max_size = -1; max_size = UINT_MAX;
while (getcline( &cfile ) && cfile.cmd) { while (getcline( &cfile ) && cfile.cmd) {
if (!strcasecmp( "MaxSize", cfile.cmd )) if (!strcasecmp( "MaxSize", cfile.cmd ))
max_size = parse_size( &cfile ); max_size = parse_size( &cfile );
@ -422,9 +423,9 @@ load_config( const char *where, int pseudo )
} else if (merge_ops( cops, channel->ops )) } else if (merge_ops( cops, channel->ops ))
cfile.err = 1; cfile.err = 1;
else { else {
if (max_size >= 0) { if (max_size != UINT_MAX) {
if (!max_size) if (!max_size)
max_size = INT_MAX; max_size = UINT_MAX;
channel->stores[M]->max_size = channel->stores[S]->max_size = max_size; channel->stores[M]->max_size = channel->stores[S]->max_size = max_size;
} }
*channelapp = channel; *channelapp = channel;
@ -487,8 +488,8 @@ load_config( const char *where, int pseudo )
else if (!strcasecmp( "BufferLimit", cfile.cmd )) else if (!strcasecmp( "BufferLimit", cfile.cmd ))
{ {
BufferLimit = parse_size( &cfile ); BufferLimit = parse_size( &cfile );
if (BufferLimit <= 0) { if (!BufferLimit) {
error( "%s:%d: BufferLimit must be positive\n", cfile.file, cfile.line ); error( "%s:%d: BufferLimit cannot be zero\n", cfile.file, cfile.line );
cfile.err = 1; cfile.err = 1;
} }
} }

2
src/config.h

@ -42,7 +42,7 @@ char *get_arg( conffile_t *cfile, int required, int *comment );
char parse_bool( conffile_t *cfile ); char parse_bool( conffile_t *cfile );
int parse_int( conffile_t *cfile ); int parse_int( conffile_t *cfile );
int parse_size( conffile_t *cfile ); uint parse_size( conffile_t *cfile );
int getcline( conffile_t *cfile ); int getcline( conffile_t *cfile );
int merge_ops( int cops, int ops[] ); int merge_ops( int cops, int ops[] );
int load_config( const char *filename, int pseudo ); int load_config( const char *filename, int pseudo );

4
src/driver.c

@ -27,10 +27,10 @@
driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver }; driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver };
int uint
count_generic_messages( message_t *msgs ) count_generic_messages( message_t *msgs )
{ {
int count = 0; uint count = 0;
for (; msgs; msgs = msgs->next) for (; msgs; msgs = msgs->next)
count++; count++;
return count; return count;

12
src/driver.h

@ -39,7 +39,7 @@ typedef struct store_conf {
const char *flat_delim; const char *flat_delim;
const char *map_inbox; const char *map_inbox;
const char *trash; const char *trash;
int max_size; /* off_t is overkill */ uint max_size; /* off_t is overkill */
char trash_remote_new, trash_only_new; char trash_remote_new, trash_only_new;
} store_conf_t; } store_conf_t;
@ -67,7 +67,7 @@ typedef struct message {
struct sync_rec *srec; struct sync_rec *srec;
char *msgid; /* owned */ char *msgid; /* owned */
/* string_list_t *keywords; */ /* string_list_t *keywords; */
int size; /* zero implies "not fetched" */ uint size; /* zero implies "not fetched" */
uint uid; uint uid;
uchar flags, status; uchar flags, status;
char tuid[TUIDL]; char tuid[TUIDL];
@ -95,7 +95,7 @@ typedef struct store {
typedef struct { typedef struct {
char *data; char *data;
int len; uint len;
time_t date; time_t date;
uchar flags; uchar flags;
} msg_data_t; } msg_data_t;
@ -127,7 +127,7 @@ typedef struct {
#define LIST_PATH 2 #define LIST_PATH 2
#define LIST_PATH_MAYBE 4 #define LIST_PATH_MAYBE 4
#define xint int // For auto-generation of appropriate printf() formats. #define xint uint // For auto-generation of appropriate printf() formats.
struct driver { struct driver {
/* Return driver capabilities. */ /* Return driver capabilities. */
@ -258,13 +258,13 @@ struct driver {
void (*commit_cmds)( store_t *ctx ); void (*commit_cmds)( store_t *ctx );
/* Get approximate amount of memory occupied by the driver. */ /* Get approximate amount of memory occupied by the driver. */
int (*get_memory_usage)( store_t *ctx ); uint (*get_memory_usage)( store_t *ctx );
/* Get the FAIL_* state of the driver. */ /* Get the FAIL_* state of the driver. */
int (*get_fail_state)( store_conf_t *conf ); int (*get_fail_state)( store_conf_t *conf );
}; };
int count_generic_messages( message_t * ); uint count_generic_messages( message_t * );
void free_generic_messages( message_t * ); void free_generic_messages( message_t * );
void parse_generic_store( store_conf_t *store, conffile_t *cfg ); void parse_generic_store( store_conf_t *store, conffile_t *cfg );

95
src/drv_imap.c

@ -53,7 +53,7 @@ typedef struct imap_server_conf {
char *pass; char *pass;
char *pass_cmd; char *pass_cmd;
int max_in_progress; int max_in_progress;
int cap_mask; uint cap_mask;
string_list_t *auth_mechs; string_list_t *auth_mechs;
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
char ssl_type; char ssl_type;
@ -71,7 +71,7 @@ typedef struct {
typedef struct { typedef struct {
message_t gen; message_t gen;
/* int seq; will be needed when expunges are tracked */ /* uint seq; will be needed when expunges are tracked */
} imap_message_t; } imap_message_t;
#define NIL (void*)0x1 #define NIL (void*)0x1
@ -80,7 +80,7 @@ typedef struct {
typedef struct _list { typedef struct _list {
struct _list *next, *child; struct _list *next, *child;
char *val; char *val;
int len; uint len;
} list_t; } list_t;
#define MAX_LIST_DEPTH 5 #define MAX_LIST_DEPTH 5
@ -100,7 +100,7 @@ struct imap_store {
const char *label; /* foreign */ const char *label; /* foreign */
const char *prefix; const char *prefix;
const char *name; const char *name;
int ref_count; uint ref_count;
uint opts; uint opts;
enum { SST_BAD, SST_HALF, SST_GOOD } state; enum { SST_BAD, SST_HALF, SST_GOOD } state;
/* trash folder's existence is not confirmed yet */ /* trash folder's existence is not confirmed yet */
@ -124,7 +124,7 @@ struct imap_store {
int nexttag, num_in_progress; int nexttag, num_in_progress;
imap_cmd_t *pending, **pending_append; imap_cmd_t *pending, **pending_append;
imap_cmd_t *in_progress, **in_progress_append; imap_cmd_t *in_progress, **in_progress_append;
int buffer_mem; /* memory currently occupied by buffers in the queue */ uint buffer_mem; /* memory currently occupied by buffers in the queue */
/* Used during sequential operations like connect */ /* Used during sequential operations like connect */
enum { GreetingPending = 0, GreetingBad, GreetingOk, GreetingPreauth } greeting; enum { GreetingPending = 0, GreetingBad, GreetingOk, GreetingPreauth } greeting;
@ -158,7 +158,7 @@ struct imap_cmd {
int (*cont)( imap_store_t *ctx, imap_cmd_t *cmd, const char *prompt ); int (*cont)( imap_store_t *ctx, imap_cmd_t *cmd, const char *prompt );
void (*done)( imap_store_t *ctx, imap_cmd_t *cmd, int response ); void (*done)( imap_store_t *ctx, imap_cmd_t *cmd, int response );
char *data; char *data;
int data_len; uint data_len;
uint uid; /* to identify fetch responses */ uint uid; /* to identify fetch responses */
char high_prio; /* if command is queued, put it at the front of the queue. */ char high_prio; /* if command is queued, put it at the front of the queue. */
char to_trash; /* we are storing to trash, not current. */ char to_trash; /* we are storing to trash, not current. */
@ -195,7 +195,7 @@ typedef struct {
} imap_cmd_find_new_t; } imap_cmd_find_new_t;
typedef struct { typedef struct {
int ref_count; uint ref_count;
int ret_val; int ret_val;
} imap_cmd_refcounted_state_t; } imap_cmd_refcounted_state_t;
@ -258,7 +258,7 @@ static const char *Flags[] = {
}; };
static imap_cmd_t * static imap_cmd_t *
new_imap_cmd( int size ) new_imap_cmd( uint size )
{ {
imap_cmd_t *cmd = nfmalloc( size ); imap_cmd_t *cmd = nfmalloc( size );
memset( &cmd->param, 0, sizeof(cmd->param) ); memset( &cmd->param, 0, sizeof(cmd->param) );
@ -290,7 +290,8 @@ done_imap_cmd( imap_store_t *ctx, imap_cmd_t *cmd, int response )
static void static void
send_imap_cmd( imap_store_t *ctx, imap_cmd_t *cmd ) send_imap_cmd( imap_store_t *ctx, imap_cmd_t *cmd )
{ {
int bufl, litplus, iovcnt = 1; int litplus, iovcnt = 1;
int bufl;
const char *buffmt; const char *buffmt;
conn_iovec_t iov[3]; conn_iovec_t iov[3];
char buf[4096]; char buf[4096];
@ -323,7 +324,7 @@ DIAG_POP
fflush( stdout ); fflush( stdout );
} }
iov[0].buf = buf; iov[0].buf = buf;
iov[0].len = bufl; iov[0].len = (uint)bufl;
iov[0].takeOwn = KeepOwn; iov[0].takeOwn = KeepOwn;
if (litplus) { if (litplus) {
if (DFlags & DEBUG_NET_ALL) { if (DFlags & DEBUG_NET_ALL) {
@ -451,7 +452,6 @@ imap_vprintf( const char *fmt, va_list ap )
{ {
const char *s; const char *s;
char *d, *ed; char *d, *ed;
int maxlen;
char c; char c;
char buf[4096]; char buf[4096];
@ -461,14 +461,14 @@ imap_vprintf( const char *fmt, va_list ap )
for (;;) { for (;;) {
c = *fmt; c = *fmt;
if (!c || c == '%') { if (!c || c == '%') {
int l = fmt - s; uint l = fmt - s;
if (d + l > ed) if (d + l > ed)
oob(); oob();
memcpy( d, s, l ); memcpy( d, s, l );
d += l; d += l;
if (!c) if (!c)
return nfstrndup( buf, d - buf ); return nfstrndup( buf, (size_t)(d - buf) );
maxlen = INT_MAX; uint maxlen = UINT_MAX;
c = *++fmt; c = *++fmt;
if (c == '\\') { if (c == '\\') {
c = *++fmt; c = *++fmt;
@ -491,7 +491,7 @@ imap_vprintf( const char *fmt, va_list ap )
fputs( "Fatal: unsupported string length specification. Please report a bug.\n", stderr ); fputs( "Fatal: unsupported string length specification. Please report a bug.\n", stderr );
abort(); abort();
} }
maxlen = va_arg( ap , int ); maxlen = va_arg( ap, uint );
c = *++fmt; c = *++fmt;
} }
if (c == 'c') { if (c == 'c') {
@ -578,7 +578,7 @@ imap_done_simple_msg( imap_store_t *ctx ATTR_UNUSED,
} }
static imap_cmd_refcounted_state_t * static imap_cmd_refcounted_state_t *
imap_refcounted_new_state( int sz ) imap_refcounted_new_state( uint sz )
{ {
imap_cmd_refcounted_state_t *sts = nfmalloc( sz ); imap_cmd_refcounted_state_t *sts = nfmalloc( sz );
sts->ref_count = 1; /* so forced sync does not cause an early exit */ sts->ref_count = 1; /* so forced sync does not cause an early exit */
@ -787,7 +787,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
goto next2; goto next2;
} else if (ctx && *s == '{') { } else if (ctx && *s == '{') {
/* literal */ /* literal */
bytes = cur->len = strtol( s + 1, &s, 10 ); bytes = (int)(cur->len = strtoul( s + 1, &s, 10 ));
if (*s != '}' || *++s) if (*s != '}' || *++s)
goto bail; goto bail;
@ -795,7 +795,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
s[cur->len] = 0; s[cur->len] = 0;
getbytes: getbytes:
n = socket_read( &ctx->conn, s, bytes ); n = socket_read( &ctx->conn, s, (uint)bytes );
if (n < 0) { if (n < 0) {
badeof: badeof:
error( "IMAP error: unexpected EOF from %s\n", ctx->conn.name ); error( "IMAP error: unexpected EOF from %s\n", ctx->conn.name );
@ -832,7 +832,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
goto bail; goto bail;
*d++ = c; *d++ = c;
} }
cur->len = d - p; cur->len = (uint)(d - p);
cur->val = nfstrndup( p, cur->len ); cur->val = nfstrndup( p, cur->len );
} else { } else {
/* atom */ /* atom */
@ -840,8 +840,8 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
for (; *s && !isspace( (uchar)*s ); s++) for (; *s && !isspace( (uchar)*s ); s++)
if (sts->level && *s == ')') if (sts->level && *s == ')')
break; break;
cur->len = s - p; cur->len = (uint)(s - p);
if (equals( p, cur->len, "NIL", 3 )) if (equals( p, (int)cur->len, "NIL", 3 ))
cur->val = NIL; cur->val = NIL;
else else
cur->val = nfstrndup( p, cur->len ); cur->val = nfstrndup( p, cur->len );
@ -975,8 +975,8 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
imap_message_t *cur; imap_message_t *cur;
msg_data_t *msgdata; msg_data_t *msgdata;
imap_cmd_t *cmdp; imap_cmd_t *cmdp;
int mask = 0, status = 0, size = 0; uchar mask = 0, status = 0;
uint i, uid = 0; uint i, uid = 0, size = 0;
time_t date = 0; time_t date = 0;
if (!is_list( list )) { if (!is_list( list )) {
@ -1080,7 +1080,7 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
in_msgid = 1; in_msgid = 1;
continue; continue;
} }
msgid = nfstrndup( val + off, len - off ); msgid = nfstrndup( val + off, (size_t)(len - off) );
in_msgid = 0; in_msgid = 0;
} }
} else { } else {
@ -1291,7 +1291,8 @@ parse_list_rsp_p2( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED )
{ {
string_list_t *narg; string_list_t *narg;
char *arg; char *arg;
int argl, l; int argl;
uint l;
if (!is_atom( list )) { if (!is_atom( list )) {
error( "IMAP error: malformed LIST response\n" ); error( "IMAP error: malformed LIST response\n" );
@ -1299,7 +1300,7 @@ parse_list_rsp_p2( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED )
return LIST_BAD; return LIST_BAD;
} }
arg = list->val; arg = list->val;
argl = list->len; argl = (int)list->len;
if (is_inbox( ctx, arg, argl )) { if (is_inbox( ctx, arg, argl )) {
// The server might be weird and have a non-uppercase INBOX. It // The server might be weird and have a non-uppercase INBOX. It
// may legitimately do so, but we need the canonical spelling. // may legitimately do so, but we need the canonical spelling.
@ -1335,7 +1336,7 @@ parse_list_rsp_p2( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED )
static int static int
prepare_name( char **buf, const imap_store_t *ctx, const char *prefix, const char *name ) prepare_name( char **buf, const imap_store_t *ctx, const char *prefix, const char *name )
{ {
int pl = strlen( prefix ); uint pl = strlen( prefix );
switch (map_name( name, buf, pl, "/", ctx->delimiter )) { switch (map_name( name, buf, pl, "/", ctx->delimiter )) {
case -1: case -1:
@ -2172,7 +2173,7 @@ imap_open_store_authenticate2( imap_store_t *ctx )
skipped_login = 1; skipped_login = 1;
#ifdef HAVE_LIBSASL #ifdef HAVE_LIBSASL
} else { } else {
int len = strlen( cmech->string ); uint len = strlen( cmech->string );
if (saslend + len + 2 > saslmechs + sizeof(saslmechs)) if (saslend + len + 2 > saslmechs + sizeof(saslmechs))
oob(); oob();
*saslend++ = ' '; *saslend++ = ' ';
@ -2567,8 +2568,8 @@ imap_finish_delete_box( store_t *gctx ATTR_UNUSED )
/******************* imap_load_box *******************/ /******************* imap_load_box *******************/
static int static uint
imap_prepare_load_box( store_t *gctx, int opts ) imap_prepare_load_box( store_t *gctx, uint opts )
{ {
imap_store_t *ctx = (imap_store_t *)gctx; imap_store_t *ctx = (imap_store_t *)gctx;
@ -2578,14 +2579,15 @@ imap_prepare_load_box( store_t *gctx, int opts )
enum { WantSize = 1, WantTuids = 2, WantMsgids = 4 }; enum { WantSize = 1, WantTuids = 2, WantMsgids = 4 };
typedef struct { typedef struct {
int first, last, flags; uint first, last;
int flags;
} imap_range_t; } imap_range_t;
static void static void
imap_set_range( imap_range_t *ranges, int *nranges, int low_flags, int high_flags, int maxlow ) imap_set_range( imap_range_t *ranges, uint *nranges, int low_flags, int high_flags, uint maxlow )
{ {
if (low_flags != high_flags) { if (low_flags != high_flags) {
for (int r = 0; r < *nranges; r++) { for (uint r = 0; r < *nranges; r++) {
if (ranges[r].first > maxlow) if (ranges[r].first > maxlow)
break; /* Range starts above split point; so do all subsequent ranges. */ break; /* Range starts above split point; so do all subsequent ranges. */
if (ranges[r].last < maxlow) if (ranges[r].last < maxlow)
@ -2599,7 +2601,7 @@ imap_set_range( imap_range_t *ranges, int *nranges, int low_flags, int high_flag
break; break;
} }
} }
for (int r = 0; r < *nranges; r++) for (uint r = 0; r < *nranges; r++)
ranges[r].flags |= (ranges[r].last <= maxlow) ? low_flags : high_flags; ranges[r].flags |= (ranges[r].last <= maxlow) ? low_flags : high_flags;
} }
@ -2617,7 +2619,6 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint seenui
void (*cb)( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux ), void *aux ) void (*cb)( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux ), void *aux )
{ {
imap_store_t *ctx = (imap_store_t *)gctx; imap_store_t *ctx = (imap_store_t *)gctx;
int i, j, bl;
char buf[1000]; char buf[1000];
if (!ctx->total_msgs) { if (!ctx->total_msgs) {
@ -2625,12 +2626,12 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint seenui
cb( DRV_OK, 0, 0, 0, aux ); cb( DRV_OK, 0, 0, 0, aux );
} else { } else {
INIT_REFCOUNTED_STATE(imap_load_box_state_t, sts, cb, aux) INIT_REFCOUNTED_STATE(imap_load_box_state_t, sts, cb, aux)
for (i = 0; i < excs.size; ) { for (uint i = 0; i < excs.size; ) {
for (bl = 0; i < excs.size && bl < 960; i++) { for (int bl = 0; i < excs.size && bl < 960; i++) {
if (bl) if (bl)
buf[bl++] = ','; buf[bl++] = ',';
bl += sprintf( buf + bl, "%u", excs.data[i] ); bl += sprintf( buf + bl, "%u", excs.data[i] );
j = i; uint j = i;
for (; i + 1 < excs.size && excs.data[i + 1] == excs.data[i] + 1; i++) {} for (; i + 1 < excs.size && excs.data[i + 1] == excs.data[i] + 1; i++) {}
if (i != j) if (i != j)
bl += sprintf( buf + bl, ":%u", excs.data[i] ); bl += sprintf( buf + bl, ":%u", excs.data[i] );
@ -2644,7 +2645,7 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint seenui
ranges[0].first = minuid; ranges[0].first = minuid;
ranges[0].last = maxuid; ranges[0].last = maxuid;
ranges[0].flags = 0; ranges[0].flags = 0;
int nranges = 1; uint nranges = 1;
if (ctx->opts & (OPEN_OLD_SIZE | OPEN_NEW_SIZE)) if (ctx->opts & (OPEN_OLD_SIZE | OPEN_NEW_SIZE))
imap_set_range( ranges, &nranges, shifted_bit( ctx->opts, OPEN_OLD_SIZE, WantSize), imap_set_range( ranges, &nranges, shifted_bit( ctx->opts, OPEN_OLD_SIZE, WantSize),
shifted_bit( ctx->opts, OPEN_NEW_SIZE, WantSize), seenuid ); shifted_bit( ctx->opts, OPEN_NEW_SIZE, WantSize), seenuid );
@ -2652,7 +2653,7 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint seenui
imap_set_range( ranges, &nranges, 0, WantTuids, newuid - 1 ); imap_set_range( ranges, &nranges, 0, WantTuids, newuid - 1 );
if (ctx->opts & OPEN_OLD_IDS) if (ctx->opts & OPEN_OLD_IDS)
imap_set_range( ranges, &nranges, WantMsgids, 0, seenuid ); imap_set_range( ranges, &nranges, WantMsgids, 0, seenuid );
for (int r = 0; r < nranges; r++) { for (uint r = 0; r < nranges; r++) {
sprintf( buf, "%u:%u", ranges[r].first, ranges[r].last ); sprintf( buf, "%u:%u", ranges[r].first, ranges[r].last );
imap_submit_load( ctx, buf, ranges[r].flags, sts ); imap_submit_load( ctx, buf, ranges[r].flags, sts );
} }
@ -2678,14 +2679,14 @@ imap_sort_msgs_comp( const void *a_, const void *b_ )
static void static void
imap_sort_msgs( imap_store_t *ctx ) imap_sort_msgs( imap_store_t *ctx )
{ {
int count = count_generic_messages( ctx->msgs ); uint count = count_generic_messages( ctx->msgs );
if (count <= 1) if (count <= 1)
return; return;
message_t **t = nfmalloc( sizeof(*t) * count ); message_t **t = nfmalloc( sizeof(*t) * count );
message_t *m = ctx->msgs; message_t *m = ctx->msgs;
for (int i = 0; i < count; i++) { for (uint i = 0; i < count; i++) {
t[i] = m; t[i] = m;
m = m->next; m = m->next;
} }
@ -2694,7 +2695,7 @@ imap_sort_msgs( imap_store_t *ctx )
ctx->msgs = t[0]; ctx->msgs = t[0];
int j; uint j;
for (j = 0; j < count - 1; j++) for (j = 0; j < count - 1; j++)
t[j]->next = t[j + 1]; t[j]->next = t[j + 1];
ctx->msgapp = &t[j]->next; ctx->msgapp = &t[j]->next;
@ -2771,7 +2772,7 @@ imap_fetch_msg_p2( imap_store_t *ctx, imap_cmd_t *gcmd, int response )
/******************* imap_set_msg_flags *******************/ /******************* imap_set_msg_flags *******************/
static int static uint
imap_make_flags( int flags, char *buf ) imap_make_flags( int flags, char *buf )
{ {
const char *s; const char *s;
@ -2946,7 +2947,7 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
imap_store_t *ctx = (imap_store_t *)gctx; imap_store_t *ctx = (imap_store_t *)gctx;
imap_cmd_out_uid_t *cmd; imap_cmd_out_uid_t *cmd;
char *buf; char *buf;
int d; uint d;
char flagstr[128], datestr[64]; char flagstr[128], datestr[64];
d = 0; d = 0;
@ -3166,7 +3167,7 @@ imap_commit_cmds( store_t *gctx )
/******************* imap_get_memory_usage *******************/ /******************* imap_get_memory_usage *******************/
static int static uint
imap_get_memory_usage( store_t *gctx ) imap_get_memory_usage( store_t *gctx )
{ {
imap_store_t *ctx = (imap_store_t *)gctx; imap_store_t *ctx = (imap_store_t *)gctx;
@ -3485,7 +3486,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
return 1; return 1;
} }
static int static uint
imap_get_caps( store_t *gctx ATTR_UNUSED ) imap_get_caps( store_t *gctx ATTR_UNUSED )
{ {
return DRV_CRLF | DRV_VERBOSE; return DRV_CRLF | DRV_VERBOSE;

95
src/drv_maildir.c

@ -69,9 +69,8 @@ typedef struct {
typedef struct { typedef struct {
store_t gen; store_t gen;
uint opts;
int uvfd, uvok, is_inbox, fresh[3]; int uvfd, uvok, is_inbox, fresh[3];
uint minuid, maxuid, newuid, seenuid, uidvalidity, nuid; uint opts, minuid, maxuid, newuid, seenuid, uidvalidity, nuid;
uint_array_t excs; uint_array_t excs;
char *path; /* own */ char *path; /* own */
char *trash; char *trash;
@ -146,7 +145,7 @@ maildir_join_path( maildir_store_conf_t *conf, int in_inbox, const char *box )
{ {
char *out, *p; char *out, *p;
const char *prefix; const char *prefix;
int pl, bl, n; uint pl, bl, n;
char c; char c;
if (in_inbox || conf->sub_style == SUB_MAILDIRPP) { if (in_inbox || conf->sub_style == SUB_MAILDIRPP) {
@ -389,7 +388,7 @@ static int maildir_list_path( maildir_store_t *ctx, int flags, const char *inbox
static int static int
maildir_list_recurse( maildir_store_t *ctx, int isBox, int flags, maildir_list_recurse( maildir_store_t *ctx, int isBox, int flags,
const char *inbox, int inboxLen, const char *basePath, int basePathLen, const char *inbox, uint inboxLen, const char *basePath, uint basePathLen,
char *path, int pathLen, char *name, int nameLen ) char *path, int pathLen, char *name, int nameLen )
{ {
DIR *dir; DIR *dir;
@ -525,7 +524,7 @@ static const char *subdirs[] = { "cur", "new", "tmp" };
typedef struct { typedef struct {
char *base; char *base;
char *msgid; char *msgid;
int size; uint size;
uint uid; uint uid;
uchar recent; uchar recent;
char tuid[TUIDL]; char tuid[TUIDL];
@ -536,7 +535,7 @@ DEFINE_ARRAY_TYPE(msg_t)
static void static void
maildir_free_scan( msg_t_array_alloc_t *msglist ) maildir_free_scan( msg_t_array_alloc_t *msglist )
{ {
int i; uint i;
if (msglist->array.data) { if (msglist->array.data) {
for (i = 0; i < msglist->array.size; i++) for (i = 0; i < msglist->array.size; i++)
@ -587,7 +586,7 @@ make_box_dir( char *buf, int bl )
if (!mkdir( buf, 0700 ) || errno == EEXIST) if (!mkdir( buf, 0700 ) || errno == EEXIST)
return 0; return 0;
p = memrchr( buf, '/', bl - 1 ); p = memrchr( buf, '/', (size_t)bl - 1 );
*p = 0; *p = 0;
if (make_box_dir( buf, (int)(p - buf) )) if (make_box_dir( buf, (int)(p - buf) ))
return -1; return -1;
@ -688,7 +687,7 @@ maildir_store_uidval( maildir_store_t *ctx )
{ {
n = sprintf( buf, "%u\n%u\n", ctx->uidvalidity, ctx->nuid ); n = sprintf( buf, "%u\n%u\n", ctx->uidvalidity, ctx->nuid );
lseek( ctx->uvfd, 0, SEEK_SET ); lseek( ctx->uvfd, 0, SEEK_SET );
if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n ) || (UseFSync && fdatasync( ctx->uvfd ))) { if (write( ctx->uvfd, buf, (uint)n ) != n || ftruncate( ctx->uvfd, n ) || (UseFSync && fdatasync( ctx->uvfd ))) {
error( "Maildir error: cannot write UIDVALIDITY.\n" ); error( "Maildir error: cannot write UIDVALIDITY.\n" );
return DRV_BOX_BAD; return DRV_BOX_BAD;
} }
@ -849,7 +848,8 @@ maildir_compare( const void *l, const void *r )
{ {
const msg_t *lm = (const msg_t *)l, *rm = (const msg_t *)r; const msg_t *lm = (const msg_t *)l, *rm = (const msg_t *)r;
char *ldot, *rdot, *ldot2, *rdot2, *lseq, *rseq; char *ldot, *rdot, *ldot2, *rdot2, *lseq, *rseq;
int ret, llen, rlen; uint llen, rlen;
int ret;
if (lm->uid != rm->uid) // Can't subtract, the result might not fit into signed int. if (lm->uid != rm->uid) // Can't subtract, the result might not fit into signed int.
return lm->uid > rm->uid ? 1 : -1; return lm->uid > rm->uid ? 1 : -1;
@ -860,21 +860,21 @@ maildir_compare( const void *l, const void *r )
faster than numeric. */ faster than numeric. */
if (!(ldot = strchr( lm->base, '.' )) || !(rdot = strchr( rm->base, '.' ))) if (!(ldot = strchr( lm->base, '.' )) || !(rdot = strchr( rm->base, '.' )))
goto stronly; /* Should never happen ... */ goto stronly; /* Should never happen ... */
llen = ldot - lm->base, rlen = rdot - rm->base; llen = (uint)(ldot - lm->base), rlen = (uint)(rdot - rm->base);
/* The shorter number is smaller. Really. This won't trigger with any /* The shorter number is smaller. Really. This won't trigger with any
mail created after Sep 9 2001 anyway. */ mail created after Sep 9 2001 anyway. */
if ((ret = llen - rlen)) if ((ret = (int)llen - (int)rlen))
return ret; return ret;
if ((ret = memcmp( lm->base, rm->base, llen ))) if ((ret = memcmp( lm->base, rm->base, llen )))
return ret; return ret;
ldot++, rdot++; ldot++, rdot++;
if ((llen = strtol( ldot, &ldot2, 10 ))) { if ((llen = strtoul( ldot, &ldot2, 10 ))) {
if (!(rlen = strtol( rdot, &rdot2, 10 ))) if (!(rlen = strtoul( rdot, &rdot2, 10 )))
goto stronly; /* Comparing apples to oranges ... */ goto stronly; /* Comparing apples to oranges ... */
/* Classical PID specs */ /* Classical PID specs */
if ((ret = llen - rlen)) { if ((ret = (int)llen - (int)rlen)) {
retpid: retpid:
/* Handle PID wraparound. This works only on systems /* Handle PID wraparound. This works only on systems
where PIDs are not reused too fast */ where PIDs are not reused too fast */
@ -888,7 +888,7 @@ maildir_compare( const void *l, const void *r )
if (!(ldot2 = strchr( ldot, '.' )) || !(rdot2 = strchr( rdot, '.' ))) if (!(ldot2 = strchr( ldot, '.' )) || !(rdot2 = strchr( rdot, '.' )))
goto stronly; /* Should never happen ... */ goto stronly; /* Should never happen ... */
llen = ldot2 - ldot, rlen = rdot2 - rdot; llen = (uint)(ldot2 - ldot), rlen = (uint)(rdot2 - rdot);
if (((lseq = memchr( ldot, '#', llen )) && (rseq = memchr( rdot, '#', rlen ))) || if (((lseq = memchr( ldot, '#', llen )) && (rseq = memchr( rdot, '#', rlen ))) ||
((lseq = memchr( ldot, 'M', llen )) && (rseq = memchr( rdot, 'M', rlen )))) ((lseq = memchr( ldot, 'M', llen )) && (rseq = memchr( rdot, 'M', rlen ))))
@ -919,7 +919,8 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
DBC *dbc; DBC *dbc;
#endif /* USE_DB */ #endif /* USE_DB */
msg_t *entry; msg_t *entry;
int i, bl, fnl, ret; uint i;
int bl, fnl, ret;
uint uid; uint uid;
time_t now, stamps[2]; time_t now, stamps[2];
struct stat st; struct stat st;
@ -1053,7 +1054,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
ctx->db->err( ctx->db, ret, "Maildir error: db->c_get()" ); ctx->db->err( ctx->db, ret, "Maildir error: db->c_get()" );
break; break;
} }
if (!equals( key.data, key.size, "UIDVALIDITY", 11 ) && if (!equals( key.data, (int)key.size, "UIDVALIDITY", 11 ) &&
(ret = tdb->get( tdb, 0, &key, &value, 0 ))) { (ret = tdb->get( tdb, 0, &key, &value, 0 ))) {
if (ret != DB_NOTFOUND) { if (ret != DB_NOTFOUND) {
tdb->err( tdb, ret, "Maildir error: tdb->get()" ); tdb->err( tdb, ret, "Maildir error: tdb->get()" );
@ -1119,11 +1120,11 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
else else
u = ru = strchr( entry->base, conf->info_delimiter ); u = ru = strchr( entry->base, conf->info_delimiter );
fnl = (u ? fnl = (u ?
nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%.*s,U=%u%s", subdirs[entry->recent], (int)(u - entry->base), entry->base, uid, ru ) : nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, "%s/%.*s,U=%u%s", subdirs[entry->recent], (int)(u - entry->base), entry->base, uid, ru ) :
nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%s,U=%u", subdirs[entry->recent], entry->base, uid )) nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, "%s/%s,U=%u", subdirs[entry->recent], entry->base, uid ))
- 4; - 4;
memcpy( nbuf, buf, bl + 4 ); memcpy( nbuf, buf, (size_t)(bl + 4) );
nfsnprintf( nbuf + bl + 4, sizeof(nbuf) - bl - 4, "%s", entry->base ); nfsnprintf( nbuf + bl + 4, _POSIX_PATH_MAX - bl - 4, "%s", entry->base );
if (rename( nbuf, buf )) { if (rename( nbuf, buf )) {
if (errno != ENOENT) { if (errno != ENOENT) {
sys_error( "Maildir error: cannot rename %s to %s", nbuf, buf ); sys_error( "Maildir error: cannot rename %s to %s", nbuf, buf );
@ -1136,7 +1137,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
goto again; goto again;
} }
free( entry->base ); free( entry->base );
entry->base = nfstrndup( buf + bl + 4, fnl ); entry->base = nfstrndup( buf + bl + 4, (size_t)fnl );
} }
int want_size = (uid > ctx->seenuid) ? (ctx->opts & OPEN_NEW_SIZE) : (ctx->opts & OPEN_OLD_SIZE); int want_size = (uid > ctx->seenuid) ? (ctx->opts & OPEN_NEW_SIZE) : (ctx->opts & OPEN_OLD_SIZE);
int want_tuid = ((ctx->opts & OPEN_FIND) && uid >= ctx->newuid); int want_tuid = ((ctx->opts & OPEN_FIND) && uid >= ctx->newuid);
@ -1144,7 +1145,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
if (!want_size && !want_tuid && !want_msgid) if (!want_size && !want_tuid && !want_msgid)
continue; continue;
if (!fnl) if (!fnl)
nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%s", subdirs[entry->recent], entry->base ); nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, "%s/%s", subdirs[entry->recent], entry->base );
if (want_size) { if (want_size) {
if (stat( buf, &st )) { if (stat( buf, &st )) {
if (errno != ENOENT) { if (errno != ENOENT) {
@ -1153,7 +1154,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
} }
goto retry; goto retry;
} }
entry->size = st.st_size; entry->size = (uint)st.st_size;
} }
if (want_tuid || want_msgid) { if (want_tuid || want_msgid) {
if (!(f = fopen( buf, "r" ))) { if (!(f = fopen( buf, "r" ))) {
@ -1200,7 +1201,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
in_msgid = 1; in_msgid = 1;
continue; continue;
} }
entry->msgid = nfstrndup( lnbuf + off, bufl - off ); entry->msgid = nfstrndup( lnbuf + off, (size_t)(bufl - off) );
want_msgid = 0; want_msgid = 0;
in_msgid = 0; in_msgid = 0;
} }
@ -1383,11 +1384,11 @@ maildir_delete_box( store_t *gctx,
error( "Maildir error: '%s' is no valid mailbox\n", ctx->path ); error( "Maildir error: '%s' is no valid mailbox\n", ctx->path );
ret = DRV_BOX_BAD; ret = DRV_BOX_BAD;
} else if ((ret = maildir_clear_tmp( buf, sizeof(buf), bl )) == DRV_OK) { } else if ((ret = maildir_clear_tmp( buf, sizeof(buf), bl )) == DRV_OK) {
nfsnprintf( buf + bl, sizeof(buf) - bl, ".uidvalidity" ); nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, ".uidvalidity" );
if (unlink( buf ) && errno != ENOENT) if (unlink( buf ) && errno != ENOENT)
goto badrm; goto badrm;
#ifdef USE_DB #ifdef USE_DB
nfsnprintf( buf + bl, sizeof(buf) - bl, ".isyncuidmap.db" ); nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, ".isyncuidmap.db" );
if (unlink( buf ) && errno != ENOENT) if (unlink( buf ) && errno != ENOENT)
goto badrm; goto badrm;
#endif #endif
@ -1420,8 +1421,8 @@ maildir_finish_delete_box( store_t *gctx )
return DRV_OK; return DRV_OK;
} }
static int static uint
maildir_prepare_load_box( store_t *gctx, int opts ) maildir_prepare_load_box( store_t *gctx, uint opts )
{ {
maildir_store_t *ctx = (maildir_store_t *)gctx; maildir_store_t *ctx = (maildir_store_t *)gctx;
@ -1440,7 +1441,7 @@ maildir_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint see
maildir_store_t *ctx = (maildir_store_t *)gctx; maildir_store_t *ctx = (maildir_store_t *)gctx;
message_t **msgapp; message_t **msgapp;
msg_t_array_alloc_t msglist; msg_t_array_alloc_t msglist;
int i; uint i;
ctx->minuid = minuid; ctx->minuid = minuid;
ctx->maxuid = maxuid; ctx->maxuid = maxuid;
@ -1467,7 +1468,7 @@ maildir_rescan( maildir_store_t *ctx )
message_t **msgapp; message_t **msgapp;
maildir_message_t *msg; maildir_message_t *msg;
msg_t_array_alloc_t msglist; msg_t_array_alloc_t msglist;
int i; uint i;
ctx->fresh[0] = ctx->fresh[1] = 0; ctx->fresh[0] = ctx->fresh[1] = 0;
if (maildir_scan( ctx, &msglist ) != DRV_OK) if (maildir_scan( ctx, &msglist ) != DRV_OK)
@ -1567,14 +1568,14 @@ maildir_fetch_msg( store_t *gctx, message_t *gmsg, msg_data_t *data,
} }
static int static int
maildir_make_flags( char info_delimiter, int flags, char *buf ) maildir_make_flags( char info_delimiter, uchar flags, char *buf )
{ {
uint i, d; int i, d;
buf[0] = info_delimiter; buf[0] = info_delimiter;
buf[1] = '2'; buf[1] = '2';
buf[2] = ','; buf[2] = ',';
for (d = 3, i = 0; i < as(Flags); i++) for (d = 3, i = 0; i < (int)as(Flags); i++)
if (flags & (1 << i)) if (flags & (1 << i))
buf[d++] = Flags[i]; buf[d++] = Flags[i];
buf[d] = 0; buf[d] = 0;
@ -1608,7 +1609,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
cb( ret, 0, aux ); cb( ret, 0, aux );
return; return;
} }
nfsnprintf( base + bl, sizeof(base) - bl, ",U=%u", uid ); nfsnprintf( base + bl, (int)sizeof(base) - bl, ",U=%u", uid );
} }
box = ctx->path; box = ctx->path;
} else { } else {
@ -1639,7 +1640,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
} }
ret = write( fd, data->data, data->len ); ret = write( fd, data->data, data->len );
free( data->data ); free( data->data );
if (ret != data->len || (UseFSync && (ret = fsync( fd )))) { if (ret != (int)data->len || (UseFSync && (ret = fsync( fd )))) {
if (ret < 0) if (ret < 0)
sys_error( "Maildir error: cannot write %s", buf ); sys_error( "Maildir error: cannot write %s", buf );
else else
@ -1689,28 +1690,28 @@ maildir_set_msg_flags( store_t *gctx, message_t *gmsg, uint uid ATTR_UNUSED, int
char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX]; char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX];
bbl = nfsnprintf( buf, sizeof(buf), "%s/", ctx->path ); bbl = nfsnprintf( buf, sizeof(buf), "%s/", ctx->path );
memcpy( nbuf, ctx->path, bbl - 1 ); memcpy( nbuf, ctx->path, (size_t)bbl - 1 );
memcpy( nbuf + bbl - 1, "/cur/", 5 ); memcpy( nbuf + bbl - 1, "/cur/", 5 );
for (;;) { for (;;) {
bl = bbl + nfsnprintf( buf + bbl, sizeof(buf) - bbl, "%s/", subdirs[gmsg->status & M_RECENT] ); bl = bbl + nfsnprintf( buf + bbl, _POSIX_PATH_MAX - bbl, "%s/", subdirs[gmsg->status & M_RECENT] );
ol = strlen( msg->base ); ol = strlen( msg->base );
if ((int)sizeof(buf) - bl < ol + 3 + NUM_FLAGS) if (_POSIX_PATH_MAX - bl < ol + 3 + NUM_FLAGS)
oob(); oob();
memcpy( buf + bl, msg->base, ol + 1 ); memcpy( buf + bl, msg->base, (size_t)ol + 1 );
memcpy( nbuf + bl, msg->base, ol + 1 ); memcpy( nbuf + bl, msg->base, (size_t)ol + 1 );
if ((s = strstr( nbuf + bl, conf->info_prefix ))) { if ((s = strstr( nbuf + bl, conf->info_prefix ))) {
s += 3; s += 3;
fl = ol - (s - (nbuf + bl)); fl = ol - (s - (nbuf + bl));
for (i = 0; i < as(Flags); i++) { for (i = 0; i < as(Flags); i++) {
if ((p = strchr( s, Flags[i] ))) { if ((p = strchr( s, Flags[i] ))) {
if (del & (1 << i)) { if (del & (1 << i)) {
memmove( p, p + 1, fl - (p - s) ); memmove( p, p + 1, (size_t)fl - (size_t)(p - s) );
fl--; fl--;
} }
} else if (add & (1 << i)) { } else if (add & (1 << i)) {
for (j = 0; j < fl && Flags[i] > s[j]; j++); for (j = 0; j < fl && Flags[i] > s[j]; j++);
fl++; fl++;
memmove( s + j + 1, s + j, fl - j ); memmove( s + j + 1, s + j, (size_t)(fl - j) );
s[j] = Flags[i]; s[j] = Flags[i];
} }
} }
@ -1726,7 +1727,7 @@ maildir_set_msg_flags( store_t *gctx, message_t *gmsg, uint uid ATTR_UNUSED, int
} }
} }
free( msg->base ); free( msg->base );
msg->base = nfstrndup( nbuf + bl, tl ); msg->base = nfstrndup( nbuf + bl, (size_t)tl );
msg->gen.flags |= add; msg->gen.flags |= add;
msg->gen.flags &= ~del; msg->gen.flags &= ~del;
gmsg->status &= ~M_RECENT; gmsg->status &= ~M_RECENT;
@ -1813,7 +1814,7 @@ maildir_close_box( store_t *gctx,
basel = nfsnprintf( buf, sizeof(buf), "%s/", ctx->path ); basel = nfsnprintf( buf, sizeof(buf), "%s/", ctx->path );
for (msg = ctx->msgs; msg; msg = msg->next) for (msg = ctx->msgs; msg; msg = msg->next)
if (!(msg->status & M_DEAD) && (msg->flags & F_DELETED)) { if (!(msg->status & M_DEAD) && (msg->flags & F_DELETED)) {
nfsnprintf( buf + basel, sizeof(buf) - basel, "%s/%s", subdirs[msg->status & M_RECENT], ((maildir_message_t *)msg)->base ); nfsnprintf( buf + basel, _POSIX_PATH_MAX - basel, "%s/%s", subdirs[msg->status & M_RECENT], ((maildir_message_t *)msg)->base );
if (unlink( buf )) { if (unlink( buf )) {
if (errno == ENOENT) if (errno == ENOENT)
retry = 1; retry = 1;
@ -1854,7 +1855,7 @@ maildir_commit_cmds( store_t *gctx )
(void) gctx; (void) gctx;
} }
static int static uint
maildir_get_memory_usage( store_t *gctx ATTR_UNUSED ) maildir_get_memory_usage( store_t *gctx ATTR_UNUSED )
{ {
return 0; return 0;
@ -1924,7 +1925,7 @@ maildir_parse_store( conffile_t *cfg, store_conf_t **storep )
return 1; return 1;
} }
static int static uint
maildir_get_caps( store_t *gctx ATTR_UNUSED ) maildir_get_caps( store_t *gctx ATTR_UNUSED )
{ {
return 0; /* XXX DRV_CRLF? */ return 0; /* XXX DRV_CRLF? */

16
src/drv_proxy.c

@ -27,7 +27,7 @@
typedef struct { typedef struct {
store_t gen; store_t gen;
const char *label; // foreign const char *label; // foreign
int ref_count; uint ref_count;
driver_t *real_driver; driver_t *real_driver;
store_t *real_store; store_t *real_store;
@ -61,7 +61,7 @@ debugn( const char *msg, ... )
static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' }; static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' };
static char * static char *
proxy_make_flags( int flags, char *buf ) proxy_make_flags( uchar flags, char *buf )
{ {
uint i, d; uint i, d;
@ -82,13 +82,13 @@ proxy_store_deref( proxy_store_t *ctx )
static int curr_tag; static int curr_tag;
typedef struct { typedef struct {
int ref_count; uint ref_count;
int tag; int tag;
proxy_store_t *ctx; proxy_store_t *ctx;
} gen_cmd_t; } gen_cmd_t;
static gen_cmd_t * static gen_cmd_t *
proxy_cmd_new( proxy_store_t *ctx, int sz ) proxy_cmd_new( proxy_store_t *ctx, uint sz )
{ {
gen_cmd_t *cmd = nfmalloc( sz ); gen_cmd_t *cmd = nfmalloc( sz );
cmd->ref_count = 2; cmd->ref_count = 2;
@ -203,7 +203,7 @@ proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), v
//# DEFINE load_box_print_args //# DEFINE load_box_print_args
if (excs.size) { if (excs.size) {
debugn( " excs:" ); debugn( " excs:" );
for (int t = 0; t < excs.size; t++) for (uint t = 0; t < excs.size; t++)
debugn( " %u", excs.data[t] ); debugn( " %u", excs.data[t] );
debug( "\n" ); debug( "\n" );
} }
@ -216,7 +216,7 @@ proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), v
//# DEFINE load_box_print_cb_args //# DEFINE load_box_print_cb_args
if (sts == DRV_OK) { if (sts == DRV_OK) {
for (message_t *msg = msgs; msg; msg = msg->next) for (message_t *msg = msgs; msg; msg = msg->next)
debug( " uid=%-5u flags=%-4s size=%-6d tuid=%." stringify(TUIDL) "s\n", debug( " uid=%-5u flags=%-4s size=%-6u tuid=%." stringify(TUIDL) "s\n",
msg->uid, (msg->status & M_FLAGS) ? (proxy_make_flags( msg->flags, fbuf ), fbuf) : "?", msg->size, *msg->tuid ? msg->tuid : "?" ); msg->uid, (msg->status & M_FLAGS) ? (proxy_make_flags( msg->flags, fbuf ), fbuf) : "?", msg->size, *msg->tuid ? msg->tuid : "?" );
} }
//# END //# END
@ -242,7 +242,7 @@ proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), v
static char fbuf[as(Flags) + 1]; static char fbuf[as(Flags) + 1];
proxy_make_flags( cmd->data->flags, fbuf ); proxy_make_flags( cmd->data->flags, fbuf );
//# END //# END
//# DEFINE fetch_msg_print_fmt_cb_args , flags=%s, date=%lld, size=%d //# DEFINE fetch_msg_print_fmt_cb_args , flags=%s, date=%lld, size=%u
//# DEFINE fetch_msg_print_pass_cb_args , fbuf, (long long)cmd->data->date, cmd->data->len //# DEFINE fetch_msg_print_pass_cb_args , fbuf, (long long)cmd->data->date, cmd->data->len
//# DEFINE fetch_msg_print_cb_args //# DEFINE fetch_msg_print_cb_args
if (sts == DRV_OK && (DFlags & DEBUG_DRV_ALL)) { if (sts == DRV_OK && (DFlags & DEBUG_DRV_ALL)) {
@ -257,7 +257,7 @@ proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), v
static char fbuf[as(Flags) + 1]; static char fbuf[as(Flags) + 1];
proxy_make_flags( data->flags, fbuf ); proxy_make_flags( data->flags, fbuf );
//# END //# END
//# DEFINE store_msg_print_fmt_args , flags=%s, date=%lld, size=%d, to_trash=%s //# DEFINE store_msg_print_fmt_args , flags=%s, date=%lld, size=%u, to_trash=%s
//# DEFINE store_msg_print_pass_args , fbuf, (long long)data->date, data->len, to_trash ? "yes" : "no" //# DEFINE store_msg_print_pass_args , fbuf, (long long)data->date, data->len, to_trash ? "yes" : "no"
//# DEFINE store_msg_print_args //# DEFINE store_msg_print_args
if (DFlags & DEBUG_DRV_ALL) { if (DFlags & DEBUG_DRV_ALL) {

9
src/main.c

@ -47,7 +47,7 @@ int Pid; /* for maildir and imap */
char Hostname[256]; /* for maildir */ char Hostname[256]; /* for maildir */
const char *Home; /* for config */ const char *Home; /* for config */
int BufferLimit = 10 * 1024 * 1024; uint BufferLimit = 10 * 1024 * 1024;
static int chans_total, chans_done; static int chans_total, chans_done;
static int boxes_total, boxes_done; static int boxes_total, boxes_done;
@ -264,7 +264,7 @@ filter_boxes( string_list_t *boxes, const char *prefix, string_list_t *patterns
string_list_t *cpat; string_list_t *cpat;
char **boxarr = 0; char **boxarr = 0;
const char *ps; const char *ps;
int not, fnot, pfxl, num = 0, rnum = 0; uint not, fnot, pfxl, num = 0, rnum = 0;
pfxl = prefix ? strlen( prefix ) : 0; pfxl = prefix ? strlen( prefix ) : 0;
for (; boxes; boxes = boxes->next) { for (; boxes; boxes = boxes->next) {
@ -350,7 +350,8 @@ add_named_channel( chan_ent_t ***chanapp, char *channame, int ops[] )
chan_ent_t *ce; chan_ent_t *ce;
box_ent_t *boxes = 0, **mboxapp = &boxes, *mbox; box_ent_t *boxes = 0, **mboxapp = &boxes, *mbox;
char *boxp, *nboxp; char *boxp, *nboxp;
int boxl, boxlist = 0; size_t boxl;
char boxlist = 0;
if ((boxp = strchr( channame, ':' ))) if ((boxp = strchr( channame, ':' )))
*boxp++ = 0; *boxp++ = 0;
@ -369,7 +370,7 @@ add_named_channel( chan_ent_t ***chanapp, char *channame, int ops[] )
do { do {
nboxp = strpbrk( boxp, ",\n" ); nboxp = strpbrk( boxp, ",\n" );
if (nboxp) { if (nboxp) {
boxl = nboxp - boxp; boxl = (size_t)(nboxp - boxp);
*nboxp++ = 0; *nboxp++ = 0;
} else { } else {
boxl = strlen( boxp ); boxl = strlen( boxp );

58
src/socket.c

@ -250,7 +250,7 @@ DIAG_POP
return 0; return 0;
} }
int options = SSL_OP_NO_SSLv3; uint options = SSL_OP_NO_SSLv3;
if (!(conf->ssl_versions & TLSv1)) if (!(conf->ssl_versions & TLSv1))
options |= SSL_OP_NO_TLSv1; options |= SSL_OP_NO_TLSv1;
#ifdef SSL_OP_NO_TLSv1_1 #ifdef SSL_OP_NO_TLSv1_1
@ -678,9 +678,9 @@ socket_close( conn_t *sock )
} }
static int static int
prepare_read( conn_t *sock, char **buf, int *len ) prepare_read( conn_t *sock, char **buf, uint *len )
{ {
int n = sock->offset + sock->bytes; uint n = sock->offset + sock->bytes;
if (!(*len = sizeof(sock->buf) - n)) { if (!(*len = sizeof(sock->buf) - n)) {
error( "Socket error: receive buffer full. Probably protocol error.\n" ); error( "Socket error: receive buffer full. Probably protocol error.\n" );
socket_fail( sock ); socket_fail( sock );
@ -691,17 +691,17 @@ prepare_read( conn_t *sock, char **buf, int *len )
} }
static int static int
do_read( conn_t *sock, char *buf, int len ) do_read( conn_t *sock, char *buf, uint len )
{ {
int n; int n;
assert( sock->fd >= 0 ); assert( sock->fd >= 0 );
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
if (sock->ssl) { if (sock->ssl) {
if ((n = ssl_return( "read from", sock, SSL_read( sock->ssl, buf, len ) )) <= 0) if ((n = ssl_return( "read from", sock, SSL_read( sock->ssl, buf, (int)len ) )) <= 0)
return n; return n;
if (n == len && SSL_pending( sock->ssl )) if (n == (int)len && SSL_pending( sock->ssl ))
conf_wakeup( &sock->ssl_fake, 0 ); conf_wakeup( &sock->ssl_fake, 0 );
} else } else
#endif #endif
@ -724,7 +724,8 @@ static void
socket_fill_z( conn_t *sock ) socket_fill_z( conn_t *sock )
{ {
char *buf; char *buf;
int len, ret; uint len;
int ret;
if (prepare_read( sock, &buf, &len ) < 0) if (prepare_read( sock, &buf, &len ) < 0)
return; return;
@ -744,7 +745,7 @@ socket_fill_z( conn_t *sock )
if (!sock->in_z->avail_out) if (!sock->in_z->avail_out)
conf_wakeup( &sock->z_fake, 0 ); conf_wakeup( &sock->z_fake, 0 );
if ((len = (char *)sock->in_z->next_out - buf)) { if ((len = (uint)((char *)sock->in_z->next_out - buf))) {
sock->bytes += len; sock->bytes += len;
sock->read_callback( sock->callback_aux ); sock->read_callback( sock->callback_aux );
} }
@ -762,21 +763,22 @@ socket_fill( conn_t *sock )
sock->in_z->next_in = (uchar *)sock->z_buf; sock->in_z->next_in = (uchar *)sock->z_buf;
if ((ret = do_read( sock, sock->z_buf, sizeof(sock->z_buf) )) <= 0) if ((ret = do_read( sock, sock->z_buf, sizeof(sock->z_buf) )) <= 0)
return; return;
sock->in_z->avail_in = ret; sock->in_z->avail_in = (uint)ret;
socket_fill_z( sock ); socket_fill_z( sock );
} else } else
#endif #endif
{ {
char *buf; char *buf;
int len; uint len;
if (prepare_read( sock, &buf, &len ) < 0) if (prepare_read( sock, &buf, &len ) < 0)
return; return;
if ((len = do_read( sock, buf, len )) <= 0) int n;
if ((n = do_read( sock, buf, len )) <= 0)
return; return;
sock->bytes += len; sock->bytes += (uint)n;
sock->read_callback( sock->callback_aux ); sock->read_callback( sock->callback_aux );
} }
} }
@ -789,9 +791,9 @@ socket_expect_activity( conn_t *conn, int expect )
} }
int int
socket_read( conn_t *conn, char *buf, int len ) socket_read( conn_t *conn, char *buf, uint len )
{ {
int n = conn->bytes; uint n = conn->bytes;
if (!n && conn->state == SCK_EOF) if (!n && conn->state == SCK_EOF)
return -1; return -1;
if (n > len) if (n > len)
@ -801,14 +803,14 @@ socket_read( conn_t *conn, char *buf, int len )
conn->offset = 0; conn->offset = 0;
else else
conn->offset += n; conn->offset += n;
return n; return (int)n;
} }
char * char *
socket_read_line( conn_t *b ) socket_read_line( conn_t *b )
{ {
char *p, *s; char *p, *s;
int n; uint n;
s = b->buf + b->offset; s = b->buf + b->offset;
p = memchr( s + b->scanoff, '\n', b->bytes - b->scanoff ); p = memchr( s + b->scanoff, '\n', b->bytes - b->scanoff );
@ -822,7 +824,7 @@ socket_read_line( conn_t *b )
return (void *)~0; return (void *)~0;
return 0; return 0;
} }
n = p + 1 - s; n = (uint)(p + 1 - s);
b->offset += n; b->offset += n;
b->bytes -= n; b->bytes -= n;
b->scanoff = 0; b->scanoff = 0;
@ -833,14 +835,14 @@ socket_read_line( conn_t *b )
} }
static int static int
do_write( conn_t *sock, char *buf, int len ) do_write( conn_t *sock, char *buf, uint len )
{ {
int n; int n;
assert( sock->fd >= 0 ); assert( sock->fd >= 0 );
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
if (sock->ssl) if (sock->ssl)
return ssl_return( "write to", sock, SSL_write( sock->ssl, buf, len ) ); return ssl_return( "write to", sock, SSL_write( sock->ssl, buf, (int)len ) );
#endif #endif
n = write( sock->fd, buf, len ); n = write( sock->fd, buf, len );
if (n < 0) { if (n < 0) {
@ -851,7 +853,7 @@ do_write( conn_t *sock, char *buf, int len )
n = 0; n = 0;
conf_notifier( &sock->notify, POLLIN, POLLOUT ); conf_notifier( &sock->notify, POLLIN, POLLOUT );
} }
} else if (n != len) { } else if (n != (int)len) {
conf_notifier( &sock->notify, POLLIN, POLLOUT ); conf_notifier( &sock->notify, POLLIN, POLLOUT );
} }
return n; return n;
@ -876,11 +878,12 @@ do_queued_write( conn_t *conn )
return 0; return 0;
while ((bc = conn->write_buf)) { while ((bc = conn->write_buf)) {
int n, len = bc->len - conn->write_offset; int n;
uint len = bc->len - conn->write_offset;
if ((n = do_write( conn, bc->data + conn->write_offset, len )) < 0) if ((n = do_write( conn, bc->data + conn->write_offset, len )) < 0)
return -1; return -1;
if (n != len) { if (n != (int)len) {
conn->write_offset += n; conn->write_offset += (uint)n;
conn->writing = 1; conn->writing = 1;
return 0; return 0;
} }
@ -915,7 +918,7 @@ do_flush( conn_t *conn )
buff_chunk_t *bc = conn->append_buf; buff_chunk_t *bc = conn->append_buf;
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
if (conn->out_z) { if (conn->out_z) {
int buf_avail = conn->append_avail; uint buf_avail = conn->append_avail;
if (!conn->z_written) if (!conn->z_written)
return; return;
do { do {
@ -936,7 +939,7 @@ do_flush( conn_t *conn )
error( "Fatal: Compression error: %s\n", z_err_msg( ret, conn->out_z ) ); error( "Fatal: Compression error: %s\n", z_err_msg( ret, conn->out_z ) );
abort(); abort();
} }
bc->len = (char *)conn->out_z->next_out - bc->data; bc->len = (uint)((char *)conn->out_z->next_out - bc->data);
if (bc->len) { if (bc->len) {
do_append( conn, bc ); do_append( conn, bc );
bc = 0; bc = 0;
@ -962,7 +965,8 @@ do_flush( conn_t *conn )
void void
socket_write( conn_t *conn, conn_iovec_t *iov, int iovcnt ) socket_write( conn_t *conn, conn_iovec_t *iov, int iovcnt )
{ {
int i, buf_avail, len, offset = 0, total = 0; int i;
uint buf_avail, len, offset = 0, total = 0;
buff_chunk_t *bc; buff_chunk_t *bc;
for (i = 0; i < iovcnt; i++) for (i = 0; i < iovcnt; i++)
@ -1006,7 +1010,7 @@ socket_write( conn_t *conn, conn_iovec_t *iov, int iovcnt )
error( "Fatal: Compression error: %s\n", z_err_msg( ret, conn->out_z ) ); error( "Fatal: Compression error: %s\n", z_err_msg( ret, conn->out_z ) );
abort(); abort();
} }
bc->len = (char *)conn->out_z->next_out - bc->data; bc->len = (uint)((char *)conn->out_z->next_out - bc->data);
buf_avail = conn->out_z->avail_out; buf_avail = conn->out_z->avail_out;
len -= conn->out_z->avail_in; len -= conn->out_z->avail_in;
conn->z_written = 1; conn->z_written = 1;

18
src/socket.h

@ -62,7 +62,7 @@ typedef struct {
typedef struct buff_chunk { typedef struct buff_chunk {
struct buff_chunk *next; struct buff_chunk *next;
int len; uint len;
char data[1]; char data[1];
} buff_chunk_t; } buff_chunk_t;
@ -105,15 +105,15 @@ typedef struct {
buff_chunk_t *write_buf, **write_buf_append; /* buffer head & tail */ buff_chunk_t *write_buf, **write_buf_append; /* buffer head & tail */
int writing; int writing;
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
int append_avail; /* space left in accumulating buffer */ uint append_avail; /* space left in accumulating buffer */
#endif #endif
int write_offset; /* offset into buffer head */ uint write_offset; /* offset into buffer head */
int buffer_mem; /* memory currently occupied by buffers in the queue */ uint buffer_mem; /* memory currently occupied by buffers in the queue */
/* reading */ /* reading */
int offset; /* start of filled bytes in buffer */ uint offset; /* start of filled bytes in buffer */
int bytes; /* number of filled bytes in buffer */ uint bytes; /* number of filled bytes in buffer */
int scanoff; /* offset to continue scanning for newline at, relative to 'offset' */ uint scanoff; /* offset to continue scanning for newline at, relative to 'offset' */
char buf[100000]; char buf[100000];
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
char z_buf[100000]; char z_buf[100000];
@ -142,12 +142,12 @@ void socket_start_tls(conn_t *conn, void (*cb)( int ok, void *aux ) );
void socket_start_deflate( conn_t *conn ); void socket_start_deflate( conn_t *conn );
void socket_close( conn_t *sock ); void socket_close( conn_t *sock );
void socket_expect_activity( conn_t *sock, int expect ); void socket_expect_activity( conn_t *sock, int expect );
int socket_read( conn_t *sock, char *buf, int len ); /* never waits */ int socket_read( conn_t *sock, char *buf, uint len ); /* never waits */
char *socket_read_line( conn_t *sock ); /* don't free return value; never waits */ char *socket_read_line( conn_t *sock ); /* don't free return value; never waits */
typedef enum { KeepOwn = 0, GiveOwn } ownership_t; typedef enum { KeepOwn = 0, GiveOwn } ownership_t;
typedef struct { typedef struct {
char *buf; char *buf;
int len; uint len;
ownership_t takeOwn; ownership_t takeOwn;
} conn_iovec_t; } conn_iovec_t;
void socket_write( conn_t *sock, conn_iovec_t *iov, int iovcnt ); void socket_write( conn_t *sock, conn_iovec_t *iov, int iovcnt );

47
src/sync.c

@ -102,10 +102,11 @@ Fprintf( FILE *f, const char *msg, ... )
/* The order is according to alphabetical maildir flag sort */ /* The order is according to alphabetical maildir flag sort */
static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' }; static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' };
static int static uchar
parse_flags( const char *buf ) parse_flags( const char *buf )
{ {
uint flags, i, d; uint i, d;
uchar flags;
for (flags = i = d = 0; i < as(Flags); i++) for (flags = i = d = 0; i < as(Flags); i++)
if (buf[d] == Flags[i]) { if (buf[d] == Flags[i]) {
@ -115,8 +116,8 @@ parse_flags( const char *buf )
return flags; return flags;
} }
static int static uint
make_flags( int flags, char *buf ) make_flags( uchar flags, char *buf )
{ {
uint i, d; uint i, d;
@ -162,8 +163,9 @@ typedef struct {
const char *orig_name[2]; const char *orig_name[2];
message_t *msgs[2], *new_msgs[2]; message_t *msgs[2], *new_msgs[2];
uint_array_alloc_t trashed_msgs[2]; uint_array_alloc_t trashed_msgs[2];
int state[2], opts[2], ref_count, nsrecs, ret, lfd, existing, replayed; int state[2], lfd, ret, existing, replayed;
int new_pending[2], flags_pending[2], trash_pending[2]; uint ref_count, nsrecs, opts[2];
uint new_pending[2], flags_pending[2], trash_pending[2];
uint maxuid[2]; // highest UID that was already propagated uint maxuid[2]; // highest UID that was already propagated
uint newmaxuid[2]; // highest UID that is currently being propagated uint newmaxuid[2]; // highest UID that is currently being propagated
uint uidval[2]; // UID validity value uint uidval[2]; // UID validity value
@ -324,10 +326,10 @@ copy_msg( copy_vars_t *vars )
static void msg_stored( int sts, uint uid, void *aux ); static void msg_stored( int sts, uint uid, void *aux );
static void static void
copy_msg_bytes( char **out_ptr, const char *in_buf, int *in_idx, int in_len, int in_cr, int out_cr ) copy_msg_bytes( char **out_ptr, const char *in_buf, uint *in_idx, uint in_len, int in_cr, int out_cr )
{ {
char *out = *out_ptr; char *out = *out_ptr;
int idx = *in_idx; uint idx = *in_idx;
if (out_cr != in_cr) { if (out_cr != in_cr) {
char c; char c;
if (out_cr) { if (out_cr) {
@ -357,19 +359,19 @@ static int
copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars ) copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars )
{ {
char *in_buf = vars->data.data; char *in_buf = vars->data.data;
int in_len = vars->data.len; uint in_len = vars->data.len;
int idx = 0, sbreak = 0, ebreak = 0; uint idx = 0, sbreak = 0, ebreak = 0;
int lines = 0, hdr_crs = 0, bdy_crs = 0, app_cr = 0, extra = 0; uint lines = 0, hdr_crs = 0, bdy_crs = 0, app_cr = 0, extra = 0;
if (vars->srec) { if (vars->srec) {
nloop: ; nloop: ;
int start = idx; uint start = idx;
int line_crs = 0; uint line_crs = 0;
while (idx < in_len) { while (idx < in_len) {
char c = in_buf[idx++]; char c = in_buf[idx++];
if (c == '\r') { if (c == '\r') {
line_crs++; line_crs++;
} else if (c == '\n') { } else if (c == '\n') {
if (starts_with_upper( in_buf + start, in_len - start, "X-TUID: ", 8 )) { if (starts_with_upper( in_buf + start, (int)(in_len - start), "X-TUID: ", 8 )) {
extra = (sbreak = start) - (ebreak = idx); extra = (sbreak = start) - (ebreak = idx);
goto oke; goto oke;
} }
@ -591,7 +593,7 @@ static char *
clean_strdup( const char *s ) clean_strdup( const char *s )
{ {
char *cs; char *cs;
int i; uint i;
cs = nfstrdup( s ); cs = nfstrdup( s );
for (i = 0; cs[i]; i++) for (i = 0; cs[i]; i++)
@ -711,7 +713,7 @@ load_state( sync_vars_t *svars )
sync_rec_t *srec, *nsrec; sync_rec_t *srec, *nsrec;
char *s; char *s;
FILE *jfp; FILE *jfp;
int ll; uint ll;
uint smaxxuid = 0; uint smaxxuid = 0;
char c; char c;
struct stat st; struct stat st;
@ -863,7 +865,7 @@ load_state( sync_vars_t *svars )
goto jbail; goto jbail;
} }
buf[ll] = 0; buf[ll] = 0;
if (!equals( buf, ll, JOURNAL_VERSION, strlen(JOURNAL_VERSION) )) { if (!equals( buf, (int)ll, JOURNAL_VERSION, strlen(JOURNAL_VERSION) )) {
error( "Error: incompatible journal version " error( "Error: incompatible journal version "
"(got %s, expected " JOURNAL_VERSION ")\n", buf ); "(got %s, expected " JOURNAL_VERSION ")\n", buf );
goto jbail; goto jbail;
@ -880,7 +882,7 @@ load_state( sync_vars_t *svars )
int tn; int tn;
uint t1, t2, t3; uint t1, t2, t3;
if ((c = buf[0]) == '#' ? if ((c = buf[0]) == '#' ?
(tn = 0, (sscanf( buf + 2, "%u %u %n", &t1, &t2, &tn ) < 2) || !tn || (ll - tn != TUIDL + 2)) : (tn = 0, (sscanf( buf + 2, "%u %u %n", &t1, &t2, &tn ) < 2) || !tn || (ll - (uint)tn != TUIDL + 2)) :
c == 'S' || c == '!' ? c == 'S' || c == '!' ?
(sscanf( buf + 2, "%u", &t1 ) != 1) : (sscanf( buf + 2, "%u", &t1 ) != 1) :
c == 'F' || c == 'T' || c == '+' || c == '&' || c == '-' || c == '=' || c == '|' ? c == 'F' || c == 'T' || c == '+' || c == '&' || c == '-' || c == '=' || c == '|' ?
@ -1202,8 +1204,7 @@ box_opened2( sync_vars_t *svars, int t )
channel_conf_t *chan; channel_conf_t *chan;
sync_rec_t *srec; sync_rec_t *srec;
uint_array_alloc_t mexcs; uint_array_alloc_t mexcs;
uint minwuid; uint opts[2], fails, minwuid;
int opts[2], fails;
svars->state[t] |= ST_SELECTED; svars->state[t] |= ST_SELECTED;
if (!(svars->state[1-t] & ST_SELECTED)) if (!(svars->state[1-t] & ST_SELECTED))
@ -1260,7 +1261,7 @@ box_opened2( sync_vars_t *svars, int t )
opts[1-t] |= OPEN_NEW; opts[1-t] |= OPEN_NEW;
if (chan->ops[t] & OP_EXPUNGE) if (chan->ops[t] & OP_EXPUNGE)
opts[1-t] |= OPEN_FLAGS; opts[1-t] |= OPEN_FLAGS;
if (chan->stores[t]->max_size != INT_MAX) { if (chan->stores[t]->max_size != UINT_MAX) {
if (chan->ops[t] & OP_RENEW) if (chan->ops[t] & OP_RENEW)
opts[1-t] |= OPEN_FLAGS|OPEN_OLD_SIZE; opts[1-t] |= OPEN_FLAGS|OPEN_OLD_SIZE;
if (chan->ops[t] & OP_NEW) if (chan->ops[t] & OP_NEW)
@ -1709,7 +1710,7 @@ box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux
} }
} }
debug( "%d excess messages remain\n", todel ); debug( "%d excess messages remain\n", todel );
if (svars->chan->expire_unread < 0 && (uint)alive * 2 > svars->chan->max_messages) { if (svars->chan->expire_unread < 0 && alive * 2 > svars->chan->max_messages) {
error( "%s: %d unread messages in excess of MaxMessages (%d).\n" error( "%s: %d unread messages in excess of MaxMessages (%d).\n"
"Please set ExpireUnread to decide outcome. Skipping mailbox.\n", "Please set ExpireUnread to decide outcome. Skipping mailbox.\n",
svars->orig_name[S], alive, svars->chan->max_messages ); svars->orig_name[S], alive, svars->chan->max_messages );
@ -1733,7 +1734,7 @@ box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux
jFprintf( svars, "~ %u %u %u\n", srec->uid[M], srec->uid[S], srec->status ); jFprintf( svars, "~ %u %u %u\n", srec->uid[M], srec->uid[S], srec->status );
} else { } else {
/* ... but the "right" transaction is already pending. */ /* ... but the "right" transaction is already pending. */
debug( " pair(%u,%u): %d (pending)\n", srec->uid[M], srec->uid[S], nex ); debug( " pair(%u,%u): %u (pending)\n", srec->uid[M], srec->uid[S], nex );
} }
} else { } else {
/* Note: the "wrong" transaction may be pending here, /* Note: the "wrong" transaction may be pending here,

2
src/sync.h

@ -52,7 +52,7 @@ typedef struct channel_conf {
char *sync_state; char *sync_state;
string_list_t *patterns; string_list_t *patterns;
int ops[2]; int ops[2];
uint max_messages; /* for slave only */ int max_messages; /* for slave only */
signed char expire_unread; signed char expire_unread;
char use_internal_date; char use_internal_date;
} channel_conf_t; } channel_conf_t;

52
src/util.c

@ -170,7 +170,7 @@ sys_error( const char *msg, ... )
} }
void void
add_string_list_n( string_list_t **list, const char *str, int len ) add_string_list_n( string_list_t **list, const char *str, uint len )
{ {
string_list_t *elem; string_list_t *elem;
@ -210,7 +210,7 @@ vasprintf( char **strp, const char *fmt, va_list ap )
if (len >= (int)sizeof(tmp)) if (len >= (int)sizeof(tmp))
vsprintf( *strp, fmt, ap ); vsprintf( *strp, fmt, ap );
else else
memcpy( *strp, tmp, len + 1 ); memcpy( *strp, tmp, (size_t)len + 1 );
return len; return len;
} }
#endif #endif
@ -239,34 +239,32 @@ strnlen( const char *str, size_t maxlen )
#endif #endif
int int
starts_with( const char *str, int strl, const char *cmp, int cmpl ) starts_with( const char *str, int strl, const char *cmp, uint cmpl )
{ {
if (strl < 0) if (strl < 0)
strl = strnlen( str, cmpl + 1 ); strl = strnlen( str, cmpl + 1 );
return (strl >= cmpl) && !memcmp( str, cmp, cmpl ); return ((uint)strl >= cmpl) && !memcmp( str, cmp, cmpl );
} }
int int
starts_with_upper( const char *str, int strl, const char *cmp, int cmpl ) starts_with_upper( const char *str, int strl, const char *cmp, uint cmpl )
{ {
int i;
if (strl < 0) if (strl < 0)
strl = strnlen( str, cmpl + 1 ); strl = strnlen( str, cmpl + 1 );
if (strl < cmpl) if ((uint)strl < cmpl)
return 0; return 0;
for (i = 0; i < cmpl; i++) for (uint i = 0; i < cmpl; i++)
if (str[i] != cmp[i] && toupper( str[i] ) != cmp[i]) if (str[i] != cmp[i] && toupper( str[i] ) != cmp[i])
return 0; return 0;
return 1; return 1;
} }
int int
equals( const char *str, int strl, const char *cmp, int cmpl ) equals( const char *str, int strl, const char *cmp, uint cmpl )
{ {
if (strl < 0) if (strl < 0)
strl = strnlen( str, cmpl + 1 ); strl = strnlen( str, cmpl + 1 );
return (strl == cmpl) && !memcmp( str, cmp, cmpl ); return ((uint)strl == cmpl) && !memcmp( str, cmp, cmpl );
} }
#ifndef HAVE_TIMEGM #ifndef HAVE_TIMEGM
@ -348,7 +346,7 @@ nfsnprintf( char *buf, int blen, const char *fmt, ... )
va_list va; va_list va;
va_start( va, fmt ); va_start( va, fmt );
if (blen <= 0 || (uint)(ret = vsnprintf( buf, blen, fmt, va )) >= (uint)blen) if (blen <= 0 || (uint)(ret = vsnprintf( buf, (size_t)blen, fmt, va )) >= (uint)blen)
oob(); oob();
va_end( va ); va_end( va );
return ret; return ret;
@ -464,7 +462,7 @@ expand_strdup( const char *s )
q = Home; q = Home;
} else { } else {
if ((p = strchr( s, '/' ))) { if ((p = strchr( s, '/' ))) {
r = nfstrndup( s, (int)(p - s) ); r = nfstrndup( s, (size_t)(p - s) );
pw = getpwnam( r ); pw = getpwnam( r );
free( r ); free( r );
} else } else
@ -481,10 +479,10 @@ expand_strdup( const char *s )
/* Return value: 0 = ok, -1 = out found in arg, -2 = in found in arg but no out specified */ /* Return value: 0 = ok, -1 = out found in arg, -2 = in found in arg but no out specified */
int int
map_name( const char *arg, char **result, int reserve, const char *in, const char *out ) map_name( const char *arg, char **result, uint reserve, const char *in, const char *out )
{ {
char *p; char *p;
int i, l, ll, num, inl, outl; uint i, l, ll, num, inl, outl;
assert( arg ); assert( arg );
l = strlen( arg ); l = strlen( arg );
@ -498,7 +496,7 @@ map_name( const char *arg, char **result, int reserve, const char *in, const cha
} }
assert( out ); assert( out );
outl = strlen( out ); outl = strlen( out );
if (equals( in, inl, out, outl )) if (equals( in, (int)inl, out, outl ))
goto copy; goto copy;
for (num = 0, i = 0; i < l; ) { for (num = 0, i = 0; i < l; ) {
for (ll = 0; ll < inl; ll++) for (ll = 0; ll < inl; ll++)
@ -556,9 +554,9 @@ sort_uint_array( uint_array_t array )
int int
find_uint_array( uint_array_t array, uint value ) find_uint_array( uint_array_t array, uint value )
{ {
int bot = 0, top = array.size; uint bot = 0, top = array.size;
while (bot < top) { while (bot < top) {
int i = (bot + top) / 2; uint i = (bot + top) / 2;
uint elt = array.data[i]; uint elt = array.data[i];
if (elt == value) if (elt == value)
return 1; return 1;
@ -624,13 +622,13 @@ static const uchar prime_deltas[] = {
1, 29, 3, 21, 7, 17, 15, 9, 43, 35, 15, 0, 0, 0, 0, 0 1, 29, 3, 21, 7, 17, 15, 9, 43, 35, 15, 0, 0, 0, 0, 0
}; };
int uint
bucketsForSize( int size ) bucketsForSize( uint size )
{ {
int base = 4, bits = 2; uint base = 4, bits = 2;
for (;;) { for (;;) {
int prime = base + prime_deltas[bits]; uint prime = base + prime_deltas[bits];
if (prime >= size) if (prime >= size)
return prime; return prime;
base <<= 1; base <<= 1;
@ -665,7 +663,7 @@ static notifier_t *notifiers;
static int changed; /* Iterator may be invalid now. */ static int changed; /* Iterator may be invalid now. */
#ifdef HAVE_SYS_POLL_H #ifdef HAVE_SYS_POLL_H
static struct pollfd *pollfds; static struct pollfd *pollfds;
static int npolls, rpolls; static uint npolls, rpolls;
#else #else
# ifdef HAVE_SYS_SELECT_H # ifdef HAVE_SYS_SELECT_H
# include <sys/select.h> # include <sys/select.h>
@ -676,7 +674,7 @@ void
init_notifier( notifier_t *sn, int fd, void (*cb)( int, void * ), void *aux ) init_notifier( notifier_t *sn, int fd, void (*cb)( int, void * ), void *aux )
{ {
#ifdef HAVE_SYS_POLL_H #ifdef HAVE_SYS_POLL_H
int idx = npolls++; uint idx = npolls++;
if (rpolls < npolls) { if (rpolls < npolls) {
rpolls = npolls; rpolls = npolls;
pollfds = nfrealloc( pollfds, npolls * sizeof(*pollfds) ); pollfds = nfrealloc( pollfds, npolls * sizeof(*pollfds) );
@ -698,7 +696,7 @@ void
conf_notifier( notifier_t *sn, short and_events, short or_events ) conf_notifier( notifier_t *sn, short and_events, short or_events )
{ {
#ifdef HAVE_SYS_POLL_H #ifdef HAVE_SYS_POLL_H
int idx = sn->index; uint idx = sn->index;
pollfds[idx].events = (pollfds[idx].events & and_events) | or_events; pollfds[idx].events = (pollfds[idx].events & and_events) | or_events;
#else #else
sn->events = (sn->events & and_events) | or_events; sn->events = (sn->events & and_events) | or_events;
@ -710,7 +708,7 @@ wipe_notifier( notifier_t *sn )
{ {
notifier_t **snp; notifier_t **snp;
#ifdef HAVE_SYS_POLL_H #ifdef HAVE_SYS_POLL_H
int idx; uint idx;
#endif #endif
for (snp = &notifiers; *snp != sn; snp = &(*snp)->next) for (snp = &notifiers; *snp != sn; snp = &(*snp)->next)
@ -813,7 +811,7 @@ event_wait( void )
break; break;
} }
for (sn = notifiers; sn; sn = sn->next) { for (sn = notifiers; sn; sn = sn->next) {
int n = sn->index; uint n = sn->index;
if ((m = pollfds[n].revents)) { if ((m = pollfds[n].revents)) {
assert( !(m & POLLNVAL) ); assert( !(m & POLLNVAL) );
sn->cb( m | shifted_bit( m, POLLHUP, POLLIN ), sn->aux ); sn->cb( m | shifted_bit( m, POLLHUP, POLLIN ), sn->aux );

Loading…
Cancel
Save