[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Start of port to win32. Missing are:



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv27211/src/common

Modified Files:
	crypto.c fakepoll.c log.c log.h test.h util.c util.h 
Log Message:
Start of port to win32.  Missing are:
  - signal support
  - forking for DNS farm
  - changes for async IO
  - daemonizing

In other words, some files still don't build, and the ones that do build,
do nonblocking IO incorrectly.

I'm also not checking in the project files till I have a good place
for them. 



Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- crypto.c	30 Jul 2003 19:10:20 -0000	1.28
+++ crypto.c	12 Aug 2003 03:08:40 -0000	1.29
@@ -40,11 +40,11 @@
 #define RETURN_SSL_OUTCOME(exp) return !(exp)
 #endif
 
-static inline const EVP_CIPHER *
-crypto_cipher_evp_cipher(int type, int enc);
-
+/* static INLINE const EVP_CIPHER *
+   crypto_cipher_evp_cipher(int type, int enc);
+*/
 
-static inline int 
+static INLINE int 
 crypto_cipher_iv_length(int type) {
   /*
   printf("%d -> %d IV\n",type, EVP_CIPHER_iv_length(
@@ -61,7 +61,7 @@
     }
 }
 
-static inline int
+static INLINE int
 crypto_cipher_key_length(int type) {
   /*
   printf("%d -> %d\n",type, EVP_CIPHER_key_length(
@@ -78,7 +78,7 @@
     }
 }
 
-static inline const EVP_CIPHER *
+static INLINE const EVP_CIPHER *
 crypto_cipher_evp_cipher(int type, int enc) {
   switch(type) 
     {

Index: fakepoll.c
===================================================================
RCS file: /home/or/cvsroot/src/common/fakepoll.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- fakepoll.c	18 Jun 2003 07:44:48 -0000	1.2
+++ fakepoll.c	12 Aug 2003 03:08:40 -0000	1.3
@@ -5,14 +5,25 @@
  *
  * Nick Mathewson <nickm@freehaven.net>
  */
-
-#include "fakepoll.h"
-
-#ifdef USE_FAKE_POLL
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
+
+#include "orconfig.h"
+#ifdef USE_FAKE_POLL
+#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#if _MSC_VER > 1300
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#elif defined(_MSC_VER)
+#include <winsock.h>
+#endif
+
+#include "fakepoll.h"
+#include "util.h"
 
 int
 poll(struct pollfd *ufds, unsigned int nfds, int timeout)

Index: log.c
===================================================================
RCS file: /home/or/cvsroot/src/common/log.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- log.c	25 Jun 2003 04:47:54 -0000	1.8
+++ log.c	12 Aug 2003 03:08:40 -0000	1.9
@@ -2,7 +2,8 @@
 /* See LICENSE for licensing information */
 /* $Id$ */
 
-#include "../or/or.h"
+#include "../or/or.h"
+#include "util.h"
 
 static const char *sev_to_string(int severity) {
   switch(severity) {
@@ -29,9 +30,8 @@
   
   assert(format);
   if (severity > loglevel)
-    return;
-  if (gettimeofday(&now,NULL) < 0)
-    return;
+    return;
+  my_gettimeofday(&now);
 
   t = time(NULL);
   strftime(buf, 200, "%b %d %H:%M:%S", localtime(&t));

Index: log.h
===================================================================
RCS file: /home/or/cvsroot/src/common/log.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- log.h	24 Jun 2003 05:18:12 -0000	1.11
+++ log.h	12 Aug 2003 03:08:40 -0000	1.12
@@ -6,8 +6,19 @@
  */
 
 #ifndef __LOG_H
-
-#include <syslog.h>
+
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#else
+#define LOG_DEBUG   0
+#define LOG_INFO    1
+#define LOG_NOTICE  2
+#define LOG_WARNING 3
+#define LOG_ERR     4
+#define LOG_CRIT    5
+#define LOG_ALERT   6
+#define LOG_EMERG   7
+#endif
 
 /* magic to make GCC check for proper format strings. */ 
 #ifdef __GNUC__

Index: test.h
===================================================================
RCS file: /home/or/cvsroot/src/common/test.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test.h	6 May 2003 17:38:14 -0000	1.5
+++ test.h	12 Aug 2003 03:08:40 -0000	1.6
@@ -9,13 +9,19 @@
 
 #define STMT_BEGIN  do {
 #define STMT_END    } while (0)
+
+#ifdef __GNUC__
+#define PRETTY_FUNCTION __PRETTY_FUNCTION__
+#else
+#define PRETTY_FUNCTION ""
+#endif
 
 #define test_fail()                                             \
   STMT_BEGIN                                                    \
     printf("\nFile %s: line %d (%s): assertion failed.",        \
       __FILE__,                                                 \
       __LINE__,                                                 \
-      __PRETTY_FUNCTION__);                                     \
+      PRETTY_FUNCTION);                                     \
     return;                                                     \
   STMT_END
 
@@ -25,7 +31,7 @@
     printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
       __FILE__,                                                 \
       __LINE__,                                                 \
-      __PRETTY_FUNCTION__,                                      \
+      PRETTY_FUNCTION,                                      \
       #expr);                                                   \
     return;                                                     \
   } STMT_END
@@ -38,7 +44,7 @@
            "      (%ld != %ld)\n",                              \
       __FILE__,                                                 \
       __LINE__,                                                 \
-      __PRETTY_FUNCTION__,                                      \
+      PRETTY_FUNCTION,                                      \
       #expr1, #expr2,                                           \
       v1, v2);                                                  \
     return;                                                     \
@@ -52,7 +58,7 @@
            "      (%ld == %ld)\n",                              \
       __FILE__,                                                 \
       __LINE__,                                                 \
-      __PRETTY_FUNCTION__,                                      \
+      PRETTY_FUNCTION,                                      \
       #expr1, #expr2,                                           \
       v1, v2);                                                  \
     return;                                                     \
