Browse Source

Import CVS 20100303.

cvs -z3 -d:pserver:anonymous@xrdp.cvs.sourceforge.net:/cvsroot/xrdp \
    co -D 03-03-2010 -P xrdp
tags/upstream/0.5.0.20100303cvs
Vincent 11 years ago
parent
commit
d768b0e0e3
100 changed files with 8207 additions and 2734 deletions
  1. +0
    -68
      Makefile
  2. +14
    -0
      Makefile.am
  3. +1
    -1
      Xserver/hw/rdp/gcops.h
  4. +1
    -1
      Xserver/hw/rdp/rdp.h
  5. +1
    -1
      Xserver/hw/rdp/rdpdraw.c
  6. +3
    -3
      Xserver/hw/rdp/rdpinput.c
  7. +1
    -1
      Xserver/hw/rdp/rdpmain.c
  8. +1
    -1
      Xserver/hw/rdp/rdpmisc.c
  9. +1
    -1
      Xserver/hw/rdp/rdpup.c
  10. +0
    -1497
      Xserver/makefile_rdp
  11. +30
    -0
      bootstrap
  12. +23
    -0
      common/Makefile.am
  13. +30
    -7
      common/arch.h
  14. +1
    -1
      common/defines.h
  15. +93
    -14
      common/file.c
  16. +8
    -3
      common/file.h
  17. +11
    -7
      common/file_loc.h
  18. +32
    -15
      common/list.c
  19. +8
    -6
      common/list.h
  20. +22
    -49
      common/log.c
  21. +12
    -12
      common/log.h
  22. +829
    -70
      common/os_calls.c
  23. +51
    -6
      common/os_calls.h
  24. +1
    -1
      common/parse.h
  25. +144
    -11
      common/ssl_calls.c
  26. +4
    -1
      common/ssl_calls.h
  27. +28
    -16
      common/thread_calls.c
  28. +12
    -10
      common/thread_calls.h
  29. +383
    -0
      common/trans.c
  30. +74
    -0
      common/trans.h
  31. +18
    -1
      common/xrdp_constants.h
  32. +79
    -0
      configure.ac
  33. +0
    -9
      debian/changelog
  34. +0
    -1
      debian/compat
  35. +0
    -13
      debian/control
  36. +0
    -25
      debian/copyright
  37. +0
    -2
      debian/dirs
  38. +0
    -0
      debian/docs
  39. +0
    -2
      debian/postinst
  40. +0
    -2
      debian/postrm
  41. +0
    -6
      debian/preinst
  42. +0
    -6
      debian/prerm
  43. +0
    -8
      debian/readme.txt
  44. +0
    -98
      debian/rules
  45. +0
    -19
      docs/Makefile
  46. +3
    -0
      docs/Makefile.am
  47. +13
    -0
      docs/man/Makefile.am
  48. +0
    -0
      docs/man/xrdp-sesman.8
  49. +0
    -0
      docs/man/xrdp-sesrun.8
  50. +20
    -0
      faq-compile.txt
  51. +16
    -0
      faq-general.txt
  52. +63
    -0
      file-loc.txt
  53. +17
    -0
      fontdump/Makefile
  54. +458
    -0
      fontdump/fontdump.c
  55. +9
    -0
      genkeymap/Makefile.am
  56. +31
    -0
      genkeymap/dump-keymaps.sh
  57. +115
    -0
      genkeymap/genkeymap.c
  58. +35
    -0
      genkeymap/readme.txt
  59. +18
    -0
      instfiles/Makefile.am
  60. +659
    -0
      instfiles/km-0407.ini
  61. +659
    -0
      instfiles/km-0409.ini
  62. +659
    -0
      instfiles/km-040c.ini
  63. +659
    -0
      instfiles/km-0410.ini
  64. +659
    -0
      instfiles/km-0419.ini
  65. +659
    -0
      instfiles/km-041d.ini
  66. +19
    -0
      instfiles/pam.d/Makefile.am
  67. +1
    -0
      instfiles/pam.d/xrdp-sesman
  68. +17
    -21
      instfiles/xrdp.sh
  69. +0
    -146
      instfiles/xrdp_control1.sh
  70. +17
    -0
      keygen/Makefile.am
  71. +473
    -0
      keygen/keygen.c
  72. +0
    -50
      libxrdp/Makefile
  73. +26
    -0
      libxrdp/Makefile.am
  74. +16
    -8
      libxrdp/libxrdp.c
  75. +10
    -3
      libxrdp/libxrdp.h
  76. +10
    -2
      libxrdp/libxrdpinc.h
  77. +0
    -42
      libxrdp/makefile_win32
  78. +2
    -2
      libxrdp/xrdp_bitmap_compress.c
  79. +14
    -76
      libxrdp/xrdp_channel.c
  80. +1
    -1
      libxrdp/xrdp_iso.c
  81. +20
    -8
      libxrdp/xrdp_mcs.c
  82. +159
    -46
      libxrdp/xrdp_orders.c
  83. +141
    -103
      libxrdp/xrdp_rdp.c
  84. +87
    -116
      libxrdp/xrdp_sec.c
  85. +1
    -1
      libxrdp/xrdp_tcp.c
  86. +17
    -0
      mc/Makefile.am
  87. +114
    -0
      mc/mc.c
  88. +96
    -0
      mc/mc.h
  89. +0
    -39
      rdp/Makefile
  90. +26
    -0
      rdp/Makefile.am
  91. +0
    -31
      rdp/makefile_win32
  92. +53
    -1
      rdp/rdp.c
  93. +11
    -3
      rdp/rdp.h
  94. +1
    -1
      rdp/rdp_bitmap.c
  95. +1
    -1
      rdp/rdp_iso.c
  96. +1
    -1
      rdp/rdp_lic.c
  97. +1
    -1
      rdp/rdp_mcs.c
  98. +158
    -18
      rdp/rdp_orders.c
  99. +45
    -17
      rdp/rdp_rdp.c
  100. +1
    -1
      rdp/rdp_sec.c

+ 0
- 68
Makefile View File

@@ -1,68 +0,0 @@

DESTDIR = /usr/local/xrdp
CFGDIR = /etc/xrdp
PIDDIR = /var/run
MANDIR = /usr/local/man
DOCDIR = /usr/doc/xrdp

all: world

world: base
make -C sesman

base:
make -C vnc
make -C libxrdp
make -C xrdp
make -C rdp
make -C xup

nopam: base
make -C sesman nopam
make -C sesman tools

kerberos: base
make -C sesman kerberos
make -C sesman tools

clean:
make -C vnc clean
make -C libxrdp clean
make -C xrdp clean
make -C rdp clean
make -C sesman clean
make -C xup clean

