2007-08-27 Aaron Bockover <abockover@novell.com>

* autogen.sh: A fresh, hip, autogen

    * src/ServiceLocator.cs:
    * src/Server.cs: Removed old Mono.Zeroconf and Avahi support, replaced
    with new Mono.Zeroconf support (which is a frontend to either
    mDNSResponder or Avahi support, abstracted from applications or other
    libraries)

    * src/Client.cs:
    * src/Database.cs: Fix some compiler warnings
    
    * configure.ac: Require Mono.Zeroconf instead of either Avahi or
    mDNSResponder; check for TagLib#; bump version to 0.4.0

    * sample/SampleServer.cs: Use TagLib instead of Entagged to build the
    sample server

    * sample/Makefile.am: Fixed up to link against TagLib


svn path=/trunk/daap-sharp/; revision=84929
This commit is contained in:
Aaron Bockover 2007-08-28 03:25:36 +00:00
Родитель c992a583e0
Коммит f406fc8f9d
10 изменённых файлов: 117 добавлений и 335 удалений

Просмотреть файл

@ -1,3 +1,24 @@
2007-08-27 Aaron Bockover <abockover@novell.com>
* autogen.sh: A fresh, hip, autogen
* src/ServiceLocator.cs:
* src/Server.cs: Removed old Mono.Zeroconf and Avahi support, replaced
with new Mono.Zeroconf support (which is a frontend to either
mDNSResponder or Avahi support, abstracted from applications or other
libraries)
* src/Client.cs:
* src/Database.cs: Fix some compiler warnings
* configure.ac: Require Mono.Zeroconf instead of either Avahi or
mDNSResponder; check for TagLib#; bump version to 0.4.0
* sample/SampleServer.cs: Use TagLib instead of Entagged to build the
sample server
* sample/Makefile.am: Fixed up to link against TagLib
2007-01-29 James Willcox <snorp@snorp.net>
* src/Database.cs: fix a regression caused by s/Song/Track/ a while

Просмотреть файл

