summaryrefslogtreecommitdiffstats
path: root/mutt_socket.h
blob: ab27bde41639253d5a5c69d5a91315c6cc46a494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright (C) 1998 Brandon Long <blong@fiction.net>
 * Copyright (C) 1999-2005 Brendan Cully <brendan@kublai.com>
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program; if not, write to the Free Software
 *     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef _MUTT_SOCKET_H_
#define _MUTT_SOCKET_H_ 1

#include "account.h"
#include "lib.h"

/* logging levels */
#define MUTT_SOCK_LOG_CMD  2
#define MUTT_SOCK_LOG_HDR  3
#define MUTT_SOCK_LOG_FULL 4

typedef struct _connection
{
  ACCOUNT account;
  /* security strength factor, in bits (in theory).
   *
   * In actuality, Mutt uses this as a boolean to determine if the connection
   * is "secure" using TLS or $tunnel if $tunnel_is_secure is set.
   *
   * The value is passed to SASL, but since no min_ssf is also passed to SASL
   * I don't believe it makes any difference.
   *
   * The GnuTLS code currently even puts bytes in here, so I doubt the exact
   * value has significance for Mutt purposes.
   */
  unsigned int ssf;
  void *data;

  char inbuf[LONG_STRING];
  int bufpos;

  int fd;
  int available;

  struct _connection *next;

  void *sockdata;
  int (*conn_read) (struct _connection* conn, char* buf, size_t len);
  int (*conn_write) (struct _connection *conn, const char *buf, size_t count);
  int (*conn_open) (struct _connection *conn);
  int (*conn_close) (struct _connection *conn);
  int (*conn_poll) (struct _connection *conn, time_t wait_secs);
} CONNECTION;

int mutt_socket_open (CONNECTION* conn);
int mutt_socket_close (CONNECTION* conn);
int mutt_socket_has_buffered_input (CONNECTION *conn);
void mutt_socket_clear_buffered_input (CONNECTION *conn);
int mutt_socket_poll (CONNECTION* conn, time_t wait_secs);
int mutt_socket_readchar (CONNECTION *conn, char *c);
#define mutt_socket_buffer_readln(A,B) mutt_socket_buffer_readln_d(A,B,MUTT_SOCK_LOG_CMD)
int mutt_socket_buffer_readln_d (BUFFER *buf, CONNECTION *conn, int dbg);
#define mutt_socket_readln(A,B,C) mutt_socket_readln_d(A,B,C,MUTT_SOCK_LOG_CMD)
int mutt_socket_readln_d (char *buf, size_t buflen, CONNECTION *conn, int dbg);
#define mutt_socket_write(A,B) mutt_socket_write_d(A,B,-1,MUTT_SOCK_LOG_CMD)
#define mutt_socket_write_n(A,B,C) mutt_socket_write_d(A,B,C,MUTT_SOCK_LOG_CMD)
int mutt_socket_write_d (CONNECTION *conn, const char *buf, int len, int dbg);

/* stupid hack for imap_logout_all */
CONNECTION* mutt_socket_head (void);
void mutt_socket_free (CONNECTION* conn);
CONNECTION* mutt_conn_find (const CONNECTION* start, const ACCOUNT* account);

int raw_socket_read (CONNECTION* conn, char* buf, size_t len);
int raw_socket_write (CONNECTION* conn, const char* buf, size_t count);
int raw_socket_open (CONNECTION *conn);
int raw_socket_close (CONNECTION *conn);
int raw_socket_poll (CONNECTION* conn, time_t wait_secs);

#endif /* _MUTT_SOCKET_H_ */