Hi,
While everyone is talking about removing old platforms and cleaning code,
I'm going to suggest adding yet another (sub-)platform and adding (a bit)
to all those #ifdef's (talk about bad timing...).
I have a complete patch which at least gets everything to compile, but for
the moment, I'm going to leave out all the places where conditions are
added to existing #ifdef's and try to start discussion on the three files
with the most interesting changes:
* In e_os2.h, define a symbol (OPENSSL_SYS_WINPHONE) that can be
used everywhere else (in the OpenSSL sources) to recognize the platform.
Also add a dummy inline implementation of getenv returning an empty
string, as there is no environment in Windows Phone. This works nicely
for compiling openssl but tends to cause problems when included in other
projects which try to handle the missing getenv themselves. Unfortunately,
I didn't find a central place that's included in all OpenSSL sources, but not
included when just using OpenSSL headers to compile something else.
* In LPdir_win.c add a workaround for missing FindFirstFile.
Also, fix an apparent typo for the old WinCE port (?).
* In rand_win.c, add code to get hopefully reasonable random numbers
from the system, as the existing code essentially relies on methods
not available on Windows Phone. Unfortunately, this requires C++ code,
but together with the added extern C {...} everything links fine in the
end, even if this single file is compiled by the C++ compiler.
Best regards,
Stefan
diff -ru openssl-SNAP-2014/e_os2.h openssl-SNAP-2014-mod/e_os2.h
--- openssl-SNAP-2014/e_os2.h 2014-09-25 01:00:06.0 +0200
+++ openssl-SNAP-2014-mod/e_os2.h 2014-11-11 11:55:11.0 +0100
@@ -98,6 +98,17 @@
# if defined(_WIN32) || defined(OPENSSL_SYSNAME_WIN32)
# undef OPENSSL_SYS_UNIX
# define OPENSSL_SYS_WIN32
+ /* Note: a subcase of this is that we are compiling for Windows Phone;
+ we add a global define for this case which is _additionally_
+ set to simplify conditions later on ... */
+# if defined(WINAPI_FAMILY) WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+# define OPENSSL_SYS_WINPHONE
+ static const char * getenv(const char*name)
+ {
+ static const char * empty = ;
+ return empty;
+ }
+# endif
# endif
# if defined(OPENSSL_SYSNAME_WINNT)
# undef OPENSSL_SYS_UNIX
diff -ru openssl-SNAP-2014/crypto/LPdir_win.c openssl-SNAP-2014-mod/crypto/LPdir_win.c
--- openssl-SNAP-2014/crypto/LPdir_win.c 2014-09-03 23:00:25.0 +0200
+++ openssl-SNAP-2014-mod/crypto/LPdir_win.c 2014-11-11 11:55:11.0 +0100
@@ -35,8 +35,10 @@
[as well as -D_UNICODE]. */
#if defined(LP_SYS_WINCE) !defined(FindFirstFile)
# define FindFirstFile FindFirstFileW
+#elif defined(OPENSSL_SYS_WINPHONE)
+# define FindFirstFile(A,B) FindFirstFileExW(A, FindExInfoStandard, B, FindExSearchNameMatch, NULL, 0)
#endif
-#if defined(LP_SYS_WINCE) !defined(FindFirstFile)
+#if defined(LP_SYS_WINCE) !defined(FindNextFile)
# define FindNextFile FindNextFileW
#endif
diff -ru openssl-SNAP-2014/crypto/rand/rand_win.c openssl-SNAP-2014-mod/crypto/rand/rand_win.c
--- openssl-SNAP-2014/crypto/rand/rand_win.c 2014-09-18 23:00:09.0 +0200
+++ openssl-SNAP-2014-mod/crypto/rand/rand_win.c 2014-11-11 11:55:11.0 +0100
@@ -116,6 +116,7 @@
#include rand_lcl.h
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
+#ifndef OPENSSL_SYS_WINPHONE
#include windows.h
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0400
@@ -132,10 +133,18 @@
*/
#define PROV_INTEL_SEC 22
#define INTEL_DEF_PROV LIntel Hardware Cryptographic Service Provider
+#define GetTickCount64 GetTickCount
+#else
+#define _CRT_RAND_S
+#include stdlib.h
+#include agile.h
+extern C {
+#endif
static void readtimer(void);
static void readscreen(void);
+#ifndef OPENSSL_SYS_WINPHONE
/* It appears like CURSORINFO, PCURSORINFO and LPCURSORINFO are only defined
when WINVER is 0x0500 and up, which currently only happens on Win2000.
Unfortunately, those are typedefs, so they're a little bit difficult to
@@ -190,12 +199,14 @@
typedef NET_API_STATUS (NET_API_FUNCTION * NETFREE)(LPBYTE);
#endif /* 1 */
#endif /* !OPENSSL_SYS_WINCE */
+#endif
int RAND_poll(void)
{
+ DWORD w;
+#if !defined(OPENSSL_SYS_WINPHONE)
MEMORYSTATUS m;
HCRYPTPROV hProvider = 0;
- DWORD w;
int good = 0;
/* Determine the OS version we are on so we can turn off things
@@ -204,6 +215,7 @@
OSVERSIONINFO osverinfo ;
osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
GetVersionEx( osverinfo ) ;
+#endif
#if defined(OPENSSL_SYS_WINCE)
# if defined(_WIN32_WCE) _WIN32_WCE=300
@@ -222,7 +234,20 @@
}
}
# endif
-#else /* OPENSSL_SYS_WINCE */
+#elif defined(OPENSSL_SYS_WINPHONE)
+ int i;
+ BYTE buf[64];
+
+ for (i = 0; i sizeof(buf); i++)
+ {
+