diff --git a/oss-internship-2020/curl/README.md b/oss-internship-2020/curl/README.md new file mode 100644 index 0000000..9c0b2ee --- /dev/null +++ b/oss-internship-2020/curl/README.md @@ -0,0 +1,22 @@ +# Curl + +This library is a sandboxed version of the original [curl](https://curl.haxx.se/libcurl/c/) C library, implemented using sandboxed-api. + +## Supported methods + +The library currently supports curl's [*Easy interface*](https://curl.haxx.se/libcurl/c/libcurl-easy.html). According to curl's website: + +> The easy interface is a synchronous, efficient, quickly used and... yes, easy interface for file transfers. +> Numerous applications have been built using this. + +However, all of the methods using function pointers, are not yet supported. + +## Examples + +The `examples` directory contains the sandboxed versions of example source codes taken from [this](https://curl.haxx.se/libcurl/c/example.html) page on curl's website. + +## Implementation details + +Variadic methods are currently not supported by sandboxed-api. Because of this, the sandboxed header `custom_curl.h` wraps the curl library and explicitly defines the variadic methods. + +For example, instead of using `curl_easy_setopt`, one of these methods can be used: `curl_easy_setopt_ptr`, `curl_easy_setopt_long` or `curl_easy_setopt_curl_off_t`. \ No newline at end of file diff --git a/oss-internship-2020/curl/custom_curl/custom_curl.cc b/oss-internship-2020/curl/custom_curl/custom_curl.cc index 4596753..e92a30e 100644 --- a/oss-internship-2020/curl/custom_curl/custom_curl.cc +++ b/oss-internship-2020/curl/custom_curl/custom_curl.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "custom_curl.h" + #include #include -#include "custom_curl.h" - CURLcode curl_easy_setopt_ptr(CURL* handle, CURLoption option, void* parameter) { return curl_easy_setopt(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 7e9d3b7..c3494bd 100644 --- a/oss-internship-2020/curl/custom_curl/custom_curl.h +++ b/oss-internship-2020/curl/custom_curl/custom_curl.h @@ -19,16 +19,16 @@ #include -extern "C" CURLcode curl_easy_setopt_ptr(CURL *handle, CURLoption option, +extern "C" CURLcode curl_easy_setopt_ptr(CURL* handle, CURLoption option, void* parameter); -extern "C" CURLcode curl_easy_setopt_long(CURL *handle, CURLoption option, +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, +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, +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 d97b6d3..4541ee9 100644 --- a/oss-internship-2020/curl/examples/CMakeLists.txt +++ b/oss-internship-2020/curl/examples/CMakeLists.txt @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Example 1: GET request, verbose +# All the examples are sandboxed versions of curl's examples +# (https://curl.haxx.se/libcurl/c/example.html) + +# Example 1: simple.c add_executable(example1 example1.cc ) diff --git a/oss-internship-2020/curl/examples/example1.cc b/oss-internship-2020/curl/examples/example1.cc index e50dfb1..5087647 100644 --- a/oss-internship-2020/curl/examples/example1.cc +++ b/oss-internship-2020/curl/examples/example1.cc @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Sandboxed version of simple.c + +#include #include #include "curl_sapi.sapi.h" @@ -30,7 +33,6 @@ class CurlApiSandboxEx1 : public CurlSandbox { } }; -// GET http://example.com int main(int argc, char* argv[]) { CurlApiSandboxEx1 sandbox; @@ -38,16 +40,11 @@ int main(int argc, char* argv[]) { assert(status.ok()); CurlApi api(&sandbox); - sapi::StatusOr status_or_culrptr = api.curl_easy_init(); - assert(status.ok()); + sapi::StatusOr status_or_curl = api.curl_easy_init(); + assert(status_or_curl.ok()); - sapi::v::RemotePtr curl(status_or_culrptr.value()); - assert(curl.GetValue()); // checking curl != NULL - - 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::RemotePtr curl(status_or_curl.value()); + assert(curl.GetValue()); // Checking curl != NULL sapi::v::ConstCStr url("http://example.com"); status_or_int = @@ -55,6 +52,11 @@ int main(int argc, char* argv[]) { assert(status_or_int.ok()); assert(status_or_int.value() == CURLE_OK); + sapi::StatusOr status_or_int = + api.curl_easy_setopt_long(&curl, CURLOPT_FOLLOWLOCATION, 1l); + assert(status_or_int.ok()); + assert(status_or_int.value() == CURLE_OK); + status_or_int = api.curl_easy_perform(&curl); assert(status_or_int.ok()); assert(status_or_int.value() == CURLE_OK); @@ -62,4 +64,6 @@ int main(int argc, char* argv[]) { status = api.curl_easy_cleanup(&curl); assert(status.ok()); + return EXIT_SUCCESS; + }