Coverage Report

Created: 2023-09-25 07:17

/src/neomutt/mutt_socket.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * @file
3
 * NeoMutt connections
4
 *
5
 * @authors
6
 * Copyright (C) 2000-2007 Brendan Cully <brendan@kublai.com>
7
 *
8
 * @copyright
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License as published by the Free Software
11
 * Foundation, either version 2 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU General Public License along with
20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
/**
24
 * @page neo_mutt_socket NeoMutt connections
25
 *
26
 * NeoMutt connections
27
 */
28
29
#include "config.h"
30
#include <stdio.h>
31
#include <string.h>
32
#include "config/lib.h"
33
#include "email/lib.h"
34
#include "core/lib.h"
35
#include "conn/lib.h"
36
#include "mutt_socket.h"
37
#include "hook.h"
38
#include "mutt_account.h"
39
#ifndef USE_SSL
40
#include "mutt/lib.h"
41
#endif
42
43
/**
44
 * mutt_conn_new - Create a new Connection
45
 * @param cac Credentials to use
46
 * @retval ptr New Connection
47
 */
48
struct Connection *mutt_conn_new(const struct ConnAccount *cac)
49
0
{
50
0
  enum ConnectionType conn_type;
51
52
0
  const char *const c_tunnel = cs_subset_string(NeoMutt->sub, "tunnel");
53
0
  if (c_tunnel)
54
0
    conn_type = MUTT_CONNECTION_TUNNEL;
55
0
  else if (cac->flags & MUTT_ACCT_SSL)
56
0
    conn_type = MUTT_CONNECTION_SSL;
57
0
  else
58
0
    conn_type = MUTT_CONNECTION_SIMPLE;
59
60
0
  struct Connection *conn = mutt_socket_new(conn_type);
61
0
  if (conn)
62
0
  {
63
0
    memcpy(&conn->account, cac, sizeof(struct ConnAccount));
64
0
  }
65
0
  else
66
0
  {
67
0
    if (conn_type == MUTT_CONNECTION_SSL)
68
0
    {
69
0
#ifndef USE_SSL
70
      /* that's probably why it failed */
71
0
      mutt_error(_("SSL is unavailable, can't connect to %s"), cac->host);
72
0
#endif
73
0
    }
74
0
  }
75
0
  return conn;
76
0
}
77
78
/**
79
 * mutt_conn_find - Find a connection from a list
80
 * @param cac   ConnAccount to match
81
 * @retval ptr Matching Connection
82
 *
83
 * find a connection off the list of connections whose account matches cac.
84
 * If start is not null, only search for connections after the given connection
85
 * (allows higher level socket code to make more fine-grained searches than
86
 * account info. Eg in IMAP we may wish to find a connection which is not in
87
 * IMAP_SELECTED state)
88
 */
89
struct Connection *mutt_conn_find(const struct ConnAccount *cac)
90
0
{
91
0
  struct Url url = { 0 };
92
0
  char hook[1024] = { 0 };
93
94
  /* cac isn't actually modified, since url isn't either */
95
0
  mutt_account_tourl((struct ConnAccount *) cac, &url);
96
0
  url.path = NULL;
97
0
  url_tostring(&url, hook, sizeof(hook), U_NO_FLAGS);
98
0
  mutt_account_hook(hook);
99
100
0
  return mutt_conn_new(cac);
101
0
}