2006-05-24 James Willcox <snorp@snorp.net>

* src/Server.cs: add a SongRequested event to Server, so apps
        can do logging or whatever when a song is requested.


svn path=/trunk/daap-sharp/; revision=61067
This commit is contained in:
James Willcox 2006-05-24 15:53:29 +00:00
Родитель 119f5602d7
Коммит 3a9c8a71da
2 изменённых файлов: 49 добавлений и 3 удалений

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

@ -1,3 +1,8 @@
2006-05-24 James Willcox <snorp@snorp.net>
* src/Server.cs: add a SongRequested event to Server, so apps
can do logging or whatever when a song is requested.
2006-05-07 James Willcox <snorp@snorp.net>
* src/ServiceLocator.cs: make sure we properly dispose of the

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

@ -36,7 +36,7 @@ using Avahi;
namespace DAAP {
internal delegate bool WebHandler (Socket client, string path, NameValueCollection query, int range);
internal delegate bool WebHandler (Socket client, string user, string path, NameValueCollection query, int range);
internal class WebServer {
@ -294,7 +294,7 @@ namespace DAAP {
return true;
}
return handler (client, uri.AbsolutePath, query, range);
return handler (client, user, uri.AbsolutePath, query, range);
} catch (IOException e) {
ret = false;
} catch (Exception e) {
@ -396,6 +396,39 @@ namespace DAAP {
}
}
public class SongRequestedArgs : EventArgs {
private string user;
private IPAddress host;
private Database db;
private Song song;
public string UserName {
get { return user; }
}
public IPAddress Host {
get { return host; }
}
public Database Database {
get { return db; }
}
public Song Song {
get { return song; }
}
public SongRequestedArgs (string user, IPAddress host, Database db, Song song) {
this.user = user;
this.host = host;
this.db = db;
this.song = song;
}
}
public delegate void SongRequestedHandler (object o, SongRequestedArgs args);
public class Server {
internal const int DefaultTimeout = 1800;
@ -426,6 +459,7 @@ namespace DAAP {
private RevisionManager revmgr = new RevisionManager ();
public event EventHandler Collision;
public event SongRequestedHandler SongRequested;
public string Name {
get { return serverInfo.Name; }
@ -634,7 +668,7 @@ namespace DAAP {
}
#endif
internal bool OnHandleRequest (Socket client, string path, NameValueCollection query, int range) {
internal bool OnHandleRequest (Socket client, string user, string path, NameValueCollection query, int range) {
int session = 0;
if (query["session-id"] != null) {
@ -720,6 +754,13 @@ namespace DAAP {
}
try {
try {
if (SongRequested != null)
SongRequested (this, new SongRequestedArgs (user,
(client.RemoteEndPoint as IPEndPoint).Address,
db, song));
} catch {}
if (song.FileName != null) {
ws.WriteResponseFile (client, song.FileName, range);
} else if (db.Client != null) {