diff options
author | LRN <lrn1986@gmail.com> | 2013-12-15 17:23:48 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-12-15 17:23:48 +0000 |
commit | 63059b5d1a1c183301624585bd1e106f1d1da8cb (patch) | |
tree | 9c8cb99547ce3afbc20df034af5efac2ab4302d1 /src/gns/w32nsp-install.c | |
parent | f117f9c905bca6ef72f0b0cbc5a6bf251b4aaf53 (diff) | |
download | gnunet-63059b5d1a1c183301624585bd1e106f1d1da8cb.tar.gz gnunet-63059b5d1a1c183301624585bd1e106f1d1da8cb.zip |
Clean up W32 NSP tools, increase verbosity
Diffstat (limited to 'src/gns/w32nsp-install.c')
-rw-r--r-- | src/gns/w32nsp-install.c | 78 |
1 files changed, 70 insertions, 8 deletions
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 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #define INITGUID | 26 | #define INITGUID |
27 | #include <ws2spi.h> | ||
27 | #include <windows.h> | 28 | #include <windows.h> |
28 | #include <nspapi.h> | 29 | #include <nspapi.h> |
29 | #include <ws2spi.h> | ||
30 | #include "gnunet_w32nsp_lib.h" | 30 | #include "gnunet_w32nsp_lib.h" |
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | 32 | ||
@@ -40,42 +40,104 @@ main (int argc, char **argv) | |||
40 | wchar_t *cmdl; | 40 | wchar_t *cmdl; |
41 | int wargc; | 41 | int wargc; |
42 | wchar_t **wargv; | 42 | wchar_t **wargv; |
43 | /* Allocate a 4K buffer to retrieve all the namespace providers */ | ||
44 | DWORD dwInitialBufferLen = 4096; | ||
45 | DWORD dwBufferLen; | ||
46 | WSANAMESPACE_INFO *pi; | ||
47 | int p_count; | ||
48 | int i; | ||
43 | 49 | ||
44 | if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) | 50 | if (WSAStartup (MAKEWORD (2,2), &wsd) != 0) |
45 | { | 51 | { |
46 | fprintf (stderr, "WSAStartup() failed: %lu\n", GetLastError()); | 52 | fprintf (stderr, "WSAStartup () failed: %lu\n", GetLastError ()); |
47 | return 5; | 53 | return 5; |
48 | } | 54 | } |
49 | 55 | ||
56 | dwBufferLen = dwInitialBufferLen; | ||
57 | pi = malloc (dwBufferLen); | ||
58 | if (NULL == pi) | ||
59 | { | ||
60 | fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno); | ||
61 | WSACleanup (); | ||
62 | return 6; | ||
63 | } | ||
64 | p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi); | ||
65 | if (SOCKET_ERROR == p_count) | ||
66 | { | ||
67 | DWORD err = GetLastError (); | ||
68 | if (WSAEFAULT == err && dwBufferLen != dwInitialBufferLen) | ||
69 | { | ||
70 | free (pi); | ||
71 | |||
72 | pi = malloc (dwBufferLen); | ||
73 | if (pi == NULL) | ||
74 | { | ||
75 | fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno); | ||
76 | WSACleanup (); | ||
77 | return 6; | ||
78 | } | ||
79 | |||
80 | p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi); | ||
81 | if (SOCKET_ERROR == p_count) | ||
82 | { | ||
83 | fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ()); | ||
84 | free (pi); | ||
85 | WSACleanup (); | ||
86 | return 7; | ||
87 | } | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ()); | ||
92 | free (pi); | ||
93 | WSACleanup (); | ||
94 | return 8; | ||
95 | } | ||
96 | } | ||
97 | for (i= 0; i < p_count; i++) | ||
98 | { | ||
99 | if (IsEqualGUID (&pi[i].NSProviderId, &id)) | ||
100 | { | ||
101 | fprintf (stderr, "GNUnet DNS provider is already installed\n"); | ||
102 | free (pi); | ||
103 | WSACleanup (); | ||
104 | return 0; | ||
105 | } | ||
106 | } | ||
107 | free (pi); | ||
108 | |||
50 | cmdl = GetCommandLineW (); | 109 | cmdl = GetCommandLineW (); |
51 | if (cmdl == NULL) | 110 | if (cmdl == NULL) |
52 | { | 111 | { |
53 | WSACleanup(); | 112 | WSACleanup (); |
54 | return 2; | 113 | return 2; |
55 | } | 114 | } |
56 | wargv = CommandLineToArgvW (cmdl, &wargc); | 115 | wargv = CommandLineToArgvW (cmdl, &wargc); |
57 | if (wargv == NULL) | 116 | if (wargv == NULL) |
58 | { | 117 | { |
59 | WSACleanup(); | 118 | WSACleanup (); |
60 | return 3; | 119 | return 3; |
61 | } | 120 | } |
62 | r = 4; | 121 | r = 4; |
63 | 122 | ||
64 | if (wargc == 2) | 123 | if (wargc == 2) |
65 | { | 124 | { |
66 | ret = WSCInstallNameSpace (L"GNUnet DNS provider", wargv[1], NS_DNS, 1, &id); | 125 | ret = WSCInstallNameSpace (L"GNUnet DNS provider", wargv[1], NS_DNS, 0, &id); |
67 | if (ret == NO_ERROR) | 126 | if (ret == NO_ERROR) |
68 | { | 127 | { |
128 | fprintf (stderr, "Installed GNUnet DNS provider\n"); | ||
69 | r = 0; | 129 | r = 0; |
70 | } | 130 | } |
71 | else | 131 | else |
72 | { | 132 | { |
73 | r = 1; | 133 | r = 1; |
74 | fprintf (stderr, | 134 | fprintf (stderr, |
75 | "WSCInstallNameSpace(L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n", | 135 | "WSCInstallNameSpace (L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n", |
76 | wargv[1], NS_DNS, &id, GetLastError ()); | 136 | wargv[1], NS_DNS, &id, GetLastError ()); |
77 | } | 137 | } |
78 | } | 138 | } |
79 | WSACleanup(); | 139 | else |
140 | fprintf (stderr, "Usage: %S <path-to-libw32nsp>\n", wargv[0]); | ||
141 | WSACleanup (); | ||
80 | return r; | 142 | return r; |
81 | } | 143 | } |