61 Commits

Author SHA1 Message Date
Ronald Wampler
2ffc48fda9 Don't link network framework with crypto 2016-06-14 20:49:26 +02:00
Allan Odgaard
8fe7681ebd Remove unnecessary include of oak/compat.h 2015-08-05 12:31:20 +02:00
Allan Odgaard
a2681bfdfb Use gethostuuid instead of creating our own UUID 2014-11-17 00:05:26 +01:00
Allan Odgaard
235d52db7e Remove unused include 2014-11-17 00:04:51 +01:00
Allan Odgaard
b694ba50af Don’t include framework umbrella header 2014-11-10 09:02:39 +01:00
Allan Odgaard
ebf20acc20 Prefer CFBundleShortVersionString over CFBundleVersion 2014-11-10 09:01:05 +01:00
Allan Odgaard
7cb2330aae Log error if curl_easy_init() or accept() fails 2014-09-30 14:15:11 +02:00
Allan Odgaard
854fa91f10 Only cause preferences files to be created for TextMate
This function is called when running ‘bl’ and ‘test_network’, so previously we would end up with ‘bl.plist’ and ‘test_network.plist’ in ~/Library/Preferences.
2014-08-30 16:37:50 +02:00
Ronald Wampler
df38101798 Use proper deallocator for SecKeychainItemCopyAttributesAndData
This was found using clang's static analyzer.
2014-08-15 15:21:12 -04:00
Allan Odgaard
2427464f60 Disable tar’s support for extended attributes and resource forks
A problem has been reported where tar will freeze while extracting the default bundles archive to a networked Application Support folder.

From the bug report (Michael Kuron):

File servers tested: SMB on OS X 10.9.3, AFP on OS X 10.9.3, AFP on OS X 10.6.8, SMB on Windows 2008 R2.

Multiple machines tested.

Using ‘gnutar’ from MacPorts does not show the problem.

Setting ‘COPYFILE_DISABLE=1’ before running tar does not show the problem (the workaround used in this commit).
2014-06-28 17:42:23 +02:00
Allan Odgaard
6be2935518 Type/format arguments for SecItemImport were swapped
Also collect proper error code incase the function fails.
2014-06-28 17:42:22 +02:00
Allan Odgaard
b8c1085b9e Let NSURL extract the host from REST_API
The custom code in network::can_reach_host only dealt with the scheme, not port number or user/password.
2014-04-28 18:23:50 +07:00
Allan Odgaard
39b94e6ac3 Harmonize whitespace and add trailing newline 2014-04-14 14:26:52 +07:00
Allan Odgaard
69c83e56df The ‘const’ keyword should be to the right of its type
The standard doesn’t care which side the keyword is placed on, but placing it on the right makes it easier to read types.