@@ -66,7 +72,7 @@
            "      (\"%s\" != \"%s\")\n",                        \
       __FILE__,                                                 \
       __LINE__,                                                 \
-      __PRETTY_FUNCTION__,                                      \
+      PRETTY_FUNCTION,                                      \
       #expr1, #expr2,                                           \
       v1, v2);                                                  \
     return;                                                     \
@@ -80,7 +86,7 @@
            "      (\"%s\" == \"%s\")\n",                        \
       __FILE__,                                                 \
       __LINE__,                                                 \
-      __PRETTY_FUNCTION__,                                      \
+      PRETTY_FUNCTION,                                      \
       #expr1, #expr2,                                           \
       v1, v2);                                                  \
     return;                                                     \
@@ -93,7 +99,7 @@
     printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \
       __FILE__,                                                 \
       __LINE__,                                                 \
-      __PRETTY_FUNCTION__,                                      \
+      PRETTY_FUNCTION,                                      \
       #expr1, #expr2);                                          \
     return;                                                     \
   } STMT_END
@@ -105,7 +111,7 @@
     printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \
       __FILE__,                                                 \
       __LINE__,                                                 \
-      __PRETTY_FUNCTION__,                                      \
+      PRETTY_FUNCTION,                                      \
       #expr1, #expr2);                                          \
     return;                                                     \
   } STMT_END

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- util.c	18 Jun 2003 07:44:48 -0000	1.7
+++ util.c	12 Aug 2003 03:08:40 -0000	1.8
@@ -1,10 +1,25 @@
 /* Copyright 2003 Roger Dingledine */
 /* See LICENSE for licensing information */
 /* $Id$ */
+
+#include "orconfig.h"
 
 #include <stdlib.h>
-#include <limits.h>
-#include "util.h"
+#include <limits.h>
+#if _MSC_VER > 1300
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#elif defined(_MSC_VER)
+#include <winsock.h>
+#endif
+#ifdef HAVE_SYS_FCNTL_H
+#include <sys/fcntl.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#include "util.h"
 #include "log.h"
 
 void *tor_malloc(size_t size) {
@@ -22,13 +37,19 @@
 
 void 
 my_gettimeofday(struct timeval *timeval) 
-{
+{
+#ifdef HAVE_GETTIMEOFDAY
   if (gettimeofday(timeval, NULL)) {
     log_fn(LOG_ERR, "gettimeofday failed.");
     /* If gettimeofday dies, we have either given a bad timezone (we didn't),
        or segfaulted.*/
     exit(1);
-  }
+  }
+#elif defined(HAVE_FTIME)
+  ftime(timeval);
+#else
+#error "No way to get time."
+#endif
   return;
 }
 
@@ -75,3 +96,14 @@
   a->tv_sec += ((ms * 1000) / 1000000) + (a->tv_usec / 1000000);
   a->tv_usec %= 1000000;
 }
+
+void set_socket_nonblocking(int socket)
+{
+#ifdef _MSC_VER
+	/* Yes means no and no means yes.  Do you not want to be nonblocking? */
+	int nonblocking = 0;
+	ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking);
+#else
+	fcntl(socket, F_SETFL, O_NONBLOCK);
+#endif
+}

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- util.h	20 May 2003 06:37:34 -0000	1.2
+++ util.h	12 Aug 2003 03:08:40 -0000	1.3
@@ -4,8 +4,32 @@
 
 #ifndef __UTIL_H
 #define __UTIL_H
-
-#include <sys/time.h>
+
+#include "orconfig.h"
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+#ifndef HAVE_GETTIMEOFDAY
+#ifdef HAVE_FTIME 
+#include <sys/timeb.h>
+#define timeval timeb
+#define tv_sec time
+#define tv_usec millitm
+#endif
+#endif
+
+#ifdef _MSC_VER
+/* Windows names string functions funnily. */
+#define strncasecmp strnicmp
+#define strcasecmp stricmp
+#define INLINE __inline
+#else
+#define INLINE inline
+#endif
 
 void *tor_malloc(size_t size);
 
@@ -18,5 +42,7 @@
 void tv_addms(struct timeval *a, long ms);
 void tv_add(struct timeval *a, struct timeval *b);
 int tv_cmp(struct timeval *a, struct timeval *b);
+
+void set_socket_nonblocking(int socket);
 
 #endif