diff --git a/Makefile b/Makefile index 1067b5a62..bc6fdeabb 100644 --- a/Makefile +++ b/Makefile @@ -801,8 +801,17 @@ config: cat contrib/init.d/rc.archlinux.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \ $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp $(DESTDIR)/etc/rc.d/asterisk ; \ rm -f contrib/init.d/rc.asterisk.tmp ; \ - elif [ -d $(DESTDIR)/Library/LaunchDaemons -a ! -f $(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist ] ; then \ - $(INSTALL) -m 644 contrib/init.d/org.asterisk.asterisk.plist $(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist; \ + elif [ -d $(DESTDIR)/Library/LaunchDaemons ]; then \ + if [ ! -f $(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist ]; then \ + sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' < contrib/init.d/org.asterisk.asterisk.plist > asterisk.plist ; \ + $(INSTALL) -m 644 asterisk.plist $(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist; \ + rm -f asterisk.plist; \ + fi; \ + if [ ! -f $(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist ]; then \ + sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' < contrib/init.d/org.asterisk.muted.plist > muted.plist ; \ + $(INSTALL) -m 644 muted.plist $(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist; \ + rm -f muted.plist; \ + fi; \ elif [ -f /etc/slackware-version ]; then \ echo "Slackware is not currently supported, although an init script does exist for it."; \ else \ diff --git a/contrib/init.d/org.asterisk.asterisk.plist b/contrib/init.d/org.asterisk.asterisk.plist index 79fe5d8aa..e22ce3e22 100644 --- a/contrib/init.d/org.asterisk.asterisk.plist +++ b/contrib/init.d/org.asterisk.asterisk.plist @@ -3,7 +3,7 @@ Label - org.asterisk.asterisk.launchagent + org.asterisk.asterisk Disabled UserName @@ -19,10 +19,10 @@ Umask 7 Program - /usr/local/sbin/asterisk + __ASTERISK_SBIN_DIR__/asterisk ProgramArguments - /usr/local/sbin/asterisk + __ASTERISK_SBIN_DIR__/asterisk -f EnvironmentVariables diff --git a/contrib/init.d/org.asterisk.muted.plist b/contrib/init.d/org.asterisk.muted.plist new file mode 100644 index 000000000..e3317ca80 --- /dev/null +++ b/contrib/init.d/org.asterisk.muted.plist @@ -0,0 +1,33 @@ + + + + + Label + org.asterisk.muted + Disabled + + UserName + asterisk + GroupName + asterisk + KeepAlive + + RunAtLoad + + Umask + 7 + Program + __ASTERISK_SBIN_DIR__/muted + ProgramArguments + + __ASTERISK_SBIN_DIR__/muted + -f + + StandardInPath + /dev/null + StandardOutPath + /dev/null + StandardErrorPath + /dev/null + + diff --git a/utils/muted.c b/utils/muted.c index 1202237b8..211766e53 100644 --- a/utils/muted.c +++ b/utils/muted.c @@ -39,6 +39,9 @@ #ifdef __Darwin__ #include +#include +#include +#include #elif defined(__linux__) || defined(__FreeBSD__) || defined(__GLIBC__) #include #endif @@ -54,7 +57,9 @@ #include #include -static char *config = "/etc/muted.conf"; +#define ast_strlen_zero(a) (!(*(a))) + +static char *config = "/etc/asterisk/muted.conf"; static char host[256] = ""; static char user[256] = ""; @@ -349,17 +354,25 @@ static float getvol(void) AudioDeviceID device; UInt32 size; UInt32 channels[2]; + AudioObjectPropertyAddress OutputAddr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; + AudioObjectPropertyAddress ChannelAddr = { kAudioDevicePropertyPreferredChannelsForStereo, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementWildcard }; + AudioObjectPropertyAddress VolumeAddr = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, }; size = sizeof(device); - err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device); + err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &OutputAddr, 0, NULL, &size, &device); size = sizeof(channels); - if (!err) - err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels); + if (!err) { + err = AudioObjectGetPropertyData(device, &ChannelAddr, 0, NULL, &size, &channels); + } size = sizeof(vol); - if (!err) - err = AudioDeviceGetProperty(device, channels[0], false, kAudioDevicePropertyVolumeScalar, &size, &volumeL); - if (!err) - err = AudioDeviceGetProperty(device, channels[1], false, kAudioDevicePropertyVolumeScalar, &size, &volumeR); + if (!err) { + VolumeAddr.mElement = channels[0]; + err = AudioObjectGetPropertyData(device, &VolumeAddr, 0, NULL, &size, &volumeL); + } + if (!err) { + VolumeAddr.mElement = channels[1]; + err = AudioObjectGetPropertyData(device, &VolumeAddr, 0, NULL, &size, &volumeR); + } if (!err) vol = (volumeL < volumeR) ? volumeR : volumeL; else { @@ -385,16 +398,23 @@ static int setvol(float vol) AudioDeviceID device; UInt32 size; UInt32 channels[2]; + AudioObjectPropertyAddress OutputAddr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; + AudioObjectPropertyAddress ChannelAddr = { kAudioDevicePropertyPreferredChannelsForStereo, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementWildcard }; + AudioObjectPropertyAddress VolumeAddr = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, }; size = sizeof(device); - err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device); + err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &OutputAddr, 0, NULL, &size, &device); size = sizeof(channels); - err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels); + err = AudioObjectGetPropertyData(device, &ChannelAddr, 0, NULL, &size, &channels); size = sizeof(vol); - if (!err) - err = AudioDeviceSetProperty(device, 0, channels[0], false, kAudioDevicePropertyVolumeScalar, size, &volumeL); - if (!err) - err = AudioDeviceSetProperty(device, 0, channels[1], false, kAudioDevicePropertyVolumeScalar, size, &volumeR); + if (!err) { + VolumeAddr.mElement = channels[0]; + err = AudioObjectSetPropertyData(device, &VolumeAddr, 0, NULL, size, &volumeL); + } + if (!err) { + VolumeAddr.mElement = channels[1]; + err = AudioObjectSetPropertyData(device, &VolumeAddr, 0, NULL, size, &volumeR); + } if (err) { #endif @@ -692,9 +712,33 @@ int main(int argc, char *argv[]) exit(1); } #else - fprintf(stderr, "Mac OS X detected. Use 'launchd -d muted -f' to launch.\n"); + const char *found = NULL, *paths[] = { + "/Library/LaunchAgents/org.asterisk.muted.plist", + "/Library/LaunchDaemons/org.asterisk.muted.plist", + "contrib/init.d/org.asterisk.muted.plist", + "/contrib/init.d/org.asterisk.muted.plist" }; + char userpath[256]; + struct stat unused; + struct passwd *pwd = getpwuid(getuid()); + int i; + + snprintf(userpath, sizeof(userpath), "%s%s", pwd->pw_dir, paths[0]); + if (!stat(userpath, &unused)) { + found = userpath; + } + + if (!found) { + for (i = 0; i < 3; i++) { + if (!stat(paths[i], &unused)) { + found = paths[i]; + break; + } + } + } + + fprintf(stderr, "Mac OS X detected. Use 'launchctl load -w %s' to launch.\n", found ? found : paths[3]); exit(1); -#endif +#endif /* !defined(HAVE_SBIN_LAUNCHD */ } #endif for(;;) {