@ -4,215 +4,71 @@ using System.Linq;
using System.Text ;
using System.Text ;
using System.Web ;
using System.Web ;
using FLocal.Core ;
using FLocal.Core ;
using FLocal.Common.URL ;
using URL = FLocal . Common . URL ;
namespace FLocal.IISHandler {
namespace FLocal.IISHandler {
class HandlersFactory {
class HandlersFactory {
public static ISpecificHandler getHandler ( WebContext context ) {
private static readonly Dictionary < Type , Func < AbstractUrl , ISpecificHandler > > handlersDictionary = new Dictionary < Type , Func < AbstractUrl , ISpecificHandler > > {
// if(!context.httprequest.Path.EndsWith("/")) {
{ typeof ( URL . forum . AllPosts ) , CreateHandler < URL . forum . AllPosts , handlers . response . AllPostsHandler > } ,
// return new handlers.WrongUrlHandler();
{ typeof ( URL . forum . AllThreads ) , CreateHandler < URL . forum . AllThreads , handlers . response . AllThreadsHandler > } ,
// throw new FLocalException("Malformed url");
{ typeof ( URL . forum . board . Headlines ) , CreateHandler < URL . forum . board . Headlines , handlers . response . BoardAsThreadHandler > } ,
// }
{ typeof ( URL . forum . board . NewThread ) , CreateHandler < URL . forum . board . NewThread , handlers . response . CreateThreadHandler > } ,
if ( context . requestParts . Length < 1 ) {
{ typeof ( URL . forum . board . thread . post . Edit ) , CreateHandler < URL . forum . board . thread . post . Edit , handlers . response . EditHandler > } ,
//return new handlers.RootHandler();
{ typeof ( URL . forum . board . thread . post . PMReply ) , CreateHandler < URL . forum . board . thread . post . PMReply , handlers . response . PMReplyToPostHandler > } ,
throw new RedirectException ( "/Boards/" ) ;
{ typeof ( URL . forum . board . thread . post . Punish ) , CreateHandler < URL . forum . board . thread . post . Punish , handlers . response . PunishHandler > } ,
}
{ typeof ( URL . forum . board . thread . post . Reply ) , CreateHandler < URL . forum . board . thread . post . Reply , handlers . response . ReplyHandler > } ,
{ typeof ( URL . forum . board . thread . post . Show ) , CreateHandler < URL . forum . board . thread . post . Show , handlers . PostHandler > } ,
#region legacy
{ typeof ( URL . forum . board . thread . Posts ) , CreateHandler < URL . forum . board . thread . Posts , handlers . ThreadHandler > } ,
if ( context . httprequest . Path . ToLower ( ) . StartsWith ( "/user/upload/" ) ) {
{ typeof ( URL . forum . board . Threads ) , CreateHandler < URL . forum . board . Threads , handlers . BoardHandler > } ,
return new handlers . response . LegacyUploadHandler ( ) ;
{ typeof ( URL . forum . Boards ) , CreateHandler < URL . forum . Boards , handlers . BoardsHandler > } ,
}
{ typeof ( URL . maintenance . CleanCache ) , CreateHandler < URL . maintenance . CleanCache , handlers . response . maintenance . CleanCacheHandler > } ,
if ( context . httprequest . Path . EndsWith ( ".php" ) ) {
{ typeof ( URL . maintenance . LocalNetworks ) , CreateHandler < URL . maintenance . LocalNetworks , handlers . response . LocalNetworksListHandler > } ,
return new handlers . response . LegacyPHPHandler ( ) ;
{ typeof ( URL . my . Avatars ) , CreateHandler < URL . my . Avatars , handlers . response . AvatarsSettingsHandler > } ,
}
{ typeof ( URL . my . conversations . Conversation ) , CreateHandler < URL . my . conversations . Conversation , handlers . response . ConversationHandler > } ,
if ( context . httprequest . Path . ToLower ( ) . StartsWith ( "/images/graemlins/" ) ) {
{ typeof ( URL . my . conversations . List ) , CreateHandler < URL . my . conversations . List , handlers . response . ConversationsHandler > } ,
throw new RedirectException ( "/static/smileys/" + context . requestParts [ 2 ] ) ;
{ typeof ( URL . my . conversations . NewPM ) , CreateHandler < URL . my . conversations . NewPM , handlers . response . PMSendHandler > } ,
}
{ typeof ( URL . my . conversations . Reply ) , CreateHandler < URL . my . conversations . Reply , handlers . response . PMReplyHandler > } ,
# endregion
{ typeof ( URL . my . login . Login ) , CreateHandler < URL . my . login . Login , handlers . response . LoginHandler > } ,
{ typeof ( URL . my . login . Migrate ) , CreateHandler < URL . my . login . Migrate , handlers . response . MigrateAccountHandler > } ,
{ typeof ( URL . my . login . RegisterByInvite ) , CreateHandler < URL . my . login . RegisterByInvite , handlers . response . RegisterByInviteHandler > } ,
{ typeof ( URL . my . Settings ) , CreateHandler < URL . my . Settings , handlers . response . SettingsHandler > } ,
{ typeof ( URL . my . UserData ) , CreateHandler < URL . my . UserData , handlers . response . UserDataHandler > } ,
{ typeof ( URL . polls . Info ) , CreateHandler < URL . polls . Info , handlers . response . PollHandler > } ,
{ typeof ( URL . polls . NewPoll ) , CreateHandler < URL . polls . NewPoll , handlers . response . CreatePollHandler > } ,
{ typeof ( URL . QuickLink ) , CreateHandler < URL . QuickLink , handlers . response . QuickLinkHandler > } ,
{ typeof ( URL . Robots ) , CreateHandler < URL . Robots , handlers . response . RobotsHandler > } ,
{ typeof ( URL . Static ) , CreateHandler < URL . Static , handlers . StaticHandler > } ,
{ typeof ( URL . upload . Item ) , CreateHandler < URL . upload . Item , handlers . response . UploadHandler > } ,
{ typeof ( URL . upload . List ) , CreateHandler < URL . upload . List , handlers . response . UploadListHandler > } ,
{ typeof ( URL . upload . New ) , CreateHandler < URL . upload . New , handlers . response . UploadNewHandler > } ,
{ typeof ( URL . users . Active ) , CreateHandler < URL . users . Active , handlers . response . ActiveAccountListHandler > } ,
{ typeof ( URL . users . All ) , CreateHandler < URL . users . All , handlers . response . UserListHandler > } ,
{ typeof ( URL . users . Online ) , CreateHandler < URL . users . Online , handlers . response . WhoIsOnlineHandler > } ,
{ typeof ( URL . users . user . Info ) , CreateHandler < URL . users . user . Info , handlers . response . UserInfoHandler > } ,
{ typeof ( URL . users . user . PollsParticipated ) , CreateHandler < URL . users . user . PollsParticipated , handlers . response . UserPollsParticipatedHandler > } ,
{ typeof ( URL . users . user . Posts ) , CreateHandler < URL . users . user . Posts , handlers . response . UserPostsHandler > } ,
{ typeof ( URL . users . user . Replies ) , CreateHandler < URL . users . user . Replies , handlers . response . UserRepliesHandler > } ,
{ typeof ( URL . users . user . Threads ) , CreateHandler < URL . users . user . Threads , handlers . response . UserThreadsHandler > } ,
} ;
#region robots
private static ISpecificHandler CreateHandler < TUrl , THandler > ( AbstractUrl url )
if ( context . httprequest . Path . ToLower ( ) . StartsWith ( "/robots.txt" ) ) {
where TUrl : AbstractUrl
return new handlers . response . RobotsHandler ( ) ;
where THandler : handlers . AbstractGetHandler < TUrl > , new ( )
{
return new THandler ( ) {
url = ( TUrl ) url
} ;
}
}
# endregion
switch ( context . requestParts [ 0 ] . ToLower ( ) ) {
public static ISpecificHandler getHandler ( WebContext context ) {
case "q" :
if ( context . httprequest . Path . ToLower ( ) . StartsWith ( "/do/" ) ) {
return new handlers . response . QuickLinkHandler ( ) ;
string action = context . httprequest . Path . ToLower ( ) . Substring ( 4 ) . Trim ( '/' ) ;
case "allposts" :
if ( action . StartsWith ( "markthreadasread" ) ) {
return new handlers . response . AllPostsHandler ( ) ;
return new handlers . request . MarkThreadAsReadHandler ( ) ;
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" :
switch ( action ) {
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" :
case "login" :
return new handlers . request . LoginHandler ( ) ;
return new handlers . request . LoginHandler ( ) ;
case "logout" :
case "logout" :
@ -237,45 +93,36 @@ namespace FLocal.IISHandler {
return new handlers . request . UserDataHandler ( ) ;
return new handlers . request . UserDataHandler ( ) ;
case "sendpm" :
case "sendpm" :
return new handlers . request . SendPMHandler ( ) ;
return new handlers . request . SendPMHandler ( ) ;
case "markthreadasread" :
return new handlers . request . MarkThreadAsReadHandler ( ) ;
case "upload" :
case "upload" :
return new handlers . request . UploadHandler ( ) ;
return new handlers . request . UploadHandler ( ) ;
case "newpoll" :
case "newpoll" :
return new handlers . request . CreatePollHandler ( ) ;
return new handlers . request . CreatePollHandler ( ) ;
case "vote" :
case "vote" :
return new handlers . request . VoteHandler ( ) ;
return new handlers . request . VoteHandler ( ) ;
case "avatars" :
case "avatars/add" :
if ( context . requestParts . Length < 3 ) {
return new handlers . WrongUrlHandler ( ) ;
}
switch ( context . requestParts [ 2 ] . ToLower ( ) ) {
case "add" :
return new handlers . request . avatars . AddHandler ( ) ;
return new handlers . request . avatars . AddHandler ( ) ;
case "remove" :
case "avatars/remove" :
return new handlers . request . avatars . RemoveHandler ( ) ;
return new handlers . request . avatars . RemoveHandler ( ) ;
case "setasdefault" :
case "avatars/setasdefault" :
return new handlers . request . avatars . SetAsDefaultHandler ( ) ;
return new handlers . request . avatars . SetAsDefaultHandler ( ) ;
default :
case "maintenance/cleancache" :
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 ( ) ;
return new handlers . request . maintenance . CleanCacheHandler ( ) ;
default :
default :
return new handlers . WrongUrlHandler ( ) ;
return new handlers . WrongUrlHandler ( ) ;
}
}
default :
return new handlers . WrongUrlHandler ( ) ;
}
}
}
default :
AbstractUrl url = UrlManager . Parse ( context . httprequest . Path , context . httprequest . QueryString , context . account ! = null ) ;
if ( url = = null ) {
return new handlers . WrongUrlHandler ( ) ;
return new handlers . WrongUrlHandler ( ) ;
}
}
if ( ! context . httprequest . Path . StartsWith ( url . canonical ) ) {
throw new RedirectException ( url . canonicalFull ) ;
}
return handlersDictionary [ url . GetType ( ) ] ( url ) ;
}
}
}
}