Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Icecast-Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
94
Issues
94
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
External Wiki
External Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xiph.Org
Icecast-Server
Commits
d3370f3d
Commit
d3370f3d
authored
Nov 28, 2015
by
Philipp Schafft
🦁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: unify util.c a bit with libshout.
parent
2ff8c50d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
52 deletions
+55
-52
src/util.c
src/util.c
+55
-52
No files found.
src/util.c
View file @
d3370f3d
...
...
@@ -54,6 +54,58 @@
#include "logging.h"
/* first all static tables, then the code */
static
const
char
hexchars
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
static
const
char
safechars
[
256
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
1
,
1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-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
};
/* Abstract out an interface to use either poll or select depending on which
* is available (poll is preferred) to watch a single fd.
*
...
...
@@ -109,7 +161,6 @@ int util_read_header(sock_t sock, char *buff, unsigned long len, int entire)
read_bytes
=
0
;
if
(
util_timed_wait_for_fd
(
sock
,
header_timeout
*
1000
)
>
0
)
{
if
((
read_bytes
=
recv
(
sock
,
&
c
,
1
,
0
)))
{
if
(
c
!=
'\r'
)
buff
[
pos
++
]
=
c
;
if
(
entire
)
{
...
...
@@ -245,29 +296,6 @@ char *util_get_path_from_normalised_uri(const char *uri) {
return
fullpath
;
}
static
const
char
hexchars
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
static
const
char
safechars
[
256
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0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,6 @@ char *util_normalise_uri(const char *uri) {
}
}
static
const
char
base64table
[
64
]
=
{
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'G'
,
'H'
,
'I'
,
'J'
,
'K'
,
'L'
,
'M'
,
'N'
,
'O'
,
'P'
,
'Q'
,
'R'
,
'S'
,
'T'
,
'U'
,
'V'
,
'W'
,
'X'
,
'Y'
,
'Z'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
'k'
,
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'+'
,
'/'
};
static
const
signed
char
base64decode
[
256
]
=
{
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
62
,
-
2
,
-
2
,
-
2
,
63
,
52
,
53
,
54
,
55
,
56
,
57
,
58
,
59
,
60
,
61
,
-
2
,
-
2
,
-
2
,
-
1
,
-
2
,
-
2
,
-
2
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
26
,
27
,
28
,
29
,
30
,
31
,
32
,
33
,
34
,
35
,
36
,
37
,
38
,
39
,
40
,
41
,
42
,
43
,
44
,
45
,
46
,
47
,
48
,
49
,
50
,
51
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
,
-
2
};
char
*
util_bin_to_hex
(
unsigned
char
*
data
,
int
len
)
{
char
*
hex
=
malloc
(
len
*
2
+
1
);
...
...
@@ -420,9 +422,10 @@ char *util_base64_encode(const char *data, size_t len) {
size_t
chunk
;
while
(
len
>
0
)
{
chunk
=
len
>
3
?
3
:
len
;
chunk
=
(
len
>
3
)
?
3
:
len
;
*
out
++
=
base64table
[(
*
data
&
0xFC
)
>>
2
];
*
out
++
=
base64table
[((
*
data
&
0x03
)
<<
4
)
|
((
*
(
data
+
1
)
&
0xF0
)
>>
4
)];
switch
(
chunk
)
{
case
3
:
*
out
++
=
base64table
[((
*
(
data
+
1
)
&
0x0F
)
<<
2
)
|
((
*
(
data
+
2
)
&
0xC0
)
>>
6
)];
...
...
@@ -771,7 +774,7 @@ void util_dict_free(util_dict *dict)
const
char
*
util_dict_get
(
util_dict
*
dict
,
const
char
*
key
)
{
while
(
dict
)
{
if
(
!
strcmp
(
key
,
dict
->
key
))
if
(
dict
->
key
&&
!
strcmp
(
key
,
dict
->
key
))
return
dict
->
val
;
dict
=
dict
->
next
;
}
...
...
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