mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Address review comments
This commit is contained in:
parent
34338411b8
commit
8c68ac221f
22
oss-internship-2020/curl/README.md
Normal file
22
oss-internship-2020/curl/README.md
Normal 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`.
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user