updates.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 24 Jun 2001 17:00:55 +0000 (17:00 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 24 Jun 2001 17:00:55 +0000 (17:00 +0000)
CHANGES
includes/silcincludes.h
includes/silcwin32.h [new file with mode: 0644]
lib/contrib/Makefile.am
lib/silcclient/client.c
lib/silcclient/client_keyagr.c
lib/silccrypt/silcrng.c
lib/silcutil/silcnet.c
lib/silcutil/silcnet.h
lib/silcutil/win32/silcwin32schedule.c

diff --git a/CHANGES b/CHANGES
index 879db1ceb7499a862c86cf777e6c0536cb4a6cfb..0021e5736545bca3ff677df441c7cec84fba45a8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,13 @@
+Sun Jun 24 19:49:23 EEST 2001  Pekka Riikonen <priikone@silcnet.org>
+
+       * lib/contrib/regex.c is not compiled on WIN32.
+
+       * Added silc_net_get_socket_opt function to the
+         lib/silcutil/silcnet.h.
+
+       * Added includes/silcwin32.h for WIN32 specific includes
+         and definitions.
+
 Sun Jun 24 12:19:52 EEST 2001  Pekka Riikonen <priikone@silcnet.org>
 
        * Moved the lib/silccore/silcsockconn.[ch] to the utility
index 63f9e6753efd2b9f5a5243f9171c9682f6e8af9f..f1686d279ae2da3153d7ac24b23d5cd0f752b73b 100644 (file)
@@ -1,11 +1,10 @@
-
 /*
 
   silcincludes.h
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2000 Pekka Riikonen
+  Copyright (C) 1997 - 2001 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
@@ -30,9 +29,7 @@
 #include "silcdefs.h"
 
 #ifdef SILC_WIN32
-#include <windows.h>
-#include <dir.h>
-#include <io.h>
+#include "silcwin32.h"
 #endif
 
 #include <stdio.h>
diff --git a/includes/silcwin32.h b/includes/silcwin32.h
new file mode 100644 (file)
index 0000000..9a0cddd
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+
+  silcwin32.h
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2001 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.
+
+*/
+/* Native WIN32 specific includes and definitions. */
+
+#ifndef SILCWIN32_H
+#define SILCWIN32_H
+
+#include <windows.h>
+#include <dir.h>
+#include <io.h>
+
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+
+#endif
+
index e5fcf4c40865eef075692832be4760f30feda2b0..73f34fdd36112ddcdac011b683f9c9346dd9043a 100644 (file)
@@ -20,10 +20,16 @@ AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign
 
 noinst_LIBRARIES = libcontrib.a
 
+if SILC_WIN32
+libcontrib_a_SOURCES = \
+       getopt.c \
+       getopt1.c
+else
 libcontrib_a_SOURCES = \
        getopt.c \
        getopt1.c \
        regex.c
+endif
 
 EXTRA_DIST = *.h
 
index dde26d5322c4f05e6a6ee2079d142d3309efa1b0..4cd047fdf71337e8075674edb23b2cc5f9808a9b 100644 (file)
@@ -369,7 +369,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_start)
   SILC_LOG_DEBUG(("Start"));
 
   /* Check the socket status as it might be in error */
