diff --git a/oss-internship-2020/curl/custom_curl/CMakeLists.txt b/oss-internship-2020/curl/custom_curl/CMakeLists.txt index a6a5605..c0e9988 100644 --- a/oss-internship-2020/curl/custom_curl/CMakeLists.txt +++ b/oss-internship-2020/curl/custom_curl/CMakeLists.txt @@ -21,12 +21,12 @@ add_subdirectory(curl) # Wrapper library including curl, # adds the explicit versions of the variadic methods add_library(custom_curl STATIC - custom_curl.h - custom_curl.cc + custom_curl.h + custom_curl.cc ) set_target_properties(custom_curl - PROPERTIES LINKER_LANGUAGE C + PROPERTIES LINKER_LANGUAGE C ) target_link_libraries(custom_curl - CURL::libcurl + CURL::libcurl ) diff --git a/oss-internship-2020/curl/custom_curl/custom_curl.cc b/oss-internship-2020/curl/custom_curl/custom_curl.cc index 0413ea4..4596753 100644 --- a/oss-internship-2020/curl/custom_curl/custom_curl.cc +++ b/oss-internship-2020/curl/custom_curl/custom_curl.cc @@ -17,18 +17,22 @@ #include "custom_curl.h" -CURLcode curl_easy_setopt_ptr(CURL* handle, CURLoption option, void* parameter) { - return curl_easy_setopt(handle, option, parameter); +CURLcode curl_easy_setopt_ptr(CURL* handle, CURLoption option, + void* parameter) { + return curl_easy_setopt(handle, option, parameter); } -CURLcode curl_easy_setopt_long(CURL* handle, CURLoption option, long parameter) { - return curl_easy_setopt(handle, option, parameter); +CURLcode curl_easy_setopt_long(CURL* handle, CURLoption option, + long parameter) { + return curl_easy_setopt(handle, option, parameter); } -CURLcode curl_easy_setopt_curl_off_t(CURL* handle, CURLoption option, curl_off_t parameter) { - return curl_easy_setopt(handle, option, parameter); +CURLcode curl_easy_setopt_curl_off_t(CURL* handle, CURLoption option, + curl_off_t parameter) { + return curl_easy_setopt(handle, option, parameter); } -CURLcode curl_easy_getinfo_ptr(CURL* handle, CURLINFO option, void* parameter) { - return curl_easy_getinfo(handle, option, parameter); +CURLcode curl_easy_getinfo_ptr(CURL* handle, CURLINFO option, + void* parameter) { + return curl_easy_getinfo(handle, option, parameter); } diff --git a/oss-internship-2020/curl/custom_curl/custom_curl.h b/oss-internship-2020/curl/custom_curl/custom_curl.h index 6b64e7e..7e9d3b7 100644 --- a/oss-internship-2020/curl/custom_curl/custom_curl.h +++ b/oss-internship-2020/curl/custom_curl/custom_curl.h @@ -19,12 +19,16 @@ #include -extern "C" CURLcode curl_easy_setopt_ptr(CURL *handle, CURLoption option, void* parameter); +extern "C" CURLcode curl_easy_setopt_ptr(CURL *handle, CURLoption option, + void* parameter); -extern "C" CURLcode curl_easy_setopt_long(CURL *handle, CURLoption option, long parameter); +extern "C" CURLcode curl_easy_setopt_long(CURL *handle, CURLoption option, + long parameter); -extern "C" CURLcode curl_easy_setopt_curl_off_t(CURL *handle, CURLoption option, curl_off_t parameter); +extern "C" CURLcode curl_easy_setopt_curl_off_t(CURL *handle, CURLoption option, + curl_off_t parameter); -extern "C" CURLcode curl_easy_getinfo_ptr(CURL *handle, CURLINFO option, void* parameter); +extern "C" CURLcode curl_easy_getinfo_ptr(CURL *handle, CURLINFO option, + void* parameter); #endif // CUSTOM_CURL_H diff --git a/oss-internship-2020/curl/examples/CMakeLists.txt b/oss-internship-2020/curl/examples/CMakeLists.txt index 80d57da..d97b6d3 100644 --- a/oss-internship-2020/curl/examples/CMakeLists.txt +++ b/oss-internship-2020/curl/examples/CMakeLists.txt @@ -14,9 +14,9 @@ # Example 1: GET request, verbose add_executable(example1 - example1.cc + example1.cc ) target_link_libraries(example1 PRIVATE - curl_sapi - sapi::sapi + curl_sapi + sapi::sapi ) diff --git a/oss-internship-2020/curl/examples/example1.cc b/oss-internship-2020/curl/examples/example1.cc index 2621542..e50dfb1 100644 --- a/oss-internship-2020/curl/examples/example1.cc +++ b/oss-internship-2020/curl/examples/example1.cc @@ -15,53 +15,51 @@ #include #include "curl_sapi.sapi.h" +#include "sandboxed_api/util/flag.h" class CurlApiSandboxEx1 : public CurlSandbox { - - std::unique_ptr ModifyPolicy( - sandbox2::PolicyBuilder*) override { - - return sandbox2::PolicyBuilder() - .DangerDefaultAllowAll() - .AllowUnrestrictedNetworking() - .AddDirectory("/lib") - .BuildOrDie(); - } - + private: + std::unique_ptr ModifyPolicy( + sandbox2::PolicyBuilder*) override { + // Return a new policy + return sandbox2::PolicyBuilder() + .DangerDefaultAllowAll() + .AllowUnrestrictedNetworking() + .AddDirectory("/lib") + .BuildOrDie(); + } }; +// GET http://example.com int main(int argc, char* argv[]) { - // GET http://example.com - - CurlApiSandboxEx1 sandbox; - - auto status_sandbox_init = sandbox.Init(); - assert(status_sandbox_init.ok()); - + CurlApiSandboxEx1 sandbox; + absl::Status status = sandbox.Init(); + assert(status.ok()); CurlApi api(&sandbox); - auto status_init = api.curl_easy_init(); - assert(status_init.ok()); + sapi::StatusOr status_or_culrptr = api.curl_easy_init(); + assert(status.ok()); - ::sapi::v::RemotePtr curl(status_init.value()); - assert(curl.GetValue()); + sapi::v::RemotePtr curl(status_or_culrptr.value()); + assert(curl.GetValue()); // checking curl != NULL - auto status_setopt_verbose = api.curl_easy_setopt_long(&curl, CURLOPT_VERBOSE, 1l); - assert(status_setopt_verbose.ok()); - assert(status_setopt_verbose.value() == CURLE_OK); + sapi::StatusOr status_or_int = + api.curl_easy_setopt_long(&curl, CURLOPT_VERBOSE, 1l); + assert(status_or_int.ok()); + assert(status_or_int.value() == CURLE_OK); - sapi::v::ConstCStr url("http://example.com"); - - auto status_setopt_url = api.curl_easy_setopt_ptr(&curl, CURLOPT_URL, url.PtrBefore()); - assert(status_setopt_url.ok()); - assert(status_setopt_url.value() == CURLE_OK); + sapi::v::ConstCStr url("http://example.com"); + status_or_int = + api.curl_easy_setopt_ptr(&curl, CURLOPT_URL, url.PtrBefore()); + assert(status_or_int.ok()); + assert(status_or_int.value() == CURLE_OK); - auto status_perform = api.curl_easy_perform(&curl); - assert(status_perform.ok()); - assert(status_perform.value() == CURLE_OK); + status_or_int = api.curl_easy_perform(&curl); + assert(status_or_int.ok()); + assert(status_or_int.value() == CURLE_OK); - auto status_cleanup = api.curl_easy_cleanup(&curl); - assert(status_cleanup.ok()); + status = api.curl_easy_cleanup(&curl); + assert(status.ok()); }