added: TextStream<> DbTextStream<> and HtmlTextStream<> have operator<<(Space&) now
added: to db: bool DbBase::AssertValueSpace(PGresult * r, int row, int col, Space & space, bool split_single)
added: environment variables for users
User::env (of type Space) and
User::aenv (of type Space) for admin variables (can be changed only by a super user)
added: winix function 'env'
for changing User::env and User::aenv ('env' winix function with a 'a' parameter)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@790 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -2,25 +2,25 @@
|
||||
|
||||
db.o: db.h dbbase.h dbconn.h dbtextstream.h ../core/textstream.h
|
||||
db.o: ../core/misc.h ../core/item.h ../core/confparser.h
|
||||
db.o: ../core/requesttypes.h ../core/error.h dbitemquery.h ../core/item.h
|
||||
db.o: dbitemcolumns.h ../core/confparser.h ../core/user.h ../core/group.h
|
||||
db.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/log.h
|
||||
db.o: ../core/textstream.h ../core/logmanipulators.h ../core/slog.h
|
||||
db.o: ../core/cur.h ../core/request.h ../core/error.h ../core/config.h
|
||||
db.o: ../core/htmlfilter.h ../templates/htmltextstream.h ../core/session.h
|
||||
db.o: ../core/user.h ../core/plugindata.h ../core/rebus.h ../core/mount.h
|
||||
db.o: ../templates/locale.h ../core/log.h ../core/misc.h
|
||||
db.o: ../core/requesttypes.h ../core/error.h ../core/confparser.h
|
||||
db.o: dbitemquery.h ../core/item.h dbitemcolumns.h ../core/user.h
|
||||
db.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
|
||||
db.o: ../core/log.h ../core/textstream.h ../core/logmanipulators.h
|
||||
db.o: ../core/slog.h ../core/cur.h ../core/request.h ../core/error.h
|
||||
db.o: ../core/config.h ../core/htmlfilter.h ../templates/htmltextstream.h
|
||||
db.o: ../core/session.h ../core/user.h ../core/plugindata.h ../core/rebus.h
|
||||
db.o: ../core/mount.h ../templates/locale.h ../core/log.h ../core/misc.h
|
||||
dbbase.o: dbbase.h dbconn.h dbtextstream.h ../core/textstream.h
|
||||
dbbase.o: ../core/misc.h ../core/item.h ../core/confparser.h
|
||||
dbbase.o: ../core/requesttypes.h ../core/error.h ../core/log.h ../core/misc.h
|
||||
dbbase.o: ../../ezc/src/utf8.h
|
||||
dbbase.o: ../core/requesttypes.h ../core/error.h ../core/confparser.h
|
||||
dbbase.o: ../core/log.h ../core/misc.h ../../ezc/src/utf8.h
|
||||
dbconn.o: dbconn.h dbtextstream.h ../core/textstream.h ../core/misc.h
|
||||
dbconn.o: ../core/item.h ../core/confparser.h ../core/requesttypes.h
|
||||
dbconn.o: ../core/log.h ../core/error.h
|
||||
dbitemcolumns.o: dbitemcolumns.h ../core/item.h ../core/confparser.h dbbase.h
|
||||
dbitemcolumns.o: dbconn.h dbtextstream.h ../core/textstream.h ../core/misc.h
|
||||
dbitemcolumns.o: dbitemcolumns.h ../core/item.h dbbase.h dbconn.h
|
||||
dbitemcolumns.o: dbtextstream.h ../core/textstream.h ../core/misc.h
|
||||
dbitemcolumns.o: ../core/item.h ../core/confparser.h ../core/requesttypes.h
|
||||
dbitemcolumns.o: ../core/error.h ../core/log.h
|
||||
dbitemcolumns.o: ../core/error.h ../core/confparser.h ../core/log.h
|
||||
dbitemquery.o: dbitemquery.h ../core/item.h
|
||||
dbtextstream.o: dbtextstream.h ../core/textstream.h ../core/misc.h
|
||||
dbtextstream.o: ../core/item.h ../core/confparser.h ../core/requesttypes.h
|
||||
|
||||
60
db/db.cpp
60
db/db.cpp
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* Copyright (c) 2008-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -68,8 +68,7 @@ return user_ok;
|
||||
|
||||
|
||||
|
||||
Error Db::AddUser(User & user, const std::wstring & password, const std::string & password_encrypted,
|
||||
int pass_type, bool pass_hash_salted)
|
||||
Error Db::AddUser(User & user, const UserPass & up)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error status = WINIX_ERR_OK;
|
||||
@@ -78,22 +77,25 @@ Error Db::AddUser(User & user, const std::wstring & password, const std::string
|
||||
{
|
||||
query.Clear();
|
||||
query << R("insert into core.user (login, password, pass_encrypted, super_user, email,"
|
||||
"notify, pass_type, pass_hash_salted) values (")
|
||||
"notify, pass_type, pass_hash_salted, env, aenv) values (")
|
||||
<< user.name;
|
||||
|
||||
// for safety
|
||||
if( password_encrypted.empty() )
|
||||
query << password;
|
||||
// for safety we put up.pass only if there is not an encrypted version
|
||||
// someone could have forgotten to clear up.pass
|
||||
if( up.pass_encrypted.empty() )
|
||||
query << up.pass;
|
||||
else
|
||||
query << "";
|
||||
|
||||
query.EPutBin(password_encrypted);
|
||||
query.EPutBin(up.pass_encrypted);
|
||||
|
||||
query << user.super_user
|
||||
<< user.email
|
||||
<< user.notify
|
||||
<< pass_type
|
||||
<< pass_hash_salted
|
||||
<< up.pass_type
|
||||
<< up.pass_hash_salted
|
||||
<< user.env
|
||||
<< user.aenv
|
||||
<< R(");");
|
||||
|
||||
r = AssertQuery(query);
|
||||
@@ -140,8 +142,31 @@ return DoCommand(query);
|
||||
}
|
||||
|
||||
|
||||
Error Db::ChangeUserEnv(long user_id, const Space & space)
|
||||
{
|
||||
query.Clear();
|
||||
query << R("update core.user set(env) = (")
|
||||
<< space
|
||||
<< R(") where id = ")
|
||||
<< user_id
|
||||
<< R(";");
|
||||
|
||||
return DoCommand(query);
|
||||
}
|
||||
|
||||
|
||||
Error Db::ChangeUserAdminEnv(long user_id, const Space & space)
|
||||
{
|
||||
query.Clear();
|
||||
query << R("update core.user set(aenv) = (")
|
||||
<< space
|
||||
<< R(") where id = ")
|
||||
<< user_id
|
||||
<< R(";");
|
||||
|
||||
return DoCommand(query);
|
||||
}
|
||||
|
||||
|
||||
//!! wywalic z nazwy 'Subject' nic nie jest robione z tytulem
|
||||
// ta metoda uzywana tez jest w EditParentUrlById()
|
||||
@@ -1239,18 +1264,13 @@ return EndTrans(result);
|
||||
|
||||
Error Db::EditMetaById(const Space & meta, long id)
|
||||
{
|
||||
meta_stream.Clear();
|
||||
meta.Serialize(meta_stream);
|
||||
|
||||
query.Clear();
|
||||
query << R("update core.item set (meta) = (")
|
||||
<< meta_stream.Str()
|
||||
<< meta
|
||||
<< R(") where id=")
|
||||
<< id
|
||||
<< R(";");
|
||||
|
||||
meta_stream.Clear();
|
||||
|
||||
return DoCommand(query);
|
||||
}
|
||||
|
||||
@@ -1506,7 +1526,7 @@ void Db::GetUsers(UGContainer<User> & user_tab)
|
||||
try
|
||||
{
|
||||
query.Clear();
|
||||
query << R("select id, login, super_user, group_id, email, notify"
|
||||
query << R("select id, login, super_user, group_id, email, notify, env, aenv"
|
||||
" from core.user left outer join core.group_mem on"
|
||||
" core.user.id = core.group_mem.user_id order by id asc;");
|
||||
|
||||
@@ -1521,12 +1541,14 @@ void Db::GetUsers(UGContainer<User> & user_tab)
|
||||
int cgroup_id = AssertColumn(r, "group_id");
|
||||
int cemail = AssertColumn(r, "email");
|
||||
int cnotify = AssertColumn(r, "notify");
|
||||
int cenv = AssertColumn(r, "env");
|
||||
int caenv = AssertColumn(r, "aenv");
|
||||
|
||||
User u;
|
||||
long last_id = -1;
|
||||
UGContainer<User>::Iterator iter = user_tab.End();
|
||||
|
||||
for(int i = 0 ; i<rows ; ++i)
|
||||
for(int i=0 ; i<rows ; ++i)
|
||||
{
|
||||
u.id = AssertValueLong(r, i, cid);
|
||||
|
||||
@@ -1536,6 +1558,8 @@ void Db::GetUsers(UGContainer<User> & user_tab)
|
||||
u.super_user = AssertValueBool(r, i, csuper_user);
|
||||
u.email = AssertValueWide(r, i, cemail);
|
||||
u.notify = AssertValueInt(r, i, cnotify);
|
||||
AssertValueSpace(r, i, cenv, u.env);
|
||||
AssertValueSpace(r, i, caenv, u.aenv);
|
||||
|
||||
log << log2 << "Db: user: id: " << u.id << ", name: " << u.name << ", super_user: " << u.super_user << logend;
|
||||
|
||||
|
||||
14
db/db.h
14
db/db.h
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* Copyright (c) 2008-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -39,11 +39,18 @@ public:
|
||||
// !! GetDir tylko dla katalogow
|
||||
// !! GetFile i GetDir beda uzywac GetItem
|
||||
|
||||
|
||||
Db() : item_cols(*this)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool GetUserPass(const std::wstring & login, long & user_id, UserPass & up);
|
||||
Error AddUser(User & user, const std::wstring & password, const std::string & password_encrypted, int pass_type, bool pass_hash_salted);
|
||||
Error AddUser(User & user, const UserPass & up);
|
||||
|
||||
// !! change name to: ChangeUserPass ?
|
||||
Error ChangePass(const std::wstring & login, const std::wstring & password, const std::string & password_encrypted, int pass_type, bool pass_hash_salted);
|
||||
Error ChangeUserEnv(long user_id, const Space & space);
|
||||
Error ChangeUserAdminEnv(long user_id, const Space & space);
|
||||
|
||||
Error AddItem(Item & item);
|
||||
Error EditItemById(Item & item, bool with_url = true);
|
||||
@@ -100,7 +107,6 @@ protected:
|
||||
Item get_item_temp;
|
||||
std::wstring iq_id_list;
|
||||
DbItemColumns item_cols;
|
||||
TextStream<std::wstring> meta_stream;
|
||||
|
||||
|
||||
bool AddItemCreateUrlSubject(Item & item);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -143,7 +143,7 @@ return res;
|
||||
const std::wstring & DbBase::AssertValueWide(PGresult * r, int row, int col)
|
||||
{
|
||||
const char * res = AssertValue(r, row, col);
|
||||
static std::wstring temp_wide_value;
|
||||
static std::wstring temp_wide_value; // !! dac jako skladowa klasy (niestatyczna)
|
||||
|
||||
Ezc::UTF8ToWide(res, temp_wide_value);
|
||||
|
||||
@@ -210,6 +210,36 @@ tm DbBase::AssertValueTm(PGresult * r, int row, int col)
|
||||
}
|
||||
|
||||
|
||||
bool DbBase::AssertValueSpace(PGresult * r, int row, int col, Space & space, bool split_single)
|
||||
{
|
||||
const char * res = AssertValue(r, row, col);
|
||||
|
||||
conf_parser.UTF8(true);
|
||||
conf_parser.SplitSingle(split_single);
|
||||
conf_parser.SetSpace(space);
|
||||
space.Clear();
|
||||
|
||||
ConfParser::Status status = conf_parser.ParseString(res);
|
||||
|
||||
if( status != ConfParser::ok )
|
||||
{
|
||||
log << log1 << "Db: a problem with parsing a Space";
|
||||
|
||||
if( status == ConfParser::syntax_error )
|
||||
log << ", syntax error at line: " << conf_parser.line;
|
||||
|
||||
log << logend;
|
||||
|
||||
space.Clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void DbBase::ClearResult(PGresult * r)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "core/error.h"
|
||||
#include "core/confparser.h"
|
||||
|
||||
|
||||
class DbBase
|
||||
@@ -36,6 +37,7 @@ public:
|
||||
void AssertResult(PGresult * r, ExecStatusType t);
|
||||
static int AssertColumn(PGresult * r, const char * column_name);
|
||||
|
||||
// static assignments
|
||||
static const char * AssertValue(PGresult * r, int row, int col);
|
||||
static const std::wstring & AssertValueWide(PGresult * r, int row, int col); // warning: this method uses a static buffer
|
||||
static void AssertValueWide(PGresult * r, int row, int col, std::wstring & result);
|
||||
@@ -46,6 +48,9 @@ public:
|
||||
static unsigned long AssertValueULong(PGresult * r, int row, int col);
|
||||
static unsigned int AssertValueUInt(PGresult * r, int row, int col);
|
||||
static tm AssertValueTm(PGresult * r, int row, int col);
|
||||
|
||||
// non static assignments
|
||||
bool AssertValueSpace(PGresult * r, int row, int col, Space & space, bool split_single = true);
|
||||
|
||||
void ClearResult(PGresult * r);
|
||||
long AssertCurrval(const char * table);
|
||||
@@ -89,6 +94,7 @@ private:
|
||||
static int UnescapeBin(const char * str, size_t & i, size_t len);
|
||||
|
||||
DbTextStream bquery;
|
||||
ConfParser conf_parser;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* Copyright (c) 2008-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
void DbItemColumns::SetColumns(PGresult * r)
|
||||
{
|
||||
// PQfnumber returns -1 if there is no such a column
|
||||
@@ -48,28 +49,6 @@ void DbItemColumns::SetColumns(PGresult * r)
|
||||
}
|
||||
|
||||
|
||||
void DbItemColumns::SetMeta(PGresult * r, long row, Item & item)
|
||||
{
|
||||
DbBase::AssertValueWide(r, row, meta, meta_str);
|
||||
|
||||
item.meta.Clear();
|
||||
conf_parser.SetSpace(item.meta);
|
||||
conf_parser.UTF8(true); // from the db we always have UTF-8 string
|
||||
conf_parser.SplitSingle(true);
|
||||
|
||||
if( conf_parser.ParseString(meta_str) != ConfParser::ok )
|
||||
{
|
||||
log << log1 << "Db: syntax error when parsing meta information for"
|
||||
<< " item id: " << item.id
|
||||
<< ", url: " << item.url
|
||||
<< ", line: " << conf_parser.line << logend;
|
||||
}
|
||||
|
||||
meta_str.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
|
||||
{
|
||||
if( id != -1 ) item.id = DbBase::AssertValueLong(r, row, id);
|
||||
@@ -101,9 +80,9 @@ void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
|
||||
if( link_to != -1 ) DbBase::AssertValueWide(r, row, link_to, item.link_to);
|
||||
if( guest_name != -1 ) DbBase::AssertValueWide(r, row, guest_name, item.guest_name);
|
||||
if( html_template != -1 ) DbBase::AssertValueWide(r, row, html_template, item.html_template);
|
||||
if( sort_index != -1 ) item.sort_index = DbBase::AssertValueInt(r, row, sort_index);
|
||||
if( sort_index != -1 ) item.sort_index = DbBase::AssertValueInt(r, row, sort_index);
|
||||
|
||||
if( meta != -1 ) SetMeta(r, row, item);
|
||||
if( meta != -1 ) db_base.AssertValueSpace(r, row, meta, item.meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -13,8 +13,7 @@
|
||||
|
||||
#include <libpq-fe.h>
|
||||
#include "core/item.h"
|
||||
#include "core/confparser.h"
|
||||
|
||||
#include "dbbase.h"
|
||||
|
||||
|
||||
|
||||
@@ -50,19 +49,16 @@ struct DbItemColumns
|
||||
int sort_index;
|
||||
int meta;
|
||||
|
||||
DbItemColumns(DbBase & db_base_) : db_base(db_base_)
|
||||
{
|
||||
}
|
||||
|
||||
void SetColumns(PGresult * r);
|
||||
void SetItem(PGresult * r, long row, Item & item);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// for parsing meta information
|
||||
ConfParser conf_parser;
|
||||
|
||||
// meta string
|
||||
std::wstring meta_str;
|
||||
|
||||
void SetMeta(PGresult * r, long row, Item & item);
|
||||
DbBase & db_base;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -577,3 +577,24 @@ return buffer;
|
||||
|
||||
|
||||
|
||||
DbTextStream & DbTextStream::operator<<(const Space * space)
|
||||
{
|
||||
space_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how much memory is needed before serializing
|
||||
space->Serialize(space_stream, true, false);
|
||||
operator<<(space_stream.Str());
|
||||
space_stream.Clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DbTextStream & DbTextStream::operator<<(const Space & space)
|
||||
{
|
||||
return operator<<(&space);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -152,6 +152,8 @@ public:
|
||||
DbTextStream & operator<<(const void *);
|
||||
DbTextStream & operator<<(const tm & t);
|
||||
DbTextStream & operator<<(const std::vector<long> & tabid);
|
||||
DbTextStream & operator<<(const Space * space);
|
||||
DbTextStream & operator<<(const Space & space);
|
||||
|
||||
|
||||
static const char * ConvertTime(const tm & t);
|
||||
@@ -161,6 +163,9 @@ private:
|
||||
bool was_param;
|
||||
bool ext_escape;
|
||||
|
||||
// a temporarily stream used when serializing spaces
|
||||
TextStream<std::wstring> space_stream;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user