Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
23416f82
Commit
23416f82
authored
5 years ago
by
Friendly Automation
Committed by
Gerrit Code Review
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge "func_curl.c: Support custom http headers"
parents
d792d847
d257a089
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/CHANGES-staging/func_curl_headers.txt
+6
-0
6 additions, 0 deletions
doc/CHANGES-staging/func_curl_headers.txt
funcs/func_curl.c
+29
-8
29 additions, 8 deletions
funcs/func_curl.c
with
35 additions
and
8 deletions
doc/CHANGES-staging/func_curl_headers.txt
0 → 100644
+
6
−
0
View file @
23416f82
Subject: func_curl
A new parameter, httpheader, has been added to CURLOPT function. This parameter
allows to set custom http headers for subsequent calls off CURL function.
Any setting of headers will replace the default curl headers
(e.g. "Content-type: application/x-www-form-urlencoded")
This diff is collapsed.
Click to expand it.
funcs/func_curl.c
+
29
−
8
View file @
23416f82
...
...
@@ -121,6 +121,11 @@
<para>Include header information in the result
(boolean)</para>
</enum>
<enum name="httpheader">
<para>Add HTTP header. Multiple calls add multiple headers.
Setting of any header will remove the default
"Content-Type application/x-www-form-urlencoded"</para>
</enum>
<enum name="httptimeout">
<para>For HTTP(S) URIs, number of seconds to wait for a
server response</para>
...
...
@@ -181,7 +186,7 @@
</syntax>
<description>
<para>Options may be set globally or per channel. Per-channel
settings will override global settings.</para>
settings will override global settings.
Only HTTP headers are added instead of overriding
</para>
</description>
<see-also>
<ref type="function">CURL</ref>
...
...
@@ -243,6 +248,9 @@ static int parse_curlopt_key(const char *name, CURLoption *key, enum optiontype
if
(
!
strcasecmp
(
name
,
"header"
))
{
*
key
=
CURLOPT_HEADER
;
*
ot
=
OT_BOOLEAN
;
}
else
if
(
!
strcasecmp
(
name
,
"httpheader"
))
{
*
key
=
CURLOPT_HTTPHEADER
;
*
ot
=
OT_STRING
;
}
else
if
(
!
strcasecmp
(
name
,
"proxy"
))
{
*
key
=
CURLOPT_PROXY
;
*
ot
=
OT_STRING
;
...
...
@@ -412,16 +420,18 @@ yuck:
return
-
1
;
}
/* Remove any existing entry */
/* Remove any existing entry
, only http headers are left
*/
AST_LIST_LOCK
(
list
);
AST_LIST_TRAVERSE_SAFE_BEGIN
(
list
,
cur
,
list
)
{
if
(
cur
->
key
==
new
->
key
)
{
AST_LIST_REMOVE_CURRENT
(
list
);
ast_free
(
cur
);
break
;
if
(
new
->
key
!=
CURLOPT_HTTPHEADER
)
{
AST_LIST_TRAVERSE_SAFE_BEGIN
(
list
,
cur
,
list
)
{
if
(
cur
->
key
==
new
->
key
)
{
AST_LIST_REMOVE_CURRENT
(
list
);
ast_free
(
cur
);
break
;
}
}
AST_LIST_TRAVERSE_SAFE_END
}
AST_LIST_TRAVERSE_SAFE_END
/* Insert new entry */
ast_debug
(
1
,
"Inserting entry %p with key %d and value %p
\n
"
,
new
,
new
->
key
,
new
->
value
);
...
...
@@ -639,6 +649,7 @@ static int acf_curl_helper(struct ast_channel *chan, struct curl_args *args)
int
ret
=
-
1
;
CURL
**
curl
;
struct
curl_settings
*
cur
;
struct
curl_slist
*
headers
=
NULL
;
struct
ast_datastore
*
store
=
NULL
;
int
hashcompat
=
0
;
AST_LIST_HEAD
(
global_curl_info
,
curl_settings
)
*
list
=
NULL
;
...
...
@@ -666,6 +677,8 @@ static int acf_curl_helper(struct ast_channel *chan, struct curl_args *args)
AST_LIST_TRAVERSE
(
&
global_curl_info
,
cur
,
list
)
{
if
(
cur
->
key
==
CURLOPT_SPECIAL_HASHCOMPAT
)
{
hashcompat
=
(
long
)
cur
->
value
;
}
else
if
(
cur
->
key
==
CURLOPT_HTTPHEADER
)
{
headers
=
curl_slist_append
(
headers
,
(
char
*
)
cur
->
value
);
}
else
{
curl_easy_setopt
(
*
curl
,
cur
->
key
,
cur
->
value
);
}
...
...
@@ -682,6 +695,8 @@ static int acf_curl_helper(struct ast_channel *chan, struct curl_args *args)
AST_LIST_TRAVERSE
(
list
,
cur
,
list
)
{
if
(
cur
->
key
==
CURLOPT_SPECIAL_HASHCOMPAT
)
{
hashcompat
=
(
long
)
cur
->
value
;
}
else
if
(
cur
->
key
==
CURLOPT_HTTPHEADER
)
{
headers
=
curl_slist_append
(
headers
,
(
char
*
)
cur
->
value
);
}
else
{
curl_easy_setopt
(
*
curl
,
cur
->
key
,
cur
->
value
);
}
...
...
@@ -697,6 +712,10 @@ static int acf_curl_helper(struct ast_channel *chan, struct curl_args *args)
curl_easy_setopt
(
*
curl
,
CURLOPT_POSTFIELDS
,
args
->
postdata
);
}
if
(
headers
)
{
curl_easy_setopt
(
*
curl
,
CURLOPT_HTTPHEADER
,
headers
);
}
/* Temporarily assign a buffer for curl to write errors to. */
curl_errbuf
[
0
]
=
curl_errbuf
[
CURL_ERROR_SIZE
]
=
'\0'
;
curl_easy_setopt
(
*
curl
,
CURLOPT_ERRORBUFFER
,
curl_errbuf
);
...
...
@@ -714,6 +733,7 @@ static int acf_curl_helper(struct ast_channel *chan, struct curl_args *args)
if
(
store
)
{
AST_LIST_UNLOCK
(
list
);
}
curl_slist_free_all
(
headers
);
if
(
args
->
postdata
)
{
curl_easy_setopt
(
*
curl
,
CURLOPT_POST
,
0
);
...
...
@@ -841,6 +861,7 @@ static struct ast_custom_function acf_curlopt = {
" ftptext - For FTP, force a text transfer (boolean)
\n
"
" ftptimeout - For FTP, the server response timeout
\n
"
" header - Retrieve header information (boolean)
\n
"
" httpheader - Add new custom http header (string)
\n
"
" httptimeout - Number of seconds to wait for HTTP response
\n
"
" maxredirs - Maximum number of redirects to follow
\n
"
" proxy - Hostname or IP to use as a proxy
\n
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment