+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
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
=====================
#
AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue)
+#
+# Native BeOS support (disabled by default)
+#
+AM_CONDITIONAL(SILC_BEOS, test xfalse = xtrue)
+
#
# IPv6 support
#
--- /dev/null
+/*
+
+ 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 */
#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
#include "silcepoc.h"
#endif
+#ifdef SILC_BEOS
+#include "silcbeos.h"
+#endif
+
#ifndef DLLAPI
#define DLLAPI
#endif
if SILC_EPOC
SUBDIRS=epoc
else
+if SILC_BEOS
+SUBDIRS=beos
+else
SUBDIRS=unix
endif
endif
+endif
noinst_LIBRARIES = libsilcutil.a
--- /dev/null
+#
+# 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
--- /dev/null
+/*
+
+ 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 */
--- /dev/null
+/*
+
+ 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"
--- /dev/null
+/*
+
+ 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"
--- /dev/null
+/*
+
+ 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 */
--- /dev/null
+/*
+
+ 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
+}
--- /dev/null
+/*
+
+ 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"