Skip to content

Commit 15c10ad

Browse files
authored
Merge pull request #123 from moteus/curl_mime
Add. Curl mime API
2 parents 14a9246 + 814c2e6 commit 15c10ad

26 files changed

+1942
-191
lines changed

.travis.yml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@ env:
99

1010
matrix:
1111
include:
12-
- compiler: ": Lua51-osx"
13-
env: LUA="lua 5.1"
12+
- env: LUA="lua 5.1"
1413
os: osx
15-
- compiler: ": Lua51"
16-
env: LUA="lua 5.1"
14+
- env: LUA="lua 5.1"
1715
os: linux
18-
- compiler: ": Lua52"
19-
env: LUA="lua 5.2"
16+
- env: LUA="lua 5.2"
2017
os: linux
21-
- compiler: ": Lua53"
22-
env: LUA="lua 5.3"
18+
- env: LUA="lua 5.3"
2319
os: linux
24-
- compiler: ": LuaJIT20"
25-
env: LUA="luajit 2.0"
20+
- env: LUA="luajit 2.0"
2621
os: linux
27-
- compiler: ": LuaJIT21"
28-
env: LUA="luajit 2.1"
22+
- env: LUA="luajit 2.1"
2923
os: linux
3024

3125
cache:
@@ -36,25 +30,35 @@ cache:
3630
branches:
3731
only:
3832
- master
33+
- curl_mime
3934

4035
before_install:
41-
- export CC=gcc
42-
- gcc --version
4336
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH=$PATH:~/Library/Python/2.7/bin/; fi
4437
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export LCURL_LD_FLAGS="-bundle -undefined dynamic_lookup -all_load --coverage"; fi
45-
- pip install --user cpp-coveralls
46-
- pip install --user hererocks
38+
- pip2 install --user cpp-coveralls
39+
- pip2 install --user hererocks
4740
- hererocks here -r^ --$LUA
4841
- source here/bin/activate
42+
- luarocks show lluv > /dev/null 2>&1 || bash .travis/setup_uv.sh
4943

5044
install:
5145
- luarocks make rockspecs/lua-curl-scm-0.rockspec CFLAGS="$LCURL_CC_FLAGS" LIBFLAG="$LCURL_LD_FLAGS"
5246

5347
before_script:
5448
- luarocks show luacov-coveralls > /dev/null 2>&1 || luarocks install luacov-coveralls
55-
- luarocks show lunitx > /dev/null 2>&1 || luarocks install lunitx
56-
- luarocks show luafilesystem > /dev/null 2>&1 || luarocks install luafilesystem
57-
- luarocks show dkjson > /dev/null 2>&1 || luarocks install dkjson --deps-mode=none
49+
- luarocks show lunitx > /dev/null 2>&1 || luarocks install lunitx
50+
- luarocks show luafilesystem > /dev/null 2>&1 || luarocks install luafilesystem
51+
- luarocks show dkjson > /dev/null 2>&1 || luarocks install dkjson --deps-mode=none
52+
- luarocks show pegasus > /dev/null 2>&1 || luarocks install pegasus http.parser
53+
--server=http://luarocks.org/manifests/moteus
54+
- luarocks show pegasus-router > /dev/null 2>&1 || luarocks install pegasus-router
55+
--server=http://luarocks.org/dev
56+
- luarocks show lluv > /dev/null 2>&1 || luarocks install lluv UV_DIR=$TRAVIS_BUILD_DIR/libuv
57+
--server=http://luarocks.org/dev
58+
- luarocks show lluv-pegasus > /dev/null 2>&1 || luarocks install lluv-pegasus
59+
--server=http://luarocks.org/dev --deps-mode=none
60+
- lua test/server.lua &
61+
- curl -s http://127.0.0.1:7090/get
5862

5963
script:
6064
- cd test
@@ -63,14 +67,12 @@ script:
6367
- lua test_pause02.c.lua
6468
- lua test_multi_callback.lua
6569
- lua test_multi_nested_callback.lua
66-
# - lunit.sh test_easy.lua
67-
# - lunit.sh test_safe.lua
68-
# - lunit.sh test_form.lua
69-
# - lunit.sh test_curl.lua
7070

71-
after_success:
71+
before_cache:
7272
- coveralls -b .. -r .. --dump c.report.json
7373
- luacov-coveralls -j c.report.json -v
74+
- luarocks remove lua-curl
75+
- rm -f /home/travis/.cache/pip/log/debug.log
7476

7577
notifications:
7678
email:

.travis/platform.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
if [ -z "${PLATFORM:-}" ]; then
2+
PLATFORM=$TRAVIS_OS_NAME;
3+
fi
4+
5+
if [ "$PLATFORM" == "osx" ]; then
6+
PLATFORM="macosx";
7+
fi
8+
9+
if [ -z "$PLATFORM" ]; then
10+
if [ "$(uname)" == "Linux" ]; then
11+
PLATFORM="linux";
12+
else
13+
PLATFORM="macosx";
14+
fi;
15+
fi

