Fix merge error

Formatting
This commit is contained in:
Flamefire committed 2014-02-25 21:04:44 +01:00
1 parent d4dc4f7c20
commit 2458e1834a
2 files changed
+18 -87

No files matched your search

+1 -2
View File
@@ -1,5 +1,4 @@
using System; using System;
using System.Net.Sockets;
using System.ServiceModel; using System.ServiceModel;
using System.ServiceModel.Web; using System.ServiceModel.Web;
using System.Diagnostics; using System.Diagnostics;
@@ -97,7 +96,7 @@ namespace ServerLib
#region server control #region server control
private void _Init(int port, bool encrypted) private void _Init(int port, bool encrypted)
{ {
string hostname = GetLocalAddress(); string hostname = Dns.GetHostName();
string protocol = (encrypted) ? "https" : "http"; string protocol = (encrypted) ? "https" : "http";
_BaseAddress = new Uri(protocol + "://" + hostname + ":" + port + "/"); _BaseAddress = new Uri(protocol + "://" + hostname + ":" + port + "/");
_Encrypted = encrypted; _Encrypted = encrypted;
+17 -85
View File
@@ -15,42 +15,33 @@ namespace ServerLib
string sessionHeader = string sessionHeader =
((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"]; ((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"];
if (string.IsNullOrEmpty(sessionHeader)) if (string.IsNullOrEmpty(sessionHeader))
{
return sessionKey; return sessionKey;
}
try try
{ {
sessionKey = Guid.Parse(sessionHeader); sessionKey = Guid.Parse(sessionHeader);
} }
catch (Exception e) catch (Exception) {}
{
}
return sessionKey; return sessionKey;
} }
public void SendKeyEvent(string key) public void SendKeyEvent(string key)
{ {
if (!_CheckRight(EUserRights.UseKeyboard)) if (!_CheckRight(EUserRights.UseKeyboard))
{
return; return;
}
if (CServer.SendKeyEvent == null) if (CServer.SendKeyEvent == null)
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found"; WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
} }
} }
else else
{
CServer.SendKeyEvent(key); CServer.SendKeyEvent(key);
}
} }
#region profile #region profile
public int GetOwnProfileId() public int GetOwnProfileId()
{ {
Guid sessionKey = _GetSession(); Guid sessionKey = _GetSession();
@@ -58,7 +49,7 @@ namespace ServerLib
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session"; WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
} }
return -1; return -1;
@@ -68,7 +59,7 @@ namespace ServerLib
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session"; WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
} }
return -1; return -1;
@@ -82,18 +73,16 @@ namespace ServerLib
if (profile.ProfileId != -1) //-1 is the id for a new profile if (profile.ProfileId != -1) //-1 is the id for a new profile
{ {
if (CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId if (CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId
&& !(_CheckRight(EUserRights.EditAllProfiles) )) && !(_CheckRight(EUserRights.EditAllProfiles)))
{
return; return;
}
} }
if (CServer.SendProfileData == null) if (CServer.SendProfileData == null)
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found"; WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
} }
return; return;
@@ -108,9 +97,7 @@ namespace ServerLib
if (_CheckRight(EUserRights.ViewOtherProfiles) || CSessionControl.GetUserIdFromSession(sessionKey) == profileId) if (_CheckRight(EUserRights.ViewOtherProfiles) || CSessionControl.GetUserIdFromSession(sessionKey) == profileId)
{ {
if (CServer.GetProfileData == null) if (CServer.GetProfileData == null)
{
return new SProfileData(); return new SProfileData();
}
bool isReadonly = (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) && bool isReadonly = (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
CSessionControl.GetUserIdFromSession(sessionKey) != profileId); CSessionControl.GetUserIdFromSession(sessionKey) != profileId);
@@ -118,36 +105,26 @@ namespace ServerLib
return CServer.GetProfileData(profileId, isReadonly); return CServer.GetProfileData(profileId, isReadonly);
} }
else else
{
return new SProfileData(); return new SProfileData();
}
} }
public SProfileData[] GetProfileList() public SProfileData[] GetProfileList()
{ {
if (CServer.GetProfileList == null) if (CServer.GetProfileList == null)
{ return new SProfileData[] {};
return new SProfileData[] { };
}
return CServer.GetProfileList(); return CServer.GetProfileList();
} }
#endregion #endregion
#region photo #region photo
public void SendPhoto(SPhotoData photo) public void SendPhoto(SPhotoData photo)
{ {
if (_CheckRight(EUserRights.UploadPhotos)) if (_CheckRight(EUserRights.UploadPhotos))
{
CServer.SendPhoto(photo); CServer.SendPhoto(photo);
}
} }
#endregion #endregion
#region website #region website
public Guid Login(string username, string password) public Guid Login(string username, string password)
{ {
Guid sessionId = CSessionControl.OpenSession(username, password); Guid sessionId = CSessionControl.OpenSession(username, password);
@@ -155,7 +132,7 @@ namespace ServerLib
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Wrong username or password"; WebOperationContext.Current.OutgoingResponse.StatusDescription = "Wrong username or password";
} }
} }
@@ -165,9 +142,7 @@ namespace ServerLib
public Stream Index() public Stream Index()
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html"; WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
}
return new MemoryStream(CServer.GetSiteFile("index.html")); return new MemoryStream(CServer.GetSiteFile("index.html"));
} }
@@ -186,14 +161,10 @@ namespace ServerLib
byte[] data = CServer.GetSiteFile("js/" + filename); byte[] data = CServer.GetSiteFile("js/" + filename);
if (data != null) if (data != null)
{
return new MemoryStream(data); return new MemoryStream(data);
}
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
}
return null; return null;
} }
@@ -211,13 +182,9 @@ namespace ServerLib
byte[] data = CServer.GetSiteFile("css/" + filename); byte[] data = CServer.GetSiteFile("css/" + filename);
if (data != null) if (data != null)
{
return new MemoryStream(data); return new MemoryStream(data);
}
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
}
return null; return null;
} }
@@ -235,13 +202,9 @@ namespace ServerLib
byte[] data = CServer.GetSiteFile("css\\images\\" + filename); byte[] data = CServer.GetSiteFile("css\\images\\" + filename);
if (data != null) if (data != null)
{
return new MemoryStream(data); return new MemoryStream(data);
}
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
}
return null; return null;
} }
@@ -259,13 +222,9 @@ namespace ServerLib
byte[] data = CServer.GetSiteFile("img/" + filename); byte[] data = CServer.GetSiteFile("img/" + filename);
if (data != null) if (data != null)
{
return new MemoryStream(data); return new MemoryStream(data);
}
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
}
return null; return null;
} }
@@ -283,14 +242,10 @@ namespace ServerLib
byte[] data = CServer.GetSiteFile("locales/" + filename); byte[] data = CServer.GetSiteFile("locales/" + filename);
if (data != null) if (data != null)
{
return new MemoryStream(data); return new MemoryStream(data);
}
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
}
return null; return null;
} }
@@ -303,11 +258,9 @@ namespace ServerLib
{ {
return true; return true;
} }
#endregion #endregion
#region songs #region songs
public SSongInfo GetSong(int songId) public SSongInfo GetSong(int songId)
{ {
return CServer.GetSong(songId); return CServer.GetSong(songId);
@@ -325,7 +278,6 @@ namespace ServerLib
#endregion #endregion
#region playlist #region playlist
public SPlaylistInfo[] GetPlaylists() public SPlaylistInfo[] GetPlaylists()
{ {
return CServer.GetPlaylists(); return CServer.GetPlaylists();
@@ -339,25 +291,19 @@ namespace ServerLib
public void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates) public void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
{ {
if (_CheckRight(EUserRights.AddSongToPlaylist)) if (_CheckRight(EUserRights.AddSongToPlaylist))
{
CServer.AddSongToPlaylist(songId, playlistId, allowDuplicates); CServer.AddSongToPlaylist(songId, playlistId, allowDuplicates);
}
} }
public void RemoveSongFromPlaylist(int position, int playlistId, int songId) public void RemoveSongFromPlaylist(int position, int playlistId, int songId)
{ {
if (_CheckRight(EUserRights.RemoveSongsFromPlaylists)) if (_CheckRight(EUserRights.RemoveSongsFromPlaylists))
{
CServer.RemoveSongFromPlaylist(position, playlistId, songId); CServer.RemoveSongFromPlaylist(position, playlistId, songId);
}
} }
public void MoveSongInPlaylist(int newPosition, int playlistId, int songId) public void MoveSongInPlaylist(int newPosition, int playlistId, int songId)
{ {
if (_CheckRight(EUserRights.ReorderPlaylists)) if (_CheckRight(EUserRights.ReorderPlaylists))
{
CServer.MoveSongInPlaylist(newPosition, playlistId, songId); CServer.MoveSongInPlaylist(newPosition, playlistId, songId);
}
} }
public bool PlaylistContainsSong(int songId, int playlistId) public bool PlaylistContainsSong(int songId, int playlistId)
@@ -373,24 +319,18 @@ namespace ServerLib
public void RemovePlaylist(int playlistId) public void RemovePlaylist(int playlistId)
{ {
if (_CheckRight(EUserRights.DeletePlaylists)) if (_CheckRight(EUserRights.DeletePlaylists))
{
CServer.RemovePlaylist(playlistId); CServer.RemovePlaylist(playlistId);
}
} }
public int AddPlaylist(string playlistName) public int AddPlaylist(string playlistName)
{ {
if (_CheckRight(EUserRights.CreatePlaylists)) if (_CheckRight(EUserRights.CreatePlaylists))
{
return CServer.AddPlaylist(playlistName); return CServer.AddPlaylist(playlistName);
}
return -1; return -1;
} }
#endregion #endregion
#region user management #region user management
public int GetUserRole(int profileId) public int GetUserRole(int profileId)
{ {
return CServer.GetUserRole(profileId); return CServer.GetUserRole(profileId);
@@ -399,11 +339,9 @@ namespace ServerLib
public void SetUserRole(int profileId, int userRole) public void SetUserRole(int profileId, int userRole)
{ {
if (_CheckRight(EUserRights.EditAllProfiles)) if (_CheckRight(EUserRights.EditAllProfiles))
{
CServer.SetUserRole(profileId, userRole); CServer.SetUserRole(profileId, userRole);
}
} }
public bool HasUserRight(int right) public bool HasUserRight(int right)
{ {
return _CheckRightWithNoErrorMessage((EUserRights)right); return _CheckRightWithNoErrorMessage((EUserRights)right);
@@ -417,7 +355,7 @@ namespace ServerLib
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session"; WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
} }
return false; return false;
@@ -427,7 +365,7 @@ namespace ServerLib
{ {
if (WebOperationContext.Current != null) if (WebOperationContext.Current != null)
{ {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden; WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed"; WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
} }
return false; return false;
@@ -440,19 +378,13 @@ namespace ServerLib
Guid sessionKey = _GetSession(); Guid sessionKey = _GetSession();
if (sessionKey == Guid.Empty) if (sessionKey == Guid.Empty)
{
return false; return false;
}
if (!CSessionControl.RequestRight(sessionKey, requestedRight)) if (!CSessionControl.RequestRight(sessionKey, requestedRight))
{
return false; return false;
}
return true; return true;
} }
#endregion #endregion
} }
} }