Browse Source

introduce uchar, ushort & uint typedefs

wip/server-refactor
Oswald Buddenhagen 10 years ago
parent
commit
42cedc8f81
  1. 6
      src/common.h
  2. 4
      src/config.c
  3. 8
      src/driver.h
  4. 38
      src/drv_imap.c
  5. 14
      src/drv_maildir.c
  6. 16
      src/sync.c
  7. 2
      src/sync.h
  8. 16
      src/util.c

6
src/common.h

@ -29,6 +29,10 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
#define as(ar) (sizeof(ar)/sizeof(ar[0])) #define as(ar) (sizeof(ar)/sizeof(ar[0]))
#define __stringify(x) #x #define __stringify(x) #x
@ -119,7 +123,7 @@ int map_name( const char *arg, char **result, int reserve, const char *in, const
void sort_ints( int *arr, int len ); void sort_ints( int *arr, int len );
void arc4_init( void ); void arc4_init( void );
unsigned char arc4_getbyte( void ); uchar arc4_getbyte( void );
int bucketsForSize( int size ); int bucketsForSize( int size );

4
src/config.c

@ -45,7 +45,7 @@ get_arg( conffile_t *cfile, int required, int *comment )
p = cfile->rest; p = cfile->rest;
assert( p ); assert( p );
while ((c = *p) && isspace( (unsigned char) c )) while ((c = *p) && isspace( (uchar)c ))
p++; p++;
if (!c || c == '#') { if (!c || c == '#') {
if (comment) if (comment)
@ -65,7 +65,7 @@ get_arg( conffile_t *cfile, int required, int *comment )
escaped = 1; escaped = 1;
else if (c == '"') else if (c == '"')
quoted ^= 1; quoted ^= 1;
else if (!quoted && isspace( (unsigned char) c )) else if (!quoted && isspace( (uchar)c ))
break; break;
else else
*t++ = c; *t++ = c;

8
src/driver.h

@ -35,7 +35,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;
unsigned 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;
@ -62,7 +62,7 @@ typedef struct message {
/* string_list_t *keywords; */ /* string_list_t *keywords; */
size_t size; /* zero implies "not fetched" */ size_t size; /* zero implies "not fetched" */
int uid; int uid;
unsigned char flags, status; uchar flags, status;
char tuid[TUIDL]; char tuid[TUIDL];
} message_t; } message_t;
@ -90,7 +90,7 @@ typedef struct store {
message_t *msgs; /* own */ message_t *msgs; /* own */
int uidvalidity; int uidvalidity;
int uidnext; /* from SELECT responses */ int uidnext; /* from SELECT responses */
unsigned opts; /* maybe preset? */ uint opts; /* maybe preset? */
/* note that the following do _not_ reflect stats from msgs, but mailbox totals */ /* note that the following do _not_ reflect stats from msgs, but mailbox totals */
int count; /* # of messages */ int count; /* # of messages */
int recent; /* # of recent messages - don't trust this beyond the initial read */ int recent; /* # of recent messages - don't trust this beyond the initial read */
@ -109,7 +109,7 @@ typedef struct {
char *data; char *data;
int len; int len;
time_t date; time_t date;
unsigned char flags; uchar flags;
} msg_data_t; } msg_data_t;
#define DRV_OK 0 #define DRV_OK 0

38
src/drv_imap.c

@ -100,11 +100,11 @@ typedef struct imap_store {
int ref_count; int ref_count;
/* trash folder's existence is not confirmed yet */ /* trash folder's existence is not confirmed yet */
enum { TrashUnknown, TrashChecking, TrashKnown } trashnc; enum { TrashUnknown, TrashChecking, TrashKnown } trashnc;
unsigned got_namespace:1; uint got_namespace:1;
char *delimiter; /* hierarchy delimiter */ char *delimiter; /* hierarchy delimiter */
list_t *ns_personal, *ns_other, *ns_shared; /* NAMESPACE info */ list_t *ns_personal, *ns_other, *ns_shared; /* NAMESPACE info */
message_t **msgapp; /* FETCH results */ message_t **msgapp; /* FETCH results */
unsigned caps; /* CAPABILITY results */ uint caps; /* CAPABILITY results */
string_list_t *auth_mechs; string_list_t *auth_mechs;
parse_list_state_t parse_list_sts; parse_list_state_t parse_list_sts;
/* command queue */ /* command queue */
@ -591,7 +591,7 @@ next_arg( char **ps )
s = *ps; s = *ps;
if (!s) if (!s)
return 0; return 0;
while (isspace( (unsigned char)*s )) while (isspace( (uchar)*s ))
s++; s++;
if (!*s) { if (!*s) {
*ps = 0; *ps = 0;
@ -613,7 +613,7 @@ next_arg( char **ps )
} else { } else {
ret = s; ret = s;
while ((c = *s)) { while ((c = *s)) {
if (isspace( (unsigned char)c )) { if (isspace( (uchar)c )) {
*s++ = 0; *s++ = 0;
break; break;
} }
@ -684,7 +684,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
if (!s) if (!s)
return LIST_BAD; return LIST_BAD;
for (;;) { for (;;) {
while (isspace( (unsigned char)*s )) while (isspace( (uchar)*s ))
s++; s++;
if (sts->level && *s == ')') { if (sts->level && *s == ')') {
s++; s++;
@ -751,7 +751,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
} else { } else {
/* atom */ /* atom */
p = s; p = s;
for (; *s && !isspace( (unsigned char)*s ); s++) for (; *s && !isspace( (uchar)*s ); s++)
if (sts->level && *s == ')') if (sts->level && *s == ')')
break; break;
cur->len = s - p; cur->len = s - p;
@ -876,7 +876,7 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
msg_data_t *msgdata; msg_data_t *msgdata;
struct imap_cmd *cmdp; struct imap_cmd *cmdp;
int uid = 0, mask = 0, status = 0, size = 0; int uid = 0, mask = 0, status = 0, size = 0;
unsigned i; uint i;
time_t date = 0; time_t date = 0;
if (!is_list( list )) { if (!is_list( list )) {
@ -1000,7 +1000,7 @@ static void
parse_capability( imap_store_t *ctx, char *cmd ) parse_capability( imap_store_t *ctx, char *cmd )
{ {
char *arg; char *arg;
unsigned i; uint i;
free_string_list( ctx->auth_mechs ); free_string_list( ctx->auth_mechs );
ctx->auth_mechs = 0; ctx->auth_mechs = 0;
@ -1052,7 +1052,7 @@ parse_response_code( imap_store_t *ctx, struct imap_cmd *cmd, char *s )
/* RFC2060 says that these messages MUST be displayed /* RFC2060 says that these messages MUST be displayed
* to the user * to the user
*/ */
for (; isspace( (unsigned char)*p ); p++); for (; isspace( (uchar)*p ); p++);
error( "*** IMAP ALERT *** %s\n", p ); error( "*** IMAP ALERT *** %s\n", p );
} else if (cmd && !strcmp( "APPENDUID", arg )) { } else if (cmd && !strcmp( "APPENDUID", arg )) {
if (!(arg = next_arg( &s )) || if (!(arg = next_arg( &s )) ||
@ -1743,8 +1743,8 @@ process_sasl_interact( sasl_interact_t *interact, imap_server_conf_t *srvc )
} }
static int static int
process_sasl_step( imap_store_t *ctx, int rc, const char *in, unsigned in_len, process_sasl_step( imap_store_t *ctx, int rc, const char *in, uint in_len,
sasl_interact_t *interact, const char **out, unsigned *out_len ) sasl_interact_t *interact, const char **out, uint *out_len )
{ {
imap_server_conf_t *srvc = ((imap_store_conf_t *)ctx->gen.conf)->server; imap_server_conf_t *srvc = ((imap_store_conf_t *)ctx->gen.conf)->server;
@ -1765,11 +1765,11 @@ process_sasl_step( imap_store_t *ctx, int rc, const char *in, unsigned in_len,
} }
static int static int
decode_sasl_data( const char *prompt, char **in, unsigned *in_len ) decode_sasl_data( const char *prompt, char **in, uint *in_len )
{ {
if (prompt) { if (prompt) {
int rc; int rc;
unsigned prompt_len = strlen( prompt ); uint prompt_len = strlen( prompt );
/* We're decoding, the output will be shorter than prompt_len. */ /* We're decoding, the output will be shorter than prompt_len. */
*in = nfmalloc( prompt_len ); *in = nfmalloc( prompt_len );
rc = sasl_decode64( prompt, prompt_len, *in, prompt_len, in_len ); rc = sasl_decode64( prompt, prompt_len, *in, prompt_len, in_len );
@ -1786,10 +1786,10 @@ decode_sasl_data( const char *prompt, char **in, unsigned *in_len )
} }
static int static int
encode_sasl_data( const char *out, unsigned out_len, char **enc, unsigned *enc_len ) encode_sasl_data( const char *out, uint out_len, char **enc, uint *enc_len )
{ {
int rc; int rc;
unsigned enc_len_max = ((out_len + 2) / 3) * 4 + 1; uint enc_len_max = ((out_len + 2) / 3) * 4 + 1;
*enc = nfmalloc( enc_len_max ); *enc = nfmalloc( enc_len_max );
rc = sasl_encode64( out, out_len, *enc, enc_len_max, enc_len ); rc = sasl_encode64( out, out_len, *enc, enc_len_max, enc_len );
if (rc != SASL_OK) { if (rc != SASL_OK) {
@ -1804,7 +1804,7 @@ static int
do_sasl_auth( imap_store_t *ctx, struct imap_cmd *cmdp ATTR_UNUSED, const char *prompt ) do_sasl_auth( imap_store_t *ctx, struct imap_cmd *cmdp ATTR_UNUSED, const char *prompt )
{ {
int rc, ret; int rc, ret;
unsigned in_len, out_len, enc_len; uint in_len, out_len, enc_len;
const char *out; const char *out;
char *in, *enc; char *in, *enc;
sasl_interact_t *interact = NULL; sasl_interact_t *interact = NULL;
@ -1851,7 +1851,7 @@ done_sasl_auth( imap_store_t *ctx, struct imap_cmd *cmd ATTR_UNUSED, int respons
if (response == RESP_OK && ctx->sasl_cont) { if (response == RESP_OK && ctx->sasl_cont) {
sasl_interact_t *interact = NULL; sasl_interact_t *interact = NULL;
const char *out; const char *out;
unsigned out_len; uint out_len;
int rc = sasl_client_step( ctx->sasl, NULL, 0, &interact, &out, &out_len ); int rc = sasl_client_step( ctx->sasl, NULL, 0, &interact, &out, &out_len );
if (process_sasl_step( ctx, rc, NULL, 0, interact, &out, &out_len ) < 0) if (process_sasl_step( ctx, rc, NULL, 0, interact, &out, &out_len ) < 0)
warn( "Warning: SASL reported failure despite successful IMAP authentication. Ignoring...\n" ); warn( "Warning: SASL reported failure despite successful IMAP authentication. Ignoring...\n" );
@ -1904,7 +1904,7 @@ imap_open_store_authenticate2( imap_store_t *ctx )
#ifdef HAVE_LIBSASL #ifdef HAVE_LIBSASL
if (saslend != saslmechs) { if (saslend != saslmechs) {
int rc; int rc;
unsigned out_len = 0; uint out_len = 0;
char *enc = NULL; char *enc = NULL;
const char *gotmech = NULL, *out = NULL; const char *gotmech = NULL, *out = NULL;
sasl_interact_t *interact = NULL; sasl_interact_t *interact = NULL;
@ -2198,7 +2198,7 @@ static int
imap_make_flags( int flags, char *buf ) imap_make_flags( int flags, char *buf )
{ {
const char *s; const char *s;
unsigned i, d; uint i, d;
for (i = d = 0; i < as(Flags); i++) for (i = d = 0; i < as(Flags); i++)
if (flags & (1 << i)) { if (flags & (1 << i)) {

14
src/drv_maildir.c

@ -85,12 +85,12 @@ static int MaildirCount;
static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' }; static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' };
static unsigned char static uchar
maildir_parse_flags( const char *info_prefix, const char *base ) maildir_parse_flags( const char *info_prefix, const char *base )
{ {
const char *s; const char *s;
unsigned i; uint i;
unsigned char flags; uchar flags;
flags = 0; flags = 0;
if ((s = strstr( base, info_prefix ))) if ((s = strstr( base, info_prefix )))
@ -312,7 +312,7 @@ static const char *subdirs[] = { "cur", "new", "tmp" };
typedef struct { typedef struct {
char *base; char *base;
int size; int size;
unsigned uid:31, recent:1; uint uid:31, recent:1;
char tuid[TUIDL]; char tuid[TUIDL];
} msg_t; } msg_t;
@ -835,7 +835,7 @@ maildir_scan( maildir_store_t *ctx, msglist_t *msglist )
} }
entry->uid = uid; entry->uid = uid;
if ((u = strstr( entry->base, ",U=" ))) if ((u = strstr( entry->base, ",U=" )))
for (ru = u + 3; isdigit( (unsigned char)*ru ); ru++); for (ru = u + 3; isdigit( (uchar)*ru ); ru++);
else else
u = ru = strchr( entry->base, conf->info_delimiter ); u = ru = strchr( entry->base, conf->info_delimiter );
fnl = (u ? fnl = (u ?
@ -1187,7 +1187,7 @@ 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, int flags, char *buf )
{ {
unsigned i, d; uint i, d;
buf[0] = info_delimiter; buf[0] = info_delimiter;
buf[1] = '2'; buf[1] = '2';
@ -1309,7 +1309,7 @@ maildir_set_flags( store_t *gctx, message_t *gmsg, int uid ATTR_UNUSED, int add,
maildir_store_t *ctx = (maildir_store_t *)gctx; maildir_store_t *ctx = (maildir_store_t *)gctx;
maildir_message_t *msg = (maildir_message_t *)gmsg; maildir_message_t *msg = (maildir_message_t *)gmsg;
char *s, *p; char *s, *p;
unsigned i; uint i;
int j, ret, ol, fl, bbl, bl, tl; int j, ret, ol, fl, bbl, bl, tl;
char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX]; char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX];

16
src/sync.c

@ -75,7 +75,7 @@ static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' };
static int static int
parse_flags( const char *buf ) parse_flags( const char *buf )
{ {
unsigned flags, i, d; uint flags, i, d;
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]) {
@ -88,7 +88,7 @@ parse_flags( const char *buf )
static int static int
make_flags( int flags, char *buf ) make_flags( int flags, char *buf )
{ {
unsigned i, d; uint i, d;
for (i = d = 0; i < as(Flags); i++) for (i = d = 0; i < as(Flags); i++)
if (flags & (1 << i)) if (flags & (1 << i))
@ -105,14 +105,14 @@ make_flags( int flags, char *buf )
#define S_NEXPIRE (1<<6) /* temporary: new expiration state */ #define S_NEXPIRE (1<<6) /* temporary: new expiration state */
#define S_DELETE (1<<7) /* ephemeral: flags propagation is a deletion */ #define S_DELETE (1<<7) /* ephemeral: flags propagation is a deletion */
#define mvBit(in,ib,ob) ((unsigned char)(((unsigned)in) * (ob) / (ib))) #define mvBit(in,ib,ob) ((uchar)(((uint)in) * (ob) / (ib)))
typedef struct sync_rec { typedef struct sync_rec {
struct sync_rec *next; struct sync_rec *next;
/* string_list_t *keywords; */ /* string_list_t *keywords; */
int uid[2]; /* -2 = pending (use tuid), -1 = skipped (too big), 0 = expired */ int uid[2]; /* -2 = pending (use tuid), -1 = skipped (too big), 0 = expired */
message_t *msg[2]; message_t *msg[2];
unsigned char status, flags, aflags[2], dflags[2]; uchar status, flags, aflags[2], dflags[2];
char tuid[TUIDL]; char tuid[TUIDL];
} sync_rec_t; } sync_rec_t;
@ -1126,7 +1126,7 @@ box_loaded( int sts, void *aux )
flag_vars_t *fv; flag_vars_t *fv;
int uid, no[2], del[2], alive, todel, t1, t2; int uid, no[2], del[2], alive, todel, t1, t2;
int sflags, nflags, aflags, dflags, nex; int sflags, nflags, aflags, dflags, nex;
unsigned hashsz, idx; uint hashsz, idx;
char fbuf[16]; /* enlarge when support for keywords is added */ char fbuf[16]; /* enlarge when support for keywords is added */
if (check_ret( sts, aux )) if (check_ret( sts, aux ))
@ -1147,7 +1147,7 @@ box_loaded( int sts, void *aux )
if (srec->status & S_DEAD) if (srec->status & S_DEAD)
continue; continue;
uid = srec->uid[t]; uid = srec->uid[t];
idx = (unsigned)((unsigned)uid * 1103515245U) % hashsz; idx = (uint)((uint)uid * 1103515245U) % hashsz;
while (srecmap[idx].uid) while (srecmap[idx].uid)
if (++idx == hashsz) if (++idx == hashsz)
idx = 0; idx = 0;
@ -1162,7 +1162,7 @@ box_loaded( int sts, void *aux )
make_flags( tmsg->flags, fbuf ); make_flags( tmsg->flags, fbuf );
printf( svars->ctx[t]->opts & OPEN_SIZE ? " message %5d, %-4s, %6lu: " : " message %5d, %-4s: ", uid, fbuf, tmsg->size ); printf( svars->ctx[t]->opts & OPEN_SIZE ? " message %5d, %-4s, %6lu: " : " message %5d, %-4s: ", uid, fbuf, tmsg->size );
} }
idx = (unsigned)((unsigned)uid * 1103515245U) % hashsz; idx = (uint)((uint)uid * 1103515245U) % hashsz;
while (srecmap[idx].uid) { while (srecmap[idx].uid) {
if (srecmap[idx].uid == uid) { if (srecmap[idx].uid == uid) {
srec = srecmap[idx].srec; srec = srecmap[idx].srec;
@ -1403,7 +1403,7 @@ box_loaded( int sts, void *aux )
} }
} }
debug( "%d excess messages remain\n", todel ); debug( "%d excess messages remain\n", todel );
if (svars->chan->expire_unread < 0 && (unsigned)alive * 2 > svars->chan->max_messages) { if (svars->chan->expire_unread < 0 && (uint)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 );

2
src/sync.h

@ -50,7 +50,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];
unsigned max_messages; /* for slave only */ uint 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;

16
src/util.c

@ -138,7 +138,7 @@ sys_error( const char *msg, ... )
flushn(); flushn();
va_start( va, msg ); va_start( va, msg );
if ((unsigned)vsnprintf( buf, sizeof(buf), msg, va ) >= sizeof(buf)) if ((uint)vsnprintf( buf, sizeof(buf), msg, va ) >= sizeof(buf))
oob(); oob();
va_end( va ); va_end( va );
perror( buf ); perror( buf );
@ -311,7 +311,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 || (unsigned)(ret = vsnprintf( buf, blen, fmt, va )) >= (unsigned)blen) if (blen <= 0 || (uint)(ret = vsnprintf( buf, blen, fmt, va )) >= (uint)blen)
oob(); oob();
va_end( va ); va_end( va );
return ret; return ret;
@ -518,14 +518,14 @@ sort_ints( int *arr, int len )
static struct { static struct {
unsigned char i, j, s[256]; uchar i, j, s[256];
} rs; } rs;
void void
arc4_init( void ) arc4_init( void )
{ {
int i, fd; int i, fd;
unsigned char j, si, dat[128]; uchar j, si, dat[128];
if ((fd = open( "/dev/urandom", O_RDONLY )) < 0 && (fd = open( "/dev/random", O_RDONLY )) < 0) { if ((fd = open( "/dev/urandom", O_RDONLY )) < 0 && (fd = open( "/dev/random", O_RDONLY )) < 0) {
error( "Fatal: no random number source available.\n" ); error( "Fatal: no random number source available.\n" );
@ -551,10 +551,10 @@ arc4_init( void )
arc4_getbyte(); arc4_getbyte();
} }
unsigned char uchar
arc4_getbyte( void ) arc4_getbyte( void )
{ {
unsigned char si, sj; uchar si, sj;
rs.i++; rs.i++;
si = rs.s[rs.i]; si = rs.s[rs.i];
@ -565,7 +565,7 @@ arc4_getbyte( void )
return rs.s[(si + sj) & 0xff]; return rs.s[(si + sj) & 0xff];
} }
static const unsigned char prime_deltas[] = { static const uchar prime_deltas[] = {
0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 17, 27, 3, 0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 17, 27, 3,
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
}; };
@ -665,7 +665,7 @@ del_fd( int fd )
} }
#define shifted_bit(in, from, to) \ #define shifted_bit(in, from, to) \
(((unsigned)(in) & from) \ (((uint)(in) & from) \
/ (from > to ? from / to : 1) \ / (from > to ? from / to : 1) \
* (to > from ? to / from : 1)) * (to > from ? to / from : 1))

Loading…
Cancel
Save