1 /* tlsComm.h - interface for the thin layer that looks
2 sort of like fgets and fprintf, but might read or write
3 to a socket or a TLS association
5 Neil Spring (nspring@cs.washington.edu)
7 Comments in @'s are for lclint's benefit:
8 http://lclint.cs.virginia.edu/
11 /* used to drill through per-mailbox debug keys */
14 /* opaque reference to the state associated with a
15 connection: may be just a file handle, or may include
17 struct connection_state
;
19 /* take a socket descriptor and negotiate a TLS connection
22 struct connection_state
*initialize_gnutls(int sd
, /*@only@ */ char *name
,
23 Pop3 pc
, const char *hostname
);
25 /* take a socket descriptor and bundle it into a connection
26 state structure for later communication */
28 struct connection_state
*initialize_unencrypted(int sd
, /*@only@ */
31 /* store a binding when connect() times out. these should be
32 skipped when trying to check mail so that other mailboxes
33 are checked responsively. I believe linux defaults to
34 around 90 seconds for a failed connect() attempt */
35 /* TODO: engineer an eventual retry scheme */
37 struct connection_state
*initialize_blacklist( /*@only@ */ char *name
);
38 int tlscomm_is_blacklisted(const struct connection_state
*scs
);
40 /* just like fprintf, only takes a connection state structure */
41 void tlscomm_printf(struct connection_state
*scs
, const char *format
, ...);
43 /* modeled after fgets; may not work exactly the same */
44 int tlscomm_gets( /*@out@ */ char *buf
,
45 int buflen
, struct connection_state
*scs
);
47 /* gobbles lines until it finds one starting with {prefix},
48 which is returned in buf */
49 int tlscomm_expect(struct connection_state
*scs
, const char *prefix
,
53 /* terminates the TLS association or just closes the socket,
54 and frees the connection state */
55 void tlscomm_close( /*@only@ */ struct connection_state
*scs
);
57 /* internal function exported for testing */
58 int getline_from_buffer(char *readbuffer
, char *linebuffer
,
61 #ifdef HAVE___ATTRIBUTE__
62 #define UNUSED(x) /*@unused@*/ x __attribute__((unused))