Commit Graph

463 Commits

Author SHA1 Message Date
Oswald Buddenhagen
256a147945 compile with -ansi -pedantic on gcc
greatly helps portability ...
2012-09-01 21:15:06 +02:00
Oswald Buddenhagen
96eaeb428d define _GNU_SOURCE on the command line
that way it is already set in configure and can thus be used by tests.
2012-09-01 21:14:53 +02:00
Oswald Buddenhagen
faeb9b5bf7 centralize imap_cmd_refcounted_state refcount decrementing
no else branches remain, so the if() can be put into
imap_refcounted_done()
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
f5086f735c get rid of redundant literal_pending state flag 2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
bd93d689db fully asynchronous IMAP operation
- asynchronous sockets using an event loop
  - connect & starttls have completion callback parameters
  - callbacks for notification about filled input buffer and emptied
    output buffer
- unsent imap command queue
  - used when
    - socket output buffer is non-empty
    - number of commands in flight exceeds limit
    - last sent command requires round-trip
    - command has a dependency on completion of previous command
  - trashnc is tri-state so only a single "scout" trash APPEND/COPY is
    sent at first. a possibly resulting CREATE is injected in front of
    the remaining trash commands, so they can succeed (or be cancel()d
    if it fails).
  - queue's presence necessitates imap_cancel implementation
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
7867eb9009 add simple mainloop implementation
not used so far
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
a55354516b move responsibility for closing sockets on error to user
the only user being imap and the first thing in imap_cancel_store()
being a call to socket_close(), this code was pretty pointless anyway.
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
802c99edcf make socket read/write error reporting callback-based
the functions still have synchronous return codes as well - this enables
early error returns without having to resort to refcounting.
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
f1df2f40d1 decouple the filling of the read buffer from consuming it
this prepares the code for being called from a callback.

notably, this makes the imap list parser have a "soft stack", so the
recursion can be suspended at any time.
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
886cd03e37 centralize imap_cmd disposal 2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
f8d73ac346 make socket_write() capable of taking ownership of the buffer
that way the user code doesn't have to free it any more.
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
8a72d204c9 change socket_write() return code semantics
instead of returning a write()-like result, return only a binary status
code - write errors are handled internally anyway, so user code doesn't
have to check the write length.
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
a85013d6ff make IMAP pipeline depth configurable
currently, this affects only "clustered" message listings and
flag stores.
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
a266f28f1c cancel submitted commands when canceling store
we already have some minimal asynchronicity, so there might be commands
in flight when a fatal error comes in.
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
171f7d6cd3 Socket_t + buffer_t => conn_t
remove the layering, in favor of a "buffered connection" abstraction.
2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
3447694c2b security fix: failure to load the certificate file is *not* OK ... 2012-09-01 16:03:36 +02:00
Oswald Buddenhagen
ef41349035 move socket code to a separate file
this makes the layering more obvious
2012-09-01 16:03:35 +02:00
Oswald Buddenhagen
d1ee94f02c move greeting response handling into get_cmd_result()
the primary purpose of this is getting rid of the "free-standing"
buffer_gets() call.
2012-09-01 16:03:35 +02:00
Oswald Buddenhagen
584e51ed7d docs
- insert "separator comments" between driver entry points
- document driver API
- document sync_vars_t parts that are stored in the sync state header
2012-09-01 16:03:35 +02:00
Oswald Buddenhagen
2ab689b3df make imap_exec() result reporting callback-based
this makes the IMAP command submission interface asynchronous.

the functions still have synchronous return codes as well - this enables
clean error return paths. only when we invoke callbacks we resort to
refcounting.

as a "side effect", properly sequence commands after CREATE resulting
from [TRYCREATE].
2012-09-01 16:03:35 +02:00
Oswald Buddenhagen
e5d323cc47 rely on the maildir's existence with "SyncState *"
now that we open the box first, we know that it will exist at this
point.
2012-09-01 16:03:35 +02:00
Oswald Buddenhagen
3169c59e10 validate maildirs more strictly
now that "SyncState *" won't create fake mailboxes any more, we can make
a full validity check again.
2012-09-01 16:03:35 +02:00
Oswald Buddenhagen
05fd0b9970 split out drv->load() from drv->select() 2012-09-01 16:02:50 +02:00
Oswald Buddenhagen
c741d5ffb5 make creation of trash folder independent from -C option
the trash is not a box which is synced, but a "byproduct" of
manipulating synced boxes, so it makes no sense to bind it to the same
option.
2012-07-30 01:21:32 +02:00
Oswald Buddenhagen
7addc3bea8 minor cleanup: use ctx->gen instead of gctx for consistency 2012-07-30 01:21:32 +02:00
Oswald Buddenhagen
424e0e7221 make callbacks return early when canceling
even after driver->cancel() the store may complete commands successfully.
return early in this case, so we don't attempt to continue syncing.
2012-07-30 01:21:32 +02:00
Oswald Buddenhagen
ea951a697f fix error paths wrt sync drivers, take 2
synchronous error codes which are passed through callbacks aren't a
particularly good idea, after all: latest when the callback does stuff
which does not concern the caller, the return code becomes ambiguous.
instead, protect the sync_vars object with a refcount when invoking
driver functions from loops, as the callbacks they call could invalidate
the object and we would have no way of knowing that the loop should be
aborted prematurely. the upcoming async imap driver will also need a
refcount to protect the cancelation marker of the imap socket dispatcher
loop.
2012-07-30 01:21:32 +02:00
Oswald Buddenhagen
ec8f440383 don't call cancel() repeatedly on a store
erroring command replies will trickle in even after canceling
2012-07-30 01:21:32 +02:00
Oswald Buddenhagen
b0bbd23512 replace DRV_STORE_BAD with a separate bad_callback()
that way we don't have to piggy-back (possibly asynchronous) fatal
errors to particular commands.

internally, the drivers still use synchronous return values as well,
so they don't try to access the invalidated store after calling back.
2012-07-30 01:21:31 +02:00
Oswald Buddenhagen
6d86e5347e don't access free'd memory in cancel_sync()
as it happens, the 1st round *may* trash svars - if we get the
cancelation request after the slave store has already died.
2012-07-29 12:26:38 +02:00
Oswald Buddenhagen
9554026443 make drv->cancel()'s callback have no status code
this function is not going to actually execute any commands, so it
makes no sense for the callback to have a status code.
2012-07-29 12:25:24 +02:00
Oswald Buddenhagen
57444e9df9 don't decode aux pointer on DRV_CANCELED
the aux data was already free()d by the error callback by the time we
get this status code.
2012-07-22 20:19:20 +02:00
Oswald Buddenhagen
06ccac1fdd always use return value from get_cmd_result()
once we have callback-based error reporting, this will ensure that we
don't operate on invalidated data structures.
2012-07-22 17:27:42 +02:00
Oswald Buddenhagen
121ce76e46 make response code parse failure of untagged OK/NO/BYE/BAD non-fatal
as such, it does not disrupt the data stream
2012-07-22 17:27:42 +02:00
Oswald Buddenhagen
d2e13f147c de-duplicate code a bit 2012-07-22 17:27:40 +02:00
Oswald Buddenhagen
4d4de6e275 remove redundant use_ssl variables
just use the presence of an SSL object as an indicator. if something
goes wrong during the ssl handshake or certificate validation, the
socket must be immediately closed anyway.
2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
fd229040d8 DRV_SERVER_BAD is and will probably stay unused => trash 2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
17dc64b414 after [TRYCREATE], just resend the same command instead of cloning it 2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
83efbe327d use return values from correct set in get_cmd_result()
DRV_OK == RESP_OK, so this worked by accident
2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
99cc328f17 do away with the dreaded rcaps hack
don't pretend that the server has no literal+ for the time of the
first relevant command's synchronous execution. instead, enable the
lower layer to do the processing by telling it for which commands
trashnc ("trash's existence not confirmed") is relevant.
2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
1545ed90a0 purge imap_store_t::currentnc vestiges
we always actually open the mailbox before appending to it, so we
obviously know that it exists - that's why the code was already
commented out. changing this assumption would significantly complicate
matters for little gain, so let's just assume it won't happen.

consequently, also don't set param.create when appending to regular
mailboxes.
2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
c66afdc0a8 move setting of ctx->listed outside the drivers
it's essentially an external state flag
2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
7bab2d6d94 de-duplicate error paths
makes the code more compact. yay for gotos.
2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
f6a25b331f check return value from close() after write()
otherwise we may lose data when quota is exceeded
or nfs is in a bad mood.
2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
61d98c5a1d fix a bunch of warnings 2012-07-07 18:00:47 +02:00
Oswald Buddenhagen
4afd31a457 avoid preprocessor warnings on missing features: #if => #ifdef 2011-03-27 12:06:41 +02:00
Oswald Buddenhagen
cf6a7b4d18 less bizarre code
we know that there is only one command in progress, so there
is no need to employ tricks to access the last command.
2011-03-27 11:54:48 +02:00
Oswald Buddenhagen
7e1c16ae02 make cram() sane
- don't silently fail in release mode (expression with side effects
  inside assert())
- save some redundand strlen()s by not throwing away known lengths
- reorganize the code for legibility
2011-03-27 11:54:48 +02:00
Oswald Buddenhagen
058d01f179 don't compare find_old_done with find_new_total
this didn't have any effect as no async drivers currently exist.
2011-03-27 11:54:48 +02:00
Oswald Buddenhagen
9e10e871fd don't hang if store cannot be opened asynchronously 2011-03-27 11:54:48 +02:00