-  getsockopt(fd, SOL_SOCKET, SO_ERROR, &opt, &opt_len);
+  silc_net_get_socket_opt(fd, SOL_SOCKET, SO_ERROR, &opt, &opt_len);
   if (opt != 0) {
     if (ctx->tries < 2) {
       /* Connection failed but lets try again */
index e4a6a25c7ff260e9e54a54bb5fbafef9989de41c..6ceb851f8e16ea95132c97664fedef78ac176612 100644 (file)
@@ -416,7 +416,7 @@ SILC_TASK_CALLBACK(silc_client_perform_key_agreement_start)
   SILC_LOG_DEBUG(("Start"));
 
   /* Check the socket status as it might be in error */
-  getsockopt(fd, SOL_SOCKET, SO_ERROR, &opt, &opt_len);
+  silc_net_get_socket_opt(fd, SOL_SOCKET, SO_ERROR, &opt, &opt_len);
   if (opt != 0) {
     if (ctx->tries < 2) {
       /* Connection failed but lets try again */
index 3aecd117b14523df2d60edc6a4530ce91fb1b5fc..e6af9540a803cd2800fddf73f51d43019ae72f70 100644 (file)
@@ -191,12 +191,15 @@ void silc_rng_init(SilcRng rng)
 
 static void silc_rng_get_soft_noise(SilcRng rng)
 {
+#ifndef SILC_WIN32
   struct tms ptime;
+#endif
   uint32 pos;
   
   pos = silc_rng_get_position(rng);
 
   silc_rng_xor(rng, clock(), 0);
+#ifndef SILC_WIN32
 #ifdef HAVE_GETPID
   silc_rng_xor(rng, getpid(), 1);
 #ifdef HAVE_GETPGID
@@ -222,7 +225,9 @@ static void silc_rng_get_soft_noise(SilcRng rng)
   silc_rng_xor(rng, (ptime.tms_stime ^ ptime.tms_cutime), pos++);
   silc_rng_xor(rng, (ptime.tms_cutime + ptime.tms_stime), pos++);
   silc_rng_xor(rng, (ptime.tms_stime << 8), pos++);
+#endif
   silc_rng_xor(rng, clock() << 4, pos++);
+#ifndef SILC_WIN32
 #ifdef HAVE_GETPGID
   silc_rng_xor(rng, getpgid(getpid() << 8), pos++);
 #endif
@@ -237,6 +242,7 @@ static void silc_rng_get_soft_noise(SilcRng rng)
 #ifdef HAVE_GETPGRP
   silc_rng_xor(rng, getpgrp(), pos++);
 #endif
+#endif
 
 #ifdef SILC_RNG_DEBUG
   SILC_LOG_HEXDUMP(("pool"), rng->pool, sizeof(rng->pool));
@@ -265,6 +271,7 @@ static void silc_rng_get_medium_noise(SilcRng rng)
 
 static void silc_rng_get_hard_noise(SilcRng rng)
 {
+#ifndef SILC_WIN32
   char buf[32];
   int fd, len, i;
   
@@ -289,6 +296,7 @@ static void silc_rng_get_hard_noise(SilcRng rng)
  out:
   close(fd);
   memset(buf, 0, sizeof(buf));
+#endif
 }
 
 /* Execs command and gets noise from its output */
index f8e75fd03d712c8a302fce52939e2d06869c331c..826c2cc228659b1a91a2c0ea406062e970a37834 100644 (file)
@@ -36,6 +36,13 @@ int silc_net_set_socket_opt(int sock, int level, int option, int on)
   return setsockopt(sock, level, option, (void *)&on, sizeof(on));
 }
 
+/* Get socket options */
+
+int silc_net_get_socket_opt(int sock, int level, int option, 
+                           void *optval, int *opt_len)
+{
+  return getsockopt(sock, level, option, optval, (socklen_t *)opt_len);
+}
 /* Checks whether IP address sent as argument is valid IP address. */
 
 bool silc_net_is_ip(const char *addr)
index 2bb23e75767103265cc3fc0e5b2d45fc572195a9..68ef081434fbbc87b268421f02734242fdbc47df 100644 (file)
@@ -142,6 +142,21 @@ int silc_net_set_socket_nonblock(int sock);
  ***/
 int silc_net_set_socket_opt(int sock, int level, int option, int on);
 
+/****f* silcutil/SilcNetAPI/silc_net_get_socket_opt
+ *
+ * SYNOPSIS
+ *
+ *    int silc_net_get_socket_opt(int sock, int level, int option, 
+ *                                void *optval, int *opt_len);
+ *
+ * DESCRIPTION
+ *
+ *    Return socket options to the `optval' and `opt_len'.
+ *
+ ***/
+int silc_net_get_socket_opt(int sock, int level, int option, 
+                           void *optval, int *opt_len);
+
 /****f* silcutil/SilcNetAPI/silc_net_is_ip
  *
  * SYNOPSIS
index 6db27fd7e24b6133095188a02bf5509cfca817d3..2d481d9650a671f45c2f189e58d102a48fb283bc 100644 (file)
@@ -72,23 +72,31 @@ int silc_select(int n, fd_set *readfds, fd_set *writefds,
        return 1;
   }
 
-  timeo = (timeout ? (timeout.tv_sec * 1000) + (timeout.tv_usec / 1000) :
+  timeo = (timeout ? (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000) :
           INFINITE);
 
   /* If we have nothing to wait and timeout is set then register a timeout
      and wait just for windows messages. */
   if (nhandles == 0 && timeout) {
     UINT timer = SetTimer(NULL, 0, timeo, NULL);
-    if (timer) {
+    curtime = GetTickCount();
+    while (timer) {
       WaitMessage();
       KillTimer(NULL, timer);
 
       while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+       if (msg.message == WM_TIMER)
+         return 0;
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
       }
 
-      return 0;
+      if (timeo != INFINITE) {
+       timeo -= GetTickCount() - curtime;
+       if (timeo < 0)
+         timeo = 0;
+       timer = SetTimer(NULL, 0, timeo, NULL);
+      }
     }
   }
 
@@ -140,13 +148,13 @@ int silc_select(int n, fd_set *readfds, fd_set *writefds,
     i = 0;
     do {
       /* Set the handle to fd set */
-      FD_SET(handle[ready], readfds);
+      FD_SET((int)handles[ready], readfds);
       i++;
 
       /* Check the status of the next handle and set it's fd to the fd
         set if data is available. */
       while (++ready < n)
-       if (WaitForSingleObject(handle[ready], 0) == WAIT_OBJECT_0)
+       if (WaitForSingleObject(handles[ready], 0) == WAIT_OBJECT_0)
          break;
     } while (ready < n);