Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xiph.Org
Icecast-Server
Commits
ca83e6b4
Commit
ca83e6b4
authored
Nov 04, 2018
by
Philipp Schafft
🦁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feature: Added type="cors" to <header>.
parent
ff0263b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
10 deletions
+31
-10
src/cfgfile.c
src/cfgfile.c
+6
-3
src/cfgfile.h
src/cfgfile.h
+3
-1
src/util.c
src/util.c
+22
-6
No files found.
src/cfgfile.c
View file @
ca83e6b4
...
...
@@ -518,7 +518,8 @@ static void config_clear_http_header(ice_config_http_header_t *header)
while
(
header
)
{
xmlFree
(
header
->
name
);
xmlFree
(
header
->
value
);
if
(
header
->
value
)
xmlFree
(
header
->
value
);
old
=
header
;
header
=
header
->
next
;
free
(
old
);
...
...
@@ -1664,13 +1665,15 @@ static void _parse_http_headers(xmlDocPtr doc,
continue
;
if
(
!
(
name
=
(
char
*
)
xmlGetProp
(
node
,
XMLSTR
(
"name"
))))
break
;
if
(
!
(
value
=
(
char
*
)
xmlGetProp
(
node
,
XMLSTR
(
"value"
))))
break
;
value
=
(
char
*
)
xmlGetProp
(
node
,
XMLSTR
(
"value"
))
;
type
=
HTTP_HEADER_TYPE_STATIC
;
/* default */
if
((
tmp
=
(
char
*
)
xmlGetProp
(
node
,
XMLSTR
(
"type"
))))
{
if
(
strcmp
(
tmp
,
"static"
)
==
0
)
{
type
=
HTTP_HEADER_TYPE_STATIC
;
}
else
if
(
strcmp
(
tmp
,
"cors"
)
==
0
||
strcmp
(
tmp
,
"corpse"
)
==
0
)
{
type
=
HTTP_HEADER_TYPE_CORS
;
}
else
{
ICECAST_LOG_WARN
(
"Unknown type %s for "
"HTTP Header %s"
,
tmp
,
name
);
...
...
src/cfgfile.h
View file @
ca83e6b4
...
...
@@ -32,7 +32,9 @@
typedef
enum
_http_header_type
{
/* static: headers are passed as is to the client. */
HTTP_HEADER_TYPE_STATIC
HTTP_HEADER_TYPE_STATIC
,
/* CORS: headers are only sent to the client if it's a CORS request. */
HTTP_HEADER_TYPE_CORS
}
http_header_type
;
typedef
struct
ice_config_http_header_tag
{
...
...
src/util.c
View file @
ca83e6b4
...
...
@@ -598,7 +598,7 @@ unsigned int util_str_to_unsigned_int(const char *str, const unsigned int defaul
}
/* TODO, FIXME: handle memory allocation errors better. */
static
inline
void
_build_headers_loop
(
char
**
ret
,
size_t
*
len
,
ice_config_http_header_t
*
header
,
int
status
)
{
static
inline
void
_build_headers_loop
(
char
**
ret
,
size_t
*
len
,
ice_config_http_header_t
*
header
,
int
status
,
const
char
*
allow
,
client_t
*
client
)
{
size_t
headerlen
;
const
char
*
name
;
const
char
*
value
;
...
...
@@ -620,7 +620,23 @@ static inline void _build_headers_loop(char **ret, size_t *len, ice_config_htt
switch
(
header
->
type
)
{
case
HTTP_HEADER_TYPE_STATIC
:
value
=
header
->
value
;
break
;
break
;
case
HTTP_HEADER_TYPE_CORS
:
if
(
name
&&
client
&&
client
->
parser
)
{
const
char
*
origin
=
httpp_getvar
(
client
->
parser
,
"origin"
);
if
(
origin
)
{
value
=
header
->
value
;
if
(
!
value
)
{
ICECAST_LOG_ERROR
(
"value='%s', name='%s', origin='%s', allow='%s'"
,
value
,
name
,
origin
,
allow
);
if
(
strcasecmp
(
name
,
"Access-Control-Allow-Origin"
)
==
0
)
{
value
=
origin
;
}
else
if
(
strcasecmp
(
name
,
"Access-Control-Allow-Methods"
)
==
0
)
{
value
=
allow
;
}
}
}
}
break
;
}
/* check data */
...
...
@@ -644,7 +660,7 @@ static inline void _build_headers_loop(char **ret, size_t *len, ice_config_htt
}
while
((
header
=
header
->
next
));
*
ret
=
r
;
}
static
inline
char
*
_build_headers
(
int
status
,
ice_config_t
*
config
,
source_t
*
source
)
{
static
inline
char
*
_build_headers
(
int
status
,
const
char
*
allow
,
ice_config_t
*
config
,
source_t
*
source
,
client_t
*
client
)
{
mount_proxy
*
mountproxy
=
NULL
;
char
*
ret
=
NULL
;
size_t
len
=
1
;
...
...
@@ -655,9 +671,9 @@ static inline char * _build_headers(int status, ice_config_t *config, source_t *
ret
=
calloc
(
1
,
1
);
*
ret
=
0
;
_build_headers_loop
(
&
ret
,
&
len
,
config
->
http_headers
,
status
);
_build_headers_loop
(
&
ret
,
&
len
,
config
->
http_headers
,
status
,
allow
,
client
);
if
(
mountproxy
&&
mountproxy
->
http_headers
)
_build_headers_loop
(
&
ret
,
&
len
,
mountproxy
->
http_headers
,
status
);
_build_headers_loop
(
&
ret
,
&
len
,
mountproxy
->
http_headers
,
status
,
allow
,
client
);
return
ret
;
}
...
...
@@ -785,7 +801,7 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset,
}
config
=
config_get_config
();
extra_headers
=
_build_headers
(
status
,
config
,
source
);
extra_headers
=
_build_headers
(
status
,
allow_header
,
config
,
source
,
client
);
ret
=
snprintf
(
out
,
len
,
"%sServer: %s
\r\n
Connection: %s
\r\n
Accept-Encoding: identity
\r\n
Allow: %s
\r\n
%s%s%s%s%s%s%s%s"
,
status_buffer
,
config
->
server_id
,
...
...
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