install:
mkdir -p $(DESTDIR)
mkdir -p $(CFGDIR)
mkdir -p $(PIDDIR)
mkdir -p $(MANDIR)
mkdir -p $(DOCDIR)
make -C vnc install
make -C libxrdp install
make -C xrdp install
make -C rdp install
make -C sesman install
make -C xup install
make -C docs install
if [ -d /etc/pam.d ]; then install instfiles/pam.d/sesman /etc/pam.d/sesman; fi
install instfiles/xrdp_control.sh $(DESTDIR)/xrdp_control.sh

installdeb:
mkdir -p $(DESTDIRDEB)/usr/lib/xrdp
mkdir -p $(DESTDIRDEB)/etc/xrdp
mkdir -p $(DESTDIRDEB)/etc/pam.d
mkdir -p $(DESTDIRDEB)/etc/init.d
mkdir -p $(DESTDIRDEB)/usr/man
mkdir -p $(DESTDIRDEB)/usr/man/man5
mkdir -p $(DESTDIRDEB)/usr/man/man8
make -C vnc installdeb DESTDIRDEB=$(DESTDIRDEB)
make -C libxrdp installdeb DESTDIRDEB=$(DESTDIRDEB)
make -C xrdp installdeb DESTDIRDEB=$(DESTDIRDEB)
make -C rdp installdeb DESTDIRDEB=$(DESTDIRDEB)
make -C sesman installdeb DESTDIRDEB=$(DESTDIRDEB)
make -C xup installdeb DESTDIRDEB=$(DESTDIRDEB)
make -C docs installdeb DESTDIRDEB=$(DESTDIRDEB)
install instfiles/pam.d/sesman $(DESTDIRDEB)/etc/pam.d/sesman
install instfiles/xrdp_control1.sh $(DESTDIRDEB)/etc/init.d/xrdp_control.sh

+ 14
- 0
Makefile.am View File

@@ -0,0 +1,14 @@

SUBDIRS = \
common \
vnc \
rdp \
xup \
mc \
libxrdp \
xrdp \
sesman \
keygen \
docs \
instfiles \
genkeymap

+ 1
- 1
Xserver/hw/rdp/gcops.h View File

@@ -1,5 +1,5 @@
/*
Copyright 2005-2007 Jay Sorg
Copyright 2005-2008 Jay Sorg

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that


+ 1
- 1
Xserver/hw/rdp/rdp.h View File

@@ -1,5 +1,5 @@
/*
Copyright 2005-2007 Jay Sorg
Copyright 2005-2008 Jay Sorg

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that


+ 1
- 1
Xserver/hw/rdp/rdpdraw.c View File

@@ -1,5 +1,5 @@
/*
Copyright 2005-2007 Jay Sorg
Copyright 2005-2008 Jay Sorg

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that


+ 3
- 3
Xserver/hw/rdp/rdpinput.c View File

@@ -1,5 +1,5 @@
/*
Copyright 2005-2007 Jay Sorg
Copyright 2005-2008 Jay Sorg

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
@@ -771,8 +771,8 @@ KbdAddEvent(int down, int param1, int param2, int param3, int param4)
case 42: /* left shift */
ch = 10;
break;
case 43: /* / */
ch = 36;
case 43: /* \ or | */
ch = 37;
break;
case 44: /* z */
ch = 63;


+ 1
- 1
Xserver/hw/rdp/rdpmain.c View File

@@ -1,5 +1,5 @@
/*
Copyright 2005-2007 Jay Sorg
Copyright 2005-2008 Jay Sorg

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that


+ 1
- 1
Xserver/hw/rdp/rdpmisc.c View File

@@ -1,5 +1,5 @@
/*
Copyright 2005-2007 Jay Sorg
Copyright 2005-2008 Jay Sorg

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that


+ 1
- 1
Xserver/hw/rdp/rdpup.c View File

@@ -1,5 +1,5 @@
/*
Copyright 2005-2007 Jay Sorg
Copyright 2005-2008 Jay Sorg

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that


+ 0
- 1497
Xserver/makefile_rdp
File diff suppressed because it is too large
View File


+ 30
- 0
bootstrap View File

@@ -0,0 +1,30 @@
#!/bin/sh

which autoconf
if ! test $? -eq 0
then
echo "error, install autoconf"
exit 1
fi

which automake
if ! test $? -eq 0
then
echo "error, install automake"
exit 1
fi

which libtool
if ! test $? -eq 0
then
echo "error, install libtool"
exit 1
fi

touch configure.ac
touch NEWS
touch AUTHORS
touch README
touch ChangeLog
ln -s ../config.c $PWD/sesman/tools/config.c
autoreconf -fvi

+ 23
- 0
common/Makefile.am View File

@@ -0,0 +1,23 @@

AM_CFLAGS = \
-DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \
-DXRDP_SBIN_PATH=\"${sbindir}\" \
-DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \
-DXRDP_PID_PATH=\"${localstatedir}/run\"

lib_LTLIBRARIES = \
libcommon.la

libcommon_la_SOURCES = \
d3des.c \
file.c \
list.c \
log.c \
os_calls.c \
ssl_calls.c \
thread_calls.c \
trans.c

libcommon_la_LIBADD = \
-lcrypto \
-lpthread

+ 30
- 7
common/arch.h View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2010 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -24,20 +24,21 @@
#if !defined(ARCH_H)
#define ARCH_H

#if !(defined(L_ENDIAN) || defined(B_ENDIAN))
/* check endianess */
#if defined(__sparc__) || defined(__PPC__) || defined(__ppc__)
#if defined(__sparc__) || defined(__PPC__) || defined(__ppc__) || \
defined(__hppa__)
#define B_ENDIAN
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#else
#define L_ENDIAN
#elif __BYTE_ORDER == __BIG_ENDIAN
#define B_ENDIAN
#endif
/* check if we need to align data */
#if defined(__sparc__) || defined(__alpha__) || defined(__hppa__) || \
defined(__AIX__) || defined(__PPC__) || defined(__mips__) || \
defined(__ia64__) || defined(__ppc__)
defined(__ia64__) || defined(__ppc__) || defined(__arm__)
#define NEED_ALIGN
#endif
#endif

/* defines for thread creation factory functions */
#if defined(_WIN32)
@@ -48,7 +49,7 @@
#define THREAD_CC
#endif

#if defined(__BORLANDC__)
#if defined(__BORLANDC__) || defined(_WIN32)
#define APP_CC __fastcall
#define DEFAULT_CC __cdecl
#else
@@ -57,10 +58,14 @@
#endif

#if defined(_WIN32)
#if defined(__BORLANDC__)
#define EXPORT_CC _export __cdecl
#else
#define EXPORT_CC
#endif
#else
#define EXPORT_CC
#endif

