From bb3f2a853b13b11d018184b2bcc91a956134edd6 Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Fri, 8 May 2020 00:11:51 -0700 Subject: [PATCH] make buf_append_{be16,be32,le16} global These functions are already used by both oNCP and Pulse protocols, and will be used by PPP protocols as well. Make them shared/global. Signed-off-by: Daniel Lenski --- http.c | 27 +++++++++++++++++++++++++++ oncp.c | 18 ------------------ openconnect-internal.h | 3 +++ pulse.c | 18 ------------------ 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/http.c b/http.c index ace81e0b..1fa30142 100644 --- a/http.c +++ b/http.c @@ -68,6 +68,33 @@ void buf_append_xmlescaped(struct oc_text_buf *buf, const char *str) } } +void buf_append_be16(struct oc_text_buf *buf, uint16_t val) +{ + unsigned char b[2]; + + store_be16(b, val); + + buf_append_bytes(buf, b, 2); +} + +void buf_append_be32(struct oc_text_buf *buf, uint32_t val) +{ + unsigned char b[4]; + + store_be32(b, val); + + buf_append_bytes(buf, b, 4); +} + +void buf_append_le16(struct oc_text_buf *buf, uint16_t val) +{ + unsigned char b[2]; + + store_le16(b, val); + + buf_append_bytes(buf, b, 2); +} + void buf_append_hex(struct oc_text_buf *buf, const void *str, unsigned len) { const unsigned char *data = str; diff --git a/oncp.c b/oncp.c index f268eaf1..188fd68c 100644 --- a/oncp.c +++ b/oncp.c @@ -72,24 +72,6 @@ static int parse_cookie(struct openconnect_info *vpninfo) return 0; } -static void buf_append_be16(struct oc_text_buf *buf, uint16_t val) -{ - unsigned char b[2]; - - store_be16(b, val); - - buf_append_bytes(buf, b, 2); -} - -static void buf_append_le16(struct oc_text_buf *buf, uint16_t val) -{ - unsigned char b[2]; - - store_le16(b, val); - - buf_append_bytes(buf, b, 2); -} - static void buf_append_tlv(struct oc_text_buf *buf, uint16_t val, uint32_t len, void *data) { unsigned char b[6]; diff --git a/openconnect-internal.h b/openconnect-internal.h index 50fa043c..2f5e9e63 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -1129,6 +1129,9 @@ int buf_ensure_space(struct oc_text_buf *buf, int len); void __attribute__ ((format (printf, 2, 3))) buf_append(struct oc_text_buf *buf, const char *fmt, ...); void buf_append_bytes(struct oc_text_buf *buf, const void *bytes, int len); +void buf_append_be16(struct oc_text_buf *buf, uint16_t val); +void buf_append_be32(struct oc_text_buf *buf, uint32_t val); +void buf_append_le16(struct oc_text_buf *buf, uint16_t val); void buf_append_hex(struct oc_text_buf *buf, const void *str, unsigned len); int buf_append_utf16le(struct oc_text_buf *buf, const char *utf8); int get_utf8char(const char **utf8); diff --git a/pulse.c b/pulse.c index 582cbdce..fbe62c76 100644 --- a/pulse.c +++ b/pulse.c @@ -95,24 +95,6 @@ #define TTLS_MOREFRAGS (1<<6) #define TTLS_START (1<<5) -static void buf_append_be16(struct oc_text_buf *buf, uint16_t val) -{ - unsigned char b[2]; - - store_be16(b, val); - - buf_append_bytes(buf, b, 2); -} - -static void buf_append_be32(struct oc_text_buf *buf, uint32_t val) -{ - unsigned char b[4]; - - store_be32(b, val); - - buf_append_bytes(buf, b, 4); -} - static void buf_append_ift_hdr(struct oc_text_buf *buf, uint32_t vendor, uint32_t type) { uint32_t b[4]; -- 2.49.0