1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-11-03 04:17:17 -05:00

Cleanup: make util_base64_encode() useful for binary data.

This commit is contained in:
Philipp Schafft 2015-01-04 09:54:36 +00:00
parent de48bdd13f
commit a650965cfd
3 changed files with 6 additions and 8 deletions

View File

@ -176,7 +176,7 @@ static client_t *open_relay_connection (relay_server *relay)
auth_header = malloc (len); auth_header = malloc (len);
snprintf (auth_header, len, "%s:%s", relay->username, relay->password); snprintf (auth_header, len, "%s:%s", relay->username, relay->password);
esc_authorisation = util_base64_encode(auth_header); esc_authorisation = util_base64_encode(auth_header, len);
free(auth_header); free(auth_header);
len = strlen (esc_authorisation) + 24; len = strlen (esc_authorisation) + 24;
auth_header = malloc (len); auth_header = malloc (len);
@ -637,7 +637,7 @@ static int update_from_master(ice_config_t *config)
len = strlen(username) + strlen(password) + 2; len = strlen(username) + strlen(password) + 2;
authheader = malloc(len); authheader = malloc(len);
snprintf (authheader, len, "%s:%s", username, password); snprintf (authheader, len, "%s:%s", username, password);
data = util_base64_encode(authheader); data = util_base64_encode(authheader, len);
sock_write (mastersock, sock_write (mastersock,
"GET /admin/streamlist.txt HTTP/1.0\r\n" "GET /admin/streamlist.txt HTTP/1.0\r\n"
"Authorization: Basic %s\r\n" "Authorization: Basic %s\r\n"

View File

@ -409,15 +409,13 @@ char *util_bin_to_hex(unsigned char *data, int len)
} }
/* This isn't efficient, but it doesn't need to be */ /* This isn't efficient, but it doesn't need to be */
char *util_base64_encode(const char *data) char *util_base64_encode(const char *data, size_t len) {
{
int len = strlen(data);
char *out = malloc(len*4/3 + 4); char *out = malloc(len*4/3 + 4);
char *result = out; char *result = out;
int chunk; size_t chunk;
while(len > 0) { while(len > 0) {
chunk = (len >3)?3:len; chunk = len > 3 ? 3 : len;
*out++ = base64table[(*data & 0xFC)>>2]; *out++ = base64table[(*data & 0xFC)>>2];
*out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)]; *out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
switch(chunk) { switch(chunk) {

View File

@ -32,7 +32,7 @@ char *util_get_extension(const char *path);
char *util_get_path_from_uri(char *uri); char *util_get_path_from_uri(char *uri);
char *util_get_path_from_normalised_uri(const char *uri); char *util_get_path_from_normalised_uri(const char *uri);
char *util_normalise_uri(const char *uri); char *util_normalise_uri(const char *uri);
char *util_base64_encode(const char *data); char *util_base64_encode(const char *data, size_t len);
char *util_base64_decode(const char *input); char *util_base64_decode(const char *input);
char *util_bin_to_hex(unsigned char *data, int len); char *util_bin_to_hex(unsigned char *data, int len);