summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorjsorg71 <jay.sorg@gmail.com>2016-08-05 14:38:41 -0700
committerGitHub <noreply@github.com>2016-08-05 14:38:41 -0700
commit8353baab3d361bcdebb32f1677dd066e0b255dc9 (patch)
tree38bd74dc119bdc115d5876383d7a65ff3e19debd /common
parent81fe939dd346420d41eb2afcd6c8c05a422a9e7b (diff)
parentace7d2c822937a9cb0637946f85d1fbd63562c44 (diff)
downloadxrdp-proprietary-8353baab3d361bcdebb32f1677dd066e0b255dc9.tar.gz
xrdp-proprietary-8353baab3d361bcdebb32f1677dd066e0b255dc9.zip
Merge pull request #390 from proski/june21
Cleanups and C++ compatibility
Diffstat (limited to 'common')
-rw-r--r--common/arch.h23
-rw-r--r--common/log.c12
-rw-r--r--common/log.h8
-rw-r--r--common/os_calls.c24
-rw-r--r--common/os_calls.h24
-rw-r--r--common/ssl_calls.c6
-rw-r--r--common/ssl_calls.h6
-rw-r--r--common/trans.c8
-rw-r--r--common/trans.h4
9 files changed, 62 insertions, 53 deletions
diff --git a/common/arch.h b/common/arch.h
index d3ae460e..7070d6ae 100644
--- a/common/arch.h
+++ b/common/arch.h
@@ -19,6 +19,10 @@
#if !defined(ARCH_H)
#define ARCH_H
+#if defined(HAVE_CONFIG_H)
+#include "config_ac.h"
+#endif
+
/* you can define L_ENDIAN or B_ENDIAN and NEED_ALIGN or NO_NEED_ALIGN
in the makefile to override */
@@ -109,7 +113,6 @@ typedef __int64 tbus;
#else
typedef long tbus;
#endif
-typedef tbus thandle;
typedef tbus tintptr;
/* wide char, socket */
#if defined(_WIN32)
@@ -125,4 +128,22 @@ typedef signed long long tsi64;
#endif
#endif /* DEFINED_Ts */
+/* format string verification */
+#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
+#define printflike(arg_format, arg_first_check) \
+ __attribute__((__format__(__printf__, arg_format, arg_first_check)))
+#else
+#define printflike(arg_format, arg_first_check)
+#endif
+
+/* module interface */
+#ifdef __cplusplus
+extern "C" {
+#endif
+ tintptr mod_init();
+ int mod_exit(tintptr);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/common/log.c b/common/log.c
index 54f625d7..77bcc6d6 100644
--- a/common/log.c
+++ b/common/log.c
@@ -212,12 +212,6 @@ internal_log_end(struct log_config *l_cfg)
l_cfg->log_file = 0;
}
- if (0 != l_cfg->program_name)
- {
- g_free(l_cfg->program_name);
- l_cfg->program_name = 0;
- }
-
ret = LOG_STARTUP_OK;
return ret;
}
@@ -336,7 +330,7 @@ internal_config_read_logging(int file, struct log_config *lc,
list_clear(param_n);
/* setting defaults */
- lc->program_name = g_strdup(applicationName);
+ lc->program_name = applicationName;
lc->log_file = 0;
lc->fd = 0;
lc->log_level = LOG_LEVEL_DEBUG;
@@ -401,7 +395,7 @@ enum logReturns DEFAULT_CC
internalInitAndAllocStruct(void)
{
enum logReturns ret = LOG_GENERAL_ERROR;
- g_staticLogConfig = g_malloc(sizeof(struct log_config), 1);
+ g_staticLogConfig = g_new0(struct log_config, 1);
if (g_staticLogConfig != NULL)
{
@@ -455,7 +449,7 @@ log_start_from_param(const struct log_config *iniParams)
g_staticLogConfig->log_level = iniParams->log_level;
g_staticLogConfig->log_lock = iniParams->log_lock;
g_staticLogConfig->log_lock_attr = iniParams->log_lock_attr;
- g_staticLogConfig->program_name = g_strdup(iniParams->program_name);
+ g_staticLogConfig->program_name = iniParams->program_name;
g_staticLogConfig->syslog_level = iniParams->syslog_level;
ret = internal_log_start(g_staticLogConfig);
diff --git a/common/log.h b/common/log.h
index 15307588..61a05d9c 100644
--- a/common/log.h
+++ b/common/log.h
@@ -65,12 +65,12 @@ enum logReturns
struct log_config
{
- char *program_name;
+ const char *program_name;
char *log_file;
int fd;
- unsigned int log_level;
+ enum logLevels log_level;
int enable_syslog;
- unsigned int syslog_level;
+ enum logLevels syslog_level;
pthread_mutex_t log_lock;
pthread_mutexattr_t log_lock_attr;
};
@@ -171,7 +171,7 @@ log_end(void);
* @return
*/
enum logReturns DEFAULT_CC
-log_message(const enum logLevels lvl, const char *msg, ...);
+log_message(const enum logLevels lvl, const char *msg, ...) printflike(2, 3);
/**
*
diff --git a/common/os_calls.c b/common/os_calls.c
index 2c8e37cd..234e01c7 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -402,7 +402,7 @@ g_tcp_set_keepalive(int sck)
/*****************************************************************************/
/* returns a newly created socket or -1 on error */
-/* in win32 a socket is an unsigned int, in linux, its an int */
+/* in win32 a socket is an unsigned int, in linux, it's an int */
int APP_CC
g_tcp_socket(void)
{
@@ -671,7 +671,6 @@ int APP_CC
g_tcp_connect(int sck, const char *address, const char *port)
{
int res = 0;
- char errorMsg[256];
struct addrinfo p;
struct addrinfo *h = (struct addrinfo *)NULL;
struct addrinfo *rp = (struct addrinfo *)NULL;
@@ -699,9 +698,8 @@ g_tcp_connect(int sck, const char *address, const char *port)
}
if (res != 0)
{
- snprintf(errorMsg, 255, "g_tcp_connect: getaddrinfo() failed: %s",
- gai_strerror(res));
- log_message(LOG_LEVEL_ERROR, errorMsg);
+ log_message(LOG_LEVEL_ERROR, "g_tcp_connect: getaddrinfo() failed: %s",
+ gai_strerror(res));
}
if (res > -1)
{
@@ -991,7 +989,7 @@ g_tcp_accept(int sck)
{
snprintf(ipAddr, 255, "A connection received from: %s port %d",
inet_ntoa(s.sin_addr), ntohs(s.sin_port));
- log_message(LOG_LEVEL_INFO,ipAddr);
+ log_message(LOG_LEVEL_INFO, "%s", ipAddr);
}
return ret ;
}
@@ -1016,7 +1014,7 @@ g_sck_accept(int sck, char *addr, int addr_bytes, char *port, int port_bytes)
{
g_snprintf(ipAddr, 255, "A connection received from: %s port %d",
inet_ntoa(s.sin_addr), ntohs(s.sin_port));
- log_message(LOG_LEVEL_INFO,ipAddr);
+ log_message(LOG_LEVEL_INFO, "%s", ipAddr);
if (s.sin_family == AF_INET)
{
g_snprintf(addr, addr_bytes, "%s", inet_ntoa(s.sin_addr));
@@ -1815,7 +1813,7 @@ g_file_read(int fd, char *ptr, int len)
/*****************************************************************************/
/* write to file, returns the number of bytes written or -1 on error */
int APP_CC
-g_file_write(int fd, char *ptr, int len)
+g_file_write(int fd, const char *ptr, int len)
{
#if defined(_WIN32)
@@ -1952,7 +1950,7 @@ g_get_current_dir(char *dirname, int maxlen)
/*****************************************************************************/
/* returns error, zero on success and -1 on failure */
int APP_CC
-g_set_current_dir(char *dirname)
+g_set_current_dir(const char *dirname)
{
#if defined(_WIN32)
@@ -2121,7 +2119,7 @@ g_strlen(const char *text)
/*****************************************************************************/
/* locates char in text */
-char* APP_CC
+const char *APP_CC
g_strchr(const char* text, int c)
{
if (text == NULL)
@@ -2218,7 +2216,7 @@ g_strdup(const char *in)
char *APP_CC
g_strndup(const char *in, const unsigned int maxlen)
{
- int len;
+ unsigned int len;
char *p;
if (in == 0)
@@ -2400,7 +2398,7 @@ g_htoi(char *str)
int APP_CC
g_pos(const char *str, const char *to_find)
{
- char *pp;
+ const char *pp;
pp = strstr(str, to_find);
@@ -3269,7 +3267,7 @@ g_save_to_bmp(const char* filename, char* data, int stride_bytes,
data -= stride_bytes;
if ((depth == 24) && (bits_per_pixel == 32))
{
- line = malloc(file_stride_bytes);
+ line = (char *) malloc(file_stride_bytes);
memset(line, 0, file_stride_bytes);
for (index = 0; index < height; index++)
{
diff --git a/common/os_calls.h b/common/os_calls.h
index 9f0e61fb..c103e144 100644
--- a/common/os_calls.h
+++ b/common/os_calls.h
@@ -21,14 +21,11 @@
#if !defined(OS_CALLS_H)
#define OS_CALLS_H
-#if defined(HAVE_CONFIG_H)
-#include "config_ac.h"
-#endif
-
#ifndef NULL
#define NULL 0
#endif
+#include <stdlib.h>
#include "arch.h"
#define g_tcp_can_recv g_sck_can_recv
@@ -45,13 +42,6 @@
#define g_tcp_select g_sck_select
#define g_close_wait_obj g_delete_wait_obj
-#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
-#define printflike(arg_format, arg_first_check) \
- __attribute__((__format__(__printf__, arg_format, arg_first_check)))
-#else
-#define printflike(arg_format, arg_first_check)
-#endif
-
int APP_CC g_rm_temp_dir(void);
int APP_CC g_mk_temp_dir(const char* app_name);
void APP_CC g_init(const char* app_name);
@@ -115,14 +105,14 @@ int APP_CC g_file_open_ex(const char *file_name, int aread, int awrite,
int acreate, int atrunc);
int APP_CC g_file_close(int fd);
int APP_CC g_file_read(int fd, char* ptr, int len);
-int APP_CC g_file_write(int fd, char* ptr, int len);
+int APP_CC g_file_write(int fd, const char *ptr, int len);
int APP_CC g_file_seek(int fd, int offset);
int APP_CC g_file_lock(int fd, int start, int len);
int APP_CC g_chmod_hex(const char* filename, int flags);
int APP_CC g_chown(const char* name, int uid, int gid);
int APP_CC g_mkdir(const char* dirname);
char* APP_CC g_get_current_dir(char* dirname, int maxlen);
-int APP_CC g_set_current_dir(char* dirname);
+int APP_CC g_set_current_dir(const char *dirname);
int APP_CC g_file_exist(const char* filename);
int APP_CC g_directory_exist(const char* dirname);
int APP_CC g_create_dir(const char* dirname);
@@ -131,7 +121,7 @@ int APP_CC g_remove_dir(const char* dirname);
int APP_CC g_file_delete(const char* filename);
int APP_CC g_file_get_size(const char* filename);
int APP_CC g_strlen(const char* text);
-char* APP_CC g_strchr(const char* text, int c);
+const char *APP_CC g_strchr(const char *text, int c);
char* APP_CC g_strcpy(char* dest, const char* src);
char* APP_CC g_strncpy(char* dest, const char* src, int len);
char* APP_CC g_strcat(char* dest, const char* src);
@@ -194,4 +184,10 @@ int APP_CC g_shmdt(const void *shmaddr);
int APP_CC g_gethostname(char *name, int len);
int APP_CC g_mirror_memcpy(void *dst, const void *src, int len);
+/* glib-style wrappers */
+#define g_new(struct_type, n_structs) \
+ (struct_type *) malloc(sizeof(struct_type) * (n_structs))
+#define g_new0(struct_type, n_structs) \
+ (struct_type *) calloc((n_structs), sizeof(struct_type))
+
#endif
diff --git a/common/ssl_calls.c b/common/ssl_calls.c
index b7eb6131..e3d3e67e 100644
--- a/common/ssl_calls.c
+++ b/common/ssl_calls.c
@@ -111,7 +111,7 @@ ssl_sha1_clear(void *sha1_info)
/*****************************************************************************/
void APP_CC
-ssl_sha1_transform(void *sha1_info, char *data, int len)
+ssl_sha1_transform(void *sha1_info, const char *data, int len)
{
SHA1_Update((SHA_CTX *)sha1_info, data, len);
}
@@ -187,7 +187,7 @@ ssl_des3_decrypt_info_create(const char *key, const char* ivec)
const tui8 *lkey;
const tui8 *livec;
- des3_ctx = g_malloc(sizeof(EVP_CIPHER_CTX), 1);
+ des3_ctx = g_new0(EVP_CIPHER_CTX, 1);
EVP_CIPHER_CTX_init(des3_ctx);
lkey = (const tui8 *) key;
livec = (const tui8 *) ivec;
@@ -560,7 +560,7 @@ ssl_tls_create(struct trans *trans, const char *key, const char *cert)
/*****************************************************************************/
int APP_CC
-ssl_tls_print_error(char *func, SSL *connection, int value)
+ssl_tls_print_error(const char *func, SSL *connection, int value)
{
switch (SSL_get_error(connection, value))
{
diff --git a/common/ssl_calls.h b/common/ssl_calls.h
index 6cfe73a3..aa7cffb1 100644
--- a/common/ssl_calls.h
+++ b/common/ssl_calls.h
@@ -41,7 +41,7 @@ ssl_sha1_info_delete(void* sha1_info);
void APP_CC
ssl_sha1_clear(void* sha1_info);
void APP_CC
-ssl_sha1_transform(void* sha1_info, char* data, int len);
+ssl_sha1_transform(void* sha1_info, const char *data, int len);
void APP_CC
ssl_sha1_complete(void* sha1_info, char* data);
void* APP_CC
@@ -84,8 +84,8 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_len,
/* ssl_tls */
struct ssl_tls
{
- void *ssl; /* SSL * */
- void *ctx; /* SSL_CTX * */
+ struct ssl_st *ssl; /* SSL * */
+ struct ssl_ctx_st *ctx; /* SSL_CTX * */
char *cert;
char *key;
struct trans *trans;
diff --git a/common/trans.c b/common/trans.c
index 9611f768..9e877d5c 100644
--- a/common/trans.c
+++ b/common/trans.c
@@ -28,7 +28,7 @@
/*****************************************************************************/
int APP_CC
-trans_tls_recv(struct trans *self, void *ptr, int len)
+trans_tls_recv(struct trans *self, char *ptr, int len)
{
if (self->tls == NULL)
{
@@ -39,7 +39,7 @@ trans_tls_recv(struct trans *self, void *ptr, int len)
/*****************************************************************************/
int APP_CC
-trans_tls_send(struct trans *self, const void *data, int len)
+trans_tls_send(struct trans *self, const char *data, int len)
{
if (self->tls == NULL)
{
@@ -61,14 +61,14 @@ trans_tls_can_recv(struct trans *self, int sck, int millis)
/*****************************************************************************/
int APP_CC
-trans_tcp_recv(struct trans *self, void *ptr, int len)
+trans_tcp_recv(struct trans *self, char *ptr, int len)
{
return g_tcp_recv(self->sck, ptr, len, 0);
}
/*****************************************************************************/
int APP_CC
-trans_tcp_send(struct trans *self, const void *data, int len)
+trans_tcp_send(struct trans *self, const char *data, int len)
{
return g_tcp_send(self->sck, data, len, 0);
}
diff --git a/common/trans.h b/common/trans.h
index 639e64d1..1bb15bcf 100644
--- a/common/trans.h
+++ b/common/trans.h
@@ -41,8 +41,8 @@ typedef int (DEFAULT_CC *ttrans_data_in)(struct trans* self);
typedef int (DEFAULT_CC *ttrans_conn_in)(struct trans* self,
struct trans* new_self);
typedef int (DEFAULT_CC *tis_term)(void);
-typedef int (APP_CC *trans_recv_proc) (struct trans *self, void *ptr, int len);
-typedef int (APP_CC *trans_send_proc) (struct trans *self, const void *data, int len);
+typedef int (APP_CC *trans_recv_proc) (struct trans *self, char *ptr, int len);
+typedef int (APP_CC *trans_send_proc) (struct trans *self, const char *data, int len);
typedef int (APP_CC *trans_can_recv_proc) (struct trans *self, int sck, int millis);
/* optional source info */