File: protocol_version.c

package info (click to toggle)
cfengine3 3.15.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,456 kB
  • sloc: ansic: 145,932; sh: 8,550; makefile: 1,558; yacc: 1,192; python: 1,056; lex: 758; perl: 211; pascal: 149; awk: 58; xml: 21; sed: 13
file content (40 lines) | stat: -rw-r--r-- 1,026 bytes parent folder | download
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
#include <platform.h>
#include <protocol_version.h>
#include <string_lib.h>

ProtocolVersion ParseProtocolVersionNetwork(const char *const s)
{
    int version;
    const int ret = sscanf(s, "CFE_v%d", &version);
    if (ret != 1 || version <= CF_PROTOCOL_UNDEFINED)
    {
        return CF_PROTOCOL_UNDEFINED;
    }
    // Note that `version` may be above CF_PROTOCOL_LATEST, if the other side
    // supports a newer protocol
    return version;
}

ProtocolVersion ParseProtocolVersionPolicy(const char *const s)
{
    if ((s == NULL) || StringSafeEqual(s, "0") || StringSafeEqual(s, "undefined"))
    {
        return CF_PROTOCOL_UNDEFINED;
    }
    if (StringSafeEqual(s, "1") || StringSafeEqual(s, "classic"))
    {
        return CF_PROTOCOL_CLASSIC;
    }
    else if (StringSafeEqual(s, "2") || StringSafeEqual(s, "tls"))
    {
        return CF_PROTOCOL_TLS;
    }
    else if (StringSafeEqual(s, "latest"))
    {
        return CF_PROTOCOL_LATEST;
    }
    else
    {
        return CF_PROTOCOL_UNDEFINED;
    }
}