.travis/setup_uv.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /bin/bash
2+
3+
source .travis/platform.sh
4+
5+
cd $TRAVIS_BUILD_DIR
6+
7+
git clone https://github.com/libuv/libuv.git -b v1.x
8+
9+
cd libuv
10+
11+
git checkout v1.19.0
12+
13+
mkdir -p lib
14+
mkdir -p build
15+
git clone https://chromium.googlesource.com/external/gyp build/gyp
16+
17+
if [ "$PLATFORM" == "macosx" ]; then
18+
./gyp_uv.py -f xcode && xcodebuild -ARCHS="x86_64" -project uv.xcodeproj -configuration Release -target All
19+
cp ./build/Release/libuv.a ./lib;
20+
else
21+
./gyp_uv.py -f make && BUILDTYPE=Release CFLAGS=-fPIC make -C out
22+
cp ./out/Release/libuv.a ./lib;
23+
fi
24+
25+
cd $TRAVIS_BUILD_DIR

appveyor.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ shallow_clone: true
77

88
environment:
99
LR_EXTERNAL: c:\external
10-
CURL_VER: 7.55.1
10+
CURL_VER: 7.59.0
1111

1212
matrix:
1313
- LUA: "lua 5.1"
@@ -39,6 +39,7 @@ install:
3939
hererocks c:\hererocks --%LUA% --target %HR_TARGET% -rlatest
4040
)
4141
- call c:\hererocks\bin\activate
42+
- luarocks show luarocks-fetch-gitrec >nul 2>&1 || luarocks install luarocks-fetch-gitrec
4243

4344
before_build:
4445
# external deps
@@ -57,6 +58,12 @@ before_test:
5758
- luarocks show dkjson >nul 2>&1 || luarocks install dkjson
5859
- luarocks show luafilesystem >nul 2>&1 || luarocks install luafilesystem
5960
- luarocks show lua-path >nul 2>&1 || luarocks install lua-path
61+
- luarocks show pegasus >nul 2>&1 || luarocks install pegasus http.parser
62+
--server=http://luarocks.org/manifests/moteus
63+
- luarocks show pegasus-router >nul 2>&1 || luarocks install pegasus-router
64+
--server=http://luarocks.org/dev
65+
- ps: $TestServer = Start-Process lua -ArgumentList test/server.lua -RedirectStandardOutput "$env:APPVEYOR_BUILD_FOLDER\server.stdout.txt" -RedirectStandardError "$env:APPVEYOR_BUILD_FOLDER\server.stderr.txt" -PassThru
66+
- curl -s http://127.0.0.1:7090/get
6067

6168
test_script:
6269
- echo "Testing..."
@@ -69,3 +76,12 @@ test_script:
6976
after_test:
7077
- cd %APPVEYOR_BUILD_FOLDER%
7178
- .appveyor\pack_artifact.bat lua-curl bin-rock
79+
80+
on_failure:
81+
- ps: Stop-Process -Id $TestServer.Id
82+
- ps: $path = "$env:APPVEYOR_BUILD_FOLDER\server.stderr.txt"; if (Test-Path $path -PathType Leaf) { Push-AppveyorArtifact $path; } else { echo "File $path does not exist"; }
83+
- ps: $path = "$env:APPVEYOR_BUILD_FOLDER\server.stdout.txt"; if (Test-Path $path -PathType Leaf) { Push-AppveyorArtifact $path; } else { echo "File $path does not exist"; }
84+
85+
on_finish:
86+
- curl -s http://127.0.0.1:7090/get
87+
- ps: Stop-Process -Id $TestServer.Id

