Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
Icecast-Server
Commits
0fba6bab
Commit
0fba6bab
authored
Feb 02, 2003
by
Ed "oddsock" Zaleski
Browse files
style changes
svn path=/trunk/icecast/; revision=4316
parent
2848150f
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
src/geturl.c
View file @
0fba6bab
...
...
@@ -17,162 +17,159 @@
#include <curl/easy.h>
#define CATMODULE "
CURL
"
#define CATMODULE "
geturl
"
static
CurlConnection
curlConnections
[
NUM_CONNECTIONS
];
static
int
nunConnections
=
NUM_CONNECTIONS
;
static
curl_connection
curl_connections
[
NUM_CONNECTIONS
];
mutex_t
_curl_mutex
;
size_t
W
rite
M
emory
C
allback
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
data
)
curl_w
rite
_m
emory
_c
allback
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
data
)
{
register
int
realsize
=
size
*
nmemb
;
register
int
realsize
=
size
*
nmemb
;
struct
M
emory
S
truct
*
mem
=
(
struct
M
emory
S
truct
*
)
data
;
struct
curl_m
emory
_s
truct
*
mem
=
(
struct
curl_m
emory
_s
truct
*
)
data
;
if
((
realsize
+
mem
->
size
)
<
YP_RESPONSE_SIZE
-
1
)
{
strncat
(
mem
->
memory
,
ptr
,
realsize
);
}
if
((
realsize
+
mem
->
size
)
<
YP_RESPONSE_SIZE
-
1
)
{
strncat
(
mem
->
memory
,
ptr
,
realsize
);
}
return
realsize
;
return
realsize
;
}
size_t
H
eader
M
emory
C
allback
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
data
)
curl_h
eader
_m
emory
_c
allback
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
data
)
{
char
*
p1
=
0
;
char
*
p2
=
0
;
int
copylen
=
0
;
register
int
realsize
=
size
*
nmemb
;
struct
M
emory
S
truct2
*
mem
=
(
struct
M
emory
S
truct2
*
)
data
;
if
(
!
strncmp
(
ptr
,
"SID: "
,
strlen
(
"SID: "
)))
{
p1
=
(
char
*
)
ptr
+
strlen
(
"SID: "
);
p2
=
strchr
((
const
char
*
)
p1
,
'\r'
);
memset
(
mem
->
sid
,
'\000'
,
sizeof
(
mem
->
sid
));
if
(
p2
)
{
if
(
p2
-
p1
>
sizeof
(
mem
->
sid
)
-
1
)
{
copylen
=
sizeof
(
mem
->
sid
)
-
1
;
}
else
{
copylen
=
p2
-
p1
;
}
strncpy
(
mem
->
sid
,
p1
,
copylen
);
}
else
{
strncpy
(
mem
->
sid
,
p1
,
sizeof
(
mem
->
sid
)
-
1
);
strcpy
(
mem
->
sid
,
p1
);
}
}
if
(
!
strncmp
(
ptr
,
"YPMessage: "
,
strlen
(
"YPMessage: "
)))
{
p1
=
(
char
*
)
ptr
+
strlen
(
"YPMessage: "
);
p2
=
strchr
((
const
char
*
)
p1
,
'\r'
);
memset
(
mem
->
message
,
'\000'
,
sizeof
(
mem
->
message
));
if
(
p2
)
{
if
(
p2
-
p1
>
sizeof
(
mem
->
message
)
-
1
)
{
copylen
=
sizeof
(
mem
->
message
)
-
1
;
}
else
{
copylen
=
p2
-
p1
;
}
strncpy
(
mem
->
message
,
p1
,
copylen
);
}
else
{
strncpy
(
mem
->
message
,
p1
,
sizeof
(
mem
->
message
)
-
1
);
strcpy
(
mem
->
message
,
p1
);
}
}
if
(
!
strncmp
(
ptr
,
"TouchFreq: "
,
strlen
(
"TouchFreq: "
)))
{
p1
=
(
char
*
)
ptr
+
strlen
(
"TouchFreq: "
);
mem
->
touch
F
req
=
atoi
(
p1
);
}
if
(
!
strncmp
(
ptr
,
"YPResponse: "
,
strlen
(
"YPResponse: "
)))
{
p1
=
(
char
*
)
ptr
+
strlen
(
"YPResponse: "
);
mem
->
response
=
atoi
(
p1
);
}
return
realsize
;
char
*
p1
=
0
;
char
*
p2
=
0
;
int
copylen
=
0
;
register
int
realsize
=
size
*
nmemb
;
struct
curl_m
emory
_s
truct2
*
mem
=
(
struct
curl_m
emory
_s
truct2
*
)
data
;
if
(
!
strncmp
(
ptr
,
"SID: "
,
strlen
(
"SID: "
)))
{
p1
=
(
char
*
)
ptr
+
strlen
(
"SID: "
);
p2
=
strchr
((
const
char
*
)
p1
,
'\r'
);
memset
(
mem
->
sid
,
'\000'
,
sizeof
(
mem
->
sid
));
if
(
p2
)
{
if
(
p2
-
p1
>
sizeof
(
mem
->
sid
)
-
1
)
{
copylen
=
sizeof
(
mem
->
sid
)
-
1
;
}
else
{
copylen
=
p2
-
p1
;
}
strncpy
(
mem
->
sid
,
p1
,
copylen
);
}
else
{
strncpy
(
mem
->
sid
,
p1
,
sizeof
(
mem
->
sid
)
-
1
);
strcpy
(
mem
->
sid
,
p1
);
}
}
if
(
!
strncmp
(
ptr
,
"YPMessage: "
,
strlen
(
"YPMessage: "
)))
{
p1
=
(
char
*
)
ptr
+
strlen
(
"YPMessage: "
);
p2
=
strchr
((
const
char
*
)
p1
,
'\r'
);
memset
(
mem
->
message
,
'\000'
,
sizeof
(
mem
->
message
));
if
(
p2
)
{
if
(
p2
-
p1
>
sizeof
(
mem
->
message
)
-
1
)
{
copylen
=
sizeof
(
mem
->
message
)
-
1
;
}
else
{
copylen
=
p2
-
p1
;
}
strncpy
(
mem
->
message
,
p1
,
copylen
);
}
else
{
strncpy
(
mem
->
message
,
p1
,
sizeof
(
mem
->
message
)
-
1
);
strcpy
(
mem
->
message
,
p1
);
}
}
if
(
!
strncmp
(
ptr
,
"TouchFreq: "
,
strlen
(
"TouchFreq: "
)))
{
p1
=
(
char
*
)
ptr
+
strlen
(
"TouchFreq: "
);
mem
->
touch
_f
req
=
atoi
(
p1
);
}
if
(
!
strncmp
(
ptr
,
"YPResponse: "
,
strlen
(
"YPResponse: "
)))
{
p1
=
(
char
*
)
ptr
+
strlen
(
"YPResponse: "
);
mem
->
response
=
atoi
(
p1
);
}
return
realsize
;
}
int
curl_initialize
()
{
int
i
=
0
;
thread_mutex_create
(
&
_curl_mutex
);
memset
(
&
curlConnections
,
'\000'
,
sizeof
(
curlConnections
));
for
(
i
=
0
;
i
<
NUM_CONNECTIONS
;
i
++
)
{
curlConnections
[
i
].
curl_handle
=
curl_easy_init
();
curl_easy_setopt
(
curlConnections
[
i
].
curl_handle
,
CURLOPT_WRITEFUNCTION
,
WriteMemoryCallback
);
curl_easy_setopt
(
curlConnections
[
i
].
curl_handle
,
CURLOPT_WRITEHEADER
,
(
void
*
)
&
(
curlConnections
[
i
].
headerresult
));
curl_easy_setopt
(
curlConnections
[
i
].
curl_handle
,
CURLOPT_HEADERFUNCTION
,
HeaderMemoryCallback
);
curl_easy_setopt
(
curlConnections
[
i
].
curl_handle
,
CURLOPT_FILE
,
(
void
*
)
&
(
curlConnections
[
i
].
result
));
}
return
(
1
);
int
i
=
0
;
thread_mutex_create
(
&
_curl_mutex
);
memset
(
&
curl_connections
,
'\000'
,
sizeof
(
curl_connections
));
for
(
i
=
0
;
i
<
NUM_CONNECTIONS
;
i
++
)
{
curl_connections
[
i
].
curl_handle
=
curl_easy_init
();
curl_easy_setopt
(
curl_connections
[
i
].
curl_handle
,
CURLOPT_WRITEFUNCTION
,
curl_write_memory_callback
);
curl_easy_setopt
(
curl_connections
[
i
].
curl_handle
,
CURLOPT_WRITEHEADER
,
(
void
*
)
&
(
curl_connections
[
i
].
header_result
));
curl_easy_setopt
(
curl_connections
[
i
].
curl_handle
,
CURLOPT_HEADERFUNCTION
,
curl_header_memory_callback
);
curl_easy_setopt
(
curl_connections
[
i
].
curl_handle
,
CURLOPT_FILE
,
(
void
*
)
&
(
curl_connections
[
i
].
result
));
}
return
(
1
);
}
void
curl_shutdown
()
{
int
i
=
0
;
for
(
i
=
0
;
i
<
NUM_CONNECTIONS
;
i
++
)
{
curl_easy_cleanup
(
curlConnections
[
i
].
curl_handle
);
memset
(
&
(
curlConnections
[
i
]),
'\000'
,
sizeof
(
curlConnections
[
i
]));
}
int
i
=
0
;
for
(
i
=
0
;
i
<
NUM_CONNECTIONS
;
i
++
)
{
curl_easy_cleanup
(
curl_connections
[
i
].
curl_handle
);
memset
(
&
(
curl_connections
[
i
]),
'\000'
,
sizeof
(
curl_connections
[
i
]));
}
}
int
getCurlConnection
()
int
curl_get_connection
()
{
int
found
=
0
;
int
curl
C
onnection
=
-
1
;
int
i
=
0
;
while
(
!
found
)
{
thread_mutex_lock
(
&
_curl_mutex
);
for
(
i
=
0
;
i
<
NUM_CONNECTIONS
;
i
++
)
{
if
(
!
curl
C
onnections
[
i
].
in
U
se
)
{
found
=
1
;
curl
C
onnections
[
i
].
in
U
se
=
1
;
curl
C
onnection
=
i
;
break
;
}
}
thread_mutex_unlock
(
&
_curl_mutex
);
int
found
=
0
;
int
curl
_c
onnection
=
-
1
;
int
i
=
0
;
while
(
!
found
)
{
thread_mutex_lock
(
&
_curl_mutex
);
for
(
i
=
0
;
i
<
NUM_CONNECTIONS
;
i
++
)
{
if
(
!
curl
_c
onnections
[
i
].
in
_u
se
)
{
found
=
1
;
curl
_c
onnections
[
i
].
in
_u
se
=
1
;
curl
_c
onnection
=
i
;
break
;
}
}
thread_mutex_unlock
(
&
_curl_mutex
);
#ifdef WIN32
Sleep
(
200
);
Sleep
(
200
);
#else
usleep
(
200
);
usleep
(
200
);
#endif
}
return
(
curl
C
onnection
);
}
return
(
curl
_c
onnection
);
}
int
release
CurlC
onnection
(
int
which
)
int
curl_
release
_c
onnection
(
int
which
)
{
thread_mutex_lock
(
&
_curl_mutex
);
curlConnections
[
which
].
inUse
=
0
;
memset
(
&
(
curlConnections
[
which
].
result
),
'\000'
,
sizeof
(
curlConnections
[
which
].
result
));
memset
(
&
(
curlConnections
[
which
].
headerresult
),
'\000'
,
sizeof
(
curlConnections
[
which
].
headerresult
));
thread_mutex_unlock
(
&
_curl_mutex
);
return
1
;
thread_mutex_lock
(
&
_curl_mutex
);
curl_connections
[
which
].
in_use
=
0
;
memset
(
&
(
curl_connections
[
which
].
result
),
'\000'
,
sizeof
(
curl_connections
[
which
].
result
));
memset
(
&
(
curl_connections
[
which
].
header_result
),
'\000'
,
sizeof
(
curl_connections
[
which
].
header_result
));
thread_mutex_unlock
(
&
_curl_mutex
);
return
1
;
}
void
printHeaderResult
(
struct
MemoryStruct2
*
mem
)
{
DEBUG1
(
"SID -> (%s)"
,
mem
->
sid
);
DEBUG1
(
"Message -> (%s)"
,
mem
->
message
);
DEBUG1
(
"Touch Freq -> (%d)"
,
mem
->
touchFreq
);
DEBUG1
(
"Response -> (%d)"
,
mem
->
response
);
void
curl_print_header_result
(
struct
curl_memory_struct2
*
mem
)
{
DEBUG1
(
"SID -> (%s)"
,
mem
->
sid
);
DEBUG1
(
"Message -> (%s)"
,
mem
->
message
);
DEBUG1
(
"Touch Freq -> (%d)"
,
mem
->
touch_freq
);
DEBUG1
(
"Response -> (%d)"
,
mem
->
response
);
}
CURL
*
getCurlH
andle
(
int
which
)
CURL
*
curl_get_h
andle
(
int
which
)
{
return
curl
C
onnections
[
which
].
curl_handle
;
return
curl
_c
onnections
[
which
].
curl_handle
;
}
struct
M
emory
S
truct
*
getCurlR
esult
(
int
which
)
struct
curl_m
emory
_s
truct
*
curl_get_r
esult
(
int
which
)
{
return
&
(
curl
C
onnections
[
which
].
result
);
return
&
(
curl
_c
onnections
[
which
].
result
);
}
struct
M
emory
S
truct2
*
getCurlH
eader
R
esult
(
int
which
)
struct
curl_m
emory
_s
truct2
*
curl_get_h
eader
_r
esult
(
int
which
)
{
return
&
(
curl
C
onnections
[
which
].
headerresult
);
return
&
(
curl
_c
onnections
[
which
].
header
_
result
);
}
src/geturl.h
View file @
0fba6bab
...
...
@@ -13,33 +13,33 @@
#define YP_RESPONSE_SIZE 2046
#define YP_SID_SIZE 255
struct
M
emory
S
truct
{
char
memory
[
YP_RESPONSE_SIZE
];
size_t
size
;
struct
curl_m
emory
_s
truct
{
char
memory
[
YP_RESPONSE_SIZE
];
size_t
size
;
};
struct
M
emory
S
truct2
{
char
sid
[
YP_SID_SIZE
];
char
message
[
YP_RESPONSE_SIZE
];
int
touch
F
req
;
int
response
;
size_t
size
;
struct
curl_m
emory
_s
truct2
{
char
sid
[
YP_SID_SIZE
];
char
message
[
YP_RESPONSE_SIZE
];
int
touch
_f
req
;
int
response
;
size_t
size
;
};
typedef
struct
tag_
C
url
C
onnection
{
struct
M
emory
S
truct
result
;
struct
M
emory
S
truct2
headerresult
;
CURL
*
curl_handle
;
int
inU
se
;
}
C
url
C
onnection
;
typedef
struct
tag_
c
url
_c
onnection
{
struct
curl_m
emory
_s
truct
result
;
struct
curl_m
emory
_s
truct2
header
_
result
;
CURL
*
curl_handle
;
int
in_u
se
;
}
c
url
_c
onnection
;
int
curl_initialize
();
void
curl_shutdown
();
CURL
*
getCurlH
andle
(
int
which
);
struct
M
emory
S
truct
*
getCurlR
esult
(
int
which
);
struct
M
emory
S
truct2
*
getCurlH
eader
R
esult
(
int
which
);
void
print
H
eader
R
esult
(
struct
M
emory
S
truct2
*
mem
);
int
getCurlC
onnection
();
int
release
CurlC
onnection
(
int
which
);
CURL
*
curl_get_h
andle
(
int
which
);
struct
curl_m
emory
_s
truct
*
curl_get_r
esult
(
int
which
);
struct
curl_m
emory
_s
truct2
*
curl_get_h
eader
_r
esult
(
int
which
);
void
curl_
print
_h
eader
_r
esult
(
struct
curl_m
emory
_s
truct2
*
mem
);
int
curl_get_c
onnection
();
int
curl_
release
_c
onnection
(
int
which
);
#endif
src/source.c
View file @
0fba6bab
...
...
@@ -57,7 +57,7 @@ source_t *source_create(client_t *client, connection_t *con, http_parser_t *pars
src
->
listeners
=
0
;
for
(
i
=
0
;
i
<
config_get_config
()
->
num_yp_directories
;
i
++
)
{
if
(
config_get_config
()
->
yp_url
[
i
])
{
src
->
ypdata
[
src
->
num_yp_directories
]
=
create_ypdata
();
src
->
ypdata
[
src
->
num_yp_directories
]
=
yp_
create_ypdata
();
src
->
ypdata
[
src
->
num_yp_directories
]
->
yp_url
=
config_get_config
()
->
yp_url
[
i
];
src
->
ypdata
[
src
->
num_yp_directories
]
->
yp_url_timeout
=
config_get_config
()
->
yp_url_timeout
[
i
];
src
->
ypdata
[
src
->
num_yp_directories
]
->
yp_touch_freq
=
0
;
...
...
@@ -117,9 +117,9 @@ int source_free_source(void *key)
avl_tree_free
(
source
->
pending_tree
,
_free_client
);
avl_tree_free
(
source
->
client_tree
,
_free_client
);
source
->
format
->
free_plugin
(
source
->
format
);
for
(
i
=
0
;
i
<
source
->
num_yp_directories
;
i
++
)
{
destroy_ypdata
(
source
->
ypdata
[
i
]);
}
for
(
i
=
0
;
i
<
source
->
num_yp_directories
;
i
++
)
{
yp_
destroy_ypdata
(
source
->
ypdata
[
i
]);
}
free
(
source
);
return
1
;
...
...
src/yp.c
View file @
0fba6bab
This diff is collapsed.
Click to expand it.
src/yp.h
View file @
0fba6bab
...
...
@@ -25,8 +25,8 @@ void *yp_touch_thread(void *arg);
int
yp_add
(
void
*
psource
,
int
which
);
int
yp_touch
(
void
*
psource
);
int
yp_remove
(
void
*
psource
);
ypdata_t
*
create_ypdata
();
void
destroy_ypdata
(
ypdata_t
*
ypdata
);
ypdata_t
*
yp_
create_ypdata
();
void
yp_
destroy_ypdata
(
ypdata_t
*
ypdata
);
#endif
...
...
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