]> Pileus Git - ~andy/fetchmail/blob - socket.h
Note Earl's regression fix for SSL_CTX_clear_options() on older OpenSSL.
[~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 #ifdef HAVE_SYS_SOCKET_H
14 #include <sys/socket.h>
15 #elif HAVE_NET_SOCKET_H
16 #include <net/socket.h>
17 #endif
18 #include <netdb.h>
19
20 /** Create a new client socket; returns -1 on error */
21 int SockOpen(const char *host, const char *service, const char *plugin, struct addrinfo **);
22
23
24 /** 
25 Get a string terminated by an '\n' (matches interface of fgets).
26 Pass it a valid socket, a buffer for the string, and
27 the length of the buffer (including the trailing \0)
28 returns length of buffer on success, -1 on failure. 
29 */
30 int SockRead(int sock, char *buf, int len);
31
32 /**
33  * Peek at the next socket character without actually reading it.
34  */
35 int SockPeek(int sock);
36
37 /**
38 Write a chunk of bytes to the socket (matches interface of fwrite).
39 Returns number of bytes successfully written.
40 */
41 int SockWrite(int sock, const char *buf, int size);
42
43 /* from /usr/include/sys/cdefs.h */
44 #if !defined __GNUC__ || __GNUC__ < 2
45 # define __attribute__(xyz)    /* Ignore. */
46 #endif
47
48 /**
49 Send formatted output to the socket (matches interface of fprintf).
50 Returns number of bytes successfully written.
51 */
52 #if defined(HAVE_STDARG_H)
53 int SockPrintf(int sock, const char *format, ...)
54     __attribute__ ((format (printf, 2, 3)))
55     ;
56 #else
57 int SockPrintf();
58 #endif
59  
60 /**
61 Close a socket previously opened by SockOpen.  This allows for some
62 additional clean-up if necessary.
63 */
64 int SockClose(int sock);
65
66 /**
67  \todo document this
68 */
69 int UnixOpen(const char *path);
70
71 #ifdef SSL_ENABLE
72 int SSLOpen(int sock, char *mycert, char *mykey, const char *myproto, int certck, char *cacertfile, char *cacertpath,
73     char *fingerprint, char *servercname, char *label, char **remotename);
74 #endif /* SSL_ENABLE */
75
76 #endif /* SOCKET__ */