examples/lcurl/smtp-mime.lua

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
local curl = require "lcurl"
2+
3+
local SMTP = {
4+
url = "smtp://mail.example.com";
5+
}
6+
7+
local FROM = "<[email protected]>"
8+
local TO = "<[email protected]>"
9+
local CC = "<[email protected]>"
10+
local FILE = "smtp-mime.lua" -- if you send this file do not forget it may have mail password
11+
local CT_FILE = "application/lua"
12+
13+
local DUMP_MIME = false
14+
15+
local headers = {
16+
"Date: Tue, 22 Aug 2017 14:08:43 +0100",
17+
"To: " .. TO,
18+
"From: " .. FROM .. " (Example User)",
19+
"Cc: " .. CC .. " (Another example User)",
20+
"Message-ID: <[email protected]>",
21+
"Subject: example sending a MIME-formatted message",
22+
}
23+
24+
local inline_text = ""
25+
.. "This is the inline text message of the e-mail.\r\n"
26+
.. "\r\n"
27+
.. " It could be a lot of lines that would be displayed in an e-mail\r\n"
28+
.. "viewer that is not able to handle HTML.\r\n"
29+
30+
local inline_html = ""
31+
.. "<html><body>\r\n"
32+
.. "<p>This is the inline <b>HTML</b> message of the e-mail.</p>"
33+
.. "<br />\r\n"
34+
.. "<p>It could be a lot of HTML data that would be displayed by "
35+
.. "e-mail viewers able to handle HTML.</p>"
36+
.. "</body></html>\r\n"
37+
38+
local function dump_mime(type, data)
39+
if type == curl.INFO_DATA_OUT then io.write(data) end
40+
end
41+
42+
local easy = curl.easy()
43+
44+
local mime = easy:mime() do
45+
local alt = easy:mime()
46+
alt
47+
:addpart()
48+
:data(inline_html, "text/html")
49+
alt
50+
:addpart()
51+
:data(inline_text)
52+
mime:addpart()
53+
:subparts(alt, "multipart/alternative", {
54+
"Content-Disposition: inline"
55+
})
56+
mime
57+
:addpart()
58+
:filedata(FILE, CT_FILE)
59+
end
60+
61+
easy:setopt{
62+
url = SMTP.url,
63+
mail_from = FROM,
64+
mail_rcpt = {TO, CC},
65+
httpheader = headers;
66+
mimepost = mime;
67+
ssl_verifyhost = false;
68+
ssl_verifypeer = false;
69+
username = SMTP.user;
70+
password = SMTP.password;
71+
upload = true;
72+
}
73+
74+
if DUMP_MIME then
75+
easy:setopt{
76+
verbose = true;
77+
debugfunction = dump_mime;
78+
}
79+
end
80+
81+
easy:perform()
82+
83+
easy:close()
84+
85+
mime:free()

lakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ target('test', install, function()
3232
run_test('test_form.lua')
3333
run_test('test_pause02.c.lua')
3434
run_test('test_curl.lua')
35+
run_test('test_mime.lua')
3536
run_test('test_multi_callback.lua')
3637
run_test('test_multi_nested_callback.lua')
3738

msvc/lcurl.vcproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="windows-1251"?>
22
<VisualStudioProject
33
ProjectType="Visual C++"
4-
Version="9.00"
4+
Version="9,00"
55
Name="lcurl"
66
ProjectGUID="{200D5C0C-8123-48F6-9EA0-CF0E6A6943F2}"
77
RootNamespace="lcurl"
@@ -41,7 +41,7 @@
4141
<Tool
4242
Name="VCCLCompilerTool"
4343
Optimization="0"
44-
AdditionalIncludeDirectories="$(CPPLIB_DIR)\curl\7.37.1\include;$(LUA_DIR)\include"
44+
AdditionalIncludeDirectories="$(CPPLIB_DIR)\curl\7.56.0\include;$(LUA_DIR)\include"
4545
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LCURL_EXPORTS"
4646
MinimalRebuild="true"
4747
BasicRuntimeChecks="3"
@@ -63,7 +63,7 @@
6363
Name="VCLinkerTool"
6464
AdditionalDependencies="lua5.1.lib libcurl.lib ws2_32.lib"
6565
LinkIncremental="2"
66-
AdditionalLibraryDirectories="&quot;$(CPPLIB_DIR)\curl\7.37.1\lib&quot;;&quot;$(LUA_DIR)\lib&quot;"
66+
AdditionalLibraryDirectories="&quot;$(CPPLIB_DIR)\curl\7.56.0\lib&quot;;&quot;$(LUA_DIR)\lib&quot;"
6767
GenerateDebugInformation="true"
6868
SubSystem="2"
6969
TargetMachine="1"
@@ -189,6 +189,10 @@
189189
RelativePath="..\src\lchttppost.c"
190190
>
191191
</File>
192+
<File
193+
RelativePath="..\src\lcmime.c"
194+
>
195+
</File>
192196
<File
193197
RelativePath="..\src\lcmulti.c"
194198
>
@@ -251,6 +255,10 @@
251255
RelativePath="..\src\lcinfoeasy.h"
252256
>
253257
</File>
258+
<File
259+
RelativePath="..\src\lcmime.h"
260+
>
261+
</File>
254262
<File
255263
RelativePath="..\src\lcmulti.h"
256264
>

rockspecs/lua-curl-scm-0.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ build = {
6363
sources = {
6464
"src/l52util.c", "src/lceasy.c", "src/lcerror.c",
6565
"src/lchttppost.c", "src/lcurl.c", "src/lcutils.c",
66-
"src/lcmulti.c", "src/lcshare.c",
66+
"src/lcmulti.c", "src/lcshare.c","src/lcmime.c",
6767
},
6868
incdirs = { "$(CURL_INCDIR)" },
6969
libdirs = { "$(CURL_LIBDIR)" }

0 commit comments

Comments
 (0)