@ -1,85 +1,62 @@
#! /bin/sh
#!/bin/bash
# Ok, simple script to do this.
PROJECT=daap-sharp
: ${AUTOCONF=autoconf}
: ${AUTOHEADER=autoheader}
: ${AUTOMAKE=automake}
: ${LIBTOOLIZE=libtoolize}
: ${ACLOCAL=aclocal}
: ${LIBTOOL=libtool}
function error () {
echo "Error: $1" 1>&2
exit 1
}
srcdir=`dirname $0`
function check_autotool_version () {
which $1 &>/dev/null || {
error "$1 is not installed, and is required to configure $PACKAGE"
}
version=$($1 --version | head -n 1 | cut -f4 -d' ')
major=$(echo $version | cut -f1 -d.)
minor=$(echo $version | cut -f2 -d.)
major_check=$(echo $2 | cut -f1 -d.)
minor_check=$(echo $2 | cut -f2 -d.)
if [ $major -lt $major_check ]; then
do_bail=yes
elif [[ $minor -lt $minor_check && $major = $major_check ]]; then
do_bail=yes
fi
if [ x"$do_bail" = x"yes" ]; then
error "$1 version $2 or better is required to configure $PROJECT"
fi
}
function run () {
echo "Running $@ ..."
$@ 2>.autogen.log || {
cat .autogen.log 1>&2
rm .autogen.log
error "Could not run $1, which is required to configure $PROJECT"
}
rm .autogen.log
}
srcdir=$(dirname $0)
test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd $srcdir
PROJECT=daap-sharp
TEST_TYPE=-f
FILE=src/Client.cs
CONFIGURE=configure.ac
aclocalinclude="-I . $ACLOCAL_FLAGS"
DIE=0
($AUTOCONF --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $PROJECT."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
(test -f $srcdir/configure.ac) || {
error "Directory \"$srcdir\" does not look like the top-level $PROJECT directory"
}
($AUTOMAKE --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have automake installed to compile $PROJECT."
echo "Get ftp://sourceware.cygnus.com/pub/automake/automake-1.4.tar.gz"
echo "(or a newer version if it is available)"
DIE=1
}
check_autotool_version aclocal 1.9
check_autotool_version automake 1.9
check_autotool_version autoconf 2.13
(grep "^AM_PROG_LIBTOOL" configure.ac >/dev/null) && {
($LIBTOOL --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`libtool' installed to compile $PROJECT."
echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.2d.tar.gz"
echo "(or a newer version if it is available)"
DIE=1
}
}
run aclocal -I .
run autoconf
run automake -a --gnu
if test "$DIE" -eq 1; then
exit 1
fi
test $TEST_TYPE $FILE || {
echo "You must run this script in the top-level $PROJECT directory"
exit 1
}
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
if [ $# = 0 ]; then
echo "WARNING: I am going to run configure without any arguments."
fi
case $CC in
*xlc | *xlc\ * | *lcc | *lcc\ *) am_opt=--include-deps;;
esac
(grep "^AM_PROG_LIBTOOL" configure.ac >/dev/null) && {
echo "Running $LIBTOOLIZE ..."
$LIBTOOLIZE --force --copy
}
echo "Running $ACLOCAL $aclocalinclude ..."
$ACLOCAL $aclocalinclude
echo "Running $AUTOMAKE --gnu $am_opt ..."
$AUTOMAKE --add-missing --gnu $am_opt
echo "Running $AUTOCONF ..."
$AUTOCONF
echo Running $srcdir/configure $conf_flags "$@" ...
$srcdir/configure --enable-maintainer-mode $conf_flags "$@" \
run ./configure --enable-maintainer-mode $@

Просмотреть файл

@ -2,8 +2,8 @@ AC_INIT(README)
AC_CANONICAL_SYSTEM
MAJOR_VERSION=0
MINOR_VERSION=3
MICRO_VERSION=5
MINOR_VERSION=4
MICRO_VERSION=0
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
AM_INIT_AUTOMAKE(daap-sharp, $VERSION)
@ -24,17 +24,9 @@ if test "x$PKG_CONFIG" = "xno"; then
AC_MSG_ERROR([You need to install pkg-config])
fi
AC_ARG_ENABLE(mdnsd, AC_HELP_STRING([--enable-mdnsd], [Use mDNSResponder instead of Avahi]), enable_mdnsd="yes", enable_mdnsd="no")
AM_CONDITIONAL(ENABLE_MDNSD, test "x$enable_mdnsd" = "xyes")
if test "x$enable_mdnsd" = "xyes"; then
MCS_FLAGS="-define:ENABLE_MDNSD"
AC_SUBST(MCS_FLAGS)
else
PKG_CHECK_MODULES(AVAHI, avahi-sharp >= 0.6.11)
MCS_FLAGS=$AVAHI_LIBS
AC_SUBST(MCS_FLAGS)
fi
PKG_CHECK_MODULES(MZC, mono-zeroconf >= 0.7.1)
MCS_FLAGS=$MZC_LIBS
AC_SUBST(MCS_FLAGS)
dnl Mono
AC_PATH_PROG(MONO, mono)
@ -48,10 +40,10 @@ if test "x$MCS" = "x" ; then
AC_MSG_ERROR([Can not find "gmcs" in your PATH])
fi
PKG_CHECK_MODULES(ENTAGGED, entagged-sharp, have_entagged=yes, have_entagged=no)
PKG_CHECK_MODULES(TAGLIB, taglib-sharp >= 2.0.2, have_taglib=yes, have_taglib=no)
PKG_CHECK_MODULES(MONODOC, monodoc >= 1.1.9, have_monodoc=yes, have_monodoc=no)
AM_CONDITIONAL(HAVE_ENTAGGED, test "x$have_entagged" = "xyes")
AM_CONDITIONAL(HAVE_TAGLIB, test "x$have_taglib" = "xyes")
if test "x$have_monodoc" = "xyes"; then
AC_PATH_PROG(MONODOCER, monodocer)
@ -76,13 +68,9 @@ src/daap-sharp.dll.config
sample/Makefile
])
zeroconf_lib="Avahi"
if test "x$enable_mdnsd" = "xyes"; then
zeroconf_lib="mDNSResponder"
fi
echo "
Installation Prefix: $prefix
C# Compiler: $MCS
echo
echo "daap-sharp prefix: $prefix"
echo "build documentation: $have_monodoc"
echo "Zeroconf Client: $zeroconf_lib"
echo
Developer Documentation: $have_monodoc
"

Просмотреть файл

@ -8,18 +8,15 @@ SERVERSOURCES = $(srcdir)/SampleServer.cs
MIRRORSOURCES = $(srcdir)/Mirror.cs
UPDATETESTSOURCES = $(srcdir)/UpdateTest.cs
if HAVE_ENTAGGED
if HAVE_TAGLIB
ASSEMBLIES += server.exe
endif
client.exe: $(CLIENTSOURCES) $(top_builddir)/src/daap-sharp.dll
$(MCS) -debug -out:$@ $(CLIENTSOURCES) -r:$(top_builddir)/src/daap-sharp.dll
entagged-sharp.dll:
cp `pkg-config --variable=Libraries entagged-sharp` .
server.exe: $(SERVERSOURCES) $(top_builddir)/src/daap-sharp.dll entagged-sharp.dll
$(MCS) -debug -out:$@ $(SERVERSOURCES) -r:$(top_builddir)/src/daap-sharp.dll -r:entagged-sharp.dll
server.exe: $(SERVERSOURCES) $(top_builddir)/src/daap-sharp.dll
$(MCS) -debug -out:$@ $(TAGLIB_LIBS) $(SERVERSOURCES) -r:$(top_builddir)/src/daap-sharp.dll
mirror.exe: $(MIRRORSOURCES) $(top_builddir)/src/daap-sharp.dll
$(MCS) -debug -out:$@ $(MIRRORSOURCES) -r:$(top_builddir)/src/daap-sharp.dll

Просмотреть файл

@ -21,7 +21,7 @@ using System;
using System.Net;
using System.IO;
using DAAP;
using Entagged;
using TagLib;
public class SampleServer
{
@ -89,24 +89,24 @@ public class SampleServer
private static void AddDirectory (Database db, string dir) {
Console.WriteLine ("Adding files in: " + dir);
foreach (string file in Directory.GetFiles (dir)) {
AudioFile afw = null;
TagLib.File afw = null;
try {
afw = new AudioFile (file);
} catch (Exception e) {
afw = TagLib.File.Create(file);
} catch (Exception) {
continue;
}
Track track = new Track ();
track.Artist = afw.Artist;
track.Album = afw.Album;
track.Title = afw.Title;
track.Year = afw.Year;
track.Artist = afw.Tag.FirstAlbumArtist;
track.Album = afw.Tag.Album;
track.Title = afw.Tag.Title;
track.Year = (int)afw.Tag.Year;
track.Format = Path.GetExtension (file).Substring (1);
track.Duration = afw.Duration;
track.Genre = afw.Genre;
track.TrackNumber = afw.TrackNumber;
track.TrackCount = afw.TrackCount;
track.Duration = afw.Properties.Duration;
track.Genre = afw.Tag.JoinedGenres;
track.TrackNumber = (int)afw.Tag.Track;
track.TrackCount = (int)afw.Tag.TrackCount;
track.DateAdded = DateTime.Now;
track.DateModified = DateTime.Now;
track.FileName = file;

Просмотреть файл

@ -79,7 +79,7 @@ namespace DAAP {
public Client (Service service) : this (service.Address, service.Port) {
}
public Client (string host, UInt16 port) : this (Dns.Resolve (host).AddressList[0], port) {
public Client (string host, UInt16 port) : this (Dns.GetHostEntry (host).AddressList[0], port) {
}
public Client (IPAddress address, UInt16 port) {
@ -151,7 +151,7 @@ namespace DAAP {
updateRunning = false;
fetcher.KillAll ();
fetcher.Fetch ("/logout");
} catch (WebException e) {
} catch (WebException) {
// some servers don't implement this, etc.
}
@ -214,7 +214,7 @@ namespace DAAP {
break;
Refresh ();
} catch (WebException e) {
} catch (WebException) {
if (!updateRunning)
break;

Просмотреть файл

@ -266,7 +266,7 @@ namespace DAAP {
try {
playlistsData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers", id, revquery));
} catch (WebException e) {
} catch (WebException) {
return;
}

Просмотреть файл

@ -23,8 +23,7 @@ DAAPSOURCES = \
$(srcdir)/ServiceLocator.cs \
$(srcdir)/Track.cs \
$(srcdir)/User.cs \
$(srcdir)/Utility.cs \
$(srcdir)/Mono.Zeroconf/*.cs
$(srcdir)/Utility.cs
if HAVE_MONODOC
docdir = $(MONODOC_DIR)

Просмотреть файл

@ -30,11 +30,7 @@ using System.Net;
using System.Net.Sockets;
using System.Web;
#if ENABLE_MDNSD
using Mono.Zeroconf;
#else
using Avahi;
#endif
namespace DAAP {
@ -297,7 +293,7 @@ namespace DAAP {
}
return handler (client, user, uri.AbsolutePath, query, range);
} catch (IOException e) {
} catch (IOException) {
ret = false;
} catch (Exception e) {
ret = false;
@ -314,7 +310,7 @@ namespace DAAP {
try {
while (HandleRequest (client)) { }
} catch (IOException e) {
} catch (IOException) {
// ignore
} catch (Exception e) {
Console.Error.WriteLine ("Error handling request: " + e);
@ -333,7 +329,7 @@ namespace DAAP {
Socket client = server.Accept ();
clients.Add (client);
ThreadPool.QueueUserWorkItem (HandleConnection, client);
} catch (SocketException e) {
} catch (SocketException) {
break;
}
}
@ -451,12 +447,7 @@ namespace DAAP {
private bool running;
private string machineId;
#if !ENABLE_MDNSD
private Avahi.Client client;
private EntryGroup eg;
#else
private RegisterService zc_service;
#endif
private object eglock = new object ();
private RevisionManager revmgr = new RevisionManager ();
@ -541,11 +532,6 @@ namespace DAAP {
running = true;
ws.Start ();
#if !ENABLE_MDNSD
client = new Avahi.Client ();
client.StateChanged += OnClientStateChanged;
#endif
if (publish)
RegisterService ();
}
@ -560,13 +546,6 @@ namespace DAAP {
lock (revmgr) {
Monitor.PulseAll (revmgr);
}
#if !ENABLE_MDNSD
if (client != null) {
client.Dispose ();
client = null;
}
#endif
}
public void AddDatabase (Database db) {
@ -597,7 +576,6 @@ namespace DAAP {
}
}
#if ENABLE_MDNSD
private void RegisterService () {
lock (eglock) {
if (zc_service != null) {
@ -606,7 +584,9 @@ namespace DAAP {
string auth = serverInfo.AuthenticationMethod == AuthenticationMethod.None ? "false" : "true";
zc_service = new RegisterService (serverInfo.Name, null, "_daap._tcp");
zc_service = new RegisterService ();
zc_service.Name = serverInfo.Name;
zc_service.RegType = "_daap._tcp";
zc_service.Port = (short)ws.BoundPort;
zc_service.TxtRecord = new TxtRecord ();
zc_service.TxtRecord.Add ("Password", auth);
@ -618,8 +598,7 @@ namespace DAAP {
zc_service.TxtRecord.Add ("txtvers", "1");
zc_service.Response += OnRegisterServiceResponse;
zc_service.AutoRename = false;
zc_service.RegisterAsync ();
zc_service.Register ();
}
}
@ -638,69 +617,10 @@ namespace DAAP {
}
private void OnRegisterServiceResponse (object o, RegisterServiceEventArgs args) {
if (args.NameConflict && Collision != null) {
if (args.ServiceError == ServiceErrorCode.AlreadyRegistered && Collision != null) {
Collision (this, new EventArgs ());
}
}
#else
private void OnClientStateChanged (object o, ClientStateArgs args) {
if (publish && args.State == ClientState.Running) {
RegisterService ();
}
}
private void RegisterService () {
lock (eglock) {
if (eg != null) {
eg.Reset ();
} else {
eg = new EntryGroup (client);
eg.StateChanged += OnEntryGroupStateChanged;
}
try {
string auth = serverInfo.AuthenticationMethod == AuthenticationMethod.None ? "false" : "true";
List<string> txtdata = new List<string> ();
txtdata.Add ("Password=" + auth);
txtdata.Add ("Machine Name=" + serverInfo.Name);
if (machineId != null) {
txtdata.Add ("Machine ID=" + machineId);
}
txtdata.Add ("txtvers=1");
eg.AddService (serverInfo.Name, "_daap._tcp", "", ws.BoundPort, txtdata.ToArray ());
eg.Commit ();
} catch (ClientException e) {
if (e.ErrorCode == ErrorCode.Collision && Collision != null) {
Collision (this, new EventArgs ());
} else {
throw e;
}
}
}
}
private void UnregisterService () {
lock (eglock) {
if (eg == null)
return;
eg.Reset ();
eg.Dispose ();
eg = null;
}
}
private void OnEntryGroupStateChanged (object o, EntryGroupStateArgs args) {
if (args.State == EntryGroupState.Collision && Collision != null) {
Collision (this, new EventArgs ());
}
}
#endif
private void ExpireSessions () {
lock (sessions) {
@ -857,7 +777,7 @@ namespace DAAP {
try {
ws.WriteResponseStream (client, trackStream, trackLength);
} catch (IOException e) {
} catch (IOException) {
}
} else {
ws.WriteResponse (client, HttpStatusCode.InternalServerError, "no file");

Просмотреть файл

@ -22,11 +22,7 @@ using System.Net;
using System.Text;
using System.Collections;
#if ENABLE_MDNSD
using Mono.Zeroconf;
#else
using Avahi;
#endif
namespace DAAP {
@ -86,8 +82,6 @@ namespace DAAP {
}
}
#if ENABLE_MDNSD
public class ServiceLocator {
private ServiceBrowser browser;
@ -111,10 +105,10 @@ namespace DAAP {
Stop ();
}
browser = new ServiceBrowser ("_daap._tcp");
browser = new ServiceBrowser ();
browser.ServiceAdded += OnServiceAdded;
browser.ServiceRemoved += OnServiceRemoved;
browser.StartAsync ();
browser.Browse ("_daap._tcp", "local");
}
public void Stop () {
@ -128,9 +122,9 @@ namespace DAAP {
args.Service.Resolve ();
}
private void OnServiceResolved (object o, EventArgs args) {
BrowseService zc_service = o as BrowseService;
private void OnServiceResolved (object o, ServiceResolvedEventArgs args) {
IResolvableService zc_service = args.Service;
string name = zc_service.Name;
string machineId = null;
@ -175,118 +169,4 @@ namespace DAAP {
}
}
}
#else
public class ServiceLocator {
private Avahi.Client client;
private ServiceBrowser browser;
private Hashtable services = new Hashtable ();
private ArrayList resolvers = new ArrayList ();
private bool showLocals = false;
public event ServiceHandler Found;
public event ServiceHandler Removed;
public bool ShowLocalServices {
get { return showLocals; }
set { showLocals = value; }
}
public IEnumerable Services {
get { return services; }
}
public ServiceLocator () {
}
public void Start () {
if (client == null) {
client = new Avahi.Client ();
browser = new ServiceBrowser (client, "_daap._tcp");
browser.ServiceAdded += OnServiceAdded;
browser.ServiceRemoved += OnServiceRemoved;
}
}
public void Stop () {
if (client != null) {
services.Clear ();
browser.Dispose ();
client.Dispose ();
client = null;
browser = null;
}
}
private void OnServiceAdded (object o, ServiceInfoArgs args) {
if ((args.Service.Flags & LookupResultFlags.Local) > 0 && !showLocals)
return;
ServiceResolver resolver = new ServiceResolver (client, args.Service);
resolvers.Add (resolver);
resolver.Found += OnServiceResolved;
resolver.Timeout += OnServiceTimeout;
}
private void OnServiceResolved (object o, ServiceInfoArgs args) {
resolvers.Remove (o);
(o as ServiceResolver).Dispose ();
string name = args.Service.Name;
string machineId = null;
if (services[args.Service.Name] != null) {
return; // we already have it somehow
}
bool pwRequired = false;
// iTunes tacks this on to indicate a passsword protected share. Ugh.
if (name.EndsWith ("_PW")) {
name = name.Substring (0, name.Length - 3);
pwRequired = true;
}
foreach (byte[] txt in args.Service.Text) {
string txtstr = Encoding.UTF8.GetString (txt);
string[] splitstr = txtstr.Split('=');
if (splitstr.Length < 2)
continue;
if (splitstr[0].ToLower () == "password") {
pwRequired = splitstr[1].ToLower () == "true";
} else if (splitstr[0].ToLower () == "machine name") {
name = splitstr[1];
} else if (splitstr[0].ToLower () == "machine id") {
machineId = splitstr[1];
}
}
Service svc = new Service (args.Service.Address, args.Service.Port,
name, pwRequired, machineId);
services[svc.Name] = svc;
if (Found != null)
Found (this, new ServiceArgs (svc));
}
private void OnServiceTimeout (object o, EventArgs args) {
Console.Error.WriteLine ("Failed to resolve");
}
private void OnServiceRemoved (object o, ServiceInfoArgs args) {
Service svc = (Service) services[args.Service.Name];
if (svc != null) {
services.Remove (svc.Name);
if (Removed != null)
Removed (this, new ServiceArgs (svc));
}
}
}
#endif
}