updates.
authorPekka Riikonen <priikone@silcnet.org>
Wed, 20 Feb 2002 16:52:04 +0000 (16:52 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 20 Feb 2002 16:52:04 +0000 (16:52 +0000)
13 files changed:
CHANGES
TODO
configure.in.pre
includes/silcbeos.h [new file with mode: 0644]
includes/silcincludes.h
lib/silcutil/Makefile.am
lib/silcutil/beos/Makefile.am [new file with mode: 0644]
lib/silcutil/beos/silcbeosmutex.c [new file with mode: 0644]
lib/silcutil/beos/silcbeosnet.c [new file with mode: 0644]
lib/silcutil/beos/silcbeosschedule.c [new file with mode: 0644]
lib/silcutil/beos/silcbeossockconn.c [new file with mode: 0644]
lib/silcutil/beos/silcbeosthread.c [new file with mode: 0644]
lib/silcutil/beos/silcbeosutil.c [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 88e5b1a2e4446a921ba347c408a0d9ba70f006c6..b2edc8703f5bd17353c70847e0723309d945666a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+Wed Feb 20 18:48:49 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added preliminary BeOS support into the util library.
+         Created lib/silcutil/beos/, and implemented all the needed
+         functions to support SILC on BeOS.  Created also file
+         includes/silcbeos.h.
+
 Mon Feb 18 15:49:22 EET 2002  Timo Sirainen <tss@iki.fi>
 
        * Added proper initializations to silc's irssi code, so it's
 Mon Feb 18 15:49:22 EET 2002  Timo Sirainen <tss@iki.fi>
 
        * Added proper initializations to silc's irssi code, so it's
diff --git a/TODO b/TODO
index abc1a8ac5584e889593aceab3d9b490ab0e4e400..21c58b76c80cb5ab32c2cc18298d81528a22c01c 100644 (file)
--- a/TODO
+++ b/TODO
@@ -106,6 +106,10 @@ Manual.
    and naming conventions used in the Toolkit (should not be 
    actually the CodingStyle document, but something more general).
 
    and naming conventions used in the Toolkit (should not be 
    actually the CodingStyle document, but something more general).
 
+ o Write "Platform Implementations" document to describe what platforms
+   Toolkit support, what has been implemented, what has not been, what
+   wors differently etc.
+
 
 TODO in SILC Protocol
 =====================
 
 TODO in SILC Protocol
 =====================
index 8fd771e78c83ca72dd2f9505bdf2856c6fbc4626..df04c31385aec210b2a772e0cb9796bb38b9bb03 100644 (file)
@@ -615,6 +615,11 @@ AM_CONDITIONAL(SILC_WIN32, test x$win32-support = xtrue)
 #
 AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue)
 
 #
 AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue)
 
+#
+# Native BeOS support (disabled by default)
+#
+AM_CONDITIONAL(SILC_BEOS, test xfalse = xtrue)
+
 #
 # IPv6 support
 #
 #
 # IPv6 support
 #
diff --git a/includes/silcbeos.h b/includes/silcbeos.h
new file mode 100644 (file)
index 0000000..cf024ed
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+
+  silcbeos.h 
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2002 Pekka Riikonen
+
+  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; version 2 of the License.
+
+  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.
+
+*/
+/* Native BeOS specific includes and definitions. */
+
+#ifndef SILCBEOS_H
+#define SILCBEOS_H
+
+#include <kernel/OS.h>
+#include <kernel/image.h>
+
+#endif /* SILCBEOS_H */
index c7182023028bd443f67b36dd1f12fde9c08223f8..c0c2d6e8ee2677b9e3d23d0712dccd9fcdb1f46b 100644 (file)
 #endif
 #endif
 
 #endif
 #endif
 
