lsquic_version.c revision c7d81ce1
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 2#include <string.h> 3 4#include "lsquic.h" 5#include "lsquic_int_types.h" 6#include "lsquic_version.h" 7 8 9static const unsigned char version_tags[N_LSQVER][4] = 10{ 11 [LSQVER_035] = { 'Q', '0', '3', '5', }, 12 [LSQVER_039] = { 'Q', '0', '3', '9', }, 13 [LSQVER_043] = { 'Q', '0', '4', '3', }, 14 [LSQVER_044] = { 'Q', '0', '4', '4', }, 15 [LSQVER_046] = { 'Q', '0', '4', '6', }, 16#if LSQUIC_USE_Q098 17 [LSQVER_098] = { 'Q', '0', '9', '8', }, 18#endif 19}; 20 21 22uint32_t 23lsquic_ver2tag (unsigned version) 24{ 25 lsquic_ver_tag_t tag; 26 if (version < N_LSQVER) 27 { 28 memcpy(&tag, version_tags[version], 4); 29 return tag; 30 } 31 else 32 return 0; 33} 34 35 36enum lsquic_version 37lsquic_tag2ver (uint32_t ver_tag) 38{ 39 unsigned n; 40 for (n = 0; n < sizeof(version_tags) / sizeof(version_tags[0]); ++n) 41 if (0 == memcmp(version_tags[n], &ver_tag, sizeof(ver_tag))) 42 return n; 43 return -1; 44} 45 46 47enum lsquic_version 48lsquic_str2ver (const char *str, size_t len) 49{ 50 uint32_t tag; 51 52 if (len == sizeof(tag) && 'Q' == str[0]) 53 { 54 memcpy(&tag, str, sizeof(tag)); 55 return lsquic_tag2ver(tag); 56 } 57 else 58 return -1; 59} 60 61 62const char *const lsquic_ver2str[N_LSQVER] = { 63 [LSQVER_035] = "Q035", 64 [LSQVER_039] = "Q039", 65 [LSQVER_043] = "Q043", 66 [LSQVER_044] = "Q044", 67 [LSQVER_046] = "Q046", 68#if LSQUIC_USE_Q098 69 [LSQVER_098] = "Q098", 70#endif 71}; 72 73 74