Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
ab39f64f
Commit
ab39f64f
authored
Aug 19, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/curl/Easy: add setter functions
parent
185fbca2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
17 deletions
+87
-17
Easy.hxx
src/lib/curl/Easy.hxx
+73
-1
Request.cxx
src/lib/curl/Request.cxx
+11
-13
Request.hxx
src/lib/curl/Request.hxx
+3
-3
No files found.
src/lib/curl/Easy.hxx
View file @
ab39f64f
/*
* Copyright
(C)
2016-2018 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2016-2018 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -90,6 +90,78 @@ public:
throw
std
::
runtime_error
(
curl_easy_strerror
(
code
));
}
void
SetPrivate
(
void
*
pointer
)
{
SetOption
(
CURLOPT_PRIVATE
,
pointer
);
}
void
SetErrorBuffer
(
char
*
buf
)
{
SetOption
(
CURLOPT_ERRORBUFFER
,
buf
);
}
void
SetURL
(
const
char
*
value
)
{
SetOption
(
CURLOPT_URL
,
value
);
}
void
SetUserAgent
(
const
char
*
value
)
{
SetOption
(
CURLOPT_USERAGENT
,
value
);
}
void
SetRequestHeaders
(
struct
curl_slist
*
headers
)
{
SetOption
(
CURLOPT_HTTPHEADER
,
headers
);
}
void
SetBasicAuth
(
const
char
*
userpwd
)
{
SetOption
(
CURLOPT_USERPWD
,
userpwd
);
}
void
SetNoProgress
(
bool
value
=
true
)
{
SetOption
(
CURLOPT_NOPROGRESS
,
(
long
)
value
);
}
void
SetNoSignal
(
bool
value
=
true
)
{
SetOption
(
CURLOPT_NOSIGNAL
,
(
long
)
value
);
}
void
SetFailOnError
(
bool
value
=
true
)
{
SetOption
(
CURLOPT_FAILONERROR
,
(
long
)
value
);
}
void
SetConnectTimeout
(
long
timeout
)
{
SetOption
(
CURLOPT_CONNECTTIMEOUT
,
timeout
);
}
void
SetHeaderFunction
(
size_t
(
*
function
)(
char
*
buffer
,
size_t
size
,
size_t
nitems
,
void
*
userdata
),
void
*
userdata
)
{
SetOption
(
CURLOPT_HEADERFUNCTION
,
function
);
SetOption
(
CURLOPT_HEADERDATA
,
userdata
);
}
void
SetWriteFunction
(
size_t
(
*
function
)(
char
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
userdata
),
void
*
userdata
)
{
SetOption
(
CURLOPT_WRITEFUNCTION
,
function
);
SetOption
(
CURLOPT_WRITEDATA
,
userdata
);
}
void
SetNoBody
(
bool
value
=
true
)
{
SetOption
(
CURLOPT_NOBODY
,
(
long
)
value
);
}
void
SetPost
(
bool
value
=
true
)
{
SetOption
(
CURLOPT_POST
,
(
long
)
value
);
}
void
SetRequestBody
(
const
void
*
data
,
size_t
size
)
{
SetOption
(
CURLOPT_POSTFIELDS
,
data
);
SetOption
(
CURLOPT_POSTFIELDSIZE
,
(
long
)
size
);
}
void
SetHttpPost
(
const
struct
curl_httppost
*
post
)
{
SetOption
(
CURLOPT_HTTPPOST
,
post
);
}
CurlString
Escape
(
const
char
*
string
,
int
length
=
0
)
const
noexcept
{
return
CurlString
(
curl_easy_escape
(
handle
,
string
,
length
));
}
...
...
src/lib/curl/Request.cxx
View file @
ab39f64f
...
...
@@ -52,17 +52,15 @@ CurlRequest::CurlRequest(CurlGlobal &_global,
{
error_buffer
[
0
]
=
0
;
easy
.
SetOption
(
CURLOPT_PRIVATE
,
(
void
*
)
this
);
easy
.
SetOption
(
CURLOPT_USERAGENT
,
"Music Player Daemon "
VERSION
);
easy
.
SetOption
(
CURLOPT_HEADERFUNCTION
,
_HeaderFunction
);
easy
.
SetOption
(
CURLOPT_WRITEHEADER
,
this
);
easy
.
SetOption
(
CURLOPT_WRITEFUNCTION
,
WriteFunction
);
easy
.
SetOption
(
CURLOPT_WRITEDATA
,
this
);
easy
.
SetPrivate
((
void
*
)
this
);
easy
.
SetUserAgent
(
"Music Player Daemon "
VERSION
);
easy
.
SetHeaderFunction
(
_HeaderFunction
,
this
);
easy
.
SetWriteFunction
(
WriteFunction
,
this
);
easy
.
SetOption
(
CURLOPT_NETRC
,
1l
);
easy
.
Set
Option
(
CURLOPT_ERRORBUFFER
,
error_buffer
);
easy
.
Set
Option
(
CURLOPT_NOPROGRESS
,
1l
);
easy
.
Set
Option
(
CURLOPT_NOSIGNAL
,
1l
);
easy
.
Set
Option
(
CURLOPT_CONNECTTIMEOUT
,
10l
);
easy
.
Set
ErrorBuffer
(
error_buffer
);
easy
.
Set
NoProgress
(
);
easy
.
Set
NoSignal
(
);
easy
.
Set
ConnectTimeout
(
10
);
easy
.
SetOption
(
CURLOPT_HTTPAUTH
,
(
long
)
CURLAUTH_ANY
);
}
...
...
@@ -220,14 +218,14 @@ CurlRequest::HeaderFunction(StringView s) noexcept
}
size_t
CurlRequest
::
_HeaderFunction
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
CurlRequest
::
_HeaderFunction
(
char
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
noexcept
{
CurlRequest
&
c
=
*
(
CurlRequest
*
)
stream
;
size
*=
nmemb
;
c
.
HeaderFunction
({
(
const
char
*
)
ptr
,
size
});
c
.
HeaderFunction
({
ptr
,
size
});
return
size
;
}
...
...
@@ -254,7 +252,7 @@ CurlRequest::DataReceived(const void *ptr, size_t received_size) noexcept
}
size_t
CurlRequest
::
WriteFunction
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
CurlRequest
::
WriteFunction
(
char
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
noexcept
{
CurlRequest
&
c
=
*
(
CurlRequest
*
)
stream
;
...
...
src/lib/curl/Request.hxx
View file @
ab39f64f
...
...
@@ -127,7 +127,7 @@ public:
}
void
SetUrl
(
const
char
*
url
)
{
easy
.
Set
Option
(
CURLOPT_URL
,
url
);
easy
.
Set
URL
(
url
);
}
/**
...
...
@@ -160,11 +160,11 @@ private:
void
OnPostponeError
()
noexcept
;
/** called by curl when new data is available */
static
size_t
_HeaderFunction
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
static
size_t
_HeaderFunction
(
char
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
noexcept
;
/** called by curl when new data is available */
static
size_t
WriteFunction
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
static
size_t
WriteFunction
(
char
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
noexcept
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment