From 6fd2df43f2be805a344de2b57d0630b69dde98a9 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Sat, 18 Sep 2010 21:32:42 +0000 Subject: [PATCH] URLs processing refactored --- Builder/IISMainHandler/build.txt | 2 +- Common/Common.csproj | 43 ++ Common/URL/AbstractUrl.cs | 44 +++ Common/URL/QuickLink.cs | 28 ++ Common/URL/Robots.cs | 24 ++ Common/URL/Static.cs | 24 ++ Common/URL/UrlManager.cs | 327 ++++++++++++++++ Common/URL/forum/AllPosts.cs | 25 ++ Common/URL/forum/AllThreads.cs | 25 ++ Common/URL/forum/Boards.cs | 24 ++ Common/URL/forum/board/Headlines.cs | 28 ++ Common/URL/forum/board/NewThread.cs | 28 ++ Common/URL/forum/board/Threads.cs | 28 ++ Common/URL/forum/board/thread/Posts.cs | 28 ++ Common/URL/forum/board/thread/post/Edit.cs | 30 ++ Common/URL/forum/board/thread/post/PMReply.cs | 30 ++ Common/URL/forum/board/thread/post/Punish.cs | 30 ++ Common/URL/forum/board/thread/post/Reply.cs | 30 ++ Common/URL/forum/board/thread/post/Show.cs | 30 ++ Common/URL/maintenance/CleanCache.cs | 25 ++ Common/URL/maintenance/LocalNetworks.cs | 24 ++ Common/URL/my/Avatars.cs | 24 ++ Common/URL/my/Settings.cs | 24 ++ Common/URL/my/UserData.cs | 24 ++ Common/URL/my/conversations/Conversation.cs | 28 ++ Common/URL/my/conversations/List.cs | 24 ++ Common/URL/my/conversations/NewPM.cs | 24 ++ Common/URL/my/conversations/Reply.cs | 28 ++ Common/URL/my/login/Login.cs | 24 ++ Common/URL/my/login/Migrate.cs | 24 ++ Common/URL/my/login/RegisterByInvite.cs | 24 ++ Common/URL/polls/Info.cs | 28 ++ Common/URL/polls/NewPoll.cs | 24 ++ Common/URL/upload/Item.cs | 49 +++ Common/URL/upload/List.cs | 24 ++ Common/URL/upload/New.cs | 24 ++ Common/URL/users/Active.cs | 25 ++ Common/URL/users/All.cs | 25 ++ Common/URL/users/Online.cs | 25 ++ Common/URL/users/user/Abstract.cs | 28 ++ Common/URL/users/user/Info.cs | 18 + Common/URL/users/user/PollsParticipated.cs | 18 + Common/URL/users/user/Posts.cs | 18 + Common/URL/users/user/Replies.cs | 18 + Common/URL/users/user/Threads.cs | 18 + IISMainHandler/HandlersFactory.cs | 369 +++++------------- IISMainHandler/IISMainHandler.csproj | 3 +- IISMainHandler/PageOuter.cs | 10 +- IISMainHandler/WebContext.cs | 4 +- IISMainHandler/handlers/AbstractGetHandler.cs | 22 +- IISMainHandler/handlers/BoardHandler.cs | 6 +- IISMainHandler/handlers/BoardsHandler.cs | 2 +- IISMainHandler/handlers/PostHandler.cs | 4 +- IISMainHandler/handlers/StaticHandler.cs | 28 +- IISMainHandler/handlers/ThreadHandler.cs | 17 +- .../request/MarkThreadAsReadHandler.cs | 9 +- .../response/AbstractNewMessageHandler.cs | 4 +- .../response/AbstractUserGetHandler.cs | 14 +- .../response/ActiveAccountListHandler.cs | 3 +- .../handlers/response/AllPostsHandler.cs | 8 +- .../handlers/response/AllThreadsHandler.cs | 8 +- .../response/AvatarsSettingsHandler.cs | 2 +- .../handlers/response/BoardAsThread.cs | 6 +- .../handlers/response/ConversationHandler.cs | 17 +- .../handlers/response/ConversationsHandler.cs | 4 +- .../handlers/response/CreatePollHandler.cs | 2 +- .../handlers/response/CreateThreadHandler.cs | 4 +- .../handlers/response/EditHandler.cs | 4 +- .../handlers/response/LegacyPHPHandler.cs | 42 -- .../handlers/response/LegacyUploadHandler.cs | 36 -- .../response/LocalNetworksListHandler.cs | 2 +- .../handlers/response/LoginHandler.cs | 2 +- .../response/MigrateAccountHandler.cs | 6 +- .../handlers/response/PMReplyHandler.cs | 4 +- .../handlers/response/PMReplyToPostHandler.cs | 4 +- .../handlers/response/PMSendHandler.cs | 6 +- .../handlers/response/PollHandler.cs | 4 +- .../handlers/response/PunishHandler.cs | 4 +- .../handlers/response/QuickLinkHandler.cs | 4 +- .../handlers/response/RedirectGetHandler.cs | 2 +- .../response/RegisterByInviteHandler.cs | 7 +- .../handlers/response/ReplyHandler.cs | 4 +- .../handlers/response/RobotsHandler.cs | 10 +- .../handlers/response/SettingsHandler.cs | 2 +- .../response/SkipXsltTransformException.cs | 9 + .../handlers/response/UploadHandler.cs | 7 +- .../handlers/response/UploadListHandler.cs | 4 +- .../handlers/response/UploadNewHandler.cs | 2 +- .../handlers/response/UserDataHandler.cs | 2 +- .../handlers/response/UserInfoHandler.cs | 2 +- .../handlers/response/UserListHandler.cs | 4 +- .../response/UserPollsParticipatedHandler.cs | 8 +- .../handlers/response/UserPostsHandler.cs | 8 +- .../handlers/response/UserRepliesHandler.cs | 8 +- .../handlers/response/UserThreadsHandler.cs | 8 +- .../handlers/response/WhoIsOnlineHandler.cs | 2 +- .../response/maintenance/CleanCacheHandler.cs | 2 +- templates/Full/Login.xslt | 2 +- templates/Lite/Login.xslt | 2 +- 99 files changed, 1730 insertions(+), 496 deletions(-) create mode 100644 Common/URL/AbstractUrl.cs create mode 100644 Common/URL/QuickLink.cs create mode 100644 Common/URL/Robots.cs create mode 100644 Common/URL/Static.cs create mode 100644 Common/URL/UrlManager.cs create mode 100644 Common/URL/forum/AllPosts.cs create mode 100644 Common/URL/forum/AllThreads.cs create mode 100644 Common/URL/forum/Boards.cs create mode 100644 Common/URL/forum/board/Headlines.cs create mode 100644 Common/URL/forum/board/NewThread.cs create mode 100644 Common/URL/forum/board/Threads.cs create mode 100644 Common/URL/forum/board/thread/Posts.cs create mode 100644 Common/URL/forum/board/thread/post/Edit.cs create mode 100644 Common/URL/forum/board/thread/post/PMReply.cs create mode 100644 Common/URL/forum/board/thread/post/Punish.cs create mode 100644 Common/URL/forum/board/thread/post/Reply.cs create mode 100644 Common/URL/forum/board/thread/post/Show.cs create mode 100644 Common/URL/maintenance/CleanCache.cs create mode 100644 Common/URL/maintenance/LocalNetworks.cs create mode 100644 Common/URL/my/Avatars.cs create mode 100644 Common/URL/my/Settings.cs create mode 100644 Common/URL/my/UserData.cs create mode 100644 Common/URL/my/conversations/Conversation.cs create mode 100644 Common/URL/my/conversations/List.cs create mode 100644 Common/URL/my/conversations/NewPM.cs create mode 100644 Common/URL/my/conversations/Reply.cs create mode 100644 Common/URL/my/login/Login.cs create mode 100644 Common/URL/my/login/Migrate.cs create mode 100644 Common/URL/my/login/RegisterByInvite.cs create mode 100644 Common/URL/polls/Info.cs create mode 100644 Common/URL/polls/NewPoll.cs create mode 100644 Common/URL/upload/Item.cs create mode 100644 Common/URL/upload/List.cs create mode 100644 Common/URL/upload/New.cs create mode 100644 Common/URL/users/Active.cs create mode 100644 Common/URL/users/All.cs create mode 100644 Common/URL/users/Online.cs create mode 100644 Common/URL/users/user/Abstract.cs create mode 100644 Common/URL/users/user/Info.cs create mode 100644 Common/URL/users/user/PollsParticipated.cs create mode 100644 Common/URL/users/user/Posts.cs create mode 100644 Common/URL/users/user/Replies.cs create mode 100644 Common/URL/users/user/Threads.cs delete mode 100644 IISMainHandler/handlers/response/LegacyPHPHandler.cs delete mode 100644 IISMainHandler/handlers/response/LegacyUploadHandler.cs create mode 100644 IISMainHandler/handlers/response/SkipXsltTransformException.cs diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 05fd828..a993081 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1392 \ No newline at end of file +1398 \ No newline at end of file diff --git a/Common/Common.csproj b/Common/Common.csproj index de2a991..ed74c9c 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -128,6 +128,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Common/URL/AbstractUrl.cs b/Common/URL/AbstractUrl.cs new file mode 100644 index 0000000..91564b9 --- /dev/null +++ b/Common/URL/AbstractUrl.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Core; + +namespace FLocal.Common.URL { + public abstract class AbstractUrl { + + protected AbstractUrl(string remainder) { + this.remainder = remainder; + } + + public string remainder { + get; + private set; + } + + abstract public string title { + get; + } + + abstract protected string _canonical { + get; + } + + public string canonical { + get { + string result = this._canonical; + //if(!result.StartsWith("/")) result = "/" + result; + //if(!result.EndsWith("/")) result = result + "/"; + return result; + } + } + + public string canonicalFull { + get { + if(this.remainder == null) throw new CriticalException("Remainder is null"); + return this.canonical + this.remainder; + } + } + + } +} diff --git a/Common/URL/QuickLink.cs b/Common/URL/QuickLink.cs new file mode 100644 index 0000000..9629d12 --- /dev/null +++ b/Common/URL/QuickLink.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL { + public class QuickLink : AbstractUrl { + + public readonly dataobjects.QuickLink link; + + public QuickLink(string quickLinkId, string remainder) : base(remainder) { + this.link = dataobjects.QuickLink.LoadByName(quickLinkId); + } + + public override string title { + get { + return this.link.name; + } + } + + protected override string _canonical { + get { + return "/q/" + this.link.name; + } + } + } +} diff --git a/Common/URL/Robots.cs b/Common/URL/Robots.cs new file mode 100644 index 0000000..51c5e5d --- /dev/null +++ b/Common/URL/Robots.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL { + public class Robots : AbstractUrl { + + public Robots() : base("") { + } + + public override string title { + get { + return "robots.txt"; + } + } + + protected override string _canonical { + get { + return "/robots.txt"; + } + } + } +} diff --git a/Common/URL/Static.cs b/Common/URL/Static.cs new file mode 100644 index 0000000..54da588 --- /dev/null +++ b/Common/URL/Static.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL { + public class Static : AbstractUrl { + + public Static(string remainder) : base(remainder) { + } + + public override string title { + get { + return this.remainder; + } + } + + protected override string _canonical { + get { + return "/static/"; + } + } + } +} diff --git a/Common/URL/UrlManager.cs b/Common/URL/UrlManager.cs new file mode 100644 index 0000000..37e1c7d --- /dev/null +++ b/Common/URL/UrlManager.cs @@ -0,0 +1,327 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Collections.Specialized; + +namespace FLocal.Common.URL { + public static class UrlManager { + + private static string GetRemainder(string[] requestParts, int start) { + return string.Join("/", (from i in Enumerable.Range(start, requestParts.Length - start) select requestParts[i]).ToArray()); + } + + public static AbstractUrl Parse(string Path, NameValueCollection Query, bool isLoggedIn) { + + string[] requestParts = Path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + + if(requestParts.Length < 1) { + return new forum.Boards(GetRemainder(requestParts, 0)); + } + + #region legacy + if(Path.ToLower().StartsWith("/user/upload/")) { + return new upload.Item(requestParts[2], GetRemainder(requestParts, 3)); + } + if(Path.EndsWith(".php")) { + string[] scriptParts = Path.Split('.'); + if(scriptParts.Length != 2) { + return null; + } + + switch(scriptParts[0].ToLower()) { + case "showflat": + case "ashowflat": + dataobjects.Post post = dataobjects.Post.LoadById(int.Parse(Query["Number"])); + return new forum.board.thread.Posts(post.threadId.ToString(), "p" + post.id.ToString()); + case "showthreaded": + case "ashowthreaded": + return new forum.board.thread.post.Show(Query["Number"], ""); + case "postlist": + return new forum.board.Threads(dataobjects.Board.LoadByLegacyName(Query["Board"]).id.ToString(), ""); + case "showprofile": + return new users.user.Info(Query["User"], ""); + default: + return null; + } + } + if(Path.ToLower().StartsWith("/images/graemlins/")) { + return new Static("smileys/" + GetRemainder(requestParts, 2)); + } + #endregion + + #region robots + if(Path.ToLower().StartsWith("/robots.txt")) { + return new Robots(); + } + #endregion + + switch(requestParts[0].ToLower()) { + #region newlegacy + case "allposts": + return new forum.AllPosts(GetRemainder(requestParts, 1)); + case "allthreads": + return new forum.AllThreads(GetRemainder(requestParts, 1)); + case "boards": + return new forum.Boards(GetRemainder(requestParts, 1)); + case "board": + if(requestParts.Length < 2) { + return null; + } + if(requestParts.Length == 2) { + return new forum.board.Threads(requestParts[1], ""); + } + switch(requestParts[2].ToLower()) { + case "threads": + return new forum.board.Threads(requestParts[1], GetRemainder(requestParts, 3)); + case "headlines": + return new forum.board.Headlines(requestParts[1], GetRemainder(requestParts, 3)); + case "newthread": + return new forum.board.NewThread(requestParts[1], GetRemainder(requestParts, 3)); + default: + return new forum.board.Threads(requestParts[1], GetRemainder(requestParts, 2)); + } + case "boardasthread": + return new forum.board.Headlines(requestParts[1], GetRemainder(requestParts, 2)); + case "thread": + return new forum.board.thread.Posts(requestParts[1], GetRemainder(requestParts, 2)); + case "post": + if(requestParts.Length < 2) { + return null; + } + if(requestParts.Length == 2) { + return new forum.board.thread.post.Show(requestParts[1], ""); + } + switch(requestParts[2].ToLower()) { + case "edit": + return new forum.board.thread.post.Edit(requestParts[1], ""); + case "reply": + return new forum.board.thread.post.Reply(requestParts[1], ""); + case "pmreply": + return new forum.board.thread.post.PMReply(requestParts[1], ""); + case "punish": + return new forum.board.thread.post.Punish(requestParts[1], ""); + default: + return null; + } + case "registerbyinvite": + return new my.login.RegisterByInvite(GetRemainder(requestParts, 1)); + case "user": + return new users.user.Info(requestParts[1], GetRemainder(requestParts, 2)); + #endregion newlegacy + #region forum + case "forum": + if(requestParts.Length == 1) { + return new forum.Boards(""); + } + switch(requestParts[1].ToLower()) { + case "board": + if(requestParts.Length == 2) { + return null; + } + if(requestParts.Length == 3) { + return new forum.board.Threads(requestParts[2], ""); + } + switch(requestParts[3].ToLower()) { + case "headlines": + return new forum.board.Headlines(requestParts[2], GetRemainder(requestParts, 4)); + case "newthread": + return new forum.board.NewThread(requestParts[2], GetRemainder(requestParts, 4)); + case "thread": + if(requestParts.Length == 4) { + return null; + } + if(requestParts.Length == 5) { + return new forum.board.thread.Posts(requestParts[4], ""); + } + switch(requestParts[5].ToLower()) { + case "post": + if(requestParts.Length == 6) { + return null; + } + if(requestParts.Length == 7) { + return new forum.board.thread.post.Show(requestParts[6], ""); + } + switch(requestParts[7].ToLower()) { + case "edit": + return new forum.board.thread.post.Edit(requestParts[6], GetRemainder(requestParts, 8)); + case "pmreply": + return new forum.board.thread.post.PMReply(requestParts[6], GetRemainder(requestParts, 8)); + case "punish": + return new forum.board.thread.post.Punish(requestParts[6], GetRemainder(requestParts, 8)); + case "reply": + return new forum.board.thread.post.Reply(requestParts[6], GetRemainder(requestParts, 8)); + case "show": + return new forum.board.thread.post.Show(requestParts[6], GetRemainder(requestParts, 8)); + default: + return null; + } + case "posts": + return new forum.board.thread.Posts(requestParts[4], GetRemainder(requestParts, 6)); + default: + return null; + } + case "threads": + return new forum.board.Threads(requestParts[2], GetRemainder(requestParts, 4)); + default: + return null; + } + case "allposts": + return new forum.AllPosts(GetRemainder(requestParts, 2)); + case "allthreads": + return new forum.AllThreads(GetRemainder(requestParts, 2)); + case "boards": + return new forum.Boards(GetRemainder(requestParts, 2)); + default: + return null; + } + #endregion forum + #region maintenance + case "maintenance": + if(requestParts.Length < 2) { + return null; + } + switch(requestParts[1].ToLower()) { + case "cleancache": + return new maintenance.CleanCache(GetRemainder(requestParts, 2)); + case "localnetworks": + return new maintenance.LocalNetworks(GetRemainder(requestParts, 1)); + default: + return null; + } + #endregion maintenance + #region my; + case "my": + if(requestParts.Length == 1) { + if(isLoggedIn) { + return new my.conversations.List(""); + } else { + return new my.login.Login(""); + } + } + switch(requestParts[1].ToLower()) { + case "conversations": + if(requestParts.Length == 2) { + return new my.conversations.List(""); + } + switch(requestParts[2].ToLower()) { + case "conversation": + return new my.conversations.Conversation(requestParts[3], GetRemainder(requestParts, 4)); + case "list": + return new my.conversations.List(GetRemainder(requestParts, 3)); + case "newpm": + case "pmsend": + return new my.conversations.NewPM(GetRemainder(requestParts, 3)); + case "reply": + case "pmreply": + return new my.conversations.Reply(requestParts[3], GetRemainder(requestParts, 4)); + default: + return null; + } + case "login": + if(requestParts.Length == 2) { + return new my.login.Login(""); + } + switch(requestParts[2].ToLower()) { + case "login": + return new my.login.Login(GetRemainder(requestParts, 3)); + case "migrate": + case "migrateaccount": + return new my.login.Migrate(GetRemainder(requestParts, 3)); + case "registerbyinvite": + return new my.login.RegisterByInvite(GetRemainder(requestParts, 3)); + default: + return null; + } + case "avatars": + return new my.Avatars(GetRemainder(requestParts, 2)); + case "settings": + return new my.Settings(GetRemainder(requestParts, 2)); + case "userdata": + return new my.UserData(GetRemainder(requestParts, 2)); + default: + return null; + } + #endregion my; + #region polls + case "poll": + case "polls": + if(requestParts.Length < 2) { + return null; + } + switch(requestParts[1].ToLower()) { + case "info": + return new polls.Info(requestParts[2], GetRemainder(requestParts, 3)); + case "newpoll": + case "create": + return new polls.NewPoll(GetRemainder(requestParts, 2)); + default: + return new polls.Info(requestParts[1], GetRemainder(requestParts, 2)); + } + #endregion polls + #region upload; + case "upload": + if(requestParts.Length < 2) { + return new upload.List(""); + } + switch(requestParts[1].ToLower()) { + case "item": + return new upload.Item(requestParts[2], GetRemainder(requestParts, 3)); + case "list": + return new upload.List(GetRemainder(requestParts, 2)); + case "new": + return new upload.New(GetRemainder(requestParts, 2)); + default: + return null; + } + #endregion upload; + #region users; + case "users": + if(requestParts.Length == 1) { + return new users.All(""); + } + switch(requestParts[1].ToLower()) { + case "user": + if(requestParts.Length < 3) { + return null; + } + if(requestParts.Length == 3) { + return new users.user.Info(requestParts[2], ""); + } + switch(requestParts[3].ToLower()) { + case "info": + return new users.user.Info(requestParts[2], GetRemainder(requestParts, 4)); + case "pollsparticipated": + return new users.user.PollsParticipated(requestParts[2], GetRemainder(requestParts, 4)); + case "posts": + return new users.user.Posts(requestParts[2], GetRemainder(requestParts, 4)); + case "replies": + return new users.user.Replies(requestParts[2], GetRemainder(requestParts, 4)); + case "threads": + return new users.user.Threads(requestParts[2], GetRemainder(requestParts, 4)); + default: + return null; + } + case "active": + return new users.Active(GetRemainder(requestParts, 2)); + case "all": + return new users.All(GetRemainder(requestParts, 2)); + case "online": + return new users.Online(GetRemainder(requestParts, 2)); + default: + return null; + } + #endregion users; + case "q": + return new QuickLink(requestParts[1], GetRemainder(requestParts, 2)); + case "robots.txt": + return new Robots(); + case "static": + return new Static(GetRemainder(requestParts, 1)); + default: + return null; + } + } + + } +} diff --git a/Common/URL/forum/AllPosts.cs b/Common/URL/forum/AllPosts.cs new file mode 100644 index 0000000..00cd7d1 --- /dev/null +++ b/Common/URL/forum/AllPosts.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.forum { + public class AllPosts : AbstractUrl { + + public AllPosts(string remainder) : base(remainder) { + } + + public override string title { + get { + return "All posts"; + } + } + + protected override string _canonical { + get { + return "/Forum/AllPosts/"; + } + } + + } +} diff --git a/Common/URL/forum/AllThreads.cs b/Common/URL/forum/AllThreads.cs new file mode 100644 index 0000000..422533e --- /dev/null +++ b/Common/URL/forum/AllThreads.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.forum { + public class AllThreads : AbstractUrl { + + public AllThreads(string remainder) : base(remainder) { + } + + public override string title { + get { + return "All threads"; + } + } + + protected override string _canonical { + get { + return "/Forum/AllThreads/"; + } + } + + } +} diff --git a/Common/URL/forum/Boards.cs b/Common/URL/forum/Boards.cs new file mode 100644 index 0000000..36f9b5d --- /dev/null +++ b/Common/URL/forum/Boards.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.forum { + public class Boards : AbstractUrl { + + public Boards(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Boards"; + } + } + + protected override string _canonical { + get { + return "/Forum/Boards/"; + } + } + } +} diff --git a/Common/URL/forum/board/Headlines.cs b/Common/URL/forum/board/Headlines.cs new file mode 100644 index 0000000..b48fb45 --- /dev/null +++ b/Common/URL/forum/board/Headlines.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board { + public class Headlines : AbstractUrl { + + public readonly Board board; + + public Headlines(string boardId, string remainder) : base(remainder) { + this.board = Board.LoadById(int.Parse(boardId)); + } + + public override string title { + get { + return this.board.name; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.board.id + "/Headlines/"; + } + } + } +} diff --git a/Common/URL/forum/board/NewThread.cs b/Common/URL/forum/board/NewThread.cs new file mode 100644 index 0000000..d4cf2bf --- /dev/null +++ b/Common/URL/forum/board/NewThread.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board { + public class NewThread : AbstractUrl { + + public readonly Board board; + + public NewThread(string boardId, string remainder) : base(remainder) { + this.board = Board.LoadById(int.Parse(boardId)); + } + + public override string title { + get { + return this.board.name; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.board.id + "/NewThread/"; + } + } + } +} diff --git a/Common/URL/forum/board/Threads.cs b/Common/URL/forum/board/Threads.cs new file mode 100644 index 0000000..0a58c25 --- /dev/null +++ b/Common/URL/forum/board/Threads.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board { + public class Threads : AbstractUrl { + + public readonly Board board; + + public Threads(string boardId, string remainder) : base(remainder) { + this.board = Board.LoadById(int.Parse(boardId)); + } + + public override string title { + get { + return this.board.name; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.board.id + "/Threads/"; + } + } + } +} diff --git a/Common/URL/forum/board/thread/Posts.cs b/Common/URL/forum/board/thread/Posts.cs new file mode 100644 index 0000000..38cf831 --- /dev/null +++ b/Common/URL/forum/board/thread/Posts.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board.thread { + public class Posts : AbstractUrl { + + public readonly dataobjects.Thread thread; + + public Posts(string threadId, string remainder) : base(remainder) { + this.thread = dataobjects.Thread.LoadById(int.Parse(threadId)); + } + + public override string title { + get { + return this.thread.title; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.thread.boardId + "/Thread/" + this.thread.id + "/Posts/"; + } + } + } +} diff --git a/Common/URL/forum/board/thread/post/Edit.cs b/Common/URL/forum/board/thread/post/Edit.cs new file mode 100644 index 0000000..7d341de --- /dev/null +++ b/Common/URL/forum/board/thread/post/Edit.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board.thread.post { + public class Edit : AbstractUrl { + + public Post post; + + public Edit(string postId, string remainder) : base(remainder) { + this.post = Post.LoadById(int.Parse(postId)); + } + + public override string title { + get { + return post.title; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/Edit/"; + } + } + + } + +} diff --git a/Common/URL/forum/board/thread/post/PMReply.cs b/Common/URL/forum/board/thread/post/PMReply.cs new file mode 100644 index 0000000..aad2b40 --- /dev/null +++ b/Common/URL/forum/board/thread/post/PMReply.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board.thread.post { + public class PMReply : AbstractUrl { + + public Post post; + + public PMReply(string postId, string remainder) : base(remainder) { + this.post = Post.LoadById(int.Parse(postId)); + } + + public override string title { + get { + return post.title; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/PMReply/"; + } + } + + } + +} diff --git a/Common/URL/forum/board/thread/post/Punish.cs b/Common/URL/forum/board/thread/post/Punish.cs new file mode 100644 index 0000000..0ccb2c2 --- /dev/null +++ b/Common/URL/forum/board/thread/post/Punish.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board.thread.post { + public class Punish : AbstractUrl { + + public Post post; + + public Punish(string postId, string remainder) : base(remainder) { + this.post = Post.LoadById(int.Parse(postId)); + } + + public override string title { + get { + return post.title; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/Punish/"; + } + } + + } + +} diff --git a/Common/URL/forum/board/thread/post/Reply.cs b/Common/URL/forum/board/thread/post/Reply.cs new file mode 100644 index 0000000..1822135 --- /dev/null +++ b/Common/URL/forum/board/thread/post/Reply.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board.thread.post { + public class Reply : AbstractUrl { + + public Post post; + + public Reply(string postId, string remainder) : base(remainder) { + this.post = Post.LoadById(int.Parse(postId)); + } + + public override string title { + get { + return post.title; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/Reply/"; + } + } + + } + +} diff --git a/Common/URL/forum/board/thread/post/Show.cs b/Common/URL/forum/board/thread/post/Show.cs new file mode 100644 index 0000000..33dbeea --- /dev/null +++ b/Common/URL/forum/board/thread/post/Show.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.forum.board.thread.post { + public class Show : AbstractUrl { + + public Post post; + + public Show(string postId, string remainder) : base(remainder) { + this.post = Post.LoadById(int.Parse(postId)); + } + + public override string title { + get { + return post.title; + } + } + + protected override string _canonical { + get { + return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/Show/"; + } + } + + } + +} diff --git a/Common/URL/maintenance/CleanCache.cs b/Common/URL/maintenance/CleanCache.cs new file mode 100644 index 0000000..5090d22 --- /dev/null +++ b/Common/URL/maintenance/CleanCache.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.maintenance { + public class CleanCache : AbstractUrl { + + public CleanCache(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Maintenance :: Clean cache"; + } + } + + protected override string _canonical { + get { + return "/Maintenance/CleanCache/"; + } + } + + } +} diff --git a/Common/URL/maintenance/LocalNetworks.cs b/Common/URL/maintenance/LocalNetworks.cs new file mode 100644 index 0000000..3c37277 --- /dev/null +++ b/Common/URL/maintenance/LocalNetworks.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.maintenance { + public class LocalNetworks : AbstractUrl { + + public LocalNetworks(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Local networks"; + } + } + + protected override string _canonical { + get { + return "/Maintenance/LocalNetworks/"; + } + } + } +} diff --git a/Common/URL/my/Avatars.cs b/Common/URL/my/Avatars.cs new file mode 100644 index 0000000..5520f32 --- /dev/null +++ b/Common/URL/my/Avatars.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.my { + public class Avatars : AbstractUrl { + + public Avatars(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Avatars settings"; + } + } + + protected override string _canonical { + get { + return "/My/Avatars/"; + } + } + } +} diff --git a/Common/URL/my/Settings.cs b/Common/URL/my/Settings.cs new file mode 100644 index 0000000..854f6ef --- /dev/null +++ b/Common/URL/my/Settings.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.my { + public class Settings : AbstractUrl { + + public Settings(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Settings"; + } + } + + protected override string _canonical { + get { + return "/My/Settings/"; + } + } + } +} diff --git a/Common/URL/my/UserData.cs b/Common/URL/my/UserData.cs new file mode 100644 index 0000000..ccc068d --- /dev/null +++ b/Common/URL/my/UserData.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.my { + public class UserData : AbstractUrl { + + public UserData(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Change user data"; + } + } + + protected override string _canonical { + get { + return "/My/UserData/"; + } + } + } +} diff --git a/Common/URL/my/conversations/Conversation.cs b/Common/URL/my/conversations/Conversation.cs new file mode 100644 index 0000000..7fce3e4 --- /dev/null +++ b/Common/URL/my/conversations/Conversation.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.my.conversations { + public class Conversation : AbstractUrl { + + public Account interlocutor; + + public Conversation(string interlocutorId, string remainder) : base(remainder) { + this.interlocutor = Account.LoadById(int.Parse(interlocutorId)); + } + + public override string title { + get { + return this.interlocutor.user.name; + } + } + + protected override string _canonical { + get { + return "/My/Conversations/Conversation/" + this.interlocutor.id + "/"; + } + } + } +} diff --git a/Common/URL/my/conversations/List.cs b/Common/URL/my/conversations/List.cs new file mode 100644 index 0000000..03ab82f --- /dev/null +++ b/Common/URL/my/conversations/List.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.my.conversations { + public class List : AbstractUrl { + + public List(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Conversations"; + } + } + + protected override string _canonical { + get { + return "/My/Conversations/List/"; + } + } + } +} diff --git a/Common/URL/my/conversations/NewPM.cs b/Common/URL/my/conversations/NewPM.cs new file mode 100644 index 0000000..bfc6aa1 --- /dev/null +++ b/Common/URL/my/conversations/NewPM.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.my.conversations { + public class NewPM : AbstractUrl { + + public NewPM(string remainder) : base(remainder) { + } + + public override string title { + get { + return "New PM"; + } + } + + protected override string _canonical { + get { + return "/My/Conversations/NewPM/"; + } + } + } +} diff --git a/Common/URL/my/conversations/Reply.cs b/Common/URL/my/conversations/Reply.cs new file mode 100644 index 0000000..6908d47 --- /dev/null +++ b/Common/URL/my/conversations/Reply.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.my.conversations { + public class Reply : AbstractUrl { + + public PMMessage pm; + + public Reply(string pmId, string remainder) : base(remainder) { + this.pm = PMMessage.LoadById(int.Parse(pmId)); + } + + public override string title { + get { + return this.pm.title; + } + } + + protected override string _canonical { + get { + return "/My/Conversations/Reply/" + this.pm.id + "/"; + } + } + } +} diff --git a/Common/URL/my/login/Login.cs b/Common/URL/my/login/Login.cs new file mode 100644 index 0000000..feaafb5 --- /dev/null +++ b/Common/URL/my/login/Login.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.my.login { + public class Login : AbstractUrl { + + public Login(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Login"; + } + } + + protected override string _canonical { + get { + return "/My/Login/Login/"; + } + } + } +} diff --git a/Common/URL/my/login/Migrate.cs b/Common/URL/my/login/Migrate.cs new file mode 100644 index 0000000..02be5a8 --- /dev/null +++ b/Common/URL/my/login/Migrate.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.my.login { + public class Migrate : AbstractUrl { + + public Migrate(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Migrate"; + } + } + + protected override string _canonical { + get { + return "/My/Login/Migrate/"; + } + } + } +} diff --git a/Common/URL/my/login/RegisterByInvite.cs b/Common/URL/my/login/RegisterByInvite.cs new file mode 100644 index 0000000..e8cc047 --- /dev/null +++ b/Common/URL/my/login/RegisterByInvite.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.my.login { + public class RegisterByInvite : AbstractUrl { + + public RegisterByInvite(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Register by invite"; + } + } + + protected override string _canonical { + get { + return "/My/Login/RegisterByInvite/"; + } + } + } +} diff --git a/Common/URL/polls/Info.cs b/Common/URL/polls/Info.cs new file mode 100644 index 0000000..c3b42b3 --- /dev/null +++ b/Common/URL/polls/Info.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.polls { + public class Info : AbstractUrl { + + public readonly Poll poll; + + public Info(string pollId, string remainder) : base(remainder) { + this.poll = Poll.LoadById(int.Parse(pollId)); + } + + public override string title { + get { + return this.poll.title; + } + } + + protected override string _canonical { + get { + return "/Polls/Info/" + this.poll.id + "/"; + } + } + } +} diff --git a/Common/URL/polls/NewPoll.cs b/Common/URL/polls/NewPoll.cs new file mode 100644 index 0000000..3f22214 --- /dev/null +++ b/Common/URL/polls/NewPoll.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.polls { + public class NewPoll : AbstractUrl { + + public NewPoll(string remainder) : base(remainder) { + } + + public override string title { + get { + return "New poll"; + } + } + + protected override string _canonical { + get { + return "/Polls/NewPoll/"; + } + } + } +} diff --git a/Common/URL/upload/Item.cs b/Common/URL/upload/Item.cs new file mode 100644 index 0000000..e0da765 --- /dev/null +++ b/Common/URL/upload/Item.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Core; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.upload { + public class Item : AbstractUrl { + + public readonly Upload upload; + + public Item(string uploadId, string remainder) : base(remainder) { + int iUploadId; + if(!int.TryParse(uploadId, out iUploadId)) { + string[] parts = uploadId.Split('.'); + if(parts.Length != 2) throw new FLocalException("wrong url"); + if(parts[0].Substring(0, 4).ToLower() != "file") throw new FLocalException("wrong url"); + int rawFileNum = int.Parse(parts[0].Substring(4)); + switch(parts[1].ToLower()) { + case "jpg": + iUploadId = rawFileNum; + break; + case "gif": + iUploadId = 500000 + rawFileNum; + break; + case "png": + iUploadId = 600000 + rawFileNum; + break; + default: + throw new FLocalException("wrong url"); + } + } + this.upload = Upload.LoadById(iUploadId); + } + + public override string title { + get { + return this.upload.filename; + } + } + + protected override string _canonical { + get { + return "/Upload/Item/" + this.upload.id + "/"; + } + } + } +} diff --git a/Common/URL/upload/List.cs b/Common/URL/upload/List.cs new file mode 100644 index 0000000..64f68e7 --- /dev/null +++ b/Common/URL/upload/List.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.upload { + public class List : AbstractUrl { + + public List(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Uploads list"; + } + } + + protected override string _canonical { + get { + return "/Upload/List/"; + } + } + } +} diff --git a/Common/URL/upload/New.cs b/Common/URL/upload/New.cs new file mode 100644 index 0000000..1498764 --- /dev/null +++ b/Common/URL/upload/New.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.upload { + public class New : AbstractUrl { + + public New(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Upload new file"; + } + } + + protected override string _canonical { + get { + return "/Upload/New/"; + } + } + } +} diff --git a/Common/URL/users/Active.cs b/Common/URL/users/Active.cs new file mode 100644 index 0000000..418647d --- /dev/null +++ b/Common/URL/users/Active.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.users { + public class Active : AbstractUrl { + + public Active(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Active users"; + } + } + + protected override string _canonical { + get { + return "/Users/Active/"; + } + } + + } +} diff --git a/Common/URL/users/All.cs b/Common/URL/users/All.cs new file mode 100644 index 0000000..421fbb1 --- /dev/null +++ b/Common/URL/users/All.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.users { + public class All : AbstractUrl { + + public All(string remainder) : base(remainder) { + } + + public override string title { + get { + return "All users"; + } + } + + protected override string _canonical { + get { + return "/Users/All/"; + } + } + + } +} diff --git a/Common/URL/users/Online.cs b/Common/URL/users/Online.cs new file mode 100644 index 0000000..fe32209 --- /dev/null +++ b/Common/URL/users/Online.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.users { + public class Online : AbstractUrl { + + public Online(string remainder) : base(remainder) { + } + + public override string title { + get { + return "Who is online"; + } + } + + protected override string _canonical { + get { + return "/Users/Online/"; + } + } + + } +} diff --git a/Common/URL/users/user/Abstract.cs b/Common/URL/users/user/Abstract.cs new file mode 100644 index 0000000..73d0851 --- /dev/null +++ b/Common/URL/users/user/Abstract.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Common.dataobjects; + +namespace FLocal.Common.URL.users.user { + public abstract class Abstract : AbstractUrl { + + public readonly User user; + + public Abstract(string userId, string remainder) : base(remainder) { + int iUserId; + if(int.TryParse(userId, out iUserId)) { + this.user = User.LoadById(iUserId); + } else { + this.user = User.LoadByName(userId); + } + } + + public override string title { + get { + return this.user.name; + } + } + + } +} diff --git a/Common/URL/users/user/Info.cs b/Common/URL/users/user/Info.cs new file mode 100644 index 0000000..b92ca7c --- /dev/null +++ b/Common/URL/users/user/Info.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.users.user { + public class Info : Abstract { + + public Info(string userId, string remainder) : base(userId, remainder) { + } + + protected override string _canonical { + get { + return "/Users/User/" + this.user.id + "/Info/"; + } + } + } +} diff --git a/Common/URL/users/user/PollsParticipated.cs b/Common/URL/users/user/PollsParticipated.cs new file mode 100644 index 0000000..71787b8 --- /dev/null +++ b/Common/URL/users/user/PollsParticipated.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.users.user { + public class PollsParticipated : Abstract { + + public PollsParticipated(string userId, string remainder) : base(userId, remainder) { + } + + protected override string _canonical { + get { + return "/Users/User/" + this.user.id + "/PollsParticipated/"; + } + } + } +} diff --git a/Common/URL/users/user/Posts.cs b/Common/URL/users/user/Posts.cs new file mode 100644 index 0000000..de254c6 --- /dev/null +++ b/Common/URL/users/user/Posts.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.users.user { + public class Posts : Abstract { + + public Posts(string userId, string remainder) : base(userId, remainder) { + } + + protected override string _canonical { + get { + return "/Users/User/" + this.user.id + "/Posts/"; + } + } + } +} diff --git a/Common/URL/users/user/Replies.cs b/Common/URL/users/user/Replies.cs new file mode 100644 index 0000000..f4cf083 --- /dev/null +++ b/Common/URL/users/user/Replies.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.users.user { + public class Replies : Abstract { + + public Replies(string userId, string remainder) : base(userId, remainder) { + } + + protected override string _canonical { + get { + return "/Users/User/" + this.user.id + "/Replies/"; + } + } + } +} diff --git a/Common/URL/users/user/Threads.cs b/Common/URL/users/user/Threads.cs new file mode 100644 index 0000000..4f4c94a --- /dev/null +++ b/Common/URL/users/user/Threads.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Common.URL.users.user { + public class Threads : Abstract { + + public Threads(string userId, string remainder) : base(userId, remainder) { + } + + protected override string _canonical { + get { + return "/Users/User/" + this.user.id + "/Threads/"; + } + } + } +} diff --git a/IISMainHandler/HandlersFactory.cs b/IISMainHandler/HandlersFactory.cs index df37ffa..a488f5a 100644 --- a/IISMainHandler/HandlersFactory.cs +++ b/IISMainHandler/HandlersFactory.cs @@ -4,278 +4,125 @@ using System.Linq; using System.Text; using System.Web; using FLocal.Core; +using FLocal.Common.URL; +using URL = FLocal.Common.URL; namespace FLocal.IISHandler { class HandlersFactory { + private static readonly Dictionary> handlersDictionary = new Dictionary> { + { typeof(URL.forum.AllPosts),CreateHandler }, + { typeof(URL.forum.AllThreads), CreateHandler }, + { typeof(URL.forum.board.Headlines), CreateHandler }, + { typeof(URL.forum.board.NewThread), CreateHandler }, + { typeof(URL.forum.board.thread.post.Edit), CreateHandler }, + { typeof(URL.forum.board.thread.post.PMReply), CreateHandler }, + { typeof(URL.forum.board.thread.post.Punish), CreateHandler }, + { typeof(URL.forum.board.thread.post.Reply), CreateHandler }, + { typeof(URL.forum.board.thread.post.Show), CreateHandler }, + { typeof(URL.forum.board.thread.Posts), CreateHandler }, + { typeof(URL.forum.board.Threads), CreateHandler }, + { typeof(URL.forum.Boards), CreateHandler }, + { typeof(URL.maintenance.CleanCache), CreateHandler }, + { typeof(URL.maintenance.LocalNetworks), CreateHandler }, + { typeof(URL.my.Avatars), CreateHandler }, + { typeof(URL.my.conversations.Conversation), CreateHandler }, + { typeof(URL.my.conversations.List), CreateHandler }, + { typeof(URL.my.conversations.NewPM), CreateHandler }, + { typeof(URL.my.conversations.Reply), CreateHandler }, + { typeof(URL.my.login.Login), CreateHandler }, + { typeof(URL.my.login.Migrate), CreateHandler }, + { typeof(URL.my.login.RegisterByInvite), CreateHandler }, + { typeof(URL.my.Settings), CreateHandler }, + { typeof(URL.my.UserData), CreateHandler }, + { typeof(URL.polls.Info), CreateHandler }, + { typeof(URL.polls.NewPoll), CreateHandler }, + { typeof(URL.QuickLink), CreateHandler }, + { typeof(URL.Robots), CreateHandler }, + { typeof(URL.Static), CreateHandler }, + { typeof(URL.upload.Item), CreateHandler }, + { typeof(URL.upload.List), CreateHandler }, + { typeof(URL.upload.New), CreateHandler }, + { typeof(URL.users.Active), CreateHandler }, + { typeof(URL.users.All), CreateHandler }, + { typeof(URL.users.Online), CreateHandler }, + { typeof(URL.users.user.Info), CreateHandler }, + { typeof(URL.users.user.PollsParticipated), CreateHandler }, + { typeof(URL.users.user.Posts), CreateHandler }, + { typeof(URL.users.user.Replies), CreateHandler }, + { typeof(URL.users.user.Threads), CreateHandler }, + }; + + private static ISpecificHandler CreateHandler(AbstractUrl url) + where TUrl : AbstractUrl + where THandler : handlers.AbstractGetHandler, new() + { + return new THandler() { + url = (TUrl)url + }; + } + public static ISpecificHandler getHandler(WebContext context) { -// if(!context.httprequest.Path.EndsWith("/")) { -// return new handlers.WrongUrlHandler(); -// throw new FLocalException("Malformed url"); -// } - if(context.requestParts.Length < 1) { - //return new handlers.RootHandler(); - throw new RedirectException("/Boards/"); + if(context.httprequest.Path.ToLower().StartsWith("/do/")) { + string action = context.httprequest.Path.ToLower().Substring(4).Trim('/'); + if(action.StartsWith("markthreadasread")) { + return new handlers.request.MarkThreadAsReadHandler(); + } + switch(action) { + case "login": + return new handlers.request.LoginHandler(); + case "logout": + return new handlers.request.LogoutHandler(); + case "migrateaccount": + return new handlers.request.MigrateAccountHandler(); + case "register": + return new handlers.request.RegisterHandler(); + case "registerbyinvite": + return new handlers.request.RegisterByInviteHandler(); + case "edit": + return new handlers.request.EditHandler(); + case "punish": + return new handlers.request.PunishHandler(); + case "reply": + return new handlers.request.ReplyHandler(); + case "newthread": + return new handlers.request.CreateThreadHandler(); + case "settings": + return new handlers.request.SettingsHandler(); + case "userdata": + return new handlers.request.UserDataHandler(); + case "sendpm": + return new handlers.request.SendPMHandler(); + case "upload": + return new handlers.request.UploadHandler(); + case "newpoll": + return new handlers.request.CreatePollHandler(); + case "vote": + return new handlers.request.VoteHandler(); + case "avatars/add": + return new handlers.request.avatars.AddHandler(); + case "avatars/remove": + return new handlers.request.avatars.RemoveHandler(); + case "avatars/setasdefault": + return new handlers.request.avatars.SetAsDefaultHandler(); + case "maintenance/cleancache": + return new handlers.request.maintenance.CleanCacheHandler(); + default: + return new handlers.WrongUrlHandler(); + } } - #region legacy - if(context.httprequest.Path.ToLower().StartsWith("/user/upload/")) { - return new handlers.response.LegacyUploadHandler(); + AbstractUrl url = UrlManager.Parse(context.httprequest.Path, context.httprequest.QueryString, context.account != null); + if(url == null) { + return new handlers.WrongUrlHandler(); } - if(context.httprequest.Path.EndsWith(".php")) { - return new handlers.response.LegacyPHPHandler(); - } - if(context.httprequest.Path.ToLower().StartsWith("/images/graemlins/")) { - throw new RedirectException("/static/smileys/" + context.requestParts[2]); - } - #endregion - #region robots - if(context.httprequest.Path.ToLower().StartsWith("/robots.txt")) { - return new handlers.response.RobotsHandler(); + if(!context.httprequest.Path.StartsWith(url.canonical)) { + throw new RedirectException(url.canonicalFull); } - #endregion - switch(context.requestParts[0].ToLower()) { - case "q": - return new handlers.response.QuickLinkHandler(); - case "allposts": - return new handlers.response.AllPostsHandler(); - case "allthreads": - return new handlers.response.AllThreadsHandler(); - case "boards": - return new handlers.BoardsHandler(); - case "board": - if(context.requestParts.Length < 2) { - return new handlers.WrongUrlHandler(); - } - if(context.requestParts.Length == 2) { - return new handlers.BoardHandler(); - } - switch(context.requestParts[2].ToLower()) { - case "newthread": - return new handlers.response.CreateThreadHandler(); - default: - return new handlers.BoardHandler(); - } - case "boardasthread": - return new handlers.response.BoardAsThreadHandler(); - case "thread": - return new handlers.ThreadHandler(); - case "post": - if(context.requestParts.Length < 2) { - return new handlers.WrongUrlHandler(); - } - if(context.requestParts.Length == 2) { - return new handlers.PostHandler(); - } - switch(context.requestParts[2].ToLower()) { - case "edit": - return new handlers.response.EditHandler(); - case "reply": - return new handlers.response.ReplyHandler(); - case "pmreply": - return new handlers.response.PMReplyToPostHandler(); - case "punish": - return new handlers.response.PunishHandler(); - default: - return new handlers.WrongUrlHandler(); - } - case "my": - if(context.requestParts.Length == 1) { - if(context.account != null) { - throw new RedirectException("/My/Conversations/"); - } else { - throw new RedirectException("/My/Login/"); - } - } - switch(context.requestParts[1].ToLower()) { - case "login": - if(context.requestParts.Length == 2) { - return new handlers.response.LoginHandler(); - } else { - switch(context.requestParts[2].ToLower()) { - case "migrateaccount": - return new handlers.response.MigrateAccountHandler(); - case "registerbyinvite": - return new handlers.response.RegisterByInviteHandler(); - default: - return new handlers.WrongUrlHandler(); - } - } - case "settings": - return new handlers.response.SettingsHandler(); - case "userdata": - return new handlers.response.UserDataHandler(); - case "avatars": - return new handlers.response.AvatarsSettingsHandler(); - case "conversations": - if(context.requestParts.Length == 2) { - return new handlers.response.ConversationsHandler(); - } else { - switch(context.requestParts[2].ToLower()) { - case "conversation": - return new handlers.response.ConversationHandler(); - case "pmsend": - return new handlers.response.PMSendHandler(); - case "pmreply": - return new handlers.response.PMReplyHandler(); - default: - return new handlers.response.ConversationsHandler(); - } - } - default: - return new handlers.WrongUrlHandler(); - } - case "users": - if(context.requestParts.Length == 1) { - throw new RedirectException("/Users/All/"); - } - switch(context.requestParts[1].ToLower()) { - case "all": - return new handlers.response.UserListHandler(); - case "active": - return new handlers.response.ActiveAccountListHandler(); - case "online": - return new handlers.response.WhoIsOnlineHandler(); - case "user": - if(context.requestParts.Length < 3) { - return new handlers.WrongUrlHandler(); - } - if(context.requestParts.Length == 3) { - throw new RedirectException("/Users/User/" + context.requestParts[2] + "/Info/"); - } - switch(context.requestParts[3].ToLower()) { - case "info": - return new handlers.response.UserInfoHandler(); - case "threads": - return new handlers.response.UserThreadsHandler(); - case "posts": - return new handlers.response.UserPostsHandler(); - case "replies": - return new handlers.response.UserRepliesHandler(); - case "pollsparticipated": - return new handlers.response.UserPollsParticipatedHandler(); - default: - return new handlers.WrongUrlHandler(); - } - default: - return new handlers.WrongUrlHandler(); - } - case "upload": - if(context.requestParts.Length < 2) { - throw new RedirectException("/Upload/List/"); - } - switch(context.requestParts[1].ToLower()) { - case "item": - return new handlers.response.UploadHandler(); - case "new": - return new handlers.response.UploadNewHandler(); - case "list": - return new handlers.response.UploadListHandler(); - default: - return new handlers.WrongUrlHandler(); - } - case "maintenance": - if(context.requestParts.Length < 2) { - return new handlers.WrongUrlHandler(); - } - switch(context.requestParts[1].ToLower()) { - case "cleancache": - return new handlers.response.maintenance.CleanCacheHandler(); - default: - return new handlers.WrongUrlHandler(); - } - case "poll": - if(context.requestParts.Length < 2) { - return new handlers.WrongUrlHandler(); - } - switch(context.requestParts[1].ToLower()) { - case "create": - return new handlers.response.CreatePollHandler(); - default: - return new handlers.response.PollHandler(); - } - case "localnetworks": - return new handlers.response.LocalNetworksListHandler(); - case "static": - return new handlers.StaticHandler(context.requestParts); - case "registerbyinvite": - string[] rbi_parts = context.requestParts; - rbi_parts[0] = "My/Login/RegisterByInvite"; - throw new RedirectException("/" + string.Join("/", rbi_parts)); - case "user": - string[] u_parts = context.requestParts; - u_parts[0] = "Users/User"; - throw new RedirectException("/" + string.Join("/", u_parts)); - case "do": - if(context.requestParts.Length < 2) { - return new handlers.WrongUrlHandler(); - } else { - switch(context.requestParts[1].ToLower()) { - case "login": - return new handlers.request.LoginHandler(); - case "logout": - return new handlers.request.LogoutHandler(); - case "migrateaccount": - return new handlers.request.MigrateAccountHandler(); - case "register": - return new handlers.request.RegisterHandler(); - case "registerbyinvite": - return new handlers.request.RegisterByInviteHandler(); - case "edit": - return new handlers.request.EditHandler(); - case "punish": - return new handlers.request.PunishHandler(); - case "reply": - return new handlers.request.ReplyHandler(); - case "newthread": - return new handlers.request.CreateThreadHandler(); - case "settings": - return new handlers.request.SettingsHandler(); - case "userdata": - return new handlers.request.UserDataHandler(); - case "sendpm": - return new handlers.request.SendPMHandler(); - case "markthreadasread": - return new handlers.request.MarkThreadAsReadHandler(); - case "upload": - return new handlers.request.UploadHandler(); - case "newpoll": - return new handlers.request.CreatePollHandler(); - case "vote": - return new handlers.request.VoteHandler(); - case "avatars": - if(context.requestParts.Length < 3) { - return new handlers.WrongUrlHandler(); - } - switch(context.requestParts[2].ToLower()) { - case "add": - return new handlers.request.avatars.AddHandler(); - case "remove": - return new handlers.request.avatars.RemoveHandler(); - case "setasdefault": - return new handlers.request.avatars.SetAsDefaultHandler(); - default: - return new handlers.WrongUrlHandler(); - } - case "maintenance": - if(context.requestParts.Length < 3) { - return new handlers.WrongUrlHandler(); - } - switch(context.requestParts[2].ToLower()) { - case "cleancache": - return new handlers.request.maintenance.CleanCacheHandler(); - default: - return new handlers.WrongUrlHandler(); - } - default: - return new handlers.WrongUrlHandler(); - } - } - default: - return new handlers.WrongUrlHandler(); - } + return handlersDictionary[url.GetType()](url); + } } diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index 8d9c0a2..2731136 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -89,8 +89,6 @@ - - @@ -152,6 +150,7 @@ + diff --git a/IISMainHandler/PageOuter.cs b/IISMainHandler/PageOuter.cs index 5379aea..b379c42 100644 --- a/IISMainHandler/PageOuter.cs +++ b/IISMainHandler/PageOuter.cs @@ -47,7 +47,9 @@ namespace FLocal.IISHandler { return result; } - public static PageOuter createFromGet(string[] requestParts, long perPage, Dictionary> customAction, int offset) { + public static PageOuter createFromUrl(FLocal.Common.URL.AbstractUrl url, long perPage, Dictionary> customAction) { + string[] requestParts = url.remainder.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + int offset = 0; bool reversed = (requestParts.Length > (offset+1)) && (requestParts[offset+1].ToLower() == "reversed"); if(requestParts.Length > offset) { if(requestParts[offset].ToLower() == "all") { @@ -55,15 +57,15 @@ namespace FLocal.IISHandler { } else if(Char.IsDigit(requestParts[offset][0])) { return new PageOuter(long.Parse(requestParts[offset]), perPage, perPage, reversed); } else { - return new PageOuter(customAction[requestParts[offset][0]](), perPage, perPage, reversed); + return new PageOuter(customAction[requestParts[offset][0]](requestParts[offset].Substring(1)), perPage, perPage, reversed); } } else { return new PageOuter(0, perPage, perPage, reversed); } } - public static PageOuter createFromGet(string[] requestParts, long perPage, int offset) { - return createFromGet(requestParts, perPage, new Dictionary>(), offset); + public static PageOuter createFromUrl(FLocal.Common.URL.AbstractUrl url, long perPage) { + return createFromUrl(url, perPage, new Dictionary>()); } public XElement exportToXml(int left, int current, int right) { diff --git a/IISMainHandler/WebContext.cs b/IISMainHandler/WebContext.cs index d172f4c..a980cbe 100644 --- a/IISMainHandler/WebContext.cs +++ b/IISMainHandler/WebContext.cs @@ -23,7 +23,7 @@ namespace FLocal.IISHandler { } } - private object requestParts_Locker = new object(); + /*private object requestParts_Locker = new object(); private string[] requestParts_Data = null; public string[] requestParts { get { @@ -36,7 +36,7 @@ namespace FLocal.IISHandler { } return this.requestParts_Data; } - } + }*/ public XElement exportRequestParameters() { return new XElement("get", diff --git a/IISMainHandler/handlers/AbstractGetHandler.cs b/IISMainHandler/handlers/AbstractGetHandler.cs index 0fa041e..6bb6bf9 100644 --- a/IISMainHandler/handlers/AbstractGetHandler.cs +++ b/IISMainHandler/handlers/AbstractGetHandler.cs @@ -4,8 +4,10 @@ using System.Linq; using System.Text; using System.Xml.Linq; using FLocal.Common; +using FLocal.Common.URL; namespace FLocal.IISHandler.handlers { + abstract class AbstractGetHandler : ISpecificHandler { abstract protected string templateName { @@ -14,7 +16,7 @@ namespace FLocal.IISHandler.handlers { abstract protected IEnumerable getSpecificData(WebContext context); - protected IEnumerable getCommonData(WebContext context) { + virtual protected IEnumerable getCommonData(WebContext context) { return new XElement[] { new XElement( "url", @@ -27,7 +29,6 @@ namespace FLocal.IISHandler.handlers { context.exportSession(), context.userSettings.skin.exportToXml(), context.userSettings.machichara.exportToXml(), - new XElement("currentUrl", "/" + String.Join("/", context.requestParts) + "/"), context.exportRequestParameters(), }; } @@ -44,6 +45,7 @@ namespace FLocal.IISHandler.handlers { public void Handle(WebContext context) { try { context.WriteTransformResult(this.templateName, this.getData(context)); + } catch(response.SkipXsltTransformException) { } catch(RedirectException) { throw; } catch(WrongUrlException) { @@ -55,4 +57,20 @@ namespace FLocal.IISHandler.handlers { } } + + abstract class AbstractGetHandler : AbstractGetHandler where TUrl : AbstractUrl { + + public TUrl url; + + protected override IEnumerable getCommonData(WebContext context) { + return base.getCommonData(context).Concat( + new XElement[] { + new XElement("currentUrl", this.url.canonicalFull), + new XElement("currentBaseUrl", this.url.canonical), + } + ); + } + + } + } diff --git a/IISMainHandler/handlers/BoardHandler.cs b/IISMainHandler/handlers/BoardHandler.cs index 132f15b..e2d039d 100644 --- a/IISMainHandler/handlers/BoardHandler.cs +++ b/IISMainHandler/handlers/BoardHandler.cs @@ -11,7 +11,7 @@ using FLocal.Core.DB; namespace FLocal.IISHandler.handlers { - class BoardHandler : AbstractGetHandler { + class BoardHandler : AbstractGetHandler { override protected string templateName { get { @@ -20,8 +20,8 @@ namespace FLocal.IISHandler.handlers { } override protected IEnumerable getSpecificData(WebContext context) { - Board board = Board.LoadById(int.Parse(context.requestParts[1])); - PageOuter pageOuter = PageOuter.createFromGet(context.requestParts, context.userSettings.threadsPerPage, 2); + Board board = this.url.board; + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.threadsPerPage); IEnumerable threads = board.getThreads(pageOuter, pageOuter.descendingDirection); XElement[] result = new XElement[] { new XElement("currentLocation", board.exportToXmlSimpleWithParent(context)), diff --git a/IISMainHandler/handlers/BoardsHandler.cs b/IISMainHandler/handlers/BoardsHandler.cs index 739bbb6..f4f5461 100644 --- a/IISMainHandler/handlers/BoardsHandler.cs +++ b/IISMainHandler/handlers/BoardsHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers { - class BoardsHandler : AbstractGetHandler { + class BoardsHandler : AbstractGetHandler { override protected string templateName { get { diff --git a/IISMainHandler/handlers/PostHandler.cs b/IISMainHandler/handlers/PostHandler.cs index 86783af..499c89b 100644 --- a/IISMainHandler/handlers/PostHandler.cs +++ b/IISMainHandler/handlers/PostHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers { - class PostHandler : AbstractGetHandler { + class PostHandler : AbstractGetHandler { override protected string templateName { get { @@ -19,7 +19,7 @@ namespace FLocal.IISHandler.handlers { } override protected IEnumerable getSpecificData(WebContext context) { - Post post = Post.LoadById(int.Parse(context.requestParts[1])); + Post post = this.url.post; int lastReadId = 0; if(context.session != null) { diff --git a/IISMainHandler/handlers/StaticHandler.cs b/IISMainHandler/handlers/StaticHandler.cs index bc42cb8..1753dd0 100644 --- a/IISMainHandler/handlers/StaticHandler.cs +++ b/IISMainHandler/handlers/StaticHandler.cs @@ -8,28 +8,26 @@ using System.IO; using FLocal.Core; namespace FLocal.IISHandler.handlers { - class StaticHandler : ISpecificHandler { + class StaticHandler : AbstractGetHandler { - private string[] requestParts; - - public StaticHandler(string[] requestParts) { - this.requestParts = requestParts; + protected override string templateName { + get { + return null; + } } - public void Handle(WebContext context) { - if(this.requestParts.Length < 2) { - //throw new HttpException(403, "listing not allowed"); - throw new WrongUrlException(); - } - + protected override IEnumerable getSpecificData(WebContext context) { + + string[] requestParts = this.url.remainder.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + Regex checker = new Regex("^[a-z][0-9a-z\\-_]*(\\.[a-zA-Z]+)?$", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline); string path = ""; - for(int i=1; i { override protected string templateName { get { @@ -21,14 +21,14 @@ namespace FLocal.IISHandler.handlers { } override protected IEnumerable getSpecificData(WebContext context) { - Thread thread = Thread.LoadById(int.Parse(context.requestParts[1])); - PageOuter pageOuter = PageOuter.createFromGet( - context.requestParts, + Thread thread = this.url.thread; + PageOuter pageOuter = PageOuter.createFromUrl( + this.url, context.userSettings.postsPerPage, - new Dictionary> { + new Dictionary> { { 'p', - () => Config.instance.mainConnection.GetCountByConditions( + s => Config.instance.mainConnection.GetCountByConditions( Post.TableSpec.instance, new ComplexCondition( ConditionsJoinType.AND, @@ -40,13 +40,12 @@ namespace FLocal.IISHandler.handlers { new ComparisonCondition( Post.TableSpec.instance.getIdSpec(), ComparisonType.LESSTHAN, - int.Parse(context.requestParts[2].PHPSubstring(1)).ToString() + int.Parse(s).ToString() ) ) ) } - }, - 2 + } ); IEnumerable posts = thread.getPosts(pageOuter, pageOuter.ascendingDirection); diff --git a/IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs b/IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs index fda7f04..53b5951 100644 --- a/IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs +++ b/IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs @@ -15,10 +15,13 @@ namespace FLocal.IISHandler.handlers.request { class MarkThreadAsReadHandler : ReturnPostHandler { protected override void _Do(WebContext context) { + + string[] requestParts = context.httprequest.Path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + Account account = context.session.account; - Thread thread = Thread.LoadById(int.Parse(context.requestParts[2])); - if(!context.requestParts[3].StartsWith("p")) throw new WrongUrlException(); //throw new CriticalException("wrong url"); - Post post = Post.LoadById(int.Parse(context.requestParts[3].PHPSubstring(1))); + Thread thread = Thread.LoadById(int.Parse(requestParts[2])); + if(!requestParts[3].StartsWith("p")) throw new WrongUrlException(); //throw new CriticalException("wrong url"); + Post post = Post.LoadById(int.Parse(requestParts[3].PHPSubstring(1))); if(post.thread.id != thread.id) throw new CriticalException("id mismatch"); diff --git a/IISMainHandler/handlers/response/AbstractNewMessageHandler.cs b/IISMainHandler/handlers/response/AbstractNewMessageHandler.cs index 2a4d5b2..121d326 100644 --- a/IISMainHandler/handlers/response/AbstractNewMessageHandler.cs +++ b/IISMainHandler/handlers/response/AbstractNewMessageHandler.cs @@ -7,7 +7,7 @@ using FLocal.Core; using FLocal.Common; namespace FLocal.IISHandler.handlers.response { - abstract class AbstractNewMessageHandler : AbstractGetHandler { + abstract class AbstractNewMessageHandler : AbstractGetHandler where TUrl : FLocal.Common.URL.AbstractUrl { abstract protected IEnumerable getSpecificNewMessageData(WebContext context); @@ -20,7 +20,7 @@ namespace FLocal.IISHandler.handlers.response { result.Add(new XElement("bodyUBB", context.httprequest.Form["Body"])); result.Add(new XElement("bodyIntermediate", context.outputParams.preprocessBodyIntermediate(UBBParser.UBBToIntermediate(context.httprequest.Form["Body"])))); } - return result.Union(this.getSpecificNewMessageData(context)); + return result.Concat(this.getSpecificNewMessageData(context)); } } diff --git a/IISMainHandler/handlers/response/AbstractUserGetHandler.cs b/IISMainHandler/handlers/response/AbstractUserGetHandler.cs index 13fe425..790b43a 100644 --- a/IISMainHandler/handlers/response/AbstractUserGetHandler.cs +++ b/IISMainHandler/handlers/response/AbstractUserGetHandler.cs @@ -12,20 +12,12 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - abstract class AbstractUserGetHandler : AbstractGetHandler { + abstract class AbstractUserGetHandler : AbstractGetHandler where TUrl : FLocal.Common.URL.users.user.Abstract { abstract protected IEnumerable getUserSpecificData(WebContext context, User user); sealed override protected IEnumerable getSpecificData(WebContext context) { - User user; - { - int userId; - if(int.TryParse(context.requestParts[2], out userId)) { - user = User.LoadById(userId); - } else { - user = User.LoadByName(context.requestParts[2]); - } - } + User user = this.url.user; Account account = null; if(context.session != null) { try { @@ -44,7 +36,7 @@ namespace FLocal.IISHandler.handlers.response { user.exportToXmlForViewing(context), (account == null) ? null : new XElement("accountId", account.id.ToString()), //for PM history, PM send etc (lastSession == null) ? null : new XElement("lastActivity", lastSession.lastHumanActivity.ToXml()), - }.Union(this.getUserSpecificData(context, user)); + }.Concat(this.getUserSpecificData(context, user)); } } diff --git a/IISMainHandler/handlers/response/ActiveAccountListHandler.cs b/IISMainHandler/handlers/response/ActiveAccountListHandler.cs index e0e99b0..30e35f7 100644 --- a/IISMainHandler/handlers/response/ActiveAccountListHandler.cs +++ b/IISMainHandler/handlers/response/ActiveAccountListHandler.cs @@ -11,7 +11,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class ActiveAccountListHandler : AbstractGetHandler { + class ActiveAccountListHandler : AbstractGetHandler { override protected string templateName { get { @@ -20,7 +20,6 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificData(WebContext context) { - //PageOuter pageOuter = PageOuter.createFromGet(context.requestParts, context.userSettings.usersPerPage, 1); PageOuter pageOuter = PageOuter.createUnlimited(context.userSettings.usersPerPage); IEnumerable accounts = Account.LoadByIds( from stringId in Config.instance.mainConnection.LoadIdsByConditions( diff --git a/IISMainHandler/handlers/response/AllPostsHandler.cs b/IISMainHandler/handlers/response/AllPostsHandler.cs index 17d28a5..9dfa537 100644 --- a/IISMainHandler/handlers/response/AllPostsHandler.cs +++ b/IISMainHandler/handlers/response/AllPostsHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class AllPostsHandler : AbstractGetHandler { + class AllPostsHandler : AbstractGetHandler { override protected string templateName { get { @@ -21,11 +21,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificData(WebContext context) { - PageOuter pageOuter = PageOuter.createFromGet( - context.requestParts, - context.userSettings.postsPerPage, - 1 - ); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.postsPerPage); IEnumerable posts = Post.LoadByIds( from stringId in Config.instance.mainConnection.LoadIdsByConditions( diff --git a/IISMainHandler/handlers/response/AllThreadsHandler.cs b/IISMainHandler/handlers/response/AllThreadsHandler.cs index ded85e3..07995c9 100644 --- a/IISMainHandler/handlers/response/AllThreadsHandler.cs +++ b/IISMainHandler/handlers/response/AllThreadsHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class AllThreadsHandler : AbstractGetHandler { + class AllThreadsHandler : AbstractGetHandler { override protected string templateName { get { @@ -21,11 +21,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificData(WebContext context) { - PageOuter pageOuter = PageOuter.createFromGet( - context.requestParts, - context.userSettings.threadsPerPage, - 1 - ); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.threadsPerPage); IEnumerable threads = Thread.LoadByIds( from stringId in Config.instance.mainConnection.LoadIdsByConditions( diff --git a/IISMainHandler/handlers/response/AvatarsSettingsHandler.cs b/IISMainHandler/handlers/response/AvatarsSettingsHandler.cs index af51875..8178415 100644 --- a/IISMainHandler/handlers/response/AvatarsSettingsHandler.cs +++ b/IISMainHandler/handlers/response/AvatarsSettingsHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class AvatarsSettingsHandler : AbstractGetHandler { + class AvatarsSettingsHandler : AbstractGetHandler { override protected string templateName { get { diff --git a/IISMainHandler/handlers/response/BoardAsThread.cs b/IISMainHandler/handlers/response/BoardAsThread.cs index 34fdfd1..63dd555 100644 --- a/IISMainHandler/handlers/response/BoardAsThread.cs +++ b/IISMainHandler/handlers/response/BoardAsThread.cs @@ -10,7 +10,7 @@ using FLocal.Core.DB; namespace FLocal.IISHandler.handlers.response { - class BoardAsThreadHandler : AbstractGetHandler { + class BoardAsThreadHandler : AbstractGetHandler { override protected string templateName { get { @@ -19,8 +19,8 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificData(WebContext context) { - Board board = Board.LoadById(int.Parse(context.requestParts[1])); - PageOuter pageOuter = PageOuter.createFromGet(context.requestParts, context.userSettings.postsPerPage, 2); + Board board = this.url.board; + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.postsPerPage); IEnumerable threads = board.getThreads( pageOuter, new SortSpec[] { diff --git a/IISMainHandler/handlers/response/ConversationHandler.cs b/IISMainHandler/handlers/response/ConversationHandler.cs index 7d20a2d..3fc6e5b 100644 --- a/IISMainHandler/handlers/response/ConversationHandler.cs +++ b/IISMainHandler/handlers/response/ConversationHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class ConversationHandler : AbstractGetHandler { + class ConversationHandler : AbstractGetHandler { override protected string templateName { get { @@ -21,15 +21,15 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificData(WebContext context) { - Account interlocutor = Account.LoadById(int.Parse(context.requestParts[3])); + Account interlocutor = this.url.interlocutor; PMConversation conversation = PMConversation.LoadByAccounts(context.session.account, interlocutor); - PageOuter pageOuter = PageOuter.createFromGet( - context.requestParts, + PageOuter pageOuter = PageOuter.createFromUrl( + this.url, context.userSettings.postsPerPage, - new Dictionary> { + new Dictionary> { { 'p', - () => Config.instance.mainConnection.GetCountByConditions( + s => Config.instance.mainConnection.GetCountByConditions( PMMessage.TableSpec.instance, new ComplexCondition( ConditionsJoinType.AND, @@ -46,13 +46,12 @@ namespace FLocal.IISHandler.handlers.response { new ComparisonCondition( PMMessage.TableSpec.instance.getIdSpec(), ComparisonType.LESSTHAN, - int.Parse(context.requestParts[4].PHPSubstring(1)).ToString() + int.Parse(s).ToString() ) ) ) } - }, - 4 + } ); IEnumerable messages = conversation.getMessages(pageOuter, context, pageOuter.ascendingDirection); diff --git a/IISMainHandler/handlers/response/ConversationsHandler.cs b/IISMainHandler/handlers/response/ConversationsHandler.cs index 09863fa..a585765 100644 --- a/IISMainHandler/handlers/response/ConversationsHandler.cs +++ b/IISMainHandler/handlers/response/ConversationsHandler.cs @@ -11,7 +11,7 @@ using FLocal.Core.DB; namespace FLocal.IISHandler.handlers.response { - class ConversationsHandler : AbstractGetHandler { + class ConversationsHandler : AbstractGetHandler { override protected string templateName { get { @@ -20,7 +20,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificData(WebContext context) { - PageOuter pageOuter = PageOuter.createFromGet(context.requestParts, context.userSettings.threadsPerPage, 2); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.threadsPerPage); IEnumerable conversations = PMConversation.getConversations(context.session.account, pageOuter, pageOuter.descendingDirection); XElement[] result = new XElement[] { new XElement("conversations", diff --git a/IISMainHandler/handlers/response/CreatePollHandler.cs b/IISMainHandler/handlers/response/CreatePollHandler.cs index dcc1888..f4e8960 100644 --- a/IISMainHandler/handlers/response/CreatePollHandler.cs +++ b/IISMainHandler/handlers/response/CreatePollHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class CreatePollHandler : AbstractGetHandler { + class CreatePollHandler : AbstractGetHandler { override protected string templateName { get { diff --git a/IISMainHandler/handlers/response/CreateThreadHandler.cs b/IISMainHandler/handlers/response/CreateThreadHandler.cs index 3a13c9a..3a6fd6c 100644 --- a/IISMainHandler/handlers/response/CreateThreadHandler.cs +++ b/IISMainHandler/handlers/response/CreateThreadHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class CreateThreadHandler : AbstractNewMessageHandler { + class CreateThreadHandler : AbstractNewMessageHandler { override protected string templateName { get { @@ -19,7 +19,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificNewMessageData(WebContext context) { - Board board = Board.LoadById(int.Parse(context.requestParts[1])); + Board board = this.url.board; return new XElement[] { board.exportToXml(context, Board.SubboardsOptions.None), diff --git a/IISMainHandler/handlers/response/EditHandler.cs b/IISMainHandler/handlers/response/EditHandler.cs index cbd72d9..42b33d3 100644 --- a/IISMainHandler/handlers/response/EditHandler.cs +++ b/IISMainHandler/handlers/response/EditHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class EditHandler : AbstractNewMessageHandler { + class EditHandler : AbstractNewMessageHandler { override protected string templateName { get { @@ -19,7 +19,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificNewMessageData(WebContext context) { - Post post = Post.LoadById(int.Parse(context.requestParts[1])); + Post post = this.url.post; return new XElement[] { post.thread.board.exportToXml(context, Board.SubboardsOptions.None), diff --git a/IISMainHandler/handlers/response/LegacyPHPHandler.cs b/IISMainHandler/handlers/response/LegacyPHPHandler.cs deleted file mode 100644 index 515e6fe..0000000 --- a/IISMainHandler/handlers/response/LegacyPHPHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FLocal.Core; -using FLocal.Common; -using FLocal.Common.dataobjects; - -namespace FLocal.IISHandler.handlers.response { - class LegacyPHPHandler : RedirectGetHandler { - - protected override string getRedirectUrl(WebContext context) { - string[] scriptParts = context.requestParts[0].Split('.'); - if(scriptParts.Length != 2) { - //throw new FLocalException("wrong url"); - throw new WrongUrlException(); - } - if(scriptParts[1].ToLower() != "php") { - //throw new FLocalException("wrong url"); - throw new WrongUrlException(); - } - - switch(scriptParts[0].ToLower()) { - case "showflat": - case "ashowflat": - Post post = Post.LoadById(int.Parse(context.httprequest.QueryString["Number"])); - return "/Thread/" + post.thread.id.ToString() + "/p" + post.id.ToString(); - case "showthreaded": - case "ashowthreaded": - return "/Post/" + int.Parse(context.httprequest.QueryString["Number"]).ToString() + "/"; - case "postlist": - return "/Board/" + Board.LoadByLegacyName(context.httprequest.QueryString["Board"]).id.ToString() + "/"; - case "showprofile": - return "/User/" + User.LoadByName(context.httprequest.QueryString["User"]).id.ToString() + "/"; - default: - //throw new NotImplementedException("unknown script " + scriptParts[0]); - throw new WrongUrlException(); - } - } - - } -} diff --git a/IISMainHandler/handlers/response/LegacyUploadHandler.cs b/IISMainHandler/handlers/response/LegacyUploadHandler.cs deleted file mode 100644 index 0d733d7..0000000 --- a/IISMainHandler/handlers/response/LegacyUploadHandler.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FLocal.Core; -using FLocal.Common; - -namespace FLocal.IISHandler.handlers.response { - class LegacyUploadHandler : RedirectGetHandler { - - protected override string getRedirectUrl(WebContext context) { - if(context.requestParts.Length != 3) throw new WrongUrlException();// throw new FLocalException("wrong url"); - string[] parts = context.requestParts[2].Split('.'); - if(parts.Length != 2) throw new WrongUrlException();// throw new FLocalException("wrong url"); - if(parts[0].PHPSubstring(0, 4).ToLower() != "file") throw new WrongUrlException();// throw new FLocalException("wrong url"); - int rawFileNum = int.Parse(parts[0].PHPSubstring(4)); - int fileNum; - switch(parts[1].ToLower()) { - case "jpg": - fileNum = rawFileNum; - break; - case "gif": - fileNum = 500000 + rawFileNum; - break; - case "png": - fileNum = 600000 + rawFileNum; - break; - default: - //throw new FLocalException("wrong url"); - throw new WrongUrlException(); - } - return "/Upload/Item/" + fileNum + "/"; - } - - } -} diff --git a/IISMainHandler/handlers/response/LocalNetworksListHandler.cs b/IISMainHandler/handlers/response/LocalNetworksListHandler.cs index ffa1f48..76f4b58 100644 --- a/IISMainHandler/handlers/response/LocalNetworksListHandler.cs +++ b/IISMainHandler/handlers/response/LocalNetworksListHandler.cs @@ -11,7 +11,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class LocalNetworksListHandler : AbstractGetHandler { + class LocalNetworksListHandler : AbstractGetHandler { override protected string templateName { get { diff --git a/IISMainHandler/handlers/response/LoginHandler.cs b/IISMainHandler/handlers/response/LoginHandler.cs index 3b680eb..a2e2e07 100644 --- a/IISMainHandler/handlers/response/LoginHandler.cs +++ b/IISMainHandler/handlers/response/LoginHandler.cs @@ -8,7 +8,7 @@ using System.Xml.Linq; using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class LoginHandler : AbstractGetHandler { + class LoginHandler : AbstractGetHandler { protected override string templateName { get { diff --git a/IISMainHandler/handlers/response/MigrateAccountHandler.cs b/IISMainHandler/handlers/response/MigrateAccountHandler.cs index c8eabea..d9daf33 100644 --- a/IISMainHandler/handlers/response/MigrateAccountHandler.cs +++ b/IISMainHandler/handlers/response/MigrateAccountHandler.cs @@ -8,7 +8,7 @@ using System.Xml.Linq; using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class MigrateAccountHandler : AbstractGetHandler { + class MigrateAccountHandler : AbstractGetHandler { protected override string templateName { get { @@ -21,10 +21,10 @@ namespace FLocal.IISHandler.handlers.response { if(context.httprequest.Form["username"] != null && context.httprequest.Form["username"] != "") { username = context.httprequest.Form["username"]; } else { - if(context.requestParts.Length != 4) { + if(string.IsNullOrEmpty(this.url.remainder)) { throw new CriticalException("Username is not specified"); } - username = context.requestParts[3]; + username = this.url.remainder; } Account account = Account.LoadByName(username); if(!account.needsMigration) throw new FLocalException("Already migrated"); diff --git a/IISMainHandler/handlers/response/PMReplyHandler.cs b/IISMainHandler/handlers/response/PMReplyHandler.cs index e905706..dab39b7 100644 --- a/IISMainHandler/handlers/response/PMReplyHandler.cs +++ b/IISMainHandler/handlers/response/PMReplyHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class PMReplyHandler : AbstractNewMessageHandler { + class PMReplyHandler : AbstractNewMessageHandler { override protected string templateName { get { @@ -19,7 +19,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificNewMessageData(WebContext context) { - PMMessage message = PMMessage.LoadById(int.Parse(context.requestParts[3])); + PMMessage message = this.url.pm; string quoted = UBBParser.StripQuotes(message.bodyUBB).Trim(); return new XElement[] { message.exportToXml(context), diff --git a/IISMainHandler/handlers/response/PMReplyToPostHandler.cs b/IISMainHandler/handlers/response/PMReplyToPostHandler.cs index 648d67a..16d400c 100644 --- a/IISMainHandler/handlers/response/PMReplyToPostHandler.cs +++ b/IISMainHandler/handlers/response/PMReplyToPostHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class PMReplyToPostHandler : AbstractNewMessageHandler { + class PMReplyToPostHandler : AbstractNewMessageHandler { override protected string templateName { get { @@ -20,7 +20,7 @@ namespace FLocal.IISHandler.handlers.response { override protected IEnumerable getSpecificNewMessageData(WebContext context) { - Post post = Post.LoadById(int.Parse(context.requestParts[1])); + Post post = this.url.post; Account receiver = Account.LoadByUser(post.poster); if(receiver.needsMigration) throw new ApplicationException("User is not migrated"); diff --git a/IISMainHandler/handlers/response/PMSendHandler.cs b/IISMainHandler/handlers/response/PMSendHandler.cs index 48a70ea..c88552a 100644 --- a/IISMainHandler/handlers/response/PMSendHandler.cs +++ b/IISMainHandler/handlers/response/PMSendHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class PMSendHandler : AbstractNewMessageHandler { + class PMSendHandler : AbstractNewMessageHandler { override protected string templateName { get { @@ -19,8 +19,8 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificNewMessageData(WebContext context) { - if(context.requestParts.Length > 3) { - Account receiver = Account.LoadById(int.Parse(context.requestParts[3])); + if(!string.IsNullOrEmpty(this.url.remainder)) { + Account receiver = Account.LoadById(int.Parse(this.url.remainder)); if(receiver.needsMigration) throw new ApplicationException("User is not migrated"); return new XElement[] { new XElement("receiver", receiver.exportToXml(context)), diff --git a/IISMainHandler/handlers/response/PollHandler.cs b/IISMainHandler/handlers/response/PollHandler.cs index 151a564..a0e9b8b 100644 --- a/IISMainHandler/handlers/response/PollHandler.cs +++ b/IISMainHandler/handlers/response/PollHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class PollHandler : AbstractGetHandler { + class PollHandler : AbstractGetHandler { override protected string templateName { get { @@ -21,7 +21,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificData(WebContext context) { - Poll poll = Poll.LoadById(int.Parse(context.requestParts[1])); + Poll poll = this.url.poll; return new XElement[] { poll.exportToXmlWithVotes(context) }; diff --git a/IISMainHandler/handlers/response/PunishHandler.cs b/IISMainHandler/handlers/response/PunishHandler.cs index 3dba876..58bd645 100644 --- a/IISMainHandler/handlers/response/PunishHandler.cs +++ b/IISMainHandler/handlers/response/PunishHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class PunishHandler : AbstractNewMessageHandler { + class PunishHandler : AbstractNewMessageHandler { override protected string templateName { get { @@ -19,7 +19,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificNewMessageData(WebContext context) { - Post post = Post.LoadById(int.Parse(context.requestParts[1])); + Post post = this.url.post; if(!Moderator.isModerator(context.account, post.thread)) throw new FLocalException(context.account.id + " is not a moderator in board " + post.thread.board.id); diff --git a/IISMainHandler/handlers/response/QuickLinkHandler.cs b/IISMainHandler/handlers/response/QuickLinkHandler.cs index edda726..bf3b2e2 100644 --- a/IISMainHandler/handlers/response/QuickLinkHandler.cs +++ b/IISMainHandler/handlers/response/QuickLinkHandler.cs @@ -7,10 +7,10 @@ using FLocal.Common; using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class QuickLinkHandler : RedirectGetHandler { + class QuickLinkHandler : RedirectGetHandler { protected override string getRedirectUrl(WebContext context) { - return QuickLink.LoadByName(context.requestParts[1]).url; + return this.url.link.url; } } diff --git a/IISMainHandler/handlers/response/RedirectGetHandler.cs b/IISMainHandler/handlers/response/RedirectGetHandler.cs index 295578d..30d5a59 100644 --- a/IISMainHandler/handlers/response/RedirectGetHandler.cs +++ b/IISMainHandler/handlers/response/RedirectGetHandler.cs @@ -5,7 +5,7 @@ using System.Text; using System.Xml.Linq; namespace FLocal.IISHandler.handlers.response { - abstract class RedirectGetHandler : AbstractGetHandler { + abstract class RedirectGetHandler : AbstractGetHandler where TUrl : FLocal.Common.URL.AbstractUrl { protected override string templateName { get { diff --git a/IISMainHandler/handlers/response/RegisterByInviteHandler.cs b/IISMainHandler/handlers/response/RegisterByInviteHandler.cs index 74d0471..43f753e 100644 --- a/IISMainHandler/handlers/response/RegisterByInviteHandler.cs +++ b/IISMainHandler/handlers/response/RegisterByInviteHandler.cs @@ -7,7 +7,7 @@ using FLocal.Core; using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class RegisterByInviteHandler : AbstractGetHandler { + class RegisterByInviteHandler : AbstractGetHandler { protected override string templateName { get { @@ -16,8 +16,9 @@ namespace FLocal.IISHandler.handlers.response { } protected override IEnumerable getSpecificData(WebContext context) { - int inviteId = int.Parse(context.requestParts[3]); - string code = context.requestParts[4]; + string[] parts = this.url.remainder.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + int inviteId = int.Parse(parts[0]); + string code = parts[1]; Invite invite = Invite.LoadById(inviteId); if(invite.isUsed) throw new FLocalException("Invite is already used"); if(invite.code != code) throw new FLocalException("Code mismatch"); diff --git a/IISMainHandler/handlers/response/ReplyHandler.cs b/IISMainHandler/handlers/response/ReplyHandler.cs index 805fa27..ca5f4a7 100644 --- a/IISMainHandler/handlers/response/ReplyHandler.cs +++ b/IISMainHandler/handlers/response/ReplyHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class ReplyHandler : AbstractNewMessageHandler { + class ReplyHandler : AbstractNewMessageHandler { override protected string templateName { get { @@ -20,7 +20,7 @@ namespace FLocal.IISHandler.handlers.response { override protected IEnumerable getSpecificNewMessageData(WebContext context) { - Post post = Post.LoadById(int.Parse(context.requestParts[1])); + Post post = this.url.post; string quoted = context.httprequest.Form["data"]; if(quoted != null) quoted = quoted.Trim(); diff --git a/IISMainHandler/handlers/response/RobotsHandler.cs b/IISMainHandler/handlers/response/RobotsHandler.cs index 3c67a11..42e3d36 100644 --- a/IISMainHandler/handlers/response/RobotsHandler.cs +++ b/IISMainHandler/handlers/response/RobotsHandler.cs @@ -8,18 +8,22 @@ using System.IO; using FLocal.Core; namespace FLocal.IISHandler.handlers.response { - class RobotsHandler : ISpecificHandler { + class RobotsHandler : AbstractGetHandler { - public RobotsHandler() { + protected override string templateName { + get { + return null; + } } - public void Handle(WebContext context) { + protected override IEnumerable getSpecificData(WebContext context) { context.httpresponse.ContentType = "text/plain"; context.httpresponse.WriteLine("User-agent: *"); context.httpresponse.WriteLine("Disallow: /"); foreach(var subnet in context.remoteHost.matchingSubnets) { context.httpresponse.WriteLine(subnet.ToString()); } + throw new SkipXsltTransformException(); } } diff --git a/IISMainHandler/handlers/response/SettingsHandler.cs b/IISMainHandler/handlers/response/SettingsHandler.cs index f194833..a49d469 100644 --- a/IISMainHandler/handlers/response/SettingsHandler.cs +++ b/IISMainHandler/handlers/response/SettingsHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class SettingsHandler : AbstractGetHandler { + class SettingsHandler : AbstractGetHandler { override protected string templateName { get { diff --git a/IISMainHandler/handlers/response/SkipXsltTransformException.cs b/IISMainHandler/handlers/response/SkipXsltTransformException.cs new file mode 100644 index 0000000..e572764 --- /dev/null +++ b/IISMainHandler/handlers/response/SkipXsltTransformException.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.IISHandler.handlers.response { + class SkipXsltTransformException : ApplicationException { + } +} diff --git a/IISMainHandler/handlers/response/UploadHandler.cs b/IISMainHandler/handlers/response/UploadHandler.cs index 1de3cc8..21eb05f 100644 --- a/IISMainHandler/handlers/response/UploadHandler.cs +++ b/IISMainHandler/handlers/response/UploadHandler.cs @@ -10,7 +10,7 @@ using FLocal.Core.DB; using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UploadHandler : AbstractGetHandler { + class UploadHandler : RedirectGetHandler { protected override string templateName { get { @@ -18,9 +18,8 @@ namespace FLocal.IISHandler.handlers.response { } } - protected override IEnumerable getSpecificData(WebContext context) { - Upload upload = Upload.LoadById(int.Parse(context.requestParts[2])); - throw new RedirectException(Config.instance.UploaderUrl + "Data/" + upload.hash + "." + upload.extension); + protected override string getRedirectUrl(WebContext context) { + return Config.instance.UploaderUrl + "Data/" + this.url.upload.hash + "." + this.url.upload.extension; } } diff --git a/IISMainHandler/handlers/response/UploadListHandler.cs b/IISMainHandler/handlers/response/UploadListHandler.cs index e15b192..9c53595 100644 --- a/IISMainHandler/handlers/response/UploadListHandler.cs +++ b/IISMainHandler/handlers/response/UploadListHandler.cs @@ -10,7 +10,7 @@ using FLocal.Core.DB; using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UploadListHandler : AbstractGetHandler { + class UploadListHandler : AbstractGetHandler { protected override string templateName { get { @@ -20,7 +20,7 @@ namespace FLocal.IISHandler.handlers.response { protected override IEnumerable getSpecificData(WebContext context) { if(context.session == null) throw new AccessViolationException(); - PageOuter pageOuter = PageOuter.createFromGet(context.requestParts, context.userSettings.uploadsPerPage, 2); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.uploadsPerPage); List uploads = Upload.LoadByIds( from stringId in Config.instance.mainConnection.LoadIdsByConditions( Upload.TableSpec.instance, diff --git a/IISMainHandler/handlers/response/UploadNewHandler.cs b/IISMainHandler/handlers/response/UploadNewHandler.cs index d4b4a04..2a7bebe 100644 --- a/IISMainHandler/handlers/response/UploadNewHandler.cs +++ b/IISMainHandler/handlers/response/UploadNewHandler.cs @@ -10,7 +10,7 @@ using FLocal.Core.DB; using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UploadNewHandler : AbstractGetHandler { + class UploadNewHandler : AbstractGetHandler { protected override string templateName { get { diff --git a/IISMainHandler/handlers/response/UserDataHandler.cs b/IISMainHandler/handlers/response/UserDataHandler.cs index 09e9ce9..c3ecf4e 100644 --- a/IISMainHandler/handlers/response/UserDataHandler.cs +++ b/IISMainHandler/handlers/response/UserDataHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class UserDataHandler : AbstractGetHandler { + class UserDataHandler : AbstractGetHandler { override protected string templateName { get { diff --git a/IISMainHandler/handlers/response/UserInfoHandler.cs b/IISMainHandler/handlers/response/UserInfoHandler.cs index 222ac9d..96828de 100644 --- a/IISMainHandler/handlers/response/UserInfoHandler.cs +++ b/IISMainHandler/handlers/response/UserInfoHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserInfoHandler : AbstractUserGetHandler { + class UserInfoHandler : AbstractUserGetHandler { override protected string templateName { get { diff --git a/IISMainHandler/handlers/response/UserListHandler.cs b/IISMainHandler/handlers/response/UserListHandler.cs index a745e29..4f755f5 100644 --- a/IISMainHandler/handlers/response/UserListHandler.cs +++ b/IISMainHandler/handlers/response/UserListHandler.cs @@ -10,7 +10,7 @@ using FLocal.Core.DB; namespace FLocal.IISHandler.handlers.response { - class UserListHandler : AbstractGetHandler { + class UserListHandler : AbstractGetHandler { override protected string templateName { get { @@ -19,7 +19,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getSpecificData(WebContext context) { - PageOuter pageOuter = PageOuter.createFromGet(context.requestParts, context.userSettings.usersPerPage, 2); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.usersPerPage); IEnumerable users = User.getUsers(pageOuter, pageOuter.ascendingDirection); return new XElement[] { new XElement("users", diff --git a/IISMainHandler/handlers/response/UserPollsParticipatedHandler.cs b/IISMainHandler/handlers/response/UserPollsParticipatedHandler.cs index e9d6cc5..7cc3f69 100644 --- a/IISMainHandler/handlers/response/UserPollsParticipatedHandler.cs +++ b/IISMainHandler/handlers/response/UserPollsParticipatedHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserPollsParticipatedHandler : AbstractUserGetHandler { + class UserPollsParticipatedHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -21,11 +21,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getUserSpecificData(WebContext context, User user) { - PageOuter pageOuter = PageOuter.createFromGet( - context.requestParts, - context.userSettings.postsPerPage, - 4 - ); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.postsPerPage); IEnumerable votes = Poll.Vote.LoadByIds( from stringId in Config.instance.mainConnection.LoadIdsByConditions( Poll.Vote.TableSpec.instance, diff --git a/IISMainHandler/handlers/response/UserPostsHandler.cs b/IISMainHandler/handlers/response/UserPostsHandler.cs index 9b994ba..b4441d5 100644 --- a/IISMainHandler/handlers/response/UserPostsHandler.cs +++ b/IISMainHandler/handlers/response/UserPostsHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserPostsHandler : AbstractUserGetHandler { + class UserPostsHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -21,11 +21,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getUserSpecificData(WebContext context, User user) { - PageOuter pageOuter = PageOuter.createFromGet( - context.requestParts, - context.userSettings.postsPerPage, - 4 - ); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.postsPerPage); IEnumerable posts = user.getPosts(pageOuter, pageOuter.descendingDirection); return new XElement[] { diff --git a/IISMainHandler/handlers/response/UserRepliesHandler.cs b/IISMainHandler/handlers/response/UserRepliesHandler.cs index cf87ccb..542edd6 100644 --- a/IISMainHandler/handlers/response/UserRepliesHandler.cs +++ b/IISMainHandler/handlers/response/UserRepliesHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserRepliesHandler : AbstractUserGetHandler { + class UserRepliesHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -21,11 +21,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getUserSpecificData(WebContext context, User user) { - PageOuter pageOuter = PageOuter.createFromGet( - context.requestParts, - context.userSettings.postsPerPage, - 4 - ); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.postsPerPage); IEnumerable posts = user.getReplies(pageOuter, pageOuter.descendingDirection); return new XElement[] { diff --git a/IISMainHandler/handlers/response/UserThreadsHandler.cs b/IISMainHandler/handlers/response/UserThreadsHandler.cs index 7ff8921..e9f517f 100644 --- a/IISMainHandler/handlers/response/UserThreadsHandler.cs +++ b/IISMainHandler/handlers/response/UserThreadsHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserThreadsHandler : AbstractUserGetHandler { + class UserThreadsHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -21,11 +21,7 @@ namespace FLocal.IISHandler.handlers.response { } override protected IEnumerable getUserSpecificData(WebContext context, User user) { - PageOuter pageOuter = PageOuter.createFromGet( - context.requestParts, - context.userSettings.postsPerPage, - 4 - ); + PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.postsPerPage); IEnumerable threads = user.getThreads(pageOuter, pageOuter.descendingDirection); return new XElement[] { diff --git a/IISMainHandler/handlers/response/WhoIsOnlineHandler.cs b/IISMainHandler/handlers/response/WhoIsOnlineHandler.cs index ea25ed2..4450204 100644 --- a/IISMainHandler/handlers/response/WhoIsOnlineHandler.cs +++ b/IISMainHandler/handlers/response/WhoIsOnlineHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class WhoIsOnlineHandler : AbstractGetHandler { + class WhoIsOnlineHandler : AbstractGetHandler { override protected string templateName { get { diff --git a/IISMainHandler/handlers/response/maintenance/CleanCacheHandler.cs b/IISMainHandler/handlers/response/maintenance/CleanCacheHandler.cs index 21837c8..b300687 100644 --- a/IISMainHandler/handlers/response/maintenance/CleanCacheHandler.cs +++ b/IISMainHandler/handlers/response/maintenance/CleanCacheHandler.cs @@ -10,7 +10,7 @@ using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response.maintenance { - class CleanCacheHandler : AbstractGetHandler { + class CleanCacheHandler : AbstractGetHandler { override protected string templateName { get { diff --git a/templates/Full/Login.xslt b/templates/Full/Login.xslt index af59ddd..44a89cf 100644 --- a/templates/Full/Login.xslt +++ b/templates/Full/Login.xslt @@ -52,7 +52,7 @@ -
+ Ëîãèí

diff --git a/templates/Lite/Login.xslt b/templates/Lite/Login.xslt index 1c5fbff..fac4f6e 100644 --- a/templates/Lite/Login.xslt +++ b/templates/Lite/Login.xslt @@ -51,7 +51,7 @@ - + Ëîãèí