added: a new way: HEX format to saving/reading from PostgreSQL bytea columns

added: to Request:
       // binary page
       BinaryPage binary_page;

       // a compressed page ready to send to the client
       BinaryPage compressed_page;

       // if true then either page or ajaxpage will be sent to the client
       // if false then binary_page is sent
       // default: true
       bool use_text_page;

       BinaryPage is defined as (in requesttypes.h):
       typedef PT::TextStreamBase<char, 1, 4096> BinaryPage;

added: to Compress: now it can gets BinaryPage as arguments (input, output)
changed: winix version to: 0.5.0
added: in templates: TexTextStream class
       for taking input to the TeX typesetting system





git-svn-id: svn://ttmath.org/publicrep/winix/trunk@884 e52654a7-88a9-db11-a3e9-0013d4bc506e
pull/3/head 0.5.0
Tomasz Sowa 11 years ago
parent 9174555ff8
commit d8260d8383

@ -51,14 +51,13 @@ app.o: plugin.h pluginmsg.h cookieparser.h postmultiparser.h
app.o: acceptencodingparser.h acceptbaseparser.h
basethread.o: basethread.h synchro.h
bbcodeparser.o: bbcodeparser.h htmlfilter.h
compress.o: compress.h log.h textstream.h logmanipulators.h
compress.o: ../../pikotools/textstream/textstream.h
compress.o: compress.h requesttypes.h ../../pikotools/textstream/textstream.h
compress.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
compress.o: ../../pikotools/convert/convert.h
compress.o: ../../pikotools/convert/inttostr.h
compress.o: ../../pikotools/membuffer/membuffer.h
compress.o: ../../pikotools/textstream/types.h slog.h cur.h request.h
compress.o: requesttypes.h item.h error.h config.h
compress.o: ../../pikotools/textstream/types.h log.h textstream.h
compress.o: logmanipulators.h slog.h cur.h request.h item.h error.h config.h
compress.o: ../../pikotools/space/spaceparser.h ../../pikotools/space/space.h
compress.o: ../../pikotools/textstream/types.h htmlfilter.h
compress.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
@ -527,18 +526,17 @@ plugindata.o: ../templates/templates.h ../templates/patterncacher.h
plugindata.o: ../templates/indexpatterns.h ../templates/patterns.h
plugindata.o: ../templates/changepatterns.h ../templates/htmltextstream.h
plugindata.o: ../core/sessionmanager.h
postmultiparser.o: postmultiparser.h error.h requesttypes.h config.h
postmultiparser.o: ../../pikotools/space/spaceparser.h
postmultiparser.o: ../../pikotools/space/space.h
postmultiparser.o: ../../pikotools/textstream/types.h htmlfilter.h misc.h
postmultiparser.o: item.h ../../pikotools/space/space.h
postmultiparser.o: ../../pikotools/date/date.h
postmultiparser.o: postmultiparser.h error.h requesttypes.h
postmultiparser.o: ../../pikotools/textstream/textstream.h
postmultiparser.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
postmultiparser.o: ../../pikotools/convert/convert.h
postmultiparser.o: ../../pikotools/convert/inttostr.h
postmultiparser.o: ../../pikotools/membuffer/membuffer.h
postmultiparser.o: ../../pikotools/textstream/types.h
postmultiparser.o: ../../pikotools/utf8/utf8.h log.h textstream.h
postmultiparser.o: ../../pikotools/textstream/types.h config.h
postmultiparser.o: ../../pikotools/space/spaceparser.h
postmultiparser.o: ../../pikotools/space/space.h
postmultiparser.o: ../../pikotools/textstream/types.h htmlfilter.h misc.h
postmultiparser.o: item.h ../../pikotools/utf8/utf8.h log.h textstream.h
postmultiparser.o: logmanipulators.h slog.h cur.h request.h
postmultiparser.o: ../templates/htmltextstream.h ../core/textstream.h
postmultiparser.o: ../../pikotools/space/spacetojson.h session.h user.h
@ -555,46 +553,46 @@ rebus.o: ../../pikotools/textstream/types.h htmlfilter.h
rebus.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
rebus.o: ../../pikotools/utf8/utf8.h ../../pikotools/space/spacetojson.h
rebus.o: session.h user.h plugindata.h rebus.h mount.h ../templates/locale.h
request.o: request.h requesttypes.h item.h ../../pikotools/space/space.h
request.o: ../../pikotools/date/date.h error.h config.h
request.o: ../../pikotools/space/spaceparser.h ../../pikotools/space/space.h
request.o: ../../pikotools/textstream/types.h htmlfilter.h textstream.h
request.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
request.o: ../../pikotools/textstream/textstream.h
request.o: request.h requesttypes.h ../../pikotools/textstream/textstream.h
request.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
request.o: ../../pikotools/convert/convert.h
request.o: ../../pikotools/convert/inttostr.h
request.o: ../../pikotools/membuffer/membuffer.h
request.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h
request.o: ../../pikotools/space/spacetojson.h log.h logmanipulators.h slog.h
request.o: cur.h session.h user.h plugindata.h rebus.h mount.h
request.o: ../templates/locale.h plugin.h pluginmsg.h system.h job.h
request.o: basethread.h synchro.h dirs.h dircontainer.h ../db/db.h
request.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h ../core/error.h
request.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
request.o: ../core/user.h ../core/group.h ../core/dircontainer.h
request.o: ../core/ugcontainer.h ../notify/notify.h ../notify/notifypool.h
request.o: ../templates/patterns.h ../templates/locale.h
request.o: ../templates/localefilter.h ../../ezc/src/ezc.h
request.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
request.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
request.o: ../../ezc/src/stringconv.h ../notify/notifythread.h
request.o: ../core/basethread.h ../notify/templatesnotify.h ../core/config.h
request.o: ../core/users.h ugcontainer.h lastcontainer.h mounts.h
request.o: mountparser.h crypt.h run.h users.h groups.h group.h loadavg.h
request.o: image.h threadmanager.h timezones.h timezone.h sessionmanager.h
request.o: sessioncontainer.h ../functions/functions.h
request.o: ../functions/functionbase.h ../core/request.h ../core/system.h
request.o: ../core/synchro.h ../functions/functionparser.h ../core/cur.h
request.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
request.o: ../functions/privchanger.h ../functions/chown.h
request.o: ../functions/ckeditor.h ../functions/cp.h ../functions/default.h
request.o: ../functions/download.h ../functions/emacs.h ../functions/env.h
request.o: ../functions/last.h ../functions/login.h ../functions/logout.h
request.o: ../functions/ln.h ../functions/ls.h ../functions/man.h
request.o: ../functions/meta.h ../functions/mkdir.h ../functions/mv.h
request.o: ../functions/nicedit.h ../functions/node.h ../functions/passwd.h
request.o: ../functions/priv.h ../functions/pw.h ../functions/reload.h
request.o: ../functions/rm.h ../functions/rmuser.h ../functions/sort.h
request.o: ../../pikotools/textstream/types.h item.h error.h config.h
request.o: ../../pikotools/space/spaceparser.h ../../pikotools/space/space.h
request.o: ../../pikotools/textstream/types.h htmlfilter.h textstream.h
request.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
request.o: ../../pikotools/utf8/utf8.h ../../pikotools/space/spacetojson.h
request.o: log.h logmanipulators.h slog.h cur.h session.h user.h plugindata.h
request.o: rebus.h mount.h ../templates/locale.h plugin.h pluginmsg.h
request.o: system.h job.h basethread.h synchro.h dirs.h dircontainer.h
request.o: ../db/db.h ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
request.o: ../core/error.h ../db/dbitemquery.h ../core/item.h
request.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
request.o: ../core/dircontainer.h ../core/ugcontainer.h ../notify/notify.h
request.o: ../notify/notifypool.h ../templates/patterns.h
request.o: ../templates/locale.h ../templates/localefilter.h
request.o: ../../ezc/src/ezc.h ../../ezc/src/generator.h
request.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
request.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
request.o: ../notify/notifythread.h ../core/basethread.h
request.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
request.o: ugcontainer.h lastcontainer.h mounts.h mountparser.h crypt.h run.h
request.o: users.h groups.h group.h loadavg.h image.h threadmanager.h
request.o: timezones.h timezone.h sessionmanager.h sessioncontainer.h
request.o: ../functions/functions.h ../functions/functionbase.h
request.o: ../core/request.h ../core/system.h ../core/synchro.h
request.o: ../functions/functionparser.h ../core/cur.h ../functions/adduser.h
request.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
request.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
request.o: ../functions/default.h ../functions/download.h
request.o: ../functions/emacs.h ../functions/env.h ../functions/last.h
request.o: ../functions/login.h ../functions/logout.h ../functions/ln.h
request.o: ../functions/ls.h ../functions/man.h ../functions/meta.h
request.o: ../functions/mkdir.h ../functions/mv.h ../functions/nicedit.h
request.o: ../functions/node.h ../functions/passwd.h ../functions/priv.h
request.o: ../functions/pw.h ../functions/reload.h ../functions/rm.h
request.o: ../functions/rmuser.h ../functions/sort.h
request.o: ../functions/specialdefault.h ../functions/stat.h
request.o: ../functions/subject.h ../functions/template.h
request.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
@ -626,32 +624,32 @@ session.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h
sessioncontainer.o: sessioncontainer.h session.h item.h
sessioncontainer.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
sessioncontainer.o: error.h user.h plugindata.h rebus.h textstream.h cur.h
sessioncontainer.o: request.h requesttypes.h config.h
sessioncontainer.o: ../../pikotools/space/spaceparser.h
sessioncontainer.o: ../../pikotools/space/space.h
sessioncontainer.o: ../../pikotools/textstream/types.h htmlfilter.h
sessioncontainer.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessioncontainer.o: request.h requesttypes.h
sessioncontainer.o: ../../pikotools/textstream/textstream.h
sessioncontainer.o: ../../pikotools/convert/convert.h
sessioncontainer.o: ../../pikotools/convert/inttostr.h
sessioncontainer.o: ../../pikotools/membuffer/membuffer.h
sessioncontainer.o: ../../pikotools/textstream/types.h
sessioncontainer.o: ../../pikotools/textstream/types.h config.h
sessioncontainer.o: ../../pikotools/space/spaceparser.h
sessioncontainer.o: ../../pikotools/space/space.h
sessioncontainer.o: ../../pikotools/textstream/types.h htmlfilter.h
sessioncontainer.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessioncontainer.o: ../../pikotools/utf8/utf8.h
sessioncontainer.o: ../../pikotools/space/spacetojson.h mount.h log.h
sessioncontainer.o: logmanipulators.h slog.h ../templates/locale.h
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h item.h
sessionmanager.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
sessionmanager.o: error.h user.h plugindata.h rebus.h textstream.h cur.h
sessionmanager.o: request.h requesttypes.h config.h
sessionmanager.o: ../../pikotools/space/spaceparser.h
sessionmanager.o: ../../pikotools/space/space.h
sessionmanager.o: ../../pikotools/textstream/types.h htmlfilter.h
sessionmanager.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessionmanager.o: request.h requesttypes.h
sessionmanager.o: ../../pikotools/textstream/textstream.h
sessionmanager.o: ../../pikotools/convert/convert.h
sessionmanager.o: ../../pikotools/convert/inttostr.h
sessionmanager.o: ../../pikotools/membuffer/membuffer.h
sessionmanager.o: ../../pikotools/textstream/types.h
sessionmanager.o: ../../pikotools/textstream/types.h config.h
sessionmanager.o: ../../pikotools/space/spaceparser.h
sessionmanager.o: ../../pikotools/space/space.h
sessionmanager.o: ../../pikotools/textstream/types.h htmlfilter.h
sessionmanager.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessionmanager.o: ../../pikotools/utf8/utf8.h
sessionmanager.o: ../../pikotools/space/spacetojson.h mount.h lastcontainer.h
sessionmanager.o: system.h job.h basethread.h synchro.h dirs.h dircontainer.h
@ -699,30 +697,31 @@ sessionmanager.o: ../core/sessionmanager.h
sessionparser.o: sessionparser.h session.h item.h
sessionparser.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
sessionparser.o: error.h user.h plugindata.h rebus.h textstream.h
sessionparser.o: sessioncontainer.h cur.h request.h requesttypes.h config.h
sessionparser.o: ../../pikotools/space/spaceparser.h
sessionparser.o: ../../pikotools/space/space.h
sessionparser.o: ../../pikotools/textstream/types.h htmlfilter.h
sessionparser.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessionparser.o: sessioncontainer.h cur.h request.h requesttypes.h
sessionparser.o: ../../pikotools/textstream/textstream.h
sessionparser.o: ../../pikotools/convert/convert.h
sessionparser.o: ../../pikotools/convert/inttostr.h
sessionparser.o: ../../pikotools/membuffer/membuffer.h
sessionparser.o: ../../pikotools/textstream/types.h
sessionparser.o: ../../pikotools/textstream/types.h config.h
sessionparser.o: ../../pikotools/space/spaceparser.h
sessionparser.o: ../../pikotools/space/space.h
sessionparser.o: ../../pikotools/textstream/types.h htmlfilter.h
sessionparser.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessionparser.o: ../../pikotools/utf8/utf8.h
sessionparser.o: ../../pikotools/space/spacetojson.h mount.h users.h log.h
sessionparser.o: logmanipulators.h slog.h ../templates/locale.h
slog.o: slog.h cur.h request.h requesttypes.h item.h
slog.o: ../../pikotools/space/space.h ../../pikotools/date/date.h error.h
slog.o: config.h ../../pikotools/space/spaceparser.h
slog.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
slog.o: htmlfilter.h textstream.h ../templates/htmltextstream.h
slog.o: ../core/textstream.h misc.h ../../pikotools/textstream/textstream.h
slog.o: ../../pikotools/convert/convert.h ../../pikotools/convert/inttostr.h
slog.o: slog.h cur.h request.h requesttypes.h
slog.o: ../../pikotools/textstream/textstream.h ../../pikotools/space/space.h
slog.o: ../../pikotools/date/date.h ../../pikotools/convert/convert.h
slog.o: ../../pikotools/convert/inttostr.h
slog.o: ../../pikotools/membuffer/membuffer.h
slog.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h
slog.o: ../../pikotools/space/spacetojson.h session.h user.h plugindata.h
slog.o: rebus.h mount.h logmanipulators.h ../templates/locale.h
slog.o: ../../pikotools/textstream/types.h item.h error.h config.h
slog.o: ../../pikotools/space/spaceparser.h ../../pikotools/space/space.h
slog.o: ../../pikotools/textstream/types.h htmlfilter.h textstream.h
slog.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
slog.o: ../../pikotools/utf8/utf8.h ../../pikotools/space/spacetojson.h
slog.o: session.h user.h plugindata.h rebus.h mount.h logmanipulators.h
slog.o: ../templates/locale.h
synchro.o: synchro.h
system.o: system.h job.h basethread.h synchro.h ../../pikotools/space/space.h
system.o: dirs.h item.h ../../pikotools/date/date.h dircontainer.h ../db/db.h
@ -813,21 +812,21 @@ user.o: user.h
users.o: users.h sessionmanager.h sessioncontainer.h session.h item.h
users.o: ../../pikotools/space/space.h ../../pikotools/date/date.h error.h
users.o: user.h plugindata.h rebus.h textstream.h cur.h request.h
users.o: requesttypes.h config.h ../../pikotools/space/spaceparser.h
users.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
users.o: htmlfilter.h ../templates/htmltextstream.h ../core/textstream.h
users.o: misc.h ../../pikotools/textstream/textstream.h
users.o: requesttypes.h ../../pikotools/textstream/textstream.h
users.o: ../../pikotools/convert/convert.h ../../pikotools/convert/inttostr.h
users.o: ../../pikotools/membuffer/membuffer.h
users.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h
users.o: ../../pikotools/space/spacetojson.h mount.h lastcontainer.h system.h
users.o: job.h basethread.h synchro.h dirs.h dircontainer.h ../db/db.h
users.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h ../core/error.h
users.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
users.o: ../core/user.h ../core/group.h ../core/dircontainer.h
users.o: ../core/ugcontainer.h log.h logmanipulators.h slog.h
users.o: ../templates/locale.h ../notify/notify.h ../notify/notifypool.h
users.o: ../templates/patterns.h ../templates/locale.h
users.o: ../../pikotools/textstream/types.h config.h
users.o: ../../pikotools/space/spaceparser.h ../../pikotools/space/space.h
users.o: ../../pikotools/textstream/types.h htmlfilter.h
users.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
users.o: ../../pikotools/utf8/utf8.h ../../pikotools/space/spacetojson.h
users.o: mount.h lastcontainer.h system.h job.h basethread.h synchro.h dirs.h
users.o: dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
users.o: ../db/dbtextstream.h ../core/error.h ../db/dbitemquery.h
users.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h ../core/group.h
users.o: ../core/dircontainer.h ../core/ugcontainer.h log.h logmanipulators.h
users.o: slog.h ../templates/locale.h ../notify/notify.h
users.o: ../notify/notifypool.h ../templates/patterns.h ../templates/locale.h
users.o: ../templates/localefilter.h ../../ezc/src/ezc.h
users.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
users.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h

