From: Florian Zeitz Date: Tue, 12 Jul 2011 21:53:43 +0000 (+0200) Subject: Support MPD_HOST/MPD_PORT environment variables X-Git-Url: https://git.babelmonkeys.de/?a=commitdiff_plain;h=3bfc0d740c800ee4d5ef71acb6fd55998d7a0aad;p=mpdbot.git Support MPD_HOST/MPD_PORT environment variables --- 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) {