forked from cfengine/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol_version.h
123 lines (102 loc) · 3.51 KB
/
protocol_version.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Copyright 2024 Northern.tech AS
This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
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; version 3.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
To the extent this program is licensed as part of the Enterprise
versions of CFEngine, the applicable Commercial Open Source License
(COSL) may apply to this file if you as a licensee so wish it. See
included file COSL.txt.
*/
#ifndef CFENGINE_PROTOCOL_VERSION_H
#define CFENGINE_PROTOCOL_VERSION_H
/**
Available protocol versions. When connection is initialised ProtocolVersion
is 0, i.e. undefined. It is after the call to ServerConnection() that
protocol version is decided, according to body copy_from and body common
control. All protocol numbers are numbered incrementally starting from 1.
*/
typedef enum
{
CF_PROTOCOL_UNDEFINED = 0,
CF_PROTOCOL_CLASSIC = 1,
/* --- Greater versions use TLS as secure communications layer --- */
CF_PROTOCOL_TLS = 2,
CF_PROTOCOL_COOKIE = 3,
} ProtocolVersion;
/* We use CF_PROTOCOL_LATEST as the default for new connections. */
#define CF_PROTOCOL_LATEST CF_PROTOCOL_COOKIE
static inline const char *ProtocolVersionString(const ProtocolVersion p)
{
switch (p)
{
case CF_PROTOCOL_COOKIE:
return "cookie";
case CF_PROTOCOL_TLS:
return "tls";
case CF_PROTOCOL_CLASSIC:
return "classic";
default:
return "undefined";
}
}
static inline bool ProtocolIsKnown(const ProtocolVersion p)
{
return ((p > CF_PROTOCOL_UNDEFINED) && (p <= CF_PROTOCOL_LATEST));
}
static inline bool ProtocolIsTLS(const ProtocolVersion p)
{
return ((p >= CF_PROTOCOL_TLS) && (p <= CF_PROTOCOL_LATEST));
}
static inline bool ProtocolIsTooNew(const ProtocolVersion p)
{
return (p > CF_PROTOCOL_LATEST);
}
static inline bool ProtocolIsUndefined(const ProtocolVersion p)
{
return (p <= CF_PROTOCOL_UNDEFINED);
}
static inline bool ProtocolIsClassic(const ProtocolVersion p)
{
return (p == CF_PROTOCOL_CLASSIC);
}
static inline bool ProtocolTerminateCSV(const ProtocolVersion p)
{
return (p < CF_PROTOCOL_COOKIE);
}
/**
* Returns CF_PROTOCOL_TLS or CF_PROTOCOL_CLASSIC (or CF_PROTOCOL_UNDEFINED)
* Maps all versions using TLS to CF_PROTOCOL_TLS for convenience
* in switch statements.
*/
static inline ProtocolVersion ProtocolClassicOrTLS(const ProtocolVersion p)
{
if (ProtocolIsTLS(p))
{
return CF_PROTOCOL_TLS;
}
if (ProtocolIsClassic(p))
{
return CF_PROTOCOL_CLASSIC;
}
return CF_PROTOCOL_UNDEFINED;
}
/**
* Parses the version string sent over network to enum, e.g. "CFE_v1" -> 1
*/
ProtocolVersion ParseProtocolVersionNetwork(const char *s);
/**
* Parses the version string set in policy to enum, e.g. "classic" -> 1
*/
ProtocolVersion ParseProtocolVersionPolicy(const char *s);
// Old name for compatibility (enterprise), TODO remove:
#define ProtocolVersionParse ParseProtocolVersionPolicy
#endif // CFENGINE_PROTOCOL_VERSION_H