]> Pileus Git - ~andy/fetchmail/blob - socket.h
Merge 'next' branch up to tag 'before-cpp'
[~andy/fetchmail] / socket.h
1 /**
2  * \file socket.h -- declarations for socket library functions
3  *
4  * For license terms, see the file COPYING in this directory.
5  */
6
7 #ifndef SOCKET__
8 #define SOCKET__
9
10 struct addrinfo;
11
12 #include <config.h>
13 #include <sys/socket.h>
14 #include <netdb.h>
15
16 /** Create a new client socket; returns -1 on error */
17 int SockOpen(const char *host, const char *service, const char *plugin, struct addrinfo **);
18
19 /** Sets the send/receive timeouts for socket \a sock to \a timeout
20  * seconds. \return zero on success. */
21 int SockTimeout(int sock, int timeout);
22
23 /** 
24 Get a string terminated by an '\n' (matches interface of fgets).
25 Pass it a valid socket, a buffer for the string, and
26 the length of the buffer (including the trailing \0)
27 returns length of buffer on success, -1 on failure. 
28 */
29 int SockRead(int sock, char *buf, int len);
30
31 /**
32  * Peek at the next socket character without actually reading it.
33  */
34 int SockPeek(int sock);
35
36 /**
37 Write a chunk of bytes to the socket (matches interface of fwrite).
38 Returns number of bytes successfully written.
39 */
40 int SockWrite(int sock, const char *buf, int size);
41
42 /* from /usr/include/sys/cdefs.h */
43 #if !defined __GNUC__
44 # define __attribute__(xyz)    /* Ignore. */
45 #endif
46
47 /**
48 Send formatted output to the socket (matches interface of fprintf).
49 Returns number of bytes successfully written.
50 */
51 int SockPrintf(int sock, const char *format, ...)
52     __attribute__ ((format (printf, 2, 3)))
53     ;
54  
55 /**
56 Close a socket previously opened by SockOpen.  This allows for some
57 additional clean-up if necessary.
58 */
59 int SockClose(int sock);
60
61 /**
62  \todo document this
63 */
64 int UnixOpen(const char *path);
65
66 #ifdef SSL_ENABLE
67 int SSLOpen(int sock, char *mycert, char *mykey, const char *myproto, int certck, char *cacertfile, char *cacertpath,
68     char *fingerprint, char *servercname, char *label, char **remotename);
69 #endif /* SSL_ENABLE */
70
71 #endif /* SOCKET__ */