88 Commits
0.4.0 ... 0.4.8

Author SHA1 Message Date
0a7432b059 added: SLog class -- session logger
messages are displayed in the browser (with locales)
changed: MountParser
         now if there is an error in a line -- the line is simply skipped
         


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@741 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-19 20:59:58 +00:00
b369fda1d9 deleted some log info
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@740 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-19 10:40:09 +00:00
c49c35cfbd added: a new mount type: static
some path in winix can be redirected to a specified static directory


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@738 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-14 23:45:42 +00:00
fb4742e165 added: nicedit: a new wysiwyg javascript editor
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@737 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-13 01:06:10 +00:00
fce45b93a2 fixed: users: flag 'super_user' was not correctly read ftom the database
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@736 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 23:00:00 +00:00
18ecd46a01 changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added:   DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
         it reads binary (bytea) data
added:   DbTextStream can handle 'bool' types now
         (is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
         with RSA
         currently we have following hashes:
         md4, md5, sha1, sha224, sha256, sha384, sha512
         we are using openssl to manage them
         (look at config options for more info)
changed: winix version to 0.4.7         
added:   class Run - you can run any program from os and send a buffer to its standard input
         and read what the program put on its standard output
added:   class Crypt (in System) - calculating hashes, and crypting/decrypting




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 21:22:08 +00:00
af8fbdae72 added: now winix will not log post parameters with 'pass' in names (at the beginning)
changed: only first few characters are logged (from POST)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@733 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-06 22:47:34 +00:00
c84997be30 small changes in Makefiles
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@731 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-06 20:35:56 +00:00
06551d6084 added: "str" "strnc" ezc functions
changed: ezc functions:
         "winix_false" to "false"
         "winix_true"  to "true"


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@730 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-04-26 17:19:08 +00:00
84145d7cc8 fixed: BBCODEParser incorrectly worked with the latest changes in HTMLFilter
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@729 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-04-16 11:27:54 +00:00
426beae796 renamed: config option 'html_filter_break_lines' to 'html_filter_break_word'
added:   config option 'html_filter_wrap_line'
         this wraps the whole line (line calculated with html tags as well)
changed: orphans (for html filter) are read from locale files now
         ('language_orphans' value )



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@728 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-04-16 08:42:22 +00:00
aadf12c7b3 added support for gzip compression
new config option: compression_encoding (integer)
 1  - use deflate if available (or raw deflate for Internet Explorer) or don't compress
 2  - use gzip if available or don't compress
 10 - prefer deflate -- use deflate (or raw deflate for IE) if both deflate and gzip are available
 20 - prefer gzip    -- use gzip if both deflate and gzip are available
 default: 20

		   


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@727 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-04-02 00:10:16 +00:00
1b60935d08 updated 'galleria' js plugin
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@726 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-04-01 16:30:14 +00:00
d68731fd55 fixed: thread plugin didn't correctly set the last item and replies (in 'thread' table)
when deleting an answer
added: ThreadInfo::Repair() method
       will be used by 'fsck' winix function       
added: plugins/groupitem 
       directory for a new plugin: 'groupitem'
       


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@725 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-03-23 17:54:53 +00:00
ba63c8c661 changed: removed Languages::Land enum
now we set the languages in the config file: option locale_files, sample:
  locale_files = ( en, pl )
it represents the name of locale files (those from locale_dir directory)
renamed config option: locale to locale_default


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@722 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-24 17:06:12 +00:00
15487b347f added ezc function: winix_function_param_is_not
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@721 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-22 04:14:26 +00:00
e7e90c6527 txt templates (a new line was missing)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@720 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-18 09:35:35 +00:00
ca5421347a fixed: a new created session doesn't have a correct time set
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@719 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-18 09:33:15 +00:00
c8a57f2046 added: to gallery plugin: gallery_theme() mount option
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@718 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-15 23:20:12 +00:00
583df13139 added: mount options: thumb_size(cx, cy)
size of a generated thumbnail (size in pixels)
added: plugin gallery: mount option gallery_type
       it can be:
       "lightbox"
       "galleria"
       "galleriathumb"


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@717 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-11 21:37:28 +00:00
5049961e17 added a new plugin: "gallery"
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@716 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-31 15:51:53 +00:00
18492e5d61 changed templates
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@715 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-27 14:35:25 +00:00
d4d9f89d1d changed: ticket templates
added: new plugin message (WINIX_END_REQUEST)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@714 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-27 12:24:45 +00:00
ecf19034ae added: winix uses now [filter] statement from ezc
added: notifications to threads (were temporarily disabled)
changed: templates in notifications



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@712 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-26 12:45:38 +00:00
00521c490e added: Q encoding in misc: QEncode()
for mails headers encoding



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@711 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-25 11:54:46 +00:00
3071df227a fixed: find_ticket_value (in plugins/ticket/templates.cpp)
should find the first item (can be more than one item with the same 'param')

fixed: added sorting tickets params in ReadTicketParams() (in plugins/ticket/ticketinfo.cpp)

fixed: plugin should have its own 'PluginInfo info' struct
a plugin's function can call another plugin's functions

added: removing tickets files/images

added: removing threads

changed: rm function will call WINIX_FILE_REMOVED now when deleting directories





git-svn-id: svn://ttmath.org/publicrep/winix/trunk@710 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-23 23:23:24 +00:00
915cabdf97 changed: added Cur structure
we have there two pointers: 
 Request * request;
 Session * session;
these are the current request and the current session


the session GC was moved to SessionManager (was in SessionContainer)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@708 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-23 14:15:30 +00:00
61ac29b2de added in ticket/templates.cpp binary search for tickets and tickets parameters
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@707 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-21 16:16:52 +00:00
ab84a5169e 'tickets' can use 'threads' now
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@706 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-20 18:37:51 +00:00
3fad25b8c8 moved some thread files to plugins/thread
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@705 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-05 21:44:19 +00:00
8154c403d8 we can create links (hard links, symbolic links) now
added winix functions: ln

winix function 'default' can be used without redirecting now

added new tickets types: TypeProgress, TypeString, TypeMultistring, TypeImages, TypeFiles
now tickets are combined with files
added winix functions: showtickets

fixed mountpoints:
when the default root mount was created its parameter table was empty
and it caused accessing to a non-existing objects

fixed logger:
modifiers (log1, log2, log3) were incorrectly treated
added modifier: log4 (debug info)

now we are moving threads to a new plugin 'thread'
created directory: plugins/thread
(not finished yet)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@704 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-05 21:24:11 +00:00
bb83aed20d changed cat template
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@703 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-12 09:41:20 +00:00
600c9fc907 Thumb thread should check the exit signal
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@701 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-12 09:25:36 +00:00
5d09eb149c added a special thread for making thumbnails (thumb.h thumb.cpp)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@700 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-11 22:55:48 +00:00
e854fe3681 changed makefile
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@698 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-10 21:20:01 +00:00
36c8822e6c changed organization of static files
removed: item.auth item.auth_path
added:   item.file_path, item.file_fs, item.file_type
now the path to a static file is a relative path
added: thumbnails (not finished yet)
fixed: db didn't correctly return the number of deleted items /DelItem() method/




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@696 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-10 21:07:01 +00:00
9b29cce1a4 added a special default function: "-"
the proper default function will be selected automatically


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@695 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-07 18:18:45 +00:00
508f06339e added to config: session_max
how many sessions can be: default 1000000 (one milion)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@694 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-07 17:41:28 +00:00
0a9cdd2f15 added: gc for sessions (another thread)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@693 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-07 12:52:52 +00:00
7f77b6e3ec added ezc function: user_is_in_all_groups
changed: ezc function user_is_in_group (we can provide more than one group now)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@691 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-06 01:37:30 +00:00
9507b0b1ba changed Makefile
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@690 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-06 00:32:12 +00:00
ad9d6f4301 db: core/user table has only 'notify' column now (previous was cms_notify, thread_notify)
added: notifications for tickets (not finished yet)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@688 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-06 00:25:46 +00:00
b721fb6860 changed path templatesnotifiy/ to notify/
i forgot to add a file: notify/notify.cpp


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@687 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-02 02:36:49 +00:00
5f46cd2ea5 moved: templatesnotify -> notify
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@686 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-02 02:16:11 +00:00
35efed9fef - now the mess with threads has gone away
- we have a class BaseThread -- this is a base class -- we can inherit from it when
  creating a new thread
- others treads are correctly stopped (when signal comes) -- pthread_join
- we have a special thread only for signals



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@685 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-02 01:02:02 +00:00
08e53919e2 changed: updated to the new ezc api, this with O(1) when looking for a specific ezc function
changed: sessions are deleted at the end of a request (and only a few sessions)
         other sessions will be deleted after a next request


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@684 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 22:42:24 +00:00
933c8841ff added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
         int Toi(const std::string & str,  int base = 10);
         int Toi(const std::wstring & str, int base = 10);
         int Toi(const char * str,         int base = 10);
         int Toi(const wchar_t * str,      int base = 10);

         long Tol(const std::string & str,  int base = 10);
         long Tol(const std::wstring & str, int base = 10);
         long Tol(const char * str,         int base = 10);
         long Tol(const wchar_t * str,      int base = 10);

         template<class CharType>
         bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);

         const wchar_t * Toa(unsigned int value,  int base = 10);
         const wchar_t * Toa(unsigned long value, int base = 10);
         const wchar_t * Toa(int value,  int base = 10);
         const wchar_t * Toa(long value, int base = 10);

         void Toa(int  value, std::string & res,  int base = 10, bool clear = true);
         void Toa(long value, std::string & res,  int base = 10, bool clear = true);
         void Toa(int  value, std::wstring & res, int base = 10, bool clear = true);
         void Toa(long value, std::wstring & res, int base = 10, bool clear = true);

added:   HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
         this is a special stream for automatically escaping html tags
	     



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 01:34:46 +00:00
518281e101 fixed: when signal comes winix properly exits
fixed:   when winix exits the session data were not properly destroyed (memory leak)
         we should set request.session pointer to each session when deleting sessions
         from session_container
         the session data were not properly destroyed when winix checked for 
         outdated sessions (and when it was removing them)
fixed:   performance (memcpy used too often)
         in some places there were reserve method used (on std::wstring/std::string objects)
         especially in AssignString() method and TextStream<> object
         if we add a new string we should check the new size
         and only call reserve() if the new size will be greater than existing one
         (plus some constant)
changed: fcgi objects moved to App class (from Request)
         now we use thread safe methods (e.g. FCGX_Accept_r)
added:   log_plugin_call option to the config
         default: false
         when true winix log when a plugin function is called
added:   winix parameter 'nostat' for not calculating statistics
         (useful when making performance tests)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@680 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-23 21:52:25 +00:00
515d4bab0d added ezc functions: winix_false, winix_true
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@679 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-22 01:12:46 +00:00
8e72a820dd added support for UTF-8
now the UTF-8 is a default charset


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@677 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-21 00:19:17 +00:00
f1f0fa34cb fixed: didn't compile
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@676 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-04 17:13:13 +00:00
5010ef93e8 added temporary debug info to Notify::ItemChanged() method
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@674 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-04 17:05:59 +00:00
e6679a3192 added a new winix function "vim" - an editor based on the WYMeditor
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@673 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-04 16:46:19 +00:00
7cf8d5d2d3 added: to htmlfilter: param tag has not an ending tag
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@672 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-25 18:00:23 +00:00
14198eca41 fixed: some log problems
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@671 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-24 19:31:43 +00:00
c6473f20dc now winix can demonize itself
parameter in the config: demonize (default: true)
 


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@669 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-24 19:26:54 +00:00
9c34cb5862 winix can drop privileges now (if started as the root)
added parameters to the config:
 user (string)
 group (string)
 additional_groups (bool)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@668 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-24 17:49:38 +00:00
149fd1629f rm function can remove tickets now
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@667 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-23 23:51:44 +00:00
c48241f78a fixed: there were mktime() used on some dirs Items
so sometimes the time of the dir was changed

now for converting tm into time_t use:
time_t Time(const tm & par);
time_t Time(const tm * par);
tm     Time(time_t par);
from core/misc.h

now winix internally use GMT time
only when printing it is converted to local user time
temporarily all users use the same local time (config: time_zone_offset)
(only logs are genereted with local system time)

added to system:
time_t LocalTime(time_t gmt_time);
tm     LocalTime(const tm * ptm);
tm     LocalTime(const tm & ptm);
they convert GMT time to local user time




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@666 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-23 23:12:47 +00:00
a1bee81a5b added 'stat' winix function
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@665 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-23 14:54:44 +00:00
1b053c03ba added: now plugin ticket uses a new horizontal table (plugins.ticket)
columns: dir_id, param, value
we are able to build complicated tickets 



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@664 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-19 00:31:20 +00:00
33057acd62 added ticket parser: plugins/ticket/ticketparser.h plugins/ticket/ticketparser.cpp
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@663 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-11 20:42:49 +00:00
07511a2eb0 fixed: DbBase::ConvertTime(tm) should not have been used in this way as it was
(it uses a static buffer)
       now DbTextStream can get tm struct so you don't have to use ConvertTime 


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@662 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-09 20:27:45 +00:00
69c634d53f added to core/misc:
bool EqualNoCase(const std::string & str1, const std::string & str2)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@660 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-01 23:20:03 +00:00
7bc17a9202 fixed: ticket sets a default function only for directories
fixed: reading a new url and subject in Functions::ReadItem()
added: tickets are sorted now (by date)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@659 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-30 20:58:20 +00:00
d94a08b991 moved: plugins/ticket/ticket.cpp -> plugins/ticket/templates.cpp
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@658 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-29 22:41:34 +00:00
a8b8c1feec tickets has been moved to a new plugin 'ticket'
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@657 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-29 21:24:34 +00:00
a589e5a090 added: TextStream a class similar to std::ostringstream
but with a Clear() method
       the dynamic allocated buffer can be easily reused
added: DbTextStream a special version of a stream
       used to create a database string query
       everything is escaped by default
added: DbBase a base class with some basic methods for communicating
       with the database
added: DbConn a class for managing connection to the database
changed: some refactoring in Db class       



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@655 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-18 00:51:12 +00:00
8b1db3304f creating winix/db directory (for the database class)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@654 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-16 10:20:20 +00:00
23aedd68b0 changed: mount points
mount type and mount fs are of type 'int' now
they can be added by plugins


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@652 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-12 23:33:27 +00:00
f48f08a98b changed: notification's template
added: notifications in tickets


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@650 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-07 23:54:01 +00:00
81dd88d25a fixed: there was missing html/fun_editticket.html template
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@649 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-05 18:58:24 +00:00
c92081d6e1 added: to stats plugin: microsoft bing searcher
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@648 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-28 21:19:30 +00:00
d6e80f5a23 fixed: plugins path
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@647 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-17 23:48:42 +00:00
37cf71234c changed makefile
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@645 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-17 23:33:27 +00:00
3b655f39e1 added: plugins_dir to config
small changes in makefiles


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@643 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-17 22:32:47 +00:00
eec0ddf466 added: method ConfParser::UseEscapeChar(bool escape)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@642 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-16 14:15:37 +00:00
ca4e53bb0f html code in editors (emacs, ckeditor...) is filtered now for normal users
(root is allowed to use any html code)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@641 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 17:56:07 +00:00
d9f2e91806 removed some debug logs from emacs
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@640 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 17:07:13 +00:00
7bfed62526 emacs didn't correctly report errors from db
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@639 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 16:55:16 +00:00
b63ac98f40 now winix waites for the database to be ready (when the operating system starts)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@638 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 16:23:18 +00:00
1e7d297c0e small changes in template winix function
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@637 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 14:45:25 +00:00
f3cd3b88b9 some improvement in templates
(now we have O(1) time for selecting the right html template)
added: winix function: template
for selecting a template for an item (file or dir)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@636 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-13 20:04:57 +00:00
9a199cd834 part II of rewriting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@635 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-12 19:10:12 +00:00
c3fac2e83f changed method: void PostMultiParser::ReadContentToFileLoop()
previous version was not clean


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@634 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-11 15:47:44 +00:00
c7f6d2727c fixed: PostMultiParser incorrectly logged the size of input items (those which were not files)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@633 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-11 10:00:23 +00:00
9901c63ede removed some thread and ticket information from request
they are in FunThread and FunTicket classes now
added funtion FunUptime (I forgot about it)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@631 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-10 20:43:38 +00:00
76897b8a83 I have forgotten to create classes: Ckeditor and Tinymce (in functions)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@630 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-10 17:05:19 +00:00
375 changed files with 31138 additions and 12965 deletions

116
Makefile
View File

@@ -1,62 +1,106 @@
# Makefile for GNU make
ifndef CXX
CXX = g++
endif
ifndef CXXFLAGS
#CXXFLAGS = -fPIC -Wall -pedantic -O2 -I/usr/local/include -I/home/tomek/roboczy/winix -I/home/tomek/roboczy/ezc/src -L/usr/local/lib -DEZC_USE_WINIX_LOGGER
CXXFLAGS = -fPIC -Wall -pedantic -O0 -g -I/usr/local/include -I/home/tomek/roboczy/winix -I/home/tomek/roboczy/ezc/src -L/usr/local/lib -DEZC_USE_WINIX_LOGGER
CXXFLAGS = -fPIC -Wall -pedantic -O2 -I/usr/local/include -I/home/tomek/roboczy/winix -I/home/tomek/roboczy/ezc/src -L/usr/local/lib -DEZC_USE_WINIX_LOGGER -DEZC_HAS_SPECIAL_STREAM
endif
export CXX
export CXXFLAGS
all: winix.so plugins winix
winix.so: FORCE
@cd core ; $(MAKE) -e
@cd db ; $(MAKE) -e
@cd functions ; $(MAKE) -e
@cd notify ; $(MAKE) -e
@cd templates ; $(MAKE) -e
@cd ../ezc/src ; $(MAKE) -e
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a -lfcgi -lpq -lz -lpthread -lfetch
all: winix
winix: FORCE
@cd core ; $(MAKE) -e
@cd functions ; $(MAKE) -e
@cd templates ; $(MAKE) -e
@cd templatesnotify ; $(MAKE) -e
@cd plugins/stats ; $(MAKE) -e
@cd ../ezc/src ; $(MAKE) -e
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o functions/*.o templates/*.o templatesnotify/*.o ../ezc/src/ezc.a -lfcgi -lpq -lz -lpthread
@cd main ; $(MAKE) -e
# use the full path with winix.so
$(CXX) -o winix $(CXXFLAGS) main/*.o /home/tomek/roboczy/winix/winix.so
$(CXX) -o winix $(CXXFLAGS) main/*.o /home/tomek/roboczy/winix/winix.so
clean:
@cd core ; $(MAKE) -e clean
@cd functions ; $(MAKE) -e clean
@cd templates ; $(MAKE) -e clean
@cd templatesnotify ; $(MAKE) -e clean
@cd plugins/stats ; $(MAKE) -e clean
@cd ../ezc/src ; $(MAKE) -e clean
@cd main ; $(MAKE) -e clean
rm -f winix.so
rm -f winix
plugins: FORCE
@cd plugins/stats ; $(MAKE) -e
@cd plugins/thread ; $(MAKE) -e
@cd plugins/ticket ; $(MAKE) -e
@cd plugins/gallery ; $(MAKE) -e
@cd plugins/groupitem ; $(MAKE) -e
FORCE:
depend:
@cd core ; $(MAKE) -e depend
@cd functions ; $(MAKE) -e depend
@cd templates ; $(MAKE) -e depend
@cd templatesnotify ; $(MAKE) -e depend
@cd plugins/stats ; $(MAKE) -e depend
@cd ../ezc/src ; $(MAKE) -e depend
@cd main ; $(MAKE) -e depend
clean:
@cd core ; $(MAKE) -e clean
@cd db ; $(MAKE) -e clean
@cd functions ; $(MAKE) -e clean
@cd templates ; $(MAKE) -e clean
@cd notify ; $(MAKE) -e clean
@cd plugins/stats ; $(MAKE) -e clean
@cd plugins/thread ; $(MAKE) -e clean
@cd plugins/ticket ; $(MAKE) -e clean
@cd plugins/gallery ; $(MAKE) -e clean
@cd plugins/groupitem ; $(MAKE) -e clean
@cd ../ezc/src ; $(MAKE) -e clean
@cd main ; $(MAKE) -e clean
rm -f winix.so
rm -f winix
#install: all
# mkdir -p bin
# rm -f bin/winix.so
# rm -f bin/winix
# cp winix.so bin/
# cp winix bin/
depend:
@cd core ; $(MAKE) -e depend
@cd db ; $(MAKE) -e depend
@cd functions ; $(MAKE) -e depend
@cd templates ; $(MAKE) -e depend
@cd notify ; $(MAKE) -e depend
@cd plugins/stats ; $(MAKE) -e depend
@cd plugins/thread ; $(MAKE) -e depend
@cd plugins/ticket ; $(MAKE) -e depend
@cd plugins/gallery ; $(MAKE) -e depend
@cd plugins/groupitem ; $(MAKE) -e depend
@cd ../ezc/src ; $(MAKE) -e depend
@cd main ; $(MAKE) -e depend
install: all
# binaries
mkdir -p /usr/local/winix/bin
cp winix.so /usr/local/winix/bin
# use the full path with winix.so (we have to recompile winix with a new path to winix.so)
$(CXX) -o /usr/local/winix/bin/winix $(CXXFLAGS) main/*.o /usr/local/winix/bin/winix.so
# html templates
mkdir -p /usr/local/winix/html
cp -rf html/ /usr/local/winix/html/
find /usr/local/winix/html/ -type d -name ".svn" | xargs -I foo rm -fr foo
# txt templates
mkdir -p /usr/local/winix/txt
cp -rf txt/ /usr/local/winix/txt/
find /usr/local/winix/txt/ -type d -name ".svn" | xargs -I foo rm -fr foo
# locales
mkdir -p /usr/local/winix/locale
cp -rf locale/ /usr/local/winix/locale/
find /usr/local/winix/locale/ -type d -name ".svn" | xargs -I foo rm -fr foo
# plugins
mkdir -p /usr/local/winix/plugins
find plugins/ -name "*.so" | xargs -I foo cp foo /usr/local/winix/plugins/
# removed provileges for others
find /usr/local/winix -exec chmod o-r,o-x,o-w "{}" "+"

View File

@@ -1 +0,0 @@
# DO NOT DELETE

View File

@@ -1 +0,0 @@
o =

View File

@@ -4,13 +4,10 @@ include Makefile.o.dep
all: $(o)
.SUFFIXES: .cpp .o
.cpp.o:
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $<
depend:
makedepend -Y. -I.. -I../../ezc/src -f- *.cpp > Makefile.dep
echo -n "o = " > Makefile.o.dep

View File

@@ -1,261 +1,454 @@
# DO NOT DELETE
Kopia config.o: ../core/log.h ../core/request.h requesttypes.h session.h
Kopia config.o: item.h error.h log.h user.h plugindata.h rebus.h thread.h
Kopia config.o: compress.h acceptencodingparser.h acceptbaseparser.h
Kopia config.o: htmlfilter.h postmultiparser.h config.h confparser.h ticket.h
Kopia config.o: ../core/config.h ../core/db.h group.h dircontainer.h
Kopia config.o: ugcontainer.h
acceptbaseparser.o: acceptbaseparser.h
app.o: app.h config.h confparser.h system.h dirs.h item.h dircontainer.h db.h
app.o: user.h group.h thread.h error.h log.h ugcontainer.h ticket.h request.h
app.o: requesttypes.h session.h plugindata.h rebus.h compress.h
app.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
app.o: postmultiparser.h mounts.h mount.h users.h lastcontainer.h groups.h
app.o: loadavg.h sessionmanager.h sessioncontainer.h notify.h
app.o: ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
app.o: ../core/mount.h ../core/locale.h ../core/config.h ../templates/misc.h
app.o: ../templates/localefilter.h ../core/locale.h ../functions/functions.h
app.o: ../functions/functionbase.h ../core/item.h ../core/db.h
app.o: ../core/request.h ../core/system.h ../core/notify.h
app.o: ../functions/functionparser.h ../functions/adduser.h
app.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
app.o: ../functions/chown.h ../functions/cp.h ../functions/createthread.h
app.o: ../functions/createticket.h ../functions/default.h
app.o: ../functions/download.h ../functions/editticket.h ../functions/emacs.h
app.o: ../functions/last.h ../functions/login.h ../functions/logout.h
app.o: app.h config.h confparser.h htmlfilter.h system.h dirs.h item.h
app.o: dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
app.o: ../db/dbtextstream.h ../core/textstream.h misc.h ../core/error.h
app.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
app.o: ../core/user.h ../core/group.h ../core/dircontainer.h
app.o: ../core/ugcontainer.h log.h textstream.h logmanipulators.h slog.h
app.o: cur.h request.h requesttypes.h error.h ../templates/htmltextstream.h
app.o: session.h user.h plugindata.h rebus.h ../templates/locale.h
app.o: ../core/confparser.h ../notify/notify.h ../notify/notifypool.h
app.o: ../templates/misc.h ../templates/localefilter.h ../templates/locale.h
app.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
app.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
app.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
app.o: ../templates/htmltextstream.h ../notify/notifythread.h
app.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
app.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
app.o: mounts.h mount.h mountparser.h crypt.h run.h users.h groups.h group.h
app.o: loadavg.h thumb.h basethread.h sessionmanager.h sessioncontainer.h
app.o: ../functions/functions.h ../functions/functionbase.h ../core/request.h
app.o: ../core/system.h ../core/synchro.h ../functions/functionparser.h
app.o: ../core/cur.h ../functions/adduser.h ../functions/cat.h
app.o: ../functions/chmod.h ../functions/privchanger.h ../functions/chown.h
app.o: ../functions/ckeditor.h ../functions/cp.h ../functions/default.h
app.o: ../functions/download.h ../functions/emacs.h ../functions/last.h
app.o: ../functions/login.h ../functions/logout.h ../functions/ln.h
app.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
app.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
app.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
app.o: ../functions/funthread.h ../core/thread.h ../functions/funticket.h
app.o: ../functions/uname.h ../functions/upload.h ../functions/who.h
app.o: ../templates/templates.h ../templates/patterncacher.h ../core/item.h
app.o: misc.h ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
app.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
app.o: plugin.h pluginmsg.h
app.o: ../functions/nicedit.h ../functions/node.h ../functions/priv.h
app.o: ../functions/reload.h ../functions/rm.h ../functions/specialdefault.h
app.o: ../functions/stat.h ../functions/subject.h ../functions/template.h
app.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
app.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
app.o: ../core/htmlfilter.h ../templates/templates.h
app.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
app.o: ../core/httpsimpleparser.h ../core/log.h ../templates/indexpatterns.h
app.o: ../core/sessionmanager.h compress.h getparser.h httpsimpleparser.h
app.o: postparser.h cookieparser.h postmultiparser.h acceptencodingparser.h
app.o: acceptbaseparser.h plugin.h pluginmsg.h
basethread.o: basethread.h log.h textstream.h logmanipulators.h slog.h cur.h
basethread.o: request.h requesttypes.h item.h error.h config.h confparser.h
basethread.o: htmlfilter.h ../templates/htmltextstream.h ../core/textstream.h
basethread.o: misc.h session.h user.h plugindata.h rebus.h
basethread.o: ../templates/locale.h ../core/confparser.h
bbcodeparser.o: bbcodeparser.h htmlfilter.h
compress.o: compress.h log.h
config.o: config.h confparser.h log.h plugin.h pluginmsg.h plugindata.h
config.o: request.h requesttypes.h session.h item.h error.h user.h rebus.h
config.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
config.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
config.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h users.h
config.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
compress.o: compress.h log.h textstream.h logmanipulators.h slog.h cur.h
compress.o: request.h requesttypes.h item.h error.h config.h confparser.h
compress.o: htmlfilter.h ../templates/htmltextstream.h ../core/textstream.h
compress.o: misc.h session.h user.h plugindata.h rebus.h
compress.o: ../templates/locale.h ../core/confparser.h
config.o: config.h confparser.h htmlfilter.h log.h textstream.h
config.o: logmanipulators.h slog.h cur.h request.h requesttypes.h item.h
config.o: error.h ../templates/htmltextstream.h ../core/textstream.h misc.h
config.o: session.h user.h plugindata.h rebus.h ../templates/locale.h
config.o: ../core/confparser.h plugin.h pluginmsg.h system.h dirs.h
config.o: dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
config.o: ../db/dbtextstream.h ../core/error.h ../db/dbitemquery.h
config.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h ../core/group.h
config.o: ../core/dircontainer.h ../core/ugcontainer.h ../notify/notify.h
config.o: ../notify/notifypool.h ../templates/misc.h
config.o: ../templates/localefilter.h ../templates/locale.h
config.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
config.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
config.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
config.o: ../templates/htmltextstream.h ../notify/notifythread.h
config.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
config.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
config.o: mounts.h mount.h mountparser.h crypt.h run.h users.h groups.h
config.o: group.h loadavg.h thumb.h basethread.h sessionmanager.h
config.o: sessioncontainer.h ../functions/functions.h
config.o: ../functions/functionbase.h ../core/item.h ../core/db.h
config.o: ../core/request.h ../core/config.h ../core/system.h
config.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
config.o: ../functions/functionbase.h ../core/request.h ../core/system.h
config.o: ../core/synchro.h ../functions/functionparser.h ../core/cur.h
config.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
config.o: ../functions/privchanger.h ../functions/chown.h ../functions/cp.h
config.o: ../functions/createthread.h ../functions/createticket.h
config.o: ../functions/default.h ../functions/download.h
config.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
config.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
config.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
config.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
config.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
config.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
config.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
config.o: ../templates/patterncacher.h ../core/item.h misc.h
config.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
config.o: ../core/log.h ../templates/indexpatterns.h
config.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
config.o: ../core/sessionmanager.h
confparser.o: confparser.h misc.h item.h
db.o: db.h item.h user.h group.h thread.h error.h log.h dircontainer.h
db.o: ugcontainer.h ticket.h misc.h
db_itemcolumns.o: db.h item.h user.h group.h thread.h error.h log.h
db_itemcolumns.o: dircontainer.h ugcontainer.h ticket.h
dircontainer.o: dircontainer.h item.h log.h
dirs.o: dirs.h item.h dircontainer.h db.h user.h group.h thread.h error.h
dirs.o: log.h ugcontainer.h ticket.h request.h requesttypes.h session.h
dirs.o: plugindata.h rebus.h compress.h acceptencodingparser.h
dirs.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
dirs.o: confparser.h
groups.o: groups.h group.h ugcontainer.h log.h db.h item.h user.h thread.h
groups.o: error.h dircontainer.h ticket.h
config.o: ../functions/privchanger.h ../functions/chown.h
config.o: ../functions/ckeditor.h ../functions/cp.h ../functions/default.h
config.o: ../functions/download.h ../functions/emacs.h ../functions/last.h
config.o: ../functions/login.h ../functions/logout.h ../functions/ln.h
config.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
config.o: ../functions/nicedit.h ../functions/node.h ../functions/priv.h
config.o: ../functions/reload.h ../functions/rm.h
config.o: ../functions/specialdefault.h ../functions/stat.h
config.o: ../functions/subject.h ../functions/template.h
config.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
config.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
config.o: ../core/htmlfilter.h ../templates/templates.h
config.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
config.o: ../core/httpsimpleparser.h ../core/log.h
config.o: ../templates/indexpatterns.h ../core/sessionmanager.h
confparser.o: confparser.h misc.h item.h ../../ezc/src/utf8.h
crypt.o: crypt.h run.h config.h confparser.h htmlfilter.h user.h
crypt.o: ../../ezc/src/utf8.h misc.h item.h log.h textstream.h
crypt.o: logmanipulators.h slog.h cur.h request.h requesttypes.h error.h
crypt.o: ../templates/htmltextstream.h ../core/textstream.h session.h
crypt.o: plugindata.h rebus.h ../templates/locale.h ../core/confparser.h
dircontainer.o: dircontainer.h item.h log.h textstream.h logmanipulators.h
dircontainer.o: slog.h cur.h request.h requesttypes.h error.h config.h
dircontainer.o: confparser.h htmlfilter.h ../templates/htmltextstream.h
dircontainer.o: ../core/textstream.h misc.h session.h user.h plugindata.h
dircontainer.o: rebus.h ../templates/locale.h ../core/confparser.h
dirs.o: dirs.h item.h dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
dirs.o: ../db/dbtextstream.h ../core/textstream.h misc.h ../core/error.h
dirs.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
dirs.o: ../core/user.h ../core/group.h ../core/dircontainer.h
dirs.o: ../core/ugcontainer.h log.h textstream.h logmanipulators.h slog.h
dirs.o: cur.h request.h requesttypes.h error.h config.h confparser.h
dirs.o: htmlfilter.h ../templates/htmltextstream.h session.h user.h
dirs.o: plugindata.h rebus.h ../templates/locale.h ../core/confparser.h
dirs.o: ../notify/notify.h ../notify/notifypool.h ../templates/misc.h
dirs.o: ../templates/localefilter.h ../templates/locale.h ../../ezc/src/ezc.h
dirs.o: ../../ezc/src/utf8.h ../../ezc/src/generator.h
dirs.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
dirs.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
dirs.o: ../templates/htmltextstream.h ../notify/notifythread.h
dirs.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
dirs.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
groups.o: groups.h group.h ugcontainer.h ../db/db.h ../db/dbbase.h
groups.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h misc.h
groups.o: item.h ../core/error.h ../db/dbitemquery.h ../core/item.h
groups.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
groups.o: ../core/dircontainer.h ../core/ugcontainer.h log.h textstream.h
groups.o: logmanipulators.h slog.h cur.h request.h requesttypes.h error.h
groups.o: config.h confparser.h htmlfilter.h ../templates/htmltextstream.h
groups.o: session.h user.h plugindata.h rebus.h ../templates/locale.h
groups.o: ../core/confparser.h
htmlfilter.o: htmlfilter.h
httpsimpleparser.o: httpsimpleparser.h
lastcontainer.o: lastcontainer.h log.h
loadavg.o: loadavg.h log.h
locale.o: locale.h confparser.h log.h
log.o: log.h
misc.o: misc.h item.h log.h
mount.o: mount.h
mountparser.o: mountparser.h mount.h item.h error.h log.h dirs.h
mountparser.o: dircontainer.h db.h user.h group.h thread.h ugcontainer.h
mountparser.o: ticket.h request.h requesttypes.h session.h plugindata.h
mountparser.o: rebus.h compress.h acceptencodingparser.h acceptbaseparser.h
mountparser.o: htmlfilter.h postmultiparser.h config.h confparser.h misc.h
mounts.o: mounts.h mount.h error.h log.h dirs.h item.h dircontainer.h db.h
mounts.o: user.h group.h thread.h ugcontainer.h ticket.h request.h
mounts.o: requesttypes.h session.h plugindata.h rebus.h compress.h
mounts.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
mounts.o: postmultiparser.h config.h confparser.h mountparser.h
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h
notify.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h confparser.h
notify.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
notify.o: ../core/locale.h request.h requesttypes.h session.h item.h error.h
notify.o: user.h plugindata.h rebus.h thread.h compress.h
notify.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
notify.o: postmultiparser.h config.h ticket.h system.h dirs.h dircontainer.h
notify.o: db.h group.h ugcontainer.h mounts.h mount.h users.h lastcontainer.h
notify.o: groups.h loadavg.h misc.h
plugin.o: plugin.h pluginmsg.h log.h plugindata.h config.h confparser.h
plugin.o: request.h requesttypes.h session.h item.h error.h user.h rebus.h
plugin.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
plugin.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
plugin.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h users.h
plugin.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
plugin.o: sessioncontainer.h ../functions/functions.h
plugin.o: ../functions/functionbase.h ../core/item.h ../core/db.h
plugin.o: ../core/request.h ../core/config.h ../core/system.h
plugin.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
plugin.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
plugin.o: ../functions/privchanger.h ../functions/chown.h ../functions/cp.h
plugin.o: ../functions/createthread.h ../functions/createticket.h
plugin.o: ../functions/default.h ../functions/download.h
plugin.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
plugin.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
plugin.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
item.o: item.h misc.h
lastcontainer.o: lastcontainer.h log.h textstream.h logmanipulators.h slog.h
lastcontainer.o: cur.h request.h requesttypes.h item.h error.h config.h
lastcontainer.o: confparser.h htmlfilter.h ../templates/htmltextstream.h
lastcontainer.o: ../core/textstream.h misc.h session.h user.h plugindata.h
lastcontainer.o: rebus.h ../templates/locale.h ../core/confparser.h
loadavg.o: loadavg.h log.h textstream.h logmanipulators.h slog.h cur.h
loadavg.o: request.h requesttypes.h item.h error.h config.h confparser.h
loadavg.o: htmlfilter.h ../templates/htmltextstream.h ../core/textstream.h
loadavg.o: misc.h session.h user.h plugindata.h rebus.h ../templates/locale.h
loadavg.o: ../core/confparser.h
log.o: log.h textstream.h logmanipulators.h slog.h cur.h request.h
log.o: requesttypes.h item.h error.h config.h confparser.h htmlfilter.h
log.o: ../templates/htmltextstream.h ../core/textstream.h misc.h session.h
log.o: user.h plugindata.h rebus.h ../templates/locale.h ../core/confparser.h
log.o: ../../ezc/src/utf8.h
misc.o: misc.h item.h log.h textstream.h logmanipulators.h slog.h cur.h
misc.o: request.h requesttypes.h error.h config.h confparser.h htmlfilter.h
misc.o: ../templates/htmltextstream.h ../core/textstream.h session.h user.h
misc.o: plugindata.h rebus.h ../templates/locale.h ../core/confparser.h
misc.o: ../templates/templates.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
misc.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
misc.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
misc.o: ../../ezc/src/stringconv.h ../templates/patterncacher.h
misc.o: ../core/item.h ../templates/ckeditorgetparser.h
misc.o: ../core/httpsimpleparser.h ../core/log.h ../templates/indexpatterns.h
misc.o: ../templates/localefilter.h ../templates/locale.h ../core/config.h
misc.o: ../templates/htmltextstream.h ../core/cur.h ../core/system.h
misc.o: ../core/sessionmanager.h ../core/htmlfilter.h ../db/db.h
misc.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h ../core/error.h
misc.o: ../db/dbitemquery.h ../db/dbitemcolumns.h ../core/user.h
misc.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
mount.o: mount.h misc.h item.h
mountparser.o: mountparser.h mount.h item.h dirs.h dircontainer.h ../db/db.h
mountparser.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
mountparser.o: ../core/textstream.h misc.h ../core/error.h
mountparser.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
mountparser.o: ../core/user.h ../core/group.h ../core/dircontainer.h
mountparser.o: ../core/ugcontainer.h log.h textstream.h logmanipulators.h
mountparser.o: slog.h cur.h request.h requesttypes.h error.h config.h
mountparser.o: confparser.h htmlfilter.h ../templates/htmltextstream.h
mountparser.o: session.h user.h plugindata.h rebus.h ../templates/locale.h
mountparser.o: ../core/confparser.h ../notify/notify.h ../notify/notifypool.h
mountparser.o: ../templates/misc.h ../templates/localefilter.h
mountparser.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
mountparser.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
mountparser.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
mountparser.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
mountparser.o: ../notify/notifythread.h ../core/basethread.h synchro.h
mountparser.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
mountparser.o: ugcontainer.h lastcontainer.h
mounts.o: mounts.h mount.h error.h dirs.h item.h dircontainer.h ../db/db.h
mounts.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
mounts.o: ../core/textstream.h misc.h ../core/error.h ../db/dbitemquery.h
mounts.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h ../core/group.h
mounts.o: ../core/dircontainer.h ../core/ugcontainer.h log.h textstream.h
mounts.o: logmanipulators.h slog.h cur.h request.h requesttypes.h config.h
mounts.o: confparser.h htmlfilter.h ../templates/htmltextstream.h session.h
mounts.o: user.h plugindata.h rebus.h ../templates/locale.h
mounts.o: ../core/confparser.h ../notify/notify.h ../notify/notifypool.h
mounts.o: ../templates/misc.h ../templates/localefilter.h
mounts.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
mounts.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
mounts.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
mounts.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
mounts.o: ../notify/notifythread.h ../core/basethread.h synchro.h
mounts.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
mounts.o: ugcontainer.h lastcontainer.h mountparser.h plugin.h pluginmsg.h
mounts.o: system.h crypt.h run.h users.h groups.h group.h loadavg.h thumb.h
mounts.o: basethread.h sessionmanager.h sessioncontainer.h
mounts.o: ../functions/functions.h ../functions/functionbase.h
mounts.o: ../core/request.h ../core/system.h ../core/synchro.h
mounts.o: ../functions/functionparser.h ../core/cur.h ../functions/adduser.h
mounts.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
mounts.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
mounts.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
mounts.o: ../functions/last.h ../functions/login.h ../functions/logout.h
mounts.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
mounts.o: ../functions/mv.h ../functions/nicedit.h ../functions/node.h
mounts.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
mounts.o: ../functions/specialdefault.h ../functions/stat.h
mounts.o: ../functions/subject.h ../functions/template.h
mounts.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
mounts.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
mounts.o: ../core/htmlfilter.h ../templates/templates.h
mounts.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
mounts.o: ../core/httpsimpleparser.h ../core/log.h
mounts.o: ../templates/indexpatterns.h ../core/sessionmanager.h
plugin.o: plugin.h pluginmsg.h log.h textstream.h logmanipulators.h slog.h
plugin.o: cur.h request.h requesttypes.h item.h error.h config.h confparser.h
plugin.o: htmlfilter.h ../templates/htmltextstream.h ../core/textstream.h
plugin.o: misc.h session.h user.h plugindata.h rebus.h ../templates/locale.h
plugin.o: ../core/confparser.h system.h dirs.h dircontainer.h ../db/db.h
plugin.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h ../core/error.h
plugin.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
plugin.o: ../core/user.h ../core/group.h ../core/dircontainer.h
plugin.o: ../core/ugcontainer.h ../notify/notify.h ../notify/notifypool.h
plugin.o: ../templates/misc.h ../templates/localefilter.h
plugin.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
plugin.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
plugin.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
plugin.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
plugin.o: ../notify/notifythread.h ../core/basethread.h synchro.h
plugin.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
plugin.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h
plugin.o: crypt.h run.h users.h groups.h group.h loadavg.h thumb.h
plugin.o: basethread.h sessionmanager.h sessioncontainer.h
plugin.o: ../functions/functions.h ../functions/functionbase.h
plugin.o: ../core/request.h ../core/system.h ../core/synchro.h
plugin.o: ../functions/functionparser.h ../core/cur.h ../functions/adduser.h
plugin.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
plugin.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
plugin.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
plugin.o: ../functions/last.h ../functions/login.h ../functions/logout.h
plugin.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
plugin.o: ../functions/mv.h ../functions/nicedit.h ../functions/node.h
plugin.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
plugin.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
plugin.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
plugin.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
plugin.o: ../templates/patterncacher.h ../core/item.h misc.h
plugin.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
plugin.o: ../core/log.h ../templates/indexpatterns.h
plugin.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
plugin.o: ../core/sessionmanager.h
plugindata.o: plugindata.h plugin.h pluginmsg.h log.h config.h confparser.h
plugindata.o: request.h requesttypes.h session.h item.h error.h user.h
plugindata.o: rebus.h thread.h compress.h acceptencodingparser.h
plugindata.o: acceptbaseparser.h htmlfilter.h postmultiparser.h ticket.h
plugindata.o: system.h dirs.h dircontainer.h db.h group.h ugcontainer.h
plugindata.o: mounts.h mount.h users.h lastcontainer.h groups.h loadavg.h
plugindata.o: sessionmanager.h sessioncontainer.h ../functions/functions.h
plugindata.o: ../functions/functionbase.h ../core/item.h ../core/db.h
plugindata.o: ../core/request.h ../core/config.h ../core/system.h
plugindata.o: ../core/notify.h ../../ezc/src/ezc.h
plugindata.o: ../functions/functionparser.h ../functions/adduser.h
plugindata.o: ../functions/cat.h ../functions/chmod.h
plugin.o: ../functions/specialdefault.h ../functions/stat.h
plugin.o: ../functions/subject.h ../functions/template.h
plugin.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
plugin.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
plugin.o: ../core/htmlfilter.h ../templates/templates.h
plugin.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
plugin.o: ../core/httpsimpleparser.h ../core/log.h
plugin.o: ../templates/indexpatterns.h ../core/sessionmanager.h
plugindata.o: plugindata.h plugin.h pluginmsg.h log.h textstream.h
plugindata.o: logmanipulators.h slog.h cur.h request.h requesttypes.h item.h
plugindata.o: error.h config.h confparser.h htmlfilter.h
plugindata.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
plugindata.o: session.h user.h rebus.h ../templates/locale.h
plugindata.o: ../core/confparser.h system.h dirs.h dircontainer.h ../db/db.h
plugindata.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
plugindata.o: ../core/error.h ../db/dbitemquery.h ../core/item.h
plugindata.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
plugindata.o: ../core/dircontainer.h ../core/ugcontainer.h ../notify/notify.h
plugindata.o: ../notify/notifypool.h ../templates/misc.h
plugindata.o: ../templates/localefilter.h ../templates/locale.h
plugindata.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h
plugindata.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
plugindata.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
plugindata.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
plugindata.o: ../notify/notifythread.h ../core/basethread.h synchro.h
plugindata.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
plugindata.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h
plugindata.o: crypt.h run.h users.h groups.h group.h loadavg.h thumb.h
plugindata.o: basethread.h sessionmanager.h sessioncontainer.h
plugindata.o: ../functions/functions.h ../functions/functionbase.h
plugindata.o: ../core/request.h ../core/system.h ../core/synchro.h
plugindata.o: ../functions/functionparser.h ../core/cur.h
plugindata.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
plugindata.o: ../functions/privchanger.h ../functions/chown.h
plugindata.o: ../functions/cp.h ../functions/createthread.h
plugindata.o: ../functions/createticket.h ../functions/default.h
plugindata.o: ../functions/download.h ../functions/editticket.h
plugindata.o: ../functions/ckeditor.h ../functions/cp.h
plugindata.o: ../functions/default.h ../functions/download.h
plugindata.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
plugindata.o: ../functions/logout.h ../functions/ls.h ../functions/mkdir.h
plugindata.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
plugindata.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
plugindata.o: ../functions/subject.h ../functions/funthread.h
plugindata.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
plugindata.o: ../functions/upload.h ../functions/who.h
plugindata.o: ../templates/templates.h ../templates/patterncacher.h
plugindata.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
plugindata.o: ../functions/logout.h ../functions/ln.h ../functions/ls.h
plugindata.o: ../functions/mkdir.h ../functions/mv.h ../functions/nicedit.h
plugindata.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
plugindata.o: ../functions/rm.h ../functions/specialdefault.h
plugindata.o: ../functions/stat.h ../functions/subject.h
plugindata.o: ../functions/template.h ../functions/tinymce.h
plugindata.o: ../functions/uname.h ../functions/upload.h
plugindata.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
plugindata.o: ../core/htmlfilter.h ../templates/templates.h
plugindata.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
plugindata.o: ../core/httpsimpleparser.h ../core/log.h
plugindata.o: ../templates/indexpatterns.h ../templates/localefilter.h
plugindata.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
postmultiparser.o: postmultiparser.h error.h log.h requesttypes.h config.h
postmultiparser.o: confparser.h
rebus.o: log.h rebus.h misc.h item.h request.h requesttypes.h session.h
rebus.o: error.h user.h plugindata.h thread.h compress.h
rebus.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
rebus.o: postmultiparser.h config.h confparser.h ticket.h
request.o: request.h requesttypes.h session.h item.h error.h log.h user.h
request.o: plugindata.h rebus.h thread.h compress.h acceptencodingparser.h
request.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
request.o: confparser.h ticket.h getparser.h httpsimpleparser.h postparser.h
request.o: cookieparser.h plugin.h pluginmsg.h system.h dirs.h dircontainer.h
request.o: db.h group.h ugcontainer.h mounts.h mount.h users.h
request.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
plugindata.o: ../templates/indexpatterns.h ../core/sessionmanager.h
postmultiparser.o: postmultiparser.h error.h requesttypes.h config.h
postmultiparser.o: confparser.h htmlfilter.h log.h textstream.h
postmultiparser.o: logmanipulators.h slog.h cur.h request.h item.h
postmultiparser.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
postmultiparser.o: session.h user.h plugindata.h rebus.h
postmultiparser.o: ../templates/locale.h ../core/confparser.h
postmultiparser.o: ../../ezc/src/utf8.h
rebus.o: log.h textstream.h logmanipulators.h slog.h cur.h request.h
rebus.o: requesttypes.h item.h error.h config.h confparser.h htmlfilter.h
rebus.o: ../templates/htmltextstream.h ../core/textstream.h misc.h session.h
rebus.o: user.h plugindata.h rebus.h ../templates/locale.h
rebus.o: ../core/confparser.h
request.o: request.h requesttypes.h item.h error.h config.h confparser.h
request.o: htmlfilter.h textstream.h ../templates/htmltextstream.h
request.o: ../core/textstream.h misc.h log.h logmanipulators.h slog.h cur.h
request.o: session.h user.h plugindata.h rebus.h ../templates/locale.h
request.o: ../core/confparser.h plugin.h pluginmsg.h system.h dirs.h
request.o: dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
request.o: ../db/dbtextstream.h ../core/error.h ../db/dbitemquery.h
request.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h
request.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
request.o: ../notify/notify.h ../notify/notifypool.h ../templates/misc.h
request.o: ../templates/localefilter.h ../templates/locale.h
request.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.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: ../templates/htmltextstream.h ../notify/notifythread.h
request.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
request.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
request.o: mounts.h mount.h mountparser.h crypt.h run.h users.h groups.h
request.o: group.h loadavg.h thumb.h basethread.h sessionmanager.h
request.o: sessioncontainer.h ../functions/functions.h
request.o: ../functions/functionbase.h ../core/item.h ../core/db.h
request.o: ../core/request.h ../core/config.h ../core/system.h
request.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.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 ../functions/cp.h
request.o: ../functions/createthread.h ../functions/createticket.h
request.o: ../functions/default.h ../functions/download.h
request.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
request.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
request.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
request.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
request.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
request.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
request.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
request.o: ../templates/patterncacher.h ../core/item.h misc.h
request.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
request.o: ../core/log.h ../templates/indexpatterns.h
request.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
request.o: ../core/sessionmanager.h ../functions/functionbase.h
session.o: session.h item.h error.h log.h user.h plugindata.h rebus.h
sessioncontainer.o: sessioncontainer.h session.h item.h error.h log.h user.h
sessioncontainer.o: plugindata.h rebus.h lastcontainer.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/last.h
request.o: ../functions/login.h ../functions/logout.h ../functions/ln.h
request.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
request.o: ../functions/nicedit.h ../functions/node.h ../functions/priv.h
request.o: ../functions/reload.h ../functions/rm.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
request.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
request.o: ../core/htmlfilter.h ../templates/templates.h
request.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
request.o: ../core/httpsimpleparser.h ../core/log.h
request.o: ../templates/indexpatterns.h ../core/sessionmanager.h
run.o: run.h log.h textstream.h logmanipulators.h slog.h cur.h request.h
run.o: requesttypes.h item.h error.h config.h confparser.h htmlfilter.h
run.o: ../templates/htmltextstream.h ../core/textstream.h misc.h session.h
run.o: user.h plugindata.h rebus.h ../templates/locale.h ../core/confparser.h
session.o: session.h item.h error.h user.h plugindata.h rebus.h textstream.h
session.o: misc.h
sessioncontainer.o: sessioncontainer.h session.h item.h error.h user.h
sessioncontainer.o: plugindata.h rebus.h textstream.h cur.h request.h
sessioncontainer.o: requesttypes.h config.h confparser.h htmlfilter.h
sessioncontainer.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessioncontainer.o: log.h logmanipulators.h slog.h ../templates/locale.h
sessioncontainer.o: ../core/confparser.h
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h item.h
sessionmanager.o: error.h log.h user.h plugindata.h rebus.h lastcontainer.h
sessionmanager.o: config.h confparser.h request.h requesttypes.h thread.h
sessionmanager.o: compress.h acceptencodingparser.h acceptbaseparser.h
sessionmanager.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
sessionmanager.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h
sessionmanager.o: users.h groups.h loadavg.h sessionparser.h plugin.h
sessionmanager.o: error.h user.h plugindata.h rebus.h textstream.h cur.h
sessionmanager.o: request.h requesttypes.h config.h confparser.h htmlfilter.h
sessionmanager.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessionmanager.o: lastcontainer.h system.h dirs.h dircontainer.h ../db/db.h
sessionmanager.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
sessionmanager.o: ../core/error.h ../db/dbitemquery.h ../core/item.h
sessionmanager.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
sessionmanager.o: ../core/dircontainer.h ../core/ugcontainer.h log.h
sessionmanager.o: logmanipulators.h slog.h ../templates/locale.h
sessionmanager.o: ../core/confparser.h ../notify/notify.h
sessionmanager.o: ../notify/notifypool.h ../templates/misc.h
sessionmanager.o: ../templates/localefilter.h ../templates/locale.h
sessionmanager.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h
sessionmanager.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
sessionmanager.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
sessionmanager.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
sessionmanager.o: ../notify/notifythread.h ../core/basethread.h synchro.h
sessionmanager.o: ../notify/templatesnotify.h ../core/config.h
sessionmanager.o: ../core/users.h ugcontainer.h mounts.h mount.h
sessionmanager.o: mountparser.h crypt.h run.h users.h groups.h group.h
sessionmanager.o: loadavg.h thumb.h basethread.h sessionparser.h plugin.h
sessionmanager.o: pluginmsg.h ../functions/functions.h
sessionmanager.o: ../functions/functionbase.h ../core/item.h ../core/db.h
sessionmanager.o: ../core/request.h ../core/config.h ../core/system.h
sessionmanager.o: ../core/notify.h ../../ezc/src/ezc.h
sessionmanager.o: ../functions/functionparser.h ../functions/adduser.h
sessionmanager.o: ../functions/cat.h ../functions/chmod.h
sessionmanager.o: ../functions/privchanger.h ../functions/chown.h
sessionmanager.o: ../functions/cp.h ../functions/createthread.h
sessionmanager.o: ../functions/createticket.h ../functions/default.h
sessionmanager.o: ../functions/download.h ../functions/editticket.h
sessionmanager.o: ../functions/emacs.h ../functions/last.h
sessionmanager.o: ../functions/login.h ../functions/logout.h
sessionmanager.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
sessionmanager.o: ../functions/node.h ../functions/priv.h
sessionmanager.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
sessionmanager.o: ../functions/subject.h ../functions/funthread.h
sessionmanager.o: ../core/thread.h ../functions/funticket.h
sessionmanager.o: ../functions/uname.h ../functions/upload.h
sessionmanager.o: ../functions/who.h ../templates/templates.h
sessionmanager.o: ../templates/patterncacher.h ../core/item.h misc.h
sessionmanager.o: ../functions/functionbase.h ../core/request.h
sessionmanager.o: ../core/system.h ../core/synchro.h
sessionmanager.o: ../functions/functionparser.h ../core/cur.h
sessionmanager.o: ../functions/adduser.h ../functions/cat.h
sessionmanager.o: ../functions/chmod.h ../functions/privchanger.h
sessionmanager.o: ../functions/chown.h ../functions/ckeditor.h
sessionmanager.o: ../functions/cp.h ../functions/default.h
sessionmanager.o: ../functions/download.h ../functions/emacs.h
sessionmanager.o: ../functions/last.h ../functions/login.h
sessionmanager.o: ../functions/logout.h ../functions/ln.h ../functions/ls.h
sessionmanager.o: ../functions/mkdir.h ../functions/mv.h
sessionmanager.o: ../functions/nicedit.h ../functions/node.h
sessionmanager.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
sessionmanager.o: ../functions/specialdefault.h ../functions/stat.h
sessionmanager.o: ../functions/subject.h ../functions/template.h
sessionmanager.o: ../functions/tinymce.h ../functions/uname.h
sessionmanager.o: ../functions/upload.h ../functions/uptime.h
sessionmanager.o: ../functions/who.h ../functions/vim.h ../core/htmlfilter.h
sessionmanager.o: ../templates/templates.h ../templates/patterncacher.h
sessionmanager.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
sessionmanager.o: ../core/log.h ../templates/indexpatterns.h
sessionmanager.o: ../templates/localefilter.h ../core/locale.h
sessionmanager.o: ../core/locale.h ../core/sessionmanager.h
sessionparser.o: sessionparser.h session.h item.h error.h log.h user.h
sessionparser.o: plugindata.h rebus.h sessioncontainer.h lastcontainer.h
sessionparser.o: users.h ugcontainer.h request.h requesttypes.h thread.h
sessionparser.o: compress.h acceptencodingparser.h acceptbaseparser.h
sessionparser.o: htmlfilter.h postmultiparser.h config.h confparser.h
sessionparser.o: ticket.h db.h group.h dircontainer.h
system.o: system.h dirs.h item.h dircontainer.h db.h user.h group.h thread.h
system.o: error.h log.h ugcontainer.h ticket.h request.h requesttypes.h
system.o: session.h plugindata.h rebus.h compress.h acceptencodingparser.h
system.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
system.o: confparser.h mounts.h mount.h users.h lastcontainer.h groups.h
system.o: loadavg.h misc.h notify.h ../templatesnotify/templatesnotify.h
system.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h
system.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
system.o: ../core/locale.h ../functions/functions.h
system.o: ../functions/functionbase.h ../core/item.h ../core/db.h
system.o: ../core/request.h ../core/system.h ../core/notify.h
system.o: ../functions/functionparser.h ../functions/adduser.h
system.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
system.o: ../functions/chown.h ../functions/cp.h ../functions/createthread.h
system.o: ../functions/createticket.h ../functions/default.h
system.o: ../functions/download.h ../functions/editticket.h
system.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
system.o: ../functions/logout.h ../functions/ls.h ../functions/mkdir.h
system.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
system.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
system.o: ../functions/subject.h ../functions/funthread.h ../core/thread.h
system.o: ../functions/funticket.h ../functions/uname.h ../functions/upload.h
system.o: ../functions/who.h ../templates/templates.h
system.o: ../templates/patterncacher.h ../core/item.h
sessionmanager.o: ../core/sessionmanager.h
sessionparser.o: sessionparser.h session.h item.h error.h user.h plugindata.h
sessionparser.o: rebus.h textstream.h sessioncontainer.h cur.h request.h
sessionparser.o: requesttypes.h config.h confparser.h htmlfilter.h
sessionparser.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
sessionparser.o: users.h log.h logmanipulators.h slog.h ../templates/locale.h
sessionparser.o: ../core/confparser.h
slog.o: slog.h cur.h request.h requesttypes.h item.h error.h config.h
slog.o: confparser.h htmlfilter.h textstream.h ../templates/htmltextstream.h
slog.o: ../core/textstream.h misc.h session.h user.h plugindata.h rebus.h
slog.o: logmanipulators.h ../templates/locale.h ../core/confparser.h
synchro.o: synchro.h
system.o: system.h dirs.h item.h dircontainer.h ../db/db.h ../db/dbbase.h
system.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h misc.h
system.o: ../core/error.h ../db/dbitemquery.h ../core/item.h
system.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
system.o: ../core/dircontainer.h ../core/ugcontainer.h log.h textstream.h
system.o: logmanipulators.h slog.h cur.h request.h requesttypes.h error.h
system.o: config.h confparser.h htmlfilter.h ../templates/htmltextstream.h
system.o: session.h user.h plugindata.h rebus.h ../templates/locale.h
system.o: ../core/confparser.h ../notify/notify.h ../notify/notifypool.h
system.o: ../templates/misc.h ../templates/localefilter.h
system.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
system.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
system.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
system.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
system.o: ../notify/notifythread.h ../core/basethread.h synchro.h
system.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
system.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h
system.o: crypt.h run.h users.h groups.h group.h loadavg.h thumb.h
system.o: basethread.h ../templates/templates.h ../templates/patterncacher.h
system.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
system.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
users.o: users.h user.h ugcontainer.h log.h lastcontainer.h request.h
users.o: requesttypes.h session.h item.h error.h plugindata.h rebus.h
users.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
users.o: htmlfilter.h postmultiparser.h config.h confparser.h ticket.h db.h
users.o: group.h dircontainer.h
system.o: ../core/log.h ../templates/indexpatterns.h ../core/cur.h
system.o: ../core/system.h ../core/sessionmanager.h ../core/htmlfilter.h
system.o: ../functions/functionbase.h ../core/request.h ../core/synchro.h
textstream.o: textstream.h misc.h item.h
thumb.o: thumb.h basethread.h textstream.h ../db/db.h ../db/dbbase.h
thumb.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h misc.h
thumb.o: item.h ../core/error.h ../db/dbitemquery.h ../core/item.h
thumb.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
thumb.o: ../core/dircontainer.h ../core/ugcontainer.h log.h logmanipulators.h
thumb.o: slog.h cur.h request.h requesttypes.h error.h config.h confparser.h
thumb.o: htmlfilter.h ../templates/htmltextstream.h session.h user.h
thumb.o: plugindata.h rebus.h ../templates/locale.h ../core/confparser.h
thumb.o: ../core/config.h ../../ezc/src/utf8.h system.h dirs.h dircontainer.h
thumb.o: ../notify/notify.h ../notify/notifypool.h ../templates/misc.h
thumb.o: ../templates/localefilter.h ../templates/locale.h
thumb.o: ../../ezc/src/ezc.h ../../ezc/src/generator.h
thumb.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
thumb.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
thumb.o: ../templates/htmltextstream.h ../notify/notifythread.h
thumb.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
thumb.o: ../core/users.h ugcontainer.h lastcontainer.h mounts.h mount.h
thumb.o: mountparser.h crypt.h run.h users.h groups.h group.h loadavg.h
users.o: users.h

View File

@@ -1 +1 @@
o = Kopia config.o acceptbaseparser.o app.o bbcodeparser.o compress.o config.o confparser.o db.o db_itemcolumns.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o system.o users.o
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o confparser.o crypt.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o item.o lastcontainer.o loadavg.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionmanager.o sessionparser.o slog.o synchro.o system.o textstream.o thumb.o users.o

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/

View File

@@ -2,13 +2,13 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreacceptbaseparser
#define headerfilecmslucoreacceptbaseparser
#ifndef headerfile_winix_core_acceptbaseparser
#define headerfile_winix_core_acceptbaseparser
#include <string>

View File

@@ -2,13 +2,13 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreacceptencodingparser
#define headerfilecmslucoreacceptencodingparser
#ifndef headerfile_winix_core_acceptencodingparser
#define headerfile_winix_core_acceptencodingparser
#include "acceptbaseparser.h"
#include "log.h"
@@ -24,24 +24,60 @@ public:
}
bool AcceptGzip()
{
return accept_gzip;
}
void ParseAndLog(const char * str)
{
Parse(str);
if( accept_deflate || accept_gzip )
{
log << log3 << "AEP: ";
if( accept_deflate )
{
log << "accept deflate";
if( accept_gzip )
log << ", ";
}
if( accept_gzip )
log << "accept gzip";
log << logend;
}
}
private:
void Init()
{
accept_deflate = false;
accept_gzip = false;
}
void Param(const std::string & param, double q)
{
if( param=="deflate" && q!=0 )
if( param=="deflate" && q!=0.0 )
{
accept_deflate = true;
log << log3 << "AEP: accept deflate" << logend;
}
if( param=="gzip" && q!=0.0 )
{
accept_gzip = true;
}
}
bool accept_deflate;
bool accept_gzip;
};

File diff suppressed because it is too large Load Diff

View File

@@ -2,13 +2,13 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* Copyright (c) 2010-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreapp
#define headerfilecmslucoreapp
#ifndef headerfile_winix_core_app
#define headerfile_winix_core_app
#include <iostream>
#include <ctime>
@@ -18,17 +18,23 @@
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <fcgiapp.h>
#include "config.h"
#include "system.h"
#include "mounts.h"
#include "request.h"
#include "synchro.h"
#include "sessionmanager.h"
#include "notify.h"
#include "db.h"
#include "db/db.h"
#include "functions/functions.h"
#include "templates/templates.h"
#include "templatesnotify/templatesnotify.h"
#include "compress.h"
#include "getparser.h"
#include "postparser.h"
#include "cookieparser.h"
#include "postmultiparser.h"
#include "acceptencodingparser.h"
@@ -39,27 +45,36 @@ public:
App();
bool InitFCGI();
bool DropPrivileges();
bool Init();
void Start();
void Close();
void LogUserGroups();
bool Demonize();
void SetStopSignal();
bool WasStopSignal();
bool Lock();
void Unlock();
void StartThreads();
void WaitForThreads();
// configuration read from a config file
Config config;
// pointers to the current request and a session
Cur cur;
// temporary one request object
// current request
Request request;
Request req;
// users sessions
SessionManager session_manager;
// notifications (by emails)
Notify notify;
// database
Db db;
DbConn db_conn;
@@ -71,13 +86,15 @@ public:
System system;
// false at the beginning
// !! moze to do loggera dac?
bool stdout_is_closed;
/*
controller
controllers
(note that the whole app object is actually a controller too)
*/
// functions (ls, cat, emacs, ...)
@@ -89,18 +106,73 @@ public:
*/
Templates templates;
TemplatesNotify templates_notify;
private:
bool CreateFCGISocket();
enum Header
{
h_200,
h_404,
h_403
};
GetParser get_parser;
PostParser post_parser;
PostMultiParser post_multi_parser;
CookieParser cookie_parser;
AcceptEncodingParser accept_encoding_parser;
Compress compress;
std::wstring clean_html, html_with_debug;
FCGX_Request fcgi_request;
int fcgi_socket;
Synchro synchro;
pthread_t signal_thread;
std::string url_to_fetch_on_exit;
std::string source_a;
std::string sendheadersstatic_t, sendheadersstatic_t2;
void ProcessRequestThrow();
void ProcessRequest();
bool BaseUrlRedirect();
void DeleteAllPluginsData();
void MakePage();
void Make();
void ReadAdditionalInfo();
void SaveSessionsIfNeeded(); // !! wywalic do managara sesji??
void SaveSessionsIfNeeded(); // !! wywalic do menagera sesji??
void LogAccess();
void ReadRequest();
void SendAnswer();
void SetEnv(const char * & env, const char * name);
void ReadEnvVariables();
void ReadGetPostVars();
void CheckIE();
void CheckKonqueror();
void CheckRequestMethod();
void CheckFCGIRole();
void PrepareSessionCookie();
void AddDebugInfo(std::wstring & out);
void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref);
void SendHeadersStatic();
void SendHeadersForbidden();
void SendHeaders(bool compressing, int compress_encoding, Header header);
int SelectDeflateVersion();
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
bool CanSendContent(Header header);
void LogUser(const char * msg, uid_t id);
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
void LogUsers();
void LogEffectiveGroups(std::vector<gid_t> & tab);
void LogGroups();
bool DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool additional_groups);
static void * SpecialThreadForSignals(void*);
void FetchPageOnExit();
void CreateStaticTree();
// !! dodac do session managera?
time_t last_sessions_save;

232
core/basethread.cpp Executable file
View File

@@ -0,0 +1,232 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <errno.h>
#include "basethread.h"
#include "log.h"
BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
{
synchro = 0;
thread_id = 0;
work_mode = 0;
wake_up_was_called = false;
}
void BaseThread::SetSynchro(Synchro * psynchro)
{
synchro = psynchro;
}
void BaseThread::Mode(int mode)
{
work_mode = mode;
}
bool BaseThread::Lock()
{
return synchro->Lock();
}
void BaseThread::Unlock()
{
synchro->Unlock();
}
bool BaseThread::IsExitSignal()
{
bool res = true;
if( Lock() )
{
res = synchro->was_stop_signal;
Unlock();
}
return res;
}
bool BaseThread::BaseInit()
{
bool init_status = false;
if( Lock() )
{
init_status = Init(); // your virtual method
Unlock();
}
return init_status;
}
void BaseThread::BaseUninit()
{
if( Lock() )
{
Uninit(); // your virtual method
Unlock();
}
}
bool BaseThread::BaseSignalReceived()
{
bool make_do = false;
wake_up_was_called = false;
try
{
make_do = SignalReceived(); // your short-time virtual method (objects are locked)
}
catch(...)
{
}
return make_do;
}
// this is called only if your SignalReceived() returned true
void BaseThread::BaseDo()
{
try
{
Do(); // your long-time virtual method (objects are *not* locked)
}
catch(...)
{
}
}
// use it with Lock and Unlock
bool BaseThread::WaitForSignal()
{
if( synchro->was_stop_signal || wake_up_was_called )
return true;
return pthread_cond_wait(&thread_signal, &synchro->mutex) == 0;
}
// you should use this method with: synchro->Lock() and Unlock()
void BaseThread::WakeUpThread()
{
wake_up_was_called = true;
pthread_cond_signal(&thread_signal);
}
// use it with Lock and Unlock
// it breaks only if there was a stop signal or the time has expired
bool BaseThread::WaitForSignalSleep(time_t second)
{
timespec t;
int res;
if( synchro->was_stop_signal )
return true;
t.tv_sec = time(0) + second;
t.tv_nsec = 0;
do
{
res = pthread_cond_timedwait(&thread_signal, &synchro->mutex, &t);
}
while( res == 0 && !synchro->was_stop_signal );
// above condition means there was a signal
// but it was not a stop signal so we should still wait
return res == 0 || res == ETIMEDOUT;
}
void BaseThread::WaitForThread()
{
pthread_join(thread_id, 0);
}
void BaseThread::SignalLoop()
{
bool make_do;
do
{
if( Lock() )
{
make_do = false;
if( WaitForSignal() ) // automatically unlock, wait and lock again when signal comes
if( !synchro->was_stop_signal )
make_do = BaseSignalReceived(); // your short-time virtual method will be called (objects locked)
Unlock(); // unlocking from WaitForSignal()
if( make_do )
BaseDo(); // your long-time virtual method will be called (objects *not* locked)
}
}
while( !IsExitSignal() );
}
void * BaseThread::StartRoutine(void * this_object)
{
BaseThread * base = reinterpret_cast<BaseThread*>(this_object);
if( base->synchro )
{
if( base->BaseInit() )
{
if( base->work_mode == 0 )
base->SignalLoop();
else
base->Work();
base->BaseUninit();
}
}
pthread_exit(0);
return 0;
}
bool BaseThread::StartThread()
{
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
int res = pthread_create(&thread_id, &attr, StartRoutine, this);
pthread_attr_destroy(&attr);
return res == 0;
}

121
core/basethread.h Executable file
View File

@@ -0,0 +1,121 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_basethread
#define headerfile_winix_core_basethread
#include <pthread.h>
#include "synchro.h"
class BaseThread
{
public:
BaseThread();
// synchro object (must be set)
void SetSynchro(Synchro * psynchro);
// work mode
// we have two modes:
// 0 - there is a loop with SignalReceived() and Do()
// if SignalReceived() returns true then Do() is called
// 1 - only Work() method is called
// the thread exits after Work() has finished
// default: 0
void Mode(int mode);
// starting the second thread
bool StartThread();
// wake up the second thread
// (if it waits for the signal)
// you should use it with: synchro->Lock() and Unlock()
// if the thread doesn't wait on a signal then nothing is done
void WakeUpThread();
// waiting until the thread exits
// you should call WakeUpThread() before
void WaitForThread();
// virtual methods which should/can be inherited by your class
// the methods will be called from the other thread
// initialize the thread
// (global objects are locked)
// if it returns false then the thread immediately exits
// default: true
virtual bool Init() { return true; }
// uninitialize the thread
// this is called before the thread is prepare to detach
// (global objects are locked)
// it's called only if Init() returned true
virtual void Uninit() {}
protected:
// signal came (work mode = 0 - default)
// signal comes when an other thread calls WakeUpThread() method
// check specific job and return true to call Do() next
// (global objects are locked -- copy some global objects to local variables)
virtual bool SignalReceived() { return false; };
// if SignalReceived() returned true then this method is called
// global objects are *not* locked -- use only your local variables
// if you have to do something on global objects use synchro->Lock() and synchro->Unlock()
virtual void Do() {}
// this method is called after Init() when Mode(1) is used
// this is for long-time job
// this method is called only once
// global objects are *not* locked
virtual void Work() {}
protected:
Synchro * synchro;
pthread_t thread_id; // thread id - set by StartThread()
pthread_cond_t thread_signal;
int work_mode;
bool wake_up_was_called;
void SignalLoop();
static void * StartRoutine(void *);
bool BaseInit();
void BaseUninit();
bool BaseSignalReceived();
void BaseDo();
bool WaitForSignal();
bool WaitForSignalSleep(time_t second);
bool Lock();
void Unlock();
// if the work done by Do() is long time consuming you should periodically check
// wheter there was a signal for exiting, and if it was just simply return from Do()
// (it's checking with locking and unlocking)
bool IsExitSignal();
};
#endif

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -12,6 +12,19 @@
bool BBCODEParser::Equal(const wchar_t * str1, const wchar_t * str2)
{
while( *str1 == *str2 && *str1 != 0 )
{
str1 += 1;
str2 += 1;
}
return *str1 == *str2;
}
bool BBCODEParser::IsValidCharForName(int c)
{
@@ -56,9 +69,13 @@ bool BBCODEParser::IsClosingXmlSimpleTagMark()
// one enter will generate one <br>
// two enters or more will generate only two br (<br><br>)
void BBCODEParser::PutNormalText(const char * str, const char * end)
void BBCODEParser::PutNormalText(const wchar_t * str, const wchar_t * end)
{
int br_len;
@@ -93,7 +110,7 @@ int br_len;
if( !has_open_ol_tag && !has_open_ul_tag && !has_open_li_tag )
{
for(int i=0 ; i < br_len ; ++i)
(*out_string) += "<br>\n";
(*out_string) += L"<br>\n";
}
}
else
@@ -105,14 +122,8 @@ int br_len;
}
void BBCODEParser::PutNormalTextTrim(const char * str, const char * end)
{
// we don't use trimming in bbcode parser
PutNormalText(str, end);
}
void BBCODEParser::ReadNormalTextSkipWhite(const char * & start, const char * & last_non_white)
void BBCODEParser::ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white)
{
}
@@ -123,8 +134,8 @@ void BBCODEParser::CheckExceptions()
{
if( pstack[stack_len-1].type == Item::opening &&
pstack[stack_len-2].type == Item::opening &&
IsNameEqual("*", pstack[stack_len-1].name) &&
IsNameEqual("*", pstack[stack_len-2].name) )
IsNameEqual(L"*", pstack[stack_len-1].name) &&
IsNameEqual(L"*", pstack[stack_len-2].name) )
{
// removing the last [*] from the stack
// </li> was put automatically
@@ -162,20 +173,20 @@ void BBCODEParser::CheckExceptions()
at the beginning and at the end
(because otherwise a space would be changed to %20 and this were probably not what you really wanted)
*/
const BBCODEParser::Tags * BBCODEParser::FindTag(const char * tag)
const BBCODEParser::Tags * BBCODEParser::FindTag(const wchar_t * tag)
{
static Tags tags[] = {
{"*", "li", ">", false},
{"b", "em", ">", true},
{"i", "span", " class=\"bbitalic\">", true},
{"u", "span", " class=\"bbunderline\">", true},
{"s", "span", " class=\"bbstrike\">", true},
{"code", "code", " class=\"bbcode\">", false},
{"list", "ul", " class=\"bblist\">", false},
{"color", "span", " class=\"bbcol%1\">", true},
{"url", "a", " href=\"%u1\">", true},
{"img", "img", " alt=\"%1\" src=\"%u2\">", true},
{"quote", "div", " class=\"bbquote\">\n<span class=\"bbquotewho\">%1</span><br>\n", false},
{L"*", L"li", L">", false},
{L"b", L"em", L">", true},
{L"i", L"span", L" class=\"bbitalic\">", true},
{L"u", L"span", L" class=\"bbunderline\">", true},
{L"s", L"span", L" class=\"bbstrike\">", true},
{L"code", L"code", L" class=\"bbcode\">", false},
{L"list", L"ul", L" class=\"bblist\">", false},
{L"color", L"span", L" class=\"bbcol%1\">", true},
{L"url", L"a", L" href=\"%u1\">", true},
{L"img", L"img", L" alt=\"%1\" src=\"%u2\">", true},
{L"quote", L"div", L" class=\"bbquote\">\n<span class=\"bbquotewho\">%1</span><br>\n", false},
};
size_t i;
@@ -183,15 +194,21 @@ const BBCODEParser::Tags * BBCODEParser::FindTag(const char * tag)
for(i=0 ; i<len ; ++i)
{
if( strcmp(tag, tags[i].bbcode) == 0 )
if( Equal(tag, tags[i].bbcode) )
return &tags[i];
}
return 0;
}
const BBCODEParser::Tags * BBCODEParser::FindTag(const std::wstring & tag)
{
return FindTag(tag.c_str());
}
void BBCODEParser::PrintArgumentCheckQuotes(const char * & start, const char * & end)
void BBCODEParser::PrintArgumentCheckQuotes(const wchar_t * & start, const wchar_t * & end)
{
// skipping white characters from the argument
while( start<end && IsWhite(*start) )
@@ -230,7 +247,7 @@ void BBCODEParser::PrintEncode(int c)
{
if( c == '&' )
{
(*out_string) += "&amp;";
(*out_string) += L"&amp;";
}
else
if( (c>='a' && c<='z') ||
@@ -244,8 +261,8 @@ void BBCODEParser::PrintEncode(int c)
}
else
{
char buffer[20];
sprintf(buffer, "%02X", c);
wchar_t buffer[20];
swprintf(buffer, 20, L"%02X", c);
(*out_string) += '%';
(*out_string) += buffer;
@@ -257,22 +274,22 @@ void BBCODEParser::PrintEscape(int c, bool change_quote)
{
if( c == '<' )
{
(*out_string) += "&lt;";
(*out_string) += L"&lt;";
}
else
if( c == '>' )
{
(*out_string) += "&gt;";
(*out_string) += L"&gt;";
}
else
if( c == '&' )
{
(*out_string) += "&amp;";
(*out_string) += L"&amp;";
}
else
if( c == '\"' && change_quote )
{
(*out_string) += "&quot;";
(*out_string) += L"&quot;";
}
else
{
@@ -281,7 +298,7 @@ void BBCODEParser::PrintEscape(int c, bool change_quote)
}
void BBCODEParser::PrintArgumentEncode(const char * start, const char * end)
void BBCODEParser::PrintArgumentEncode(const wchar_t * start, const wchar_t * end)
{
PrintArgumentCheckQuotes(start, end);
TrimWhiteWithNewLines(start, end);
@@ -291,7 +308,7 @@ void BBCODEParser::PrintArgumentEncode(const char * start, const char * end)
}
void BBCODEParser::PrintArgumentEscape(const char * start, const char * end)
void BBCODEParser::PrintArgumentEscape(const wchar_t * start, const wchar_t * end)
{
PrintArgumentCheckQuotes(start, end);
@@ -300,9 +317,9 @@ void BBCODEParser::PrintArgumentEscape(const char * start, const char * end)
}
void BBCODEParser::CheckOpeningTag(const Tags * tag, const char * tag_name, bool & condition)
void BBCODEParser::CheckOpeningTag(const Tags * tag, const wchar_t * tag_name, bool & condition)
{
if( strcmp(tag->html_tag, tag_name) == 0 )
if( Equal(tag->html_tag, tag_name) )
{
if( condition )
{
@@ -319,13 +336,13 @@ void BBCODEParser::CheckOpeningTag(const Tags * tag)
{
bool has_list_tag = has_open_ul_tag || has_open_ol_tag;
CheckOpeningTag(tag, "li", has_open_li_tag);
CheckOpeningTag(tag, "ul", has_open_ul_tag);
CheckOpeningTag(tag, "ol", has_open_ol_tag);
CheckOpeningTag(tag, L"li", has_open_li_tag);
CheckOpeningTag(tag, L"ul", has_open_ul_tag);
CheckOpeningTag(tag, L"ol", has_open_ol_tag);
if( has_open_li_tag && !has_list_tag )
{
(*out_string) += "<ul>\n";
(*out_string) += L"<ul>\n";
has_open_ul_tag = true;
}
}
@@ -334,7 +351,7 @@ void BBCODEParser::CheckOpeningTag(const Tags * tag)
void BBCODEParser::PrintEscape(const char * start, const char * end, bool change_quote)
void BBCODEParser::PrintEscape(const wchar_t * start, const wchar_t * end, bool change_quote)
{
for( ; start < end ; ++start)
PrintEscape(*start, change_quote);
@@ -342,7 +359,7 @@ void BBCODEParser::PrintEscape(const char * start, const char * end, bool change
void BBCODEParser::PrintEncode(const char * start, const char * end)
void BBCODEParser::PrintEncode(const wchar_t * start, const wchar_t * end)
{
for( ; start < end ; ++start)
PrintEncode(*start);
@@ -350,26 +367,28 @@ void BBCODEParser::PrintEncode(const char * start, const char * end)
void BBCODEParser::PutOpeningTagFromEzc(const char * start, const char * end)
void BBCODEParser::PutOpeningTagFromEzc()
{
// this can be a tag from Ezc templates system
(*out_string) += '[';
(*out_string) += LastItem().name;
if( start != end )
{
(*out_string) += ' ';
PrintEscape(start, end);
}
const wchar_t * start = pchar;
(*out_string) += ']';
while( *pchar && *pchar!=']' )
++pchar;
if( *pchar == ']' )
++pchar;
Put(start, pchar);
}
void BBCODEParser::PutHtmlArgument1(const char * arg_start, const char * arg_end, bool has_u)
void BBCODEParser::PutHtmlArgument1(const wchar_t * arg_start, const wchar_t * arg_end, bool has_u)
{
if( has_u )
PrintArgumentEncode(arg_start, arg_end);
@@ -379,7 +398,7 @@ void BBCODEParser::PutHtmlArgument1(const char * arg_start, const char * arg_end
void BBCODEParser::TrimWhiteWithNewLines(const char * & start, const char * & end)
void BBCODEParser::TrimWhiteWithNewLines(const wchar_t * & start, const wchar_t * & end)
{
while( start < end && (IsWhite(*start) || *start==10) )
++start;
@@ -392,8 +411,8 @@ void BBCODEParser::TrimWhiteWithNewLines(const char * & start, const char * & en
void BBCODEParser::PutHtmlArgument2(const Tags * tag, bool has_u)
{
const char * start = pchar;
const char * end = pchar;
const wchar_t * start = pchar;
const wchar_t * end = pchar;
bool first_tag_removed = false;
while( *pchar != 0 )
@@ -432,9 +451,9 @@ bool first_tag_removed = false;
void BBCODEParser::PutHtmlArgument(const Tags * tag, const char * arg_start, const char * arg_end)
void BBCODEParser::PutHtmlArgument(const Tags * tag, const wchar_t * arg_start, const wchar_t * arg_end)
{
const char * pattern = tag->html_argument;
const wchar_t * pattern = tag->html_argument;
bool has_u;
while( *pattern )
@@ -478,33 +497,40 @@ bool has_u;
}
void BBCODEParser::PutOpeningTagFromBBCode(const Tags * tag, const char * start, const char * end)
void BBCODEParser::PutOpeningTagFromBBCode(const Tags * tag)
{
CheckOpeningTag(tag);
PutOpeningTagMark();
(*out_string) += tag->html_tag;
PutHtmlArgument(tag, start, end);
Put(tag->html_tag);
const wchar_t * start = pchar;
while( *pchar && *pchar != ']' )
++pchar;
PutHtmlArgument(tag, start, pchar);
if( *pchar == ']' )
++pchar;
if( !tag->inline_tag )
{
(*out_string) += "\n";
Put(10);
SkipWhiteLines();
}
}
void BBCODEParser::PutOpeningTag(const char * start, const char * end)
bool BBCODEParser::PutOpeningTag()
{
const Tags * tag = FindTag(LastItem().name);
if( !tag )
{
PutOpeningTagFromEzc(start, end);
}
PutOpeningTagFromEzc();
else
{
PutOpeningTagFromBBCode(tag, start, end);
}
PutOpeningTagFromBBCode(tag);
return false;
}
@@ -520,22 +546,22 @@ void BBCODEParser::PutClosingTag(const Tags * tag)
if( !tag->inline_tag )
{
(*out_string) += "\n";
(*out_string) += L"\n";
SkipWhiteLines();
}
if( strcmp(tag->html_tag, "li") == 0 )
if( Equal(tag->html_tag, L"li") )
has_open_li_tag = false;
if( strcmp(tag->html_tag, "ol") == 0 )
if( Equal(tag->html_tag, L"ol") )
has_open_ol_tag = false;
if( strcmp(tag->html_tag, "ul") == 0 )
if( Equal(tag->html_tag, L"ul") )
has_open_ul_tag = false;
}
void BBCODEParser::PutClosingTag(const char * tag_name)
void BBCODEParser::PutClosingTag(const wchar_t * tag_name)
{
const Tags * tag = FindTag(tag_name);
PutClosingTag(tag);
@@ -553,14 +579,14 @@ void BBCODEParser::Init()
}
void BBCODEParser::Deinit()
void BBCODEParser::Uninit()
{
if( has_open_li_tag )
(*out_string) += "</li>\n";
(*out_string) += L"</li>\n";
if( has_open_ol_tag )
(*out_string) += "</ol>\n";
(*out_string) += L"</ol>\n";
if( has_open_ul_tag )
(*out_string) += "</ul>\n";
(*out_string) += L"</ul>\n";
}

View File

@@ -2,94 +2,92 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorebbcodeparser
#define headerfilecmslucorebbcodeparser
#ifndef headerfile_winix_core_bbcodeparser
#define headerfile_winix_core_bbcodeparser
#include "htmlfilter.h"
class BBCODEParser : public HTMLFilter
{
//using HTMLFilter::pchar;
struct Tags
{
/*
const char * bbcode;
const char * html_tag;
const char * html_arg_prefix;
const char * html_arg_postfix;
const char * additional_html_tag_prefix;
const char * additional_html_tag_postfix;
bool inline_tag;
*/
const char * bbcode;
const char * html_tag;
const char * html_argument; // with closing '>'
const wchar_t * bbcode;
const wchar_t * html_tag;
const wchar_t * html_argument; // with closing '>'
bool inline_tag;
};
virtual bool IsValidCharForName(int c);
/*
virtual methods
(from HTMLFilter class)
*/
virtual void Init();
virtual void Uninit();
virtual bool IsOpeningTagMark();
virtual bool IsOpeningCommentaryTagMark();
virtual bool SkipCommentaryTagIfExists();
virtual bool IsClosingTagMark();
virtual bool IsClosingXmlSimpleTagMark();
virtual bool IsValidCharForName(int c);
virtual void CheckExceptions();
virtual bool SkipCommentaryTagIfExists();
void PutHtmlArgument1(const char * arg_start, const char * arg_end, bool has_u);
virtual bool PutOpeningTag();
virtual void PutClosingTag(const wchar_t * tag);
virtual void PutNormalText(const wchar_t * str, const wchar_t * end);
virtual void ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white);
/*
others
*/
bool Equal(const wchar_t * str1, const wchar_t * str2);
void PutHtmlArgument1(const wchar_t * arg_start, const wchar_t * arg_end, bool has_u);
void PutHtmlArgument2(const Tags * tag, bool has_u);
void PutHtmlArgument(const Tags * tag, const char * arg_start, const char * arg_end);
void PutHtmlArgument(const Tags * tag, const wchar_t * arg_start, const wchar_t * arg_end);
void PutOpeningTagFromEzc(const char * start, const char * end);
void PutOpeningTagFromBBCode(const Tags * tag, const char * start, const char * end);
virtual void PutOpeningTag(const char * start, const char * end);
virtual void PutClosingTag(const char * tag);
const Tags * FindTag(const char * tag);
void PrintArgumentCheckQuotes(const char * & start, const char * & end);
void PutOpeningTagFromEzc();
void PutOpeningTagFromBBCode(const Tags * tag);
const Tags * FindTag(const wchar_t * tag);
const Tags * FindTag(const std::wstring & tag);
void PrintArgumentCheckQuotes(const wchar_t * & start, const wchar_t * & end);
void PrintEscape(int c, bool change_quote = false);
void PrintEncode(int c);
void PrintEscape(const char * start, const char * end, bool change_quote = false);
void PrintEncode(const char * start, const char * end);
void PrintEscape(const wchar_t * start, const wchar_t * end, bool change_quote = false);
void PrintEncode(const wchar_t * start, const wchar_t * end);
void PrintArgumentEncode(const char * start, const char * end);
void PrintArgumentEscape(const char * start, const char * end);
virtual void ReadNormalTextSkipWhite(const char * & start, const char * & last_non_white);
virtual void PutNormalText(const char * str, const char * end);
virtual void PutNormalTextTrim(const char * str, const char * end);
virtual void CheckExceptions();
virtual void Init();
virtual void Deinit();
void PrintArgumentEncode(const wchar_t * start, const wchar_t * end);
void PrintArgumentEscape(const wchar_t * start, const wchar_t * end);
void PutClosingTag(const Tags * tag);
void CheckOpeningTag(const Tags * tag, const char * tag_name, bool & condition);
void CheckOpeningTag(const Tags * tag, const wchar_t * tag_name, bool & condition);
void CheckOpeningTag(const Tags * tag);
void TrimWhiteWithNewLines(const char * & start, const char * & end);
void TrimWhiteWithNewLines(const wchar_t * & start, const wchar_t * & end);
bool has_open_ol_tag; // has open html <ol> tag
bool has_open_ul_tag; // has open html <ul> tag
bool has_open_li_tag; // has open html <li> tag
};
#endif

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -15,9 +15,13 @@
Compress::Compress()
{
buffer = 0;
buffer_max_len = 65536; // 64KB
buffer = 0;
buffer_max_len = 65536; // 64KB
ready_for_compress = false;
compress_level = 6;
raw_deflate_inited = false;
deflate_inited = false;
gzip_inited = false;
}
@@ -25,6 +29,15 @@ Compress::~Compress()
{
if( buffer )
delete [] buffer;
if( raw_deflate_inited )
deflateEnd(&strm_raw_deflate);
if( deflate_inited )
deflateEnd(&strm_deflate);
if( gzip_inited )
deflateEnd(&strm_gzip);
}
@@ -33,7 +46,6 @@ bool Compress::AllocateMemory()
if( buffer )
delete [] buffer;
try
{
buffer = new char[buffer_max_len];
@@ -41,7 +53,6 @@ bool Compress::AllocateMemory()
catch(const std::bad_alloc &)
{
log << log1 << "Compress: can't allocate memory" << logend;
buffer = 0;
return false;
}
@@ -50,39 +61,93 @@ return true;
}
bool Compress::InitRawDeflate()
{
raw_deflate_inited = false;
strm_raw_deflate.next_in = 0;
strm_raw_deflate.zalloc = Z_NULL;
strm_raw_deflate.zfree = Z_NULL;
strm_raw_deflate.opaque = Z_NULL;
int ret = deflateInit2(&strm_raw_deflate, compress_level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
if( ret != Z_OK )
log << log1 << "Compress: problem with deflateInit2() for raw deflate" << logend;
else
raw_deflate_inited = true;
return ret == Z_OK;
}
bool Compress::InitDeflate()
{
deflate_inited = false;
strm_deflate.next_in = 0;
strm_deflate.zalloc = Z_NULL;
strm_deflate.zfree = Z_NULL;
strm_deflate.opaque = Z_NULL;
int ret = deflateInit2(&strm_deflate, compress_level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
if( ret != Z_OK )
log << log1 << "Compress: problem with deflateInit2() for deflate" << logend;
else
deflate_inited = true;
return ret == Z_OK;
}
bool Compress::InitGzip()
{
gzip_inited = false;
strm_gzip.next_in = 0;
strm_gzip.zalloc = Z_NULL;
strm_gzip.zfree = Z_NULL;
strm_gzip.opaque = Z_NULL;
int ret = deflateInit2(&strm_gzip, compress_level, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY);
if( ret != Z_OK )
log << log1 << "Compress: problem with deflateInit2() for gzip" << logend;
else
gzip_inited = true;
return ret == Z_OK;
}
/*
return:
0 - ok;
1 - can't allocate memory
100 - unknown
0 - ok
1 - can't allocate memory
100 - unknown error
*/
int Compress::Init(int compress_level)
int Compress::Init(int compress_level_)
{
compress_level = compress_level_;
if( buffer == 0 )
if( !AllocateMemory() )
return 1;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
int ret = deflateInit(&strm, compress_level);
if( ret != Z_OK )
log << log1 << "Compress: problem with deflateInit()" << logend;
if( ret == Z_MEM_ERROR )
return 1;
if( ret != Z_OK )
return 100;
ready_for_compress = true;
if( InitRawDeflate() && InitDeflate() && InitGzip() )
ready_for_compress = true;
else
return 100;
return 0;
}
int Compress::MakeCompress(const char * source, size_t source_len, FCGX_Stream * out_stream)
int Compress::MakeCompress(z_stream & strm, const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding)
{
int ret, flush;
size_t have;
@@ -133,6 +198,62 @@ return 0;
z_stream * Compress::SelectStream(int encoding)
{
z_stream * pstrm;
if( encoding == 0 )
pstrm = &strm_raw_deflate;
else
if( encoding == 1 )
pstrm = &strm_deflate;
else
pstrm = &strm_gzip;
return pstrm;
}
void Compress::ResetStream(z_stream * pstrm, int encoding)
{
if( deflateReset(pstrm) != Z_OK )
{
log << log1 << "Compress: problem with deflateReset()" << logend;
deflateEnd(pstrm);
if( encoding == 0 )
InitRawDeflate();
else
if( encoding == 1 )
InitDeflate();
else
InitGzip();
}
}
void Compress::PutLog(size_t source_len, int encoding)
{
double ratio = 100.0 - (double(last_out_size) / double(source_len) * 100.0);
char buffer[30];
sprintf(buffer, "%.1f", ratio);
log << log2 << "Compress: ";
if( encoding == 0 )
log << "raw deflate";
else
if( encoding == 1 )
log << "deflate";
else
log << "gzip";
log << ", original size: " << source_len << ", size after compressing: "
<< (int)last_out_size << ", ratio: " << buffer << "%" << logend;
}
/*
return:
@@ -142,10 +263,11 @@ return 0;
3 - not inited (use Init() first)
100 - unknown
*/
int Compress::CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int level)
int Compress::CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding)
{
int ret;
z_stream * pstrm;
last_out_size = 0;
if( !ready_for_compress )
@@ -156,17 +278,11 @@ int ret;
if( source_len == 0 )
return 0;
ret = MakeCompress(source, source_len, out_stream);
if( deflateReset(&strm) != Z_OK )
log << log1 << "Compress: problem with deflateReset()" << logend;
double ratio = 100.0 - (double(last_out_size) / double(source_len) * 100.0);
char buffer[30];
sprintf(buffer, "%.1f", ratio);
log << log2 << "Compress: original size: " << source_len << ", compress size: " << (int)last_out_size << ", ratio: " << buffer << "%" << logend;
pstrm = SelectStream(encoding);
ret = MakeCompress(*pstrm, source, source_len, out_stream, encoding);
ResetStream(pstrm, encoding);
PutLog(source_len, encoding);
return ret;
}

View File

@@ -2,13 +2,13 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorecompress
#define headerfilecmslucorecompress
#ifndef headerfile_winix_core_compress
#define headerfile_winix_core_compress
#include <cstring>
#include <fcgiapp.h>
@@ -23,18 +23,35 @@ public:
Compress();
~Compress();
int Init(int compress_level = 6);
int CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int level = 6);
int Init(int compress_level_ = 6);
/*
encoding:
0 - raw deflate data with no zlib header or trailer, and will not compute an adler32 check value
(for Internet Explorer)
1 - deflate
2 - gzip
*/
int CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding = 2);
size_t last_out_size;
private:
bool AllocateMemory();
int MakeCompress(const char * source, size_t source_len, FCGX_Stream * out_stream);
bool InitRawDeflate();
bool InitDeflate();
bool InitGzip();
int MakeCompress(z_stream & strm, const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding);
z_stream * SelectStream(int encoding);
void ResetStream(z_stream * pstrm, int encoding);
void PutLog(size_t source_len, int encoding);
int compress_level;
size_t buffer_max_len;
char * buffer;
z_stream strm;
z_stream strm_raw_deflate, strm_deflate, strm_gzip;
bool raw_deflate_inited, deflate_inited, gzip_inited;
bool ready_for_compress;
};

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -11,6 +11,7 @@
#include "log.h"
#include "plugin.h"
#include "misc.h"
#include "crypt.h"
@@ -68,6 +69,7 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
log << log2 << "Config: reading a config file" << logend;
parser.SplitSingle(true);
parser.UTF8(true); // config is always read in UTF-8
ConfParser::Status status = parser.Parse( config_file );
@@ -89,183 +91,314 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
void Config::AssignValues(bool stdout_is_closed)
{
log_file = Text("log_file");
log_notify_file = Text("log_notify_file");
fcgi_socket = Text("fcgi_socket");
fcgi_socket_chmod = Int("fcgi_socket_chmod", 0770);
fcgi_socket_user = Text("fcgi_socket_user");
fcgi_socket_group = Text("fcgi_socket_group");
log_level = Int("log_level", 1);
log_request = Int("log_request", 1);
log_stdout = Bool("log_stdout", false);
post_file_max = Int("post_file_max", 8388608); // 8 MB
auth_simplefs_dir = Text("auth_simplefs_dir");
auth_hashfs_dir = Text("auth_hashfs_dir");
auth_tmp_dir = Text("auth_tmp_dir");
demonize = Bool(L"demonize", true);
templates_dir = Text("templates_dir");
templates_dir_default = Text("templates_dir_default");
http_session_id_name = Text("http_session_id_name");
db_database = Text("db_database");
db_user = Text("db_user");
db_pass = Text("db_pass");
item_url_empty = Text("item_url_empty");
user = AText(L"user");
group = AText(L"group");
additional_groups = Bool(L"additional_groups", true);
base_server = Text("base_server");
base_url = Text("base_url");
base_url_auth = Text("base_url_auth");
base_url_static = Text("base_url_static");
base_url_common = Text("base_url_common");
log_file = AText(L"log_file");
log_notify_file = AText(L"log_notify_file");
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
fcgi_socket = AText(L"fcgi_socket");
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);
fcgi_socket_user = AText(L"fcgi_socket_user");
fcgi_socket_group = AText(L"fcgi_socket_group");
log_level = Int(L"log_level", 1);
log_request = Int(L"log_request", 1);
log_save_each_line = Bool(L"log_save_each_line", false);
log_stdout = Bool(L"log_stdout", false);
log_db_query = Bool(L"log_db_query", false);
log_plugin_call = Bool(L"log_plugin_call", false);
log_post_value_size = Size(L"log_post_value_size", 80);
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
upload_dir = Text(L"upload_dir");
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
upload_files_chmod = Int(L"upload_files_chmod", 0640);
ListText(L"static_dirs", static_dirs);
dont_use_static_dirs = Bool(L"dont_use_static_dirs", false);
create_thumb = Bool(L"create_thumb", true);
thumb_mode = Int(L"thumb_mode", 2);
thumb_cx = Size(L"thumb_cx", 150);
thumb_cy = Size(L"thumb_cy", 150);
convert_cmd = Text(L"convert_cmd", L"/usr/local/bin/convert");
templates_dir = Text(L"templates_dir");
templates_dir_default = Text(L"templates_dir_default");
txt_templates_dir = Text(L"txt_templates_dir");
txt_templates_dir_default = Text(L"txt_templates_dir_default");
templates_fun_prefix = Text(L"templates_fun_prefix", L"fun_");
templates_fun_postfix = Text(L"templates_fun_postfix", L".html");
templates_index = Text(L"templates_index", L"index.html");
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
http_session_id_name = AText(L"http_session_id_name");
db_database = AText(L"db_database");
db_user = AText(L"db_user");
db_pass = AText(L"db_pass");
item_url_empty = Text(L"item_url_empty");
base_server = Text(L"base_server");
base_url = Text(L"base_url");
base_url_static = Text(L"base_url_static");
base_url_common = Text(L"base_url_common");
NoLastSlash(base_server);
NoLastSlash(base_url);
NoLastSlash(base_url_auth);
NoLastSlash(base_url_static);
NoLastSlash(base_url_common);
priv_no_user = Text("priv_no_user", "-- no user --");
priv_no_group = Text("priv_no_group", "-- no group --");
priv_no_user = Text(L"priv_no_user", L"-- no user --");
priv_no_group = Text(L"priv_no_group", L"-- no group --");
session_max_idle = Int("session_max_idle", 10800); // 3h
session_remember_max_idle = Int("session_remember_max_idle", 16070400); // 3 months
session_file = Text("session_file");
session_max_idle = Int(L"session_max_idle", 10800); // 3h
session_remember_max_idle = Int(L"session_remember_max_idle", 16070400); // 3 months
session_file = AText(L"session_file");
session_max = Size(L"session_max", 1000000);
compression = Bool("compression", true);
html_filter = Bool("html_filter", true);
compression = Bool(L"compression", true);
compression_page_min_size = Size(L"compression_page_min_size", 512);
compression_encoding = Int(L"compression_encoding", 20);
locale_str = Text("locale", "en");
locale_dir = Text("locale_dir");
locale_dir_default = Text("locale_dir_default");
html_filter = Bool(L"html_filter", true);
html_filter_trim_white = Bool(L"html_filter_trim_white", true);
html_filter_break_word = Int(L"html_filter_break_word", 60);
html_filter_wrap_line = Int(L"html_filter_wrap_line", 110);
html_filter_tabs = Size(L"html_filter_tabs", 2);
html_filter_orphans = Bool(L"html_filter_orphans", true);
html_filter_orphans_mode_str = AText(L"html_filter_orphans_mode_str", L"nbsp");
title_separator = Text("title_separator", " / ");
locale_dir = Text(L"locale_dir");
locale_dir_default = Text(L"locale_dir_default");
locale_default = Text(L"locale_default");
ListText(L"locale_files", locale_files);
parser.ListText("plugins", plugin_file);
title_separator = Text(L"title_separator", L" / ");
http_header_send_file = Text(L"http_header_send_file", L"X-LIGHTTPD-send-file");
debug_info = Bool(L"debug_info", false);
editors_html_safe_mode = Bool(L"editors_html_safe_mode", true);
editors_html_safe_mode_skip_root = Bool(L"editors_html_safe_mode_skip_root", true);
plugins_dir = Text(L"plugins_dir", L"/usr/local/winix/plugins");
NoLastSlash(plugins_dir);
ListText(L"plugins", plugin_file);
time_zone_offset = Int(L"time_zone_offset", 0);
time_zone_offset_guest = Int(L"time_zone_offset_guest", 0);
utf8 = Bool(L"utf8", true);
symlinks_follow_max = Size(L"symlinks_follow_max", 20);
ticket_form_prefix = Text(L"ticket_form_prefix", L"ticketparam");
pass_min_size = Size(L"pass_min_size", 5);
pass_type = Int(L"pass_type", 12);
pass_hash_use_salt = Bool(L"pass_hash_use_salt", false);
pass_hash_salt = Text(L"pass_hash_salt");
pass_use_rsa = Bool(L"pass_use_rsa", false);
pass_rsa_private_key = Text(L"pass_rsa_private_key");
opensll_path = Text(L"opensll_path", L"/usr/bin/openssl");
}
void Config::SetAdditionalVariables()
{
SetHttpHost(base_url, base_url_http_host);
SetHttpHost(base_url_auth, base_url_auth_http_host);
if( html_filter_orphans_mode_str == "160" )
html_filter_orphans_mode = HTMLFilter::orphan_160space;
else
html_filter_orphans_mode = HTMLFilter::orphan_nbsp;
for(size_t i=0 ; i<static_dirs.size() ; ++i)
NoLastSlash(static_dirs[i]);
CheckLocale();
CheckPasswd();
}
void Config::SetHttpHost(const std::string & in, std::string & out)
void Config::CheckLocale()
{
if( strncmp(in.c_str(), "http://", 7) == 0 )
out = in.substr(7);
bool found = false;
if( locale_files.empty() )
locale_files.push_back(L"en");
if( locale_default.empty() )
locale_default = locale_files[0];
for(size_t i=0 ; i<locale_files.size() ; ++i)
{
if( locale_files[i] == locale_default )
{
locale_default_index = i;
found = true;
break;
}
}
if( !found )
{
// we have at least one item
locale_default = locale_files[0];
locale_default_index = 0;
}
}
void Config::CheckPasswd()
{
switch(pass_type)
{
case WINIX_CRYPT_HASH_PLAIN:
case WINIX_CRYPT_HASH_MD4:
case WINIX_CRYPT_HASH_MD5:
case WINIX_CRYPT_HASH_SHA1:
case WINIX_CRYPT_HASH_SHA224:
case WINIX_CRYPT_HASH_SHA256:
case WINIX_CRYPT_HASH_SHA384:
case WINIX_CRYPT_HASH_SHA512:
break;
default:
pass_type = WINIX_CRYPT_HASH_SHA256;
}
}
void Config::SetHttpHost(const std::wstring & in, std::wstring & out)
{
const char http[] = "http://";
const char https[] = "https://";
size_t http_len = sizeof(http) / sizeof(char) - 1;
size_t https_len = sizeof(https) / sizeof(char) - 1;
if( IsSubString(http, in.c_str()) )
out = in.substr(http_len);
else
if( strncmp(in.c_str(), "https://", 8) == 0 )
out = in.substr(8);
if( IsSubString(https, in.c_str()) )
out = in.substr(https_len);
else
out.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done
}
std::string Config::Text(const char * name)
std::wstring Config::Text(const wchar_t * name)
{
return parser.Text(name);
}
std::string Config::Text(const char * name, const char * def)
std::wstring Config::Text(const wchar_t * name, const wchar_t * def)
{
return parser.Text(name, def);
}
std::string Config::Text(const std::string & name, const std::string & def)
std::wstring Config::Text(const std::wstring & name, const std::wstring & def)
{
return parser.Text(name, def);
}
int Config::Int(const char * name)
std::string Config::AText(const wchar_t * name)
{
return parser.AText(name);
}
std::string Config::AText(const wchar_t * name, const wchar_t * def)
{
return parser.AText(name, def);
}
std::string Config::AText(const std::wstring & name, const std::wstring & def)
{
return parser.AText(name, def);
}
int Config::Int(const wchar_t * name)
{
return parser.Int(name);
}
int Config::Int(const char * name, int def)
int Config::Int(const wchar_t * name, int def)
{
return parser.Int(name, def);
}
int Config::Int(const std::string & name, int def)
int Config::Int(const std::wstring & name, int def)
{
return parser.Int(name, def);
}
bool Config::Bool(const char * name)
size_t Config::Size(const wchar_t * name)
{
return parser.Size(name);
}
size_t Config::Size(const wchar_t * name, size_t def)
{
return parser.Size(name, def);
}
size_t Config::Size(const std::wstring & name, size_t def)
{
return parser.Size(name, def);
}
bool Config::Bool(const wchar_t * name)
{
return parser.Bool(name);
}
bool Config::Bool(const char * name, bool def)
bool Config::Bool(const wchar_t * name, bool def)
{
return parser.Bool(name, def);
}
bool Config::Bool(const std::string & name, bool def)
bool Config::Bool(const std::wstring & name, bool def)
{
return parser.Bool(name, def);
}
void Config::ListText(const char * name, std::vector<std::string> & list)
void Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
{
parser.ListText(name, list);
}
void Config::ListText(const std::string & name, std::vector<std::string> & list)
void Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
{
parser.ListText(name, list);
}
void Config::NoLastSlash(std::string & s)
void Config::Print(std::ostream & out)
{
if( s.empty() )
return;
size_t i = s.size();
for( ; i>0 && s[i-1]=='/' ; --i);
if( i < s.size() )
s.erase(i);
}
void Config::NoFirstHttp(std::string & s)
{
if( s.empty() )
return;
const char http[] = "http://";
const char https[] = "https://";
if( IsSubStringNoCase(http, s.c_str()) )
{
s.erase(0, sizeof(http)/sizeof(char));
}
else
if( IsSubStringNoCase(https, s.c_str()) )
{
s.erase(0, sizeof(https)/sizeof(char));
}
parser.Print(out);
}
@@ -274,4 +407,3 @@ void Config::NoFirstHttp(std::string & s)

View File

@@ -2,16 +2,17 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreconfig
#define headerfilecmslucoreconfig
#ifndef headerfile_winix_core_config
#define headerfile_winix_core_config
#include <string>
#include "confparser.h"
#include "htmlfilter.h"
@@ -20,9 +21,28 @@ class Config
{
public:
// name of the config file (full path can be)
// name of the config file
// this is the parameter passed to winix programm
std::string config_file;
// start as a demon (in the background)
// default: true
bool demonize;
// system user name (to which drop privileges)
// used only if winix is started as the root
std::string user;
// system group name (to which drop privileges)
// used only if winix is started as the root
std::string group;
// setting additional effective groups from /etc/group
// by using initgroups()
// used only if winix is started as the root
// default: true
bool additional_groups;
// log file name, log file name for notifications (sending emails, etc)
std::string log_file, log_notify_file;
@@ -32,12 +52,34 @@ public:
int log_level;
// logging to stdout too
// only if demonize is 'false'
// default: false
bool log_stdout;
// how many requests should be logged in the same time
// how many requests should be saved in the same time
// default: 1
int log_request;
// whether to save each line of the config (use it for debug purposes)
// default: false
bool log_save_each_line;
// logging db queries
// default: false
bool log_db_query;
// logging when a plugin function is called
// default: false
bool log_plugin_call;
// how many characters in values should be logged from POST parameters
// default: 80
// set to 0 to turn off
size_t log_post_value_size;
// request delimiter in the log file, default "---------"
std::wstring log_delimiter;
// fast cgi: socket (unix domain)
std::string fcgi_socket;
@@ -50,8 +92,26 @@ public:
// fast cgi: group of the socket
std::string fcgi_socket_group;
std::string templates_dir;
std::string templates_dir_default; // templates from winix
std::wstring templates_dir;
std::wstring templates_dir_default; // html templates from winix
std::wstring txt_templates_dir;
std::wstring txt_templates_dir_default; // txt (notifications) templates from winix
// prefix and postfix for functions templates
// default:
// prefix: "fun_"
// postfix: ".html"
std::wstring templates_fun_prefix;
std::wstring templates_fun_postfix;
// main html template
// default: index.html
std::wstring templates_index;
// if true then only root can use 'template' function
// default: false
bool template_only_root_use_template_fun;
std::string db_database;
std::string db_user;
@@ -65,8 +125,8 @@ public:
bool base_url_redirect;
// string used in a place where is a user (or group) selected
std::string priv_no_user;
std::string priv_no_group;
std::wstring priv_no_user;
std::wstring priv_no_group;
// time in seconds when the user will be automatically logged out (iddle time)
int session_max_idle;
@@ -78,88 +138,284 @@ public:
// this file is used when the program is starting and ending
std::string session_file;
// allow the html ouput to be compressed
bool compression;
// plugins
std::vector<std::string> plugin_file;
// how many sessions can be (zero turn off this checking)
// default: 1000000 (one milion)
size_t session_max;
// the html code is cleaned by our filter
// allow the html output to be compressed
// default: true
bool compression;
// if the output is shorter than this value then it will not be compressed
// default: 512 bytes
size_t compression_page_min_size;
// 1 - use deflate if available (or raw deflate for Internet Explorer) or don't compress
// 2 - use gzip if available or don't compress
// 10 - prefer deflate -- use deflate (or raw deflate for IE) if both deflate and gzip are available
// 20 - prefer gzip -- use gzip if both deflate and gzip are available
// default: 20
int compression_encoding;
// plugins directory
// default: /usr/local/winix/plugins
std::wstring plugins_dir;
// plugins
// you can provide either a relative path (plugins_dir will be used)
// or a full path to a plugin
std::vector<std::wstring> plugin_file;
// should the html code be cleaned by the html filter
bool html_filter;
// should white characters be trimmed
bool html_filter_trim_white;
// when long words should be broken (a space will be inserted)
// default: after 60 non white characters will be put a space
// set zero to turn off
size_t html_filter_break_word;
// when long lines should be broken (a new line character will be inserted)
// default: 80
// set zero to turn off
size_t html_filter_wrap_line;
// how many spaces will be put at one tree level
// default: 2
size_t html_filter_tabs;
// use checking for 'orphans' for a specicic language
// default: true
bool html_filter_orphans;
// orphans mode
// either: "nbsp" or "160"
// default: "nbsp"
std::string html_filter_orphans_mode_str;
HTMLFilter::OrphanMode html_filter_orphans_mode;
// the url of a new empty item (if there is not the subject too)
std::string item_url_empty;
std::wstring item_url_empty;
// maximum length of a file send by post multipart form
// 0 - not used
int post_file_max;
size_t post_file_max;
// directories for static files
std::string auth_simplefs_dir;
std::string auth_hashfs_dir;
// directory for static files
std::wstring upload_dir;
// temporary directory for static content used by the upload function
// should be on the same partition as auth_simplefs_dir and auth_hashfs_dir
std::string auth_tmp_dir;
// additional static directories *not* managed by winix
// you can refer to this directories by using 'static' mount point
// e.g.
// let we say in the config you have:
// static_dirs = ("/home/a", "/home/b", "/home/c")
// and in /etc/fstab (in winix) you have such a line:
// "static /my/dir simplefs static(2)"
// above line in /etc/fstab means that when a user enters http://domain.com/my/dir/file.txt
// then "file.txt" will be taken from "/home/c/file.txt"
// this is useful for some javascript files which are protected from running from other domains
std::vector<std::wstring> static_dirs;
// default locale: en pl
std::string locale_str;
// sometimes you can have trouble when you have set an incorrect static path in /etc/fstab
// in such a case set dont_use_static_dirs to true
// and winix will behave as there are not any static directories
// so you can correct your mistake and then set this value to false
bool dont_use_static_dirs;
// chmod of newly created directories (under upload_dir)
// default: 0750
int upload_dirs_chmod;
// chmod of newly created files (under upload_dir)
// default: 0640
int upload_files_chmod;
// create a thumbnail from an image
// default: true
bool create_thumb;
// the mode of creating a thumbnail
// width means thumb_cx, height means thumb_cy
// 1: Width given, height automagically selected to preserve aspect ratio.
// 2: Height given, width automagically selected to preserve aspect ratio.
// 3: Maximum values of height and width given, aspect ratio preserved.
// 4: Minimum values of width and height given, aspect ratio preserved.
// 5: Width and height emphatically given, original aspect ratio ignored.
// 6: Change as per widthxheight (3) but only if an image dimension exceeds a specified dimension.
// 7: Change dimensions only if both image dimensions are less than specified dimensions.
// default: 2
int thumb_mode;
// width of thumbnails
// default: 150
size_t thumb_cx;
// height of thumbnails
// default: 150
size_t thumb_cy;
// the convert program
// default: /usr/local/bin/convert
std::wstring convert_cmd;
// directory with locale files
std::string locale_dir;
std::wstring locale_dir;
// directory with default locale files (those from winix)
std::string locale_dir_default;
std::wstring locale_dir_default;
// locale files (e.g. "en", "pl")
// default: only one item: en
std::vector<std::wstring> locale_files;
// default locale
// default: the first item from locale_files
std::wstring locale_default;
// default locale - index to locale_files
// not available in config -- set automatically based on locale_default
size_t locale_default_index;
// the main address of the server (e.g. someserver.com) (without the 'www' part etc)
std::string base_server;
std::wstring base_server;
// the main address of the site (e.g. http://www.someserver.com)
std::string base_url;
// static content authorized by winix
std::string base_url_auth;
std::wstring base_url;
// static content not authorized by winix
std::string base_url_static;
std::wstring base_url_static;
// additional static server for common content (not authorized)
std::string base_url_common;
std::wstring base_url_common;
// separator used in <title> html tag
std::string title_separator;
std::wstring title_separator;
// http header recognized by www server as a file to send back
// default: X-LIGHTTPD-send-file
std::wstring http_header_send_file;
// prints additional information (in the end of the html page as a commentary)
bool debug_info;
// in editors (emacs, ckeditor,...) the html will be filtered and unsafe tags
// will be dropped (script, frame, etc.)
// default: true;
bool editors_html_safe_mode;
// don't filter the html code for root
// default: true
// (if true the html code for root is not filtered)
bool editors_html_safe_mode_skip_root;
// temporarily we do not support time zones per user
// there is one offset for all users
// default: 0
int time_zone_offset;
// time zone offset for guests (not logged users)
// default: 0
int time_zone_offset_guest;
// charset used in templates, locales, logs etc.
// default: true (UTF-8)
// if false it means 8-bit ASCII
bool utf8;
// how many maximum symlinks can be followed
// (symlinks on directories as well)
// default: 20
size_t symlinks_follow_max;
// the prefix of a name of html form controls used in the ticket plugin
// default: ticketparam
std::wstring ticket_form_prefix;
// the minimal size of a user's password
// default: 5
size_t pass_min_size;
// how passwords should be stored
// 0 - plain text
// 1 - md4 hash
// 2 - md5 hash
// 10 - sha1 hash
// 11 - sha224 hash
// 12 - sha256 hash (default)
// 13 - sha384 hash
// 14 - sha512 hash
int pass_type;
// whether the passwords' hashes should be salted or not
// this affects newly created accounts
// default: false
bool pass_hash_use_salt;
// salt to a password's hash
// default empty
// !! once you set this salt don't change it any more (people wouldn't be allowed to login)
std::wstring pass_hash_salt;
// whether the passwords' hashes should be encrypted
// this affects newly created accounts
// default: false
bool pass_use_rsa;
// path to a RSA private key
// this is actually private + public key in one file
// generated by "openssl genrsa"
// default empty which means encryption will not be used
// !! once you set these keys don't change it any more (people wouldn't be allowed to login)
std::wstring pass_rsa_private_key;
// path to 'openssl'
// default: /usr/bin/openssl
std::wstring opensll_path;
/*
*/
// based on base_url
// set by SetAdditionalVariables()
// without the first part http:// (or https://) or the whole string is empty
std::string base_url_http_host;
std::string base_url_auth_http_host;
std::wstring base_url_http_host;
Config();
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
std::string Text(const char * name);
std::string Text(const char * name, const char * def);
std::string Text(const std::string & name, const std::string & def);
int Int(const char *);
int Int(const char * name, int def);
int Int(const std::string & name, int def);
bool Bool(const char *);
bool Bool(const char * name, bool def);
bool Bool(const std::string & name, bool def);
void ListText(const char * name, std::vector<std::string> & list);
void ListText(const std::string & name, std::vector<std::string> & list);
std::wstring Text(const wchar_t * name);
std::wstring Text(const wchar_t * name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const std::wstring & def);
std::string AText(const wchar_t * name);
std::string AText(const wchar_t * name, const wchar_t * def);
std::string AText(const std::wstring & name, const std::wstring & def);
void NoLastSlash(std::string & s);
void NoFirstHttp(std::string & s);
int Int(const wchar_t *);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
size_t Size(const wchar_t *);
size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def);
bool Bool(const wchar_t *);
bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def);
void ListText(const wchar_t * name, std::vector<std::wstring> & list);
void ListText(const std::wstring & name, std::vector<std::wstring> & list);
// for debug
void Print(std::ostream & out);
private:
void ShowError();
void AssignValues(bool stdout_is_closed);
void SetHttpHost(const std::string & in, std::string & out);
void SetHttpHost(const std::wstring & in, std::wstring & out);
void SetAdditionalVariables();
void CheckLocale();
void CheckPasswd();
ConfParser parser;

View File

@@ -7,8 +7,11 @@
*
*/
#include <cstdlib>
#include <wchar.h>
#include "confparser.h"
#include "misc.h"
#include "utf8.h"
@@ -24,9 +27,12 @@ ConfParser::ConfParser()
list_delimiter = ',';
split_single = false;
skip_empty = false;
use_escape_char = true;
input_as_utf8 = false;
default_str = "";
default_str = L"";
default_int = 0;
default_size = 0;
default_bool = false;
}
@@ -43,6 +49,15 @@ void ConfParser::SkipEmpty(bool skip)
}
void ConfParser::UseEscapeChar(bool escape)
{
use_escape_char = escape;
}
ConfParser::Status ConfParser::Parse(const char * file_name)
{
line = 1;
@@ -74,6 +89,23 @@ ConfParser::Status ConfParser::Parse(const std::string & file_name)
ConfParser::Status ConfParser::Parse(const wchar_t * file_name)
{
Ezc::WideToUTF8(file_name, afile_name);
return Parse(afile_name.c_str());
}
ConfParser::Status ConfParser::Parse(const std::wstring & file_name)
{
return Parse(file_name.c_str());
}
ConfParser::Status ConfParser::ParseFile()
{
ReadChar();
@@ -140,7 +172,7 @@ void ConfParser::AddOption()
void ConfParser::DeleteFromTable(const std::string & var)
void ConfParser::DeleteFromTable(const std::wstring & var)
{
Table::iterator i = table.find(var);
@@ -150,7 +182,7 @@ void ConfParser::DeleteFromTable(const std::string & var)
void ConfParser::DeleteFromTableSingle(const std::string & var)
void ConfParser::DeleteFromTableSingle(const std::wstring & var)
{
TableSingle::iterator i = table_single.find(var);
@@ -251,7 +283,7 @@ bool ConfParser::ReadValueQuoted()
while( lastc != '"' && lastc != -1 )
{
if( lastc == '\\' )
if( use_escape_char && lastc == '\\' )
ReadChar();
value_item += lastc;
@@ -294,7 +326,33 @@ return true;
}
int ConfParser::ReadChar()
int ConfParser::ReadUTF8Char()
{
int c;
bool correct;
lastc = -1;
do
{
Ezc::UTF8ToInt(file, c, correct);
if( !file )
return lastc;
}
while( !correct );
lastc = c;
if( lastc == '\n' )
++line;
return lastc;
}
int ConfParser::ReadASCIIChar()
{
lastc = file.get();
@@ -305,6 +363,15 @@ return lastc;
}
int ConfParser::ReadChar()
{
if( input_as_utf8 )
return ReadUTF8Char();
return ReadASCIIChar();
}
bool ConfParser::IsWhite(int c)
{
// dont use '\n' here
@@ -350,9 +417,9 @@ void ConfParser::SkipLine()
void ConfParser::Trim(std::string & s)
void ConfParser::Trim(std::wstring & s)
{
std::string::size_type i;
std::wstring::size_type i;
if( s.empty() )
return;
@@ -369,7 +436,7 @@ std::string::size_type i;
// deleting white characters at the end
if( i != s.size() - 1 )
s.erase(i+1, std::string::npos);
s.erase(i+1, std::wstring::npos);
// looking for white characters at the beginning
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
@@ -384,20 +451,20 @@ std::string::size_type i;
std::string ConfParser::Text(const char * name)
std::wstring ConfParser::Text(const wchar_t * name)
{
return Text(std::string(name), default_str);
return Text(std::wstring(name), default_str);
}
std::string ConfParser::Text(const char * name, const char * def)
std::wstring ConfParser::Text(const wchar_t * name, const wchar_t * def)
{
return Text(std::string(name), std::string(def));
return Text(std::wstring(name), std::wstring(def));
}
std::string ConfParser::Text(const std::string & name, const std::string & def)
std::wstring ConfParser::Text(const std::wstring & name, const std::wstring & def)
{
TableSingle::iterator i = table_single.find(name);
@@ -416,27 +483,63 @@ return i->second;
int ConfParser::Int(const char * name)
std::string ConfParser::AText(const wchar_t * name)
{
return Int(std::string(name), default_int);
std::wstring res = Text(name);
std::string ares;
Ezc::WideToUTF8(res, ares);
return ares;
}
int ConfParser::Int(const char * name, int def)
std::string ConfParser::AText(const wchar_t * name, const wchar_t * def)
{
return Int(std::string(name), def);
std::wstring res = Text(name, def);
std::string ares;
Ezc::WideToUTF8(res, ares);
return ares;
}
int ConfParser::ToInt(const std::string & value)
std::string ConfParser::AText(const std::wstring & name, const std::wstring & def)
{
long res = (value[0] == '0')? strtol(value.c_str() + 1, 0, 8) : strtol(value.c_str(), 0, 10);
std::wstring res = Text(name, def);
std::string ares;
Ezc::WideToUTF8(res, ares);
return ares;
}
int ConfParser::Int(const wchar_t * name)
{
return Int(std::wstring(name), default_int);
}
int ConfParser::Int(const wchar_t * name, int def)
{
return Int(std::wstring(name), def);
}
int ConfParser::ToInt(const std::wstring & value)
{
long res = (value[0] == '0')? wcstol(value.c_str() + 1, 0, 8) : wcstol(value.c_str(), 0, 10);
return res;
return static_cast<int>(res);
}
int ConfParser::Int(const std::string & name, int def)
int ConfParser::Int(const std::wstring & name, int def)
{
TableSingle::iterator i = table_single.find(name);
@@ -454,28 +557,70 @@ return ToInt(i->second);
}
bool ConfParser::Bool(const char * name)
size_t ConfParser::Size(const wchar_t * name)
{
return Bool(std::string(name), default_bool);
return Size(std::wstring(name), default_size);
}
bool ConfParser::Bool(const char * name, bool def)
size_t ConfParser::Size(const wchar_t * name, size_t def)
{
return Bool(std::string(name), def);
return Size(std::wstring(name), def);
}
bool ConfParser::ToBool(const std::string & value)
size_t ConfParser::ToSize(const std::wstring & value)
{
return ( EqualNoCase(value.c_str(), "true") ||
EqualNoCase(value.c_str(), "yes") ||
EqualNoCase(value.c_str(), "1")
unsigned long res = (value[0] == '0')? wcstoul(value.c_str() + 1, 0, 8) : wcstoul(value.c_str(), 0, 10);
return static_cast<size_t>(res);
}
size_t ConfParser::Size(const std::wstring & name, size_t def)
{
TableSingle::iterator i = table_single.find(name);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() )
return def;
return ToSize(t->second[0]);
}
return ToSize(i->second);
}
bool ConfParser::Bool(const wchar_t * name)
{
return Bool(std::wstring(name), default_bool);
}
bool ConfParser::Bool(const wchar_t * name, bool def)
{
return Bool(std::wstring(name), def);
}
bool ConfParser::ToBool(const std::wstring & value)
{
return ( EqualNoCase(value.c_str(), L"true") ||
EqualNoCase(value.c_str(), L"yes") ||
EqualNoCase(value.c_str(), L"1")
);
}
bool ConfParser::Bool(const std::string & name, bool def)
bool ConfParser::Bool(const std::wstring & name, bool def)
{
TableSingle::iterator i = table_single.find(name);
@@ -493,7 +638,7 @@ return ToBool(i->second);
}
void ConfParser::SetDefaultText(const std::string & def)
void ConfParser::SetDefaultText(const std::wstring & def)
{
default_str = def;
}
@@ -503,6 +648,11 @@ void ConfParser::SetDefaultInt(int def)
default_int = def;
}
void ConfParser::SetDefaultSize(size_t def)
{
default_size = def;
}
void ConfParser::SetDefaultBool(bool def)
{
default_bool = def;
@@ -512,13 +662,13 @@ void ConfParser::SetDefaultBool(bool def)
// in lists we don't use default values
void ConfParser::ListText(const char * name, std::vector<std::string> & list)
void ConfParser::ListText(const wchar_t * name, std::vector<std::wstring> & list)
{
ListText(std::string(name), list);
ListText(std::wstring(name), list);
}
void ConfParser::ListText(const std::string & name, std::vector<std::string> & list)
void ConfParser::ListText(const std::wstring & name, std::vector<std::wstring> & list)
{
list.clear();
@@ -539,3 +689,41 @@ void ConfParser::ListText(const std::string & name, std::vector<std::string> & l
}
}
void ConfParser::UTF8(bool utf)
{
input_as_utf8 = utf;
}
void ConfParser::Print(std::ostream & out)
{
TableSingle::iterator i1;
for(i1 = table_single.begin() ; i1 != table_single.end() ; ++i1)
{
Ezc::WideToUTF8(i1->first, out);
out << '=';
Ezc::WideToUTF8(i1->second, out);
out << std::endl;
}
Table::iterator i2;
Value::iterator i3;
for(i2 = table.begin() ; i2 != table.end() ; ++i2)
{
Ezc::WideToUTF8(i2->first, out);
out << '=';
for(i3 = i2->second.begin() ; i3 != i2->second.end() ; ++i3)
{
Ezc::WideToUTF8(*i3, out);
out << ',';
}
out << std::endl;
}
}

View File

@@ -122,6 +122,7 @@ config syntax:
"\a" gives "a"
"\\" gives "\"
"\Z" gives "Z" and so on
you can call UseEscapeChar(false) to turn this off
*/
@@ -150,6 +151,8 @@ public:
*/
Status Parse(const char * file_name);
Status Parse(const std::string & file_name);
Status Parse(const wchar_t * file_name);
Status Parse(const std::wstring & file_name);
/*
@@ -162,8 +165,8 @@ public:
this is the table which represents your config file
in the Table map: the first (key) is your 'option' and the second is 'list'
*/
typedef std::vector<std::string> Value;
typedef std::map<std::string, Value> Table;
typedef std::vector<std::wstring> Value;
typedef std::map<std::wstring, Value> Table;
Table table;
@@ -173,10 +176,10 @@ public:
option2 = value2
then you can call SplitSingle(true) for not inserting single values to
previous 'table' but instead to 'table_single'
table_single as the second parameter takes only std::string (instead of the whole std::vector)
table_single as the second parameter takes only std::wstring (instead of the whole std::vector)
so you can save a little memory from not using std::vector
*/
typedef std::map<std::string, std::string> TableSingle;
typedef std::map<std::wstring, std::wstring> TableSingle;
TableSingle table_single;
@@ -202,6 +205,15 @@ public:
void SkipEmpty(bool skip);
/*
'\' character is used to escape other characters in a quoted string
so "some \t t\"ext" will produce "some t t"ext"
(this is only use in quoted string)
default: true
*/
void UseEscapeChar(bool escape);
/*
those methods are used to extract information from table or table_single
as a parameter they take the name of an option
@@ -209,15 +221,21 @@ public:
they return appropriate value (either text, int or boolean)
(in lists they return the first item if exists)
*/
std::string Text(const char * name);
std::string Text(const char * name, const char * def);
std::string Text(const std::string & name, const std::string & def);
int Int(const char *);
int Int(const char * name, int def);
int Int(const std::string & name, int def);
bool Bool(const char *);
bool Bool(const char * name, bool def);
bool Bool(const std::string & name, bool def);
std::wstring Text(const wchar_t * name);
std::wstring Text(const wchar_t * name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const std::wstring & def);
std::string AText(const wchar_t * name);
std::string AText(const wchar_t * name, const wchar_t * def);
std::string AText(const std::wstring & name, const std::wstring & def);
int Int(const wchar_t *);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
size_t Size(const wchar_t *);
size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def);
bool Bool(const wchar_t *);
bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def);
/*
@@ -226,11 +244,12 @@ public:
if you don't set it directly then:
default text is: "" (empty)
default int is: 0
default int or size is: 0
default bool is: false
*/
void SetDefaultText(const std::string & def);
void SetDefaultText(const std::wstring & def);
void SetDefaultInt(int def);
void SetDefaultSize(size_t def);
void SetDefaultBool(bool def);
@@ -238,8 +257,21 @@ public:
those methods are used to extract lists
note: if there is one option in table_single they will return it
*/
void ListText(const char * name, std::vector<std::string> & list);
void ListText(const std::string & name, std::vector<std::string> & list);
void ListText(const wchar_t * name, std::vector<std::wstring> & list);
void ListText(const std::wstring & name, std::vector<std::wstring> & list);
/*
if true then the input file is treated as UTF-8
*/
void UTF8(bool utf);
/*
printing the content
(for debug purposes)
*/
void Print(std::ostream & out);
private:
@@ -247,13 +279,13 @@ private:
/*
last read variable (option)
*/
std::string variable;
std::wstring variable;
/*
last read list item
*/
std::string value_item;
std::wstring value_item;
/*
@@ -294,6 +326,7 @@ private:
/*
last read char
or -1 if the end
*/
int lastc;
@@ -321,19 +354,34 @@ private:
bool skip_empty;
/*
input file is in UTF-8
default: false
*/
bool input_as_utf8;
std::string default_str;
/*
if true you can use an escape character '\' in quoted values
*/
bool use_escape_char;
std::string afile_name;
std::wstring default_str;
int default_int;
size_t default_size;
bool default_bool;
int ToInt(const std::string & value);
bool ToBool(const std::string & value);
int ToInt(const std::wstring & value);
size_t ToSize(const std::wstring & value);
bool ToBool(const std::wstring & value);
Status ParseFile();
void AddOption();
void DeleteFromTable(const std::string & var);
void DeleteFromTableSingle(const std::string & var);
void DeleteFromTable(const std::wstring & var);
void DeleteFromTableSingle(const std::wstring & var);
bool ReadVariable();
bool ReadValue();
@@ -342,13 +390,15 @@ private:
bool ReadValueQuoted();
bool ReadValueSimple(bool use_list_delimiter = false);
int ReadUTF8Char();
int ReadASCIIChar();
int ReadChar();
bool IsWhite(int c);
bool IsVariableChar(int c);
void SkipWhite();
void SkipWhiteLines();
void SkipLine();
void Trim(std::string & s);
void Trim(std::wstring & s);
};

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucorecookieparser
#define headerfilecmslucorecookieparser
#ifndef headerfile_winix_core_cookieparser
#define headerfile_winix_core_cookieparser
#include <fcgiapp.h>
#include "httpsimpleparser.h"
@@ -21,7 +21,7 @@ class CookieParser : public HttpSimpleParser
{
const char * cookie_string;
CookieTable & cookie_table;
CookieTab * cookie_tab;
protected:
@@ -41,7 +41,7 @@ protected:
// Cookie names are case insensitive according to section 3.1 of RFC 2965
ToLower(name);
std::pair<CookieTable::iterator, bool> res = cookie_table.insert( std::make_pair(name, value) );
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(name, value) );
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
@@ -58,7 +58,7 @@ protected:
public:
CookieParser(const char * cookie_string_, CookieTable & cookie_table_) : cookie_string(cookie_string_), cookie_table(cookie_table_)
CookieParser()
{
HttpSimpleParser::separator = ';';
HttpSimpleParser::value_can_be_quoted = true;
@@ -66,6 +66,16 @@ public:
HttpSimpleParser::recognize_special_chars = false;
}
// cookie_string can be null
void Parse(const char * cookie_string_, CookieTab & cookie_tab_)
{
cookie_string = cookie_string_;
cookie_tab = &cookie_tab_;
HttpSimpleParser::Parse();
}
};

273
core/crypt.cpp Executable file
View File

@@ -0,0 +1,273 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include <cstring>
#include "crypt.h"
#include "utf8.h"
#include "misc.h"
#include "log.h"
void Crypt::SetConfig(Config * pconfig)
{
config = pconfig;
}
void Crypt::TrimLastWhite(std::string & str)
{
if( str.empty() )
return;
size_t i = str.size();
while( i > 0 && (IsWhite(str[i-1]) || str[i-1]==10) )
i -= 1;
if( i < str.size() )
str.erase(i);
}
bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
{
out.clear();
if( !config )
return false;
run.Clear();
Ezc::WideToUTF8(config->opensll_path, command);
run.Cmd(command);
run.Par("dgst");
switch(hash)
{
case WINIX_CRYPT_HASH_MD4: run.Par("-md4"); break;
case WINIX_CRYPT_HASH_MD5: run.Par("-md5"); break;
case WINIX_CRYPT_HASH_SHA1: run.Par("-sha1"); break;
case WINIX_CRYPT_HASH_SHA224: run.Par("-sha224"); break;
case WINIX_CRYPT_HASH_SHA256: run.Par("-sha256"); break;
case WINIX_CRYPT_HASH_SHA384: run.Par("-sha384"); break;
case WINIX_CRYPT_HASH_SHA512: run.Par("-sha512"); break;
default:
return false;
}
bool result = run.Go(in, inlen, out) == 0;
TrimLastWhite(out);
return result;
}
bool Crypt::Hash(int hash, const char * in, std::string & out)
{
size_t len = strlen(in);
return Hash(hash, in, len, out);
}
bool Crypt::Hash(int hash, const std::string & in, std::string & out)
{
return Hash(hash, in.c_str(), in.size(), out);
}
bool Crypt::Hash(int hash, const wchar_t * in, size_t inlen, std::wstring & out)
{
Ezc::WideToUTF8(in, inlen, bufina);
int res = Hash(hash, bufina.c_str(), bufina.size(), bufouta);
// the output hash is not a UTF8 string
// it consists only from ascii letters
AssignString(bufouta, out);
return res;
}
bool Crypt::Hash(int hash, const wchar_t * in, std::wstring & out)
{
size_t len = wcslen(in);
return Hash(hash, in, len, out);
}
bool Crypt::Hash(int hash, const std::wstring & in, std::wstring & out)
{
return Hash(hash, in.c_str(), in.size(), out);
}
bool IsAllWhite(const char * str)
{
for( ; *str ; ++str)
{
if( !(IsWhite(*str) || *str==10) )
return false;
}
return true;
}
bool Crypt::RSA(bool encrypt, const char * keypath, const char * in, size_t inlen, std::string & out)
{
out.clear();
if( !config || IsAllWhite(keypath) )
return false;
run.Clear();
Ezc::WideToUTF8(config->opensll_path, command);
run.Cmd(command);
run.Par("rsautl");
run.Par("-inkey");
run.Par(keypath);
if(encrypt)
run.Par("-encrypt");
else
run.Par("-decrypt");
return run.Go(in, inlen, out) == 0;
}
bool Crypt::RSA(bool encrypt, const char * keypath, const std::string & in, std::string & out)
{
return RSA(encrypt, keypath, in.c_str(), in.size(), out);
}
bool Crypt::RSA(bool encrypt, const std::string & keypath, const std::string & in, std::string & out)
{
return RSA(encrypt, keypath.c_str(), in.c_str(), in.size(), out);
}
bool Crypt::RSA(bool encrypt, const wchar_t * keypath, const char * in, size_t inlen, std::string & out)
{
Ezc::WideToUTF8(keypath, keypatha);
return RSA(encrypt, keypatha.c_str(), in, inlen, out);
}
bool Crypt::RSA(bool encrypt, const wchar_t * keypath, const std::string & in, std::string & out)
{
return RSA(encrypt, keypath, in.c_str(), in.size(), out);
}
bool Crypt::RSA(bool encrypt, const std::wstring & keypath, const std::string & in, std::string & out)
{
return RSA(encrypt, keypath.c_str(), in.c_str(), in.size(), out);
}
bool Crypt::PassHash(const std::wstring & salt, UserPass & up)
{
bool result = true;
up.pass_hash_salted = false;
if( up.pass_type != WINIX_CRYPT_HASH_PLAIN )
{
pass_org = up.pass;
pass_salted = up.pass;
pass_salted += salt;
if( Hash(up.pass_type, pass_salted, up.pass) )
{
if( !salt.empty() )
up.pass_hash_salted = true;
}
else
{
log << log1 << "Crypt: problem with generating a hash, the password will not be hashed" << logend;
up.pass = pass_org;
up.pass_type = WINIX_CRYPT_HASH_PLAIN;
result = false;
}
ClearString(pass_salted);
ClearString(pass_org);
}
return result;
}
bool Crypt::PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & up)
{
bool result = false;
ClearString(up.pass_encrypted);
if( !path_to_rsa_private_key.empty() )
{
Ezc::WideToUTF8(up.pass, passa);
if( RSA(true, path_to_rsa_private_key, passa, up.pass_encrypted) )
{
result = true;
}
else
{
ClearString(up.pass_encrypted);
log << log1 << "AddUser: problem with encrypting, the password will not be encrypted!" << logend;
}
ClearString(passa);
}
return result;
}
void Crypt::PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, UserPass & up)
{
PassHash(salt, up);
PassCrypt(path_to_rsa_private_key, up);
}
void Crypt::PassHashCrypt(UserPass & up)
{
up.pass_type = config->pass_type;
empty.clear();
if( config->pass_hash_use_salt && !config->pass_hash_salt.empty() )
PassHash(config->pass_hash_salt, up);
else
PassHash(empty, up);
if( config->pass_use_rsa && !config->pass_rsa_private_key.empty() )
PassCrypt(config->pass_rsa_private_key, up);
}

209
core/crypt.h Executable file
View File

@@ -0,0 +1,209 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_crypt
#define headerfile_winix_core_crypt
#include <string>
#include "run.h"
#include "config.h"
#include "user.h"
/*
the kind of hashes we are able to obtain in winix
*/
#define WINIX_CRYPT_HASH_PLAIN 0
#define WINIX_CRYPT_HASH_MD4 1
#define WINIX_CRYPT_HASH_MD5 2
#define WINIX_CRYPT_HASH_SHA1 10
#define WINIX_CRYPT_HASH_SHA224 11
#define WINIX_CRYPT_HASH_SHA256 12
#define WINIX_CRYPT_HASH_SHA384 13
#define WINIX_CRYPT_HASH_SHA512 14
/*
calculating hashes, encrypting and decrypting with RSA
*/
class Crypt
{
public:
void SetConfig(Config * pconfig);
/*
calculating a hash from a given input
input:
hash - the kind of the hash - WINIX_CRYPT_HASH_*
in - input buffer
inlen - the length of the buffer
output:
out - the hash
*/
bool Hash(int hash, const char * in, size_t inlen, std::string & out);
bool Hash(int hash, const char * in, std::string & out);
bool Hash(int hash, const std::string & in, std::string & out);
/*
calculating a hash from a given input
the input string is first changed to UTF8 and then hash is calculated
input:
hash - the kind of the hash - WINIX_CRYPT_HASH_*
in - input buffer
inlen - the length of the buffer
output:
out - the hash
*/
bool Hash(int hash, const wchar_t * in, size_t inlen, std::wstring & out);
bool Hash(int hash, const wchar_t * in, std::wstring & out);
bool Hash(int hash, const std::wstring & in, std::wstring & out);
/*
encrypt/decrypt by using RSA algorithm
input:
encrypt - true means encrypting, false means decrypting
keypath - path to a RSA private key (this is a private and public key in one file)
in - input buffer
inlen - the size of the buffer
output:
out - encrypted or decrypted buffer
*/
bool RSA(bool encrypt, const char * keypath, const char * in, size_t inlen, std::string & out);
bool RSA(bool encrypt, const char * keypath, const std::string & in, std::string & out);
bool RSA(bool encrypt, const std::string & keypath, const std::string & in, std::string & out);
bool RSA(bool encrypt, const wchar_t * keypath, const char * in, size_t inlen, std::string & out);
bool RSA(bool encrypt, const wchar_t * keypath, const std::string & in, std::string & out);
bool RSA(bool encrypt, const std::wstring & keypath, const std::string & in, std::string & out);
/*
this method creates a hash from the given plain text password
input.
salt - salt for the hash
up.pass_type - what kind of hash do you want - look at WINIX_CRYPT_HASH_* macros (in crypt.h)
up.pass - plain text password
if salt is empty then the hash will not be salted
output:
up.pass_type - (can be changed to 0 when there is a problem with generating a hash)
up.pass - hash from the password (or plain text if up.pass_type was zero)
up.pass_hash_salted (true if the hash is salted - when salt was not empty)
if there is a problem with generating a hash the method stores a plain text password
and changes up.pass_type to zero (plain text passwords are not salted)
*/
bool PassHash(const std::wstring & salt, UserPass & up);
/*
this method encrypts the given password
input:
path_to_rsa_private_key - a path to rsa private key (this are a private and public keys both in one file)
up.pass - given password (can be a plain text or a hash)
if path_to_rsa_private_key is empty then the password will not be encrypted
output:
up.pass_encrypted
if there is a problem (or the path to the key is empty) then up.pass_encrypted will be empty
and the method returns false
*/
bool PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & up);
/*
this method creates a hash from the given plain text password and then encrypts it
input:
salt - salt for the hash
path_to_rsa_private_key - a path to rsa private key (this are a private and public keys both in one file)
up.pass_type - what kind of hash do you want - look at WINIX_CRYPT_HASH_* macros (in crypt.h)
up.pass - plain text password
if salt is empty then the hash will not be salted
if path_to_rsa_private_key is empty then the password will not be encrypted
output:
up.pass_type - (can be changed to 0 when there is a problem with generating a hash)
up.pass - hash from the password (or plain text if up.pass_type was zero)
up.pass_hash_salted (true if the hash is salted - when salt was not empty)
up.pass_encrypted - encrypted password (if not empty)
*/
void PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, UserPass & up);
/*
this method creates a hash from the given plain text password and then encrypts it
input:
up.pass - plain text password
output:
up.pass_type - what kind of hash there is in up.pass
up.pass - hash from the password (or plain text if up.pass_type is zero)
up.pass_hash_salted - true if the hash is salted (plain text are never salted)
up.pass_encrypted - encrypted password (if not empty)
*/
void PassHashCrypt(UserPass & up);
/*
putting some characters into the string and then calling clear()
*/
template<class StringType>
void ClearString(StringType & str);
private:
void TrimLastWhite(std::string & str);
Config * config;
Run run;
std::string command, bufina, bufouta, keypatha;
//std::wstring pass_salted;//, pass_hashed;
//std::string pass_hasheda, pass_encrypteda;
std::wstring pass_salted, pass_org;
std::string passa;
std::wstring empty;
};
template<class StringType>
void Crypt::ClearString(StringType & str)
{
for(size_t i=0 ; i<str.size() ; ++i)
str[i] = 0x0c;
str.clear();
}
#endif

34
core/cur.h Executable file
View File

@@ -0,0 +1,34 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_cur
#define headerfile_winix_core_cur
#include "request.h"
#include "session.h"
/*
current request and session
*/
struct Cur
{
Request * request;
Session * session;
// those pointers are never null, if there is no a session for the user
// the 'session' pointer pointers at a special temporary session
};
#endif

File diff suppressed because it is too large Load Diff

256
core/db.h
View File

@@ -1,256 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoredb
#define headerfilecmslucoredb
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <libpq-fe.h>
#include <cstdio>
#include <ctime>
#include <cstring>
#include "item.h"
#include "user.h"
#include "group.h"
#include "thread.h"
#include "error.h"
#include "dircontainer.h"
#include "ugcontainer.h"
#include "ticket.h"
class Db
{
public:
Db(bool close_at_end_ = true);
~Db();
// !! przerobic tak aby GetItem zwracalo wszystkie pozycja
// !! GetFile tylko dla plikow
// !! GetDir tylko dla katalogow
// !! GetFile i GetDir beda uzywac GetItem
void Init(const std::string & database, const std::string & user, const std::string & pass);
bool CheckUser(std::string & login, std::string & password, long & user_id);
Error AddUser(User & user, const std::string & password);
Error AddItem(Item & item);
Error EditItemById(Item & item, bool with_url = true);
Error EditItemByUrl(Item & item, bool with_url = true);
void CheckAllUrlSubject();
struct ItemQuery
{
// id is selected always
bool sel_parent_id; // parent_id
bool sel_user_id; // user_id, modification_user_id
bool sel_group_id; // group_id
bool sel_guest_name; // guest_name
bool sel_privileges; // privileges
bool sel_date; // date_creation, date_modification
bool sel_subject; // subject
bool sel_content; // content, content_type, (content_id)
bool sel_url; // url
bool sel_type; // type (dir, file, none)
bool sel_default_item; // default_item
bool sel_auth; // auth, auth_path
bool where_id; //
bool where_parent_id; //
bool where_type;
bool where_auth;
long id; // if where_id is true
long parent_id; // if where_parent_id is true
Item::Type type;
Item::Auth auth;
bool auth_equal; // if true means auth should be equal
bool sort_asc;
void SetAllSel(bool sel)
{
sel_parent_id = sel;
sel_user_id = sel;
sel_group_id = sel;
sel_guest_name = sel;
sel_privileges = sel;
sel_date = sel;
sel_subject = sel;
sel_content = sel;
sel_url = sel;
sel_type = sel;
sel_default_item= sel;
sel_auth = sel;
}
void SetAllWhere(bool where_)
{
where_id = where_;
where_parent_id = where_;
where_type = where_;
where_auth = where_;
}
void SetAll(bool sel, bool where_)
{
SetAllSel(sel);
SetAllWhere(where_);
}
void WhereId(long id_) { where_id = true; id = id_; }
void WhereParentId(long parent_id_) { where_parent_id = true; parent_id = parent_id_; }
void WhereType(Item::Type type_) { where_type = true; type = type_; }
void WhereAuth(Item::Auth st,
bool equal = true) { where_auth = true; auth = st; auth_equal = equal; }
ItemQuery()
{
sort_asc = true;
auth_equal = true;
SetAll(true, false);
id = -1;
parent_id = -1;
type = Item::none;
auth = Item::auth_none;
}
};
void GetItems(std::vector<Item> & item_table, const ItemQuery & item_query);
void GetItems(std::vector<long> & item_table, const ItemQuery & item_query);
// !! pobiera tylko jeden item (cos wymyslec innego z nazwa albo argumentem)
void GetItem(std::vector<Item> & item_table, long id);
bool GetPriv(Item & item, long id);
Error EditPrivById(Item & item, long id);
Error EditParentUrlById(Item & item, long id);
Error EditAuthById(Item & item, long id);
Error DelDirById(long id);
Error EditSubjectById(Item & item, long id);
bool DelItem(const Item & item);
void GetDirs(DirContainer & dir_table);
void GetUsers(UGContainer<User> & user_table);
void GetGroups(UGContainer<Group> & group_table);
// !! nowy interfejs
long Size(long parent_id, Item::Type type = Item::none);
Error GetItemById(long item_id, Item & item);
Error GetItem(long parent_id, const std::string & url, Item & item);
Error EditDefaultItem(long id, long new_default_item);
long GetItemId(long parent_id, const std::string & url, Item::Type type);
long GetFileId(long parent_id, const std::string & url);
long GetDirId(long parent_id, const std::string & url);
static tm ConvertTime(const char * str);
static const char * ConvertTime(const tm & t);
PGconn * GetPGconn();
virtual void Connect();
Error AddThread(Thread & thread);
Error GetThreadByDirId(long dir_id, Thread & thread);
Error GetThreads(long parent_id, std::vector<Thread> & thread_tab);
Error EditThreadAddItem(long dir_id, long item_id);
Error EditThreadRemoveItem(long dir_id);
Error RemoveThread(long dir_id);
Error GetTicketByDirId(long dir_id, Ticket & ticket);
Error GetTickets(long parent_id, std::vector<Ticket> & ticket_tab);
//bool IsTicket(long dir_id);
Error AddTicket(Ticket & ticket);
Error EditTicketById(Ticket & ticket);
Error EditTicketRemoveItem(long item_id);
Error RemoveTicket(long dir_id);
protected:
PGconn * pg_conn;
std::string db_database, db_user, db_pass;
bool close_at_end;
void SetDbParameters();
void Close();
void AssertConnection();
std::string Escape(const std::string & s);
std::string Escape(const char * s);
PGresult * AssertQuery(const std::string & q);
void AssertResultStatus(PGresult * r, ExecStatusType t);
static int AssertColumn(PGresult * r, const char * column_name);
static const char * AssertValue(PGresult * r, int row, int col);
void ClearResult(PGresult * r);
long AssertCurrval(const char * table);
bool AddItemCreateUrlSubject(Item & item);
Error AddItemIntoContent(Item & item);
Error AddItemIntoItem(Item & item);
Error EditItemInItem(Item & item, bool with_url);
Error EditItemInContent(Item & item);
Error EditItemGetId(Item & item);
Error EditItemGetContentId(Item & item);
void CheckAllUrlSubjectModifyItem(Item & item);
PGresult * GetItemsQuery(const ItemQuery & iq, bool skip_other_sel = false);
bool DelItemDelItem(const Item & item);
void DelItemDelContent(const Item & item);
Error DelItemCountContents(const Item & item, long & contents);
struct ItemColumns
{
int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id,
content_id, default_item, subject, content, content_type, guest_name, auth, auth_path, modification_user_id;
void SetColumns(PGresult * r);
void SetItem(PGresult * r, long row, Item & item);
};
struct TicketColumns
{
int id, dir_id, parent_id, type, status, priority, category, expected, progress, item_id;
void SetColumns(PGresult * r);
void SetTicket(PGresult * r, long row, Ticket & ticket);
};
}; // class Db
#endif

View File

@@ -1,97 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "db.h"
void Db::ItemColumns::SetColumns(PGresult * r)
{
// PQfnumber returns -1 if there is no such a column
id = PQfnumber(r, "id");
user_id = PQfnumber(r, "user_id");
group_id = PQfnumber(r, "group_id");
privileges = PQfnumber(r, "privileges");
date_creation = PQfnumber(r, "date_creation");
date_modification = PQfnumber(r, "date_modification");
url = PQfnumber(r, "url");
type = PQfnumber(r, "type");
parent_id = PQfnumber(r, "parent_id");
content_id = PQfnumber(r, "content_id");
default_item = PQfnumber(r, "default_item");
subject = PQfnumber(r, "subject");
content = PQfnumber(r, "content");
content_type = PQfnumber(r, "content_type");
guest_name = PQfnumber(r, "guest_name");
auth = PQfnumber(r, "auth");
auth_path = PQfnumber(r, "auth_path");
modification_user_id = PQfnumber(r, "modification_user_id");
}
void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item)
{
if( id != -1 ) item.id = atol( Db::AssertValue(r, row, id) );
if( user_id != -1 ) item.user_id = atol( Db::AssertValue(r, row, user_id) );
if( group_id != -1 ) item.group_id = atol( Db::AssertValue(r, row, group_id) );
if( privileges != -1 ) item.privileges = atoi( Db::AssertValue(r, row, privileges) );
if( date_creation != -1 ) item.date_creation = ConvertTime( Db::AssertValue(r, row, date_creation) );
if( date_modification != -1 ) item.date_modification = ConvertTime( Db::AssertValue(r, row, date_modification) );
if( url != -1 ) item.url = Db::AssertValue(r, row, url);
if( type != -1 ) item.type = static_cast<Item::Type>( atoi(Db::AssertValue(r, row, type)) );
if( parent_id != -1 ) item.parent_id = atol( Db::AssertValue(r, row, parent_id) );
if( content_id != -1 ) item.content_id = atol( Db::AssertValue(r, row, content_id) );
if( default_item != -1 ) item.default_item = atol( Db::AssertValue(r, row, default_item) );
if( subject != -1 ) item.subject = Db::AssertValue(r, row, subject);
if( content != -1 ) item.content = Db::AssertValue(r, row, content);
if( content_type != -1 ) item.content_type = static_cast<Item::ContentType>( atoi(Db::AssertValue(r, row, content_type)) );
if( guest_name != -1 ) item.guest_name = Db::AssertValue(r, row, guest_name);
if( auth != -1 ) item.auth = static_cast<Item::Auth>( atoi(Db::AssertValue(r, row, auth)) );
if( auth_path != -1 ) item.auth_path = Db::AssertValue(r, row, auth_path);
if( modification_user_id != -1 ) item.modification_user_id = atol( Db::AssertValue(r, row, modification_user_id) );
}
void Db::TicketColumns::SetColumns(PGresult * r)
{
// PQfnumber returns -1 if there is no such a column
id = PQfnumber(r, "id");
dir_id = PQfnumber(r, "dir_id");
parent_id = PQfnumber(r, "parent_id");
type = PQfnumber(r, "type");
status = PQfnumber(r, "status");
priority = PQfnumber(r, "priority");
category = PQfnumber(r, "category");
expected = PQfnumber(r, "expected");
progress = PQfnumber(r, "progress");
item_id = PQfnumber(r, "item_id");
}
void Db::TicketColumns::SetTicket(PGresult * r, long row, Ticket & ticket)
{
if( id != -1 ) ticket.id = atol( Db::AssertValue(r, row, id) );
if( dir_id != -1 ) ticket.dir_id = atol( Db::AssertValue(r, row, dir_id) );
if( parent_id != -1 ) ticket.parent_id = atol( Db::AssertValue(r, row, parent_id) );
if( type != -1 ) ticket.type = atoi( Db::AssertValue(r, row, type) );
if( status != -1 ) ticket.status = atoi( Db::AssertValue(r, row, status) );
if( priority != -1 ) ticket.priority = atoi( Db::AssertValue(r, row, priority) );
if( category != -1 ) ticket.category = atoi( Db::AssertValue(r, row, category) );
if( expected != -1 ) ticket.expected = atoi( Db::AssertValue(r, row, expected) );
if( progress != -1 ) ticket.progress = atoi( Db::AssertValue(r, row, progress) );
if( item_id != -1 ) ticket.item_id = atol( Db::AssertValue(r, row, item_id) );
}

View File

@@ -11,13 +11,15 @@
#include "log.h"
std::string DirContainer::dir_etc = "etc";
std::wstring DirContainer::dir_etc = L"etc";
std::wstring DirContainer::dir_var = L"var";
DirContainer::DirContainer()
{
is_root = false;
is_etc = false;
is_var = false;
}
@@ -40,6 +42,15 @@ return etc_iter;
}
DirContainer::Iterator DirContainer::GetVar()
{
if( !is_var )
return table.end();
return var_iter;
}
DirContainer::Iterator DirContainer::Begin()
{
return table.begin();
@@ -54,7 +65,7 @@ DirContainer::Iterator DirContainer::End()
DirContainer::SizeType DirContainer::Size()
{
return table.size();
return table.size(); // !! warning: it has O(n)
}
bool DirContainer::Empty()
@@ -63,25 +74,37 @@ bool DirContainer::Empty()
}
bool DirContainer::IsNameOfSpecialFolder(const std::wstring & name)
{
return name == dir_etc || name == dir_var;
}
// looking for '/etc'
// 'root' is found beforehand
// CheckSpecialFolder() may not find everything (when the first is a special folder and then the root)
void DirContainer::FindSpecialFolders()
{
is_etc = false;
is_var = false;
if( !is_root )
return;
DirContainer::ParentIterator i = FindFirstParent(root_iter->id);
DirContainer::ParentIterator i = FindFirstChild(root_iter->id);
for( ; i!=ParentEnd() ; i = NextParent(i) )
for( ; i!=ParentEnd() ; i = NextChild(i) )
{
if( i->second->url == dir_etc )
{
is_etc = true;
etc_iter = i->second;
break;
}
else
if( i->second->url == dir_var )
{
is_var = true;
var_iter = i->second;
}
}
}
@@ -103,8 +126,16 @@ void DirContainer::CheckSpecialFolder(const Item & item, Iterator iter)
{
is_etc = true;
etc_iter = iter;
log << log1 << "DirCont: added special folder: /etc" << logend;
log << log2 << "DirCont: added special folder: /etc" << logend;
}
if( item.parent_id==root_iter->id && item.url==dir_var )
{
is_var = true;
var_iter = iter;
log << log2 << "DirCont: added special folder: /var" << logend;
}
}
@@ -141,10 +172,10 @@ bool DirContainer::ChangeParent(long dir_id, long new_parent_id)
if( i->parent_id == new_parent_id )
return true; // nothing to do
ParentIterator p = FindFirstParent(i->parent_id);
ParentIterator p = FindFirstChild(i->parent_id);
bool found = false;
for( ; p != table_parent.end() ; p = NextParent(p) )
for( ; p != table_parent.end() ; p = NextChild(p) )
{
if( p->second->id == dir_id )
{
@@ -157,7 +188,7 @@ bool DirContainer::ChangeParent(long dir_id, long new_parent_id)
found = true;
if( i->url == "etc" ) // !! in the future can be more special folders
if( IsNameOfSpecialFolder(i->url) )
FindSpecialFolders();
break; // that iterator (p) is only one
@@ -220,7 +251,7 @@ bool DirContainer::ParentEmpty()
}
DirContainer::ParentIterator DirContainer::FindFirstParent(long parent)
DirContainer::ParentIterator DirContainer::FindFirstChild(long parent)
{
ParentIterator i = table_parent.lower_bound(parent);
@@ -231,7 +262,7 @@ return i;
}
DirContainer::ParentIterator DirContainer::NextParent(ParentIterator i)
DirContainer::ParentIterator DirContainer::NextChild(ParentIterator i)
{
if( i == table_parent.end() )
return table_parent.end();

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucoredircontainer
#define headerfilecmslucoredircontainer
#ifndef headerfile_winix_core_dircontainer
#define headerfile_winix_core_dircontainer
#include <list>
#include <map>
@@ -34,6 +34,7 @@ public:
Iterator GetRoot();
Iterator GetEtc();
Iterator GetVar();
Iterator Begin();
Iterator End();
@@ -51,9 +52,10 @@ public:
ParentIterator ParentEnd();
ParentSizeType ParentSize();
bool ParentEmpty();
ParentIterator FindFirstParent(long parent);
ParentIterator NextParent(ParentIterator pi);
ParentIterator FindFirstChild(long parent);
ParentIterator NextChild(ParentIterator pi);
bool IsNameOfSpecialFolder(const std::wstring & name);
void FindSpecialFolders();
private:
@@ -75,12 +77,18 @@ private:
// etc
Iterator etc_iter;
// true if there is a var dir in the table
bool is_var;
// var
Iterator var_iter;
// indexes
TableId table_id;
TableParent table_parent;
// names of folders
static std::string dir_etc;
static std::wstring dir_etc, dir_var;
};

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -13,21 +13,28 @@
void Dirs::SetDb(Db * pdb)
{
db = pdb;
}
void Dirs::SetRequest(Request * prequest)
void Dirs::SetCur(Cur * pcur)
{
request = prequest;
cur = pcur;
}
void Dirs::SetNotify(Notify * pnotify)
{
notify = pnotify;
}
void Dirs::Clear()
{
dir_table.Clear();
dir_tab.Clear();
}
@@ -40,9 +47,9 @@ bool Dirs::HasReadExecAccessForRoot(const Item & item)
void Dirs::CheckRootDir()
{
DirContainer::Iterator i = dir_table.GetRoot();
DirContainer::Iterator i = dir_tab.GetRoot();
if( i != dir_table.End() )
if( i != dir_tab.End() )
{
if( !HasReadExecAccessForRoot(*i) )
{
@@ -64,13 +71,12 @@ void Dirs::CheckRootDir()
root.user_id = -1;
root.group_id = -1;
root.privileges = 0755;
root.default_item = -1;
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
// !! zrobic jakis wyjatek do wprowadzania roota?
if( db->AddItem(root) == WINIX_ERR_OK )
{
dir_table.PushBack(root);
dir_tab.PushBack(root);
}
}
@@ -81,13 +87,13 @@ void Dirs::ReadDirs()
{
Clear();
db->GetDirs(dir_table);
db->GetDirs(dir_tab);
CheckRootDir();
dir_table.FindSpecialFolders();
dir_tab.FindSpecialFolders();
}
bool Dirs::ExtractName(const char * & s, std::string & name)
bool Dirs::ExtractName(const wchar_t * & s, std::wstring & name)
{
name.clear();
@@ -106,9 +112,9 @@ return !name.empty();
bool Dirs::IsDir(long id)
{
DirContainer::Iterator i = dir_table.FindId(id);
DirContainer::Iterator i = dir_tab.FindId(id);
if( i == dir_table.End() )
if( i == dir_tab.End() )
return false;
return true;
@@ -116,38 +122,39 @@ return true;
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_table)
// !! dac clearowanie childs_tab
// !! ewentualnie mozna dodac trzeci domyslny parametr bool clear_tab = true
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_tab)
{
if( parent != -1 && !IsDir(parent) )
return false;
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent);
for( ; i != dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
childs_table.push_back( &(*i->second) );
for( ; i != dir_tab.ParentEnd() ; i = dir_tab.NextChild(i) )
childs_tab.push_back( &(*i->second) );
return true;
}
DirContainer::ParentIterator Dirs::FindFirstParent(long parent_id)
DirContainer::ParentIterator Dirs::FindFirstChild(long parent_id)
{
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent_id);
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent_id);
return i;
}
DirContainer::ParentIterator Dirs::NextParent(DirContainer::ParentIterator i)
DirContainer::ParentIterator Dirs::NextChild(DirContainer::ParentIterator i)
{
return dir_table.NextParent(i);
return dir_tab.NextChild(i);
}
DirContainer::ParentIterator Dirs::ParentEnd()
{
return dir_table.ParentEnd();
return dir_tab.ParentEnd();
}
@@ -155,36 +162,68 @@ DirContainer::ParentIterator Dirs::ParentEnd()
// albo tutaj stringa nie czyscic?
// O(m * log n) (m- how many parts are in 'id')
// path with a slash at the end
bool Dirs::MakePath(long id, std::string & path)
bool Dirs::MakePath(long id, std::wstring & path, bool clear_path)
{
DirContainer::Iterator i;
path = '/';
if( clear_path )
path.clear();
temp_path = '/';
while( true )
{
i = dir_table.FindId(id);
i = dir_tab.FindId(id);
if( i == dir_table.End() ||
if( i == dir_tab.End() ||
i->parent_id == id ) // means a loop (something wrong in the db)
{
// we don't change path if there is no such a directory
return false;
}
if( i->parent_id == -1 )
{
path += temp_path;
return true;
}
id = i->parent_id;
path.insert(0, i->url);
path.insert(path.begin(), '/');
temp_path.insert(0, i->url);
temp_path.insert(temp_path.begin(), '/');
}
}
size_t Dirs::DirLevel(long id)
{
DirContainer::Iterator i;
size_t level = 0;
while( true )
{
i = dir_tab.FindId(id);
if( i == dir_tab.End() ||
i->parent_id == id ) // means a loop (something wrong in the db)
{
// we don't change path if there is no such a directory
return level;
}
if( i->parent_id == -1 )
return level;
id = i->parent_id;
level += 1;
}
}
bool Dirs::ChangeParent(long dir_id, long new_parent_id)
{
return dir_table.ChangeParent(dir_id, new_parent_id);
return dir_tab.ChangeParent(dir_id, new_parent_id);
}
@@ -198,9 +237,9 @@ DirContainer::Iterator i;
while( true )
{
i = dir_table.FindId(dir_id);
i = dir_tab.FindId(dir_id);
if( i==dir_table.End() || i->parent_id==-1 )
if( i==dir_tab.End() || i->parent_id==-1 )
return false;
if( i->parent_id == parent_id )
@@ -213,11 +252,38 @@ DirContainer::Iterator i;
bool Dirs::CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab)
{
DirContainer::Iterator i;
out_dir_tab.clear();
do
{
i = dir_tab.FindId(dir_id);
if( i == dir_tab.End() )
return false;
if( out_dir_tab.empty() )
out_dir_tab.insert(out_dir_tab.end(), &(*i)); // !! I am not sure whether begin() can be used on an empty container
else
out_dir_tab.insert(out_dir_tab.begin(), &(*i));
dir_id = i->parent_id;
}
while( dir_id != -1 );
return true;
}
Item * Dirs::GetRootDir()
{
DirContainer::Iterator root = dir_table.GetRoot();
DirContainer::Iterator root = dir_tab.GetRoot();
if( root == dir_table.End() )
if( root == dir_tab.End() )
return 0;
return &(*root);
@@ -226,20 +292,31 @@ return &(*root);
Item * Dirs::GetEtcDir()
{
DirContainer::Iterator etc = dir_table.GetEtc();
DirContainer::Iterator etc = dir_tab.GetEtc();
if( etc == dir_table.End() )
if( etc == dir_tab.End() )
return 0;
return &(*etc);
}
Item * Dirs::GetDir(const std::string & name, long parent)
Item * Dirs::GetVarDir()
{
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
DirContainer::Iterator etc = dir_tab.GetVar();
for( ; i!=dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
if( etc == dir_tab.End() )
return 0;
return &(*etc);
}
Item * Dirs::GetDir(const std::wstring & name, long parent)
{
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent);
for( ; i!=dir_tab.ParentEnd() ; i = dir_tab.NextChild(i) )
if( i->second->url == name )
return &(*i->second);
@@ -248,18 +325,18 @@ return 0;
Item * Dirs::GetDir(const std::string & path)
Item * Dirs::GetDir(const std::wstring & path)
{
DirContainer::Iterator root = dir_table.GetRoot();
DirContainer::Iterator root = dir_tab.GetRoot();
if( root == dir_table.End() )
if( root == dir_tab.End() )
// ops, we do not have a root dir
return 0;
Item * pitem = &(*root);
std::string name;
const char * s = path.c_str();
std::wstring name; // !! dodac jako skladowa klasy
const wchar_t * s = path.c_str();
while( ExtractName(s, name) )
{
@@ -269,16 +346,15 @@ Item * Dirs::GetDir(const std::string & path)
return 0;
}
return pitem;
}
Item * Dirs::GetDir(long id)
{
DirContainer::Iterator i = dir_table.FindId(id);
DirContainer::Iterator i = dir_tab.FindId(id);
if( i == dir_table.End() )
if( i == dir_tab.End() )
return 0;
return &(*i);
@@ -289,13 +365,13 @@ return &(*i);
Item * Dirs::AddDir(const Item & item)
{
return &(*dir_table.PushBack(item));
return &(*dir_tab.PushBack(item));
}
size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, std::string & dir)
size_t Dirs::AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir)
{
size_t i = 0;
size_t old_i;
@@ -341,7 +417,7 @@ size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, st
2 - the path is empty
3 - there is not such a directory
*/
int Dirs::AnalyzePath(const std::string & path, long & dir_id, std::string & dir, std::string & file)
int Dirs::AnalyzePath(const std::wstring & path, long & dir_id, std::wstring & dir, std::wstring & file)
{
Item * pdir = GetRootDir();
dir = '/';
@@ -374,10 +450,139 @@ return 0;
void Dirs::SplitPath(const std::string & path, std::string & dir, std::string & file)
// current_dir_tab can be the same container as out_dir_tab
void Dirs::CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out)
{
std::string::size_type i;
if( &in != &out )
{
out.resize(in.size());
for(size_t i=0 ; i<in.size() ; ++i)
out[i] = in[i];
}
}
size_t Dirs::AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to)
{
if( dir_tab.empty() )
return 0;
size_t i = 0;
size_t old_i;
while( true )
{
// skipping slashes
for( ; i<link_to.size() && link_to[i] == '/' ; ++i);
if( i == link_to.size() )
return i; // end of the path
// creating a name
old_i = i;
analyze_temp.clear();
for( ; i<link_to.size() && link_to[i] != '/' ; ++i)
analyze_temp += link_to[i];
Item * pdir = GetDir(analyze_temp, dir_tab.back()->id);
if( !pdir )
return old_i; // analyze_temp is not a directory
dir_tab.push_back(pdir);
}
}
int Dirs::FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item)
{
size_t i = AnalyzeDir(dir_tab, link_to);
if( i < link_to.size() )
{
// checking if at least one slash has left
for(size_t a=i ; a < link_to.size() ; ++a)
if( link_to[a] == '/' )
return 2; // there is not such a directory
// the rest of the path is a file name
out_item = link_to.c_str() + i;
return 1;
}
return 0;
}
/*
return codes:
ok:
0 - the link_to is a path to a directory (out_item skipped, out_dir_tab will not be empty)
1 - the link_to is a path to a file (out_item is used, out_dir_tab will not be empty)
error:
2 - incorrect link_to
3 - there is not a root dir
4 - current_dir_tab was empty
current_dir_tab can be the same container as out_dir_tab
link_to can be a relative path (without the first slash)
*/
int Dirs::FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, std::wstring & out_item)
{
temp_link_to = link_to; // link_to can be from the out_item and would be cleared next
out_item.clear();
if( current_dir_tab.empty() )
return 4;
if( temp_link_to.empty() )
{
CopyDirTab(current_dir_tab, out_dir_tab);
return 0;
}
if( temp_link_to[0] == '/' )
{
// temp_link_to is an absolute path
Item * pdir = GetRootDir();
if( !pdir )
return 3;
out_dir_tab.clear();
out_dir_tab.push_back(pdir);
}
else
{
// temp_link_to is a relative path
CopyDirTab(current_dir_tab, out_dir_tab);
}
return FollowLink(out_dir_tab, temp_link_to, out_item);
}
void Dirs::SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file)
{
std::wstring::size_type i;
dir.clear();
file.clear();
@@ -405,12 +610,15 @@ void Dirs::SplitPath(const std::string & path, std::string & dir, std::string &
// !! dodac kasowanie z bazy
bool Dirs::DelDir(long dir_id)
{
return dir_table.DelById(dir_id);
return dir_tab.DelById(dir_id);
}
Error Dirs::AddDirectory(Item & item, bool add_to_dir_table)
Error Dirs::AddDirectory(Item & item, bool add_to_dir_tab, Item ** pdir, int notify_code)
{
if( pdir )
*pdir = 0;
if( item.type != Item::dir )
return WINIX_ERR_DIR_EXPECTED;
@@ -418,10 +626,16 @@ Error Dirs::AddDirectory(Item & item, bool add_to_dir_table)
if( status == WINIX_ERR_OK )
{
Item * pdir = AddDir(item);
Item * d = AddDir(item);
if( add_to_dir_table && request->dir_table.back()->id == item.parent_id )
request->dir_table.push_back(pdir);
if( add_to_dir_tab && !cur->request->dir_tab.empty() && cur->request->dir_tab.back()->id == item.parent_id )
cur->request->dir_tab.push_back(d);
if( pdir )
*pdir = d;
if( notify_code )
notify->ItemChanged(notify_code, item);
}
return status;
@@ -429,5 +643,42 @@ return status;
Item * Dirs::CreateVarDir()
{
Item * var = GetVarDir();
if( var )
return var;
Item v;
Item * root = GetRootDir();
if( root )
{
v.parent_id = root->id;
v.user_id = -1;
v.group_id = -1;
v.privileges = 0755;
v.subject = L"var";
v.url = L"var";
v.type = Item::dir;
AddDirectory(v, false, &var);
}
return var;
}
// printing first and last slash
void Dirs::LogDir(const std::vector<Item*> & dir_tab)
{
log << '/';
// skipping the first (root) directory
for(size_t i=1 ; i<dir_tab.size() ; ++i)
log << dir_tab[i]->url << '/';
}

View File

@@ -2,13 +2,13 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoredirs
#define headerfilecmslucoredirs
#ifndef headerfile_winix_core_dirs
#define headerfile_winix_core_dirs
#include <vector>
@@ -17,8 +17,9 @@
#include "item.h"
#include "dircontainer.h"
#include "db.h"
#include "db/db.h"
#include "request.h"
#include "notify/notify.h"
// we do not support '..' in a path (for simplicity and security reasons)
@@ -31,51 +32,75 @@ public:
void Clear();
void ReadDirs();
void SetRequest(Request * prequest);
void SetCur(Cur * pcur);
void SetDb(Db * pdb);
void SetNotify(Notify * pnotify);
// these methods return false if there is no such a dir
bool IsDir(long dir_id);
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_table);
bool MakePath(long dir_id, std::string & path);
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()
bool MakePath(long dir_id, std::wstring & path, bool clear_path = true);
bool ChangeParent(long dir_id, long new_parent_id);
bool HasParent(long dir_id, long parent_id);
bool DelDir(long dir_id);
int AnalyzePath(const std::string & path, long & dir_id, std::string & dir, std::string & file);
static void SplitPath(const std::string & path, std::string & dir, std::string & file);
bool CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab);
DirContainer::ParentIterator FindFirstParent(long parent_id);
DirContainer::ParentIterator NextParent(DirContainer::ParentIterator i);
DirContainer::ParentIterator ParentEnd();
void LogDir(const std::vector<Item*> & dir_tab);
int AnalyzePath(const std::wstring & path, long & dir_id, std::wstring & dir, std::wstring & file);
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, std::wstring & out_item);
static void SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file);
DirContainer::ParentIterator FindFirstChild(long parent_id);
DirContainer::ParentIterator NextChild(DirContainer::ParentIterator i);
DirContainer::ParentIterator ParentEnd(); // !! pozostalo do zamiany na child
// these methods return null if there is no such a dir
// !! zmienic nazwy wskazujace ze operujemy tylko na lokalnej tablicy
Item * GetRootDir();
Item * GetEtcDir();
Item * GetDir(const std::string & name, long parent);
Item * GetDir(const std::string & path);
Item * GetVarDir();
Item * GetDir(const std::wstring & name, long parent);
Item * GetDir(const std::wstring & path);
Item * GetDir(long id);
Item * AddDir(const Item & item);
void CheckRootDir();
Item * CreateVarDir();
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir()
Error AddDirectory(Item & item, bool add_to_dir_table = false);
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
Error AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
// returns how many levels of directories there are
// "/" -> 0 (root dir)
// "/abc" -> 1
// "/abc/def" -> 2
size_t DirLevel(long id);
private:
Request * request;
Db * db;
Cur * cur;
Db * db;
Notify * notify;
DirContainer dir_table;
DirContainer dir_tab;
std::wstring temp_path;
std::wstring temp_link_to;
size_t AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, std::string & dir);
std::string analyze_temp;
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
size_t AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to);
std::wstring analyze_temp;
bool ExtractName(const char * & s, std::string & name);
void CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out);
int FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item);
bool ExtractName(const wchar_t * & s, std::wstring & name);
bool HasReadExecAccessForRoot(const Item & item);
};

View File

@@ -2,16 +2,16 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreerror
#define headerfilecmslucoreerror
#ifndef headerfile_winix_core_error
#define headerfile_winix_core_error
#include <iostream>
#include "log.h"
#define WINIX_ERR_OK 0
//#define WINIX_ERR_INCORRECT_PATH 1
@@ -55,7 +55,6 @@
#define WINIX_DIFFERENT_MOUNT_POINTS 29
#define WINIX_ERR_DB_FATAL_ERROR_DURING_CONNECTING 100
#define WINIX_ERR_DB_INCORRECT_QUERY 101
#define WINIX_ERR_DB_INCORRENT_RESULT_STATUS 102
@@ -70,6 +69,8 @@
//#define WINIX_ERR_UNKNOWN 1000
#define WINIX_NOTHING_TO_DO 109
typedef int Error;

View File

@@ -7,18 +7,23 @@
*
*/
#ifndef headerfilecmslucoregetparser
#define headerfilecmslucoregetparser
#ifndef headerfile_winix_core_getparser
#define headerfile_winix_core_getparser
#include "httpsimpleparser.h"
#include "requesttypes.h"
#include "misc.h"
#include "utf8.h"
#include "log.h"
class GetParser : public HttpSimpleParser
{
const char * get_string;
GetTable & get_table;
GetTab * get_tab;
std::wstring temp;
bool input_as_utf8;
protected:
@@ -33,22 +38,47 @@ protected:
virtual void Parameter(std::string &, std::string & value)
{
get_table.push_back(value);
log << log2 << "Get, value: \"" << value << "\"" << logend;
if( input_as_utf8 )
Ezc::UTF8ToWide(value, temp);
else
AssignString(value, temp);
get_tab->push_back(temp);
log << log2 << "Get, value: \"" << temp << "\"" << logend;
}
public:
GetParser(const char * get_string_, GetTable & get_table_) : get_string(get_string_), get_table(get_table_)
GetParser()
{
HttpSimpleParser::separator = '/';
HttpSimpleParser::read_name = false;
if( get_string && *get_string == separator ) // one '/' at the beginning
input_as_utf8 = false;
}
void UTF8(bool utf)
{
input_as_utf8 = utf;
}
// get_string_ can be null
void Parse(const char * get_string_, GetTab & get_tab_)
{
get_string = get_string_;
get_tab = &get_tab_;
if( get_string && *get_string == separator )
{
// skipping one '/' at the beginning
++get_string;
}
HttpSimpleParser::Parse();
}
};

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucoregroup
#define headerfilecmslucoregroup
#ifndef headerfile_winix_core_group
#define headerfile_winix_core_group
#include <string>
#include <vector>
@@ -18,7 +18,7 @@
struct Group
{
long id;
std::string name; // group name
std::wstring name; // group name
std::vector<long> members; // users id
Group()

View File

@@ -43,7 +43,7 @@ return &(*i);
}
Group * Groups::GetGroup(const std::string & name)
Group * Groups::GetGroup(const std::wstring & name)
{
Table::Iterator i = table.FindName(name);
@@ -54,7 +54,7 @@ return &(*i);
}
long Groups::GetGroupId(const std::string & name)
long Groups::GetGroupId(const std::wstring & name)
{
Group * pgroup = GetGroup(name);

View File

@@ -7,14 +7,14 @@
*
*/
#ifndef headerfilecmslucoregroups
#define headerfilecmslucoregroups
#ifndef headerfile_winix_core_groups
#define headerfile_winix_core_groups
#include <map>
#include "group.h"
#include "ugcontainer.h"
#include "db.h"
#include "db/db.h"
@@ -33,8 +33,8 @@ public:
void Clear();
void ReadGroups(Db * db);
Group * GetGroup(long group_id);
Group * GetGroup(const std::string & name);
long GetGroupId(const std::string & name);
Group * GetGroup(const std::wstring & name);
long GetGroupId(const std::wstring & name);
Iterator Begin();
Iterator End();
SizeType Size();

File diff suppressed because it is too large Load Diff

View File

@@ -2,27 +2,40 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorehtmlfilter
#define headerfilecmslucorehtmlfilter
#ifndef headerfile_winix_core_htmlfilter
#define headerfile_winix_core_htmlfilter
#include <string>
#include <map>
#include <vector>
#include <algorithm>
// max length of a name of a html tag (with terminating null)
#define WINIX_HTMLFILTER_ITEM_MAXLEN 30
#define WINIX_HTMLFILTER_ITEM_NAME_MAXLEN 30
// max length of a html lang attribute (e.g. "en", "pl")
#define WINIX_HTMLFILTER_ITEM_LANG_MAXLEN 10
#define WINIX_HTMLFILTER_ATTR_NAME_MAXLEN 40
#define WINIX_HTMLFILTER_ATTR_VALUE_MAXLEN 500
// depth of the html tree
#define WINIX_HTMLFILTER_STACK_MAXLEN 100
#define WINIX_HTMLFILTER_STACK_MAXLEN 100
// length of a buffer used for printing
// it should be at least: WINIX_HTMLFILTER_ITEM_MAXLEN+3
// it should be at least: WINIX_HTMLFILTER_ITEM_NAME_MAXLEN+3
#define WINIX_HTMLFILTER_BUFFER_MAXLEN 2048
@@ -48,23 +61,12 @@ class HTMLFilter
{
public:
// for checking orphans
enum Lang
{
lang_pl,
lang_cz,
lang_sk,
lang_none
};
enum OrphanMode
{
orphan_nbsp, // putting "&nbsp;" string
orphan_160space // putting 160 ascii code
};
HTMLFilter();
HTMLFilter(const HTMLFilter & f);
HTMLFilter & operator=(const HTMLFilter & f);
@@ -72,16 +74,22 @@ public:
// main methods used for filtering
void Filter(const char * in, std::string & out);
void Filter(const std::string & in, std::string & out);
void Filter(const wchar_t * in, std::wstring & out);
void Filter(const std::wstring & in, std::wstring & out);
// insert a white space into long lines
// only between html tags
// insert a white space into long words
// (only between html tags)
// skipped in such tags: script, pre, textarea
// break_after - after how many characters insert a space (0 - off)
void BreakLines(size_t break_after_);
void BreakWord(size_t break_after_);
// insert a new line character into long lines
// (only between html tags)
// skipped in such tags: script, pre, textarea
// wrap_line - after how many characters wrap a line (0 - off)
// lines are wrapped only in 'body' tag (useful for text in 'title' tag which is in 'head' section)
void WrapLine(size_t wrap_line_);
// trimming white characters (with new lines)
// at the beginning, at the end and in the middle of a string
@@ -98,10 +106,16 @@ public:
void InsertTabs(size_t tabsize);
// orphans are checked only in 'body' tag
void AssignOrphans(const wchar_t * lang_code, const std::vector<std::wstring> & otab);
void AssignOrphans(const std::wstring & lang_code, const std::vector<std::wstring> & otab);
void ClearOrphans();
// check 'orphans' for the specicic language
// if an orphan is detected then the non-break space ("&nbsp;" or ascii 160 code) will be put
// default disable (lang_none)
void CheckOrphans(Lang lang_, OrphanMode mode = orphan_nbsp);
void OrphansMode(OrphanMode mode = orphan_nbsp);
// skipping some unsafe tags
@@ -112,107 +126,171 @@ public:
protected:
// orphans for one language
struct Orphans
{
std::vector<std::wstring> tab;
size_t max_len;
};
// orphans for all languages
// map<language_code, Orphans>
typedef std::map<std::wstring, Orphans> OrphansTab;
OrphansTab orphans_tab;
struct Item
{
char name[WINIX_HTMLFILTER_ITEM_MAXLEN];
size_t name_len;
std::wstring name; // max size: WINIX_HTMLFILTER_ITEM_NAME_MAXLEN
enum Type
{
opening,
closing,
simple,
special,
opening, /* sample: <h1> */
closing, /* sample: </h1> */
simple, /* sample: <br/> */
special, /* sample: <!doctype> */
none
} type;
// is there a new line after this tag
bool new_line;
// current orphans table
// (will be propagated)
Orphans * porphans;
// this item or one from its parents is a 'body' html tag
// (will be propagated)
bool has_body_tag;
void Clear();
Item();
};
// only this method have direct access to the output string
// you can easily change the output from a std::string to something else
virtual void Put(const char * str, const char * end);
/*
virtual methods
*/
virtual void Init();
virtual void Uninit();
virtual bool IsOpeningTagMark();
virtual bool IsOpeningCommentaryTagMark();
virtual bool IsClosingTagMark();
virtual bool IsClosingXmlSimpleTagMark();
virtual bool IsValidCharForName(int c);
virtual bool IsValidCharForAttrName(int c);
virtual void CheckExceptions();
virtual bool SkipCommentaryTagIfExists();
virtual void Put(wchar_t c);
virtual void Put(const wchar_t * str);
virtual void Put(const wchar_t * str, const wchar_t * end);
virtual void Put(const std::wstring & str);
virtual void PutOpeningTagMark();
virtual void PutClosingTagMark();
virtual bool PutOpeningTag();
virtual void PutClosingTag(const wchar_t * tag);
virtual void PutNormalText(const wchar_t * str, const wchar_t * end);
virtual void ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white);
/*
others
*/
Item & GetItem(size_t i);
Item & LastItem();
int ToLower(int c);
bool IsNameEqual(const char * name1, const char * name2);
bool IsNameEqual(const char * name1, const char * name2, size_t len);
bool IsLastTag(const char * name);
bool IsTagSafe(const char * tag);
wchar_t ToLower(wchar_t c);
void ToLower(std::wstring & str);
int CheckOrphan(const char * str, const char * end, const char * orphan);
bool CheckOrphanTable(const char * str, const char * end, const char ** table, size_t o1, size_t o2);
bool CheckOrphanLangPl(const char * str, const char * end);
bool CheckOrphanLangCz(const char * str, const char * end);
bool CheckOrphan(const char * str, const char * end);
bool IsNameEqual(const wchar_t * name1, const wchar_t * name2);
bool IsNameEqual(const wchar_t * name1, const std::wstring & name2);
bool IsNameEqual(const std::wstring & name1, const wchar_t * name2);
bool IsNameEqual(const std::wstring & name1, const std::wstring & name2);
bool IsNameEqual(const wchar_t * name1, const wchar_t * name2, size_t len);
bool IsNameEqual(const wchar_t * name1, const std::wstring & name2, size_t len);
bool IsNameEqual(const std::wstring & name1, const wchar_t * name2, size_t len);
bool IsNameEqual(const std::wstring & name1, const std::wstring & name2, size_t len);
bool IsLastTag(const wchar_t * name);
bool IsTagSafe(const wchar_t * tag);
bool IsTagSafe(const std::wstring & tag);
int CheckOrphan(const wchar_t * str, const wchar_t * end, const std::wstring & orphan_str);
bool CheckOrphan(const wchar_t * str, const wchar_t * end, const std::vector<std::wstring> & orphans);
bool CheckOrphan(const wchar_t * str, const wchar_t * end);
bool IsWhite(int c);
void SkipWhite();
void SkipWhiteLines();
void SkipWhiteWithFirstNewLine();
void SkipWhiteLines(const wchar_t * & str, const wchar_t * end);
bool IsClosingTagForLastItem();
virtual bool IsOpeningTagMark();
virtual bool IsOpeningCommentaryTagMark();
size_t OpeningCommentaryTagMarkSize();
virtual bool IsClosingTagMark();
virtual bool IsClosingXmlSimpleTagMark();
bool SkipCommentaryTagIfExists();
const char * SkipItemCheckXmlSimple();
void SkipAndCheckClosingTag();
void PopStack();
bool PushStack();
virtual bool IsValidCharForName(int c);
void CheckNewLine();
virtual void CheckExceptions();
void CheckStackPrintRest();
void AddForgottenTags();
void CheckClosingTags();
virtual void ReadNormalTextSkipWhite(const char * & start, const char * & last_non_white);
void ReadNormalText();
bool PrintRest();
void PrintItem(const char * start, const char * end);
bool PrintOpeningItem();
void ReadItemName();
void ReadItemAttrName();
void ReadItemAttrValue(bool has_quote);
bool ReadItemAttr();
bool CheckItemAttr();
void PrinItemAttr();
void ReadItemClosing();
void ReadItemSpecial();
void ReadItemOpening();
bool ReadItem();
virtual void Init();
virtual void Deinit();
void ReadLoop();
void Read();
size_t PutNormalTextTrimFillBuffer(const char * & str, const char * & end);
size_t PutNormalTextFillBuffer(const char * & str, const char * & end);
virtual void PutNormalText(const char * str, const char * end);
virtual void PutNormalTextTrim(const char * str, const char * end);
void PutLastTagWithClosingTag();
virtual void PutOpeningTagMark();
virtual void PutClosingTagMark();
virtual void PutTagName(const char * name);
virtual void PutOpeningTag(const char * start, const char * end);
virtual void PutClosingTag(const char * tag);
size_t PutTabsToBuffer(size_t index, size_t len);
size_t PutNonBreakSpaceToBuffer(size_t index);
void PutTabs(size_t len);
void PutNewLine();
void CheckChar(wchar_t c);
const char * pchar;
void CheckLineWrap();
bool HasSemiloconAround(const wchar_t * str, const wchar_t * end);
void PutNormalNonWhite(const wchar_t * & str, const wchar_t * end);
void PutNormalWhite(const wchar_t * & str, const wchar_t * end);
void PutLastTagWithClosingTag();
void PutTabs(size_t len);
void PutNonBreakingSpace();
void PutNewLine();
void CalcOrphansMaxLen(Orphans & orphans);
const wchar_t * pchar;
Item empty;
Item * pstack; // stack pointer
size_t stack_len; // length of the stack
char * buffer; // buffer used when printing
std::string * out_string;
Item * pstack; // stack pointer
size_t stack_len; // length of the stack
wchar_t * buffer; // buffer used when printing
std::wstring * out_string;
bool last_new_line;
size_t break_after; // insert a space into long lines after break_after characters
bool trim_white; // trimming white characters
size_t break_after; // insert a space into long words after 'break_after' characters
size_t wrap_line; // insert a new line character into long lines
bool trim_white; // trimming white characters
size_t tab_size;
Lang lang; // current language for checking orphans
OrphanMode orphan_mode;
bool safe_mode; // skipping some unsafe tags
std::wstring attr_name;
std::wstring attr_value;
std::wstring attr_value_lower;
bool attr_has_value;
std::wstring lang_code_lower;
size_t line_len; //length of the current line (without first spaces which create the html tree)
bool safe_mode; // skipping some unsafe tags
Orphans orphans_temp;
};

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucorehttpsimpleparser
#define headerfilecmslucorehttpsimpleparser
#ifndef headerfile_winix_core_httpsimpleparser
#define headerfile_winix_core_httpsimpleparser
#include <string>
@@ -46,7 +46,7 @@ protected:
void TrimWhiteChars(std::string & s);
void CheckSpecialChar();
void Parse();
public:
@@ -60,12 +60,6 @@ public:
skip_white_chars = false;
recognize_special_chars = true;
}
void Parse();
};

72
core/item.cpp Executable file
View File

@@ -0,0 +1,72 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "item.h"
#include "misc.h"
Item::Item()
{
Clear();
}
void Item::SetDateToNow()
{
date_creation = Time(std::time(0));
date_modification = date_creation;
}
void Item::SetDateModifyToNow()
{
date_modification = Time(std::time(0));
}
void Item::Clear()
{
id = -1;
user_id = -1;
group_id = -1;
privileges = 0;
modification_user_id = -1;
guest_name.clear();
subject.clear();
content.clear();
modify_index = 0;
url.clear();
content_type = ct_formatted_text;
type = none;
parent_id = -1;
link_to.clear();
link_redirect = false;
content_id = -1;
ref = 1;
file_path.clear();
file_fs = -1;
file_type = WINIX_ITEM_FILETYPE_NONE;
has_thumb = false;
html_template.clear();
SetDateToNow();
}

View File

@@ -7,12 +7,18 @@
*
*/
#ifndef headerfilecmslucoreitem
#define headerfilecmslucoreitem
#ifndef headerfile_winix_core_item
#define headerfile_winix_core_item
#include <string>
#define WINIX_ITEM_FILETYPE_NONE 0
#define WINIX_ITEM_FILETYPE_IMAGE 1
#define WINIX_ITEM_FILETYPE_DOCUMENT 2
#define WINIX_ITEM_FILETYPE_UNKNOWN 3
struct Item
@@ -23,7 +29,7 @@ long parent_id;
long user_id;
long group_id;
std::string guest_name; // used as a user name when user_id is equal -1
std::wstring guest_name; // used as a user name when user_id is equal -1
long modification_user_id; // who has modified the item last (not taken into account when checking permissions)
@@ -32,10 +38,11 @@ int privileges;
tm date_creation;
tm date_modification;
std::string subject;
std::string content;
long content_id; // used by the database
std::string url;
std::wstring subject;
std::wstring content;
std::wstring url;
int modify_index;
enum ContentType
{
@@ -54,90 +61,44 @@ enum Type
{
dir = 0,
file = 1,
symlink = 2,
none = 1000 // !! pozbyc sie tego
none = 1000
};
Type type;
long default_item;
// used when type is symlink or to a directory too (function 'default')
std::wstring link_to;
int link_redirect;
// static file (if exists)
std::wstring file_path; // relative file path
int file_fs; // file system type where the file was saved
int file_type; // file type (none, image, doc, etc)
bool has_thumb;
// external static file authorized by winix
enum Auth
{
auth_none = 0, /* there is not an external file */
auth_image = 1, /* png, gif, jpg - only types available to render by a web browser*/
auth_document = 2, /* pdf doc xls txt */
auth_other = 3 /* other file */
};
Auth auth;
std::string auth_path; // path to a file (if auth!=auth_none)
// methods
Item()
{
Clear();
}
void SetDateToNow()
{
time_t t = std::time(0);
date_creation = *std::localtime( &t );
date_modification = date_creation;
}
void SetDateModifyToNow()
{
time_t t = std::time(0);
date_modification = *std::localtime( &t );
}
void Clear()
{
id = -1;
user_id = -1;
group_id = -1;
privileges = 0;
modification_user_id = -1;
guest_name.clear();
subject.clear();
content.clear();
url.clear();
content_type = ct_formatted_text;
type = none;
parent_id = -1;
default_item = -1;
content_id = -1;
auth = auth_none;
auth_path.clear();
SetDateToNow();
}
std::wstring html_template;
// methods
Item();
void SetDateToNow();
void SetDateModifyToNow();
void Clear();
private:
// used by the database
long content_id; // content id in 'content' table
int ref; // content references
friend class Db;
friend class DbItemColumns;
};

View File

@@ -10,7 +10,7 @@
#include "lastcontainer.h"
#include "log.h"
#include "misc.h"
LastItem::LastItem()
@@ -68,7 +68,7 @@ return last_tab.end();
void LastContainer::UserLogin(long user_id, const std::string & name, unsigned int ip, long session_id)
void LastContainer::UserLogin(long user_id, const std::wstring & name, unsigned int ip, long session_id)
{
LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
@@ -78,7 +78,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
return;
}
if( last_tab.size() >= LAST_TABLE_SIZE )
if( last_tab.size() >= WINIX_LASTCONTAINER_TABLE_SIZE ) // last_tab has O(n) complexity
last_tab.erase(last_tab.begin());
LastItem li;
@@ -87,9 +87,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
li.name = name;
li.ip = ip;
li.session_id = session_id;
time_t t = std::time(0);
li.start = *localtime(&t);
li.start = Time(std::time(0));
last_tab.insert(last_tab.end(), li);
@@ -105,11 +103,10 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
if( i != last_tab.end() )
{
time_t t = std::time(0);
i->end = *localtime(&t);
i->end = Time(std::time(0));
}
else
{
log << log1 << "LC: there is no such a user to log out" << logend;
log << log4 << "LC: there is no such a user to log out" << logend;
}
}

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucorelastcontainer
#define headerfilecmslucorelastcontainer
#ifndef headerfile_winix_core_lastcontainer
#define headerfile_winix_core_lastcontainer
#include <string>
#include <list>
@@ -18,7 +18,7 @@
// how many items we store in the 'last' function
#define LAST_TABLE_SIZE 100
#define WINIX_LASTCONTAINER_TABLE_SIZE 100
@@ -28,7 +28,7 @@ struct LastItem
// additional we store the whole string-name
// (you can delete a user from the database but we can still print the name)
std::string name;
std::wstring name;
// ip address
unsigned int ip;
@@ -62,7 +62,7 @@ public:
Iterator Begin();
Iterator End();
void UserLogin(long user_id, const std::string & name, unsigned int ip, long session_id);
void UserLogin(long user_id, const std::wstring & name, unsigned int ip, long session_id);
void UserLogout(long user_id, long session_id);

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucoreloadavg
#define headerfilecmslucoreloadavg
#ifndef headerfile_winix_core_loadavg
#define headerfile_winix_core_loadavg
#include <ctime>

View File

@@ -1,234 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "locale.h"
#include "log.h"
Locale::Locale()
{
loc_tab.resize(lang_unknown);
default_lang = lang_en;
current_lang = lang_en;
}
void Locale::AddLocale(Lang lang)
{
ConfParser::TableSingle::iterator i = loc_parser.table_single.begin();
for( ; i != loc_parser.table_single.end() ; ++i)
loc_tab[lang][i->first] = i->second;
}
void Locale::ReadFile(const char * dir, const char * dir_def, Lang lang, const char * file)
{
if( static_cast<size_t>(lang) >= loc_tab.size() )
{
// ops, something wrong
return;
}
loc_tab[lang].clear();
bool read = false;
if( dir_def && ReadFile(dir_def, lang, file) )
read = true;
if( dir && ReadFile(dir, lang, file) )
read = true;
if( !read )
log << log1 << "Locale: can't open locale's file: " << file << logend;
}
bool Locale::ReadFile(const char * dir, Lang lang, const char * file)
{
bool read = false;
file_name = dir;
file_name += '/';
file_name += file;
loc_parser.SplitSingle(true);
if( loc_parser.Parse(file_name) == ConfParser::ok )
{
read = true;
AddLocale(lang);
log << log3 << "Locale: read locale from: " << file_name << logend;
}
return read;
}
void Locale::Read(const char * dir, const char * dir_def)
{
ReadFile(dir, dir_def, lang_pl, "pl");
ReadFile(dir, dir_def, lang_en, "en");
}
void Locale::Read(const std::string & dir, const std::string & dir_def)
{
if( dir_def.empty() )
Read(dir.c_str());
else
Read(dir.c_str(), dir_def.c_str());
}
void Locale::SetLang(Lang lang)
{
current_lang = lang;
}
Locale::Lang Locale::GetLang()
{
return current_lang;
}
void Locale::SetLangDef(Lang lang)
{
default_lang = lang_en;
}
bool Locale::IsKey(const std::string & key) const
{
return IsKey(key, current_lang);
}
bool Locale::IsKey(const std::string & key, Lang lang) const
{
if( static_cast<size_t>(lang) >= loc_tab.size() )
{
// ops, something wrong
return false;
}
// looking in the lang language
ConfParser::TableSingle::const_iterator i = loc_tab[lang].find(key);
if( i != loc_tab[lang].end() )
return true;
if( lang == default_lang )
return false;
if( static_cast<size_t>(default_lang) >= loc_tab.size() )
{
// ops, something wrong
return false;
}
// looking in a default language
i = loc_tab[default_lang].find(key);
if( i != loc_tab[default_lang].end() )
return true;
// there is no such a key
return false;
}
const std::string & Locale::Get(const std::string & key) const
{
return Get(key, current_lang);
}
const std::string & Locale::Get(const std::string & key, Lang lang) const
{
if( static_cast<size_t>(lang) >= loc_tab.size() )
{
// ops, something wrong
return empty;
}
// looking in the lang language
ConfParser::TableSingle::const_iterator i = loc_tab[lang].find(key);
if( i != loc_tab[lang].end() )
return i->second;
if( lang == default_lang )
return empty;
if( static_cast<size_t>(default_lang) >= loc_tab.size() )
{
// ops, something wrong
return empty;
}
// looking in a default language
i = loc_tab[default_lang].find(key);
if( i != loc_tab[default_lang].end() )
return i->second;
// there is no such a key
return empty;
}
Locale::Lang Locale::StrToLang(const std::string & str)
{
if( str == "en" )
return lang_en;
else
if( str == "pl" )
return lang_pl;
return lang_unknown;
}
const char * Locale::LangToStr(Lang lang)
{
static char buffer[30];
switch(lang)
{
case lang_en:
sprintf(buffer, "en");
break;
case lang_pl:
sprintf(buffer, "pl");
break;
default:
sprintf(buffer, "unknown");
}
return buffer;
}
size_t Locale::Size()
{
return loc_tab.size();
}

View File

@@ -1,71 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorelocale
#define headerfilecmslucorelocale
#include "confparser.h"
#include <vector>
#include <string>
// !! locale nie powinny byc w templates?
class Locale
{
public:
enum Lang
{
lang_en = 0,
lang_pl,
lang_unknown // should be last
};
Locale();
void Read(const char * dir, const char * dir_def = 0);
void Read(const std::string & dir, const std::string & dir_def);
bool IsKey(const std::string & key) const;
bool IsKey(const std::string & key, Lang lang) const;
const std::string & Get(const std::string & key) const;
const std::string & Get(const std::string & key, Lang lang) const;
// default is english
void SetLang(Lang lang);
Lang GetLang();
// which language is used instead if there is no a key in an other language
// default: lang_en
void SetLangDef(Lang lang);
static Lang StrToLang(const std::string & str);
static const char * LangToStr(Lang lang);
size_t Size();
private:
void AddLocale(Lang lang);
void ReadFile(const char * dir, const char * dir_def, Lang lang, const char * file);
bool ReadFile(const char * dir, Lang lang, const char * file);
std::vector<ConfParser::TableSingle> loc_tab;
ConfParser loc_parser;
std::string file_name;
std::string empty;
Lang default_lang;
Lang current_lang;
};
#endif

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -10,38 +10,54 @@
#include "log.h"
#include <ctime>
#include <string.h>
#include "utf8.h"
Log::Log()
{
log_level = 3;
current_level = 4; // nothing to log (call Init() first)
item = 0;
item_save = 1;
log_level = 1;
current_level = 100; // nothing to log (call Init() first)
request = 0;
max_requests = 1;
lines = 0;
max_lines = 5000;
log_file_open = false;
}
void Log::Init(int log_l, const std::string & log_f, bool log_std, int log_request)
Log::~Log()
{
log_level = log_l;
log_file = log_f;
log_stdout = log_std;
item_save = log_request;
SaveLogAndClear();
}
OpenFile();
void Log::Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests)
{
log_level = log_level_;
log_file = log_file_;
log_stdout = log_std;
max_requests = log_max_requests;
save_each_line = save_each_line_;
// don't open the file here
// because it would be created with the root as an owner
}
void Log::OpenFile()
{
if( !log_file.empty() )
{
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
log_file_open = true;
}
}
void Log::PutDate(Manipulators m)
void Log::PutDate(LogManipulators m)
{
// logs are related to localtime
time_t t = std::time(0);
std::tm * loct = std::localtime(&t);
@@ -57,10 +73,22 @@ void Log::PutDate(Manipulators m)
}
Log & Log::operator<<(const void * s)
{
if( current_level > log_level )
return *this;
buffer << s;
return *this;
}
Log & Log::operator<<(const char * s)
{
if( current_level > log_level )
return *this;
if( !s )
return *this;
@@ -73,8 +101,10 @@ return *this;
Log & Log::operator<<(const std::string & s)
{
buffer << s;
if( current_level > log_level )
return *this;
buffer << s;
return *this;
}
@@ -82,23 +112,63 @@ Log & Log::operator<<(const std::string & s)
Log & Log::operator<<(const std::string * s)
{
buffer << *s;
if( current_level > log_level )
return *this;
buffer << *s;
return *this;
}
Log & Log::operator<<(const void * s)
Log & Log::operator<<(const wchar_t * s)
{
buffer << s;
if( current_level <= log_level )
{
if( s )
buffer << s;
}
return *this;
}
Log & Log::operator<<(const std::wstring & s)
{
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
Log & Log::operator<<(const std::wstring * s)
{
if( current_level <= log_level )
{
buffer << *s;
}
return *this;
}
Log & Log::operator<<(int s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@@ -107,7 +177,10 @@ Log & Log::operator<<(int s)
Log & Log::operator<<(long s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@@ -117,16 +190,32 @@ Log & Log::operator<<(long s)
Log & Log::operator<<(char s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
Log & Log::operator<<(wchar_t s)
{
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
Log & Log::operator<<(size_t s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@@ -135,39 +224,38 @@ Log & Log::operator<<(size_t s)
Log & Log::operator<<(double s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
Log & Log::operator<<(Manipulators m)
Log & Log::operator<<(LogManipulators m)
{
switch(m)
{
case logend:
buffer << '\n';
lines += 1;
break;
if( current_level <= log_level )
{
buffer << '\n';
lines += 1;
case logsavenow:
SaveLog();
buffer.str( "" );
item = 0;
lines = 0;
if( save_each_line )
SaveLogAndClear();
}
break;
case logsave:
item += 1;
SaveLogAndClear();
break;
if( item >= item_save || lines > 3000 )
{
SaveLog();
buffer.str( "" );
item = 0;
lines = 0;
}
case logendrequest:
if( ++request >= max_requests || lines > max_lines )
SaveLogAndClear();
break;
case log1:
@@ -181,12 +269,20 @@ Log & Log::operator<<(Manipulators m)
case log3:
current_level = 3;
break;
case log4:
current_level = 4;
break;
default:
break;
}
return *this;
}
void Log::SystemErr(int err)
{
(*this) << "errno: " << err;
@@ -198,23 +294,28 @@ void Log::SystemErr(int err)
}
void Log::SaveLogAndClear()
{
SaveLog();
buffer.Clear();
request = 0;
lines = 0;
}
void Log::SaveLog()
{
if( current_level > log_level )
return;
const std::string & source = buffer.str();
if( source.empty() )
if( buffer.Str().empty() )
return;
if( log_stdout )
std::cout << source;
Ezc::WideToUTF8(buffer.Str(), std::cout);
if( log_file.empty() )
return;
if( !file )
if( !log_file_open || !file )
{
file.close();
file.clear();
@@ -225,7 +326,8 @@ void Log::SaveLog()
return;
}
file << source << std::endl;
Ezc::WideToUTF8(buffer.Str(), file);
file.flush();
}

View File

@@ -2,67 +2,124 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorelog
#define headerfilecmslucorelog
#ifndef headerfile_winix_core_log
#define headerfile_winix_core_log
#include <sstream>
#include <fstream>
#include <iostream>
#include <string>
// !! dodac manipulator logsave, logi zostana zapisane pod koniec wykonywania jednego requesta (albo po kilku w zaleznosci od jakiejs opcji w konfigu)
// logsave zostanie wywolane w requestcontroller.cpp przy konczeniu wykonywania requesta
enum Manipulators { logsave, logsavenow, logend, log1, log2, log3 };
#include "textstream.h"
#include "logmanipulators.h"
class Log
{
std::ostringstream buffer;
int log_level, current_level;
int item, item_save;
std::string log_file;
bool log_stdout;
std::ofstream file;
int lines;
void OpenFile();
public:
Log();
void Init(int log_l, const std::string & log_f, bool log_std, int log_request);
void PutDate(Manipulators m);
Log & operator<<(const char * s);
Log();
~Log();
void Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests);
void PutDate(LogManipulators m);
Log & operator<<(const void * s);
Log & operator<<(const char * s);
Log & operator<<(const std::string * s);
Log & operator<<(const std::string & s);
Log & operator<<(const wchar_t * s);
Log & operator<<(const std::wstring * s);
Log & operator<<(const std::wstring & s);
Log & operator<<(int s);
Log & operator<<(long s);
Log & operator<<(char s);
Log & operator<<(wchar_t s);
Log & operator<<(size_t s);
Log & operator<<(double s);
Log & operator<<(Manipulators m);
void SystemErr(int err);
Log & operator<<(LogManipulators m);
template<class StringType>
void LogString(const StringType & value, size_t max_size);
void SystemErr(int err);
void SaveLog();
void SaveLogAndClear();
private:
// buffer for the log
TextStream<std::wstring> buffer;
// log lovel from the config file
int log_level;
// current level set by a modifier (e.g. log << log3)
int current_level;
// current request for logging
// starts from zero and incremented after logendrequest modifier
int request;
// how many request to save at once
int max_requests;
// file log
std::string log_file;
std::ofstream file;
// logging to stdout
bool log_stdout;
// how many lines there are in the buffer
int lines;
// is the config file already open
bool log_file_open;
// how many lines can be in the config buffer
// default: 5000
int max_lines;
// whether to save each line (for debug)
bool save_each_line;
void OpenFile();
};
template<class StringType>
void Log::LogString(const StringType & value, size_t max_size)
{
size_t min_size = value.size() < max_size ? value.size() : max_size;
if( current_level <= log_level )
{
for(size_t i=0 ; i<min_size ; ++i)
{
if( value[i] < 32 )
buffer << '.';
else
buffer << value[i];
}
}
}
extern Log log;
extern Log nlog;
// for convenience, we have to use only #include "log.h" in the winix
#include "slog.h"
#endif

48
core/logmanipulators.h Executable file
View File

@@ -0,0 +1,48 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_logmanipulators
#define headerfile_winix_core_logmanipulators
/*
log1 - the first level
log2
log3
log4 - the last level (debug level)
logend - the end of a line
logendrequest - end of a current request
logsave - current log buffer is saved and cleared
manipulators used by the session logger (SLog)
loginfo - normal info to a user
logerror - we are reporting an error
logwarning - we are reporting a warning
make sure that loginfo, logerror and logwarning have values less than 32 (space)
their are used as control codes in a string
*/
enum LogManipulators
{
log1,
log2,
log3,
log4,
logend,
logendrequest,
logsave,
loginfo,
logerror,
logwarning
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -2,75 +2,586 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoremisc
#define headerfilecmslucoremisc
#ifndef headerfile_winix_core_misc
#define headerfile_winix_core_misc
#include <string>
#include <sstream>
#include <ctime>
#include "item.h"
#include <cstdio>
#include "item.h"
void ToString(std::string & s, int value);
void ToString(std::string & s, long value);
int ChangeLocalChar(unsigned char c);
bool CorrectUrlChar(char c);
void CorrectUrlDots(std::string & url);
void CorrectUrlChars(std::string & url);
void CorrectUrlOnlyAllowedChar(std::string & url);
/*
conversions between text and numbers
*/
void HtmlEscape(std::ostringstream & out, const std::string & in);
void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in);
std::string HtmlEscape(const std::string & in);
std::string HtmlEscapeFormTxt(const std::string & in);
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
const char * DateToStr(int year, int month, int day);
const char * DateToStr(int year, int month, int day, int hour, int min, int sec);
const char * DateToStr(tm * ptm);
const char * DateToStr(time_t t);
const char * DateToStrWithoutHours(tm * ptm);
const char * DateToStrWithoutHours(time_t t);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
// if the buffer is too small it will be terminated at the beginning (empty string)
// and the function returns false
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10)
{
size_t i1, i2;
long rest;
if( buf_len == 0 )
return false;
i1 = i2 = 0;
if( base < 2 ) base = 2;
if( base > 16 ) base = 16;
do
{
rest = value % base;
value = value / base;
buffer[i2++] = (rest < 10) ? char(rest) + '0' : char(rest) - 10 + 'A';
}
while(value != 0 && i2 < buf_len);
if( i2 >= buf_len )
{
buffer[0] = 0; // ops, the buffer was too small
return false;
}
buffer[i2--] = 0;
for( ; i1 < i2 ; ++i1, --i2)
{
CharType temp = buffer[i1];
buffer[i1] = buffer[i2];
buffer[i2] = temp;
}
return true;
}
// if the buffer is too small it will be terminated at the beginning (empty string)
// and the function returns false
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10)
{
if( buf_len == 0 )
return false;
CharType * buf = buffer;
if( value < 0 )
{
buffer[0] = '-';
buf += 1;
buf_len -= 1;
value = -value;
}
bool res = Toa(static_cast<unsigned long>(value), buf, buf_len, base);
if( !res )
buffer[0] = 0;
return res;
}
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10)
{
return Toa(static_cast<unsigned long>(value), buffer, buf_len, base);
}
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10)
{
return Toa(static_cast<long>(value), buffer, buf_len, base);
}
// warning: it uses its own static buffer
// one buffer for both these functions
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
/*
conversions between ascii text and wide characters
(destination is always std::string or std::wstring)
characters are copied as they are without any locales checking
*/
void AssignString(const char * src, size_t len, std::wstring & dst, bool clear = true);
void AssignString(const char * src, std::wstring & dst, bool clear = true);
void AssignString(const std::string & src, std::wstring & dst, bool clear = true);
void AssignString(const wchar_t * src, size_t len, std::string & dst, bool clear = true);
void AssignString(const wchar_t * src, std::string & dst, bool clear = true);
void AssignString(const std::wstring & src, std::string & dst, bool clear = true);
void AssignString(const char * src, size_t len, std::string & dst, bool clear = true);
void AssignString(const char * src, std::string & dst, bool clear = true);
void AssignString(const std::string & src, std::string & dst, bool clear = true);
void AssignString(const wchar_t * src, size_t len, std::wstring & dst, bool clear = true);
void AssignString(const wchar_t * src, std::wstring & dst, bool clear = true);
void AssignString(const std::wstring & src, std::wstring & dst, bool clear = true);
bool CorrectUrlChar(wchar_t c);
void CorrectUrlDots(std::wstring & url);
void CorrectUrlChars(std::wstring & url);
void CorrectUrlOnlyAllowedChar(std::wstring & url);
const wchar_t * DateToStr(int year, int month, int day);
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec);
const wchar_t * DateToStr(const tm * ptm);
const wchar_t * DateToStr(const tm & rtm);
const wchar_t * DateToStr(time_t t);
const wchar_t * DateToStrWithoutHours(const tm * ptm);
const wchar_t * DateToStrWithoutHours(const tm & rtm);
const wchar_t * DateToStrWithoutHours(time_t t);
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec);
const char * DateToStrCookie(tm * ptm);
const char * DateToStrCookie(const tm * ptm);
const char * DateToStrCookie(const tm & rtm);
const char * DateToStrCookie(time_t t);
const char * IpToStr(unsigned int ip_);
const wchar_t * IpToStr(unsigned int ip_);
bool IsWhite(wchar_t s);
template<class StringType>
void TrimWhite(StringType & s)
{
typename StringType::size_type i;
if( s.empty() )
return;
// looking for white characters at the end
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
if( i==0 && IsWhite(s[i]) )
{
// the whole string has white characters
s.clear();
return;
}
// deleting white characters at the end
if( i != s.size() - 1 )
s.erase(i+1, StringType::npos);
// looking for white characters at the beginning
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}
template<class StringType>
void Trim(StringType & s, wchar_t c)
{
typename StringType::size_type i;
if( s.empty() )
return;
// looking for the 'c' characters at the end
for(i=s.size()-1 ; i>0 && s[i]==c ; --i);
if( i==0 && s[i]==c )
{
// the whole string has the 'c' characters
s.clear();
return;
}
// deleting 'c' characters at the end
if( i != s.size() - 1 )
s.erase(i+1, StringType::npos);
// looking for the 'c' characters at the beginning
for(i=0 ; i<s.size() && s[i]==c ; ++i);
// deleting the 'c' characters at the beginning
if( i != 0 )
s.erase(0, i);
}
wchar_t ToSmall(wchar_t c);
void ToSmall(std::wstring & s);
bool IsWhite(int s);
void TrimWhite(std::string & s);
void Trim(std::string & s, char c);
int ToSmall(int c);
void ToSmall(std::string & s);
const char * SkipWhite(const char * s);
const char * ToStr(int value);
const wchar_t * SkipWhite(const wchar_t * s);
bool IsSubString(const char * short_str, const char * long_str);
bool IsSubStringNoCase(const char * short_str, const char * long_str);
bool EqualNoCase(const char * str1, const char * str2);
bool ValidateEmail(const std::string & email);
bool IsFile(const char * file);
bool IsFile(const std::string & file);
bool CreateDir(const char * dir, int priv);
bool CreateDir(const std::string & dir, int priv);
bool CreateDirs(const char * base_dir, const char * dirs, int priv);
bool CreateDirs(const std::string & base_dir, const std::string & dirs, int priv);
template<class StringType1, class StringType2>
bool IsSubString(const StringType1 * short_str, const StringType2 * long_str)
{
while( *short_str && *long_str && wchar_t(*short_str) == wchar_t(*long_str) )
{
++short_str;
++long_str;
}
if( *short_str == 0 )
return true;
return false;
}
template<class StringType1, class StringType2>
bool IsSubString(const StringType1 & short_str, const StringType2 & long_str)
{
return IsSubString(short_str.c_str(), long_str.c_str());
}
template<class StringType1, class StringType2>
bool IsSubStringNoCase(const StringType1 * short_str, const StringType2 * long_str)
{
while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
{
++short_str;
++long_str;
}
if( *short_str == 0 )
return true;
return false;
}
template<class StringType1, class StringType2>
bool IsSubStringNoCase(const StringType1 & short_str, const StringType2 & long_str)
{
return IsSubStringNoCase(short_str.c_str(), long_str.c_str());
}
template<class StringType1, class StringType2>
bool Equal(const StringType1 * str1, const StringType2 * str2)
{
while( *str1 && *str2 && wchar_t(*str1) == wchar_t(*str2) )
{
++str1;
++str2;
}
if( *str1 == 0 && *str2 == 0 )
return true;
return false;
}
template<class StringType1, class StringType2>
bool Equal(const StringType1 & str1, const StringType2 & str2)
{
return Equal(str1.c_str(), str2.c_str());
}
template<class StringType1, class StringType2>
bool EqualNoCase(const StringType1 * str1, const StringType2 * str2)
{
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
{
++str1;
++str2;
}
if( *str1 == 0 && *str2 == 0 )
return true;
return false;
}
template<class StringType1, class StringType2>
bool EqualNoCase(const StringType1 & str1, const StringType2 & str2)
{
return EqualNoCase(str1.c_str(), str2.c_str());
}
template<class StringType>
void NoLastSlash(StringType & s)
{
if( s.empty() )
return;
size_t i = s.size();
for( ; i>0 && s[i-1]=='/' ; --i);
if( i < s.size() )
s.erase(i);
}
template<class StringType>
void NoFirstHttp(StringType & s)
{
if( s.empty() )
return;
const char http[] = "http://";
const char https[] = "https://";
if( IsSubStringNoCase(http, s.c_str()) )
{
s.erase(0, sizeof(http)/sizeof(char));
}
else
if( IsSubStringNoCase(https, s.c_str()) )
{
s.erase(0, sizeof(https)/sizeof(char));
}
}
/*
this method returns true if there are two dots meaning 'go up' somewhere in the path
for example such paths return true:
".."
"test/../path"
"test/where/../"
"test/where/.."
"../abc"
*/
template<class StringType>
bool PathHasUpDir(const StringType * str)
{
size_t i = 0;
while( str[i] )
{
if( str[i]=='.' && str[i+1]=='.' )
{
i += 2;
if( str[i]=='/' || str[i]==0 )
return true;
}
// skipping until to next slash
while( str[i] && str[i]!='/' )
i += 1;
// skipping the slash (or slashes)
while( str[i]=='/' )
i += 1;
}
return false;
}
template<class StringType>
bool PathHasUpDir(const StringType & str)
{
return PathHasUpDir(str.c_str());
}
/*
this method calculates how many directories there are in the given path
input:
str - path
last_is_dir - true if the last part of the path should be treated as a directory too
samples:
HowManyDirs("", false) -> 0
HowManyDirs("", true) -> 0
HowManyDirs("abc", false) -> 0
HowManyDirs("abc", true) -> 1
HowManyDirs("/abc/", true) -> 1
HowManyDirs("////", false) -> 0
HowManyDirs("////", true) -> 0
HowManyDirs("////abc", false) -> 0
HowManyDirs("////abc", true) -> 1
HowManyDirs("/var/static", false) -> 1
HowManyDirs("/var/static", true) -> 2
HowManyDirs("/var/static/", false) -> 2
HowManyDirs("/var/static/", true) -> 2
*/
template<class StringType>
size_t HowManyDirs(const StringType * str, bool is_last_dir = false)
{
size_t res = 0;
size_t i = 0;
// first slash (root dir) is not calculated
while( str[i]=='/' )
i += 1;
while( str[i] )
{
if( str[i]=='/' )
{
res += 1;
while( str[i]=='/' )
i += 1;
}
else
{
i += 1;
}
}
if( is_last_dir && i>0 && str[i-1]!='/' )
res += 1;
return res;
}
template<class StringType>
size_t HowManyDirs(const StringType & str, bool is_last_dir = false)
{
return HowManyDirs(str.c_str(), is_last_dir);
}
/*
this method skips some first directories from given path
samples:
SkipDirs("/var/test", 1) -> "test"
SkipDirs("/var/test/somewhere", 1) -> "test/somewhere"
SkipDirs("/var/test/somewhere", 2) -> "somewhere"
SkipDirs("/var/test/somewhere", 10) -> ""
*/
template<class StringType>
const StringType * SkipDirs(const StringType * str, size_t how_many_skip)
{
size_t i = 0;
size_t skipped = 0;
if( how_many_skip == 0 )
return str;
// first slash (root dir) is not calculated
while( str[i]=='/' )
i += 1;
while( str[i] )
{
if( str[i]=='/' )
{
skipped += 1;
while( str[i]=='/' )
i += 1;
if( skipped == how_many_skip )
return str+i;
}
else
{
i += 1;
}
}
return str + i;
}
bool ValidateEmail(const std::wstring & email);
bool IsFile(const wchar_t * file);
bool IsFile(const std::wstring & file);
bool CreateDir(const wchar_t * dir, int priv);
bool CreateDir(const std::wstring & dir, int priv);
// creating directories (dirs) under base_dir (base_dir must exist)
// if skip_last == true then last part from dir is treated as a file (the last directory is not created)
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv = 0755, bool skip_last = false);
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv = 0755, bool skip_last = false);
bool CopyFile(FILE * in, FILE * out);
bool CopyFile(const char * src, const char * dst);
bool CopyFile(const std::string & src, const std::string & dst);
bool CopyFile(const wchar_t * src, const wchar_t * dst);
bool CopyFile(const std::wstring & src, const std::wstring & dst);
bool RemoveFile(const wchar_t * file);
bool RemoveFile(const std::wstring & file);
bool RenameFile(const wchar_t * from, const wchar_t * to);
bool RenameFile(const std::wstring & from, const std::wstring & to);
const wchar_t * GetFileExt(const wchar_t * name);
int SelectFileType(const wchar_t * file_name);
int SelectFileType(const std::wstring & file_name);
time_t Time(const tm & par);
time_t Time(const tm * par);
tm Time(time_t par);
void UrlEncode(const std::string & in, std::string & out, bool clear_out = true);
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
void QEncode(const std::wstring & in, std::string & out, bool clear = true);
const char * GetFileExt(const char * name);
Item::Auth SelectFileType(const char * file_name);
#endif

View File

@@ -2,118 +2,21 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* Copyright (c) 2009-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "mount.h"
#include "misc.h"
Mount::Mount()
{
type = cms;
dir_id = -1;
fs = simplefs;
param.resize(par_none);
}
const char * Mount::TypeToStr()
{
static char buffer[30];
switch( type )
{
case cms:
sprintf(buffer, "cms");
break;
case thread:
sprintf(buffer, "thread");
break;
case ticket:
sprintf(buffer, "ticket");
break;
default:
sprintf(buffer, "unknown");
break;
}
return buffer;
}
const char * Mount::FsToStr()
{
static char buffer[30];
switch( fs )
{
case simplefs:
sprintf(buffer, "simplefs");
break;
case hashfs:
sprintf(buffer, "hashfs");
break;
default:
sprintf(buffer, "unknown");
break;
}
return buffer;
}
Mount::ParamCode Mount::ParseParam(const char * param_name)
{
struct ParName
{
ParamCode param_code;
const char * name;
};
static ParName par_name_tab[] = {
{ par_page, "page" },
{ par_thread, "thread" },
{ par_ticket, "ticket" },
{ par_ticket_type, "ticket_type" },
{ par_ticket_type_default, "ticket_type_default" },
{ par_ticket_status, "ticket_status" },
{ par_ticket_status_default, "ticket_status_default" },
{ par_ticket_priority, "ticket_priority" },
{ par_ticket_priority_default, "ticket_priority_default" },
{ par_ticket_category, "ticket_category" },
{ par_ticket_category_default, "ticket_category_default" },
{ par_ticket_expected, "ticket_expected" },
{ par_ticket_expected_default, "ticket_expected_default" },
{ par_createthread_on, "createthread_on" },
{ par_createticket_on, "createticket_on" },
{ par_only_root_remove, "only_root_remove" },
{ par_emacs_on, "emacs_on" },
{ par_mkdir_on, "mkdir_on" },
{ par_app, "app" },
{ par_html_template, "html_template" },
};
size_t i, len = sizeof(par_name_tab) / sizeof(ParName);
for(i=0 ; i<len ; ++i)
{
if( strcmp(par_name_tab[i].name, param_name) == 0 )
return par_name_tab[i].param_code;
}
return par_none;
type = -1;
fs = -1;
}
@@ -127,8 +30,11 @@ size_t i;
}
bool Mount::IsPar(Mount::ParamCode code)
bool Mount::IsPar(int code)
{
if( code < 0 || code >= (int)param.size() )
return false;
if( !param[code].defined )
return false;
@@ -137,9 +43,12 @@ return true;
bool Mount::IsArg(Mount::ParamCode code, const char * arg)
bool Mount::IsArg(int code, const wchar_t * arg)
{
ParamArg::iterator i;
ParamRow::ParamArg::iterator i;
if( code < 0 || code >= (int)param.size() )
return false;
if( !param[code].defined )
return false;
@@ -154,22 +63,25 @@ return false;
}
bool Mount::IsArg(Mount::ParamCode code, const std::string & arg)
bool Mount::IsArg(int code, const std::wstring & arg)
{
return IsArg(code, arg.c_str());
}
bool Mount::IsArg(Mount::ParamCode code, int arg)
bool Mount::IsArg(int code, int arg)
{
ParamArg::iterator i;
ParamRow::ParamArg::iterator i;
if( code < 0 || code >= (int)param.size() )
return false;
if( !param[code].defined )
return false;
for(i=param[code].arg.begin() ; i!=param[code].arg.end() ; ++i)
{
if( atoi(i->c_str()) == arg )
if( Toi(*i) == arg )
return true;
}
@@ -177,15 +89,23 @@ return false;
}
const std::string * Mount::HtmlTemplate() const
const std::wstring & Mount::Arg(int code, int arg) const
{
if( !param[par_html_template].defined )
return 0;
if( code < 0 || code >= (int)param.size() )
return empty_str;
if( param[par_html_template].arg.size() != 1 )
return 0;
if( !param[code].defined )
return empty_str;
return & param[par_html_template].arg[0];
if( arg >= (int)param[code].arg.size() )
return empty_str;
return param[code].arg[arg];
}
const std::wstring & Mount::FirstArg(int code) const
{
return Arg(code, 0);
}

View File

@@ -2,14 +2,14 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* Copyright (c) 2009-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoremount
#define headerfilecmslucoremount
#ifndef headerfile_winix_core_mount
#define headerfile_winix_core_mount
#include <map>
#include <string>
@@ -17,59 +17,14 @@
class Mount
{
public:
enum Type
{
cms = 0,
thread,
ticket
};
enum Fs
{
simplefs = 0,
hashfs
};
// the first should be with 0 index
// the last should be 'none'
enum ParamCode
{
par_page = 0,
par_thread,
par_ticket,
par_ticket_type,
par_ticket_type_default,
par_ticket_status,
par_ticket_status_default,
par_ticket_priority,
par_ticket_priority_default,
par_ticket_category,
par_ticket_category_default,
par_ticket_expected,
par_ticket_expected_default,
par_createthread_on,
par_createticket_on,
par_only_root_remove,
par_emacs_on,
par_mkdir_on,
par_app,
par_html_template,
par_none
};
typedef std::vector<std::string> ParamArg;
struct ParamRow
{
typedef std::vector<std::wstring> ParamArg;
bool defined;
ParamArg arg;
@@ -78,31 +33,36 @@ public:
};
typedef std::vector<ParamRow> Param;
long dir_id;
int type;
int fs;
Param param;
long dir_id;
Type type;
Fs fs;
Mount();
const char * TypeToStr();
const char * FsToStr();
static ParamCode ParseParam(const char * param);
void ClearParams();
bool IsPar(int code);
bool IsPar(Mount::ParamCode code);
bool IsArg(int code, const wchar_t * arg);
bool IsArg(int code, const std::wstring & arg);
bool IsArg(int code, int arg);
bool IsArg(Mount::ParamCode code, const char * arg);
bool IsArg(Mount::ParamCode code, const std::string & arg);
bool IsArg(Mount::ParamCode code, int arg);
// returning the arg argument if defined (or an empty string)
const std::wstring & Arg(int code, int arg) const;
// returning a name to html template (can be null if not defined)
const std::string * HtmlTemplate() const;
// returning the first argument (arg=0) if defined (or an empty string)
const std::wstring & FirstArg(int code) const;
private:
// for Arg() methods when the argument is not defined
const std::wstring empty_str;
};

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* Copyright (c) 2010-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -12,12 +12,55 @@
#include "misc.h"
MountParser::MountParser()
{
dirs = 0;
skip_static = false;
mount_type_tab = 0;
mount_fs_tab = 0;
mount_par_tab = 0;
static_mount_id = -1;
}
void MountParser::SkipStaticDirs(bool skip)
{
skip_static = skip;
}
void MountParser::SetStaticMountId(int id)
{
static_mount_id = id;
}
void MountParser::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
}
void MountParser::SetMountTypeTab(const std::vector<std::wstring> & tab)
{
mount_type_tab = &tab;
}
void MountParser::SetMountFsTab(const std::vector<std::wstring> & tab)
{
mount_fs_tab = &tab;
}
void MountParser::SetMountParTab(const std::vector<std::wstring> & tab)
{
mount_par_tab = &tab;
}
bool MountParser::IsWhite(int c)
{
if( c==' ' || c=='\t' || c==13 || c==160 )
@@ -44,7 +87,7 @@ void MountParser::SkipLine()
}
void MountParser::ReadWordQuote(std::string & res)
void MountParser::ReadWordQuote(std::wstring & res)
{
++pinput;
@@ -74,7 +117,7 @@ void MountParser::ReadWordQuote(std::string & res)
// a white character is the separator
void MountParser::ReadWordWhite(std::string & res)
void MountParser::ReadWordWhite(std::wstring & res)
{
while( *pinput && *pinput!=10 && !IsWhite(*pinput) )
{
@@ -85,7 +128,7 @@ void MountParser::ReadWordWhite(std::string & res)
// the comma or the second bracket ')' are the separators
void MountParser::ReadWordComma(std::string & res)
void MountParser::ReadWordComma(std::wstring & res)
{
while( *pinput && *pinput!=10 && *pinput!=',' && *pinput!=')' )
{
@@ -99,7 +142,7 @@ void MountParser::ReadWordComma(std::string & res)
}
void MountParser::ReadWord(std::string & res, bool comma_bracket_separator)
void MountParser::ReadWord(std::wstring & res, bool comma_bracket_separator)
{
res.clear();
SkipWhite();
@@ -122,7 +165,7 @@ void MountParser::ReadWord(std::string & res, bool comma_bracket_separator)
void MountParser::ReadParamArgsLoop(Mount::ParamArg & args)
void MountParser::ReadParamArgsLoop(Mount::ParamRow::ParamArg & args)
{
SkipWhite();
@@ -139,7 +182,7 @@ void MountParser::ReadParamArgsLoop(Mount::ParamArg & args)
}
void MountParser::ReadParamArgs(Mount::ParamArg & args)
void MountParser::ReadParamArgs(Mount::ParamRow::ParamArg & args)
{
SkipWhite();
args.clear();
@@ -164,7 +207,7 @@ void MountParser::ReadParamArgs(Mount::ParamArg & args)
void MountParser::ReadParamName(std::string & res)
void MountParser::ReadParamName(std::wstring & res)
{
SkipWhite();
res.clear();
@@ -177,7 +220,7 @@ void MountParser::ReadParamName(std::string & res)
}
void MountParser::ReadParam(std::string & res, Mount::ParamArg & args)
void MountParser::ReadParam(std::wstring & res, Mount::ParamRow::ParamArg & args)
{
ReadParamName(res);
@@ -193,83 +236,83 @@ void MountParser::ReadParam(std::string & res, Mount::ParamArg & args)
}
int MountParser::FindIndex(const std::vector<std::wstring> * tab, const std::wstring & value)
{
for(size_t i=0 ; i < tab->size() ; ++i)
{
if( (*tab)[i] == value )
return static_cast<int>(i);
}
void MountParser::ReadMountType()
return -1;
}
bool MountParser::ReadMountType()
{
ReadWord(temp);
if( temp.empty() )
{
// an empty line (some white characters only)
err = WINIX_ERR_EMPTY;
return false;
}
else
if( temp == "cms" )
mount.type = FindIndex(mount_type_tab, temp);
if( mount.type != -1 )
{
mount.type = Mount::cms;
log << log3 << "MP: mount type: cms" << logend;
}
else
if( temp == "thread" )
{
mount.type = Mount::thread;
log << log3 << "MP: mount type: thread" << logend;
}
else
if( temp == "ticket" )
{
mount.type = Mount::ticket;
log << log3 << "MP: mount type: ticket" << logend;
log << log3 << "MP: mount type: " << (*mount_type_tab)[mount.type] << logend;
}
else
{
err = WINIX_ERR_MOUNT_UNKNOWN;
log << log1 << "MP: unknown mount type: " << temp << logend;
slog << logerror << T("unknown_mount_type") << ": " << temp << logend;
}
return mount.type != -1;
}
void MountParser::ReadMountPoint()
bool MountParser::ReadMountPoint()
{
ReadWord(temp);
ReadWord(last_dir);
pdir = dirs->GetDir(temp);
pdir = dirs->GetDir(last_dir);
if( pdir )
{
mount.dir_id = pdir->id;
log << log3 << "MP: mount point: " << temp << logend;
log << log3 << "MP: mount point (directory): " << last_dir << logend;
}
else
{
err = WINIX_ERR_NO_MOUNTPOINT;
log << log1 << "MP: there is no such a mount point: " << temp << logend;
log << log1 << "MP: there is no such a mount point (directory): " << last_dir << logend;
slog << logerror << T("no_such_dir") << ": " << last_dir << logend;
}
return pdir != 0;
}
void MountParser::ReadFs()
bool MountParser::ReadFs()
{
ReadWord(temp);
mount.fs = FindIndex(mount_fs_tab, temp);
if( temp == "simplefs" )
if( mount.fs != -1 )
{
mount.fs = Mount::simplefs;
log << log1 << "MP: file system: simplefs" << logend;
}
else
if( temp == "hashfs" )
{
mount.fs = Mount::hashfs;
log << log1 << "MP: file system: hashfs" << logend;
log << log2 << "MP: file system: " << (*mount_fs_tab)[mount.fs] << logend;
}
else
{
err = WINIX_ERR_UNKNOWN_FILESYSTEM;
log << log1 << "MP: unknown filesystem: " << temp << logend;
slog << logerror << T("unknown_filesystem") << ": " << temp << " (" << last_dir << ")" << logend;
}
return mount.fs != -1;
}
@@ -299,17 +342,18 @@ void MountParser::ReadMountParams()
for( ReadParam(temp, param_args) ; !temp.empty() ; ReadParam(temp, param_args) )
{
Mount::ParamCode p = Mount::ParseParam(temp.c_str());
int code = FindIndex(mount_par_tab, temp);
if( p != Mount::par_none )
if( code != -1 )
{
mount.param[p].defined = true;
mount.param[p].arg = param_args;
mount.param[code].defined = true;
mount.param[code].arg = param_args;
LogMountParams();
}
else
{
log << log1 << "MP: unknown mount param: " << temp << " (skipped)" << logend;
log << log1 << "MP: unknown mount param: " << temp << logend;
slog << logwarning << T("unknown_mount_param") << ": " << temp << " (" << T("skipped") << ")" << logend;
}
}
}
@@ -318,30 +362,25 @@ void MountParser::ReadMountParams()
void MountParser::ReadRow(std::map<long, Mount> & output)
{
ReadMountType();
if( err == WINIX_ERR_EMPTY )
if( ReadMountType() && ReadMountPoint() && ReadFs() )
{
err = WINIX_ERR_OK;
SkipLine();
return;
}
if( err == WINIX_ERR_OK )
ReadMountPoint();
if( err == WINIX_ERR_OK )
ReadFs();
if( err == WINIX_ERR_OK )
ReadMountParams();
if( err == WINIX_ERR_OK )
{
std::pair<std::map<long, Mount>::iterator, bool> res = output.insert( std::make_pair(mount.dir_id, mount) );
if( !res.second )
log << log1 << "MP: this mount point exists (skipped)" << logend;
if( skip_static && mount.type==static_mount_id )
{
log << log1 << "MP: static mount points are skipped (dont_use_static_dirs in config is true)" << logend;
slog << logwarning << T("skipped_static_mount") << ": " << last_dir << logend;
}
else
{
std::pair<std::map<long, Mount>::iterator, bool> res = output.insert( std::make_pair(mount.dir_id, mount) );
if( !res.second )
{
log << log1 << "MP: this mount point exists (skipped)" << logend;
slog << logwarning << T("mount_exists") << ": " << last_dir << " (" << T("skipped") << ")" << logend;
}
}
}
SkipLine();
@@ -350,16 +389,21 @@ void MountParser::ReadRow(std::map<long, Mount> & output)
Error MountParser::Parse(const std::string & input, std::map<long, Mount> & output)
void MountParser::Parse(const std::wstring & input, std::map<long, Mount> & output)
{
if( !dirs || !mount_type_tab || !mount_fs_tab || !mount_par_tab )
{
log << log1 << "MP: input tables not set" << logend;
return;
}
pinput = input.c_str();
err = WINIX_ERR_OK;
mount.param.resize(mount_par_tab->size());
mount.ClearParams();
output.clear();
while( *pinput && err == WINIX_ERR_OK )
while( *pinput )
ReadRow(output);
return err;
}

View File

@@ -2,13 +2,13 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* Copyright (c) 2010-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoremountparser
#define headerfilecmslucoremountparser
#ifndef headerfile_winix_core_mountparser
#define headerfile_winix_core_mountparser
#include <map>
#include <string>
@@ -18,7 +18,6 @@
#include "mount.h"
#include "item.h"
#include "error.h"
#include "dirs.h"
@@ -27,41 +26,53 @@ class MountParser
{
public:
Error Parse(const std::string & input, std::map<long, Mount> & output);
MountParser();
void SkipStaticDirs(bool skip);
void SetStaticMountId(int id);
void Parse(const std::wstring & input, std::map<long, Mount> & output);
void SetDirs(Dirs * pdirs);
void SetMountTypeTab(const std::vector<std::wstring> & tab);
void SetMountFsTab(const std::vector<std::wstring> & tab);
void SetMountParTab(const std::vector<std::wstring> & tab);
private:
Dirs * dirs;
bool skip_static;
int static_mount_id;
const std::vector<std::wstring> * mount_type_tab;
const std::vector<std::wstring> * mount_fs_tab;
const std::vector<std::wstring> * mount_par_tab;
bool IsWhite(int c);
void SkipWhite();
void SkipLine();
void ReadWordQuote(std::string & res);
void ReadWordWhite(std::string & res);
void ReadWordComma(std::string & res);
void ReadWord(std::string & res, bool comma_bracket_separator = false);
void ReadParamArgsLoop(Mount::ParamArg & args);
void ReadParamArgs(Mount::ParamArg & args);
void ReadParamName(std::string & res);
void ReadParam(std::string & res, Mount::ParamArg & args);
void ReadMountType();
void ReadMountPoint();
void ReadFs();
void ReadWordQuote(std::wstring & res);
void ReadWordWhite(std::wstring & res);
void ReadWordComma(std::wstring & res);
void ReadWord(std::wstring & res, bool comma_bracket_separator = false);
void ReadParamArgsLoop(Mount::ParamRow::ParamArg & args);
void ReadParamArgs(Mount::ParamRow::ParamArg & args);
void ReadParamName(std::wstring & res);
void ReadParam(std::wstring & res, Mount::ParamRow::ParamArg & args);
int FindIndex(const std::vector<std::wstring> * tab, const std::wstring & value);
bool ReadMountType();
bool ReadMountPoint();
bool ReadFs();
void LogMountParams();
void ReadMountParams();
void ReadRow(std::map<long, Mount> & output);
const char * pinput;
std::string temp;
std::string temp_arg;
Mount::ParamArg param_args;
const wchar_t * pinput;
std::wstring temp;
std::wstring last_dir;
std::wstring temp_arg;
Mount::ParamRow::ParamArg param_args;
Mount mount;
Item * pdir;
Error err;
};

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* Copyright (c) 2009-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -10,18 +10,71 @@
#include "mounts.h"
#include "request.h"
#include "log.h"
#include "mountparser.h"
#include "db.h"
#include "db/db.h"
#include "plugin.h"
Mounts::Mounts()
{
pmount = 0;
pmount = &empty_mount;
skip_static = false;
}
void Mounts::SkipStaticDirs(bool skip)
{
skip_static = skip;
}
void Mounts::CreateMountType()
{
mount_type_cms = AddMountType(L"cms");
mount_type_static = AddMountType(L"static");
}
void Mounts::CreateMountFs()
{
mount_fs_simplefs = AddMountFs(L"simplefs");
mount_fs_hashfs = AddMountFs(L"hashfs");
}
void Mounts::CreateMountPar()
{
mount_par_page = AddMountPar(L"page");
mount_par_thumb_size = AddMountPar(L"thumb_size");
mount_par_thumb_mode = AddMountPar(L"thumb_mode");
//mount_par_thread = AddMountPar(L"thread");
//mount_par_createthread_on = AddMountPar(L"createthread_on");
mount_par_only_root_remove = AddMountPar(L"only_root_remove");
mount_par_emacs_on = AddMountPar(L"emacs_on");
mount_par_mkdir_on = AddMountPar(L"mkdir_on");
mount_par_app = AddMountPar(L"app");
mount_par_html_template = AddMountPar(L"html_template");
mount_par_static = AddMountPar(L"static");
mount_par_css = AddMountPar(L"css");
}
void Mounts::CreateMounts()
{
CreateMountType();
CreateMountFs();
CreateMountPar();
plugin.Call(WINIX_ADD_MOUNTS);
empty_mount.param.resize(mount_par_tab.size());
empty_mount.ClearParams();
}
void Mounts::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
@@ -33,29 +86,109 @@ void Mounts::SetDb(Db * pdb)
db = pdb;
}
void Mounts::SetRequest(Request * prequest)
void Mounts::SetCur(Cur * pcur)
{
request = prequest;
cur = pcur;
}
int Mounts::AddMountType(const wchar_t * type)
{
mount_type_tab.push_back(type);
return static_cast<int>(mount_type_tab.size()) - 1;
}
int Mounts::AddMountType(const std::wstring & type)
{
return AddMountType(type.c_str());
}
int Mounts::AddMountFs(const wchar_t * fs)
{
mount_fs_tab.push_back(fs);
return static_cast<int>(mount_fs_tab.size()) - 1;
}
const std::wstring & Mounts::GetMountType(int id)
{
if( id < 0 || id >= (int)mount_type_tab.size() )
return empty_str;
return mount_type_tab[id];
}
int Mounts::FindMountType(const std::wstring & type)
{
for(size_t i=0 ; i<mount_type_tab.size() ; ++i)
if( mount_type_tab[i] == type )
return (int)i;
return -1;
}
int Mounts::AddMountFs(const std::wstring & fs)
{
return AddMountFs(fs.c_str());
}
const std::wstring & Mounts::GetMountFs(int id)
{
if( id < 0 || id >= (int)mount_fs_tab.size() )
return empty_str;
return mount_fs_tab[id];
}
int Mounts::AddMountPar(const wchar_t * par)
{
mount_par_tab.push_back(par);
return static_cast<int>(mount_par_tab.size()) - 1;
}
int Mounts::AddMountPar(const std::wstring & par)
{
return AddMountPar(par.c_str());
}
const std::wstring & Mounts::GetMountPar(int id)
{
if( id < 0 || id >= (int)mount_par_tab.size() )
return empty_str;
return mount_par_tab[id];
}
// reading from 'mounts'
Error Mounts::ReadMounts(const std::string & mounts)
void Mounts::ReadMounts(const std::wstring & mounts)
{
MountParser mp;
mp.SetDirs(dirs);
Error err = mp.Parse(mounts, mount_tab);
mount_parser.SkipStaticDirs(skip_static);
mount_parser.SetStaticMountId(mount_type_static);
mount_parser.SetDirs(dirs);
mount_parser.SetMountTypeTab(mount_type_tab);
mount_parser.SetMountFsTab(mount_fs_tab);
mount_parser.SetMountParTab(mount_par_tab);
if( err != WINIX_ERR_OK )
{
log << log1 << "M: some problems with mountpoints (mountpoints table will be empty)" << logend;
mount_tab.clear();
}
mount_parser.Parse(mounts, mount_tab);
CalcCurMount();
return err;
plugin.Call(WINIX_FSTAB_CHANGED);
}
@@ -63,7 +196,7 @@ return err;
// reading from /etc/fstab
Error Mounts::ReadMounts()
{
static std::string file = "fstab";
static std::wstring file = L"fstab";
Item * etc = dirs->GetEtcDir();
@@ -88,15 +221,17 @@ Error Mounts::ReadMounts()
return err;
}
return ReadMounts(fstab.content);
ReadMounts(fstab.content);
return WINIX_ERR_OK;
}
void Mounts::MountCmsForRoot()
{
Mount mount;
mount.type = Mount::cms;
mount.fs = Mount::simplefs;
mount.type = MountTypeCms();
mount.fs = MountFsSimplefs();
Item * proot = dirs->GetRootDir();
@@ -108,6 +243,9 @@ void Mounts::MountCmsForRoot()
log << log1 << "M: there is no a root dir" << logend;
}
mount.param.resize(mount_par_tab.size());
mount.ClearParams();
std::pair<MountTab::iterator, bool> res = mount_tab.insert( std::make_pair(mount.dir_id, mount) );
pmount = &(res.first->second);
}
@@ -119,20 +257,22 @@ void Mounts::CalcCurMount()
{
std::vector<Item*>::reverse_iterator i;
// when the program starts (when the dir_table is empty()
pmount = &empty_mount;
// when the program starts (when the dir_tab is empty()
// we don't want to call MountCmsForRoot()
if( request->dir_table.empty() )
if( cur->request->dir_tab.empty() )
return;
for(i = request->dir_table.rbegin() ; i!=request->dir_table.rend() ; ++i)
for(i = cur->request->dir_tab.rbegin() ; i!=cur->request->dir_tab.rend() ; ++i)
{
std::map<long, Mount>::iterator m = mount_tab.find( (*i)->id );
if( m != mount_tab.end() )
{
pmount = &(m->second);
log << log2 << "M: current mount point is: " << pmount->TypeToStr()
<< ", fs: " << pmount->FsToStr() << logend;
log << log2 << "M: current mount point is: " << GetMountType(pmount->type)
<< ", fs: " << GetMountFs(pmount->fs) << logend;
return;
}
}
@@ -140,8 +280,8 @@ std::vector<Item*>::reverse_iterator i;
// if nothing was found
// we assume that 'cms' mount point is used
MountCmsForRoot();
log << log2 << "M: current mount point is: " << pmount->TypeToStr() << " (default)"
<< ", fs: " << pmount->FsToStr() << logend;
log << log2 << "M: current mount point is: " << GetMountType(pmount->type) << " (default)"
<< ", fs: " << GetMountFs(pmount->fs) << logend;
}

View File

@@ -2,23 +2,25 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* Copyright (c) 2009-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorecoremounts
#define headerfilecmslucorecoremounts
#ifndef headerfile_winix_core_mounts
#define headerfile_winix_core_mounts
#include <map>
#include <string>
#include <vector>
#include "mount.h"
#include "error.h"
#include "dirs.h"
#include "db.h"
#include "db/db.h"
#include "request.h"
#include "mountparser.h"
@@ -26,15 +28,68 @@ class Mounts
{
public:
void SkipStaticDirs(bool skip);
/*
mount point's types
*/
int AddMountType(const wchar_t * type);
int AddMountType(const std::wstring & type);
const std::wstring & GetMountType(int id);
// id of a specific mount type (the id is always valid)
int MountTypeCms() { return mount_type_cms; }
int MountTypeStatic() { return mount_type_static; }
// return -1 if there is no such a mount type
// or index otherwhise
int FindMountType(const std::wstring & type);
/*
file systems
*/
int AddMountFs(const wchar_t * fs);
int AddMountFs(const std::wstring & fs);
const std::wstring & GetMountFs(int id);
// id of a specific file system (the id is always valid)
int MountFsSimplefs() { return mount_fs_simplefs; }
int MountFsHashfs() { return mount_fs_hashfs; }
/*
mount point's parameters
*/
int AddMountPar(const wchar_t * par);
int AddMountPar(const std::wstring & par);
const std::wstring & GetMountPar(int id);
int MountParPage() { return mount_par_page; }
int MountParThumbSize() { return mount_par_thumb_size; }
int MountParThumbMode() { return mount_par_thumb_mode; }
//int MountParThread() { return mount_par_thread; }
//int MountParCreatethreadOn() { return mount_par_createthread_on; }
int MountParOnlyRootRemove() { return mount_par_only_root_remove; }
int MountParEmacsOn() { return mount_par_emacs_on; }
int MountParMkdirOn() { return mount_par_mkdir_on; }
int MountParApp() { return mount_par_app; }
int MountParHtmlTemplate() { return mount_par_html_template; }
int MountParStatic() { return mount_par_static; }
int MountParCss() { return mount_par_css; }
void SetDirs(Dirs * pdirs);
void SetDb(Db * pdb);
void SetRequest(Request * prequest);
void SetCur(Cur * pcur);
// dir_id, mount_point
typedef std::map<long, Mount> MountTab;
Mounts();
Error ReadMounts(const std::string & mounts);
void CreateMounts();
void ReadMounts(const std::wstring & mounts);
Error ReadMounts();
void CalcCurMount();
@@ -49,12 +104,51 @@ public:
private:
Db * db;
Dirs * dirs;
Db * db;
Request * request;
Cur * cur;
bool skip_static;
Mount empty_mount;
const std::wstring empty_str;
MountParser mount_parser;
std::vector<std::wstring> mount_type_tab;
int mount_type_cms;
int mount_type_static;
// simplefs
// hashfs
std::vector<std::wstring> mount_fs_tab;
int mount_fs_simplefs;
int mount_fs_hashfs;
std::vector<std::wstring> mount_par_tab;
int mount_par_page;
int mount_par_thumb_size;
int mount_par_thumb_mode;
//int mount_par_thread;
//int mount_par_createthread_on;
int mount_par_only_root_remove;
int mount_par_emacs_on;
int mount_par_mkdir_on;
int mount_par_app;
int mount_par_html_template;
int mount_par_static;
int mount_par_css;
MountTab mount_tab;
void CreateMountType();
void CreateMountFs();
void CreateMountPar();
void MountCmsForRoot();
};

View File

@@ -1,288 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <pthread.h>
#include <unistd.h>
#include "log.h"
#include "notify.h"
#include "misc.h"
#include "request.h"
// the second thread uses this pointer to reference to 'this'
// (methods for the thread should be static)
Notify * Notify::obj;
void Notify::SetRequest(Request * prequest)
{
request = prequest;
}
void Notify::SetConfig(Config * pconfig)
{
config = pconfig;
}
void Notify::SetSystem(System * psystem)
{
system = psystem;
}
void Notify::SetTemplatesNotify(TemplatesNotify * ptemplates_notify)
{
templates_notify = ptemplates_notify;
}
/*
methods for the second thread
the thread can reference to 'this' by using 'obj' pointer
*/
void * Notify::ThreadRoutine(void * arg)
{
obj = (Notify*)arg;
while( true )
{
CheckQueue();
sleep(30);
}
}
void Notify::CheckQueue()
{
std::list<NotifyMsg>::iterator i = obj->notify_pool.begin();
while( i != obj->notify_pool.end() )
{
SendEmail(*i);
obj->Lock();
i = obj->notify_pool.erase(i);
obj->Unlock();
sleep(3);
}
}
void Notify::SendEmail(NotifyMsg & n)
{
TemplatesNotifyFunctions::notify_msg = &n;
obj->Lock(); // templates can be reloaded from the first thread
obj->templates_notify->Generate(n.lang);
obj->Unlock();
SendEmail(n.email, obj->templates_notify->notify_str.str());
}
void Notify::SendEmail(const std::string & email, const std::string & message)
{
nlog.PutDate(log1);
if( !ValidateEmail(email) )
{
nlog << "Notify: email: " << email << " is not correct" << logend;
return;
}
obj->command = "sendmail " + email;
FILE * sendmail = popen(obj->command.c_str(), "w");
if( !sendmail )
{
nlog << "Notify: can't run sendmail" << logend;
return;
}
SendMessage(sendmail, message);
pclose(sendmail);
nlog << "Notify: email to: " << email << " has been sent" << logend;
nlog << logsave;
}
void Notify::SendMessage(FILE * sendmail, const std::string & message)
{
for(size_t i=0 ; i<message.length() ; ++i)
{
if( message[i] == '\n' )
fprintf(sendmail, "\r\n");
else
fputc(message[i], sendmail);
}
}
/*
methods for main thread
*/
Notify::Notify() : mutex(PTHREAD_MUTEX_INITIALIZER)
{
}
Notify::~Notify()
{
}
void Notify::ReadTemplates()
{
// we are in the first thread here
// the second thread can use our templates and we must Lock()
// (the second thread is using Lock() too)
Lock();
templates_notify->Read();
Unlock();
}
bool Notify::Init()
{
templates_notify->CreateFunctions();
int t = pthread_create(&thread, 0, ThreadRoutine, (void*)this);
if( t != 0 )
{
// log (not nlog) here
log << log1 << "Notify: can't create a thread" << logend;
return false;
}
return true;
}
bool Notify::Lock()
{
if( pthread_mutex_lock(&mutex) != 0 )
return false;
return true;
}
void Notify::Unlock()
{
pthread_mutex_unlock(&mutex);
}
void Notify::CreateItemDir(std::string & dir, bool clear)
{
if( clear )
dir.clear();
for(size_t a=0 ; a<request->dir_table.size() ; ++a)
{
dir += request->dir_table[a]->url;
dir += '/';
}
}
void Notify::CreateItemLink(std::string & link)
{
link = config->base_url;
CreateItemDir(link, false);
link += request->item.url;
}
void Notify::ItemChanged(int notify_code)
{
bool sending;
Users::Iterator i;
if( notify_code == 0 )
return;
n.notify_code = notify_code;
n.current_mount_type = system->mounts.pmount->type;
n.doc_base_url = config->base_url;
CreateItemDir(n.item_dir);
CreateItemLink(n.item_link);
Lock();
try
{
// don't clear notify_pool here -- it is used (and will be cleared) by the second thread
for(i=system->users.Begin() ; i != system->users.End() ; ++i)
{
sending = false;
if( system->mounts.pmount->type == Mount::thread )
{
if( (i->thread_notify & notify_code) != 0 )
sending = true;
}
else
if( system->mounts.pmount->type == Mount::cms )
{
if( (i->cms_notify & notify_code) != 0 )
sending = true;
}
if( sending )
{
n.email = i->email;
n.lang = Locale::StrToLang(config->locale_str);// !! bedzie osobno dla kazdego uzytkownika
if( n.lang == Locale::lang_unknown )
n.lang = Locale::lang_en;
notify_pool.insert(notify_pool.end(), n);
}
}
}
catch(...)
{
Unlock();
throw;
}
Unlock();
}

View File

@@ -1,91 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslunotify
#define headerfilecmslunotify
#include <list>
#include <string>
#include <cstdio>
#include "templatesnotify/templatesnotify.h"
#include "request.h"
#include "config.h"
#include "system.h"
#include "users.h"
#define WINIX_NOTIFY_ITEM_ADD 1
#define WINIX_NOTIFY_ITEM_EDIT 2
#define WINIX_NOTIFY_ITEM_DELETE 4
#define WINIX_NOTIFY_DIR_ADD 8
class Notify
{
public:
Notify();
~Notify();
void SetRequest(Request * prequest);
void SetConfig(Config * pconfig);
void SetSystem(System * psystem);
void SetTemplatesNotify(TemplatesNotify * ptemplates_notify);
void ReadTemplates();
bool Init();
/*
this method addes an item to our special pool
the pool is used by a second thread
*/
void ItemChanged(int notify_code);
private:
Request * request;
Config * config;
System * system;
TemplatesNotify * templates_notify;
static void * ThreadRoutine(void * arg);
bool Lock();
void Unlock();
static void CheckQueue();
static void SendEmail(NotifyMsg & n);
static void SendEmail(const std::string & email);
static void SendEmail(const std::string & email, const std::string & message);
static void SendMessage(FILE * sendmail, const std::string & message);
void CreateItemDir(std::string & dir, bool clear = true);
void CreateItemLink(std::string & link);
pthread_t thread;
pthread_mutex_t mutex;
NotifyMsg n;
/*
objects accessed by the second thread
*/
std::list<NotifyMsg> notify_pool;
static Notify * obj;
std::string command;
};
#endif

View File

@@ -8,8 +8,10 @@
*/
#include <dlfcn.h>
#include <string.h>
#include "plugin.h"
#include "pluginmsg.h"
#include "misc.h"
@@ -29,16 +31,19 @@ size_t i;
Plugin::Plugin()
{
current_plugin = -1;
request = 0;
current_plugin = -1;
db = 0;
config = 0;
request = 0;
cur = 0;
system = 0;
functions = 0;
templates = 0;
synchro = 0;
session_manager = 0;
ret_false = 0;
ret_true = 0;
}
@@ -59,9 +64,9 @@ void Plugin::SetConfig(Config * pconfig)
}
void Plugin::SetRequest(Request * prequest)
void Plugin::SetCur(Cur * pcur)
{
request = prequest;
cur = pcur;
}
@@ -83,38 +88,57 @@ void Plugin::SetTemplates(Templates * ptemplates)
}
void Plugin::SetSynchro(Synchro * psynchro)
{
synchro = psynchro;
}
void Plugin::SetSessionManager(SessionManager * psession_manager)
{
session_manager = psession_manager;
}
bool Plugin::SetPointers(PluginInfo & info)
{
// for safety we call a plugin function only when all our pointers are not null
bool res = (db && config && request && system && functions && templates && session_manager);
bool res = (db && config && cur && system && functions && templates && synchro && session_manager);
if( !res )
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
info.db = db;
info.config = config;
info.request = request;
info.cur = cur;
info.system = system;
info.functions = functions;
info.templates = templates;
info.synchro = synchro;
info.session_manager = session_manager;
return res;
}
void Plugin::LoadPlugins(const std::vector<std::string> & plugins)
void Plugin::LoadPlugins(const std::wstring & plugins_dir, const std::vector<std::wstring> & plugins)
{
size_t i;
for(i=0 ; i<plugins.size() ; ++i)
LoadPlugin(plugins[i]);
for(size_t i=0 ; i<plugins.size() ; ++i)
{
if( !plugins[i].empty() && plugins[i][0] == '/' )
{
LoadPlugin(plugins[i]);
}
else
{
temp_path = plugins_dir;
temp_path += '/';
temp_path += plugins[i];
LoadPlugin(temp_path);
}
}
}
@@ -124,6 +148,7 @@ void Plugin::LoadPlugin(const std::string & filename)
}
void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
{
void * p = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
@@ -146,7 +171,7 @@ void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
return 0;
}
log << log1 << "Plugin: plugin loaded"
log << log2 << "Plugin: plugin loaded"
<< ", file: " << filename
<< ", index: " << plugins.size() << logend;
@@ -160,6 +185,7 @@ void Plugin::LoadPlugin(const char * filename)
Fun1 fun_init;
void * plugin_handle;
int old_current_plugin;
PluginInfo info;
if( !SetPointers(info) )
return;
@@ -176,7 +202,7 @@ int old_current_plugin;
PluginsItem item;
item.handle = plugin_handle;
item.plugin_name = reinterpret_cast<const char *>(info.p1);
item.plugin_name = reinterpret_cast<const wchar_t *>(info.p1);
plugins.push_back(item);
@@ -184,8 +210,43 @@ int old_current_plugin;
}
void Plugin::LoadPlugin(const wchar_t * filename)
{
AssignString(filename, afilename);
LoadPlugin(afilename.c_str());
}
void Plugin::Call(int message, Slots::iterator & slot)
void Plugin::LoadPlugin(const std::wstring & filename)
{
LoadPlugin(filename.c_str());
}
bool Plugin::HasPlugin(const wchar_t * name)
{
if( *name == 0 )
return false;
for(size_t i=0 ; i<plugins.size() ; ++i)
{
if( plugins[i].plugin_name && Equal(plugins[i].plugin_name, name) )
return true;
}
return false;
}
bool Plugin::HasPlugin(const std::wstring & name)
{
return HasPlugin(name.c_str());
}
void Plugin::Call(int message, Slots::iterator & slot, PluginInfo & info)
{
if( !SetPointers(info) )
return;
@@ -193,13 +254,16 @@ void Plugin::Call(int message, Slots::iterator & slot)
current_plugin = slot->second.index;
info.plugin_id = current_plugin;
if( request && request->session && current_plugin != -1 )
info.plugin_data_base = request->session->plugin_data.Get(current_plugin);
if( current_plugin != -1 )
info.plugin_data_base = cur->session->plugin_data.Get(current_plugin);
else
info.plugin_data_base = 0;
if( !slot->second.is_running )
{
if( config->log_plugin_call )
log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend;
slot->second.is_running = true;
if( slot->second.fun1 )
@@ -209,6 +273,10 @@ void Plugin::Call(int message, Slots::iterator & slot)
slot->second.fun2();
slot->second.is_running = false;
if( config->log_plugin_call )
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message << logend;
}
else
{
@@ -220,10 +288,18 @@ void Plugin::Call(int message, Slots::iterator & slot)
void Plugin::Call(int message, void * p1_, void * p2_, long l1_, long l2_)
{
// how many plugins return 'false' and 'true'
// we are using local variables because Call() method can be called
// from a plugin too (one Call() can execute another Call())
int ret_false_loc = 0;
int ret_true_loc = 0;
int old_current_plugin = current_plugin;
PluginInfo info;
Slots::iterator i = slots.lower_bound(message);
int old_current_plugin = current_plugin;
for( ; i!=slots.end() && i->first==message ; ++i )
{
@@ -233,10 +309,17 @@ void Plugin::Call(int message, void * p1_, void * p2_, long l1_, long l2_)
info.l1 = l1_;
info.l2 = l2_;
Call(message, i);
Call(message, i, info);
if( info.res )
++ret_true_loc;
else
++ret_false_loc;
}
current_plugin = old_current_plugin;
ret_false = ret_false_loc;
ret_true = ret_true_loc;
}
@@ -288,8 +371,6 @@ void Plugin::Call(int message, void * p1_, void * p2_, long l1_)
}
size_t Plugin::Size()
{
return plugins.size();
@@ -297,10 +378,26 @@ size_t Plugin::Size()
int Plugin::True()
{
return ret_true;
}
int Plugin::False()
{
return ret_false;
}
void Plugin::Assign(int message, Fun1 fun1)
{
Slot s;
if( current_plugin == -1 )
return;
s.fun1 = fun1;
s.index = current_plugin;
@@ -313,6 +410,9 @@ void Plugin::Assign(int message, Fun2 fun2)
{
Slot s;
if( current_plugin == -1 )
return;
s.fun2 = fun2;
s.index = current_plugin;

View File

@@ -8,8 +8,8 @@
*/
#ifndef headerfilecmsluplugin
#define headerfilecmsluplugin
#ifndef headerfile_winix_core_plugin
#define headerfile_winix_core_plugin
#include <vector>
#include <string>
@@ -21,6 +21,7 @@
#include "request.h"
#include "system.h"
#include "sessionmanager.h"
#include "synchro.h"
#include "functions/functions.h"
#include "templates/templates.h"
@@ -59,10 +60,11 @@ struct PluginInfo
// objects from winix which are accessible from a plugin
Db * db;
Config * config;
Request * request;
Cur * cur;
System * system;
Functions * functions;
Templates * templates;
Synchro * synchro;
SessionManager * session_manager;
// pointer to the plugin session (can be null if not set by the plugin)
@@ -72,7 +74,7 @@ struct PluginInfo
// function return status
// default: false (if not set by the plugin)
bool ret;
bool res;
void Clear()
@@ -87,7 +89,7 @@ struct PluginInfo
plugin_id = -1;
plugin_data_base = 0;
ret = false;
res = false;
}
};
@@ -128,17 +130,24 @@ public:
void SetDb(Db * pdb);
void SetConfig(Config * pconfig);
void SetRequest(Request * prequest);
void SetCur(Cur * pcur);
void SetSystem(System * psystem);
void SetFunctions(Functions * pfunctions);
void SetTemplates(Templates * ptemplates);
void SetSynchro(Synchro * psynchro);
void SetSessionManager(SessionManager * psession_manager);
void LoadPlugin(const char * filename);
void LoadPlugin(const std::string & filename);
void LoadPlugins(const std::vector<std::string> & plugins);
void LoadPlugin(const wchar_t * filename);
void LoadPlugin(const std::wstring & filename);
void LoadPlugins(const std::wstring & plugins_dir, const std::vector<std::wstring> & plugins);
void UnloadPlugins();
bool HasPlugin(const wchar_t * name);
bool HasPlugin(const std::wstring & name);
void Call(int message);
void Call(int message, void * p1_);
void Call(int message, void * p1_, void * p2_);
@@ -152,6 +161,14 @@ public:
// how many plugins there are
size_t Size();
// how many plugins returned 'true'
// from last Call()
int True();
// how many plugins returned 'false'
// from last Call()
int False();
// assign a function to a message
// you can assign more than one function to a specific message
void Assign(int message, Fun1);
@@ -161,17 +178,22 @@ private:
Db * db;
Config * config;
Request * request;
Cur * cur;
System * system;
Functions * functions;
Templates * templates;
Synchro * synchro;
SessionManager * session_manager;
int ret_false;
int ret_true;
std::wstring temp_path;
struct PluginsItem
{
void * handle;
const char * plugin_name; // plugin name (can be null if was not set by the plugin)
const wchar_t * plugin_name; // plugin name (can be null if was not set by the plugin)
};
typedef std::vector<PluginsItem> Plugins;
@@ -180,10 +202,10 @@ private:
typedef std::multimap<int, Slot> Slots;
Slots slots;
PluginInfo info;
std::string afilename;
void * LoadInitFun(const char * filename, Fun1 & fun_init);
void Call(int message, Slots::iterator & slot);
void Call(int message, Slots::iterator & slot, PluginInfo & info);
bool SetPointers(PluginInfo & info);
};

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucoreplugindata
#define headerfilecmslucoreplugindata
#ifndef headerfile_winix_core_plugindata
#define headerfile_winix_core_plugindata
#include <vector>

View File

@@ -2,23 +2,45 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslupluginmsg
#define headerfilecmslupluginmsg
#ifndef headerfile_winix_core_pluginmsg
#define headerfile_winix_core_pluginmsg
// here you can add your own EZC functions ([function])
// PluginInfo.p1 is a pointer to Ezc::Functions object
#define WINIX_TEMPLATES_CREATEFUNCTIONS 999
#define WINIX_REQUEST_CLEAR 1000
// here you can add your own EZC functions to notify system
// warning: this functions will be called from an other thread
// so you should use synchro->Lock() and synchro->Unlock()
// when attempting to winix objects
// PluginInfo.p1 is a pointer to Ezc::Functions object
// which is defined as:
// Ezc::Functions<NotifyStream> ezc_functions;
// and Notify Stream is:
// typedef TextStream<std::wstring> NotifyStream;
#define WINIX_NOTIFY_TEMPLATES_CREATEFUNCTIONS 998
#define WINIX_CONTENT_MAKE 2000
// winix function and parameters have been parsed
// the request.status is OK
// (the winix function was not called yet)
#define WINIX_PREPARE_REQUEST 2000
// post and get functions have done their jobs
// now you can act
// this is called only if the request.status is OK
#define WINIX_PROCESS_REQUEST 2001
// prepere your content for displaying
// this is called after WINIX_PROCESS_REQUEST
// and when there is not a redirect
// request.status is not checked here
#define WINIX_CONTENT_MAKE 2002
// here you can attach your own session data (based on PluginDataBase class)
// call request.session->plugin_data.Assign(pointer)
@@ -31,10 +53,12 @@
#define WINIX_SESSION_CHANGED 3002
// the winix is closing
// the is not any session available (cur->session is null)
#define WINIX_CLOSE 3004
// item was removed (rm function)
// a file or symlink was removed (rm function)
// PluginInfo::l1 is the file (item) id
// !! moze zmienic nazwe i dodac symlink w nazwie?
#define WINIX_FILE_REMOVED 3005
// directory was removed (rm function)
@@ -45,6 +69,41 @@
// PluginInfo::l1 is the dir id
#define WINIX_DIR_PREPARE_TO_REMOVE 3007
// winix is initialized,
// now you can initialize your plugin
#define WINIX_PLUGIN_INIT 3008
// here you can add your own mount point, file systems, mount parameters
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
#define WINIX_ADD_MOUNTS 3009
// add plugin functions here
#define WINIX_CREATE_FUNCTIONS 3010
// choose a default function
// if you do not select it then it will be choosen by winix
#define WINIX_SELECT_DEFAULT_FUNCTION 3011
// /etc/fstab has been changed
// now we have new mount points
#define WINIX_FSTAB_CHANGED 3012
// here you add your own template to notification system
// call system->notify.AddTemplate() method
// with a template file name
#define WINIX_NOTIFY_ADD_TEMPLATE 3013
// the request is ended
// you can clear some of your object here
#define WINIX_END_REQUEST 3014
// values from 4000 - 4099 reserved for 'thread' plugin
// see plugins/thread/pluginmsg.h
// values from 4100 - 4199 reserved for 'ticket' plugin
// see plugins/ticket/pluginmsg.h
#endif

View File

@@ -2,14 +2,15 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "postmultiparser.h"
#include "log.h"
#include "utf8.h"
#include "misc.h"
PostMultiParser::PostMultiParser()
@@ -210,8 +211,6 @@ return true;
void PostMultiParser::LogFirst(const std::string & to_log, size_t len)
{
size_t i;
if( len > to_log.size() )
len = to_log.size();
@@ -223,31 +222,31 @@ size_t i;
log << "empty";
log << "): \"";
for(i=0 ; i<len ; ++i)
{
if( to_log[i] < 32 )
log << '.';
else
log << to_log[i];
}
log.LogString(to_log, len);
log << "\"" << logend;
}
void PostMultiParser::ReadContentSkipBoundary(bool has_boundary)
{
if( has_boundary )
if( has_boundary && content.size() >= boundary.size() )
{
content.erase(content.size()-boundary.size());
content_len -= boundary.size();
}
// the last new line character doesn't belong to the content
// this is a new line character before the boundary
if( !content.empty() && content[content.size()-1] == 10 )
{
content.erase(content.size()-1);
content_len -= 1;
if( line_end_dos && !content.empty() && content[content.size()-1] == 13 )
{
content.erase(content.size()-1);
content_len -= 1;
}
}
}
@@ -257,19 +256,25 @@ void PostMultiParser::ReadContentToFileLoop()
bool has_boundary = false;
while( last!=-1 && !(has_boundary=HasBoundary()) )
while( last!=-1 )
{
content += last;
content_len += 1;
ReadChar();
if( content.size() > WINIX_POSTMULTI_OUTPUT_BUFFER + boundary.size() + 2 ) // +2 for the new line character
if( HasBoundary() )
{
tmp_file.write(content.c_str(), WINIX_POSTMULTI_OUTPUT_BUFFER);
content_len += WINIX_POSTMULTI_OUTPUT_BUFFER;
content.erase(0, WINIX_POSTMULTI_OUTPUT_BUFFER);
has_boundary = true;
break;
}
if( config->post_file_max != 0 && content_len > (size_t)config->post_file_max )
if( content.size() >= WINIX_POSTMULTI_OUTPUT_BUFFER )
{
tmp_file.write(content.c_str(), content.size());
content.clear();
}
if( config->post_file_max != 0 && content_len > config->post_file_max )
{
err = WINIX_ERR_INPUT_TOO_LARGE;
log << log1 << "PMP: content greater than " << config->post_file_max << " (skipping)" << logend;
@@ -283,7 +288,6 @@ bool has_boundary = false;
if( !content.empty() )
{
tmp_file.write(content.c_str(), content.size());
content_len += content.size();
content.clear();
}
}
@@ -296,9 +300,9 @@ void PostMultiParser::ReadContentToFile()
time_t t1, t2;
content.clear();
content.reserve(WINIX_POSTMULTI_OUTPUT_BUFFER + boundary.size());
content.reserve(WINIX_POSTMULTI_OUTPUT_BUFFER);
content_len = 0;
t1 = time(0);
t1 = time(0);
ReadContentToFileLoop();
@@ -343,23 +347,37 @@ void PostMultiParser::ReadContent()
ReadContentLoop();
log << log2 << "PMP: content size: " << content_len << " bytes" << logend;
LogFirst(content, 200);
if( !IsSubStringNoCase("pass", name.c_str()) )
LogFirst(content, config->log_post_value_size);
}
void PostMultiParser::AddNormalPostVar()
{
if( post_table->size() >= WINIX_POSTTABLE_MAXSIZE )
if( post_tab->size() >= WINIX_POSTTABLE_MAXSIZE )
{
err = WINIX_ERR_INPUT_TOO_LARGE;
log << log1 << "PMP: more than " << WINIX_POSTTABLE_MAXSIZE << " post variables (skipping)" << logend;
return;
}
std::pair<PostTable::iterator, bool> res = post_table->insert( std::make_pair(name, content) );
if( config->utf8 )
{
Ezc::UTF8ToWide(name, namew);
Ezc::UTF8ToWide(content, contentw);
}
else
{
AssignString(name, namew);
AssignString(content, contentw);
}
std::pair<PostTab::iterator, bool> res = post_tab->insert( std::make_pair(namew, contentw) );
bool added = res.second;
log << log2 << "PMP: POST var, name: \"" << name << "\"";
log << log2 << "PMP: POST var, name: \"" << namew << "\"";
if( !added )
log << log2 << " (skipped)";
@@ -370,19 +388,29 @@ void PostMultiParser::AddNormalPostVar()
void PostMultiParser::AddFilePostVar()
{
if( post_file_table->size() >= WINIX_POSTTABLE_MAXSIZE )
if( post_file_tab->size() >= WINIX_POSTTABLE_MAXSIZE )
{
err = WINIX_ERR_INPUT_TOO_LARGE;
log << log1 << "PMP: more than " << WINIX_POSTTABLE_MAXSIZE << " post file variables (skipping)" << logend;
return;
}
post_file_temp.filename = filename;
if( config->utf8 )
{
Ezc::UTF8ToWide(name, namew);
Ezc::UTF8ToWide(filename, post_file_temp.filename);
}
else
{
AssignString(name, namew);
AssignString(filename, post_file_temp.filename);
}
post_file_temp.tmp_filename = tmp_filename;
std::pair<PostFileTable::iterator, bool> res = post_file_table->insert( std::make_pair(name, post_file_temp) );
std::pair<PostFileTab::iterator, bool> res = post_file_tab->insert( std::make_pair(namew, post_file_temp) );
bool added = res.second;
log << log2 << "PMP: POST FILE var, name: \"" << name << "\"";
log << log2 << "PMP: POST FILE var, name: \"" << namew << "\"";
if( !added )
log << log2 << " (skipped)";
@@ -437,29 +465,33 @@ void PostMultiParser::CheckBoundaryEnd()
void PostMultiParser::CreateTmpFile()
{
char buf[100];
wchar_t buf[1024];
size_t buf_len = sizeof(buf)/sizeof(wchar_t);
if( config->auth_tmp_dir.empty() )
if( config->upload_dir.empty() )
{
log << log1 << "PMP: auth_tmp_dir is not set in the config" << logend;
log << log1 << "PMP: upload_dir is not set in the config" << logend;
err = WINIX_ERR_CANT_CREATE_FILE;
return;
}
sprintf(buf, "%s/winix_%u_%d_%u", config->auth_tmp_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
swprintf(buf, buf_len, L"%ls/tmp/pmp_%u_%d_%u", config->upload_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
tmp_filename_postfix += 1;
tmp_file.open(buf, std::ios_base::binary | std::ios_base::out);
tmp_filename = buf;
Ezc::WideToUTF8(tmp_filename, atmp_filename);
tmp_file.open(atmp_filename.c_str(), std::ios_base::binary | std::ios_base::out);
// !! dodac ustawienie chmod config.upload_files_chmod dla tymczasowego pliku
if( !tmp_file )
{
log << log1 << "PMP: can't create a temporary file: " << tmp_filename << logend;
log << log1 << "PMP: can't create a temporary file: " << atmp_filename << logend;
err = WINIX_ERR_CANT_CREATE_FILE;
return;
}
log << log3 << "PMP: using temporary file for the content: " << tmp_filename << logend;
log << log3 << "PMP: using temporary file for the content: " << atmp_filename << logend;
}
@@ -496,7 +528,7 @@ void PostMultiParser::ReadPart()
if( err != WINIX_ERR_OK && !filename.empty() )
{
log << log1 << "PMP: deleting the tmp file: " << tmp_filename << logend;
unlink(tmp_filename.c_str());
RemoveFile(tmp_filename);
}
}
@@ -531,7 +563,8 @@ void PostMultiParser::ReadChar()
Error PostMultiParser::Parse(FCGX_Stream * in_, PostTable & post_table_, PostFileTable & post_file_table_)
Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab & post_file_tab_)
{
in = in_;
last = 0;
@@ -539,8 +572,8 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTable & post_table_, PostFil
line_end_dos = false;
in_buffer_ind = WINIX_POSTMULTI_INPUT_BUFFER;
in_buffer_len = WINIX_POSTMULTI_INPUT_BUFFER;
post_table = &post_table_;
post_file_table = &post_file_table_;
post_tab = &post_tab_;
post_file_tab = &post_file_tab_;
tmp_filename_postfix = 1;
ReadChar();
@@ -554,8 +587,8 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTable & post_table_, PostFil
if( err != WINIX_ERR_OK )
{
post_table->clear();
post_file_table->clear();
post_tab->clear();
post_file_tab->clear();
if( err != WINIX_ERR_INPUT_TOO_LARGE && err != WINIX_ERR_CANT_CREATE_FILE )
log << log1 << "PMP: syntax error" << logend;

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucorepostmultiparser
#define headerfilecmslucorepostmultiparser
#ifndef headerfile_winix_core_postmultiparser
#define headerfile_winix_core_postmultiparser
#include <string>
#include <fcgiapp.h>
@@ -34,7 +34,7 @@ public:
~PostMultiParser();
void SetConfig(Config * pconfig);
Error Parse(FCGX_Stream * in_, PostTable & post_table_, PostFileTable & post_file_table_);
Error Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab & post_file_tab_);
private:
@@ -43,13 +43,14 @@ private:
FCGX_Stream * in;
unsigned char * in_buffer;
std::ofstream tmp_file;
std::string tmp_filename;
std::wstring tmp_filename;
std::string atmp_filename;
int tmp_filename_postfix;
size_t in_buffer_ind;
size_t in_buffer_len;
PostTable * post_table;
PostFileTable * post_file_table;
PostTab * post_tab;
PostFileTab * post_file_tab;
int last; // last read character
@@ -62,6 +63,7 @@ private:
Error err;
std::string name, filename;
std::wstring namew, contentw;
PostFile post_file_temp;
void LogFirst(const std::string & to_log, size_t len);

View File

@@ -2,19 +2,22 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorepostparser
#define headerfilecmslucorepostparser
#ifndef headerfile_winix_core_postparser
#define headerfile_winix_core_postparser
#include <fcgiapp.h>
#include <string>
#include "httpsimpleparser.h"
#include "requesttypes.h"
#include "misc.h"
#include "utf8.h"
#include "log.h"
#include "config.h"
@@ -22,7 +25,11 @@ class PostParser : public HttpSimpleParser
{
FCGX_Stream * in;
PostTable & post_table;
PostTab * post_tab;
std::wstring temp_name, temp_value;
bool input_as_utf8;
size_t log_value_size;
protected:
@@ -33,23 +40,72 @@ protected:
}
virtual void Parameter(std::string & name, std::string & value)
void CreateLog(bool param_added)
{
std::pair<PostTable::iterator, bool> res = post_table.insert( std::make_pair(name, value) );
log << log2 << "Method POST, name: \"" << name << "\", value: \"" << value << "\"";
log << log2 << "Method POST, name: \"" << temp_name << "\"";
if( res.second == false )
if( log_value_size > 0 && !IsSubStringNoCase(L"pass", temp_name.c_str()) )
{
log << ", value: ";
if( temp_value.size() > log_value_size )
log << "(first " << log_value_size << " characters) ";
log << "\"";
log.LogString(temp_value, log_value_size);
log << "\" (size: " << temp_value.size() << ")";
}
if( param_added == false )
log << log2 << " (skipped)";
log << log2 << logend;
}
virtual void Parameter(std::string & name, std::string & value)
{
if( input_as_utf8 )
{
Ezc::UTF8ToWide(name, temp_name);
Ezc::UTF8ToWide(value, temp_value);
}
else
{
AssignString(name, temp_name);
AssignString(value, temp_value);
}
std::pair<PostTab::iterator, bool> res = post_tab->insert( std::make_pair(temp_name, temp_value) );
CreateLog(res.second);
}
public:
PostParser(FCGX_Stream * in_, PostTable & post_table_) : in(in_), post_table(post_table_)
PostParser()
{
input_as_utf8 = false;
log_value_size = 0;
}
void UTF8(bool utf)
{
input_as_utf8 = utf;
}
void LogValueSize(size_t s)
{
log_value_size = s;
}
void Parse(FCGX_Stream * in_, PostTab & post_tab_)
{
in = in_;
post_tab = &post_tab_;
HttpSimpleParser::Parse();
}
};

View File

@@ -12,24 +12,25 @@
#include "log.h"
#include "rebus.h"
#include "misc.h"
#include "request.h"
#include "cur.h"
void Rebus::SetRequest(Request * prequest)
void Rebus::SetCur(Cur * pcur)
{
request = prequest;
cur = pcur;
}
bool Rebus::InitPair(int a, int b, Item & item)
{
char buffer[100];
wchar_t buffer[100];
size_t buffer_len = sizeof(buffer) / sizeof(wchar_t);
bool add = false;
if( a+b <= 15 )
{
sprintf(buffer, "%d+%d", a, b);
swprintf(buffer, buffer_len, L"%d+%d", a, b);
item.question = buffer;
item.answer = a+b;
add = true;
@@ -37,7 +38,7 @@ bool add = false;
if( a-b >= 0 )
{
sprintf(buffer, "%d-%d", a, b);
swprintf(buffer, buffer_len, L"%d-%d", a, b);
item.question = buffer;
item.answer = a-b;
add = true;
@@ -91,23 +92,23 @@ return &table[0] + i;
bool Rebus::IsAnswerOk(Rebus::Item * item, const std::string & answer)
bool Rebus::IsAnswerOk(Rebus::Item * item, const std::wstring & answer)
{
if( item == 0 )
return false;
char * end;
const char * a = answer.c_str();
wchar_t * end;
const wchar_t * a = answer.c_str();
a = SkipWhite(a);
int value = (int)strtol(a, &end, 10);
int value = (int)wcstol(a, &end, 10);
if( a == end )
// nothing has been read
return false;
log << log2 << "Rebus: your answer is: " << value << logend;
end = (char*)SkipWhite(end);
end = (wchar_t*)SkipWhite(end);
if( *end != 0 )
{
@@ -127,31 +128,29 @@ return result;
bool Rebus::CheckRebus()
{
if( !request->session )
if( !cur->session )
return false;
if( request->session->puser )
if( cur->session->puser )
// logged users don't have to use the rebus
return true;
if( request->session->rebus_checked )
if( cur->session->rebus_checked )
return true;
request->session->rebus_checked = true;
cur->session->rebus_checked = true;
if( !request->session->rebus_item )
if( !cur->session->rebus_item )
{
log << log1 << "Rebus: rebus not set" << logend;
return false;
}
std::string * answer = request->PostVar("rebus");
if( answer && IsAnswerOk(request->session->rebus_item, *answer) )
if( IsAnswerOk(cur->session->rebus_item, cur->request->PostVar(L"rebus")) )
return true;
log << log1 << "Rebus: rebus has an incorrect answer" << logend;
// don't add request->session->spam_score when the rebus has incorrect answer
// don't add cur->session->spam_score when the rebus has incorrect answer
// a user could have made a mistake
return false;

View File

@@ -7,15 +7,15 @@
*
*/
#ifndef headerfilecmslucorerebus
#define headerfilecmslucorerebus
#ifndef headerfile_winix_core_rebus
#define headerfile_winix_core_rebus
#include <string>
#include <vector>
class Request;
struct Cur;
class Rebus
@@ -25,21 +25,21 @@ public:
struct Item
{
int key;
std::string question;
std::wstring question;
int answer;
};
void SetRequest(Request * prequest);
void SetCur(Cur * pcur);
void Init();
Item * Rand();
bool IsAnswerOk(Item * item, const std::string & answer);
bool IsAnswerOk(Item * item, const std::wstring & answer);
bool CheckRebus();
private:
Request * request;
Cur * cur;
bool InitPair(int a, int b, Item & item);

View File

@@ -7,18 +7,12 @@
*
*/
#include <ctime>
#include <sys/stat.h>
#include <unistd.h>
#include "request.h"
#include "getparser.h"
#include "postparser.h"
#include "cookieparser.h"
#include "log.h"
#include "plugin.h"
#include "misc.h"
#include "db.h"
#include "functions/functionbase.h"
@@ -27,7 +21,6 @@
Request::Request() : char_empty(0)
{
id = 0;
Clear();
}
@@ -37,86 +30,68 @@ void Request::SetConfig(Config * pconfig)
}
void Request::Init()
{
compress.Init();
}
void Request::ClearPostFileTmp()
{
// deleting temporary files (if exists)
while( !post_file_table.empty() )
while( !post_file_tab.empty() )
{
const std::string & tmp_filename = post_file_table.begin()->second.tmp_filename;
const std::wstring & tmp_filename = post_file_tab.begin()->second.tmp_filename;
if( unlink(tmp_filename.c_str()) == 0 )
if( RemoveFile(tmp_filename) )
log << log3 << "Request: deleted tmp file: " << tmp_filename << logend;
post_file_table.erase(post_file_table.begin());
post_file_tab.erase(post_file_tab.begin());
}
}
void Request::Clear()
{
// warning: don't clear: in, out, err, env
// id is never 0
if( ++id == 0 )
++id;
get_table.clear();
post_table.clear();
post_file_table.clear();
cookie_table.clear();
ClearPostFileTmp();
get_tab.clear();
post_tab.clear();
post_file_tab.clear();
cookie_tab.clear();
method = none;
role = responder;
headers.str("");
page.str("");
debug.str("");
notify.str("");
headers.Clear();
page.Clear();
debug.Clear();
env_request_method = &char_empty;
env_request_uri = &char_empty;
env_http_cookie = &char_empty;
env_remote_addr = &char_empty;
env_http_host = &char_empty;
env_http_user_agent = &char_empty;
env_request_method = &char_empty;
env_request_uri = &char_empty;
env_http_cookie = &char_empty;
env_remote_addr = &char_empty;
env_http_host = &char_empty;
env_http_user_agent = &char_empty;
env_fcgi_role = &char_empty;
env_content_type = &char_empty;
env_http_accept_encoding = &char_empty;
env_fcgi_role = &char_empty;
env_content_type = &char_empty;
session = 0;
item_table.clear();
item_tab.clear();
item.Clear();
dir_table.clear();
dir_tab.clear();
last_item = &item;
is_item = false;
pfunction = 0;
param_table.clear();
function = 0; // !! dodac jakas empty funkcje
param_tab.clear();
status = WINIX_ERR_OK;
is_thread = false;
thread.Clear();
thread_tab.clear();
is_ticket = false;
ticket.Clear();
ticket_tab.clear();
notify_code = 0;
browser_msie = false;
redirect_to.clear();
x_sendfile.clear();
send_as_attachment = false;
plugin.Call(WINIX_REQUEST_CLEAR);
}
@@ -152,13 +127,13 @@ void Request::SetCookie(const char * name, long value, tm * expires)
bool Request::IsPostVar(const char * var)
bool Request::IsPostVar(const wchar_t * var)
{
PostTable::iterator p;
PostTab::iterator p;
p = post_table.find(var);
p = post_tab.find(var);
if( p == post_table.end() )
if( p == post_tab.end() )
return false;
return true;
@@ -166,23 +141,23 @@ return true;
std::string * Request::PostVar(const char * var)
const std::wstring & Request::PostVar(const wchar_t * var)
{
PostTable::iterator p = post_table.find(var);
PostTab::iterator p = post_tab.find(var);
if( p == post_table.end() )
return 0;
if( p == post_tab.end() )
return str_empty;
return &(p->second);
return p->second;
}
bool Request::PostVar(const char * var, std::string & result)
bool Request::PostVar(const wchar_t * var, std::wstring & result)
{
PostTable::iterator p = post_table.find(var);
PostTab::iterator p = post_tab.find(var);
if( p == post_table.end() )
if( p == post_tab.end() )
{
result.clear();
return false;
@@ -194,23 +169,29 @@ return true;
}
//
void Request::PrintGetTable()
std::wstring * Request::PostVarp(const wchar_t * var)
{
debug << "get_table: " << get_table.size() << "\n";
PostTab::iterator p = post_tab.find(var);
for(GetTable::iterator i = get_table.begin() ; i != get_table.end() ; ++i)
debug << " \"" << *i << "\"\n";
debug << std::endl;
if( p == post_tab.end() )
return 0;
return &p->second;
}
void Request::PrintGetTab()
{
debug << "get_tab: " << get_tab.size() << "\n";
for(GetTab::iterator i = get_tab.begin() ; i != get_tab.end() ; ++i)
debug << " \"" << *i << "\"\n";
debug << '\n';
}
/*
void Request::PrintEnv()
{
char ** e;
@@ -220,116 +201,16 @@ char ** e;
for( e = env ; *e ; ++e )
debug << ' ' << *e << "\n";
debug << std::endl;
}
void Request::PrintIn()
{
char buf[100];
int buf_len = sizeof(buf) / sizeof(char);
int len;
debug << "fcgi input:\n";
do
{
len = FCGX_GetStr(buf, buf_len - 1, in);
if( len != 0 )
{
buf[len] = 0;
debug << buf;
}
}
while( len == buf_len - 1 );
debug << std::endl;
}
const char * Request::SetEnvVar(const char * var)
{
const char * v = FCGX_GetParam(var, env);
if( v )
return v;
// char_empty contains '\0'
return &char_empty;
}
void Request::ReadEnvVariables()
{
// we store that values because FCGX_GetParam has O(n) complexity
// with this variables (env_*) we have O(1)
env_request_method = SetEnvVar("REQUEST_METHOD");
env_request_uri = SetEnvVar("REQUEST_URI");
env_http_cookie = SetEnvVar("HTTP_COOKIE");
env_remote_addr = SetEnvVar("REMOTE_ADDR");
env_http_host = SetEnvVar("HTTP_HOST");
env_http_user_agent = SetEnvVar("HTTP_USER_AGENT");
env_http_accept_encoding = SetEnvVar("HTTP_ACCEPT_ENCODING");
env_fcgi_role = SetEnvVar("FCGI_ROLE");
env_content_type = SetEnvVar("CONTENT_TYPE");
}
void Request::CheckIE()
{
char * msie = strstr(env_http_user_agent, "MSIE");
if( msie )
browser_msie = true;
else
browser_msie = false;
}
void Request::CheckKonqueror()
{
char * kon = strstr(env_http_user_agent, "Konqueror");
if( kon )
browser_konqueror = true;
else
browser_konqueror = false;
}
void Request::CheckMethod()
{
method = none;
if( ToSmall(env_request_method[0]) == 'g' )
method = get;
else
if( ToSmall(env_request_method[0]) == 'p' )
method = post;
// default we assume 'responder'
role = responder;
if( ToSmall(env_fcgi_role[0]) == 'a' )
role = authorizer;
debug << '\n';
}
*/
bool Request::AllPostVarEmpty()
{
PostTable::iterator i;
PostTab::iterator i;
for(i=post_table.begin() ; i!=post_table.end() ; ++i)
for(i=post_tab.begin() ; i!=post_tab.end() ; ++i)
if( !i->second.empty() )
return false;
@@ -338,224 +219,12 @@ return true;
// !! czy te parsery powinny byc skladowymi Request?
void Request::ReadParameters()
bool Request::IsParam(const wchar_t * param_name)
{
// !! wrzucic jako skladowa klasy
GetParser get_parser(env_request_uri, get_table);
get_parser.Parse();
if( method == post )
ParamTab::iterator i;
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
{
if( IsSubStringNoCase("multipart/form-data", env_content_type) )
{
log << log3 << "Request: post content type: multipart/form-data" << logend;
post_multi_parser.SetConfig(config);
post_multi_parser.Parse(in, post_table, post_file_table);
}
else
{
// !! wrzucic jako skladowa klasy
PostParser post_parser(in, post_table);
post_parser.Parse();
}
}
CookieParser cookie_parser(env_http_cookie, cookie_table);
cookie_parser.Parse();
accept_encoding_parser.Parse(env_http_accept_encoding);
}
void Request::StandardLog()
{
log.PutDate(log1);
log << env_remote_addr << ' ' << env_request_method << ' ';
log << env_http_host << env_request_uri << ' ' << env_http_user_agent << logend;
}
// reading everything
void Request::Read()
{
ReadEnvVariables();
CheckMethod();
StandardLog();
ReadParameters();
CheckIE();
if( role == authorizer )
log << log3 << "Request: fast cgi role: authorizer" << logend;
CheckKonqueror();
}
void Request::SendSessionCookie()
{
if( !session || session->id==0 )
return;
if( !session->puser || !session->remember_me )
{
SetCookie(config->http_session_id_name.c_str(), session->id);
return;
}
time_t t = time(0) + config->session_remember_max_idle;
tm * expires = localtime(&t);
if( !expires )
{
// oops, something wrong
SetCookie(config->http_session_id_name.c_str(), session->id);
return;
}
SetCookie(config->http_session_id_name.c_str(), session->id, expires);
}
void Request::SendHeaders(bool compressing, Header header)
{
if( send_as_attachment )
FCGX_PutS("Content-Disposition: attachment\r\n", out);
if( !redirect_to.empty() )
{
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);
FCGX_FPrintF(out, "Location: %s\r\n", redirect_to.c_str());
log << log2 << "Redirect to: " << redirect_to << logend;
}
else
if( !x_sendfile.empty() )
{
FCGX_FPrintF(out, "X-LIGHTTPD-send-file: %s\r\n", x_sendfile.c_str());
FCGX_PutS("Status: 200 OK\r\n", out);
log << log2 << "Sending file: " << x_sendfile << logend;
}
else
{
switch(header)
{
case h_404:
FCGX_PutS("Status: 404 Not Found\r\n", out);
FCGX_PutS("Content-Type: text/html\r\n", out);
log << log2 << "Request: response: 404 Not Found" << logend;
break;
case h_403:
FCGX_PutS("Status: 403 Forbidden\r\n", out);
FCGX_PutS("Content-Type: text/html\r\n", out);
log << log2 << "Request: response: 403 Forbidden" << logend;
break;
default:
FCGX_PutS("Status: 200 OK\r\n", out);
if( role != authorizer )
FCGX_PutS("Content-Type: text/html\r\n", out);
}
}
if( compressing )
FCGX_PutS("Content-Encoding: deflate\r\n", out);
FCGX_PutS(headers.str().c_str(), out);
FCGX_PutS("\r\n", out);
}
void Request::AddDebugInfo()
{
const std::string & d = debug.str();
if( !d.empty() )
{
page << "\n<!--\n";
page << d;
page << "\n-->\n";
}
}
// !! to powinno isc do kontrolera app
void Request::SendPage(bool compressing, const std::string & source_ref)
{
const std::string * source = &source_ref;
bool raw = is_item && item.content_type == Item::ct_raw && status == WINIX_ERR_OK &&
pfunction && (pfunction->fun.url == "cat" || pfunction->fun.url == "run");
if( config->html_filter && !raw )
{
html_filter.TrimWhite(true);
html_filter.BreakLines(60);
html_filter.InsertTabs(2);
html_filter.CheckOrphans(HTMLFilter::lang_pl, HTMLFilter::orphan_160space);
html_filter.Filter(*source, clean_html);
source = &clean_html;
}
if( compressing )
compress.CompressAndPut(source->c_str(), source->length(), out);
else
FCGX_PutS(source->c_str(), out);
}
void Request::SendAll()
{
const std::string & source = page.str();
Header header = h_200;
bool compressing = config->compression && role == responder && redirect_to.empty() && x_sendfile.empty() &&
!browser_msie && !browser_konqueror &&
accept_encoding_parser.AcceptDeflate() && source.size() >= 512;
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;
SendSessionCookie();
SendHeaders(compressing, header);
if( !redirect_to.empty() || !x_sendfile.empty() )
// if there is a redirect or a file to send then we do not send a content
return;
if( header == h_200 && role == authorizer && is_item && item.auth != Item::auth_none )
// if there is an item and the item has 'file' storage we do not send a content
return;
// adding debug info if exists
AddDebugInfo();
// sending content
SendPage(compressing, source);
}
bool Request::IsParam(const char * param_name)
{
ParamTable::iterator i;
for(i=param_table.begin() ; i!=param_table.end() ; ++i)
{
// !! make sure that exists std::string::operator==(const char*)
// (optimization)
if( i->name == param_name )
return true;
}
@@ -564,22 +233,39 @@ return false;
}
const std::string & Request::ParamValue(const char * param_name)
bool Request::IsParam(const std::wstring & param_name)
{
ParamTable::iterator i;
for(i=param_table.begin() ; i!=param_table.end() ; ++i)
ParamTab::iterator i;
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
{
if( i->name == param_name )
return true;
}
return false;
}
const std::wstring & Request::ParamValue(const wchar_t * param_name)
{
ParamTab::iterator i;
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
{
if( i->name == param_name )
{
return i->value;
}
}
return str_empty;
}
const std::wstring & Request::ParamValue(const std::wstring & param_name)
{
return ParamValue(param_name.c_str());
}

View File

@@ -7,31 +7,25 @@
*
*/
#ifndef headerfilecmslucorerequest
#define headerfilecmslucorerequest
#ifndef headerfile_winix_core_request
#define headerfile_winix_core_request
#include <fcgiapp.h>
#include <sstream>
#include <vector>
#include <iomanip>
#include "requesttypes.h"
#include "session.h"
#include "item.h"
#include "error.h"
#include "thread.h"
#include "compress.h"
#include "acceptencodingparser.h"
#include "htmlfilter.h"
#include "postmultiparser.h"
#include "ticket.h"
#include "config.h"
#include "textstream.h"
#include "templates/htmltextstream.h"
class FunctionBase;
struct Request
{
// request id
@@ -40,23 +34,20 @@ struct Request
// it's used for some optimalizations e.g. in templates
size_t id;
FCGX_Stream * in, * out, * err;
FCGX_ParamArray env; // defined as 'char **'
enum Method { get, post, none } method;
// !! moze pozbyc sie tego none?
enum Method { get, post, head, none } method;
enum Role { responder, authorizer } role;
// headers, page and debug
// notify (for mailing)
std::ostringstream headers, page, debug, notify;
//std::ostringstream headers, page, debug;
TextStream<std::string> headers;
HtmlTextStream page, debug;
GetTable get_table;
PostTable post_table;
PostFileTable post_file_table;
CookieTable cookie_table;
// raw parameters
GetTab get_tab;
PostTab post_tab;
PostFileTab post_file_tab;
CookieTab cookie_tab;
// environment variables
// they are not null -- when the server doesn't have such a variable
@@ -77,125 +68,81 @@ struct Request
// true if the browser is Konqueror
bool browser_konqueror;
// current session
// is set after calling session_manager.SetSession()
Session * session;
// current directory
std::vector<Item*> dir_table;
std::vector<Item*> dir_tab;
// true if a file exists
bool is_item;
// this item is used for many purposes such as editing, adding an item etc.
// current file (if exists)
Item item;
// current winix function
// null if there is no a function
FunctionBase * pfunction;
FunctionBase * function;
// parameters (name:value)
ParamTable param_table;
ParamTab param_tab;
// request status
Error status;
// last notify
int notify_code;
// items in the current directory
// maybe without contents?
std::vector<Item> item_table;
// current thread (if exists)
bool is_thread;
Thread thread;
std::vector<Thread> thread_tab;
// current ticket (if exists)
bool is_ticket;
Ticket ticket;
std::vector<Ticket> ticket_tab;
// usually items in the current directory (depends on the function)
std::vector<Item> item_tab;
// if not empty means an address for redirecting to
std::string redirect_to;
std::wstring redirect_to;
std::string aredirect_to;
// send header X-LIGHTTPD-send-file with path to a file
std::string x_sendfile;
std::wstring x_sendfile;
// send as attachment (causing header: content-disposition: attachment)
bool send_as_attachment;
// for debugging
void PrintGetTable();
void PrintEnv();
void PrintIn();
// this is a pointer either to the item (if exists) or to the last directory
Item * last_item;
Request();
void ClearPostFileTmp();
void SetConfig(Config * pconfig);
void Clear();
void Init();
// for debugging
void PrintGetTab();
//void PrintEnv();
bool IsParam(const char * param_name);
const std::string & ParamValue(const char * param_name); // returns empty string if there is no such a parameter
bool IsParam(const wchar_t * param_name);
bool IsParam(const std::wstring & param_name);
const std::wstring & ParamValue(const wchar_t * param_name); // returns empty string if there is no such a parameter
const std::wstring & ParamValue(const std::wstring & param_name); // returns empty string if there is no such a parameter
void SetCookie(const char * name, const char * value, tm * expires = 0);
void SetCookie(const char * name, long value, tm * expires = 0);
bool IsPostVar(const char * var);
std::string * PostVar(const char * var); // it can return null when there is no such a post variable
bool PostVar(const char * var, std::string & result);
bool IsPostVar(const wchar_t * var);
const std::wstring & PostVar(const wchar_t * var); // !! zamienic na referencje nie do sta³ej (bez const)
bool PostVar(const wchar_t * var, std::wstring & result);
std::wstring * PostVarp(const wchar_t * var);
bool AllPostVarEmpty(); // returning true if all post vars are empty
void ReadEnvVariables();
void CheckMethod();
void ReadParameters();
void Read();
void SendAll();
void SendNotify();
void SetConfig(Config * pconfig);
private:
Config * config;
enum Header
{
h_200,
h_404,
h_403
};
void ClearPostFileTmp();
bool CanUse(long user_id, const char * group_name);
void SendSessionCookie();
void CheckIE();
void CheckKonqueror();
void SendHeaders(bool compressing, Header header);
void AddDebugInfo();
void SendPage(bool compressing, const std::string & source_ref);
// used to set some env_* variables into it, when the server didn't set that variable
// it contains '\0'
// contains '\0'
// used to set env_* pointers to the empty value
const char char_empty;
// used in ParamValue(const char * param_name) when there is no such a param
const std::string str_empty;
PostMultiParser post_multi_parser;
const char * SetEnvVar(const char * var);
void StandardLog();
Compress compress;
AcceptEncodingParser accept_encoding_parser;
HTMLFilter html_filter;
// html after filtering
std::string clean_html;
// used in ParamValue() and PostVar() when there is no such a param
const std::wstring str_empty;
};

View File

@@ -7,38 +7,41 @@
*
*/
#ifndef headerfilecmslucorerequesttypes
#define headerfilecmslucorerequesttypes
#ifndef headerfile_winix_core_requesttypes
#define headerfile_winix_core_requesttypes
#include <string>
#include <vector>
#include <map>
#define WINIX_POSTTABLE_MAXSIZE 20
// !! narazie uzywane tylko w post multi parserze
// dodac do zwyklego parsera post
#define WINIX_POSTTABLE_MAXSIZE 50
struct PostFile
{
std::string filename; // original file name
std::string tmp_filename; // file with content (in /tmp)
std::wstring filename; // original file name
std::wstring tmp_filename; // file with content (in /tmp)
};
// parameters from get name:value
struct Param
{
std::string name;
std::string value;
std::wstring name;
std::wstring value;
};
// some global types used by Request class
typedef std::vector<std::string> GetTable;
typedef std::map<std::string, std::string> PostTable;
typedef std::map<std::string, PostFile> PostFileTable;
typedef std::map<std::string, std::string> CookieTable;
typedef std::vector<Param> ParamTable;
typedef std::vector<std::wstring> GetTab;
typedef std::map<std::wstring, std::wstring> PostTab;
typedef std::map<std::wstring, PostFile> PostFileTab;
typedef std::vector<Param> ParamTab;
typedef std::map<std::string, std::string> CookieTab;

385
core/run.cpp Executable file
View File

@@ -0,0 +1,385 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/wait.h>
#include "run.h"
#include "log.h"
Run::Run()
{
Clear();
}
void Run::Clear()
{
parlen = 0;
envlen = 0;
command = 0;
last_status = 0;
last_return = 255;
}
void Run::SetName()
{
size_t i=0;
while( command[i] )
i += 1;
while( i>0 && command[i-1]!='/' )
i -= 1;
par[0] = const_cast<char*>(command + i);
}
void Run::Par(const char * p)
{
if( parlen < WINIX_RUN_MAX_PARAMETERS )
{
// they will be copied (fork)
// the first (zero) parameter is a program name
par[1 + parlen++] = const_cast<char*>(p);
}
}
void Run::Env(const char * e)
{
if( envlen < WINIX_RUN_MAX_PARAMETERS )
{
// they will be copied (fork)
env[envlen++] = const_cast<char*>(e);
}
}
void Run::Cmd(const char * c)
{
command = c;
SetName();
}
void Run::Par(const std::string & p)
{
Par(p.c_str());
}
void Run::Env(const std::string & e)
{
Env(e.c_str());
}
void Run::Cmd(const std::string & c)
{
Cmd(c.c_str());
}
int Run::LastStatus()
{
return last_status;
}
int Run::LastReturn()
{
return last_return;
}
void Run::Write(const char * in, size_t inlen)
{
ssize_t len;
while( inlen > 0 )
{
len = write(desout[1], in, inlen);
if( len < 0 || len > (ssize_t)inlen )
{
// something wrong
last_status = 3;
break;
}
in += len;
inlen -= len;
}
}
void Run::Read(std::string & out)
{
char buf[1024];
size_t buflen = sizeof(buf) / sizeof(char);
ssize_t len;
do
{
len = read(desin[0], buf, buflen);
if( len < 0 || len > (ssize_t)buflen )
{
// something wrong
last_status = 4;
break;
}
if( len > 0 )
out.append(buf, len);
}
while( len > 0 );
}
void Run::ChildThrow()
{
if( dup2(desout[0], 0) == -1 )
return;
if( dup2(desin[1], 1) == -1 )
return;
close(2);
close(desin[0]);
close(desout[1]);
par[parlen+1] = 0;
env[envlen] = 0;
execve(command, par, env);
// if we are here then there is something wrong (execve failed)
}
void Run::Child()
{
try
{
ChildThrow();
}
catch(...)
{
}
exit(255);
}
bool Run::CreatePipes()
{
int res = pipe(desin);
if( res != 0 )
{
log << log1 << "Run: pipe failed (desin)" << logend;
last_status = 1;
return false;
}
res = pipe(desout);
if( res != 0 )
{
log << log1 << "Run: pipe failed (desout)" << logend;
last_status = 1;
close(desin[0]);
close(desin[1]);
return false;
}
return true;
}
bool Run::Fork()
{
childpid = fork();
if( childpid == -1 )
{
log << log1 << "Run: fork failed" << logend;
last_status = 2;
close(desin[0]);
close(desin[1]);
close(desout[0]);
close(desout[1]);
return false;
}
if( childpid == 0 )
Child();
return true;
}
void Run::WriteRead(const char * in, size_t inlen, std::string * out)
{
if( in && inlen>0 )
Write(in, inlen);
close(desout[1]);
if( out )
Read(*out);
close(desin[0]);
}
void Run::CheckStatus()
{
int status;
pid_t res = waitpid(childpid, &status, 0);
if( res == -1 )
{
log << log1 << "Run: waitpid failed" << logend;
last_status = 6;
}
else
{
if( WIFEXITED(status) )
{
last_return = WEXITSTATUS(status);
}
else
{
if( WIFCONTINUED(status) )
log << log1 << "Run: child error: WIFCONTINUED" << logend;
else
if( WIFSIGNALED(status) )
log << log1 << "Run: child error: WIFSIGNALED" << logend;
else
if( WIFSTOPPED(status) )
log << log1 << "Run: child error: WIFSTOPPED" << logend;
last_status = 5;
}
}
}
int Run::Go(const char * in, size_t inlen, std::string * out)
{
last_status = 0;
last_return = 255;
if( out )
out->clear();
if( !command )
{
last_status = 7;
return last_return;
}
if( !CreatePipes() )
return last_return;
if( !Fork() )
return last_return;
// here goes the parent
close(desin[1]);
close(desout[0]);
WriteRead(in, inlen, out);
CheckStatus();
if( last_status != 0 )
log << log1 << "Run: a problem with the command, last_status: " << last_status << logend;
return last_return;
}
int Run::Go(const char * in, size_t inlen, std::string & out)
{
return Go(in, inlen, &out);
}
int Run::Go(const char * in, std::string & out)
{
size_t len = strlen(in);
return Go(in, len, &out);
}
int Run::Go(const char * in, size_t inlen)
{
return Go(in, inlen, 0);
}
int Run::Go(const char * in)
{
size_t len = strlen(in);
return Go(in, len, 0);
}
int Run::Go()
{
return Go(0, 0, 0);
}
int Run::Go(const std::string in, std::string & out)
{
return Go(in.c_str(), in.size(), &out);
}
int Run::Go(const std::string in)
{
return Go(in.c_str(), in.size(), 0);
}
int Run::Go(std::string & out)
{
return Go(0, 0, &out);
}

163
core/run.h Executable file
View File

@@ -0,0 +1,163 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_run
#define headerfile_winix_core_run
#include <string>
#include <cstdio>
/*
how many parameters and environment variables can be passed to a program
*/
#define WINIX_RUN_MAX_PARAMETERS 30
/*
objects of this class allows you to run an external program
when you call Go() then:
1. winix creates pipes for communicating with a child process
2. then winix fork()
3. the child process execve() the specified command
4. winix (parent) sends 'in' to the standard input of the child process
5. after sending it closes the descriptor so the child sees it as end-of-file
6. now winix reads what the child sends to standard output (until EOF)
7. winix waitpid() for the child
8. Go() returns
*/
class Run
{
public:
Run();
/*
clearing parameters, environment variables and the command
(and clearing LastStatus and LastResult)
so you can call another different program now
*/
void Clear();
/*
setting parameters
each parameter should be passed in different call to Par() method
sample:
if you want to call from your shell:
$ myprog -a -b -f "test file"
you should call Par() in this way:
Par("-a");
Par("-b");
Par("test file"); // apostrophes are not needed here
arguments passed to Par() should not be changed afterwards, this method does not copy them anywhere
it uses only the pointer
*/
void Par(const char * p);
void Par(const std::string & p);
/*
setting environment variables
one variable per one Env() call
arguments passed to Env() should not be changed afterwards, this method does not copy them anywhere
it uses only the pointer
*/
void Env(const char * e);
void Env(const std::string & e);
/*
full path to command you want to execute
arguments passed to Cmd() should not be changed afterwards, this method does not copy them anywhere
it uses only the pointer
*/
void Cmd(const char * c);
void Cmd(const std::string & c);
/*
executing the command
you should call Par(), Env() and Cmd() beforehand
*/
int Go(const char * in, size_t inlen, std::string & out);
int Go(const char * in, std::string & out);
int Go(const char * in, size_t inlen);
int Go(const char * in);
int Go(const std::string in, std::string & out);
int Go(const std::string in);
int Go(std::string & out);
int Go();
/*
last status:
0 - ok (program was successfully called)
1 - pipe failed
2 - fork failed
3 - write failed
4 - read failed
5 - child process has done something wrong (caught a signal etc.)
6 - waitpid failed
7 - the command is not set (call Cmd method first)
*/
int LastStatus();
/*
the code which the command returned (usually "0" means no errors found)
if LastStatus is different from zero then LastReturn always returns 255
(so you don't have to check LastStatus() first)
*/
int LastReturn();
private:
int Go(const char * in, size_t inlen, std::string * out);
void SetName();
void CheckStatus();
void WriteRead(const char * in, size_t inlen, std::string * out);
bool CreatePipes();
bool Fork();
void ChildThrow();
void Child();
void Write(const char * in, size_t inlen);
void Read(std::string & out);
int last_status;
// the return code returned by a program (if last_status==0)
// if last_status!=0 then last_return is 255
int last_return;
int desin[2];
int desout[2];
char * par[WINIX_RUN_MAX_PARAMETERS + 2];
char * env[WINIX_RUN_MAX_PARAMETERS + 1];
const char * command;
size_t parlen;
size_t envlen;
pid_t childpid;
};
#endif

View File

@@ -8,17 +8,22 @@
*/
#include "session.h"
#include "misc.h"
Session::Session()
{
SetTimeToNow();
Clear();
}
void Session::SetTimeToNow()
{
time = std::time(0);
tm_time = *std::localtime(&time);
tm_time = Time(time);
last_time = time;
tm_last_time = tm_time;
@@ -28,29 +33,18 @@ Session::Session()
}
// this doesn't clear times
void Session::Clear()
{
id = 0;
time = 0;
puser = 0;
rebus_item = 0;
id = 0;
time = 0;
puser = 0;
rebus_item = 0;
rebus_checked = false;
remember_me = false;
new_session = true;
spam_score = 0;
// dir_old.clear();
remember_me = false;
new_session = true;
spam_score = 0;
plugin_data.Resize(0);
}
bool Session::operator==(const Session & s) const
{
return id == s.id;
}
bool Session::operator<(const Session & s) const
{
return id < s.id;
}

View File

@@ -2,13 +2,13 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoresession
#define headerfilecmslucoresession
#ifndef headerfile_winix_core_session
#define headerfile_winix_core_session
#include <ctime>
#include "item.h"
@@ -16,11 +16,16 @@
#include "user.h"
#include "plugindata.h"
#include "rebus.h"
#include "textstream.h"
// when deleting Sessions you should set request.session into the session object as well
// this allows to delete plugins session data
// because a session object has plugin_data object
// and in its destructor the plugin.Call(WINIX_SESSION_REMOVE) is called
struct Session
{
// 0 - means that there is no session
// 0 - means that there is a temporary session
long id;
// true if the session was created now
@@ -51,21 +56,20 @@ struct Session
Rebus::Item * rebus_item;
bool rebus_checked;
//std::string dir_old;
int spam_score;
PluginData plugin_data;
// -------------------
// buffer for the session log
TextStream<std::wstring> log_buffer;
Session();
void SetTimeToNow();
void Clear();
bool operator==(const Session & s) const;
bool operator<(const Session & s) const;
void DecTimer(int & timer);
};

View File

@@ -9,27 +9,81 @@
#include "sessioncontainer.h"
#include "log.h"
#include "misc.h"
SessionContainer::SessionContainer()
{
table_size = 0;
}
void SessionContainer::SetCur(Cur * pcur)
{
cur = pcur;
}
void SessionContainer::SetConfig(Config * pconfig)
{
config = pconfig;
}
void SessionContainer::SetTmpSession(Session * psession)
{
tmp_session = psession;
}
void SessionContainer::Clear()
{
table.clear();
Table::iterator i = table.begin();
log << log3 << "SC: deleting all sessions" << logend;
// don't use table.clear();
// because plugins session data would not be erased
// we must set cur->session for each session and then delete it
while( i != table.end() )
{
cur->session = &(*i);
table.erase(i++);
}
// erasing indexes
index_id.clear();
index_time.clear();
table_size = 0;
cur->session = tmp_session;
}
void SessionContainer::SetLastContainer(LastContainer * plast_container)
void SessionContainer::EraseById(IdIterator i)
{
last_container = plast_container;
Session * old_session = tmp_session;
if( cur->session != &(*i->second) )
old_session = cur->session;
cur->session = &(*i->second);
log << log4 << "SC: deleting session, id: " << i->second->id << logend;
table.erase(i->second);
index_id.erase(i);
table_size -= 1;
cur->session = old_session;
}
SessionContainer::TableSize SessionContainer::Size()
size_t SessionContainer::Size()
{
return table.size();
// don't use table.size() as it has O(n) complexity on FreeBSD
return table_size;
}
@@ -51,19 +105,35 @@ Session & SessionContainer::Back()
}
SessionContainer::IdIterator SessionContainer::IdBegin()
{
return index_id.begin();
}
SessionContainer::IdIterator SessionContainer::IdEnd()
{
return index_id.end();
}
bool SessionContainer::PushBack(const Session & session)
{
if( index_id.find(session.id) != index_id.end() )
// that element already exists
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(session.id, table.end()) );
if( !index_id_res.second )
{
// that element already exists (was not inserted now)
return false;
}
Iterator last = table.insert(table.end(), session);
index_id.insert( std::make_pair(session.id, last) );
index_time.insert( std::make_pair(session.last_time, last) );
index_id_res.first->second = last;
table_size += 1;
log << log3 << "SC: added session, id: " << session.id << logend;
return true;
}
@@ -84,78 +154,8 @@ return i->second;
void SessionContainer::DelFirstByTimeInterval(time_t interval, bool skip_remember_flag)
{
IndexTime::iterator i = index_time.begin();
IndexTime::iterator iold;
time_t limit = std::time(0) - interval;
while( i != index_time.end() && i->second->last_time < limit )
{
long id = i->second->id;
iold = i;
++i; // incrementing before deleting old one
if( skip_remember_flag && iold->second->puser && iold->second->remember_me )
// don't delete sessions which have 'remember_me' flag (and a user is logged)
continue;
if( iold->second->puser )
last_container->UserLogout(iold->second->puser->id, iold->second->id);
// we're logging session.id (call this before table.erase())
DelFromIdIndex(iold->second);
table.erase(iold->second);
index_time.erase(iold);
log << log3 << "SC: deleted index_time for session id: " << id << logend;
log << log3 << "SC: deleted session, id: " << id << logend;
}
}
void SessionContainer::DelFromIdIndex(SessionContainer::Iterator iter)
{
IndexId::iterator i;
for( i = index_id.begin() ; i!=index_id.end() ; ++i)
{
if( i->second == iter )
{
index_id.erase(i);
log << log3 << "SC: deleted index_id for session id: " << iter->id << logend;
break;
}
}
}
void SessionContainer::UpdateLastTime(SessionContainer::Iterator iter, time_t new_time)
{
IndexTime::iterator i = index_time.lower_bound(iter->last_time);
bool found = false;
for( ; i != index_time.end() ; ++i)
{
if( i->second == iter )
{
index_time.erase(i);
index_time.insert( std::make_pair(new_time, iter) );
iter->last_time = new_time;
iter->tm_last_time = *std::localtime(&new_time);
log << log3 << "SC: last time and the time index for session id: " << iter->id << " updated" << logend;
found = true;
break;
}
}
if( !found )
log << log1 << "SC: cannot update the time, time index not found for session id: " << iter->id << logend;
}

View File

@@ -7,60 +7,66 @@
*
*/
#ifndef headerfilecmslucoresessioncontainer
#define headerfilecmslucoresessioncontainer
#ifndef headerfile_winix_core_sessioncontainer
#define headerfile_winix_core_sessioncontainer
#include <list>
#include <map>
#include <ctime>
#include "session.h"
#include "lastcontainer.h"
#include "cur.h"
#include "config.h"
class SessionContainer
{
public:
typedef std::list<Session> Table;
typedef Table::iterator Iterator;
typedef Table::size_type TableSize;
typedef std::map<long, Iterator> IndexId;
typedef std::multimap<time_t, Iterator> IndexTime;
void SetLastContainer(LastContainer * plast_container);
private:
LastContainer * last_container;
Table table;
IndexId index_id;
IndexTime index_time;
void DelFromIdIndex(Iterator iter);
public:
// when deleting Sessions you should set request.session into the session object
// this allows to delete plugins session data
// because a session object has plugin_data object
// and in its destructor the plugin.Call(WINIX_SESSION_REMOVE) is called
typedef std::list<Session> Table;
typedef Table::iterator Iterator;
typedef std::map<long, Iterator> IndexId;
typedef IndexId::iterator IdIterator;
SessionContainer();
void SetCur(Cur * pcur);
void SetConfig(Config * pconfig);
void SetTmpSession(Session * psession);
void Clear();
TableSize Size();
Iterator Begin();
Iterator End();
size_t Size();
Iterator Begin();
Iterator End();
Session & Back();
bool PushBack(const Session & session);
Iterator FindById(long);
void DelFirstByTimeInterval(time_t interval, bool skip_remember_flag = true);
IdIterator IdBegin();
IdIterator IdEnd();
void EraseById(IdIterator i);
private:
Table table;
IndexId index_id;
Cur * cur;
Config * config;
Session * tmp_session;
// in FreeBSD implementation (GCC) list::size() has linear complexity
// so we use our own table_size with O(1)
size_t table_size;
void UpdateLastTime(Iterator iter, time_t new_time);
};

View File

@@ -22,19 +22,26 @@
SessionManager::SessionManager()
{
session_checker = 0;
temporary_session.id = 0;
session = &temporary_session;
session_tab.SetTmpSession(&temporary_session);
// thread work mode
work_mode = 1;
}
void SessionManager::SetRequest(Request * prequest)
void SessionManager::SetCur(Cur * pcur)
{
request = prequest;
cur = pcur;
session_tab.SetCur(pcur);
}
void SessionManager::SetConfig(Config * pconfig)
{
config = pconfig;
session_tab.SetConfig(pconfig);
}
@@ -43,15 +50,23 @@ void SessionManager::SetSystem(System * psystem)
system = psystem;
}
void SessionManager::SetLastContainer(LastContainer * plast_container)
{
session_table.SetLastContainer(plast_container);
last_container = plast_container;
}
size_t SessionManager::Size()
{
return session_tab.Size();
}
bool SessionManager::IsSession(long id)
{
if( session_table.FindById(id) == session_table.End() )
if( session_tab.FindById(id) == session_tab.End() )
return false;
return true;
@@ -90,52 +105,44 @@ return id;
void SessionManager::CreateTemporarySession()
{
SessionContainer::Iterator i = session_table.FindById( 0 );
if( i == session_table.End() )
{
Session s;
s.id = 0;
session_table.PushBack(s);
request->session = &session_table.Back();
}
else
{
request->session = &(*i);
}
}
void SessionManager::CreateSession()
{
Session s;
int attempts = 100;
int attempts = 100;
bool added = false;
for( ; attempts > 0 ; --attempts )
new_session.SetTimeToNow();
new_session.Clear();
if( config->session_max == 0 || session_tab.Size() < config->session_max )
{
s.id = CreateSessionId();
bool added = session_table.PushBack(s);
if( added )
for( ; !added && attempts > 0 ; --attempts )
{
request->session = &session_table.Back();
request->session->new_session = true;
log << log2 << "SM: created a new session: " << request->session->id << logend;
return;
new_session.id = CreateSessionId();
added = session_tab.PushBack(new_session);
}
}
// there is a problem with generating a new session id
// we do not set a session cookie
CreateTemporarySession();
log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend;
else
{
log << log2 << "SM: sessions limit exceeded (" << config->session_max << ")" << logend;
}
if( added )
{
session = &session_tab.Back();
session->new_session = true;
log << log2 << "SM: created a new session: " << session->id << logend;
}
else
{
// there is a problem with generating a new session id
// we do not set a session cookie
session = &temporary_session;
session->SetTimeToNow();
session->Clear(); // !! uwaga ten Clear wyczysci plugins data
session->new_session = false; // temporary session was initialized at the beginning
log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend;
}
}
@@ -143,24 +150,25 @@ int attempts = 100;
bool SessionManager::SetSessionFromCookie(const std::string & cookie)
{
long id = atol(cookie.c_str());
SessionContainer::Iterator s = session_table.FindById(id);
long id = Tol(cookie.c_str());
SessionContainer::Iterator s = session_tab.FindById(id);
if( s == session_table.End() )
if( s == session_tab.End() )
return false;
// that session is in the table
request->session = &(*s);
request->session->new_session = false;
session_table.UpdateLastTime(s, std::time(0));
session = &(*s);
session->new_session = false;
session->last_time = std::time(0);
session->tm_last_time = Time(session->last_time);
if( request->method == Request::get )
request->session->last_time_get = request->session->last_time;
if( cur->request->method == Request::get )
session->last_time_get = session->last_time;
log << log2 << "SM: session: " << s->id;
log << log2 << "SM: session: " << session->id;
if( request->session->puser )
log << log2 << ", user: " << request->session->puser->name << ", id: " << request->session->puser->id;
if( session->puser )
log << log2 << ", user: " << session->puser->name << ", id: " << session->puser->id;
log << log2 << logend;
@@ -171,9 +179,9 @@ return true;
void SessionManager::SetSession()
{
CookieTable::iterator i = request->cookie_table.find(config->http_session_id_name);
CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name);
if( i == request->cookie_table.end() )
if( i == cur->request->cookie_tab.end() )
{
CreateSession();
}
@@ -183,74 +191,65 @@ void SessionManager::SetSession()
{
// there is no such a session
// deleting the old cookie
request->cookie_table.erase(i);
cur->request->cookie_tab.erase(i);
// and creating a new one
CreateSession();
}
}
// request->session is set now
if( request->session->new_session )
{
request->session->plugin_data.Resize(plugin.Size());
plugin.Call(WINIX_SESSION_CREATED);
}
plugin.Call(WINIX_SESSION_CHANGED);
}
SessionContainer::Iterator SessionManager::SessionBegin()
{
return session_table.Begin();
return session_tab.Begin();
}
SessionContainer::Iterator SessionManager::SessionEnd()
{
return session_table.End();
return session_tab.End();
}
void SessionManager::DeleteOldSessions()
void SessionManager::DeleteSessions()
{
session_table.DelFirstByTimeInterval(config->session_max_idle);
if( ++session_checker > 1000 )
{
// we make the test after 1000 requests
log << log3 << "SM: checking sessions which have 'remember me' flag set" << logend;
session_checker = 0;
session_table.DelFirstByTimeInterval(config->session_remember_max_idle, false);
}
session_tab.Clear();
}
void SessionManager::DeleteAllPluginsData()
void SessionManager::InitTmpSession()
{
SessionContainer::Iterator i = session_table.Begin();
Session * old_session = cur->session;
Session * old_session = request->session;
log << log4 << "SM: initializing temporary session" << logend;
cur->session = &temporary_session;
plugin.Call(WINIX_SESSION_CREATED);
for( ; i!=session_table.End() ; ++i )
{
request->session = &(*i);
i->plugin_data.DeleteAll();
}
request->session = old_session;
cur->session = old_session;
}
void SessionManager::UninitTmpSession()
{
Session * old_session = cur->session;
log << log4 << "SM: uninitializing temporary session" << logend;
cur->session = &temporary_session;
cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_SESSION_REMOVE);
cur->session->plugin_data.Resize(0);
cur->session = old_session;
}
void SessionManager::LoadSessions()
@@ -258,20 +257,20 @@ void SessionManager::LoadSessions()
SessionParser sp;
SessionContainer::Iterator i;
// sessions will be overwritten (pointers are invalidated)
cur->session = &temporary_session;
sp.SetUsers(&system->users);
Session * old_session = request->session;
sp.Parse(config->session_file, session_tab);
sp.Parse(config->session_file, session_table);
i = session_table.Begin();
for( ; i!=session_table.End() ; ++i )
for(i=session_tab.Begin() ; i != session_tab.End() ; ++i)
{
i->plugin_data.Resize(plugin.Size());
request->session = &(*i);
cur->session = &(*i);
plugin.Call(WINIX_SESSION_CREATED);
}
request->session = old_session;
cur->session = &temporary_session;
}
@@ -294,9 +293,9 @@ void SessionManager::SaveSessions()
log << log2 << "SM: saving sessions" << logend;
long len = 0;
SessionContainer::Iterator i = session_table.Begin();
SessionContainer::Iterator i = session_tab.Begin();
for( ; i!=session_table.End() ; ++i )
for( ; i!=session_tab.End() ; ++i )
{
if( i->id != 0 && i->puser )
{
@@ -316,4 +315,124 @@ void SessionManager::SaveSessions()
Session * SessionManager::GetTmpSession()
{
return &temporary_session;
}
Session * SessionManager::GetCurSession()
{
return session;
}
/*
*
*
* sessions gc (second thread)
*
*
*/
void SessionManager::Work()
{
bool exit = false;
SessionContainer::IndexId::iterator i;
deleted = 0;
Lock();
i = session_tab.IdBegin();
Unlock();
while( !exit )
{
Lock();
CheckSession(i);
exit = synchro->was_stop_signal;
Unlock();
}
}
// it's called from the other thread (with Lock and Unlock)
void SessionManager::CheckSession(SessionContainer::IndexId::iterator & i)
{
const int deleted_max_at_once = 10;
if( i == session_tab.IdEnd() )
{
if( deleted > 0 )
{
deleted = 0;
log << logsave;
}
i = session_tab.IdBegin();
WaitForSignalSleep(10);
}
else
{
if( IsSessionOutdated(*i->second) )
{
DeleteSession(i++);
++deleted;
}
else
{
++i;
}
if( deleted >= deleted_max_at_once )
{
log << logsave;
WaitForSignalSleep(1);
deleted = 0;
}
}
}
// it's called from the other thread (with Lock and Unlock)
bool SessionManager::IsSessionOutdated(const Session & s) const
{
bool outdated;
if( s.remember_me )
outdated = s.last_time < std::time(0) - config->session_remember_max_idle;
else
outdated = s.last_time < std::time(0) - config->session_max_idle;
return outdated;
}
// it's called from the other thread (with Lock and Unlock)
void SessionManager::DeleteSession(SessionContainer::IdIterator i)
{
Session * del_session = &(*i->second);
if( del_session->puser )
last_container->UserLogout(del_session->puser->id, del_session->id);
session_tab.EraseById(i);
}
/*
*
*
* end of sessions gc
*
*
*/

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucoresessionmanager
#define headerfilecmslucoresessionmanager
#ifndef headerfile_winix_core_sessionmanager
#define headerfile_winix_core_sessionmanager
#include <set>
#include <ctime>
@@ -18,43 +18,72 @@
#include "request.h"
#include "lastcontainer.h"
#include "system.h"
#include "synchro.h"
#include "basethread.h"
class SessionManager
class SessionManager : public BaseThread
{
Config * config;
Request * request;
System * system;
SessionContainer session_table;
bool IsSession(long s);
long CreateSessionId();
void CreateTemporarySession();
void CreateSession();
bool SetSessionFromCookie(const std::string & cookie);
int session_checker;
public:
SessionManager();
void SetRequest(Request * prequest);
void SetCur(Cur * pcur);
void SetConfig(Config * pconfig);
void SetSystem(System * psystem);
void SetLastContainer(LastContainer * plast_container);
void SetSession();
void DeleteAllPluginsData();
void DeleteOldSessions();
void DeleteSessions(); // deleting all sessions
void InitTmpSession();
void UninitTmpSession();
Session * GetTmpSession();
Session * GetCurSession();
void LoadSessions();
void SaveSessions();
SessionContainer::Iterator SessionBegin();
SessionContainer::Iterator SessionEnd();
size_t Size();
private:
Config * config;
Cur * cur;
System * system;
LastContainer * last_container;
// current session - set by SetSession()
Session * session;
SessionContainer session_tab;
// session with id 0
Session temporary_session;
// for adding a new session to the container
Session new_session;
bool IsSession(long s);
long CreateSessionId();
void CreateSession();
bool SetSessionFromCookie(const std::string & cookie);
// second thread
int deleted;
virtual void Work();
void CheckSession(SessionContainer::IndexId::iterator & i);
bool IsSessionOutdated(const Session & s) const;
void DeleteSession(SessionContainer::IdIterator i);
};

View File

@@ -9,6 +9,7 @@
#include "sessionparser.h"
#include "log.h"
#include "misc.h"
@@ -98,8 +99,8 @@ bool SessionParser::MakeSession(long user_id)
session.puser = puser;
session.new_session = true;
session.tm_time = *std::localtime(&session.time);
session.tm_last_time = *std::localtime(&session.last_time);
session.tm_time = Time(session.time);
session.tm_last_time = Time(session.last_time);
return true;
}

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucoresessionparser
#define headerfilecmslucoresessionparser
#ifndef headerfile_winix_core_sessionparser
#define headerfile_winix_core_sessionparser
#include <fstream>
#include <string>

216
core/slog.cpp Executable file
View File

@@ -0,0 +1,216 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "slog.h"
SLog::SLog()
{
cur = 0;
locale = 0;
}
void SLog::SetCur(Cur * pcur)
{
cur = pcur;
}
void SLog::SetLocale(Locale * plocale)
{
locale = plocale;
}
SLog & SLog::operator<<(const void * s)
{
return PutLog(s);
}
SLog & SLog::operator<<(const char * s)
{
return PutLog(s);
}
SLog & SLog::operator<<(const std::string * s)
{
return PutLog(s);
}
SLog & SLog::operator<<(const std::string & s)
{
return PutLog(s);
}
SLog & SLog::operator<<(const wchar_t * s)
{
return PutLog(s);
}
SLog & SLog::operator<<(const std::wstring * s)
{
return PutLog(s);
}
SLog & SLog::operator<<(const std::wstring & s)
{
return PutLog(s);
}
SLog & SLog::operator<<(int s)
{
return PutLog(s);
}
SLog & SLog::operator<<(long s)
{
return PutLog(s);
}
SLog & SLog::operator<<(char s)
{
return PutLog(s);
}
SLog & SLog::operator<<(wchar_t s)
{
return PutLog(s);
}
SLog & SLog::operator<<(size_t s)
{
return PutLog(s);
}
SLog & SLog::operator<<(double s)
{
return PutLog(s);
}
SLog & SLog::operator<<(LogManipulators m)
{
if( cur && cur->session )
{
TextStream<std::wstring> & buf = cur->session->log_buffer;
switch(m)
{
case logend:
buf << '\n';
if( buf.Size() > WINIX_SLOG_MAX_LOG_SIZE )
{
buf.Clear();
(*this) << logwarning << T("slog_turn_over") << " " << WINIX_SLOG_MAX_LOG_SIZE << logend;
}
break;
case loginfo:
case logwarning:
case logerror:
buf << (wchar_t)(int)m;
break;
default:
break;
}
}
return *this;
}
SLog & SLog::TranslateText(const char * str)
{
AssignString(str, key_temp);
return TranslateText(key_temp.c_str());
}
SLog & SLog::TranslateText(const wchar_t * str)
{
if( cur && cur->session )
{
const std::wstring * trans = 0;
if( locale )
trans = &locale->Get(str);
if( !trans || trans->empty() )
cur->session->log_buffer << "Not translated: " << str;
else
cur->session->log_buffer << trans;
}
return *this;
}
SLog & SLog::operator<<(const TranslateTextHelper<const char*> & raw)
{
return TranslateText(raw.par);
}
SLog & SLog::operator<<(const TranslateTextHelper<const wchar_t*> & raw)
{
return TranslateText(raw.par);
}
SLog & SLog::operator<<(TranslateTextHelper<const std::string*> raw)
{
return TranslateText(raw.par->c_str());
}
SLog & SLog::operator<<(TranslateTextHelper<const std::wstring*> raw)
{
return TranslateText(raw.par->c_str());
}
SLog & SLog::operator<<(TranslateTextHelper<std::string> raw)
{
return TranslateText(raw.par.c_str());
}
SLog & SLog::operator<<(TranslateTextHelper<std::wstring> raw)
{
return TranslateText(raw.par.c_str());
}

122
core/slog.h Executable file
View File

@@ -0,0 +1,122 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_slog
#define headerfile_winix_core_slog
#include "cur.h"
#include "logmanipulators.h"
#include "templates/locale.h"
#define WINIX_SLOG_MAX_LOG_SIZE 10240
/*
session logger
sample:
#include "log.h" (or slog.h)
slog << logerror << "message" << "something" << logend;
slog << logwarning << T("message_to_translate") << x << logend;
if the latter example "message_to_translate" will be taken from locales
currently following manipulators are taken into account:
loginfo - the message in a normal info
logwarning - this is a warning
logerror - this is an error
logend - end of a line -- we have one kind of a message (info, warning, error) per line
loginfo, logwarning, logerror should be specified at the beginning of a line
(other manipulators are skipped)
*/
class SLog
{
public:
SLog();
void SetCur(Cur * pcur);
void SetLocale(Locale * plocale);
template<class RawType>
struct TranslateTextHelper
{
const RawType & par;
TranslateTextHelper(const TranslateTextHelper<RawType> & p) : par(p.par) {}
TranslateTextHelper(const RawType & p) : par(p) {}
};
SLog & operator<<(const void * s);
SLog & operator<<(const char * s);
SLog & operator<<(const std::string * s);
SLog & operator<<(const std::string & s);
SLog & operator<<(const wchar_t * s);
SLog & operator<<(const std::wstring * s);
SLog & operator<<(const std::wstring & s);
SLog & operator<<(int s);
SLog & operator<<(long s);
SLog & operator<<(char s);
SLog & operator<<(wchar_t s);
SLog & operator<<(size_t s);
SLog & operator<<(double s);
SLog & operator<<(LogManipulators m);
SLog & TranslateText(const char * str);
SLog & TranslateText(const wchar_t * str);
template<size_t str_size>
SLog & operator<<(const TranslateTextHelper<char [str_size]> & raw) { return TranslateText(raw.par); }
template<size_t str_size>
SLog & operator<<(const TranslateTextHelper<wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
SLog & operator<<(const TranslateTextHelper<const char*> & raw);
SLog & operator<<(const TranslateTextHelper<const wchar_t*> & raw);
SLog & operator<<(TranslateTextHelper<const std::string*> raw);
SLog & operator<<(TranslateTextHelper<const std::wstring*> raw);
SLog & operator<<(TranslateTextHelper<std::string> raw);
SLog & operator<<(TranslateTextHelper<std::wstring> raw);
private:
template<class LogParam>
SLog & PutLog(LogParam par);
Cur * cur;
Locale * locale;
std::wstring key_temp;
};
template<class RawType>
SLog::TranslateTextHelper<RawType> T(const RawType & par)
{
return SLog::TranslateTextHelper<RawType>(par);
}
template<class LogParam>
SLog & SLog::PutLog(LogParam par)
{
if( cur && cur->session )
cur->session->log_buffer << par;
return *this;
}
extern SLog slog;
#endif

35
core/synchro.cpp Executable file
View File

@@ -0,0 +1,35 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "synchro.h"
Synchro::Synchro() : mutex(PTHREAD_MUTEX_INITIALIZER)
{
was_stop_signal = false;
}
bool Synchro::Lock()
{
return pthread_mutex_lock(&mutex) == 0;
}
void Synchro::Unlock()
{
pthread_mutex_unlock(&mutex);
}

36
core/synchro.h Executable file
View File

@@ -0,0 +1,36 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_synchro
#define headerfile_winix_core_synchro
#include <pthread.h>
struct Synchro
{
// one global mutex
pthread_mutex_t mutex;
// true when winix is closing
volatile bool was_stop_signal;
Synchro();
bool Lock();
void Unlock();
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -7,23 +7,25 @@
*
*/
#ifndef headerfilecmslucorefs
#define headerfilecmslucorefs
#ifndef headerfile_winix_core_system
#define headerfile_winix_core_system
#include <ctime>
#include "dirs.h"
#include "mounts.h"
#include "db.h"
#include "db/db.h"
#include "request.h"
#include "config.h"
#include "crypt.h"
#include "users.h"
#include "groups.h"
#include "rebus.h"
#include "loadavg.h"
#include "synchro.h"
#include "thumb.h"
#include "notify/notify.h"
class Functions;
class Templates;
// file system
@@ -49,24 +51,33 @@ public:
// load averages
LoadAvg load_avg;
// notifications (by emails)
Notify notify;
// thumbnails (special thread)
Thumb thumb;
// the time when the winix starts
time_t system_start;
// cryptography and hashes
Crypt crypt;
void SetRequest(Request * prequest);
void SetCur(Cur * pcur);
void SetConfig(Config * pconfig);
void SetDb(Db * pdb);
void SetFunctions(Functions * pfunctions);
void SetTemplates(Templates * ptemplates);
void SetSynchro(Synchro * psynchro);
void Init();
void RedirectTo(const Item & item, const char * postfix = 0);
void RedirectTo(long item_id, const char * postfix = 0);
void AddParams(const ParamTab & param_tab, std::wstring & str, bool clear_str = true);
void RedirectTo(const Item & item, const wchar_t * postfix = 0);
void RedirectTo(long item_id, const wchar_t * postfix = 0);
void RedirectTo(const std::wstring & url);
void RedirectWithFunctionAndParamsTo(const std::wstring & url);
void RedirectToLastDir();
void RedirectToLastItem(); // redirect to an item if exists or to the last directory
void PrepareUrl(Item & item);
bool CanChangeUser(const Item & item, long new_user_id);
bool CanChangeGroup(const Item & item, long new_group_id);
bool CanChangePrivileges(const Item & item, int new_priv);
@@ -76,34 +87,69 @@ public:
bool HasReadWriteAccess(const Item & item);
bool HasReadExecAccess(const Item & item);
bool HasReadExecAccessToPath(long dir_id);
bool HasReadExecAccessToPath(const std::vector<Item*> & dir_tab);
bool DirsHaveReadExecPerm();
void CheckAccessToItems(std::vector<Item> & item_table);
void CheckAccessToItems(std::vector<Item> & item_tab);
bool CanUseHtml(long user_id);
bool CanUseBBCode(long user_id);
bool CanUseRaw(long user_id);
bool IsMemberOfGroup(long user_id, const char * group_name);
bool IsMemberOfGroup(long user_id, const wchar_t * group_name);
bool MakePath(const Item & item, std::string & path, bool create_dir);
bool MakePath(Item & item, bool create_dir); // output path is: item.auth_path
// creating item.file_path and item.file_fs (the mountpoint where the item is located)
bool CreateNewFile(Item & item);
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755);
Error AddFile(Item & item);
Error EditFile(Item & item, bool with_url = true);
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
Error CheckSpecialFile(const Item & item);
Error AddFile(Item & item, int notify_code = 0);
Error EditFile(Item & item, bool with_url = true, int notify_code = 0);
// converting GMT time to local time (different for each user)
time_t LocalTime(time_t gmt_time);
tm LocalTime(const tm * ptm);
tm LocalTime(const tm & ptm);
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, Item & out_item);
int FollowAllLinks(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, Item & out_item,
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
// starting from root dir
int FollowAllLinks(const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, Item & out_item,
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
// using cur->request->dir_tab and cur->request->item
bool FollowAllLinks(const std::wstring & link_to,
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
private:
Request * request;
Config * config;
Db * db;
Functions * functions;
Templates * templates;
Cur * cur;
Db * db;
Config * config;
Synchro * synchro;
std::string path;
bool MakePathSimpleFs(std::string & path, long dir_id, bool create_dir);
bool MakePathHashFs(std::string & path, long id, bool create_dir);
Item item_temp;
std::wstring link_to_temp, name_temp;
// for FollowAllLinks
std::vector<Item*> temp_follow_dir_tab;
std::vector<Item*> root_follow_dir_tab;
Item temp_follow_item;
bool CreateNewFileSimpleFs(Item & item);
bool CreateNewFileHashFs(Item & item);
bool FollowAllLinksDirFound(std::vector<Item*> & out_dir_tab,
bool follow_dir_default, bool stop_on_link_redirect, bool check_access);
bool FollowAllLinksFileOrSymlinkFound(std::vector<Item*> & out_dir_tab, Item & out_item,
bool stop_on_link_redirect, bool check_access);
};

13
core/textstream.cpp Executable file
View File

@@ -0,0 +1,13 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "textstream.h"
#include "misc.h"

305
core/textstream.h Executable file
View File

@@ -0,0 +1,305 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_textstream
#define headerfile_winix_core_textstream
#include <string>
#include "misc.h"
/*
a special class representing a stream buffer
similar to std::ostringstream
StringType can be either std::string or std::wstring
this class doesn't use UTF-8 in any kind
*/
template<class StringType>
class TextStream
{
public:
typedef typename StringType::value_type CharType;
typedef typename StringType::value_type char_type;
void Clear();
bool Empty() const;
size_t Size() const;
void Reserve(size_t len);
const StringType & Str() const;
const CharType * CStr() const;
CharType operator[](size_t index);
TextStream & operator<<(const char * str);
TextStream & operator<<(const std::string * str);
TextStream & operator<<(const std::string & str);
TextStream & operator<<(const wchar_t * str);
TextStream & operator<<(const std::wstring * str);
TextStream & operator<<(const std::wstring & str);
TextStream & operator<<(char);
TextStream & operator<<(wchar_t);
TextStream & operator<<(int);
TextStream & operator<<(long);
TextStream & operator<<(unsigned int);
TextStream & operator<<(unsigned long);
TextStream & operator<<(double);
TextStream & operator<<(const void *);// printing a pointer
TextStream & Write(const char * buf, size_t len);
TextStream & Write(const wchar_t * buf, size_t len);
TextStream & write(const char * buf, size_t len); // for compatibility with standard library (Ezc uses it)
TextStream & write(const wchar_t * buf, size_t len);
protected:
StringType buffer;
};
template<class StringType>
void TextStream<StringType>::Clear()
{
buffer.clear();
}
template<class StringType>
bool TextStream<StringType>::Empty() const
{
return buffer.empty();
}
template<class StringType>
size_t TextStream<StringType>::Size() const
{
return buffer.size();
}
template<class StringType>
void TextStream<StringType>::Reserve(size_t len)
{
buffer.reserve(len);
}
template<class StringType>
const StringType & TextStream<StringType>::Str() const
{
return buffer;
}
template<class StringType>
const typename TextStream<StringType>::CharType * TextStream<StringType>::CStr() const
{
return buffer.c_str();
}
template<class StringType>
typename TextStream<StringType>::CharType TextStream<StringType>::operator[](size_t index)
{
return buffer[index];
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const char * str)
{
AssignString(str, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string * str)
{
AssignString(*str, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string & str)
{
AssignString(str, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const wchar_t * str)
{
AssignString(str, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring * str)
{
AssignString(*str, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring & str)
{
AssignString(str, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(char v)
{
buffer += v;
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(wchar_t v)
{
buffer += static_cast<CharType>(v);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(int v)
{
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
Toa(v, buf, len);
AssignString(buf, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(long v)
{
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
Toa(v, buf, len);
AssignString(buf, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(unsigned int v)
{
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
Toa(v, buf, len);
AssignString(buf, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(unsigned long v)
{
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
Toa(v, buf, len);
AssignString(buf, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(double v)
{
char buf[50];
sprintf(buf, "%f", v);
AssignString(buf, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const void * v)
{
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
buf[0] = '0';
buf[1] = 'x';
Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16);
AssignString(buf, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
{
AssignString(buf, len, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::write(const char * buf, size_t len)
{
return Write(buf, len);
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::Write(const wchar_t * buf, size_t len)
{
AssignString(buf, len, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::write(const wchar_t * buf, size_t len)
{
return Write(buf, len);
}
#endif

View File

@@ -1,53 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorecorethread
#define headerfilecmslucorecorethread
#include <string>
class Thread
{
public:
long id;
long parent_id;
long dir_id;
bool closed;
// how many items there are inside
long items;
// last item in the directory (this variable is mainly for reading)
// at the moment only used: id, date_modification, user_id
Item last_item;
// used when sorting
long sort;
void Clear()
{
id = parent_id = dir_id = -1;
last_item.Clear();
closed = false;
items = 0;
sort = 0;
}
Thread()
{
Clear();
}
};
#endif

309
core/thumb.cpp Executable file
View File

@@ -0,0 +1,309 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <ctime>
#include "thumb.h"
#include "utf8.h"
#include "log.h"
#include "system.h"
void Thumb::SetDb(Db * pdb)
{
db = pdb;
}
void Thumb::SetConfig(Config * pconfig)
{
config = pconfig;
}
void Thumb::SetSystem(System * psystem)
{
system = psystem;
}
// first thread (objects locked)
void Thumb::CreateThumb(const Item & item, size_t cx, size_t cy, int aspect_mode)
{
item_temp.file = item;
item_temp.cx = cx;
item_temp.cy = cy;
item_temp.aspect_mode = aspect_mode;
thumb_tab.insert(thumb_tab.end(), item_temp);
WakeUpThread();
}
// second thread (objects locked)
bool Thumb::SignalReceived()
{
return !thumb_tab.empty();
}
// second thread (objects not locked)
void Thumb::Do()
{
ThumbTab::iterator i;
bool end;
Lock();
i = thumb_tab.begin();
Unlock();
do
{
Lock();
if( i != thumb_tab.end() )
{
item_work = *i;
thumb_tab.erase(i++);
end = false;
}
else
{
end = true;
}
Unlock();
if( !end )
CreateThumbnail();
}
while( !end && !IsExitSignal() );
}
void Thumb::EscapePath(const std::string & path)
{
command << '"';
for(size_t i=0 ; i<path.size() ; ++i)
{
if( path[i] == '"' )
command << '\\';
command << path[i];
}
command << "\" ";
}
/*
from: http://www.imagemagick.org/script/command-line-processing.php#geometry
scale% Height and width both scaled by specified percentage.
scale-x%xscale-y% Height and width individually scaled by specified percentages. (Only one % symbol needed.)
width Width given, height automagically selected to preserve aspect ratio.
xheight Height given, width automagically selected to preserve aspect ratio.
widthxheight Maximum values of height and width given, aspect ratio preserved.
widthxheight^ Minimum values of width and height given, aspect ratio preserved.
widthxheight! Width and height emphatically given, original aspect ratio ignored.
widthxheight> Change as per widthxheight but only if an image dimension exceeds a specified dimension.
widthxheight< Change dimensions only if both image dimensions exceed specified dimensions.
*/
void Thumb::SelectAspect()
{
switch( item_work.aspect_mode )
{
case WINIX_THUMB_MODE_1:
command << item_work.cx;
break;
case WINIX_THUMB_MODE_3:
command << item_work.cx << "x" << item_work.cy;
break;
case WINIX_THUMB_MODE_4:
command << '"' << item_work.cx << "x" << item_work.cy << "^\"";
break;
case WINIX_THUMB_MODE_5:
command << '"' << item_work.cx << "x" << item_work.cy << "!\"";
break;
case WINIX_THUMB_MODE_6:
command << '"' << item_work.cx << "x" << item_work.cy << ">\"";
break;
case WINIX_THUMB_MODE_7:
command << '"' << item_work.cx << "x" << item_work.cy << "<\"";
break;
case WINIX_THUMB_MODE_2:
default:
command << "x" << item_work.cy;
break;
}
}
// second thread (objects are not locked)
bool Thumb::CreateCommand()
{
bool res;
command.Clear();
stream_tmp_path.Clear();
Lock();
Ezc::WideToUTF8(config->convert_cmd, tempa);
command << tempa << " -quiet -strip -thumbnail ";
SelectAspect();
command << " ";
if( system->MakeFilePath(item_work.file, src_path) )
{
Ezc::WideToUTF8(src_path, tempa);
EscapePath(tempa);
stream_tmp_path << config->upload_dir << L"/tmp/thumb_" << std::time(0);
Ezc::WideToUTF8(stream_tmp_path.Str(), string_tmp_patha);
EscapePath(string_tmp_patha);
res = true;
}
else
{
log << log1 << "Thumb: cannot create a source path" << logend;
res = false;
}
Unlock();
return res;
}
// second thread (objects are not locked)
void Thumb::SaveTmpThumbnail()
{
bool moved = false;
Lock();
// the file could have been changed especially when creating thumbnail lasted too long
iq.SetAll(false, false);
iq.sel_parent_id = true;
iq.sel_file = true;
iq.sel_url = true;
iq.sel_type = true;
iq.WhereId(item_work.file.id);
if( db->GetItem(item_work.file, iq) == WINIX_ERR_OK )
{
if( system->MakeFilePath(item_work.file, dst_path, true, true, config->upload_dirs_chmod) )
{
if( RenameFile(stream_tmp_path.Str(), dst_path) )
{
log << log3 << "Thumb: created a thumbnail: " << dst_path << logend;
db->EditHasThumbById(true, item_work.file.id);
moved = true;
}
else
{
log << log1 << "Thumb: cannot move a temporary file: " << stream_tmp_path.Str() << ", to: " << dst_path << logend;
}
}
else
{
log << log1 << "Thumb: cannot create a destination path" << logend;
}
}
if( !moved )
::RemoveFile(stream_tmp_path.Str());
Unlock();
}
// second thread (objects are not locked)
void Thumb::CreateThumbnail()
{
if( !CreateCommand() )
return;
int res = std::system(command.CStr());
if( res == 0 )
{
SaveTmpThumbnail();
}
else
{
Lock();
log << log3 << "Thumb: some problems with creating a thumbnail " << tempa
<< ", 'convert' process returned: " << res << logend;
Unlock();
}
}
// second thread (objects are not locked)
// !! there is a problem with GIF files
// Bus error (core dumped)
/*
#include "wand/MagickWand.h"
// compiler options:
// include: -I/usr/local/include/ImageMagick
// link with: `MagickWand-config --ldflags --libs`
void Thumb::CreateThumbnail()
{
Ezc::WideToUTF8(item_work.source, sourcea);
Ezc::WideToUTF8(item_work.dst, dsta);
MagickWandGenesis();
MagickWand * wand = NewMagickWand();
if( MagickReadImage(wand, sourcea.c_str()) )
{
MagickThumbnailImage(wand, item_work.cx, item_work.cy);
if( MagickWriteImage(wand, dsta.c_str()) )
{
Lock();
log << log3 << "Thumb: created a thumbnail: " << dsta << logend;
Unlock();
}
}
DestroyMagickWand(wand);
MagickWandTerminus();
}
*/

97
core/thumb.h Executable file
View File

@@ -0,0 +1,97 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_thumb
#define headerfile_winix_core_thumb
#include <string>
#include <list>
#include "basethread.h"
#include "textstream.h"
#include "db/db.h"
#include "core/item.h"
#include "core/config.h"
class System;
// Width given, height automagically selected to preserve aspect ratio.
#define WINIX_THUMB_MODE_1 1
// Height given, width automagically selected to preserve aspect ratio.
#define WINIX_THUMB_MODE_2 2
// Maximum values of height and width given, aspect ratio preserved.
#define WINIX_THUMB_MODE_3 3
// Minimum values of width and height given, aspect ratio preserved.
#define WINIX_THUMB_MODE_4 4
// Width and height emphatically given, original aspect ratio ignored.
#define WINIX_THUMB_MODE_5 5
// Change as per widthxheight but only if an image dimension exceeds a specified dimension.
#define WINIX_THUMB_MODE_6 6
// Change dimensions only if both image dimensions are less than specified dimensions.
#define WINIX_THUMB_MODE_7 7
class Thumb : public BaseThread
{
public:
void CreateThumb(const Item & item, size_t cx, size_t cy, int aspect_mode);
void SetDb(Db * pdb);
void SetConfig(Config * pconfig);
void SetSystem(System * psystem);
private:
Db * db;
Config * config;
System * system;
struct ThumbItem
{
Item file;
size_t cx;
size_t cy;
int aspect_mode;
};
// queue of thumbnails to create
typedef std::list<ThumbItem> ThumbTab;
ThumbTab thumb_tab;
ThumbItem item_temp;
// only for second thread
ThumbItem item_work;
std::wstring src_path, dst_path;
std::string tempa, string_tmp_patha;
TextStream<std::string> command;
TextStream<std::wstring> stream_tmp_path;
DbItemQuery iq;
virtual bool SignalReceived();
virtual void Do();
bool CreateCommand();
void SaveTmpThumbnail();
void CreateThumbnail();
void SelectAspect();
void EscapePath(const std::string & path);
};
#endif

View File

@@ -1,58 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreticket
#define headerfilecmslucoreticket
#include <string>
struct Ticket
{
long id;
long dir_id;
long parent_id;
unsigned int type;
unsigned int status;
unsigned int priority;
unsigned int category;
unsigned int expected;
unsigned int progress; // 0 - 100 (percentage)
// the first item (with the content for the ticket)
long item_id;
void Clear()
{
id = -1;
dir_id = -1;
parent_id = -1;
type = 0;
status = 0;
priority = 0;
category = 0;
expected = 0;
progress = 0;
item_id = -1;
}
Ticket()
{
Clear();
}
};
#endif

View File

@@ -7,8 +7,8 @@
*
*/
#ifndef headerfilecmslucoreugcontainer
#define headerfilecmslucoreugcontainer
#ifndef headerfile_winix_core_ugcontainer
#define headerfile_winix_core_ugcontainer
#include <vector>
#include <map>
@@ -27,8 +27,8 @@ public:
typedef typename Table::iterator Iterator;
typedef typename Table::size_type SizeType;
typedef typename std::map<long, SizeType> TableId;
typedef typename std::map<std::string, SizeType> TableName;
typedef typename std::map<long, SizeType> TableId;
typedef typename std::map<std::wstring, SizeType> TableName;
UGContainer();
@@ -41,10 +41,10 @@ public:
void Clear();
bool Is(long id);
bool Is(const std::string & name);
bool Is(const std::wstring & name);
Iterator FindId(long id);
Iterator FindName(const std::string & name);
Iterator FindName(const std::wstring & name);
Type & operator[](SizeType pos);
@@ -141,7 +141,7 @@ return true;
template<class Type>
bool UGContainer<Type>::Is(const std::string & name)
bool UGContainer<Type>::Is(const std::wstring & name)
{
typename TableName::iterator i = table_name.find(name);
@@ -167,7 +167,7 @@ return table.begin() + i->second;
template<class Type>
typename UGContainer<Type>::Iterator UGContainer<Type>::FindName(const std::string & name)
typename UGContainer<Type>::Iterator UGContainer<Type>::FindName(const std::wstring & name)
{
typename TableName::iterator i = table_name.find(name);
@@ -185,7 +185,7 @@ void UGContainer<Type>::AddIndexes(UGContainer<Type>::SizeType pos)
table_id.insert( std::make_pair(table[pos].id, pos) );
table_name.insert( std::make_pair(table[pos].name, pos) );
log << log2 << "UGCont: added indexes to: id: " << table[pos].id << ", name: " << table[pos].name << logend;
log << log4 << "UGCont: added indexes to: id: " << table[pos].id << ", name: " << table[pos].name << logend;
}
@@ -193,7 +193,7 @@ void UGContainer<Type>::AddIndexes(UGContainer<Type>::SizeType pos)
template<class Type>
void UGContainer<Type>::RebuildIndexes()
{
log << log2 << "UGCont: rebuilding indexes" << logend;
log << log4 << "UGCont: rebuilding indexes" << logend;
table_id.clear();
table_name.clear();
@@ -204,7 +204,7 @@ void UGContainer<Type>::RebuildIndexes()
for(i=0 ; i!=len ; ++i)
AddIndexes( i );
log << log2 << "UGCont: indexes rebuilt, table.size: " << table.size() << ", table_id.size: "
log << log4 << "UGCont: indexes rebuilt, table.size: " << table.size() << ", table_id.size: "
<< table_id.size() << ", table_name.size: " << table_name.size() << logend;
}

View File

@@ -2,31 +2,48 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreuser
#define headerfilecmslucoreuser
#ifndef headerfile_winix_core_user
#define headerfile_winix_core_user
#include <string>
#include <vector>
/*
a temporary struct used for hashing and encrypting a user's password
*/
struct UserPass
{
int pass_type; // the kind of hash (WINIX_CRYPT_HASH_* see crypt.h)
std::wstring pass; // password hashed or plain text if pass_type==0
std::string pass_encrypted; // password encrypted
bool pass_hash_salted; // true when the hash was salted (plain text passwords are never salted)
};
struct User
{
long id;
std::string name;
std::wstring name;
bool super_user;
std::vector<long> groups;
std::string email;
int cms_notify;
int thread_notify;
std::wstring email;
int notify;
// !! currently all users have the same offset
// option in config: time_zone_offset
int time_zone_offset;
User()
{
Clear();
@@ -40,8 +57,8 @@ struct User
super_user = false;
groups.clear();
email.clear();
cms_notify = 0;
thread_notify = 0;
notify = 0;
time_zone_offset = 0;
}

View File

@@ -19,9 +19,9 @@ Users::Users()
}
void Users::SetRequest(Request * prequest)
void Users::SetCur(Cur * pcur)
{
request = prequest;
cur = pcur;
}
@@ -39,6 +39,17 @@ void Users::ReadUsers(Db * db)
}
void Users::SetTimeZoneOffset(int offset)
{
Table::Iterator i;
for(i=table.Begin() ; i!=table.End() ; ++i)
{
i->time_zone_offset = offset;
}
}
bool Users::AddUser(const User & user)
{
Table::Iterator i = table.PushBack(user);
@@ -47,7 +58,7 @@ return (i != table.End());
}
bool Users::IsUser(const std::string & name)
bool Users::IsUser(const std::wstring & name)
{
return table.Is(name);
}
@@ -64,7 +75,7 @@ return &(*i);
}
User * Users::GetUser(const std::string & name)
User * Users::GetUser(const std::wstring & name)
{
Table::Iterator i = table.FindName(name);
@@ -76,7 +87,7 @@ return &(*i);
long Users::GetUserId(const std::string & name)
long Users::GetUserId(const std::wstring & name)
{
User * puser = GetUser(name);
@@ -117,24 +128,30 @@ User & Users::operator[](Users::SizeType pos)
void Users::LoginUser(long user_id, bool remember_me)
{
if( !request->session )
if( !cur->session )
return;
request->session->puser = GetUser(user_id);
request->session->spam_score = 0;
if( cur->session->id == 0 )
{
log << log1 << "Users: cannot login a user on a temporary session" << logend;
return;
}
if( !request->session->puser )
cur->session->puser = GetUser(user_id);
cur->session->spam_score = 0;
if( !cur->session->puser )
{
log << log1 << "Users: user id: " << user_id << " is not in system.users table" << logend;
return;
}
request->session->remember_me = remember_me;
cur->session->remember_me = remember_me;
last.UserLogin(user_id, request->session->puser->name, inet_addr(request->env_remote_addr), request->session->id);
last.UserLogin(user_id, cur->session->puser->name, inet_addr(cur->request->env_remote_addr), cur->session->id);
how_many_logged += 1;
log << log2 << "User " << request->session->puser->name << " (id: " << user_id << ") logged" << logend;
log << log2 << "User " << cur->session->puser->name << " (id: " << user_id << ") logged" << logend;
}
@@ -142,19 +159,19 @@ void Users::LoginUser(long user_id, bool remember_me)
void Users::LogoutCurrentUser()
{
if( !request->session || !request->session->puser )
if( !cur->session || !cur->session->puser )
return;
log << log2 << "Users: user " << request->session->puser->name << ", id: "
<< request->session->puser->id << " logged out" << logend;
log << log2 << "Users: user " << cur->session->puser->name << ", id: "
<< cur->session->puser->id << " logged out" << logend;
last.UserLogout(request->session->puser->id, request->session->id);
last.UserLogout(cur->session->puser->id, cur->session->id);
if( how_many_logged > 0 ) // for safety
how_many_logged -= 1;
request->session->puser = 0;
request->session->remember_me = 0;
cur->session->puser = 0;
cur->session->remember_me = 0;
}

View File

@@ -7,15 +7,15 @@
*
*/
#ifndef headerfilecmslucoreusers
#define headerfilecmslucoreusers
#ifndef headerfile_winix_core_users
#define headerfile_winix_core_users
#include <map>
#include "user.h"
#include "ugcontainer.h"
#include "lastcontainer.h"
#include "request.h"
#include "db.h"
#include "cur.h"
#include "db/db.h"
class Users
@@ -23,7 +23,7 @@ class Users
typedef UGContainer<User> Table;
Table table;
Request * request;
Cur * cur;
long how_many_logged;
public:
@@ -35,15 +35,16 @@ public:
Users();
void SetRequest(Request * request);
void SetCur(Cur * pcur);
void Clear();
void ReadUsers(Db * db);
void SetTimeZoneOffset(int offset); // !! temporarily one time_zone for all users
bool AddUser(const User & user);
bool IsUser(const std::string & name);
bool IsUser(const std::wstring & name);
User * GetUser(long user_id);
User * GetUser(const std::string & name);
long GetUserId(const std::string & name);
User * GetUser(const std::wstring & name);
long GetUserId(const std::wstring & name);
Iterator Begin();
Iterator End();
SizeType Size();

View File

@@ -2,18 +2,18 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreversion
#define headerfilecmslucoreversion
#ifndef headerfile_winix_core_version
#define headerfile_winix_core_version
#define WINIX_VER_MAJOR 0
#define WINIX_VER_MINOR 4
#define WINIX_VER_REVISION 0
#define WINIX_VER_REVISION 8
#endif

View File

@@ -4,13 +4,10 @@ include Makefile.o.dep
all: $(o)
.SUFFIXES: .cpp .o
.cpp.o:
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $<
depend:
makedepend -Y. -I.. -I../../ezc/src -f- *.cpp > Makefile.dep
echo -n "o = " > Makefile.o.dep

Some files were not shown because too many files have changed in this diff Show More