updates.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 7 Feb 2002 18:53:52 +0000 (18:53 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 7 Feb 2002 18:53:52 +0000 (18:53 +0000)
includes/silcepoc.h [new file with mode: 0644]
includes/silcincludes.h
lib/silcutil/Makefile.am
lib/silcutil/symbian/silcepocsockconn.cpp [new file with mode: 0644]
lib/silcutil/symbian/silcepocthread.cpp [new file with mode: 0644]
lib/silcutil/symbian/silcepocutil.cpp [new file with mode: 0644]

diff --git a/includes/silcepoc.h b/includes/silcepoc.h
new file mode 100644 (file)
index 0000000..ab57922
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+
+  silcepoc.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 EPOC specific includes and definitions. */
+
+#ifndef SILCEPOC_H
+#define SILCEPOC_H
+
+#include <e32std.h>
+#include <e32base.h>
+#include <e32cons.h>
+#include <e32svr.h>
+#include <e32hal.h>
+#include <w32std.h>
+#include <apgtask.h>
+#include <es_sock.h>
+#include <in_sock.h>
+
+#endif
index 0291158c4002bf1cfd372a03d4c6e25f28bb711a..fb68ce56c02f9bec916b242bcb876c5ae771fa53 100644 (file)
 #endif
 
 #if defined(__EPOC32__)
+#ifndef SILC_EPOC
 #define SILC_EPOC
 #endif
+#endif
 
 #ifdef SILC_WIN32
 #include "silcwin32.h"
index af1f7fb74c0a0426d9b9a3c6ec1ced7dd18cd0fe..07fb94619bb4d008c72a9fc45fa7446a6a6ff5ad 100644 (file)
@@ -1,14 +1,13 @@
 #
 #  Makefile.am
 #
-#  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+#  Author: Pekka Riikonen <priikone@silcnet.org>
 #
-#  Copyright (C) 2000 Pekka Riikonen
+#  Copyright (C) 2000 - 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.
+#  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
@@ -21,8 +20,12 @@ AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign
 if SILC_WIN32
 SUBDIRS=win32
 else
+if SILC_EPOC
+SUBDIRS=epoc
+else
 SUBDIRS=unix
 endif
+endif
 
 noinst_LIBRARIES = libsilcutil.a
 
diff --git a/lib/silcutil/symbian/silcepocsockconn.cpp b/lib/silcutil/symbian/silcepocsockconn.cpp
new file mode 100644 (file)
index 0000000..99853dc
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+
+  silcepocsockconn.cpp 
+
+  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"
+
+/* 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)
+{
+  /* XXX */
+}
+
+/* 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)
+{
+  /* XXX */
+}
+
+/* Returns human readable socket error message. These are copied from the
+   PuTTY. */
+
+#define PUT_ERROR(s) 
+do {
+  if (strlen(s) > err_len)
+    return FALSE;
+  memset(error, 0, error_len);
+  memcpy(error, s, strlen(s));
+  return TRUE;
+} while(0)
+
+bool silc_socket_get_error(SilcSocketConnection sock, char *error,
+                          uint32 error_len)
+{
+  if (sock->sock_error == KErrNone)
+    return FALSE;
+
+  switch (sock->sock_error) {
+  case KErrNotFound:
+    PUT_ERROR("Item not found. (NotFound)");
+  case KErrGeneral:
+    PUT_ERROR("Uncategorized error. (General)");
+  case KErrCancel:
+    PUT_ERROR("Operation cancelled. (Cancel)");
+  case KErrNoMemory:
+    PUT_ERROR("A memory allocation failed. (NoMemory)");
+  case KErrNotSupported:
+    PUT_ERROR("A function is not supported in a given context. "
+             "(NotSupported)");
+  case KErrArgument:
+    PUT_ERROR("An argument is out of range. (Argument)");
+  case KErrBadHandle:
+    PUT_ERROR("Bad handle. (BadHandle)");
+  case KErrOverflow:
+    PUT_ERROR("Overflow. (Overflow)");
+  case KErrUnderflow:
+    PUT_ERROR("Underflow. (Underflow)");
+  case KErrAlreadyExists:
+    PUT_ERROR("The resource already exists. (AlreadyExists)");
+  case KErrPathNotFound:
+    PUT_ERROR("In the context of file operations, the path was "
+             "not found. (PathNotFound)");
+  case KErrDied:
+    PUT_ERROR("A handle refers to a thread which has died (Died)");
+  case KErrInUse:
+    PUT_ERROR("A requested resource is already in use. (InUse)");
+  case KErrServerTerminated:
+    PUT_ERROR("A client/server operation cannot execute, because the "
+             "server has terminated. (ServerTerminated)");
+  case KErrServerBusy:
+    PUT_ERROR("A client/server operation cannot execute, because the server "
+             "is busy. (ServerBusy)");
+  case KErrNotReady:
+    PUT_ERROR("Resource not ready. Not initialized, or has no power. "
+             "(NotReady)");
+  case KErrUnknown:
+    PUT_ERROR("A device is of unknown type. (Unknown)");
+  case KErrCorrupt:
+    PUT_ERROR("Corrupted. (Corrupt)");
+  case KErrAccessDenied:
+    PUT_ERROR("Access denied. (AccessDenied)");
+  case KErrLocked:
+    PUT_ERROR("The operation cannot be performed, because the resource "
+             "is locked. (Locked)");
+  case KErrWrite:
+    PUT_ERROR("During a file write operation, not all the data could "
+             "be written. (Write)");
+  case KErrDisMounted:
+    PUT_ERROR("A volume which was to be used for a file system operation "
+             "has been dismounted. (DisMounted)");
+  case KErrEof:
+    PUT_ERROR("End of file has been reached. (Eof)");
+  case KErrDiskFull:
+    PUT_ERROR("A write operation could not complete, because the disk "
+             "was full. (DiskFull)");
+  case KErrBadDriver:
+    PUT_ERROR("A driver DLL was of the wrong type. (BadDriver)");
+  case KErrBadName:
+    PUT_ERROR("Name did not conform with the required syntax. (BadName)");
+  case KErrCommsLineFail:
+    PUT_ERROR("The communication line failed. (CommsLineFail)");
+  case KErrCommsFrame:
+    PUT_ERROR("A frame error occurred in a communications operation. "
+             "(CommsFrame)");
+  case KErrCommsOverrun:
+    PUT_ERROR("An overrun was detected by a communications driver. "
+             "(CommsOverrun)");
+  case KErrCommsParity:
+    PUT_ERROR("A parity error occurred in communications. (CommsParity)");
+  case KErrTimedOut:
+    PUT_ERROR("An operation timed out. (TimedOut)");
+  case KErrCouldNotConnect:
+    PUT_ERROR("A session could not connect. (CouldNotConnect)");
+  case KErrCouldNotDisconnect:
+    PUT_ERROR("A session could not disconnect. (CouldNotDisconnect)");
+  case KErrDisconnected:
+    PUT_ERROR("The required session was disconnected. (Disconnected)");
+  case KErrBadLibraryEntryPoint:
+    PUT_ERROR("A library entry point was not of the required type. "
+             "(BadLibraryEntryPoint)");
+  case KErrBadDescriptor:
+    PUT_ERROR("A non-descriptor parameter was passed. (BadDescriptor)");
+  case KErrAbort:
+    PUT_ERROR("An operation was aborted (Abort)");
+  case KErrTooBig:
+    PUT_ERROR("A number was too big (TooBig)");
+  case KErrDivideByZero:
+    PUT_ERROR("A divide-by-zero operation was attempted. (DivideByZero)");
+  case KErrBadPower:
+    PUT_ERROR("Insufficient power was available to complete an operation. "
+             "(BadPower)");
+  case KErrWouldBlock:
+    PUT_ERROR("Network error: Resource temporarily unavailable (WouldBlock)");
+  case KErrNetUnreach:
+    PUT_ERROR("Network unreachable. (NetUnreach)");
+  case KErrHostUnreach:
+    PUT_ERROR("Host unreachable. (HostUnreach)");
+  case KErrNoProtocolOpt:
+    PUT_ERROR("No such protocol option. (NoProtocolOpt)");
+  case KErrUrgentData:
+    PUT_ERROR("Urgent data arrived. (UrgentData)");
+  case KInvalSocket:
+    PUT_ERROR("Got NULL sokcet.");
+  }
+
+  return FALSE;
+}
diff --git a/lib/silcutil/symbian/silcepocthread.cpp b/lib/silcutil/symbian/silcepocthread.cpp
new file mode 100644 (file)
index 0000000..12ad59c
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+
+  silcepocthread.cpp
+
+  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 EPOC */
+typedef struct {
+  RThread *thread;
+  SilcThreadStart start_func;
+  void *context;
+  bool waitable;
+} *SilcEpocThread;
+
+/* The actual thread function */
+
+TInt silc_thread_epoc_start(TAny *context)
+{
+  SilcEpocThread thread = (SilcEpocThread)context;
+
+  thread->start_func(thread->context);
+  silc_thread_exit(NULL);
+
+  return 0;
+}
+
+SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
+                             bool waitable)
+{
+#ifdef SILC_THREADS
+  SilcEpocThread thread;
+  TInt ret;
+
+  SILC_LOG_DEBUG(("Creating new thread"));
+
+  thread = silc_calloc(1, sizeof(*thread));
+  thread->start_func = start_func;
+  thread->context = context;
+  thread->waitable = waitable;
+
+  /* Create the thread */
+  /* XXX Unique name should be given for the thread */
+  thread->thread = new RThread();
+  ret = thread->thread->Create(NULL, silc_thread_epoc_start, 0, 0, 0,
+                              (TAny *)thread, EOwnerProcess);
+  if (ret != KErrNone) {
+    SILC_LOG_ERROR(("Could not create new thread"));
+    delete thread->thread;
+    silc_free(thread);
+    return NULL;
+  }
+
+  return (SilcThread)thread;
+#else
+  /* Call thread callback immediately */
+  (*start_func)(context);
+  return NULL;
+#endif
+}
+
+void silc_thread_exit(void *exit_value)
+{
+#ifdef SILC_THREADS
+  /* XXX */
+#endif
+}
+
+SilcThread silc_thread_self(void)
+{
+#ifdef SILC_THREADS
+  /* XXX */
+  return NULL;
+#else
+  return NULL;
+#endif
+}
+
+bool silc_thread_wait(SilcThread thread, void **exit_value)
+{
+#ifdef SILC_THREADS
+  /* XXX */
+  return TRUE;
+#else
+  return FALSE;
+#endif
+}
diff --git a/lib/silcutil/symbian/silcepocutil.cpp b/lib/silcutil/symbian/silcepocutil.cpp
new file mode 100644 (file)
index 0000000..b43eda9
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+
+  silcepocutil.cpp
+
+  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"
+
+/* XXX TODO or use GNU regex if it compiles */
+char *silc_string_regexify(const char *string)
+{
+  return strdup(string);
+}
+
+char *silc_string_regex_combine(const char *string1, const char *string2)
+{
+  return strdup(string1);
+}
+
+int silc_string_regex_match(const char *regex, const char *string)
+{
+  return TRUE;
+}
+
+int silc_string_match(const char *string1, const char *string2)
+{
+  return TRUE;
+}
+
+/* Return current time to struct timeval. */
+
+int silc_gettimeofday(struct timeval *p)
+{
+  return gettimeofday(p, NULL);
+}