From 97cd5e75463b2f60a8542a459794a16a9dbc3e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Thu, 30 Jun 2011 19:25:11 -0400 Subject: [PATCH] libfreerdp-utils: added include headers --- include/freerdp/utils/datablob.h | 33 +++++++++++++ include/freerdp/utils/debug.h | 46 ++++++++++++++++++ include/freerdp/utils/hexdump.h | 27 +++++++++++ include/freerdp/utils/memory.h | 30 ++++++++++++ include/freerdp/utils/semaphore.h | 27 +++++++++++ include/freerdp/utils/stream.h | 80 +++++++++++++++++++++++++++++++ include/freerdp/utils/unicode.h | 53 ++++++++++++++++++++ 7 files changed, 296 insertions(+) create mode 100644 include/freerdp/utils/datablob.h create mode 100644 include/freerdp/utils/debug.h create mode 100644 include/freerdp/utils/hexdump.h create mode 100644 include/freerdp/utils/memory.h create mode 100644 include/freerdp/utils/semaphore.h create mode 100644 include/freerdp/utils/stream.h create mode 100644 include/freerdp/utils/unicode.h diff --git a/include/freerdp/utils/datablob.h b/include/freerdp/utils/datablob.h new file mode 100644 index 000000000..8eaf5ce6f --- /dev/null +++ b/include/freerdp/utils/datablob.h @@ -0,0 +1,33 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * DATABLOB Utils + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __DATABLOB_UTILS_H +#define __DATABLOB_UTILS_H + +struct _DATABLOB +{ + void* data; + int length; +}; +typedef struct _DATABLOB DATABLOB; + +void datablob_alloc(DATABLOB *datablob, int length); +void datablob_free(DATABLOB *datablob); + +#endif /* __DATABLOB_UTILS_H */ diff --git a/include/freerdp/utils/debug.h b/include/freerdp/utils/debug.h new file mode 100644 index 000000000..99bc8e796 --- /dev/null +++ b/include/freerdp/utils/debug.h @@ -0,0 +1,46 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Debug Utils + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTILS_DEBUG_H +#define __UTILS_DEBUG_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef WITH_DEBUG_ASSERT +#include +#define ASSERT(a) assert(a) +#else +#define ASSERT(a) do { } while (0) +#endif + +#include + +#define DEBUG_NULL(fmt, ...) do { } while (0) +#define DEBUG_PRINT(_dbg_str, fmt, ...) printf(_dbg_str fmt "\n" , __FUNCTION__, __LINE__, ## __VA_ARGS__) +#define DEBUG_CLASS(_dbg_class, fmt, ...) DEBUG_PRINT("DBG_" #_dbg_class " %s (%d): ", fmt, ## __VA_ARGS__) + +#ifdef WITH_DEBUG +#define DEBUG(fmt, ...) DEBUG_PRINT("DBG %s (%d): ", fmt, ## __VA_ARGS__) +#else +#define DEBUG(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +#endif + +#endif /* __UTILS_DEBUG_H */ diff --git a/include/freerdp/utils/hexdump.h b/include/freerdp/utils/hexdump.h new file mode 100644 index 000000000..3587c2953 --- /dev/null +++ b/include/freerdp/utils/hexdump.h @@ -0,0 +1,27 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Hex Dump Utils + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTILS_HEXDUMP_H +#define __UTILS_HEXDUMP_H + +#define FREERDP_HEXDUMP_LINE_LENGTH 16 + +void freerdp_hexdump(uint8* data, int length); + +#endif /* __UTILS_HEXDUMP_H */ diff --git a/include/freerdp/utils/memory.h b/include/freerdp/utils/memory.h new file mode 100644 index 000000000..520906284 --- /dev/null +++ b/include/freerdp/utils/memory.h @@ -0,0 +1,30 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Memory Utils + * + * Copyright 2009-2011 Jay Sorg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MEMORY_UTILS_H +#define __MEMORY_UTILS_H + +#include + +void* xmalloc(size_t size); +void* xrealloc(void * oldmem, size_t size); +void xfree(void * mem); +char* xstrdup(const char * s); + +#endif /* __MEMORY_UTILS_H */ diff --git a/include/freerdp/utils/semaphore.h b/include/freerdp/utils/semaphore.h new file mode 100644 index 000000000..cdb6da3eb --- /dev/null +++ b/include/freerdp/utils/semaphore.h @@ -0,0 +1,27 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Semaphore Utils + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SEMAPHORE_UTILS_H +#define __SEMAPHORE_UTILS_H + +void freerdp_sem_create(void * sem_struct, int iv); +void freerdp_sem_signal(void * sem_struct); +void freerdp_sem_wait(void * sem_struct); + +#endif /* __SEMAPHORE_UTILS_H */ diff --git a/include/freerdp/utils/stream.h b/include/freerdp/utils/stream.h new file mode 100644 index 000000000..fd16c1ee6 --- /dev/null +++ b/include/freerdp/utils/stream.h @@ -0,0 +1,80 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Stream Macro Utils + * + * Copyright 2009-2011 Jay Sorg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __STREAM_UTILS_H +#define __STREAM_UTILS_H + +#define GET_UINT8(_p1, _offset) *(((uint8 *) _p1) + _offset) +#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) +#define SET_UINT8A(_dest, _offset, _src, _len) ( \ + memcpy( \ + ((void *) (_dest + _offset)), \ + ((const void *) _src), \ + ((size_t) _len) \ + )) +#define SET_UINT8V(_dest, _offset, _value, _len) ( \ + memset( \ + ((void *) (_dest + _offset)), \ + ((int) _value), \ + ((size_t) _len) \ + )) +#define SET_UINT16(_p1, _offset, _value) \ + *(((uint8 *) _p1) + _offset) = (uint8) (((uint16) (_value)) & 0xff), \ + *(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint16) (_value)) >> 8) & 0xff) +#define SET_UINT32(_p1, _offset, _value) \ + *(((uint8 *) _p1) + _offset) = (uint8) (((uint32) (_value)) & 0xff), \ + *(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint32) (_value)) >> 8) & 0xff), \ + *(((uint8 *) _p1) + _offset + 2) = (uint8) ((((uint32) (_value)) >> 16) & 0xff), \ + *(((uint8 *) _p1) + _offset + 3) = (uint8) ((((uint32) (_value)) >> 24) & 0xff) +#define SET_UINT64(_p1, _offset, _value) \ + *(((uint8 *) _p1) + _offset) = (uint8) (((uint64) (_value)) & 0xff), \ + *(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint64) (_value)) >> 8) & 0xff), \ + *(((uint8 *) _p1) + _offset + 2) = (uint8) ((((uint64) (_value)) >> 16) & 0xff), \ + *(((uint8 *) _p1) + _offset + 3) = (uint8) ((((uint64) (_value)) >> 24) & 0xff), \ + *(((uint8 *) _p1) + _offset + 4) = (uint8) ((((uint64) (_value)) >> 32) & 0xff), \ + *(((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 */ + diff --git a/include/freerdp/utils/unicode.h b/include/freerdp/utils/unicode.h new file mode 100644 index 000000000..134d13780 --- /dev/null +++ b/include/freerdp/utils/unicode.h @@ -0,0 +1,53 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Unicode Utils + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UNICODE_UTILS_H +#define __UNICODE_UTILS_H + +#include +#include + +#define DEFAULT_CODEPAGE "UTF-8" +#define WINDOWS_CODEPAGE "UTF-16LE" + +#ifdef HAVE_ICONV +#include +#endif + +#ifndef ICONV_CONST +#define ICONV_CONST "" +#endif + +struct _UNICONV +{ + int iconv; +#ifdef HAVE_ICONV + iconv_t* in_iconv_h; + iconv_t* out_iconv_h; +#endif +}; +typedef struct _UNICONV UNICONV; + +UNICONV* freerdp_uniconv_new(); +void freerdp_uniconv_free(UNICONV *uniconv); +char* freerdp_uniconv_in(UNICONV *uniconv, unsigned char* pin, size_t in_len); +char* freerdp_uniconv_out(UNICONV *uniconv, char *str, size_t *pout_len); +void freerdp_uniconv_uppercase(UNICONV *uniconv, char *wstr, int length); + +#endif /* __UNICODE_UTILS_H */