<commit_before>/*
 * Copyright (C) 2005-2008  <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/*
this code probes the system for dns settings.  blah.

q3dns strategies
----------------

windows:

domain name, name server, "search list" found in windows registry here:

  HKEY_LOCAL_MACHINE
  System\CurrentControlSet\Services\Tcpip\Parameters  <-- win nt+
  System\CurrentControlSet\Services\VxD\MSTCP  <-- win 98

  for domain, try DhcpDomain else Domain
  for name servers, try DhcpNameServer, else NameServer
  for search list, try SearchList

iphlpapi.dll : GetNetworkParams(PFIXED_INFO, PULONG);

  info->DomainName
  info->DnsServerList (if not null, use it, and loop through ->Next until
    null)
  no search list

first try getnetworkparams.  if that fails, try the nt regkey then the 98
  regkey.  it seems that search list can only come from the registry, so
  maybe we need to grab that entry even if getnetworkparams works.

in the case of the registry, the nameserver and searchlist entries are
  delimited by spaces on win nt and commas on win 98.  probably a good
  idea to simplify white space first (chop away space at start and end,
  reduce all sections of spaces to one char).  also, lowercase the search
  list.

qt doesn't read the hosts file on windows.  this might be a good idea, but
  probably not worth it.

unix:

read /etc/resolv.conf manually:
  for each line, split at spaces
  if the first item is "nameserver", then there should be an IP address
    following it.  note: may contain mixed ipv4 and ipv6 addresses
  if the first item is "search", all other items are added to the domain
    list
  if the first item is "domain", then the next item should be added to the
    domain list.
  do case-insensitive matching for the item types
  for search/domain, the items are in the 8-bit system locale

info can also be fetched using system calls.  we use the res_* stuff here.
  first we should detect for a "modern res api".  this is available from
  glibc 2.3 and onward.  use the following scheme to check for it:

#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2)
  && (__GLIBC_MINOR__ >= 3)))
  // modern res api
#endif

on mac we should look up res_init in the system library.  see:
  qt_mac_resolve_sys(RTLD_NEXT, "res_init"); for a hint.
otherwise we can just use res_init() straight.

under a modern res api, we do:
  struct __res_state res;
  res_ninit(&res);
otherwise, we simply call res_init().  for the modern api, we use the "res"
  struct that we made.  otherwise, we use the global "_res" struct.

read the res struct to obtain the name servers, search list, and domain.
  lowercase the search list and domain.

qt tries the file, and if that fails it tries the syscalls.  we may want to
  do the syscalls first, or even just do both all the time.

read /etc/hosts manually:
  for each line
    if there is a '#' character in the line, remove it and everything to
      the right
    simplify white space
    convert to lowercase
  split the line at spaces
  first item is the ip address
  all remaining items are hostnames

  note: these hosts could also be used for reverse-dns too
  note2: Windows has a hosts file as well (like C:\WINDOWS\hosts)
*/

#include "jdns_p.h"

#ifdef JDNS_OS_WIN
# include <windows.h>
#endif

#ifdef JDNS_OS_ANDROID
# include <netinet/in.h>
# include <dlfcn.h>
# include <arpa_nameser.h>
# include <resolv_private.h>
# include <res_private.h>
# include <resolv_static.h>
#else
#ifdef JDNS_OS_UNIX
# include <netinet/in.h>
# include <arpa/nameser.h>
# include <resolv.h>
# include <dlfcn.h>
#endif
#endif

#define string_indexOf jdns_string_indexOf
#define string_split jdns_string_split

static int char_isspace(unsigned char c)
{<commit_msg>Local headers are now included using double quotes<commit_after>/*
 * Copyright (C) 2005-2008  <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/*
this code probes the system for dns settings.  blah.

q3dns strategies
----------------

windows:

domain name, name server, "search list" found in windows registry here:

  HKEY_LOCAL_MACHINE
  System\CurrentControlSet\Services\Tcpip\Parameters  <-- win nt+
  System\CurrentControlSet\Services\VxD\MSTCP  <-- win 98

  for domain, try DhcpDomain else Domain
  for name servers, try DhcpNameServer, else NameServer
  for search list, try SearchList

iphlpapi.dll : GetNetworkParams(PFIXED_INFO, PULONG);

  info->DomainName
  info->DnsServerList (if not null, use it, and loop through ->Next until
    null)
  no search list

first try getnetworkparams.  if that fails, try the nt regkey then the 98
  regkey.  it seems that search list can only come from the registry, so
  maybe we need to grab that entry even if getnetworkparams works.

in the case of the registry, the nameserver and searchlist entries are
  delimited by spaces on win nt and commas on win 98.  probably a good
  idea to simplify white space first (chop away space at start and end,
  reduce all sections of spaces to one char).  also, lowercase the search
  list.

qt doesn't read the hosts file on windows.  this might be a good idea, but
  probably not worth it.

unix:

read /etc/resolv.conf manually:
  for each line, split at spaces
  if the first item is "nameserver", then there should be an IP address
    following it.  note: may contain mixed ipv4 and ipv6 addresses
  if the first item is "search", all other items are added to the domain
    list
  if the first item is "domain", then the next item should be added to the
    domain list.
  do case-insensitive matching for the item types
  for search/domain, the items are in the 8-bit system locale

info can also be fetched using system calls.  we use the res_* stuff here.
  first we should detect for a "modern res api".  this is available from
  glibc 2.3 and onward.  use the following scheme to check for it:

#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2)
  && (__GLIBC_MINOR__ >= 3)))
  // modern res api
#endif

on mac we should look up res_init in the system library.  see:
  qt_mac_resolve_sys(RTLD_NEXT, "res_init"); for a hint.
otherwise we can just use res_init() straight.

under a modern res api, we do:
  struct __res_state res;
  res_ninit(&res);
otherwise, we simply call res_init().  for the modern api, we use the "res"
  struct that we made.  otherwise, we use the global "_res" struct.

read the res struct to obtain the name servers, search list, and domain.
  lowercase the search list and domain.

qt tries the file, and if that fails it tries the syscalls.  we may want to
  do the syscalls first, or even just do both all the time.

read /etc/hosts manually:
  for each line
    if there is a '#' character in the line, remove it and everything to
      the right
    simplify white space
    convert to lowercase
  split the line at spaces
  first item is the ip address
  all remaining items are hostnames

  note: these hosts could also be used for reverse-dns too
  note2: Windows has a hosts file as well (like C:\WINDOWS\hosts)
*/

#include "jdns_p.h"

#ifdef JDNS_OS_WIN
# include <windows.h>
#endif

#ifdef JDNS_OS_ANDROID
# include <netinet/in.h>
# include <dlfcn.h>
# include "arpa_nameser.h"
# include "resolv_private.h"
# include "res_private.h"
# include "resolv_static.h"
#else
#ifdef JDNS_OS_UNIX
# include <netinet/in.h>
# include <arpa/nameser.h>
# include <resolv.h>
# include <dlfcn.h>
#endif
#endif

#define string_indexOf jdns_string_indexOf
#define string_split jdns_string_split

static int char_isspace(unsigned char c)
{
{'fraction_non_alphanumeric': 0.06671531324924423, 'fraction_numerical': 0.005003648493693318, 'mean_word_length': 3.7542120911793857, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '468630', 'n_tokens_mistral': 2904, 'n_tokens_neox': 2785, 'n_words': 1385}