typedef char ti8;
typedef unsigned char tui8;
@@ -71,6 +76,24 @@ typedef signed short tsi16;
typedef int ti32;
typedef unsigned int tui32;
typedef signed int tsi32;
#if defined(_WIN64)
/* Microsoft's VC++ compiler uses the more backwards-compatible LLP64 model.
Most other 64 bit compilers(Solaris, AIX, HP, Linux, Mac OS X) use
the LP64 model.
long is 32 bits in LLP64 model, 64 bits in LP64 model. */
typedef __int64 tbus;
#else
typedef long tbus;
#endif
typedef tbus thandle;
typedef tbus tintptr;
/* wide char, socket */
#if defined(_WIN32)
typedef unsigned short twchar;
typedef unsigned int tsock;
#else
typedef int twchar;
typedef int tsock;
#endif

#endif

+ 1
- 1
common/defines.h View File

@@ -14,7 +14,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2007
Copyright (C) Jay Sorg 2004-2009

main define/macro file



+ 93
- 14
common/file.c View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -32,8 +32,8 @@
/* returns error
returns 0 if everything is ok
returns 1 if problem reading file */
int APP_CC
file_read_sections(int fd, struct list* names)
static int APP_CC
l_file_read_sections(int fd, int max_file_size, struct list* names)
{
struct stream* s;
char text[256];
@@ -51,8 +51,8 @@ file_read_sections(int fd, struct list* names)
g_memset(text, 0, 256);
list_clear(names);
make_stream(s);
init_stream(s, 8192);
len = g_file_read(fd, s->data, 8192);
init_stream(s, max_file_size);
len = g_file_read(fd, s->data, max_file_size);
if (len > 0)
{
s->end = s->p + len;
@@ -65,7 +65,7 @@ file_read_sections(int fd, struct list* names)
}
else if (c == ']')
{
list_add_item(names, (long)g_strdup(text));
list_add_item(names, (tbus)g_strdup(text));
in_it = 0;
in_it_index = 0;
g_memset(text, 0, 256);
@@ -105,7 +105,7 @@ file_read_line(struct stream* s, char* text)
in_uint8(s, c);
while (c != 10 && c != 13)
{
if (c == '#' || c == '!')
if (c == '#' || c == '!' || c == ';')
{
skip_to_end = 1;
}
@@ -154,6 +154,7 @@ file_read_line(struct stream* s, char* text)
}

/*****************************************************************************/
/* returns error */
static int APP_CC
file_split_name_value(char* text, char* name, char* value)
{
@@ -188,14 +189,16 @@ file_split_name_value(char* text, char* name, char* value)
name[name_index] = 0;
}
}
g_strtrim(name, 3); /* trim both right and left */
g_strtrim(value, 3); /* trim both right and left */
return 0;
}

