From 4cbfda90fd8c47385236b9e22c6f39ba6f135733 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Thu, 28 Sep 2017 19:12:11 +0200 Subject: [PATCH] Move static stream helper functions to parse.c --- Makefile.in | 2 +- cssp.c | 28 ------------------------ parse.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ parse.h | 13 ++++++++++-- 4 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 parse.c diff --git a/Makefile.in b/Makefile.in index b83267d..0a6c4bc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -25,7 +25,7 @@ SOUNDOBJ = @SOUNDOBJ@ SCARDOBJ = @SCARDOBJ@ CREDSSPOBJ = @CREDSSPOBJ@ -RDPOBJ = tcp.o asn.o iso.o mcs.o secure.o licence.o rdp.o orders.o bitmap.o cache.o rdp5.o channels.o rdpdr.o serial.o printer.o disk.o parallel.o printercache.o mppc.o pstcache.o lspci.o seamless.o ssl.o utils.o +RDPOBJ = tcp.o asn.o iso.o mcs.o secure.o licence.o rdp.o orders.o bitmap.o cache.o rdp5.o channels.o rdpdr.o serial.o printer.o disk.o parallel.o printercache.o mppc.o pstcache.o lspci.o seamless.o ssl.o utils.o parse.o X11OBJ = rdesktop.o xwin.o xkeymap.o ewmhints.o xclip.o cliprdr.o ctrl.o .PHONY: all diff --git a/cssp.c b/cssp.c index 6ac3774..5183010 100644 --- a/cssp.c +++ b/cssp.c @@ -30,34 +30,6 @@ extern char *g_sc_container_name; static gss_OID_desc _gss_spnego_krb5_mechanism_oid_desc = { 9, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" }; - -static void -s_realloc(STREAM s, unsigned int size) -{ - unsigned char *data; - - if (s->size >= size) - return; - - data = s->data; - s->size = size; - s->data = xrealloc(data, size); - s->p = s->data + (s->p - data); - s->end = s->data + (s->end - data); - s->iso_hdr = s->data + (s->iso_hdr - data); - s->mcs_hdr = s->data + (s->mcs_hdr - data); - s->sec_hdr = s->data + (s->sec_hdr - data); - s->rdp_hdr = s->data + (s->rdp_hdr - data); - s->channel_hdr = s->data + (s->channel_hdr - data); -} - -static void -s_free(STREAM s) -{ - free(s->data); - free(s); -} - static STREAM ber_wrap_hdr_data(int tagval, STREAM in) { diff --git a/parse.c b/parse.c new file mode 100644 index 0000000..2b51fcf --- /dev/null +++ b/parse.c @@ -0,0 +1,61 @@ +/* + rdesktop: A Remote Desktop Protocol client. + Parsing primitives + Copyright 2017 Henrik Andersson for Cendio AB + + 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, either version 3 of the License, or + (at your option) any later version. + + 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, see . +*/ + +#include +#include "rdesktop.h" + +#include "parse.h" + +void +s_realloc(STREAM s, unsigned int size) +{ + unsigned char *data; + + if (s->size >= size) + return; + + data = s->data; + s->size = size; + s->data = xrealloc(data, size); + s->p = s->data + (s->p - data); + s->end = s->data + (s->end - data); + s->iso_hdr = s->data + (s->iso_hdr - data); + s->mcs_hdr = s->data + (s->mcs_hdr - data); + s->sec_hdr = s->data + (s->sec_hdr - data); + s->rdp_hdr = s->data + (s->rdp_hdr - data); + s->channel_hdr = s->data + (s->channel_hdr - data); +} + +void +s_reset(STREAM s) +{ + struct stream tmp; + tmp = *s; + memset(s, 0, sizeof(struct stream)); + s->size = tmp.size; + s->end = s->p = s->data = tmp.data; +} + + +void +s_free(STREAM s) +{ + free(s->data); + free(s); +} diff --git a/parse.h b/parse.h index 88ecbc9..ad26e1a 100644 --- a/parse.h +++ b/parse.h @@ -2,7 +2,7 @@ rdesktop: A Remote Desktop Protocol client. Parsing primitives Copyright (C) Matthew Chapman 1999-2008 - Copyright 2012 Henrik Andersson for Cendio AB + Copyright 2012-2017 Henrik Andersson for Cendio AB 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 @@ -18,6 +18,9 @@ along with this program. If not, see . */ +#ifndef _PARSE_H +#define _PARSE_H + /* Parser state */ typedef struct stream { @@ -36,6 +39,10 @@ typedef struct stream } *STREAM; +void s_realloc(STREAM s, unsigned int size); +void s_free(STREAM s); +void s_reset(STREAM s); + #define s_push_layer(s,h,n) { (s)->h = (s)->p; (s)->p += n; } #define s_pop_layer(s,h) (s)->p = (s)->h; #define s_mark_end(s) (s)->end = (s)->p; @@ -43,7 +50,6 @@ typedef struct stream #define s_check_rem(s,n) ((s)->p + n <= (s)->end) #define s_check_end(s) ((s)->p == (s)->end) #define s_length(s) ((s)->end - (s)->data) -#define s_reset(s) ((s)->end = (s)->p = (s)->data) #if defined(L_ENDIAN) && !defined(NEED_ALIGN) #define in_uint16_le(s,v) { v = *(uint16 *)((s)->p); (s)->p += 2; } @@ -95,3 +101,6 @@ typedef struct stream #define out_uint8s(s,n) { memset((s)->p,0,n); (s)->p += n; } #define next_be(s,v) v = ((v) << 8) + *((s)->p++); + + +#endif /* _PARSE_H */