gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r31395 - gnunet/src/gns


From: gnunet
Subject: [GNUnet-SVN] r31395 - gnunet/src/gns
Date: Sun, 15 Dec 2013 18:23:48 +0100

Author: LRN
Date: 2013-12-15 18:23:48 +0100 (Sun, 15 Dec 2013)
New Revision: 31395

Modified:
   gnunet/src/gns/w32nsp-install.c
   gnunet/src/gns/w32nsp-resolve.c
   gnunet/src/gns/w32nsp-uninstall.c
Log:
Clean up W32 NSP tools, increase verbosity

Modified: gnunet/src/gns/w32nsp-install.c
===================================================================
--- gnunet/src/gns/w32nsp-install.c     2013-12-15 17:23:24 UTC (rev 31394)
+++ gnunet/src/gns/w32nsp-install.c     2013-12-15 17:23:48 UTC (rev 31395)
@@ -24,9 +24,9 @@
  */
 
 #define INITGUID
+#include <ws2spi.h>
 #include <windows.h>
 #include <nspapi.h>
-#include <ws2spi.h>
 #include "gnunet_w32nsp_lib.h"
 #include <stdio.h>
 
@@ -40,42 +40,104 @@
   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 <path-to-libw32nsp>\n", wargv[0]);
+  WSACleanup ();
   return r;
 }

Modified: gnunet/src/gns/w32nsp-resolve.c
===================================================================
--- gnunet/src/gns/w32nsp-resolve.c     2013-12-15 17:23:24 UTC (rev 31394)
+++ gnunet/src/gns/w32nsp-resolve.c     2013-12-15 17:23:48 UTC (rev 31395)
@@ -206,6 +206,15 @@
     else
       wargc -= 1;
   }
+  else
+  {
+    fprintf (stderr, "Usage: %S <record type> <service name> <NSP library 
path> <NSP id>\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 @@
     else
     {
       LPNSPSTARTUP startup = (LPNSPSTARTUP) GetProcAddress (nsp, "NSPStartup");
+      if (startup == NULL)
+        startup = (LPNSPSTARTUP) GetProcAddress (nsp, "address@hidden");
       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 @@
             err = GetLastError ();
             if (ret != NO_ERROR)
             {
-              fprintf (stderr, "lookup next failed\n");
+              fprintf (stderr, "lookup next failed: %lu\n", err);
             }
             else
             {

Modified: gnunet/src/gns/w32nsp-uninstall.c
===================================================================
--- gnunet/src/gns/w32nsp-uninstall.c   2013-12-15 17:23:24 UTC (rev 31394)
+++ gnunet/src/gns/w32nsp-uninstall.c   2013-12-15 17:23:48 UTC (rev 31395)
@@ -1,7 +1,7 @@
 #define INITGUID
+#include <ws2spi.h>
 #include <windows.h>
 #include <nspapi.h>
-#include <ws2spi.h>
 #include "gnunet_w32nsp_lib.h"
 #include <stdio.h>
 
@@ -12,19 +12,20 @@
   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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]