E.g. reading “int const* const” from right to left we get “const pointer to const integer”.
2014-03-31 08:27:19 +07:00
Allan Odgaard
c2397484b8 Use C++11 for loop
Majority of the edits done using the following ruby script:

    def update_loops(src)
      dst, cnt = '', 0

      block_indent, variable = nil, nil
      src.each_line do |line|
        if block_indent
          if line =~ /^#{block_indent}([{}\t])|^\t*$/
            block_indent = nil if $1 == '}'
            line = line.gsub(%r{ ([^a-z>]) \(\*#{variable}\) | \*#{variable}\b | \b#{variable}(->) }x) do
              $1.to_s + variable + ($2 == "->" ? "." : "")
            end
          else
            block_indent = nil
          end
        elsif line =~ /^(\t*)c?iterate\((\w+), (?!diacritics::make_range)(.*\))$/
          block_indent, variable = $1, $2
          line = "#$1for(auto const& #$2 : #$3\n"
          cnt += 1
        end
        dst << line
      end
      return dst, cnt
    end

    paths.each do |path|
      src = IO.read(path)

      cnt = 1
      while cnt != 0
        src, cnt = update_loops(src)
        STDERR << "#{path}: #{cnt}\n"
      end

      File.open(path, "w") { |io| io << src }
    end
2014-03-03 10:34:13 +07:00
Allan Odgaard
bdba01a30f Do not report “Failed: Extracting Archive” on download failure 2014-01-13 09:02:16 +07:00
Allan Odgaard
1c308c810d Use map::emplace instead of inserting std::pair (C++11) 2013-09-05 20:59:11 +02:00
Allan Odgaard
e4e80a946c Use std::make_shared 2013-09-03 12:27:20 +02:00
Allan Odgaard
de03c27a63 Update network::tbz_t API
The main issue with the old API was inability to capture error output from the tar process.
2013-08-25 21:13:06 +02:00
Allan Odgaard
bf1e92b865 Do not use global constructors for fixtures 2013-08-16 22:40:08 +02:00
Allan Odgaard
22abe6d74f Disallow curl from using signals
If libcurl is built with the default DNS resolver then it will handle a timeout by using SIGALRM, though since we are using threads, and signals are not compatible with threads, this may have led to a crash in Curl_resolv_timeout (for users where a DNS lookup could take longer than the timeout, presumably 300 seconds).
2013-08-12 22:57:57 +02:00
Allan Odgaard
1d4358fac6 Remove unused include 2013-08-05 18:55:43 +02:00
Allan Odgaard
82e7749546 Explicitly run libcurl’s global init function
This function is not thread safe so we should not have it implicitly called, as we generally do not call the libcurl functions from the main thread.
2013-08-04 22:18:30 +02:00
Allan Odgaard
9d37cb976a Remove unnecessary call to c_str 2013-07-29 15:50:31 +02:00
Allan Odgaard
ecede39eeb Don’t pass (https) scheme to the reachability API
The reachability API does a DNS lookup on the literal string and prior to this commit, could stall for as long as it takes to lookup a non-existing host name via DNS.
2013-06-26 12:33:43 +02:00
Allan Odgaard
f8d71729fe Add SOCKS proxy support
This is for updating bundles and itself plus posting crash reports.

It now also ignores unknown proxy types.
2013-05-26 10:24:35 +08:00
Allan Odgaard
ee32b97ea0 Fix error checks for key chain lookups 2013-05-26 10:24:35 +08:00
Allan Odgaard
66b8ab54f9 Rewrite proxy code
We now use CFNetworkCopyProxiesForURL() to get the list of potential proxies, hopefully this will perform the proper “proxy auto discovery” (issue #973) though we still need to handle PAC ourself.

Presently we only use the first proxy found, ideally we would try them all (but this will require some API changes).
2013-05-13 18:08:35 +07:00
Allan Odgaard
ba2130f0c8 Don’t change signal mask in library code
This belongs in main(), where it is already being set.

It might however be necessary to set it when running tests, although none of the tests seems to fail w/o this.
2013-03-21 14:39:35 +01:00
Allan Odgaard
fbec3539c6 Use io::spawn for launching tar 2013-03-21 14:39:34 +01:00
Allan Odgaard
beb5348e32 Don’t abort when failing to run subcommand
Fixes #907.
2013-03-19 14:56:22 +01:00
Allan Odgaard
dfee671b6a Don’t use POSIX_SPAWN_CLOEXEC_DEFAULT on 10.7
Using this flag on 10.7.5 seems to cause a kernel panic.

Fixes #896.
2013-03-17 15:44:06 +01:00
Allan Odgaard
398e55cdbe Add helper functions to get OS version
We need this in a few places and while calling Gestalt() isn’t that much code, that function is deprecated in 10.8 and the alternative is a lot more code, so we don’t want to repeat that once we update the code.
2013-03-17 15:44:06 +01:00
Allan Odgaard
24f6f3bd2c Use posix_spawn instead of fork/exec
Using Apple’s POSIX_SPAWN_CLOEXEC_DEFAULT appears to be the only safe way to spawn a child process in a multi-threaded program.
2013-03-10 16:07:11 +01:00
Allan Odgaard
f69ac60b0c Limit file descriptors passed to child process
Instead of passing the file descriptor to the child, and have the child close it, we set FD_CLOEXEC on the file descriptor in the parent process.

While it limits the window in which another thread can fork() and cause the file descriptor to be “leaked”, it doesn’t eliminate the problem.
2013-03-10 16:07:10 +01:00
Allan Odgaard
13edc6d131 Use O_CLOEXEC when opening files
This avoids leaking file descriptors into child processes, which would otherwise happen if another thread forks while the file descriptor is open.
2013-03-10 16:07:10 +01:00
Allan Odgaard
4dada34bde Make network tests concurrent 2013-03-10 16:07:10 +01:00
Allan Odgaard
710e4ffad0 Remove unused tbz (download) filter 2013-03-10 16:07:09 +01:00
Allan Odgaard
609c332e0a Parse headers received in post_to_server 2013-02-08 11:20:35 +01:00
Allan Odgaard
9eb4044fdb Switch to simpler regexp::search 2013-02-08 11:20:35 +01:00
Allan Odgaard
e75e7ec8e5 Change text::format → std::to_string (C++11) 2013-02-08 11:20:34 +01:00
Allan Odgaard
b1f19e93f2 Corrupt archive → extracting archive
This is a more correct error.

Also write exit code and potential error from tar to stderr.
2013-01-29 21:47:40 +01:00
Allan Odgaard
0208414672 Download s/w updates to cache folder
This should hopefully solve the issue with the (on some systems) fairly aggressive temp cleaner.

Also remove the archive incase the user cancels the update, now that we are extracting it to a less temporary location.
2013-01-21 15:03:52 +01:00
Allan Odgaard
df914261f4 Update code to std::thread with lambda 2012-12-30 03:00:53 +01:00
Allan Odgaard
685039c0e9 Don’t rely on com.apple.CrashReporter existing
This used to contain an UUID used for identifying the client in network requests, but for majority of users, this is unset, so now we create our own UUID for the user agent string used when polling for software updates.
2012-12-30 03:00:53 +01:00
Allan Odgaard
49c37ca864 Skip ‘null’ payload fields when posting to server 2012-09-30 15:25:44 +02:00
Allan Odgaard
22c38ebe11 Remove legacy code (10.4 compatibility)
The code itself was using Gestalt() to check OS version which is deprecated on 10.8.
2012-09-16 11:41:24 +02:00
Allan Odgaard
400be883b9 URL-escape PAC string
Since the PAC URL is user supplied it’s unknown what state it actually is in, so we try to create a CFURL object from the raw string and if that fails, we URL-escape it (though not escaping slashes and colons).

Should fix issue #228.
2012-09-09 22:49:55 +02:00
Allan Odgaard
0e96a04d76 Remove compatibility checks
Since we now require 10.7 we don’t need all of this. Keeping it around is just noise that can lead to confusion about code paths.
2012-08-29 16:02:29 +02:00
Allan Odgaard
cbe91ff831 Assume compiler support for explicit keyword
Since we require a fairly recent clang for other features, there is no reason to test for this one.
2012-08-29 14:27:35 +02:00