2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <curl/curl.h>
23 #include <libcxml/cxml.h>
27 #define BUFFER_SIZE 1024
32 using std::stringstream;
34 UpdateChecker::UpdateChecker ()
35 : _buffer (new char[BUFFER_SIZE])
41 UpdateChecker::~UpdateChecker ()
47 write_callback_wrapper (void* data, size_t size, size_t nmemb, void* user)
49 return reinterpret_cast<UpdateChecker*>(user)->write_callback (data, size, nmemb);
55 curl_global_init (CURL_GLOBAL_ALL);
56 CURL* curl = curl_easy_init ();
61 curl_easy_setopt (curl, CURLOPT_URL, "http://dcpomatic.com/update.php");
62 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_callback_wrapper);
63 curl_easy_setopt (curl, CURLOPT_WRITEDATA, this);
64 string const agent = "dcpomatic/" + string (dcpomatic_version);
65 curl_easy_setopt (curl, CURLOPT_USERAGENT, agent.c_str ());
66 int r = curl_easy_perform (curl);
71 _buffer[BUFFER_SIZE-1] = '\0';
74 cxml::Document doc ("Update");
77 cout << doc.string_child ("Stable") << "\n";
82 UpdateChecker::write_callback (void* data, size_t size, size_t nmemb)
84 size_t const t = min (size * nmemb, size_t (BUFFER_SIZE - _offset));
85 memcpy (_buffer + _offset, data, t);