1 /* cclive
2  * Copyright (C) 2013  Toni Gundogdu <legatvs@gmail.com>
3  *
4  * This file is part of cclive <http://cclive.sourceforge.net/>.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <ccinternal>
21 
22 #include <curl/curl.h>
23 
24 #include <ccquvi>
25 #include <ccoptions>
26 #include <ccutil>
27 
28 namespace cc
29 {
30 
31 namespace po = boost::program_options;
32 
_set_proxy(CURL * c,const po::variables_map & map)33 static void _set_proxy(CURL *c, const po::variables_map& map)
34 {
35   if (map.count("proxy"))
36     {
37       curl_easy_setopt(c, CURLOPT_PROXY,
38                        map["proxy"].as<std::string>().c_str());
39     }
40 
41   if (opts.flags.no_proxy)
42     curl_easy_setopt(c, CURLOPT_PROXY, "");
43 }
44 
curl_setup(CURL * c)45 void curl_setup(CURL *c)
46 {
47   const po::variables_map map = cc::opts.map();
48 
49   if (map.count("throttle"))
50     {
51       curl_off_t limit = map["throttle"].as<int>()*1024;
52       curl_easy_setopt(c, CURLOPT_MAX_RECV_SPEED_LARGE, limit);
53     }
54 
55   curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1L);
56 
57   if (cc::opts.flags.verbose_libcurl)
58     curl_easy_setopt(c, CURLOPT_VERBOSE, 1L);
59 
60   curl_easy_setopt(c, CURLOPT_USERAGENT,
61                    map["agent"].as<std::string>().c_str());
62 
63   curl_easy_setopt(c, CURLOPT_DNS_CACHE_TIMEOUT,
64                    map["dns-cache-timeout"].as<int>());
65 
66   curl_easy_setopt(c, CURLOPT_CONNECTTIMEOUT,
67                    map["connect-timeout"].as<int>());
68 
69   curl_easy_setopt(c, CURLOPT_TIMEOUT,
70                    map["transfer-timeout"].as<int>());
71 
72   _set_proxy(c, map);
73 }
74 
75 } // namespace cc
76 
77 // vim: set ts=2 sw=2 tw=72 expandtab:
78