]> git.babelmonkeys.de Git - mpdbot.git/commitdiff
Support MPD_HOST/MPD_PORT environment variables
authorFlorian Zeitz <florob@babelmonkeys.de>
Tue, 12 Jul 2011 21:53:43 +0000 (23:53 +0200)
committerFlorian Zeitz <florob@babelmonkeys.de>
Tue, 12 Jul 2011 21:53:43 +0000 (23:53 +0200)
src/PEPThread.h
src/PEPThread.m

index ef30241527429e7bad8be55e29535c2bd08d4634..b483fc289f9348591569917ac25c650fc5f78859 100644 (file)
@@ -25,4 +25,6 @@
 - (OFMutableDictionary*)MPD_responseFromSocket: (OFTCPSocket*)sock;
 
 OFTCPSocket *sock;
+OFString *mpd_host;
+uint16_t mpd_port;
 @end
index b6b9cb1b50b23e18c56136d05747d4655135e2ac..cd13eb382ca57452cf979da8426fc777f83c4131 100644 (file)
@@ -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"
 
 - (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) {