/*****************************************************************************/
/* return error */
int APP_CC
file_read_section(int fd, const char* section, struct list* names,
struct list* values)
static int APP_CC
l_file_read_section(int fd, int max_file_size, const char* section,
struct list* names, struct list* values)
{
struct stream* s;
char text[512];
@@ -206,7 +209,9 @@ file_read_section(int fd, const char* section, struct list* names,
int in_it_index;
int len;
int index;
int file_size;

file_size = 32 * 1024; /* 32 K file size limit */
g_file_seek(fd, 0);
in_it_index = 0;
in_it = 0;
@@ -214,8 +219,8 @@ file_read_section(int fd, const char* section, struct list* names,
list_clear(names);
list_clear(values);
make_stream(s);
init_stream(s, 8192);
len = g_file_read(fd, s->data, 8192);
init_stream(s, file_size);
len = g_file_read(fd, s->data, file_size);
if (len > 0)
{
s->end = s->p + len;
@@ -236,8 +241,8 @@ file_read_section(int fd, const char* section, struct list* names,
if (g_strlen(text) > 0)
{
file_split_name_value(text, name, value);
list_add_item(names, (long)g_strdup(name));
list_add_item(values, (long)g_strdup(value));
list_add_item(names, (tbus)g_strdup(name));
list_add_item(values, (tbus)g_strdup(value));
}
}
free_stream(s);
@@ -257,3 +262,77 @@ file_read_section(int fd, const char* section, struct list* names,
free_stream(s);
return 1;
}

/*****************************************************************************/
/* returns error
returns 0 if everything is ok
returns 1 if problem reading file */
/* 32 K file size limit */
int APP_CC
file_read_sections(int fd, struct list* names)
{
return l_file_read_sections(fd, 32 * 1024, names);
}

/*****************************************************************************/
/* return error */
/* this function should be prefered over file_read_sections because it can
read any file size */
int APP_CC
file_by_name_read_sections(const char* file_name, struct list* names)
{
int fd;
int file_size;
int rv;

file_size = g_file_get_size(file_name);
if (file_size < 1)
{
return 1;
}
fd = g_file_open(file_name);
if (fd < 1)
{
return 1;
}
rv = l_file_read_sections(fd, file_size, names);
g_file_close(fd);
return rv;
}

/*****************************************************************************/
/* return error */
/* 32 K file size limit */
int APP_CC
file_read_section(int fd, const char* section,
struct list* names, struct list* values)
{
return l_file_read_section(fd, 32 * 1024, section, names, values);
}

/*****************************************************************************/
/* return error */
/* this function should be prefered over file_read_section because it can
read any file size */
int APP_CC
file_by_name_read_section(const char* file_name, const char* section,
struct list* names, struct list* values)
{
int fd;
int file_size;
int rv;

file_size = g_file_get_size(file_name);
if (file_size < 1)
{
return 1;
}
fd = g_file_open(file_name);
if (fd < 1)
{
return 1;
}
rv = l_file_read_section(fd, file_size, section, names, values);
g_file_close(fd);
return rv;
}

+ 8
- 3
common/file.h View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -30,7 +30,12 @@
int APP_CC
file_read_sections(int fd, struct list* names);
int APP_CC
file_read_section(int fd, const char* section, struct list* names,
struct list* values);
file_by_name_read_sections(const char* file_name, struct list* names);
int APP_CC
file_read_section(int fd, const char* section,
struct list* names, struct list* values);
int APP_CC
file_by_name_read_section(const char* file_name, const char* section,
struct list* names, struct list* values);

#endif

+ 11
- 7
common/file_loc.h View File

@@ -14,7 +14,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2007
Copyright (C) Jay Sorg 2004-2009

default file locations for log, config, etc

@@ -23,16 +23,20 @@
#if !defined(FILE_LOC_H)
#define FILE_LOC_H

#if !defined(XRDP_CFG_FILE)
#define XRDP_CFG_FILE "xrdp.ini"
#if !defined(XRDP_CFG_PATH)
#define XRDP_CFG_PATH "/etc/xrdp"
#endif

#if !defined(XRDP_KEY_FILE)
#define XRDP_KEY_FILE "rsakeys.ini"
#if !defined(XRDP_PID_PATH)
#define XRDP_PID_PATH "/var/run"
#endif

#if !defined(XRDP_PID_FILE)
#define XRDP_PID_FILE "xrdp.pid"
#if !defined(XRDP_SBIN_PATH)
#define XRDP_SBIN_PATH "/usr/local/sbin"
#endif

#if !defined(XRDP_SHARE_PATH)
#define XRDP_SHARE_PATH "/usr/local/share/xrdp"
#endif

#endif

+ 32
- 15
common/list.c View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -35,7 +35,7 @@ list_create(void)
self = (struct list*)g_malloc(sizeof(struct list), 1);
self->grow_by = 10;
self->alloc_size = 10;
self->items = (long*)g_malloc(sizeof(long) * 10, 1);
self->items = (tbus*)g_malloc(sizeof(tbus) * 10, 1);
return self;
}

@@ -63,17 +63,17 @@ list_delete(struct list* self)

/*****************************************************************************/
void APP_CC
list_add_item(struct list* self, long item)
list_add_item(struct list* self, tbus item)
{
long* p;
tbus* p;
int i;

if (self->count >= self->alloc_size)
{
i = self->alloc_size;
self->alloc_size += self->grow_by;
p = (long*)g_malloc(sizeof(long) * self->alloc_size, 1);
g_memcpy(p, self->items, sizeof(long) * i);
p = (tbus*)g_malloc(sizeof(tbus) * self->alloc_size, 1);
g_memcpy(p, self->items, sizeof(tbus) * i);
g_free(self->items);
self->items = p;
}
@@ -82,7 +82,7 @@ list_add_item(struct list* self, long item)
}

/*****************************************************************************/
long APP_CC
tbus APP_CC
list_get_item(struct list* self, int index)
{
if (index < 0 || index >= self->count)
@@ -110,12 +110,12 @@ list_clear(struct list* self)
self->count = 0;
self->grow_by = 10;
self->alloc_size = 10;
self->items = (long*)g_malloc(sizeof(long) * 10, 1);
self->items = (tbus*)g_malloc(sizeof(tbus) * 10, 1);
}

/*****************************************************************************/
int APP_CC
list_index_of(struct list* self, long item)
list_index_of(struct list* self, tbus item)
{
int i;

@@ -152,9 +152,9 @@ list_remove_item(struct list* self, int index)

/*****************************************************************************/
void APP_CC
list_insert_item(struct list* self, int index, long item)
list_insert_item(struct list* self, int index, tbus item)
{
long* p;
tbus* p;
int i;

if (index == self->count)
@@ -169,8 +169,8 @@ list_insert_item(struct list* self, int index, long item)
{
i = self->alloc_size;
self->alloc_size += self->grow_by;
p = (long*)g_malloc(sizeof(long) * self->alloc_size, 1);
g_memcpy(p, self->items, sizeof(long) * i);
p = (tbus*)g_malloc(sizeof(tbus) * self->alloc_size, 1);
g_memcpy(p, self->items, sizeof(tbus) * i);
g_free(self->items);
self->items = p;
}
@@ -189,13 +189,30 @@ void APP_CC
list_append_list_strdup(struct list* self, struct list* dest, int start_index)
{
int index;
long item;
tbus item;
char* dup;

for (index = start_index; index < self->count; index++)
{
item = list_get_item(self, index);
dup = g_strdup((char*)item);
list_add_item(dest, (long)dup);
list_add_item(dest, (tbus)dup);
}
}

/*****************************************************************************/
void APP_CC
list_dump_items(struct list* self)
{
int index;
tbus item;

if (self->count == 0)
{
g_writeln("List is empty");
}
for (index = 0; index < self->count; index++)
{
g_writeln("%d: %s", index, list_get_item(self, index));
}
}

+ 8
- 6
common/list.h View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -30,7 +30,7 @@
/* list */
struct list
{
long* items;
tbus* items;
int count;
int alloc_size;
int grow_by;
@@ -42,18 +42,20 @@ list_create(void);
void APP_CC
list_delete(struct list* self);
void APP_CC
list_add_item(struct list* self, long item);
long APP_CC
list_add_item(struct list* self, tbus item);
tbus APP_CC
list_get_item(struct list* self, int index);
void APP_CC
list_clear(struct list* self);
int APP_CC
list_index_of(struct list* self, long item);
list_index_of(struct list* self, tbus item);
void APP_CC
list_remove_item(struct list* self, int index);
void APP_CC
list_insert_item(struct list* self, int index, long item);
list_insert_item(struct list* self, int index, tbus item);
void APP_CC
list_append_list_strdup(struct list* self, struct list* dest, int start_index);
void APP_CC
list_dump_items(struct list* self);

#endif

+ 22
- 49
common/log.c View File

@@ -14,7 +14,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2005-2007
Copyright (C) Jay Sorg 2005-2009
*/

#include <sys/types.h>
@@ -29,18 +29,6 @@

#include "log.h"

/* this gets created in log_start and freed in log_end */
static struct log_config* l_cfg;

/* threading additions */
#ifdef LOG_ENABLE_THREAD
#include "pthread.h"
/* these get initalized in log_start, they don't need
to get freed */
static pthread_mutex_t log_lock;
static pthread_mutexattr_t log_lock_attr;
#endif

/**
*
* @brief Opens log file
@@ -115,7 +103,7 @@ log_lvl2str(int lvl, char* str)

/******************************************************************************/
int DEFAULT_CC
log_message(const unsigned int lvl, const char* msg, ...)
log_message(struct log_config* l_cfg, const unsigned int lvl, const char* msg, ...)
{
char buff[LOG_BUFFER_SIZE + 31]; /* 19 (datetime) 4 (space+cr+lf+\0) */
va_list ap;
@@ -151,7 +139,7 @@ log_message(const unsigned int lvl, const char* msg, ...)
/* checking for truncated messages */
if (len > LOG_BUFFER_SIZE)
{
log_message(LOG_LEVEL_WARNING, "next message will be truncated");
log_message(l_cfg, LOG_LEVEL_WARNING, "next message will be truncated");
}

/* forcing the end of message string */
@@ -182,11 +170,11 @@ log_message(const unsigned int lvl, const char* msg, ...)

/* log to application logfile */
#ifdef LOG_ENABLE_THREAD
pthread_mutex_lock(&log_lock);
pthread_mutex_lock(&(l_cfg->log_lock));
#endif
rv = g_file_write(l_cfg->fd, (char*)buff, g_strlen((char*)buff));
#ifdef LOG_ENABLE_THREAD
pthread_mutex_unlock(&log_lock);
pthread_mutex_unlock(&(l_cfg->log_lock));
#endif
}
return rv;
@@ -194,44 +182,24 @@ log_message(const unsigned int lvl, const char* msg, ...)

/******************************************************************************/
int DEFAULT_CC
log_start(const char* progname, const char* logfile, const unsigned int loglvl,
const int syslog, const unsigned int syslvl)
log_start(struct log_config* l_cfg)
{
/* setup log struct */
l_cfg = (struct log_config*)g_malloc(sizeof(struct log_config), 1);

if (0 == l_cfg)
{
return LOG_ERROR_MALLOC;
}

/* if logfile is NULL, we use a default logfile */
if (0 == logfile)
if (0 == l_cfg->log_file)
{
l_cfg->log_file = g_strdup("./myprogram.log");
}
else
{
l_cfg->log_file = g_strdup(logfile);
}

/* if progname is NULL, we use a default name */
if (0 == progname)
if (0 == l_cfg->program_name)
{
l_cfg->program_name = g_strdup("myprogram");
}
else
{
l_cfg->program_name = g_strdup(progname);
}

/* setting log level */
l_cfg->log_level = loglvl;

/* 0 disables syslog, everything else enables it */
l_cfg->enable_syslog = (syslog ? 1 : 0);
/* forcing syslog_level to be always <= app logging level */
l_cfg->syslog_level = (syslvl>loglvl ? loglvl : syslvl);

/* open file */
l_cfg->fd = log_file_open(l_cfg->log_file);
@@ -248,8 +216,8 @@ log_start(const char* progname, const char* logfile, const unsigned int loglvl,
}

#ifdef LOG_ENABLE_THREAD
pthread_mutexattr_init(&log_lock_attr);
pthread_mutex_init(&log_lock, &log_lock_attr);
pthread_mutexattr_init(&(l_cfg->log_lock_attr));
pthread_mutex_init(&(l_cfg->log_lock), &(l_cfg->log_lock_attr));
#endif

return LOG_STARTUP_OK;
@@ -257,7 +225,7 @@ log_start(const char* progname, const char* logfile, const unsigned int loglvl,

/******************************************************************************/
void DEFAULT_CC
log_end(void)
log_end(struct log_config* l_cfg)
{
/* if log is closed, quit silently */
if (0 == l_cfg)
@@ -266,7 +234,7 @@ log_end(void)
}

/* closing log file */
log_message(LOG_LEVEL_ALWAYS, "shutting down log subsystem...");
log_message(l_cfg, LOG_LEVEL_ALWAYS, "shutting down log subsystem...");

if (0 > l_cfg->fd)
{
@@ -287,11 +255,16 @@ log_end(void)
}

/* freeing allocated memory */
g_free(l_cfg->log_file);
g_free(l_cfg->program_name);
g_free(l_cfg);

l_cfg = 0;
if (0 != l_cfg->log_file)
{
g_free(l_cfg->log_file);
l_cfg->log_file = 0;
}
if (0 != l_cfg->program_name)
{
g_free(l_cfg->program_name);
l_cfg->program_name = 0;
}
}

/******************************************************************************/


+ 12
- 12
common/log.h View File

@@ -14,12 +14,14 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2005-2007
Copyright (C) Jay Sorg 2005-2009
*/

#ifndef LOG_H
#define LOG_H

#include <pthread.h>

#include "arch.h"

/* logging buffer size */
@@ -44,9 +46,9 @@
/*#define LOG_ENABLE_THREAD*/

#ifdef DEBUG
#define LOG_DBG(s,args...) log_message(LOG_LEVEL_DEBUG,s,args);
#define LOG_DBG(lcfg,args...) log_message((lcfg), LOG_LEVEL_DEBUG, args);
#else
#define LOG_DBG(s,args...)
#define LOG_DBG(lcfg,args...)
#endif

struct log_config
@@ -57,6 +59,8 @@ struct log_config
unsigned int log_level;
int enable_syslog;
unsigned int syslog_level;
pthread_mutex_t log_lock;
pthread_mutexattr_t log_lock_attr;
};

/**
@@ -68,30 +72,26 @@ struct log_config
*
*/
int DEFAULT_CC
log_message(const unsigned int lvl, const char* msg, ...);
log_message(struct log_config* l_cfg, const unsigned int lvl, const char* msg, ...);

/**
*
* @brief Starts the logging subsystem
* @param progname string to prepend to syslog messages
* @param logfile log file path
* @param loglvl level of messages to log
* @param syslog if set to 0, disables the use of syslog
* @param syslvl level of messages to log to syslog
* @param l_cfg loggging system configuration
* @return
*
*/
int DEFAULT_CC
log_start(const char* progname, const char* logfile, const unsigned int loglvl,
const int syslog, const unsigned int syslvl);
log_start(struct log_config* l_cfg);

/**
*
* @brief Shuts down the logging subsystem
* @param l_cfg pointer to the logging subsystem to stop
*
*/
void DEFAULT_CC
log_end(void);
log_end(struct log_config* l_cfg);

/**
*


+ 829
- 70
common/os_calls.c
File diff suppressed because it is too large
View File


+ 51
- 6
common/os_calls.h View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -27,6 +27,10 @@

#include "arch.h"

void APP_CC
g_init(void);
void APP_CC
g_deinit(void);
void* APP_CC
g_malloc(int size, int zero);
void APP_CC
@@ -60,6 +64,8 @@ g_tcp_close(int sck);
int APP_CC
g_tcp_connect(int sck, const char* address, const char* port);
int APP_CC
g_tcp_local_connect(int sck, const char* port);
int APP_CC
g_tcp_force_send(int sck, char* data, int len);
int APP_CC
g_tcp_force_recv(int sck, char* data, int len);
@@ -89,6 +95,23 @@ int APP_CC
g_tcp_select(int sck1, int sck2);
void APP_CC
g_sleep(int msecs);
tbus APP_CC
g_create_wait_obj(char* name);
tbus APP_CC
g_create_wait_obj_from_socket(tbus socket, int write);
void APP_CC
g_delete_wait_obj_from_socket(tbus wait_obj);
int APP_CC
g_set_wait_obj(tbus obj);
int APP_CC
g_reset_wait_obj(tbus obj);
int APP_CC
g_is_wait_obj_set(tbus obj);
int APP_CC
g_delete_wait_obj(tbus obj);
int APP_CC
g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs, int wcount,
int mstimeout);
void APP_CC
g_random(char* data, int len);
int APP_CC
@@ -108,8 +131,6 @@ g_file_seek(int fd, int offset);
int APP_CC
g_file_lock(int fd, int start, int len);
int APP_CC
g_set_file_rights(const char* filename, int read, int write);
int APP_CC
g_chmod_hex(const char* filename, int flags);
int APP_CC
g_mkdir(const char* dirname);
@@ -128,6 +149,8 @@ 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_strcpy(char* dest, const char* src);
@@ -148,7 +171,15 @@ g_strncasecmp(const char* c1, const char* c2, int len);
int APP_CC
g_atoi(char* str);
int APP_CC
g_htoi(char* str);
int APP_CC
g_pos(char* str, const char* to_find);
int APP_CC
g_mbstowcs(twchar* dest, const char* src, int n);
int APP_CC
g_wcstombs(char* dest, const twchar* src, int n);
int APP_CC
g_strtrim(char* str, int trim_flags);
long APP_CC
g_load_library(char* in);
int APP_CC
@@ -160,15 +191,23 @@ g_system(char* aexec);
char* APP_CC
g_get_strerror(void);
int APP_CC
g_get_errno(void);
int APP_CC
g_execvp(const char* p1, char* args[]);
int APP_CC
g_execlp3(const char* a1, const char* a2, const char* a3);
void APP_CC
g_signal(int sig_num, void (*func)(int));
void APP_CC
g_signal_child_stop(void (*func)(int));
void APP_CC
g_unset_signals(void);
g_signal_hang_up(void (*func)(int));
void APP_CC
g_signal_user_interrupt(void (*func)(int));
void APP_CC
g_signal_kill(void (*func)(int));
void APP_CC
g_signal_terminate(void (*func)(int));
void APP_CC
g_signal_pipe(void (*func)(int));
int APP_CC
g_fork(void);
int APP_CC
@@ -176,6 +215,8 @@ g_setgid(int pid);
int APP_CC
g_initgroups(const char* user, int gid);
int APP_CC
g_getuid(void);
int APP_CC
g_setuid(int pid);
int APP_CC
g_waitchild(void);
@@ -202,5 +243,9 @@ int APP_CC
g_check_user_in_group(const char* username, int gid, int* ok);
int APP_CC
g_time1(void);
int APP_CC
g_time2(void);
int APP_CC
g_time3(void);

#endif

+ 1
- 1
common/parse.h View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),


+ 144
- 11
common/ssl_calls.c View File

@@ -14,7 +14,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2007
Copyright (C) Jay Sorg 2004-2009

ssl calls

@@ -25,18 +25,25 @@
#include <openssl/md5.h>
#include <openssl/sha.h>
#include <openssl/bn.h>
#include <openssl/rsa.h>

#include "os_calls.h"
#include "arch.h"
#include "ssl_calls.h"

#if defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x0090800f)
#undef OLD_RSA_GEN1
#else
#define OLD_RSA_GEN1
#endif

/* rc4 stuff */

/*****************************************************************************/
void* APP_CC
ssl_rc4_info_create(void)
{
return g_malloc(sizeof(RC4_KEY), 1);;
return g_malloc(sizeof(RC4_KEY), 1);
}

/*****************************************************************************/
@@ -50,14 +57,14 @@ ssl_rc4_info_delete(void* rc4_info)
void APP_CC
ssl_rc4_set_key(void* rc4_info, char* key, int len)
{
RC4_set_key((RC4_KEY*)rc4_info, len, (unsigned char*)key);
RC4_set_key((RC4_KEY*)rc4_info, len, (tui8*)key);
}

/*****************************************************************************/
void APP_CC
ssl_rc4_crypt(void* rc4_info, char* data, int len)
{
RC4((RC4_KEY*)rc4_info, len, (unsigned char*)data, (unsigned char*)data);
RC4((RC4_KEY*)rc4_info, len, (tui8*)data, (tui8*)data);
}

/* sha1 stuff */
@@ -94,7 +101,7 @@ ssl_sha1_transform(void* sha1_info, char* data, int len)
void APP_CC
ssl_sha1_complete(void* sha1_info, char* data)
{
SHA1_Final((unsigned char*)data, (SHA_CTX*)sha1_info);
SHA1_Final((tui8*)data, (SHA_CTX*)sha1_info);
}

/* md5 stuff */
@@ -131,7 +138,7 @@ ssl_md5_transform(void* md5_info, char* data, int len)
void APP_CC
ssl_md5_complete(void* md5_info, char* data)
{
MD5_Final((unsigned char*)data, (MD5_CTX*)md5_info);
MD5_Final((tui8*)data, (MD5_CTX*)md5_info);
}

/*****************************************************************************/
@@ -157,7 +164,7 @@ ssl_reverse_it(char* p, int len)
/*****************************************************************************/
int APP_CC
ssl_mod_exp(char* out, int out_len, char* in, int in_len,
char* mod, int mod_len, char* exp, int exp_len)
char* mod, int mod_len, char* exp, int exp_len)
{
BN_CTX* ctx;
BIGNUM lmod;
@@ -185,11 +192,11 @@ ssl_mod_exp(char* out, int out_len, char* in, int in_len,
BN_init(&lexp);
BN_init(&lin);
BN_init(&lout);
BN_bin2bn((unsigned char*)l_mod, mod_len, &lmod);
BN_bin2bn((unsigned char*)l_exp, exp_len, &lexp);
BN_bin2bn((unsigned char*)l_in, in_len, &lin);
BN_bin2bn((tui8*)l_mod, mod_len, &lmod);
BN_bin2bn((tui8*)l_exp, exp_len, &lexp);
BN_bin2bn((tui8*)l_in, in_len, &lin);
BN_mod_exp(&lout, &lin, &lexp, &lmod, ctx);
rv = BN_bn2bin(&lout, (unsigned char*)l_out);
rv = BN_bn2bin(&lout, (tui8*)l_out);
if (rv <= out_len)
{
ssl_reverse_it(l_out, rv);
@@ -210,3 +217,129 @@ ssl_mod_exp(char* out, int out_len, char* in, int in_len,
g_free(l_exp);
return rv;
}

#if defined(OLD_RSA_GEN1)
/*****************************************************************************/
/* returns error
generates a new rsa key
exp is passed in and mod and pri are passed out */
int APP_CC
ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_len,
char* mod, int mod_len, char* pri, int pri_len)
{
int my_e;
RSA* my_key;
char* lmod;
char* lpri;
tui8* lexp;
int error;
int len;

if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
{
return 1;
}
lmod = (char*)g_malloc(mod_len, 0);
lpri = (char*)g_malloc(pri_len, 0);
lexp = (tui8*)exp;
my_e = lexp[0];
my_e |= lexp[1] << 8;
my_e |= lexp[2] << 16;
my_e |= lexp[3] << 24;
/* srand is in stdlib.h */
srand(g_time1());
my_key = RSA_generate_key(key_size_in_bits, my_e, 0, 0);
error = my_key == 0;
if (error == 0)
{
len = BN_num_bytes(my_key->n);
error = len != mod_len;
}
if (error == 0)
{
BN_bn2bin(my_key->n, (tui8*)lmod);
ssl_reverse_it(lmod, mod_len);
}
if (error == 0)
{
len = BN_num_bytes(my_key->d);
error = len != pri_len;
}
if (error == 0)
{
BN_bn2bin(my_key->d, (tui8*)lpri);
ssl_reverse_it(lpri, pri_len);
}
if (error == 0)
{
g_memcpy(mod, lmod, mod_len);
g_memcpy(pri, lpri, pri_len);
}
RSA_free(my_key);
g_free(lmod);
g_free(lpri);
return error;
}
#else
/*****************************************************************************/
/* returns error
generates a new rsa key
exp is passed in and mod and pri are passed out */
int APP_CC
ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_len,
char* mod, int mod_len, char* pri, int pri_len)
{
BIGNUM* my_e;
RSA* my_key;
char* lexp;
char* lmod;
char* lpri;
int error;
int len;

if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
{
return 1;
}
lexp = (char*)g_malloc(exp_len, 0);
lmod = (char*)g_malloc(mod_len, 0);
lpri = (char*)g_malloc(pri_len, 0);
g_memcpy(lexp, exp, exp_len);
ssl_reverse_it(lexp, exp_len);
my_e = BN_new();
BN_bin2bn((tui8*)lexp, exp_len, my_e);
my_key = RSA_new();
error = RSA_generate_key_ex(my_key, key_size_in_bits, my_e, 0) == 0;
if (error == 0)
{
len = BN_num_bytes(my_key->n);
error = len != mod_len;
}
if (error == 0)
{
BN_bn2bin(my_key->n, (tui8*)lmod);
ssl_reverse_it(lmod, mod_len);
}
if (error == 0)
{
len = BN_num_bytes(my_key->d);
error = len != pri_len;
}
if (error == 0)
{
BN_bn2bin(my_key->d, (tui8*)lpri);
ssl_reverse_it(lpri, pri_len);
}
if (error == 0)
{
g_memcpy(mod, lmod, mod_len);
g_memcpy(pri, lpri, pri_len);
}
BN_free(my_e);
RSA_free(my_key);
g_free(lexp);
g_free(lmod);
g_free(lpri);
return error;
}
#endif

+ 4
- 1
common/ssl_calls.h View File

@@ -14,7 +14,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2007
Copyright (C) Jay Sorg 2004-2009

*/

@@ -54,5 +54,8 @@ ssl_md5_complete(void* md5_info, char* data);
int APP_CC
ssl_mod_exp(char* out, int out_len, char* in, int in_len,
char* mod, int mod_len, char* exp, int exp_len);
int APP_CC
ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_len,
char* mod, int mod_len, char* pri, int pri_len);

#endif

+ 28
- 16
common/thread_calls.c View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -64,34 +64,46 @@ tc_thread_create(void* (* start_routine)(void*), void* arg)
#endif

/*****************************************************************************/
long APP_CC
tbus APP_CC
tc_get_threadid(void)
{
#if defined(_WIN32)
return (long)GetCurrentThreadId();
return (tbus)GetCurrentThreadId();
#else
return (long)pthread_self();
return (tbus)pthread_self();
#endif
}

/*****************************************************************************/
long APP_CC
/* returns boolean */
int APP_CC
tc_threadid_equal(tbus tid1, tbus tid2)
{
#if defined(_WIN32)
return tid1 == tid2;
#else
return pthread_equal((pthread_t)tid1, (pthread_t)tid2);
#endif
}

/*****************************************************************************/
tbus APP_CC
tc_mutex_create(void)
{
#if defined(_WIN32)
return (long)CreateMutex(0, 0, 0);
return (tbus)CreateMutex(0, 0, 0);
#else
pthread_mutex_t* lmutex;

lmutex = (pthread_mutex_t*)g_malloc(sizeof(pthread_mutex_t), 0);
pthread_mutex_init(lmutex, 0);
return (long)lmutex;
return (tbus)lmutex;
#endif
}

/*****************************************************************************/
void APP_CC
tc_mutex_delete(long mutex)
tc_mutex_delete(tbus mutex)
{
#if defined(_WIN32)
CloseHandle((HANDLE)mutex);
@@ -106,7 +118,7 @@ tc_mutex_delete(long mutex)

/*****************************************************************************/
int APP_CC
tc_mutex_lock(long mutex)
tc_mutex_lock(tbus mutex)
{
#if defined(_WIN32)
WaitForSingleObject((HANDLE)mutex, INFINITE);
@@ -119,7 +131,7 @@ tc_mutex_lock(long mutex)

/*****************************************************************************/
int APP_CC
tc_mutex_unlock(long mutex)
tc_mutex_unlock(tbus mutex)
{
#if defined(_WIN32)
ReleaseMutex((HANDLE)mutex);
@@ -131,26 +143,26 @@ tc_mutex_unlock(long mutex)
}

/*****************************************************************************/
long APP_CC
tbus APP_CC
tc_sem_create(int init_count)
{
#if defined(_WIN32)
HANDLE sem;

sem = CreateSemaphore(0, init_count, init_count + 10, 0);
return (long)sem;
return (tbus)sem;
#else
sem_t* sem;

sem = g_malloc(sizeof(sem_t), 0);
sem_init(sem, 0, init_count);
return (long)sem;
return (tbus)sem;
#endif
}

/*****************************************************************************/
void APP_CC
tc_sem_delete(long sem)
tc_sem_delete(tbus sem)
{
#if defined(_WIN32)
CloseHandle((HANDLE)sem);
@@ -165,7 +177,7 @@ tc_sem_delete(long sem)

/*****************************************************************************/
int APP_CC
tc_sem_dec(long sem)
tc_sem_dec(tbus sem)
{
#if defined(_WIN32)
WaitForSingleObject((HANDLE)sem, INFINITE);
@@ -178,7 +190,7 @@ tc_sem_dec(long sem)

/*****************************************************************************/
int APP_CC
tc_sem_inc(long sem)
tc_sem_inc(tbus sem)
{
#if defined(_WIN32)
ReleaseSemaphore((HANDLE)sem, 1, 0);


+ 12
- 10
common/thread_calls.h View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2007 Jay Sorg
Copyright (c) 2004-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -30,23 +30,25 @@

int APP_CC
tc_thread_create(THREAD_RV (THREAD_CC * start_routine)(void*), void* arg);
long APP_CC
tbus APP_CC
tc_get_threadid(void);
long APP_CC
int APP_CC
tc_threadid_equal(tbus tid1, tbus tid2);
tbus APP_CC
tc_mutex_create(void);
void APP_CC
tc_mutex_delete(long mutex);
tc_mutex_delete(tbus mutex);
int APP_CC
tc_mutex_lock(long mutex);
tc_mutex_lock(tbus mutex);
int APP_CC
tc_mutex_unlock(long mutex);
long APP_CC
tc_mutex_unlock(tbus mutex);
tbus APP_CC
tc_sem_create(int init_count);
void APP_CC
tc_sem_delete(long sem);
tc_sem_delete(tbus sem);
int APP_CC
tc_sem_dec(long sem);
tc_sem_dec(tbus sem);
int APP_CC
tc_sem_inc(long sem);
tc_sem_inc(tbus sem);

#endif

+ 383
- 0
common/trans.c View File

@@ -0,0 +1,383 @@
/*
Copyright (c) 2008-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

generic transport

*/

#include "os_calls.h"
#include "trans.h"
#include "arch.h"
#include "parse.h"

/*****************************************************************************/
struct trans* APP_CC
trans_create(int mode, int in_size, int out_size)
{
struct trans* self;

self = (struct trans*)g_malloc(sizeof(struct trans), 1);
make_stream(self->in_s);
init_stream(self->in_s, in_size);
make_stream(self->out_s);
init_stream(self->out_s, out_size);
self->mode = mode;
return self;
}

/*****************************************************************************/
void APP_CC
trans_delete(struct trans* self)
{
if (self == 0)
{
return;
}
free_stream(self->in_s);
free_stream(self->out_s);
g_tcp_close(self->sck);
if (self->listen_filename != 0)
{
g_file_delete(self->listen_filename);
g_free(self->listen_filename);
}
g_free(self);
}

/*****************************************************************************/
int APP_CC
trans_get_wait_objs(struct trans* self, tbus* objs, int* count, int* timeout)
{
if (self == 0)
{
return 1;
}
if (self->status != 1)
{
return 1;
}
objs[*count] = self->sck;
(*count)++;
return 0;
}

/*****************************************************************************/
int APP_CC
trans_check_wait_objs(struct trans* self)
{
tbus in_sck;
struct trans* in_trans;
int read_bytes;
int to_read;
int read_so_far;
int rv;

if (self == 0)
{
return 1;
}
if (self->status != 1)
{
return 1;
}
rv = 0;
if (self->type1 == 1) /* listening */
{
if (g_tcp_can_recv(self->sck, 0))
{
in_sck = g_tcp_accept(self->sck);
if (in_sck == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
/* ok, but shouldn't happen */
}
else
{
/* error */
self->status = 0;
rv = 1;
}
}
if (in_sck != -1)
{
if (self->trans_conn_in != 0) /* is function assigned */
{
in_trans = trans_create(self->mode, self->in_s->size,
self->out_s->size);
in_trans->sck = in_sck;
in_trans->type1 = 2;
in_trans->status = 1;
if (self->trans_conn_in(self, in_trans) != 0)
{
trans_delete(in_trans);
}
}
else
{
g_tcp_close(in_sck);
}
}
}
}
else /* connected server or client (2 or 3) */
{
if (g_tcp_can_recv(self->sck, 0))
{
read_so_far = (int)(self->in_s->end - self->in_s->data);
to_read = self->header_size - read_so_far;
read_bytes = g_tcp_recv(self->sck, self->in_s->end, to_read, 0);
if (read_bytes == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
/* ok, but shouldn't happen */
}
else
{
/* error */
self->status = 0;
rv = 1;
}
}
else if (read_bytes == 0)
{
/* error */
self->status = 0;
rv = 1;
}
else
{
self->in_s->end += read_bytes;
}
read_so_far = (int)(self->in_s->end - self->in_s->data);
if (read_so_far == self->header_size)
{
if (self->trans_data_in != 0)
{
rv = self->trans_data_in(self);
init_stream(self->in_s, 0);
}
}
}
}
return rv;
}

/*****************************************************************************/
int APP_CC
trans_force_read(struct trans* self, int size)
{
int rv;
int rcvd;

if (self->status != 1)
{
return 1;
}
rv = 0;
while (size > 0)
{
rcvd = g_tcp_recv(self->sck, self->in_s->end, size, 0);
if (rcvd == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
if (!g_tcp_can_recv(self->sck, 10))
{
/* check for term here */
}
}
else
{
/* error */
self->status = 0;
rv = 1;
}
}
else if (rcvd == 0)
{
/* error */
self->status = 0;
rv = 1;
}
else
{
self->in_s->end += rcvd;
size -= rcvd;
}
}
return rv;
}

/*****************************************************************************/
int APP_CC
trans_force_write(struct trans* self)
{
int size;
int total;
int rv;
int sent;

if (self->status != 1)
{
return 1;
}
rv = 0;
size = (int)(self->out_s->end - self->out_s->data);
total = 0;
while (total < size)
{
sent = g_tcp_send(self->sck, self->out_s->data + total, size - total, 0);
if (sent == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
if (!g_tcp_can_send(self->sck, 10))
{
/* check for term here */
}
}
else
{
/* error */
self->status = 0;
rv = 1;
}
}
else if (sent == 0)
{
/* error */
self->status = 0;
rv = 1;
}
else
{
total = total + sent;
}
}
return rv;
}

/*****************************************************************************/
int APP_CC
trans_connect(struct trans* self, const char* server, const char* port,
int timeout)
{
int error;

if (self->sck != 0)
{
g_tcp_close(self->sck);
}
if (self->mode == 1) /* tcp */
{
self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck);
error = g_tcp_connect(self->sck, server, port);
}
else if (self->mode == 2) /* unix socket */
{
self->sck = g_tcp_local_socket();
g_tcp_set_non_blocking(self->sck);
error = g_tcp_local_connect(self->sck, port);
}
else
{
self->status = 0;
return 1;
}
if (error == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
if (g_tcp_can_send(self->sck, timeout))
{
self->status = 1; /* ok */
self->type1 = 3; /* client */
return 0;
}
}
return 1;
}
self->status = 1; /* ok */
self->type1 = 3; /* client */
return 0;
}

/*****************************************************************************/
int APP_CC
trans_listen(struct trans* self, char* port)
{
if (self->sck != 0)
{
g_tcp_close(self->sck);
}
if (self->mode == 1) /* tcp */
{
self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck);
if (g_tcp_bind(self->sck, port) == 0)
{
if (g_tcp_listen(self->sck) == 0)
{
self->status = 1; /* ok */
self->type1 = 1; /* listener */
return 0;
}
}
}
else if (self->mode == 2) /* unix socket */
{
g_free(self->listen_filename);
self->listen_filename = 0;
g_file_delete(port);
self->sck = g_tcp_local_socket();
g_tcp_set_non_blocking(self->sck);
if (g_tcp_local_bind(self->sck, port) == 0)
{
self->listen_filename = g_strdup(port);
if (g_tcp_listen(self->sck) == 0)
{
g_chmod_hex(port, 0xffff);
self->status = 1; /* ok */
self->type1 = 1; /* listener */
return 0;
}
}
}
return 1;
}

/*****************************************************************************/
struct stream* APP_CC
trans_get_in_s(struct trans* self)
{
return self->in_s;
}

/*****************************************************************************/
struct stream* APP_CC
trans_get_out_s(struct trans* self, int size)
{
init_stream(self->out_s, size);
return self->out_s;
}

+ 74
- 0
common/trans.h View File

@@ -0,0 +1,74 @@
/*
Copyright (c) 2008-2009 Jay Sorg

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

generic transport

*/

#if !defined(TRANS_H)
#define TRANS_H

#include "arch.h"
#include "parse.h"

struct trans; /* forward declaration */

typedef int (*ttrans_data_in)(struct trans* self);
typedef int (*ttrans_conn_in)(struct trans* self, struct trans* new_self);

struct trans
{
tbus sck;
int mode; /* 1 tcp, 2 unix socket */
int status;
int type1; /* 1 listener 2 server 3 client */