Skip to content

Commit

Permalink
Remove PerfectCURL dependency
Browse files Browse the repository at this point in the history
Instead, the relevant source files are copied into this project directly, and the Perfect-specific parts (that are not used by the wrapper anyway) are deleted.
  • Loading branch information
vzsg committed Feb 14, 2019
1 parent 6d97e07 commit 97e4bfe
Show file tree
Hide file tree
Showing 12 changed files with 1,983 additions and 9 deletions.
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/PerfectlySoft/Perfect-CURL.git", from: "3.1.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "3.1.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "CurlyClient",
dependencies: ["PerfectCURL", "Vapor"]),
dependencies: ["CCurl", "Vapor"]),
.systemLibrary(name: "CCurl", pkgConfig: "libcurl"),
.testTarget(
name: "CurlyClientTests",
dependencies: ["CurlyClient"]),
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public func configure(_ config: inout Config, _ env: inout Environment, _ servic
}
```

### 3. (Linux only) Check system dependencies

If you're building for Linux, you need to have the `uuid-dev` package installed – a requirement of Perfect-LinuxBridge. If you are building a thin Docker image, be sure to install `libuuid1` in the final build.

### 4. Profit!
### 3. Profit!

Your Vapor app should now use curl directly instead of URLSession.
114 changes: 114 additions & 0 deletions Sources/CCurl/ccurl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

#ifndef _p_curl_h_
#define _p_curl_h_

#include <curl/curl.h>

#ifdef CURLOPT_HEADERDATA
#undef CURLOPT_HEADERDATA
CURLoption CURLOPT_HEADERDATA = CURLOPT_WRITEHEADER;
#endif
#ifdef CURLOPT_WRITEDATA
#undef CURLOPT_WRITEDATA
CURLoption CURLOPT_WRITEDATA = CURLOPT_FILE;
#endif
#ifdef CURLOPT_READDATA
#undef CURLOPT_READDATA
CURLoption CURLOPT_READDATA = CURLOPT_INFILE;
#endif

typedef size_t (*curl_func)(void * ptr, size_t size, size_t num, void * ud);

static CURLcode curl_easy_setopt_long(CURL *handle, CURLoption option, long value)
{
return curl_easy_setopt(handle, option, value);
}

static CURLcode curl_easy_setopt_cstr(CURL *handle, CURLoption option, const char * value)
{
return curl_easy_setopt(handle, option, value);
}

static CURLcode curl_easy_setopt_int64(CURL *handle, CURLoption option, long long value)
{
return curl_easy_setopt(handle, option, value);
}

static CURLcode curl_easy_setopt_slist(CURL *handle, CURLoption option, struct curl_slist * value)
{
return curl_easy_setopt(handle, option, value);
}

static CURLcode curl_easy_setopt_void(CURL *handle, CURLoption option, void * value)
{
return curl_easy_setopt(handle, option, value);
}

static CURLcode curl_easy_setopt_func(CURL *handle, CURLoption option, curl_func value)
{
return curl_easy_setopt(handle, option, value);
}

static CURLcode curl_easy_getinfo_long(CURL *handle, CURLINFO option, long * value)
{
return curl_easy_getinfo(handle, option, value);
}

static CURLcode curl_easy_getinfo_cstr(CURL *handle, CURLINFO option, const char ** value)
{
return curl_easy_getinfo(handle, option, value);
}

static CURLcode curl_easy_getinfo_double(CURL *handle, CURLINFO option, double * value)
{
return curl_easy_getinfo(handle, option, value);
}

static CURLcode curl_easy_getinfo_slist(CURL *handle, CURLINFO option, struct curl_slist ** value)
{
return curl_easy_getinfo(handle, option, value);
}

static CURLcode curl_get_msg_result(CURLMsg * msg)
{
return msg->data.result;
}

static CURLFORMcode curl_formadd_content(struct curl_httppost **firstitem, struct curl_httppost **lastitem,
const char * name, const char * content, const long size, const char * type) {
return type ?
curl_formadd(firstitem, lastitem,
CURLFORM_COPYNAME, name,
CURLFORM_COPYCONTENTS, content,
CURLFORM_CONTENTSLENGTH, size,
CURLFORM_CONTENTTYPE, type,
CURLFORM_END)
:
curl_formadd(firstitem, lastitem,
CURLFORM_COPYNAME, name,
CURLFORM_COPYCONTENTS, content,
CURLFORM_CONTENTSLENGTH, size,
CURLFORM_END);
}

static CURLFORMcode curl_formadd_file(struct curl_httppost **firstitem, struct curl_httppost **lastitem,
const char * name, const char * path, const char * type) {
return type ?
curl_formadd(firstitem, lastitem,
CURLFORM_COPYNAME, name,
CURLFORM_CONTENTTYPE, type,
CURLFORM_FILE, path,
CURLFORM_END)
:
curl_formadd(firstitem, lastitem,
CURLFORM_COPYNAME, name,
CURLFORM_FILE, path,
CURLFORM_END);
}

static CURLcode curl_form_post(CURL * handle, struct curl_httppost * post) {
return curl_easy_setopt(handle, CURLOPT_HTTPPOST, post);
}


#endif
6 changes: 6 additions & 0 deletions Sources/CCurl/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module CCurl
{
umbrella header "ccurl.h"
link "curl"
export *
}
Loading

0 comments on commit 97e4bfe

Please sign in to comment.