libfreerdp-utils: add new stream interface.

This commit is contained in:
Vic Lee 2011-07-01 16:06:53 +08:00
parent cfbb6c286c
commit cc6598de8f

View File

@ -1,8 +1,9 @@
/** /**
* FreeRDP: A Remote Desktop Protocol Client * FreeRDP: A Remote Desktop Protocol Client
* Stream Macro Utils * Stream Utils
* *
* Copyright 2009-2011 Jay Sorg * Copyright 2009-2011 Jay Sorg
* Copyright 2011 Vic Lee
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,61 +21,35 @@
#ifndef __STREAM_UTILS_H #ifndef __STREAM_UTILS_H
#define __STREAM_UTILS_H #define __STREAM_UTILS_H
#define GET_UINT8(_p1, _offset) *(((uint8 *) _p1) + _offset) #include <freerdp/types/base.h>
#define GET_UINT8A(_dest, _src, _offset, _len) ( \
memcpy( \
((void *) _dest), \
((const void *) (_src + _offset)), \
((size_t) _len) \
))
#define GET_UINT16(_p1, _offset) ( \
(uint16) (*(((uint8 *) _p1) + _offset)) + \
((uint16) (*(((uint8 *) _p1) + _offset + 1)) << 8))
#define GET_UINT32(_p1, _offset) ( \
(uint32) (*(((uint8 *) _p1) + _offset)) + \
((uint32) (*(((uint8 *) _p1) + _offset + 1)) << 8) + \
((uint32) (*(((uint8 *) _p1) + _offset + 2)) << 16) + \
((uint32) (*(((uint8 *) _p1) + _offset + 3)) << 24))
#define GET_UINT64(_p1, _offset) ( \
(uint64) (*(((uint8 *) _p1) + _offset)) + \
((uint64) (*(((uint8 *) _p1) + _offset + 1)) << 8) + \
((uint64) (*(((uint8 *) _p1) + _offset + 2)) << 16) + \
((uint64) (*(((uint8 *) _p1) + _offset + 3)) << 24) + \
((uint64) (*(((uint8 *) _p1) + _offset + 4)) << 32) + \
((uint64) (*(((uint8 *) _p1) + _offset + 5)) << 40) + \
((uint64) (*(((uint8 *) _p1) + _offset + 6)) << 48) + \
((uint64) (*(((uint8 *) _p1) + _offset + 7)) << 56))
#define SET_UINT8(_p1, _offset, _value) *(((uint8 *) _p1) + _offset) = (uint8) (_value) typedef struct _STREAM STREAM;
#define SET_UINT8A(_dest, _offset, _src, _len) ( \ struct _STREAM
memcpy( \ {
((void *) (_dest + _offset)), \ uint8 * buffer;
((const void *) _src), \ uint8 * ptr;
((size_t) _len) \ int size;
)) };
#define SET_UINT8V(_dest, _offset, _value, _len) ( \
memset( \ typedef uint8 * STREAM_MARK;
((void *) (_dest + _offset)), \
((int) _value), \ STREAM *
((size_t) _len) \ stream_new(int size);
)) void
#define SET_UINT16(_p1, _offset, _value) \ stream_free(STREAM * stream);
*(((uint8 *) _p1) + _offset) = (uint8) (((uint16) (_value)) & 0xff), \
*(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint16) (_value)) >> 8) & 0xff) #define stream_get_mark(_s) _s->ptr
#define SET_UINT32(_p1, _offset, _value) \ #define stream_set_mark(_s,_m) _s->ptr = _m
*(((uint8 *) _p1) + _offset) = (uint8) (((uint32) (_value)) & 0xff), \
*(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint32) (_value)) >> 8) & 0xff), \ #define stream_get_uint8(_s, _v) do { _v = *_s->ptr++; } while (0)
*(((uint8 *) _p1) + _offset + 2) = (uint8) ((((uint32) (_value)) >> 16) & 0xff), \ #define stream_get_uint16(_s, _v) do { _v = \
*(((uint8 *) _p1) + _offset + 3) = (uint8) ((((uint32) (_value)) >> 24) & 0xff) (uint16)(*_s->ptr) + \
#define SET_UINT64(_p1, _offset, _value) \ (((uint16)(*(_s->ptr + 1))) << 8); } while (0)
*(((uint8 *) _p1) + _offset) = (uint8) (((uint64) (_value)) & 0xff), \
*(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint64) (_value)) >> 8) & 0xff), \ #define stream_set_uint8(_s, _v) do { *_s->ptr++ = (uint8)(_v); } while (0)
*(((uint8 *) _p1) + _offset + 2) = (uint8) ((((uint64) (_value)) >> 16) & 0xff), \ #define stream_set_uint16(_s, _v) do { \
*(((uint8 *) _p1) + _offset + 3) = (uint8) ((((uint64) (_value)) >> 24) & 0xff), \ *_s->ptr++ = (_v) & 0xFF; \
*(((uint8 *) _p1) + _offset + 4) = (uint8) ((((uint64) (_value)) >> 32) & 0xff), \ *_s->ptr++ = (_v) >> 8; } while (0)
*(((uint8 *) _p1) + _offset + 5) = (uint8) ((((uint64) (_value)) >> 40) & 0xff), \
*(((uint8 *) _p1) + _offset + 6) = (uint8) ((((uint64) (_value)) >> 48) & 0xff), \
*(((uint8 *) _p1) + _offset + 7) = (uint8) ((((uint64) (_value)) >> 56) & 0xff)
#endif /* __STREAM_UTILS_H */ #endif /* __STREAM_UTILS_H */