+#ifdef BEOS
+#ifndef SILC_BEOS
+#define SILC_BEOS
+#endif
+#elif defined(__BEOS__)
+#ifndef SILC_BEOS
+#define SILC_BEOS
+#endif
+#endif
+
+/* Platform specific includes */
+
 #ifdef SILC_WIN32
 #include "silcwin32.h"
 #endif
 #ifdef SILC_WIN32
 #include "silcwin32.h"
 #endif
 #include "silcepoc.h"
 #endif
 
 #include "silcepoc.h"
 #endif
 
+#ifdef SILC_BEOS
+#include "silcbeos.h"
+#endif
+
 #ifndef DLLAPI
 #define DLLAPI
 #endif
 #ifndef DLLAPI
 #define DLLAPI
 #endif
index ac4e73e0d7cca1997c143ebce0ec5c0a4d3d916d..c44060007dd25426c4eac895ddbdec9edbff7a6c 100644 (file)
@@ -23,9 +23,13 @@ else
 if SILC_EPOC
 SUBDIRS=epoc
 else
 if SILC_EPOC
 SUBDIRS=epoc
 else
+if SILC_BEOS
+SUBDIRS=beos
+else
 SUBDIRS=unix
 endif
 endif
 SUBDIRS=unix
 endif
 endif
+endif
 
 noinst_LIBRARIES = libsilcutil.a
 
 
 noinst_LIBRARIES = libsilcutil.a
 
