Skip to content

Commit

Permalink
expicite disable tls
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Mar 13, 2019
1 parent d90cbc8 commit ef74155
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
73 changes: 54 additions & 19 deletions lib/libshout/src/shout.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ void shout_free(shout_t *self)

int shout_open(shout_t *self)
{
/* sanity check */
puts("shout_open() ######################################");

/* sanity check */
if (!self)
return SHOUTERR_INSANE;
if (self->state != SHOUT_STATE_UNCONNECTED)
Expand Down Expand Up @@ -321,7 +323,9 @@ int shout_metadata_add(shout_metadata_t *self, const char *name, const char *val
* TODO: prettier error-handling. */
int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
{
int error;
puts("shout_set_metadata() ######################################");

int error;
sock_t socket = -1;
int rv;
char *encvalue = NULL;
Expand All @@ -333,18 +337,24 @@ int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
shout_tls_t *tls = NULL;
#endif

if (!self || !metadata)
if (!self || !metadata) {
puts("return SHOUTERR_INSANE");
return SHOUTERR_INSANE;
}

if (!(encvalue = _shout_util_dict_urlencode(metadata, '&')))
if (!(encvalue = _shout_util_dict_urlencode(metadata, '&'))) {
puts("goto error_malloc");
goto error_malloc;
}

switch (self->protocol) {
case SHOUT_PROTOCOL_ICY:
request_template = "GET /admin.cgi?mode=updinfo&pass=%s&%s HTTP/1.0\r\nUser-Agent: %s (Mozilla compatible)\r\n\r\n";
request_len = strlen(request_template) + strlen(self->password) + strlen(encvalue) + strlen(shout_get_agent(self)) + 1;
if (!(request = malloc(request_len)))
if (!(request = malloc(request_len))) {
puts("goto error_malloc");
goto error_malloc;
}
snprintf(request, request_len, request_template, self->password, encvalue, shout_get_agent(self));
break;
case SHOUT_PROTOCOL_HTTP:
Expand All @@ -354,15 +364,19 @@ int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
request_len = strlen(request_template) + strlen(self->mount) + strlen(encvalue) + strlen(shout_get_agent(self)) + 1;
if (auth)
request_len += strlen(auth);
if (!(request = malloc(request_len)))
if (!(request = malloc(request_len))) {
puts("goto error_malloc");
goto error_malloc;
}
snprintf(request, request_len, request_template, self->mount, encvalue, shout_get_agent(self), auth ? auth : "");
break;
default:
request_template = "GET /admin.cgi?mode=updinfo&pass=%s&mount=%s&%s HTTP/1.0\r\nUser-Agent: %s\r\n\r\n";
request_len = strlen(request_template) + strlen(self->password) + strlen(self->mount) + strlen(encvalue) + strlen(shout_get_agent(self)) + 1;
if (!(request = malloc(request_len)))
if (!(request = malloc(request_len))) {
puts("goto error_malloc");
goto error_malloc;
}
snprintf(request, request_len, request_template, self->password, self->mount, encvalue, shout_get_agent(self));
break;
}
Expand All @@ -374,8 +388,10 @@ int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
free(auth);
auth = NULL;

if ((socket = sock_connect(self->host, self->port)) <= 0)
if ((socket = sock_connect(self->host, self->port)) <= 0) {
puts("return SHOUTERR_NOCONNECT");
return SHOUTERR_NOCONNECT;
}

#ifdef HAVE_OPENSSL
switch (self->tls_mode) {
Expand All @@ -393,17 +409,23 @@ int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
self->host, self->port);
upgrade[sizeof(upgrade)-1] = 0;
len = strlen(upgrade);
if (len == (sizeof(upgrade) - 1))
if (len == (sizeof(upgrade) - 1)) {
puts("goto error_malloc");
goto error_malloc;
}
rv = sock_write_bytes(socket, upgrade, len);
if (len != (size_t)rv)
if (len != (size_t)rv) {
puts("goto error_socket");
goto error_socket;
}

/* read status line */
if (!sock_read_line(socket, upgrade, sizeof(upgrade)))
goto error_socket;
if (strncmp(upgrade, "HTTP/1.1 101 ", 13) != 0)
goto error_socket;
if (strncmp(upgrade, "HTTP/1.1 101 ", 13) != 0) {
puts("goto error_socket");
goto error_socket;
}

/* read headers */
len = 0;
Expand All @@ -419,29 +441,39 @@ int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
/* read body */
while (len) {
rv = sock_read_bytes(socket, upgrade, len > sizeof(upgrade) ? sizeof(upgrade) : len);
if (rv < 1)
goto error_socket;
if (rv < 1) {
puts("goto error_socket");
goto error_socket;
}
len -= rv;
}
} while (0);
/* fall thru */
case SHOUT_TLS_RFC2818: /* Use TLS for transport layer like HTTPS [RFC2818] does. */
tls = shout_tls_new(self, socket);
if (!tls)
goto error_malloc;
if (!tls) {
puts("goto error_malloc");
goto error_malloc;
}
error = shout_tls_try_connect(tls);
if (error != SHOUTERR_SUCCESS)
if (error != SHOUTERR_SUCCESS) {
puts("goto error 2");
goto error;
}
break;
default:
/* Bad mode or auto detection not completed. */
error = SHOUTERR_INSANE;
puts("goto error 3");
goto error;
break;
}
#endif

#ifdef HAVE_OPENSSL
puts("######################################");
puts(request);
puts("######################################");
if (tls) {
rv = shout_tls_write(tls, request, strlen(request));
} else {
Expand All @@ -451,8 +483,10 @@ int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
rv = sock_write(socket, "%s", request);
#endif

if (!rv)
goto error_socket;
if (!rv) {
puts("goto error_socket");
goto error_socket;
}

error = SHOUTERR_SUCCESS;
goto error;
Expand All @@ -476,6 +510,7 @@ int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
free(request);
if (auth)
free(auth);
puts("~shout_set_metadata() ######################################");
return error;
}

Expand Down
6 changes: 6 additions & 0 deletions src/engine/sidechain/shoutconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ ShoutConnection::ShoutConnection(BroadcastProfilePtr profile,
errorDialog(tr("Error setting non-blocking mode:"),
shout_get_error(m_pShout));
}

if (shout_set_tls(m_pShout, SHOUT_TLS_DISABLED) != SHOUTERR_SUCCESS) {
errorDialog(tr("Error setting tls mode:"),
shout_get_error(m_pShout));
}

}

ShoutConnection::~ShoutConnection() {
Expand Down

0 comments on commit ef74155

Please sign in to comment.