Address review comments

This commit is contained in:
Federico Stazi 2020-08-07 14:21:00 +00:00
parent 34338411b8
commit 8c68ac221f
5 changed files with 46 additions and 17 deletions

View File

@ -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`.

View File

@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "custom_curl.h"
#include <cstdlib>
#include <iostream>
#include "custom_curl.h"
CURLcode curl_easy_setopt_ptr(CURL* handle, CURLoption option,
void* parameter) {
return curl_easy_setopt(handle, option, parameter);

View File

@ -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
)

View File

@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Sandboxed version of simple.c
#include <cstdlib>
#include <iostream>
#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<CURL*> status_or_culrptr = api.curl_easy_init();
assert(status.ok());
sapi::StatusOr<CURL*> 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<int> 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<int> 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;
}