diff --git a/lib/silcutil/beos/Makefile.am b/lib/silcutil/beos/Makefile.am
new file mode 100644 (file)
index 0000000..5cfe911
--- /dev/null
@@ -0,0 +1,31 @@
+#
+#  Makefile.am
+#
+#  Author: Pekka Riikonen <priikone@silcnet.org>
+#
+#  Copyright (C) 2002 Pekka Riikonen
+#
+#  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 2 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.
+#
+
+AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign
+
+noinst_LIBRARIES = libsilcbeosutil.a
+
+libsilcbeosutil_a_SOURCES =    \
+       silcbeosschedule.c      \
+       silcbeosnet.c           \
+       silcbeosutil.c          \
+       silcbeossockconn.c      \
+       silcbeosmutex.c         \
+       silcbeosthread.c
+
+include $(top_srcdir)/Makefile.defines.in
diff --git a/lib/silcutil/beos/silcbeosmutex.c b/lib/silcutil/beos/silcbeosmutex.c
new file mode 100644 (file)
index 0000000..7454492
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+
+  silcbeosmutex.c 
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2002 Pekka Riikonen
+
+  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; version 2 of the License.
+
+  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.
+
+*/
+/* $Id$ */
+
+#include "silcincludes.h"
+
+#ifdef SILC_THREADS
+
+/* SILC Mutex structure */
+struct SilcMutexStruct {
+  int sema_count;
+  sem_id sema;
+};
+
+bool silc_mutex_alloc(SilcMutex *mutex)
+{
+  int ret;
+
+  *mutex = silc_calloc(1, sizeof(**mutex));
+  if (*mutex == NULL)
+    return FALSE;
+
+  ret = create_sem(0, "SILC_MUTEX");
+  if (ret < B_NO_ERROR) {
+    silc_free(*mutex);
+    return FALSE;
+  }
+
+  (*mutex)->sema_count = 0;
+  (*mutex)->sema = ret;
+
+  return TRUE;
+}
+
+void silc_mutex_free(SilcMutex mutex)
+{
+  delete_sem(mutex->sema);
+  silc_free(mutex);
+}
+
+void silc_mutex_lock(SilcMutex mutex)
+{
+  if (atomic_add(&mutex->sema_count, 1) > 0) {
+    if (acquire_sem(mutex->sema) < B_NO_ERROR)
+      assert(FALSE);
+  }
+}
+
+void silc_mutex_unlock(SilcMutex mutex)
+{
+  if (atomic_add(&mutes->sema_count, -1) > 1) {
+    if (release_sem(mutex->sema) < B_NO_ERROR)
+      assert(FALSE);
+  }
+}
+
+#endif /* SILC_THREADS */
diff --git a/lib/silcutil/beos/silcbeosnet.c b/lib/silcutil/beos/silcbeosnet.c
new file mode 100644 (file)
index 0000000..616649d
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+
+  silcbeosnet.c 
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2002 Pekka Riikonen
+
+  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; version 2 of the License.
+
+  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.
+
+*/
+/* $Id$ */
+
+#include "silcincludes.h"
+
+/* Maybe works, or maybe not */
+#include "../unix/silcunixnet.c"
diff --git a/lib/silcutil/beos/silcbeosschedule.c b/lib/silcutil/beos/silcbeosschedule.c
new file mode 100644 (file)
index 0000000..5ff1549
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+
+  silcbeosschedule.c 
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2002 Pekka Riikonen
+
+  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; version 2 of the License.
+
+  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.
+
+*/
+/* $Id$ */
+
+/* Maybe works, or maybe not. The wakeup may cause problems, except 
+   on BONE... */
+#include "../unix/silcunixschedule.c"
diff --git a/lib/silcutil/beos/silcbeossockconn.c b/lib/silcutil/beos/silcbeossockconn.c
new file mode 100644 (file)
index 0000000..3b7c057
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+
+  silcbeossockconn.c 
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2002 Pekka Riikonen
+
+  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; version 2 of the License.
+
+  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.
+
+*/
+/* $Id$ */
+
+/* On BONE we can use Unix code */
+#ifdef SILC_BEOS_BONE
+#include "../unix/silcunixsockconn.c"
+#else
+#include "silcincludes.h"
+
+/* Writes data from encrypted buffer to the socket connection. If the
+   data cannot be written at once, it will be written later with a timeout. 
+   The data is written from the data section of the buffer, not from head
+   or tail section. This automatically pulls the data section towards end
+   after writing the data. */
+
+int silc_socket_write(SilcSocketConnection sock)
+{
+  int ret = 0;
+  SilcBuffer src = sock->outbuf;
+
+  if (SILC_IS_DISABLED(sock))
+    return -1;
+
+  SILC_LOG_DEBUG(("Writing data to socket %d", sock->sock));
+
+  if (src->len > 0) {
+    ret = send(sock->sock, src->data, src->len, 0);
+    if (ret == -1) {
+      if (errno == EWOULDBLOCK) {
+       SILC_LOG_DEBUG(("Could not write immediately, will do it later"));
+       return -2;
+      }
+      SILC_LOG_ERROR(("Cannot write to socket: %d", sock->sock));
+      sock->sock_error = errno;
+      return -1;
+    }
+
+    silc_buffer_pull(src, ret);
+  }
+
+  SILC_LOG_DEBUG(("Wrote data %d bytes", ret));
+
+  return ret;
+}
+
+/* Reads data from the socket connection into the incoming data buffer.
+   It reads as much as possible from the socket connection. This returns
+   amount of bytes read or -1 on error or -2 on case where all of the
+   data could not be read at once. */
+
+int silc_socket_read(SilcSocketConnection sock)
+{
+  int len = 0;
+  unsigned char buf[SILC_SOCKET_READ_SIZE];
+
+  if (SILC_IS_DISABLED(sock))
+    return -1;
+
+  SILC_LOG_DEBUG(("Reading data from socket %d", sock->sock));
+
+  /* Read the data from the socket. */
+  len = recv(sock->sock, buf, sizeof(buf), 0);
+  if (len == -1) {
+    if (errno == EWOULDBLOCK || errno == EINTR) {
+      SILC_LOG_DEBUG(("Could not read immediately, will do it later"));
+      return -2;
+    }
+    SILC_LOG_ERROR(("Cannot read from socket: %d", sock->sock));
+    sock->sock_error = errno;
+    return -1;
+  }
+
+  if (!len)
+    return 0;
+
+  /* Insert the data to the buffer. */
+
+  if (!sock->inbuf)
+    sock->inbuf = silc_buffer_alloc(SILC_SOCKET_BUF_SIZE);
+  
+  /* If the data does not fit to the buffer reallocate it */
+  if ((sock->inbuf->end - sock->inbuf->tail) < len)
+    sock->inbuf = silc_buffer_realloc(sock->inbuf, sock->inbuf->truelen + 
+                                     (len * 2));
+  silc_buffer_put_tail(sock->inbuf, buf, len);
+  silc_buffer_pull_tail(sock->inbuf, len);
+
+  SILC_LOG_DEBUG(("Read %d bytes", len));
+
+  return len;
+}
+
+/* Returns human readable socket error message */
+
+bool silc_socket_get_error(SilcSocketConnection sock, char *error,
+                          uint32 error_len)
+{
+  char *err;
+
+  if (!sock->sock_error)
+    return FALSE;
+
+  err = strerror(sock->sock_error);
+  if (strlen(err) > error_len)
+    return FALSE;
+
+  memset(error, 0, error_len);
+  memcpy(error, err, strlen(err));
+  return TRUE;
+}
+
+#endif /* SILC_BEOS_BONE */
diff --git a/lib/silcutil/beos/silcbeosthread.c b/lib/silcutil/beos/silcbeosthread.c
new file mode 100644 (file)
index 0000000..d6e88be
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+
+  silcbeosthread.c 
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2002 Pekka Riikonen
+
+  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; version 2 of the License.
+
+  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.
+
+*/
+/* $Id$ */
+
+#include "silcincludes.h"
+
+#ifdef SILC_THREADS
+
+/* Thread structure for BeOS */
+typedef struct {
+  thread_id thread;
+  SilcThreadStart start_func;
+  void *context;
+  bool waitable;
+} *SilcBeosThread;
+
+/* Actual routine that is called by BeOS when the thread is created.
+   We will call the start_func from here. */
+
+static void *silc_thread_beos_start(void *context)
+{
+  SilcBeosThread thread = (SilcBeosThread)context;
+  return (*thread->start_func)(thread->context);
+}
+
+#endif
+
+SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
+                             bool waitable)
+{
+#ifdef SILC_THREADS
+  int ret;
+  SilcBeosThread thread = silc_calloc(1, sizeof(*thread));
+  if (!thread)
+    return NULL;
+
+  thread->start_func = start_func;
+  thread->context = context;
+  thread->waitable = waitable;
+
+  /* Create the thread, and run it */
+  thread->thread = spawn_thread((thread_func)silc_thread_beos_start,
+                               B_NORMAL_PRIORITY, thread);
+  ret = resume_thread(thread->thread);
+  if (ret < B_NO_ERROR) {
+    SILC_LOG_ERROR(("Could not create new thread"));
+    silc_free(thread);
+    return NULL;
+  }
+
+  return (SilcThread)thread->thread;
+#else
+  /* Call thread callback immediately */
+  (*start_func)(context);
+  return NULL;
+#endif
+}
+
+void silc_thread_exit(void *exit_value)
+{
+#ifdef SILC_THREADS
+  exit_thread((status_t)exit_value);
+#endif
+}
+
+SilcThread silc_thread_self(void)
+{
+#ifdef SILC_THREADS
+  return (SilcThread)find_thread(NULL);
+#else
+  return NULL;
+#endif
+}
+
+bool silc_thread_wait(SilcThread thread, void **exit_value)
+{
+#ifdef SILC_THREADS
+  status_t ret, retval;
+
+  ret = wait_for_thread((thread_id)thread, &retval);
+  if (ret == B_NO_ERROR) {
+    if (exit_value)
+      *exit_value = retval;
+    return TRUE;
+  }
+
+  return FALSE;
+#else
+  return FALSE;
+#endif
+}
diff --git a/lib/silcutil/beos/silcbeosutil.c b/lib/silcutil/beos/silcbeosutil.c
new file mode 100644 (file)
index 0000000..555839d
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+
+  silcbeosutil.c 
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2002 Pekka Riikonen
+
+  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; version 2 of the License.
+
+  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.
+
+*/
+/* $Id$ */
+
+#include "silcincludes.h"
+
+/* Maybe works, or maybe not */
+#include "../unix/silcunixutil.c"