@ -977,6 +977,7 @@ void App::FilterCompressSend(bool compressing, int compress_encoding, const std:
int App::SelectDeflateVersion()
{
if( cur.request->browser_msie )
@ -1070,7 +1071,7 @@ void App::AddDebugInfo(std::wstring & out)
void App::SendAnswer()
void App::SendTextAnswer()
{
const std::wstring * source;
Header header = h_200;
@ -1083,7 +1084,6 @@ int compress_encoding;
else
source = &cur.request->page.Str();
SelectCompression(source->length(), compressing, compress_encoding);
if( status == WINIX_ERR_NO_ITEM || status == WINIX_ERR_NO_FUNCTION || status == WINIX_ERR_UNKNOWN_PARAM )
@ -1102,6 +1102,86 @@ int compress_encoding;
}
void App::SendData(const BinaryPage & page, FCGX_Stream * out)
{
const size_t buf_size = 4096;
if( send_data_buf.size() != buf_size )
send_data_buf.resize(buf_size);
BinaryPage::const_iterator i = page.begin();
BinaryPage::const_iterator end = page.end();
// log << log1 << "size: " << page.size() << logend;
// for(size_t x=0 ; x<page.size() ; ++x)
// log << int((unsigned char)page[x]) << ' ';
// log << logend;
while( i != end )
{
size_t s = 0;
for( ; i != end && s < buf_size ; ++i, ++s)
{
send_data_buf[s] = *i;
// log << "swinka: " << int((unsigned char)*i) << logend;
}
if( s > 0 )
FCGX_PutStr(send_data_buf.c_str(), s, fcgi_request.out);
}
}
void App::SendBinaryAnswer()
{
BinaryPage & source = cur.request->binary_page;
BinaryPage & compressed_page = cur.request->compressed_page;
Header header = h_200;
Error status = cur.request->status;
bool compressing;
int compress_encoding;
SelectCompression(source.size(), compressing, compress_encoding);
if( status == WINIX_ERR_NO_ITEM || status == WINIX_ERR_NO_FUNCTION || status == WINIX_ERR_UNKNOWN_PARAM )
header = h_404;
if( status == WINIX_ERR_PERMISSION_DENIED || status == WINIX_ERR_CANT_CHANGE_USER || status == WINIX_ERR_CANT_CHANGE_GROUP )
header = h_403;
// !! IMPROVE ME add header: content-size
SendHeaders(compressing, compress_encoding, header);
if( CanSendContent(header) )
{
if( compressing )
{
compress.Compressing(source, compressed_page, compress_encoding);
SendData(compressed_page, fcgi_request.out);
}
else
{
SendData(source, fcgi_request.out);
}
}
}
void App::SendAnswer()
{
if( cur.request->use_text_page )
SendTextAnswer();
else
SendBinaryAnswer();
}
void App::LogUser(const char * msg, uid_t id)
{
log << log3 << msg << " ";

@ -121,6 +121,7 @@ private:
std::string source_a;
std::string sendh_t, sendh_t2, sendh_t3;
std::string sendfilea, sendfile2a;
std::string send_data_buf;
void ProcessRequestThrow();
void ProcessRequest();
@ -135,8 +136,11 @@ private:
void Make();
void SaveSessionsIfNeeded(); // !! wywalic do menagera sesji??
void LogAccess();
void SendData(const BinaryPage & page, FCGX_Stream * out);
void ReadRequest();
void SendTextAnswer();
void SendBinaryAnswer();
void SendAnswer();
void PrintEnv();

@ -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.
*
*/
@ -15,7 +15,8 @@
Compress::Compress()
{
buffer = 0;
buffer_in = 0;
buffer_out = 0;
buffer_max_len = 65536; // 64KB
ready_for_compress = false;
compress_level = 6;
@ -27,8 +28,8 @@ Compress::Compress()
Compress::~Compress()
{
if( buffer )
delete [] buffer;
delete [] buffer_in;
delete [] buffer_out;
if( raw_deflate_inited )
deflateEnd(&strm_raw_deflate);
@ -43,17 +44,23 @@ Compress::~Compress()
bool Compress::AllocateMemory()
{
if( buffer )
delete [] buffer;
if( buffer_in )
delete [] buffer_in;
if( buffer_out )
delete [] buffer_out;
buffer_in = 0;
buffer_out = 0;
try
{
buffer = new char[buffer_max_len];
buffer_in = new char[buffer_max_len];
buffer_out = new char[buffer_max_len];
}
catch(const std::bad_alloc &)
{
log << log1 << "Compress: can't allocate memory" << logend;
buffer = 0;
return false;
}
@ -133,9 +140,8 @@ int Compress::Init(int compress_level_)
{
compress_level = compress_level_;
if( buffer == 0 )
if( !AllocateMemory() )
return 1;
if( !AllocateMemory() )
return 1;
if( InitRawDeflate() && InitDeflate() && InitGzip() )
ready_for_compress = true;
@ -163,7 +169,69 @@ size_t have;
do
{
strm.avail_out = buffer_max_len;
strm.next_out = (Bytef*)buffer;
strm.next_out = (Bytef*)buffer_out;
ret = deflate(&strm, flush);
if( ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR )
{
log << log1 << "Compress: problem with deflate()" << logend;
return 2;
}
have = buffer_max_len - strm.avail_out;
last_out_size += have;
FCGX_PutStr(buffer_out, have, out_stream);
}
while( strm.avail_out == 0 );
if( strm.avail_in != 0 )
{
log << log1 << "Compress: problem with deflate() - not all input is used" << logend;
return 2;
}
}
while( flush != Z_FINISH );
if( ret != Z_STREAM_END )
{
log << log1 << "Compress: problem with deflate() - stream not complete" << logend;
return 2;
}
return 0;
}
void Compress::CopyToInputBuffer(BinaryPage::const_iterator & i, size_t len)
{
for(size_t a=0 ; a<len ; ++a, ++i)
buffer_in[a] = *i;
}
// new way
int Compress::MakeCompress(z_stream & strm, const BinaryPage & page, BinaryPage & out, int encoding)
{
int ret, flush;
size_t have;
BinaryPage::const_iterator i = page.begin();
size_t source_len = page.size();
do
{
strm.avail_in = (source_len > buffer_max_len) ? buffer_max_len : source_len;
source_len -= strm.avail_in;
flush = (source_len == 0) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = (Bytef*)buffer_in;
CopyToInputBuffer(i, strm.avail_in);
do
{
strm.avail_out = buffer_max_len;
strm.next_out = (Bytef*)buffer_out;
ret = deflate(&strm, flush);
if( ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR )
@ -174,7 +242,7 @@ size_t have;
have = buffer_max_len - strm.avail_out;
last_out_size += have;
FCGX_PutStr(buffer, have, out_stream);
out.write(buffer_out, have);
}
while( strm.avail_out == 0 );
@ -289,3 +357,36 @@ return ret;
/*
return:
0 - ok;
1 - can't allocate memory
2 - error during compressing
3 - not inited (use Init() first)
100 - unknown
*/
int Compress::Compressing(const BinaryPage & in, BinaryPage & out, int encoding)
{
int ret;
z_stream * pstrm;
last_out_size = 0;
out.clear();
if( !ready_for_compress )
{
log << log1 << "Compress: not ready yet" << logend;
return 3;
}
if( in.empty() )
return 0;
pstrm = SelectStream(encoding);
ret = MakeCompress(*pstrm, in, out, encoding);
ResetStream(pstrm, encoding);
PutLog(in.size(), encoding);
return ret;
}

@ -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,8 @@
#include <cstring>
#include <fcgiapp.h>
#include <zlib.h>
#include "requesttypes.h"
class Compress
@ -33,7 +35,8 @@ public:
2 - gzip
*/
int CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding = 2);
size_t last_out_size;
int Compressing(const BinaryPage & in, BinaryPage & out, int encoding = 2);
private:
@ -43,13 +46,20 @@ private:
bool InitGzip();
int MakeCompress(z_stream & strm, const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding);
int MakeCompress(z_stream & strm, const BinaryPage & page, BinaryPage & out, int encoding);
z_stream * SelectStream(int encoding);
void ResetStream(z_stream * pstrm, int encoding);
void PutLog(size_t source_len, int encoding);
void CopyToInputBuffer(BinaryPage::const_iterator & i, size_t len);
int compress_level;
size_t buffer_max_len;
char * buffer;
// size of the last compressed page
size_t last_out_size;
char * buffer_in;
char * buffer_out;
z_stream strm_raw_deflate, strm_deflate, strm_gzip;
bool raw_deflate_inited, deflate_inited, gzip_inited;
bool ready_for_compress;

@ -120,6 +120,10 @@ void Request::Clear()
ClearAjax();
ajax_serializer = 0;
binary_page.clear();
compressed_page.clear();
use_text_page = true;
gen_trim_white = false;
gen_skip_new_line = false;
gen_use_special_chars = false;

@ -48,6 +48,17 @@ struct Request
HtmlTextStream page, debug;
TextStream<std::wstring> ajaxpage;
// binary page
BinaryPage binary_page;
// a compressed page ready to send to the client
BinaryPage compressed_page;
// if true then either page or ajaxpage will be sent to the client
// if false then binary_page is sent
// default: true
bool use_text_page;
// if set to true then the standard template system will not be generated
// default: false
bool page_generated;

@ -13,6 +13,7 @@
#include <string>
#include <vector>
#include <map>
#include "textstream/textstream.h"
// !! narazie uzywane tylko w post multi parserze
@ -45,5 +46,7 @@ typedef std::vector<Param> ParamTab;
typedef std::map<std::string, std::string> CookieTab;
typedef PT::TextStreamBase<char, 1, 4096> BinaryPage;
#endif

@ -181,6 +181,7 @@ void Run::ChildThrow()
execve(command, par, env);
// if we are here then there is something wrong (execve failed)
// !! IMPROVE ME may add exit() ?
}

@ -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.
*
*/
@ -12,8 +12,8 @@
#define WINIX_VER_MAJOR 0
#define WINIX_VER_MINOR 4
#define WINIX_VER_REVISION 8
#define WINIX_VER_MINOR 5
#define WINIX_VER_REVISION 0
#endif

@ -470,8 +470,9 @@ return err;
/*
converting from a bytea
the old way (escape format)
*/
/*
int DbBase::CharToInt(char c)
{
return (int)(unsigned char)(c-'0');
@ -537,6 +538,53 @@ size_t i = 0;
out += c;
}
}
*/
/*
converting from a bytea
the new way (hex format)
*/
char DbBase::UnescapeBinHexToDigit(char hex)
{
if( hex>='0' && hex<='9' )
return hex - '0';
if( hex>='a' && hex<='z' )
return hex - 'a' + 10;
if( hex>='A' && hex<='Z' )
return hex - 'A' + 10;
return 0;
}
void DbBase::UnescapeBin(const char * str, size_t len, std::string & out, bool clear_out)
{
if( clear_out )
out.clear();
if( len < 2 || str[0]!='\\' || str[1]!='x' )
{
log << log1 << "Db: unsupported binary format (skipping)" << logend;
return;
}
for(size_t i=2 ; i + 1 < len ; i+=2 )
{
int c1 = UnescapeBinHexToDigit(str[i]);
int c2 = UnescapeBinHexToDigit(str[i+1]);
out += ((c1 << 4) | c2);
}
}
/*
end of converting from bytea

@ -93,9 +93,11 @@ protected:
private:
static int CharToInt(char c);
static bool IsCorrectOctalDigit(char c);
static int UnescapeBin(const char * str, size_t & i, size_t len);
// static int CharToInt(char c);
// static bool IsCorrectOctalDigit(char c);
// static int UnescapeBin(const char * str, size_t & i, size_t len);
static char UnescapeBinHexToDigit(char hex);
DbTextStream bquery;
PT::SpaceParser conf_parser;

@ -217,6 +217,10 @@ return *this;
*/
/*
old PostgreSQL Escape Format
*/
/*
DbTextStream & DbTextStream::EBinPutChar(char c_)
{
char buf[20];
@ -235,6 +239,26 @@ char buf[20];
return *this;
}
*/
// get hex digit for c_ between <0, 15>
char DbTextStream::EBinGetHex(char c)
{
if( c < 10 )
return c + '0';
return c - 10 + 'A';
}
DbTextStream & DbTextStream::EBinPutChar(char c)
{
buffer += EBinGetHex(((unsigned char)c) >> 4);
buffer += EBinGetHex(((unsigned char)c) & 0x0f);
return *this;
}
DbTextStream & DbTextStream::ETextPutChar(char c)
@ -341,7 +365,7 @@ DbTextStream & DbTextStream::EPutBin(const char * str, size_t len)
if( ext_escape )
buffer += 'E';
buffer += '\'';
buffer += "\'\\\\x";
for(size_t i = 0 ; i < len ; ++i)
EBinPutChar(str[i]);

@ -161,6 +161,8 @@ private:
bool ext_escape;
TextStream<std::wstring> tmp_stream;
char EBinGetHex(char c);
};

@ -420,10 +420,10 @@ functionbase.o: ../core/timezones.h ../core/synchro.h
functionparser.o: functionparser.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
functionparser.o: ../db/dbtextstream.h ../core/textstream.h ../core/misc.h
functionparser.o: ../core/item.h ../core/requesttypes.h
functionparser.o: ../../pikotools/date/date.h
functionparser.o: ../../pikotools/textstream/textstream.h
functionparser.o: ../../pikotools/space/space.h
functionparser.o: ../../pikotools/textstream/types.h
functionparser.o: ../../pikotools/date/date.h
functionparser.o: ../../pikotools/convert/convert.h
functionparser.o: ../../pikotools/convert/inttostr.h
functionparser.o: ../../pikotools/membuffer/membuffer.h
@ -1057,9 +1057,8 @@ privchanger.o: ../../pikotools/textstream/types.h ../core/dirs.h
privchanger.o: ../core/item.h ../core/dircontainer.h ../db/db.h
privchanger.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
privchanger.o: ../core/textstream.h ../core/misc.h ../core/requesttypes.h
privchanger.o: ../../pikotools/date/date.h
privchanger.o: ../../pikotools/textstream/textstream.h
privchanger.o: ../../pikotools/convert/convert.h
privchanger.o: ../../pikotools/date/date.h ../../pikotools/convert/convert.h
privchanger.o: ../../pikotools/convert/inttostr.h
privchanger.o: ../../pikotools/membuffer/membuffer.h
privchanger.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h

@ -109,9 +109,9 @@ templates.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
templates.o: ../../core/item.h ../../../ezc/src/functions.h
templates.o: ../../../ezc/src/funinfo.h ../../../ezc/src/stringconv.h
templates.o: ../../../pikotools/utf8/utf8.h ../../core/misc.h
templates.o: ../../core/requesttypes.h ../../../pikotools/date/date.h
templates.o: ../../core/requesttypes.h
templates.o: ../../../pikotools/textstream/textstream.h
templates.o: ../../../pikotools/space/space.h
templates.o: ../../../pikotools/space/space.h ../../../pikotools/date/date.h
templates.o: ../../../pikotools/convert/convert.h
templates.o: ../../../pikotools/convert/inttostr.h
templates.o: ../../../pikotools/membuffer/membuffer.h

@ -97,10 +97,11 @@ templates.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
templates.o: ../../core/item.h ../../../ezc/src/functions.h
templates.o: ../../../ezc/src/funinfo.h ../../../ezc/src/stringconv.h
templates.o: ../../../pikotools/utf8/utf8.h ../../core/misc.h
templates.o: ../../core/requesttypes.h ../../../pikotools/date/date.h
templates.o: ../../core/requesttypes.h
templates.o: ../../../pikotools/textstream/textstream.h
templates.o: ../../../pikotools/space/space.h
templates.o: ../../../pikotools/textstream/types.h
templates.o: ../../../pikotools/date/date.h
templates.o: ../../../pikotools/convert/convert.h
templates.o: ../../../pikotools/convert/inttostr.h
templates.o: ../../../pikotools/membuffer/membuffer.h

@ -82,16 +82,16 @@ templates.o: templates.h ../../core/plugin.h ../../core/pluginmsg.h
templates.o: ../../core/log.h ../../core/plugindata.h ../../core/config.h
templates.o: ../../../pikotools/space/spaceparser.h
templates.o: ../../../pikotools/space/space.h ../../core/htmlfilter.h
templates.o: ../../core/request.h ../../core/requesttypes.h ../../core/item.h
templates.o: ../../core/request.h ../../core/requesttypes.h
templates.o: ../../../pikotools/textstream/textstream.h
templates.o: ../../../pikotools/space/space.h
templates.o: ../../../pikotools/textstream/types.h
templates.o: ../../../pikotools/date/date.h ../../core/error.h
templates.o: ../../core/textstream.h ../../core/misc.h
templates.o: ../../../pikotools/textstream/textstream.h
templates.o: ../../../pikotools/date/date.h
templates.o: ../../../pikotools/convert/convert.h
templates.o: ../../../pikotools/convert/inttostr.h
templates.o: ../../../pikotools/membuffer/membuffer.h
templates.o: ../../../pikotools/textstream/types.h
templates.o: ../../../pikotools/textstream/types.h ../../core/item.h
templates.o: ../../core/error.h ../../core/textstream.h ../../core/misc.h
templates.o: ../../../pikotools/utf8/utf8.h ../../templates/htmltextstream.h
templates.o: ../../core/textstream.h ../../../pikotools/space/spacetojson.h
templates.o: ../../core/system.h ../../core/job.h ../../core/basethread.h

@ -66,10 +66,10 @@ createthread.o: ../../functions/uname.h ../../functions/upload.h
createthread.o: ../../functions/uptime.h ../../functions/who.h
createthread.o: ../../functions/vim.h ../../core/htmlfilter.h
funthread.o: ../../core/misc.h ../../core/item.h ../../core/requesttypes.h
funthread.o: ../../../pikotools/date/date.h
funthread.o: ../../../pikotools/textstream/textstream.h
funthread.o: ../../../pikotools/space/space.h
funthread.o: ../../../pikotools/textstream/types.h
funthread.o: ../../../pikotools/date/date.h
funthread.o: ../../../pikotools/convert/convert.h
funthread.o: ../../../pikotools/convert/inttostr.h
funthread.o: ../../../pikotools/membuffer/membuffer.h

@ -967,6 +967,20 @@ templates.o: ../functions/subject.h ../functions/template.h
templates.o: ../functions/tinymce.h ../functions/uname.h
templates.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
templates.o: ../functions/vim.h ../templates/templates.h
textextstream.o: textextstream.h ../core/textstream.h misc.h localefilter.h
textextstream.o: locale.h ../../pikotools/space/spaceparser.h
textextstream.o: ../../pikotools/space/space.h
textextstream.o: ../../pikotools/textstream/types.h
textextstream.o: ../../pikotools/textstream/textstream.h
textextstream.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
textextstream.o: ../../pikotools/convert/convert.h
textextstream.o: ../../pikotools/convert/inttostr.h
textextstream.o: ../../pikotools/membuffer/membuffer.h
textextstream.o: ../../pikotools/textstream/types.h ../../ezc/src/ezc.h
textextstream.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
textextstream.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h
textextstream.o: ../../ezc/src/functions.h ../../ezc/src/stringconv.h
textextstream.o: ../../pikotools/utf8/utf8.h htmltextstream.h
upload.o: ../core/request.h templates.h ../../ezc/src/ezc.h
upload.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
upload.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h

@ -1 +1 @@
o = adduser.o changepatterns.o config.o dir.o doc.o env.o filters.o htmltextstream.o indexpatterns.o insert.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o patterncacher.o patterns.o priv.o pw.o rebus.o slog.o stat.o sys.o template.o templates.o upload.o uptime.o user.o who.o winix.o
o = adduser.o changepatterns.o config.o dir.o doc.o env.o filters.o htmltextstream.o indexpatterns.o insert.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o patterncacher.o patterns.o priv.o pw.o rebus.o slog.o stat.o sys.o template.o templates.o textextstream.o upload.o uptime.o user.o who.o winix.o

@ -0,0 +1,456 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2012, Tomasz Sowa
* All rights reserved.
*
*/
#include "textextstream.h"
TexTextStream::TexTextStream()
{
}
/*
without escaping
*/
TexTextStream & TexTextStream::PutText(const char * str)
{
TextStream<std::wstring>::operator<<(str);
return *this;
}
TexTextStream & TexTextStream::PutText(const char * str, size_t len)
{
TextStream<std::wstring>::operator<<(str);
return *this;
}
TexTextStream & TexTextStream::PutText(const std::string * str)
{
return PutText(str->c_str());
}
TexTextStream & TexTextStream::PutText(const std::string & str)
{
return PutText(str.c_str());
}
TexTextStream & TexTextStream::PutText(const wchar_t * str)
{
TextStream<std::wstring>::operator<<(str);
return *this;
}
TexTextStream & TexTextStream::PutText(const std::wstring * str)
{
return PutText(str->c_str());
}
TexTextStream & TexTextStream::PutText(const std::wstring & str)
{
return PutText(str.c_str());
}
TexTextStream & TexTextStream::operator<<(const RawText<const char*> & raw)
{
return PutText(raw.par);
}
TexTextStream & TexTextStream::operator<<(const RawText<const wchar_t*> & raw)
{
return PutText(raw.par);
}
TexTextStream & TexTextStream::operator<<(RawText<const std::string*> raw)
{
return PutText(raw.par);
}
TexTextStream & TexTextStream::operator<<(RawText<const std::wstring*> raw)
{
return PutText(raw.par);
}
TexTextStream & TexTextStream::operator<<(RawText<std::string> raw)
{
return PutText(raw.par);
}
TexTextStream & TexTextStream::operator<<(RawText<std::wstring> raw)
{
return PutText(raw.par);
}
TexTextStream & TexTextStream::operator<<(RawText<char> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
TexTextStream & TexTextStream::operator<<(RawText<wchar_t> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
TexTextStream & TexTextStream::operator<<(RawText<int> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
TexTextStream & TexTextStream::operator<<(RawText<long> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
TexTextStream & TexTextStream::operator<<(RawText<unsigned int> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
TexTextStream & TexTextStream::operator<<(RawText<unsigned long> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
TexTextStream & TexTextStream::operator<<(RawText<double> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
TexTextStream & TexTextStream::operator<<(RawText<void*> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
TexTextStream & TexTextStream::Write(const char * buf, size_t len)
{
TextStream<std::wstring>::Write(buf, len);
return *this;
}
TexTextStream & TexTextStream::Write(const wchar_t * buf, size_t len)
{
TextStream<std::wstring>::Write(buf, len);
return *this;
}
TexTextStream & TexTextStream::write(const char * buf, size_t len)
{
TextStream<std::wstring>::write(buf, len);
return *this;
}
TexTextStream & TexTextStream::write(const wchar_t * buf, size_t len)
{
TextStream<std::wstring>::write(buf, len);
return *this;
}
/*
with escaping
*/
TexTextStream & TexTextStream::ETextPutChar(char c)
{
return ETextPutChar(static_cast<wchar_t>(c));
}
TexTextStream & TexTextStream::ETextPutChar(wchar_t c)
{
if( c == '$' )
buffer += L"\\$";
else
if( c == '#' )
buffer += L"\\#";
else
if( c == '%' )
buffer += L"\\%";
else
if( c == '&' )
buffer += L"\\&";
else
if( c == '\\' )
buffer += L"$\\backslash$";
else
if( c == '{' )
buffer += L"$\\{$";
else
if( c == '}' )
buffer += L"$\\}$";
else
if( c == '^' )
buffer += L""; // !! IMPROVE ME add \char with specific code
else
if( c == '_' )
buffer += L"\\_";
else
if( c == '~' )
buffer += L""; // !! IMPROVE ME add \char with specific code
else
if( c == '-' )
buffer += L"{-}";
else
if( c != 0 )
buffer += c;
return *this;
}
TexTextStream & TexTextStream::EPutText(const char * str)
{
for( ; *str ; ++str )
ETextPutChar(*str);
return *this;
}
TexTextStream & TexTextStream::EPutText(const char * str, size_t len)
{
for(size_t i=0 ; i<len ; ++i)
ETextPutChar(str[i]);
return *this;
}
TexTextStream & TexTextStream::EPutText(const std::string * str)
{
return EPutText(str->c_str(), str->size());
}
TexTextStream & TexTextStream::EPutText(const std::string & str)
{
return EPutText(str.c_str(), str.size());
}
TexTextStream & TexTextStream::EPutText(const wchar_t * str)
{
for( ; *str ; ++str )
ETextPutChar(*str);
return *this;
}
TexTextStream & TexTextStream::EPutText(const wchar_t * str, size_t len)
{
for(size_t i=0 ; i<len ; ++i)
ETextPutChar(str[i]);
return *this;
}
TexTextStream & TexTextStream::EPutText(const std::wstring * str)
{
return EPutText(str->c_str(), str->size());
}
TexTextStream & TexTextStream::EPutText(const std::wstring & str)
{
return EPutText(str.c_str(), str.size());
}
TexTextStream & TexTextStream::operator<<(const char * str)
{
return EPutText(str);
}
TexTextStream & TexTextStream::operator<<(const std::string * str)
{
return EPutText(str);
}
TexTextStream & TexTextStream::operator<<(const std::string & str)
{
return EPutText(str);
}
TexTextStream & TexTextStream::operator<<(const wchar_t * str)
{
return EPutText(str);
}
TexTextStream & TexTextStream::operator<<(const std::wstring * str)
{
return EPutText(str);
}
TexTextStream & TexTextStream::operator<<(const std::wstring & str)
{
return EPutText(str);
}