Skip to content

Commit

Permalink
Add force_tls setting
Browse files Browse the repository at this point in the history
Use TLS for all actions when requested. Closes #234
  • Loading branch information
PromyLOPh committed Apr 14, 2012
1 parent ed6d013 commit 35763de
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions contrib/pianobar.1
Expand Up @@ -194,6 +194,11 @@ Location of control fifo. Defaults to $XDG_CONFIG_HOME/pianobar/ctl (which is
usually the value above). See section
.B REMOTE CONTROL

.TP
.B force_tls = {0,1}
Use TLS for all actions (not just sending login credentials). Use if you are on
an untrusted network or to get around GeoIP restrictions.

.TP
.B format_list_song = %i) %a - %t%r
Available format characters:
Expand Down
3 changes: 3 additions & 0 deletions src/settings.c
Expand Up @@ -121,6 +121,7 @@ void BarSettingsRead (BarSettings_t *settings) {
#endif
#endif
settings->autoselect = true;
settings->forceTls = false;
settings->history = 5;
settings->volume = 0;
settings->sortOrder = BAR_SORT_NAME_AZ;
Expand Down Expand Up @@ -245,6 +246,8 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->fifo = strdup (val);
} else if (streq ("autoselect", key)) {
settings->autoselect = atoi (val);
} else if (streq ("force_tls", key)) {
settings->forceTls = atoi (val);
} else if (streq ("tls_fingerprint", key)) {
/* expects 40 byte hex-encoded sha1 */
if (strlen (val) == 40) {
Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Expand Up @@ -81,6 +81,7 @@ typedef struct {

typedef struct {
bool autoselect;
bool forceTls;
unsigned int history;
int volume;
BarStationSorting_t sortOrder;
Expand Down
7 changes: 4 additions & 3 deletions src/ui.c
Expand Up @@ -134,14 +134,15 @@ void BarUiMsg (const BarSettings_t *settings, const BarUiMsg_t type,
/* fetch http resource (post request)
* @param waitress handle
* @param piano request (initialized by PianoRequest())
* @param ignore libpiano TLS hint and use it always
*/
static WaitressReturn_t BarPianoHttpRequest (WaitressHandle_t *waith,
PianoRequest_t *req) {
PianoRequest_t *req, bool forceTls) {
waith->extraHeaders = "Content-Type: text/xml\r\n";
waith->postData = req->postData;
waith->method = WAITRESS_METHOD_POST;
waith->url.path = req->urlPath;
waith->url.tls = req->secure;
waith->url.tls = req->secure || forceTls;

return WaitressFetchBuf (waith, &req->responseData);
}
Expand Down Expand Up @@ -172,7 +173,7 @@ int BarUiPianoCall (BarApp_t * const app, PianoRequestType_t type,
return 0;
}

*wRet = BarPianoHttpRequest (&app->waith, &req);
*wRet = BarPianoHttpRequest (&app->waith, &req, app->settings.forceTls);
if (*wRet != WAITRESS_RET_OK) {
BarUiMsg (&app->settings, MSG_NONE, "Network error: %s\n", WaitressErrorToStr (*wRet));
if (req.responseData != NULL) {
Expand Down

0 comments on commit 35763de

Please sign in to comment.