REST: nothing triggers rest
[oweals/gnunet.git] / src / gns / w32nsp.c
index 6370f64bf7acb98fa1f97708788a46bdbd10d87f..56d07a50c041265442c1325dc9e31af29570df75 100644 (file)
@@ -1,21 +1,21 @@
 /*
      This file is part of GNUnet.
-     (C) 2012 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 /**
  * @file gns/w32nsp.c
  * "Network Programming For Microsoft Windows, 2Nd Edition".
  */
 
-#if 1
+#define VERBOSE 0
+#if !VERBOSE
 #  define DEBUGLOG(s, ...)
 #endif
-#if 0
+#if VERBOSE
 #  define __printf__ printf
 #  define DEBUGLOG(s, ...) printf (s, ##__VA_ARGS__)
 #endif
@@ -70,7 +71,7 @@
 #endif
 #endif
 #include "w32resolver.h"
-#define INITGUID
+#include <initguid.h>
 #include "gnunet_w32nsp_lib.h"
 #undef INITGUID
 
@@ -102,7 +103,7 @@ resize_records ()
     SetLastError (WSA_NOT_ENOUGH_MEMORY);
     return 0;
   }
-  memcpy (new_records, records, records_len * sizeof (struct record));
+  GNUNET_memcpy (new_records, records, records_len * sizeof (struct record));
   memset (&new_records[records_len], 0, sizeof (struct record) * (new_size - records_len));
   records_size = new_size;
   free (records);
@@ -143,14 +144,6 @@ add_record (SOCKET s, const wchar_t *name, DWORD flags)
   return res;
 }
 
-static void
-free_record (int i)
-{
-  if (records[i].name)
-    free (records[i].name);
-  records[i].state = 0;
-}
-
 /* These are not defined by mingw.org headers at the moment*/
 typedef INT (WSPAPI *LPNSPIOCTL) (HANDLE,DWORD,LPVOID,DWORD,LPVOID,DWORD,LPDWORD,LPWSACOMPLETION,LPWSATHREADID);
 typedef struct _NSP_ROUTINE_XP {
@@ -209,7 +202,6 @@ send_name_to_ip_request (LPWSAQUERYSETW lpqsRestrictions,
   char *buf;
   int ret = 1;
   int i;
-  uint32_t id;
   size_t size = sizeof (struct GNUNET_W32RESOLVER_GetMessage);
   size_t namelen = 0;
   if (lpqsRestrictions->lpszServiceInstanceName)
@@ -237,7 +229,7 @@ send_name_to_ip_request (LPWSAQUERYSETW lpqsRestrictions,
   else
     msg->af = htonl (AF_UNSPEC);
   if (lpqsRestrictions->lpszServiceInstanceName)
-    memcpy (&msg[1], lpqsRestrictions->lpszServiceInstanceName, namelen);
+    GNUNET_memcpy (&msg[1], lpqsRestrictions->lpszServiceInstanceName, namelen);
   msg->sc_data1 = htonl (lpqsRestrictions->lpServiceClassId->Data1);
   msg->sc_data2 = htons (lpqsRestrictions->lpServiceClassId->Data2);
   msg->sc_data3 = htons (lpqsRestrictions->lpServiceClassId->Data3);
@@ -248,7 +240,9 @@ send_name_to_ip_request (LPWSAQUERYSETW lpqsRestrictions,
   {
     if (size != send (*resolver, buf, size, 0))
     {
+#if VERBOSE
       DWORD err = GetLastError ();
+#endif
       closesocket (*resolver);
       *resolver = INVALID_SOCKET;
       DEBUGLOG ("GNUNET_W32NSP_LookupServiceBegin: failed to send request: %lu\n", err);
@@ -386,7 +380,7 @@ static int WSAAPI
 GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
     LPDWORD lpdwBufferLength, LPWSAQUERYSETW lpqsResults)
 {
-  DWORD effective_flags;
+  /*DWORD effective_flags;*/
   int i;
   struct GNUNET_MessageHeader header = {0, 0};
   int rec = -1;
@@ -419,7 +413,7 @@ GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
     //LeaveCriticalSection (&records_cs);
     return SOCKET_ERROR;
   }
-  effective_flags = dwControlFlags & records[rec].flags;
+  /*effective_flags = dwControlFlags & records[rec].flags;*/
   if (records[rec].buf)
   {
     DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: checking buffer\n");
@@ -431,7 +425,7 @@ GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
       //LeaveCriticalSection (&records_cs);
       return SOCKET_ERROR;
     }
-    memcpy (lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)records[rec].buf)[1], header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage));
+    GNUNET_memcpy (lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)records[rec].buf)[1], header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage));
     free (records[rec].buf);
     records[rec].buf = NULL;
     //LeaveCriticalSection (&records_cs);
