From 3bfc0d740c800ee4d5ef71acb6fd55998d7a0aad Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Tue, 12 Jul 2011 23:53:43 +0200 Subject: [PATCH] Support MPD_HOST/MPD_PORT environment variables --- src/PEPThread.h | 2 ++ src/PEPThread.m | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/PEPThread.h b/src/PEPThread.h index ef30241..b483fc2 100644 --- a/src/PEPThread.h +++ b/src/PEPThread.h @@ -25,4 +25,6 @@ - (OFMutableDictionary*)MPD_responseFromSocket: (OFTCPSocket*)sock; OFTCPSocket *sock; +OFString *mpd_host; +uint16_t mpd_port; @end diff --git a/src/PEPThread.m b/src/PEPThread.m index b6b9cb1..cd13eb3 100644 --- a/src/PEPThread.m +++ b/src/PEPThread.m @@ -43,8 +43,8 @@ @try { [sock release]; sock = [[OFTCPSocket alloc] init]; - [sock connectToHost: @"localhost" - port: 6600]; + [sock connectToHost: mpd_host + port: mpd_port]; return; } @catch (id e) { [of_stderr writeFormat: @"Connection failed, retrying" @@ -77,6 +77,16 @@ - (id)main { + OFDictionary *environment = [OFApplication environment]; + OFString *mpd_port_string; + mpd_host = [environment objectForKey: @"MPD_HOST"]; + if (mpd_host == nil) + mpd_host = @"localhost"; + mpd_port_string = [environment objectForKey: @"MPD_PORT"]; + if (mpd_port_string && [mpd_port_string decimalValue] <= UINT16_MAX) + mpd_port = (uint16_t) [mpd_port_string decimalValue]; + else + mpd_port = 6600; [self MPD_connect]; [self MPD_responseFromSocket: sock]; while (1) { -- 2.39.5