added: std::wstring Request::subdomain

support for subdomains



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@828 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-04-22 18:23:44 +00:00
parent bcea4f9464
commit baf10a9ba9
17 changed files with 110 additions and 11 deletions

View File

@ -446,6 +446,7 @@ void App::ReadRequest()
CheckRequestMethod();
CheckFCGIRole();
CheckSSL();
SetSubdomain();
LogAccess();
@ -531,6 +532,12 @@ void App::CheckSSL()
}
void App::SetSubdomain()
{
CreateSubdomain(config.base_url.c_str(), cur.request->env_http_host, cur.request->subdomain);
}
void App::LogAccess()
{
log.PutDate(log1);

View File

@ -146,6 +146,7 @@ private:
void CheckRequestMethod();
void CheckFCGIRole();
void CheckSSL();
void SetSubdomain();
void PrepareSessionCookie();
void AddDebugInfo(std::wstring & out);

View File

@ -711,4 +711,49 @@ void RemovePostFileTmp(PostFileTab & post_file_tab);
/*
short_str is removed from long_str (and a last dots are removed too)
and the result is stored in out
sample:
short_str: "mydomain.tld"
long_str: "www.subdomain.mydomain.tld"
out: "www.subdomain"
short_str: "mydomain.tld"
long_str: "otherdifferentstring"
out: ""
*/
template<class StringType1, class StringType2, class StringType3>
void CreateSubdomain(const StringType1 * short_str, const StringType2 * long_str, StringType3 & out)
{
size_t i1, i2;
out.clear();
for(i1=0 ; short_str[i1] != 0 ; ++i1);
for(i2=0 ; long_str[i2] != 0 ; ++i2);
if( i1 >= i2 )
return;
// i1 is < i2
while( i1-- > 0 )
{
i2 -= 1;
if( short_str[i1] != long_str[i2] )
return; // short_str is not a last substring of long_str
}
while( i2>0 && long_str[i2-1] == '.' )
i2 -= 1;
for(i1=0 ; i1 < i2 ; ++i1)
out += long_str[i1];
}
#endif

View File

@ -86,6 +86,8 @@ void Request::Clear()
start_time = 0;
memset(&start_tm, 0, sizeof(start_tm));
subdomain.clear();
}

View File

@ -133,6 +133,10 @@ struct Request
time_t start_time;
tm start_tm;
// a subdomain
// subdomain = HTTP_HOST environment variable - config->base_url
std::wstring subdomain;
Request();

View File