@@ -443,11 +437,13 @@ GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
   //LeaveCriticalSection (&records_cs);
   to_receive = sizeof (header);
   rc = 0;
+#if VERBOSE
   {
     unsigned long have;
     int ior = ioctlsocket ((SOCKET) hLookup, FIONREAD, &have);
     DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: reading %d bytes as a header from %p, %lu bytes available\n", to_receive, hLookup, have);
   }
+#endif
   while (to_receive > 0)
   {
     t = recv ((SOCKET) hLookup, &((char *) &header)[rc], to_receive, 0);
@@ -459,11 +455,13 @@ GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
     else
       break;
   }
+#if VERBOSE
   {
     unsigned long have;
     int ior = ioctlsocket ((SOCKET) hLookup, FIONREAD, &have);
     DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: read %d bytes as a header from %p, %lu bytes available\n", rc, hLookup, have);
   }
+#endif
   //EnterCriticalSection (&records_cs);
   records[rec].state &= ~8;
   if (rc != sizeof (header))
@@ -510,14 +508,16 @@ GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
   }
   records[rec].state |= 8;
   //LeaveCriticalSection (&records_cs);
-  memcpy (buf, &header, sizeof (header));
+  GNUNET_memcpy (buf, &header, sizeof (header));
   to_receive = header.size - sizeof (header);
   rc = 0;
+#if VERBOSE
   {
     unsigned long have;
     int ior = ioctlsocket ((SOCKET) hLookup, FIONREAD, &have);
     DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: reading %d bytes as a body from %p, %lu bytes available\n", to_receive, hLookup, have);
   }
+#endif
   while (to_receive > 0)
   {
     DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: recv (%d)\n", to_receive);
@@ -531,11 +531,13 @@ GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
     else
       break;
   }
+#if VERBOSE
   {
     unsigned long have;
     int ior = ioctlsocket ((SOCKET) hLookup, FIONREAD, &have);
     DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: read %d bytes as a body from %p, %lu bytes available\n", rc, hLookup, have);
   }
+#endif
   //EnterCriticalSection (&records_cs);
   records[rec].state &= ~8;
   if (rc != header.size - sizeof (header))
@@ -565,7 +567,7 @@ GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
   }
   //LeaveCriticalSection (&records_cs);
   DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: writing %d bytes into result buffer\n", header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage));
-  memcpy (lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)buf)[1], header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage));
+  GNUNET_memcpy (lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)buf)[1], header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage));
   free (buf);
   DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: OK\n");
   UnmarshallWSAQUERYSETW ((LPWSAQUERYSETW) lpqsResults);
@@ -576,12 +578,8 @@ GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags,
 static int WSPAPI
 GNUNET_W32NSP_LookupServiceEnd (HANDLE hLookup)
 {
-  DWORD effective_flags;
   int i;
-  struct GNUNET_MessageHeader header = {0, 0};
   int rec = -1;
-  int rc;
-  char *buf;
 
   DEBUGLOG ("GNUNET_W32NSP_LookupServiceEnd\n");
   //EnterCriticalSection (&records_cs);