diff options
author | valerino <valerino@te4i.com> | 2010-05-20 22:53:39 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-05-24 11:46:45 -0400 |
commit | 8d31141ccbdbeee9589d04ea99819af7aa35193b (patch) | |
tree | 42b596b609a885d04a6a985b07b95fbd4d4ce015 /src/or | |
parent | ddf250119df44927c424512f286a3255aea1d16b (diff) | |
download | tor-8d31141ccbdbeee9589d04ea99819af7aa35193b.tar.gz tor-8d31141ccbdbeee9589d04ea99819af7aa35193b.zip |
Port Tor to work on Windows CE
Most of the changes here are switches to use APIs available on Windows
CE. The most pervasive change is that Windows CE only provides the
wide-character ("FooW") variants of most of the windows function, and
doesn't support the older ASCII verions at all.
This patch will require use of the wcecompat library to get working
versions of the posix-style fd-based file IO functions.
[commit message by nickm]
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 11 | ||||
-rw-r--r-- | src/or/eventdns.c | 32 | ||||
-rw-r--r-- | src/or/main.c | 56 | ||||
-rw-r--r-- | src/or/or.h | 2 |
4 files changed, 87 insertions, 14 deletions
diff --git a/src/or/config.c b/src/or/config.c index 5d07cd7343..82184c77d6 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -217,8 +217,12 @@ static config_var_t _option_vars[] = { V(ExitPortStatistics, BOOL, "0"), V(ExtraInfoStatistics, BOOL, "0"), +#if defined (WINCE) + V(FallbackNetworkstatusFile, FILENAME, "fallback-consensus"), +#else V(FallbackNetworkstatusFile, FILENAME, SHARE_DATADIR PATH_SEPARATOR "tor" PATH_SEPARATOR "fallback-consensus"), +#endif V(FascistFirewall, BOOL, "0"), V(FirewallPorts, CSV, ""), V(FastFirstHopPK, BOOL, "1"), @@ -3697,6 +3701,7 @@ get_windows_conf_root(void) { static int is_set = 0; static char path[MAX_PATH+1]; + WCHAR wpath[MAX_PATH] = {0}; LPITEMIDLIST idl; IMalloc *m; @@ -3714,7 +3719,7 @@ get_windows_conf_root(void) #define APPDATA_PATH CSIDL_APPDATA #endif if (!SUCCEEDED(SHGetSpecialFolderLocation(NULL, APPDATA_PATH, &idl))) { - GetCurrentDirectory(MAX_PATH, path); + getcwd(path,MAX_PATH); is_set = 1; log_warn(LD_CONFIG, "I couldn't find your application data folder: are you " @@ -3723,7 +3728,9 @@ get_windows_conf_root(void) return path; } /* Convert the path from an "ID List" (whatever that is!) to a path. */ - result = SHGetPathFromIDList(idl, path); + result = SHGetPathFromIDListW(idl, wpath); + wcstombs(path,wpath,MAX_PATH); + /* Now we need to free the */ SHGetMalloc(&m); if (m) { diff --git a/src/or/eventdns.c b/src/or/eventdns.c index 06add11b1d..4e44d15163 100644 --- a/src/or/eventdns.c +++ b/src/or/eventdns.c @@ -3132,13 +3132,13 @@ load_nameservers_with_getnetworkparams(void) GetNetworkParams_fn_t fn; /* XXXX Possibly, we should hardcode the location of this DLL. */ - if (!(handle = LoadLibrary("iphlpapi.dll"))) { + if (!(handle = LoadLibraryW(L"iphlpapi.dll"))) { log(EVDNS_LOG_WARN, "Could not open iphlpapi.dll"); /* right now status = 0, doesn't that mean "good" - mikec */ status = -1; goto done; } - if (!(fn = (GetNetworkParams_fn_t) GetProcAddress(handle, "GetNetworkParams"))) { + if (!(fn = (GetNetworkParams_fn_t) GetProcAddress(handle, TEXT("GetNetworkParams")))) { log(EVDNS_LOG_WARN, "Could not get address of function."); /* same as above */ status = -1; @@ -3205,32 +3205,40 @@ config_nameserver_from_reg_key(HKEY key, const char *subkey) { char *buf; DWORD bufsz = 0, type = 0; + WCHAR wsubkey[MAX_PATH] = {0}; + char ansibuf[MAX_PATH] = {0}; int status = 0; - if (RegQueryValueEx(key, subkey, 0, &type, NULL, &bufsz) + mbstowcs(wsubkey,subkey,MAX_PATH); + if (RegQueryValueExW(key, wsubkey, 0, &type, NULL, &bufsz) != ERROR_MORE_DATA) return -1; if (!(buf = mm_malloc(bufsz))) return -1; - if (RegQueryValueEx(key, subkey, 0, &type, (LPBYTE)buf, &bufsz) + if (RegQueryValueExW(key, wsubkey, 0, &type, (LPBYTE)buf, &bufsz) == ERROR_SUCCESS && bufsz > 1) { - status = evdns_nameserver_ip_add_line(buf); + wcstombs(ansibuf,(wchar_t*)buf,MAX_PATH); + status = evdns_nameserver_ip_add_line(ansibuf); } mm_free(buf); return status; } -#define SERVICES_KEY "System\\CurrentControlSet\\Services\\" -#define WIN_NS_9X_KEY SERVICES_KEY "VxD\\MSTCP" -#define WIN_NS_NT_KEY SERVICES_KEY "Tcpip\\Parameters" +#define SERVICES_KEY L"System\\CurrentControlSet\\Services\\" +#define WIN_NS_9X_KEY SERVICES_KEY L"VxD\\MSTCP" +#define WIN_NS_NT_KEY SERVICES_KEY L"Tcpip\\Parameters" static int load_nameservers_from_registry(void) { int found = 0; int r; + OSVERSIONINFO info = {0}; + info.dwOSVersionInfoSize = sizeof (info); + GetVersionExW((LPOSVERSIONINFO)&info); + #define TRY(k, name) \ if (!found && config_nameserver_from_reg_key(k,name) == 0) { \ log(EVDNS_LOG_DEBUG,"Found nameservers in %s/%s",#k,name); \ @@ -3240,15 +3248,15 @@ load_nameservers_from_registry(void) #k,#name); \ } - if (((int)GetVersion()) > 0) { /* NT */ + if (info.dwMajorVersion >= 5) { /* NT */ HKEY nt_key = 0, interfaces_key = 0; - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &nt_key) != ERROR_SUCCESS) { log(EVDNS_LOG_DEBUG,"Couldn't open nt key, %d",(int)GetLastError()); return -1; } - r = RegOpenKeyEx(nt_key, "Interfaces", 0, + r = RegOpenKeyExW(nt_key, L"Interfaces", 0, KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &interfaces_key); if (r != ERROR_SUCCESS) { @@ -3263,7 +3271,7 @@ load_nameservers_from_registry(void) RegCloseKey(nt_key); } else { HKEY win_key = 0; - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_9X_KEY, 0, + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, WIN_NS_9X_KEY, 0, KEY_READ, &win_key) != ERROR_SUCCESS) { log(EVDNS_LOG_DEBUG, "Couldn't open registry key, %d", (int)GetLastError()); return -1; diff --git a/src/or/main.c b/src/or/main.c index 0ddb65a749..542383526c 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -24,6 +24,10 @@ #include <event.h> #endif +#if defined (WINCE) +#include <projects.h> +#endif + void evdns_shutdown(int); /********* PROTOTYPES **********/ @@ -2104,6 +2108,31 @@ do_hash_password(void) printf("16:%s\n",output); } +#if defined (WINCE) +int +find_flashcard_path(PWCHAR path, size_t size) +{ + WIN32_FIND_DATA d = {0}; + HANDLE h = NULL; + + if (!path) + return -1; + + h = FindFirstFlashCard(&d); + if (h == INVALID_HANDLE_VALUE) + return -1; + + if (wcslen(d.cFileName) == 0) { + FindClose(h); + return -1; + } + + wcsncpy(path,d.cFileName,size); + FindClose(h); + return 0; +} +#endif + /** Main entry point for the Tor process. Called from main(). */ /* This function is distinct from main() only so we can link main.c into * the unittest binary without conflicting with the unittests' main. */ @@ -2111,6 +2140,33 @@ int tor_main(int argc, char *argv[]) { int result = 0; +#if defined (WINCE) + WCHAR path [MAX_PATH] = {0}; + WCHAR fullpath [MAX_PATH] = {0}; + PWCHAR p = NULL; + FILE* redir = NULL; + FILE* redirdbg = NULL; + + // this is to facilitate debugging by opening + // a file on a folder shared by the wm emulator. + // if no flashcard (real or emulated) is present, + // log files will be written in the root folder + if (find_flashcard_path(path,MAX_PATH) == -1) + { + redir = _wfreopen( L"\\stdout.log", L"w", stdout ); + redirdbg = _wfreopen( L"\\stderr.log", L"w", stderr ); + } else { + swprintf(fullpath,L"\\%s\\tor",path); + CreateDirectory(fullpath,NULL); + + swprintf(fullpath,L"\\%s\\tor\\stdout.log",path); + redir = _wfreopen( fullpath, L"w", stdout ); + + swprintf(fullpath,L"\\%s\\tor\\stderr.log",path); + redirdbg = _wfreopen( fullpath, L"w", stderr ); + } +#endif + update_approx_time(time(NULL)); tor_threads_init(); init_logging(); diff --git a/src/or/or.h b/src/or/or.h index 9c613d28d1..ec8dd3a5dc 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -4377,8 +4377,10 @@ void networkstatus_free_all(void); /********************************* ntmain.c ***************************/ #ifdef MS_WINDOWS +#if !defined (WINCE) #define NT_SERVICE #endif +#endif #ifdef NT_SERVICE int nt_service_parse_options(int argc, char **argv, int *should_exit); |