From a5a05e454ea5beea0ba690f1d45c3bde184a9142 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 23 Jun 2016 17:00:33 -0700 Subject: [PATCH] cli work... --- cli/zerotier.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cli/zerotier.cpp b/cli/zerotier.cpp index f9eb4716b..f9eec5d08 100644 --- a/cli/zerotier.cpp +++ b/cli/zerotier.cpp @@ -159,9 +159,9 @@ static size_t _curlStringAppendCallback(void *contents,size_t size,size_t nmemb, static std::tuple GET(const CLIState &state,const std::map &headers,const std::string &url) { - int status = -1; std::string body; char errbuf[CURL_ERROR_SIZE]; + char urlbuf[4096]; CURL *curl = curl_easy_init(); if (!curl) { @@ -174,6 +174,20 @@ static std::tuple GET(const CLIState &state,const std::map 0) ? 0L : 1L); curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errbuf); + curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,0L); + + Utils::scopy(urlbuf,sizeof(urlbuf),url.c_str()); + curl_easy_setopt(curl,CURLOPT_URL,urlbuf); + + struct curl_slist *hdrs = (struct curl_slist *)0; + for(std::map::const_iterator i(headers.begin());i!=headers.end();++i) { + std::string htmp(i->first); + htmp.append(": "); + htmp.append(i->second); + hdrs = curl_slist_append(hdrs,htmp.c_str()); + } + if (hdrs) + curl_easy_setopt(curl,CURLOPT_HTTPHEADER,hdrs); memset(errbuf,0,sizeof(errbuf)); CURLcode res = curl_easy_perform(curl); @@ -182,9 +196,13 @@ static std::tuple GET(const CLIState &state,const std::map