mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Improve style
This commit is contained in:
parent
5be51fabbe
commit
34338411b8
|
@ -17,18 +17,22 @@
|
||||||
|
|
||||||
#include "custom_curl.h"
|
#include "custom_curl.h"
|
||||||
|
|
||||||
CURLcode curl_easy_setopt_ptr(CURL* handle, CURLoption option, void* parameter) {
|
CURLcode curl_easy_setopt_ptr(CURL* handle, CURLoption option,
|
||||||
|
void* parameter) {
|
||||||
return curl_easy_setopt(handle, option, parameter);
|
return curl_easy_setopt(handle, option, parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
CURLcode curl_easy_setopt_long(CURL* handle, CURLoption option, long parameter) {
|
CURLcode curl_easy_setopt_long(CURL* handle, CURLoption option,
|
||||||
|
long parameter) {
|
||||||
return curl_easy_setopt(handle, option, parameter);
|
return curl_easy_setopt(handle, option, parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
CURLcode curl_easy_setopt_curl_off_t(CURL* handle, CURLoption option, curl_off_t parameter) {
|
CURLcode curl_easy_setopt_curl_off_t(CURL* handle, CURLoption option,
|
||||||
|
curl_off_t parameter) {
|
||||||
return curl_easy_setopt(handle, option, parameter);
|
return curl_easy_setopt(handle, option, parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
CURLcode curl_easy_getinfo_ptr(CURL* handle, CURLINFO option, void* parameter) {
|
CURLcode curl_easy_getinfo_ptr(CURL* handle, CURLINFO option,
|
||||||
|
void* parameter) {
|
||||||
return curl_easy_getinfo(handle, option, parameter);
|
return curl_easy_getinfo(handle, option, parameter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,16 @@
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
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
|
#endif // CUSTOM_CURL_H
|
||||||
|
|
|
@ -15,53 +15,51 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "curl_sapi.sapi.h"
|
#include "curl_sapi.sapi.h"
|
||||||
|
#include "sandboxed_api/util/flag.h"
|
||||||
|
|
||||||
class CurlApiSandboxEx1 : public CurlSandbox {
|
class CurlApiSandboxEx1 : public CurlSandbox {
|
||||||
|
private:
|
||||||
std::unique_ptr<sandbox2::Policy> ModifyPolicy(
|
std::unique_ptr<sandbox2::Policy> ModifyPolicy(
|
||||||
sandbox2::PolicyBuilder*) override {
|
sandbox2::PolicyBuilder*) override {
|
||||||
|
// Return a new policy
|
||||||
return sandbox2::PolicyBuilder()
|
return sandbox2::PolicyBuilder()
|
||||||
.DangerDefaultAllowAll()
|
.DangerDefaultAllowAll()
|
||||||
.AllowUnrestrictedNetworking()
|
.AllowUnrestrictedNetworking()
|
||||||
.AddDirectory("/lib")
|
.AddDirectory("/lib")
|
||||||
.BuildOrDie();
|
.BuildOrDie();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GET http://example.com
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
// GET http://example.com
|
|
||||||
|
|
||||||
CurlApiSandboxEx1 sandbox;
|
CurlApiSandboxEx1 sandbox;
|
||||||
|
absl::Status status = sandbox.Init();
|
||||||
auto status_sandbox_init = sandbox.Init();
|
assert(status.ok());
|
||||||
assert(status_sandbox_init.ok());
|
|
||||||
|
|
||||||
CurlApi api(&sandbox);
|
CurlApi api(&sandbox);
|
||||||
|
|
||||||
auto status_init = api.curl_easy_init();
|
sapi::StatusOr<CURL*> status_or_culrptr = api.curl_easy_init();
|
||||||
assert(status_init.ok());
|
assert(status.ok());
|
||||||
|
|
||||||
::sapi::v::RemotePtr curl(status_init.value());
|
sapi::v::RemotePtr curl(status_or_culrptr.value());
|
||||||
assert(curl.GetValue());
|
assert(curl.GetValue()); // checking curl != NULL
|
||||||
|
|
||||||
auto status_setopt_verbose = api.curl_easy_setopt_long(&curl, CURLOPT_VERBOSE, 1l);
|
sapi::StatusOr<int> status_or_int =
|
||||||
assert(status_setopt_verbose.ok());
|
api.curl_easy_setopt_long(&curl, CURLOPT_VERBOSE, 1l);
|
||||||
assert(status_setopt_verbose.value() == CURLE_OK);
|
assert(status_or_int.ok());
|
||||||
|
assert(status_or_int.value() == CURLE_OK);
|
||||||
|
|
||||||
sapi::v::ConstCStr url("http://example.com");
|
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_setopt_url = api.curl_easy_setopt_ptr(&curl, CURLOPT_URL, url.PtrBefore());
|
status_or_int = api.curl_easy_perform(&curl);
|
||||||
assert(status_setopt_url.ok());
|
assert(status_or_int.ok());
|
||||||
assert(status_setopt_url.value() == CURLE_OK);
|
assert(status_or_int.value() == CURLE_OK);
|
||||||
|
|
||||||
auto status_perform = api.curl_easy_perform(&curl);
|
status = api.curl_easy_cleanup(&curl);
|
||||||
assert(status_perform.ok());
|
assert(status.ok());
|
||||||
assert(status_perform.value() == CURLE_OK);
|
|
||||||
|
|
||||||
auto status_cleanup = api.curl_easy_cleanup(&curl);
|
|
||||||
assert(status_cleanup.ok());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user