From: LRN Date: Sun, 15 Dec 2013 17:23:48 +0000 (+0000) Subject: Clean up W32 NSP tools, increase verbosity X-Git-Tag: initial-import-from-subversion-38251~5462 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=63059b5d1a1c183301624585bd1e106f1d1da8cb;p=oweals%2Fgnunet.git Clean up W32 NSP tools, increase verbosity --- diff --git a/src/gns/w32nsp-install.c b/src/gns/w32nsp-install.c index 5c2ccf23e..cb25ca9b2 100644 --- a/src/gns/w32nsp-install.c +++ b/src/gns/w32nsp-install.c @@ -24,9 +24,9 @@ */ #define INITGUID +#include #include #include -#include #include "gnunet_w32nsp_lib.h" #include @@ -40,42 +40,104 @@ main (int argc, char **argv) wchar_t *cmdl; int wargc; wchar_t **wargv; + /* Allocate a 4K buffer to retrieve all the namespace providers */ + DWORD dwInitialBufferLen = 4096; + DWORD dwBufferLen; + WSANAMESPACE_INFO *pi; + int p_count; + int i; - if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) + if (WSAStartup (MAKEWORD (2,2), &wsd) != 0) { - fprintf (stderr, "WSAStartup() failed: %lu\n", GetLastError()); + fprintf (stderr, "WSAStartup () failed: %lu\n", GetLastError ()); return 5; } + dwBufferLen = dwInitialBufferLen; + pi = malloc (dwBufferLen); + if (NULL == pi) + { + fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno); + WSACleanup (); + return 6; + } + p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi); + if (SOCKET_ERROR == p_count) + { + DWORD err = GetLastError (); + if (WSAEFAULT == err && dwBufferLen != dwInitialBufferLen) + { + free (pi); + + pi = malloc (dwBufferLen); + if (pi == NULL) + { + fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno); + WSACleanup (); + return 6; + } + + p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi); + if (SOCKET_ERROR == p_count) + { + fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ()); + free (pi); + WSACleanup (); + return 7; + } + } + else + { + fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ()); + free (pi); + WSACleanup (); + return 8; + } + } + for (i= 0; i < p_count; i++) + { + if (IsEqualGUID (&pi[i].NSProviderId, &id)) + { + fprintf (stderr, "GNUnet DNS provider is already installed\n"); + free (pi); + WSACleanup (); + return 0; + } + } + free (pi); + cmdl = GetCommandLineW (); if (cmdl == NULL) { - WSACleanup(); + WSACleanup (); return 2; } wargv = CommandLineToArgvW (cmdl, &wargc); if (wargv == NULL) { - WSACleanup(); + WSACleanup (); return 3; } r = 4; if (wargc == 2) { - ret = WSCInstallNameSpace (L"GNUnet DNS provider", wargv[1], NS_DNS, 1, &id); + ret = WSCInstallNameSpace (L"GNUnet DNS provider", wargv[1], NS_DNS, 0, &id); if (ret == NO_ERROR) { + fprintf (stderr, "Installed GNUnet DNS provider\n"); r = 0; } else { r = 1; fprintf (stderr, - "WSCInstallNameSpace(L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n", + "WSCInstallNameSpace (L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n", wargv[1], NS_DNS, &id, GetLastError ()); } } - WSACleanup(); + else + fprintf (stderr, "Usage: %S \n", wargv[0]); + WSACleanup (); return r; } diff --git a/src/gns/w32nsp-resolve.c b/src/gns/w32nsp-resolve.c index 2bbe45021..31f806343 100644 --- a/src/gns/w32nsp-resolve.c +++ b/src/gns/w32nsp-resolve.c @@ -206,6 +206,15 @@ main (int argc, char **argv) else wargc -= 1; } + else + { + fprintf (stderr, "Usage: %S \n" + "record type - one of the following: A | AAAA | name | addr\n" + "service name - a string to resolve; \" \" (a space) means 'blank'\n" + "NSP library path - path to libw32nsp\n" + "NSP id - one of the following: mswdns | gnunetdns\n", + wargv[0]); + } if (wargc == 5) { @@ -219,12 +228,15 @@ main (int argc, char **argv) else { LPNSPSTARTUP startup = (LPNSPSTARTUP) GetProcAddress (nsp, "NSPStartup"); + if (startup == NULL) + startup = (LPNSPSTARTUP) GetProcAddress (nsp, "NSPStartup@8"); if (startup != NULL) { NSP_ROUTINE api; + api.cbSize = sizeof (api); ret = startup (&prov, &api); if (NO_ERROR != ret) - fprintf (stderr, "startup failed\n"); + fprintf (stderr, "startup failed: %lu\n", GetLastError ()); else { HANDLE lookup; @@ -251,7 +263,7 @@ main (int argc, char **argv) err = GetLastError (); if (ret != NO_ERROR) { - fprintf (stderr, "lookup next failed\n"); + fprintf (stderr, "lookup next failed: %lu\n", err); } else { diff --git a/src/gns/w32nsp-uninstall.c b/src/gns/w32nsp-uninstall.c index ac5aafe2d..6b123cc38 100644 --- a/src/gns/w32nsp-uninstall.c +++ b/src/gns/w32nsp-uninstall.c @@ -1,7 +1,7 @@ #define INITGUID +#include #include #include -#include #include "gnunet_w32nsp_lib.h" #include @@ -12,19 +12,20 @@ main (int argc, char **argv) GUID id = GNUNET_NAMESPACE_PROVIDER_DNS; WSADATA wsd; - if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) + if (WSAStartup (MAKEWORD (2,2), &wsd) != 0) { - fprintf (stderr, "WSAStartup() failed: %lu\n", GetLastError()); + fprintf (stderr, "WSAStartup () failed: %lu\n", GetLastError ()); return 5; } ret = WSCUnInstallNameSpace (&id); if (ret == NO_ERROR) { + fprintf (stderr, "Uninstalled GNUnet DNS provider\n"); WSACleanup (); return 0; } - fprintf (stderr, "WSCUnInstallNameSpace() failed: %lu\n", GetLastError ()); + fprintf (stderr, "WSCUnInstallNameSpace () failed: %lu\n", GetLastError ()); WSACleanup (); return 1; } \ No newline at end of file