@ -126,6 +126,13 @@ bool ssl = false;
void System::RedirectTo(const Item & item, const wchar_t * postfix)
{
PutUrlProto(config->use_ssl, cur->request->redirect_to);
if( !cur->request->subdomain.empty() )
{
cur->request->redirect_to += cur->request->subdomain;
cur->request->redirect_to += '.';
}
cur->request->redirect_to += config->base_url;
if( item.type == Item::dir )
@ -152,6 +159,13 @@ void System::RedirectTo(const Item & item, const wchar_t * postfix)
void System::RedirectTo(long item_id, const wchar_t * postfix)
{
PutUrlProto(config->use_ssl, cur->request->redirect_to);
if( !cur->request->subdomain.empty() )
{
cur->request->redirect_to += cur->request->subdomain;
cur->request->redirect_to += '.';
}
cur->request->redirect_to += config->base_url;
Item * pdir = dirs.GetDir(item_id);
@ -193,6 +207,13 @@ void System::RedirectTo(long item_id, const wchar_t * postfix)
void System::RedirectTo(const wchar_t * url)
{
PutUrlProto(config->use_ssl, cur->request->redirect_to);
if( !cur->request->subdomain.empty() )
{
cur->request->redirect_to += cur->request->subdomain;
cur->request->redirect_to += '.';
}
cur->request->redirect_to += config->base_url;
if( url[0] == '/' )

View File

@ -153,7 +153,7 @@ void Notify::CreateItemLink(const Item & item, std::wstring & item_link, std::ws
{
dirs->MakePath(item.id, tmp_path);
item_link = config->url_proto;
item_link += config->base_url;
item_link += config->base_url; // !! IMPROVE ME what about subdomains?
item_link += tmp_path;
dir_link = item_link;
}
@ -161,7 +161,7 @@ void Notify::CreateItemLink(const Item & item, std::wstring & item_link, std::ws
{
dirs->MakePath(item.parent_id, tmp_path);
item_link = config->url_proto;
item_link += config->base_url;
item_link += config->base_url; // !! IMPROVE ME what about subdomains?
item_link += tmp_path;
dir_link = item_link;
item_link += item.url;
@ -175,7 +175,7 @@ void Notify::CreateActivateLink(const std::wstring & name, long code, std::wstri
wchar_t buff[50];
link = config->url_proto;
link += config->base_url;
link += config->base_url;// !! IMPROVE ME what about subdomains?
link += L"/pw/activate/login:";
UrlEncode(name, link, false);
link += L"/code:";
@ -188,7 +188,7 @@ void Notify::CreateResetPasswordLink(const std::wstring & name, long code, std::
wchar_t buff[50];
link = config->url_proto;
link += config->base_url;
link += config->base_url;// !! IMPROVE ME what about subdomains?
link += L"/pw/resetpassword/login:";
UrlEncode(name, link, false);
link += L"/code:";

View File

@ -170,7 +170,7 @@ void ExportInfo::SendFile(const Item & item, bool thumb)
{
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE;
msg.url = config->url_proto;
msg.url += config->base_url;
msg.url += config->base_url;// !! IMPROVE ME what about subdomains?
system->dirs.MakePath(item.parent_id, msg.url, false);
msg.url += item.url;
msg.path += L".php"; // !! do konfiga
@ -224,7 +224,7 @@ void ExportInfo::SendDir(const Item & item)
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE;
msg.url = config->url_proto;
msg.url += config->base_url;
msg.url += config->base_url;// !! IMPROVE ME what about subdomains?
system->dirs.MakePath(item.id, msg.url, false);
msg.path += L"index.html"; // !! do konfiga

View File

@ -78,7 +78,7 @@ void gallery_tab_subject(Info & i)
void gallery_tab_link(Info & i)
{
doc_proto(i);
i.out << config->base_url;
i.out << config->base_url;// !! IMPROVE ME what about subdomains?
gallery_tab_dir(i);
gallery_tab_url(i);
}

View File

@ -56,7 +56,7 @@ void CreateThread::SendNotify(const Item & item)
notify_msg.code = WINIX_NOTIFY_CODE_ADD;
notify_msg.template_index = thread_info->template_index;
notify_msg.dir_link = config->url_proto;
notify_msg.dir_link += config->base_url;
notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains?
system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false);
notify_msg.item_link = notify_msg.dir_link;
notify_msg.item_link += item.url;

View File

@ -62,7 +62,7 @@ void Reply::SendNotify(const Item & item)
notify_msg.code = WINIX_NOTIFY_CODE_REPLY;
notify_msg.template_index = thread_info->template_index;
notify_msg.dir_link = config->url_proto;
notify_msg.dir_link += config->base_url;
notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains?
system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false);
notify_msg.item_link = notify_msg.dir_link;
notify_msg.item_link += item.url;

View File

@ -62,7 +62,7 @@ void CreateTicket::AddTicket(Ticket & ticket, Item & item)
notify_msg.code = WINIX_NOTIFY_CODE_ADD;
notify_msg.template_index = ticket_info->template_index;
notify_msg.dir_link = config->url_proto;
notify_msg.dir_link += config->base_url;
notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains?
system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false);
notify_msg.item_link = notify_msg.dir_link;
notify_msg.item_link += item.url;

View File

@ -67,7 +67,7 @@ void EditTicket::ChangeTicket(Ticket & ticket, Item & item)
notify_msg.code = WINIX_NOTIFY_CODE_EDIT;
notify_msg.template_index = ticket_info->template_index;
notify_msg.dir_link = config->url_proto;
notify_msg.dir_link += config->base_url;
notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains?
system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false);
notify_msg.item_link = notify_msg.dir_link;
notify_msg.item_link += item.url;

View File

@ -275,6 +275,10 @@ void dir_tab_url(Info & i)
void dir_tab_link(Info & i)
{
doc_proto(i);
if( !cur->request->subdomain.empty() )
i.out << cur->request->subdomain << '.';
i.out << config->base_url;
for(size_t a = 0 ; a <= dir_index && a < cur->request->dir_tab.size() ; ++a)

View File

@ -75,6 +75,10 @@ void doc_proto_common(Info & i)
void doc_base_url(Info & i)
{
doc_proto(i);
if( !cur->request->subdomain.empty() )
i.out << cur->request->subdomain << '.';
i.out << config->base_url;
}

View File

@ -165,6 +165,10 @@ void item_url_is(Info & i)
void item_link(Info & i)
{
doc_proto(i);
if( !cur->request->subdomain.empty() )
i.out << cur->request->subdomain << '.';
i.out << config->base_url;
item_dir(i);
item_url(i);
@ -500,6 +504,10 @@ void item_tab_link(Info & i)
if( item_index < cur->request->item_tab.size() )
{
doc_proto(i);
if( !cur->request->subdomain.empty() )
i.out << cur->request->subdomain << '.';
i.out << config->base_url;
item_tab_dir(i);
item_tab_url(i);

View File

@ -22,6 +22,9 @@ void login_path(Info & i)
else
i.out << config->url_proto;
if( !cur->request->subdomain.empty() )
i.out << cur->request->subdomain << '.';
i.out << config->base_url;
if( system->HasReadExecAccessToPath(cur->request->dir_tab) )