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
This commit is contained in:
Tomasz Sowa 2010-09-18 00:51:12 +00:00
parent 8b1db3304f
commit a589e5a090
52 changed files with 3261 additions and 1913 deletions

View File

@ -19,12 +19,13 @@ all: winix
winix: FORCE
@cd core ; $(MAKE) -e
@cd db ; $(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
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o db/*.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
@ -33,6 +34,7 @@ winix: FORCE
clean:
@cd core ; $(MAKE) -e clean
@cd db ; $(MAKE) -e clean
@cd functions ; $(MAKE) -e clean
@cd templates ; $(MAKE) -e clean
@cd templatesnotify ; $(MAKE) -e clean
@ -48,6 +50,7 @@ FORCE:
depend:
@cd core ; $(MAKE) -e depend
@cd db ; $(MAKE) -e depend
@cd functions ; $(MAKE) -e depend
@cd templates ; $(MAKE) -e depend
@cd templatesnotify ; $(MAKE) -e depend

View File

@ -2,16 +2,19 @@
acceptbaseparser.o: acceptbaseparser.h
app.o: app.h config.h confparser.h htmlfilter.h system.h dirs.h item.h
app.o: dircontainer.h db.h user.h group.h thread.h error.h log.h
app.o: ugcontainer.h ticket.h request.h requesttypes.h session.h plugindata.h
app.o: rebus.h mounts.h mount.h mountparser.h users.h lastcontainer.h
app.o: groups.h loadavg.h sessionmanager.h sessioncontainer.h notify.h
app.o: dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
app.o: ../db/dbtextstream.h ../core/textstream.h ../db/dbitemquery.h
app.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h ../core/group.h
app.o: ../core/thread.h ../core/error.h log.h ../core/dircontainer.h
app.o: ../core/ugcontainer.h ../core/ticket.h request.h requesttypes.h
app.o: session.h error.h user.h plugindata.h rebus.h mounts.h mount.h
app.o: mountparser.h users.h ugcontainer.h lastcontainer.h groups.h group.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/functionbase.h ../core/request.h ../core/system.h
app.o: ../core/notify.h ../functions/functionparser.h ../functions/adduser.h
app.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
app.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
app.o: ../functions/createthread.h ../functions/createticket.h
@ -21,12 +24,11 @@ app.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
app.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
app.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
app.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
app.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
app.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
app.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
app.o: ../core/htmlfilter.h ../templates/templates.h
app.o: ../templates/patterncacher.h ../core/item.h misc.h
app.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
app.o: ../functions/funticket.h ../functions/template.h
app.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
app.o: ../functions/uptime.h ../functions/who.h ../core/htmlfilter.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: compress.h getparser.h httpsimpleparser.h postparser.h cookieparser.h
app.o: postmultiparser.h acceptencodingparser.h acceptbaseparser.h plugin.h
@ -35,11 +37,15 @@ bbcodeparser.o: bbcodeparser.h htmlfilter.h
compress.o: compress.h log.h
config.o: config.h confparser.h htmlfilter.h log.h plugin.h pluginmsg.h
config.o: plugindata.h request.h requesttypes.h session.h item.h error.h
config.o: user.h rebus.h system.h dirs.h dircontainer.h db.h group.h thread.h
config.o: ugcontainer.h ticket.h mounts.h mount.h mountparser.h users.h
config.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
config.o: sessioncontainer.h ../functions/functions.h
config.o: ../functions/functionbase.h ../core/item.h ../core/db.h
config.o: user.h rebus.h system.h dirs.h dircontainer.h ../db/db.h
config.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
config.o: ../core/textstream.h ../db/dbitemquery.h ../core/item.h
config.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
config.o: ../core/thread.h ../core/error.h ../core/dircontainer.h
config.o: ../core/ugcontainer.h ../core/ticket.h mounts.h mount.h
config.o: mountparser.h users.h ugcontainer.h lastcontainer.h groups.h
config.o: group.h loadavg.h sessionmanager.h sessioncontainer.h
config.o: ../functions/functions.h ../functions/functionbase.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/adduser.h ../functions/cat.h ../functions/chmod.h
@ -52,30 +58,32 @@ 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 ../core/ticket.h
config.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
config.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
config.o: ../core/htmlfilter.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
config.o: ../functions/funticket.h ../functions/template.h
config.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
config.o: ../functions/uptime.h ../functions/who.h ../core/htmlfilter.h
config.o: ../templates/templates.h ../templates/patterncacher.h
config.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
config.o: ../core/httpsimpleparser.h ../core/log.h
config.o: ../templates/indexpatterns.h ../templates/localefilter.h
config.o: ../core/locale.h ../core/locale.h ../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 config.h confparser.h htmlfilter.h notify.h
dirs.o: ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
dirs.o: ../core/mount.h ../core/locale.h ../core/config.h ../templates/misc.h
dirs.o: ../templates/localefilter.h ../core/locale.h system.h mounts.h
dirs.o: mount.h mountparser.h users.h lastcontainer.h groups.h loadavg.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
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 ../db/dbitemquery.h
dirs.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h ../core/group.h
dirs.o: ../core/thread.h ../core/error.h log.h ../core/dircontainer.h
dirs.o: ../core/ugcontainer.h ../core/ticket.h request.h requesttypes.h
dirs.o: session.h error.h user.h plugindata.h rebus.h config.h confparser.h
dirs.o: htmlfilter.h notify.h ../templatesnotify/templatesnotify.h
dirs.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h ../core/config.h
dirs.o: ../templates/misc.h ../templates/localefilter.h ../core/locale.h
dirs.o: system.h mounts.h mount.h mountparser.h users.h ugcontainer.h
dirs.o: lastcontainer.h groups.h group.h loadavg.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
groups.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
groups.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
groups.o: log.h ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
htmlfilter.o: htmlfilter.h
httpsimpleparser.o: httpsimpleparser.h
lastcontainer.o: lastcontainer.h log.h
@ -84,22 +92,29 @@ 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 config.h confparser.h htmlfilter.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 config.h confparser.h
mountparser.o: mountparser.h mount.h item.h error.h dirs.h dircontainer.h
mountparser.o: ../db/db.h ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
mountparser.o: ../core/textstream.h ../db/dbitemquery.h ../core/item.h
mountparser.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
mountparser.o: ../core/thread.h ../core/error.h log.h ../core/dircontainer.h
mountparser.o: ../core/ugcontainer.h ../core/ticket.h request.h
mountparser.o: requesttypes.h session.h user.h plugindata.h rebus.h config.h
mountparser.o: confparser.h htmlfilter.h misc.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 ../db/dbitemquery.h ../core/item.h
mounts.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
mounts.o: ../core/thread.h ../core/error.h log.h ../core/dircontainer.h
mounts.o: ../core/ugcontainer.h ../core/ticket.h request.h requesttypes.h
mounts.o: session.h user.h plugindata.h rebus.h config.h confparser.h
mounts.o: htmlfilter.h mountparser.h plugin.h pluginmsg.h system.h users.h
mounts.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
mounts.o: sessioncontainer.h ../functions/functions.h
mounts.o: ../functions/functionbase.h ../core/item.h ../core/db.h
mounts.o: ../core/request.h ../core/config.h ../core/system.h
mounts.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
mounts.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
mounts.o: ../functions/privchanger.h ../functions/chown.h
mounts.o: ../functions/ckeditor.h ../functions/cp.h
mounts.o: ugcontainer.h lastcontainer.h groups.h group.h loadavg.h
mounts.o: sessionmanager.h sessioncontainer.h ../functions/functions.h
mounts.o: ../functions/functionbase.h ../core/request.h ../core/config.h
mounts.o: ../core/system.h ../core/notify.h ../../ezc/src/ezc.h
mounts.o: ../functions/functionparser.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/createthread.h ../functions/createticket.h
mounts.o: ../functions/default.h ../functions/download.h
mounts.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
@ -107,30 +122,37 @@ mounts.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
mounts.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
mounts.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
mounts.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
mounts.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
mounts.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
mounts.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
mounts.o: ../core/htmlfilter.h ../templates/templates.h
mounts.o: ../templates/patterncacher.h ../core/item.h misc.h
mounts.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
mounts.o: ../core/log.h ../templates/indexpatterns.h
mounts.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
mounts.o: ../core/sessionmanager.h
mounts.o: ../functions/funticket.h ../functions/template.h
mounts.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
mounts.o: ../functions/uptime.h ../functions/who.h ../core/htmlfilter.h
mounts.o: ../templates/templates.h ../templates/patterncacher.h
mounts.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
mounts.o: ../core/httpsimpleparser.h ../core/log.h
mounts.o: ../templates/indexpatterns.h ../templates/localefilter.h
mounts.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.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 config.h htmlfilter.h system.h dirs.h
notify.o: dircontainer.h db.h group.h thread.h ugcontainer.h ticket.h
notify.o: mounts.h mount.h mountparser.h users.h lastcontainer.h groups.h
notify.o: loadavg.h misc.h
notify.o: dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
notify.o: ../db/dbtextstream.h ../core/textstream.h ../db/dbitemquery.h
notify.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h ../core/group.h
notify.o: ../core/thread.h ../core/error.h ../core/dircontainer.h
notify.o: ../core/ugcontainer.h ../core/ticket.h mounts.h mount.h
notify.o: mountparser.h users.h ugcontainer.h lastcontainer.h groups.h
notify.o: group.h loadavg.h misc.h
plugin.o: plugin.h pluginmsg.h log.h plugindata.h config.h confparser.h
plugin.o: htmlfilter.h request.h requesttypes.h session.h item.h error.h
plugin.o: user.h rebus.h system.h dirs.h dircontainer.h db.h group.h thread.h
plugin.o: ugcontainer.h ticket.h mounts.h mount.h mountparser.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: user.h rebus.h system.h dirs.h dircontainer.h ../db/db.h
plugin.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
plugin.o: ../core/textstream.h ../db/dbitemquery.h ../core/item.h
plugin.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
plugin.o: ../core/thread.h ../core/error.h ../core/dircontainer.h
plugin.o: ../core/ugcontainer.h ../core/ticket.h mounts.h mount.h
plugin.o: mountparser.h users.h ugcontainer.h lastcontainer.h groups.h
plugin.o: group.h loadavg.h sessionmanager.h sessioncontainer.h
plugin.o: ../functions/functions.h ../functions/functionbase.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
@ -143,22 +165,25 @@ plugin.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
plugin.o: ../functions/mkdir.h ../functions/mv.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 ../core/ticket.h
plugin.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
plugin.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
plugin.o: ../core/htmlfilter.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
plugin.o: ../functions/funticket.h ../functions/template.h
plugin.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
plugin.o: ../functions/uptime.h ../functions/who.h ../core/htmlfilter.h
plugin.o: ../templates/templates.h ../templates/patterncacher.h
plugin.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
plugin.o: ../core/httpsimpleparser.h ../core/log.h
plugin.o: ../templates/indexpatterns.h ../templates/localefilter.h
plugin.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
plugindata.o: plugindata.h plugin.h pluginmsg.h log.h config.h confparser.h
plugindata.o: htmlfilter.h request.h requesttypes.h session.h item.h error.h
plugindata.o: user.h rebus.h system.h dirs.h dircontainer.h db.h group.h
plugindata.o: thread.h ugcontainer.h ticket.h mounts.h mount.h mountparser.h
plugindata.o: users.h lastcontainer.h groups.h loadavg.h sessionmanager.h
plugindata.o: sessioncontainer.h ../functions/functions.h
plugindata.o: ../functions/functionbase.h ../core/item.h ../core/db.h
plugindata.o: user.h rebus.h system.h dirs.h dircontainer.h ../db/db.h
plugindata.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
plugindata.o: ../core/textstream.h ../db/dbitemquery.h ../core/item.h
plugindata.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
plugindata.o: ../core/thread.h ../core/error.h ../core/dircontainer.h
plugindata.o: ../core/ugcontainer.h ../core/ticket.h mounts.h mount.h
plugindata.o: mountparser.h users.h ugcontainer.h lastcontainer.h groups.h
plugindata.o: group.h loadavg.h sessionmanager.h sessioncontainer.h
plugindata.o: ../functions/functions.h ../functions/functionbase.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
@ -172,8 +197,7 @@ plugindata.o: ../functions/last.h ../functions/login.h ../functions/logout.h
plugindata.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
plugindata.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
plugindata.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
plugindata.o: ../functions/funthread.h ../core/thread.h
plugindata.o: ../functions/funticket.h ../core/ticket.h
plugindata.o: ../functions/funthread.h ../functions/funticket.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 ../core/htmlfilter.h
@ -182,17 +206,21 @@ plugindata.o: ../core/item.h misc.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 htmlfilter.h
postmultiparser.o: postmultiparser.h error.h requesttypes.h config.h
postmultiparser.o: confparser.h htmlfilter.h log.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 config.h confparser.h htmlfilter.h
request.o: request.h requesttypes.h session.h item.h error.h log.h user.h
request.o: plugindata.h rebus.h config.h confparser.h htmlfilter.h plugin.h
request.o: pluginmsg.h system.h dirs.h dircontainer.h db.h group.h thread.h
request.o: ugcontainer.h ticket.h mounts.h mount.h mountparser.h users.h
request.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
request.o: sessioncontainer.h ../functions/functions.h
request.o: ../functions/functionbase.h ../core/item.h ../core/db.h
request.o: request.h requesttypes.h session.h item.h error.h user.h
request.o: plugindata.h rebus.h config.h confparser.h htmlfilter.h log.h
request.o: plugin.h pluginmsg.h system.h dirs.h dircontainer.h ../db/db.h
request.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
request.o: ../core/textstream.h ../db/dbitemquery.h ../core/item.h
request.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
request.o: ../core/thread.h ../core/error.h ../core/dircontainer.h
request.o: ../core/ugcontainer.h ../core/ticket.h mounts.h mount.h
request.o: mountparser.h users.h ugcontainer.h lastcontainer.h groups.h
request.o: group.h loadavg.h sessionmanager.h sessioncontainer.h
request.o: ../functions/functions.h ../functions/functionbase.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/adduser.h ../functions/cat.h ../functions/chmod.h
@ -205,26 +233,29 @@ 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 ../core/ticket.h
request.o: ../functions/template.h ../functions/tinymce.h
request.o: ../functions/uname.h ../functions/upload.h ../functions/uptime.h
request.o: ../functions/who.h ../core/htmlfilter.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
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/funticket.h ../functions/template.h
request.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
request.o: ../functions/uptime.h ../functions/who.h ../core/htmlfilter.h
request.o: ../templates/templates.h ../templates/patterncacher.h
request.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
request.o: ../core/httpsimpleparser.h ../core/log.h
request.o: ../templates/indexpatterns.h ../templates/localefilter.h
request.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
session.o: session.h item.h error.h user.h plugindata.h rebus.h
sessioncontainer.o: sessioncontainer.h session.h item.h error.h user.h
sessioncontainer.o: plugindata.h rebus.h lastcontainer.h log.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: error.h user.h plugindata.h rebus.h lastcontainer.h
sessionmanager.o: config.h confparser.h htmlfilter.h request.h requesttypes.h
sessionmanager.o: system.h dirs.h dircontainer.h db.h group.h thread.h
sessionmanager.o: ugcontainer.h ticket.h mounts.h mount.h mountparser.h
sessionmanager.o: users.h groups.h loadavg.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: system.h dirs.h dircontainer.h ../db/db.h ../db/dbbase.h
sessionmanager.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h
sessionmanager.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
sessionmanager.o: ../core/user.h ../core/group.h ../core/thread.h
sessionmanager.o: ../core/error.h log.h ../core/dircontainer.h
sessionmanager.o: ../core/ugcontainer.h ../core/ticket.h mounts.h mount.h
sessionmanager.o: mountparser.h users.h ugcontainer.h groups.h group.h
sessionmanager.o: loadavg.h sessionparser.h plugin.h pluginmsg.h
sessionmanager.o: ../functions/functions.h ../functions/functionbase.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
@ -239,8 +270,7 @@ sessionmanager.o: ../functions/logout.h ../functions/ls.h
sessionmanager.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
sessionmanager.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
sessionmanager.o: ../functions/run.h ../functions/subject.h
sessionmanager.o: ../functions/funthread.h ../core/thread.h
sessionmanager.o: ../functions/funticket.h ../core/ticket.h
sessionmanager.o: ../functions/funthread.h ../functions/funticket.h
sessionmanager.o: ../functions/template.h ../functions/tinymce.h
sessionmanager.o: ../functions/uname.h ../functions/upload.h
sessionmanager.o: ../functions/uptime.h ../functions/who.h
@ -250,20 +280,32 @@ 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 config.h
sessionparser.o: confparser.h htmlfilter.h db.h group.h thread.h
sessionparser.o: dircontainer.h ticket.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 config.h confparser.h htmlfilter.h
system.o: mounts.h mount.h mountparser.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
users.o: users.h user.h ugcontainer.h log.h lastcontainer.h request.h
sessionparser.o: sessionparser.h session.h item.h error.h user.h plugindata.h
sessionparser.o: rebus.h sessioncontainer.h lastcontainer.h users.h
sessionparser.o: ugcontainer.h request.h requesttypes.h config.h confparser.h
sessionparser.o: htmlfilter.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
sessionparser.o: ../db/dbtextstream.h ../core/textstream.h
sessionparser.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
sessionparser.o: ../core/user.h ../core/group.h ../core/thread.h
sessionparser.o: ../core/error.h log.h ../core/dircontainer.h
sessionparser.o: ../core/ugcontainer.h ../core/ticket.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
system.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
system.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
system.o: log.h ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
system.o: request.h requesttypes.h session.h error.h user.h plugindata.h
system.o: rebus.h config.h confparser.h htmlfilter.h mounts.h mount.h
system.o: mountparser.h users.h ugcontainer.h lastcontainer.h groups.h
system.o: group.h loadavg.h misc.h notify.h
system.o: ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
system.o: ../core/mount.h ../core/locale.h ../core/config.h
system.o: ../templates/misc.h ../templates/localefilter.h ../core/locale.h
textstream.o: textstream.h
users.o: users.h user.h ugcontainer.h lastcontainer.h request.h
users.o: requesttypes.h session.h item.h error.h plugindata.h rebus.h
users.o: config.h confparser.h htmlfilter.h db.h group.h thread.h
users.o: dircontainer.h ticket.h
users.o: config.h confparser.h htmlfilter.h ../db/db.h ../db/dbbase.h
users.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h
users.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
users.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
users.o: log.h ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h

View File

@ -1 +1 @@
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 bbcodeparser.o compress.o config.o confparser.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 textstream.o users.o

View File

@ -21,6 +21,8 @@ App::App()
stdout_is_closed = false;
last_sessions_save = time(0);
db.SetConn(db_conn);
plugin.SetDb(&db);
plugin.SetConfig(&config);
plugin.SetRequest(&request);
@ -131,8 +133,9 @@ return true;
bool App::Init()
{
db.Init(config.db_database, config.db_user, config.db_pass);
db.WaitForConnection();
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
db_conn.WaitForConnection();
db.LogQueries(config.log_db_query);
if( !CreateFCGISocket() )
return false;

View File

@ -25,7 +25,7 @@
#include "request.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"
@ -67,7 +67,7 @@ public:
// database
Db db;
DbConn db_conn;

View File

@ -99,6 +99,7 @@ void Config::AssignValues(bool stdout_is_closed)
log_level = Int("log_level", 1);
log_request = Int("log_request", 1);
log_stdout = Bool("log_stdout", false);
log_db_query = Bool("log_db_query", false);
post_file_max = Int("post_file_max", 8388608); // 8 MB
auth_simplefs_dir = Text("auth_simplefs_dir");

View File

@ -39,6 +39,10 @@ public:
// default: 1
int log_request;
// logging db queries
// default: false
bool log_db_query;
// request delimiter in the log file, default "---------"
std::string log_delimiter;

View File

@ -17,7 +17,7 @@
#include "item.h"
#include "dircontainer.h"
#include "db.h"
#include "db/db.h"
#include "request.h"

View File

@ -14,7 +14,7 @@
#include "group.h"
#include "ugcontainer.h"
#include "db.h"
#include "db/db.h"

View File

@ -10,7 +10,7 @@
#include "mounts.h"
#include "request.h"
#include "log.h"
#include "db.h"
#include "db/db.h"
#include "plugin.h"

View File

@ -18,7 +18,7 @@
#include "mount.h"
#include "error.h"
#include "dirs.h"
#include "db.h"
#include "db/db.h"
#include "request.h"
#include "mountparser.h"

View File

@ -13,7 +13,7 @@
#include "dirs.h"
#include "mounts.h"
#include "db.h"
#include "db/db.h"
#include "request.h"
#include "config.h"
#include "users.h"

126
core/textstream.cpp Executable file
View File

@ -0,0 +1,126 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "textstream.h"
void TextStream::Clear()
{
buffer.clear();
}
const std::string & TextStream::Str() const
{
return buffer;
}
const char * TextStream::CStr() const
{
return buffer.c_str();
}
TextStream & TextStream::operator<<(const char * str)
{
buffer += str;
return *this;
}
TextStream & TextStream::operator<<(const std::string * str)
{
buffer += *str;
return *this;
}
TextStream & TextStream::operator<<(const std::string & str)
{
buffer += str;
return *this;
}
TextStream & TextStream::operator<<(char v)
{
buffer += v;
return *this;
}
TextStream & TextStream::operator<<(int v)
{
char buf[50];
sprintf(buf, "%d", v);
buffer += buf;
return *this;
}
TextStream & TextStream::operator<<(long v)
{
char buf[50];
sprintf(buf, "%ld", v);
buffer += buf;
return *this;
}
TextStream & TextStream::operator<<(unsigned int v)
{
char buf[50];
sprintf(buf, "%u", v);
buffer += buf;
return *this;
}
TextStream & TextStream::operator<<(unsigned long v)
{
char buf[50];
sprintf(buf, "%lu", v);
buffer += buf;
return *this;
}
TextStream & TextStream::operator<<(double v)
{
char buf[50];
sprintf(buf, "%f", v);
buffer += buf;
return *this;
}
TextStream & TextStream::operator<<(const void * v)
{
char buf[50];
sprintf(buf, "%p", v);
buffer += buf;
return *this;
}

47
core/textstream.h Executable file
View File

@ -0,0 +1,47 @@
/*
* 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>
class TextStream
{
public:
void Clear();
const std::string & Str() const;
const char * CStr() const;
TextStream & operator<<(const char * str);
TextStream & operator<<(const std::string * str);
TextStream & operator<<(const std::string & str);
TextStream & operator<<(char);
TextStream & operator<<(int);
TextStream & operator<<(long);
TextStream & operator<<(unsigned int);
TextStream & operator<<(unsigned long);
TextStream & operator<<(double);
TextStream & operator<<(const void *);// printing a pointer
protected:
std::string buffer;
};
#endif

View File

@ -15,7 +15,7 @@
#include "ugcontainer.h"
#include "lastcontainer.h"
#include "request.h"
#include "db.h"
#include "db/db.h"
class Users

22
db/Makefile Executable file
View File

@ -0,0 +1,22 @@
include Makefile.o.dep
all: $(o)
.SUFFIXES: .cpp .o
.cpp.o:
$(CXX) -c $(CXXFLAGS) $<
depend:
makedepend -Y. -I.. -I../../ezc/src -f- *.cpp > Makefile.dep
echo -n "o = " > Makefile.o.dep
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
clean:
rm -f *.o
include Makefile.dep

15
db/Makefile.dep Executable file
View File

@ -0,0 +1,15 @@
# DO NOT DELETE
db.o: db.h dbbase.h dbconn.h dbtextstream.h ../core/textstream.h
db.o: dbitemquery.h ../core/item.h dbitemcolumns.h ../core/user.h
db.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
db.o: ../core/dircontainer.h ../core/item.h ../core/ugcontainer.h
db.o: ../core/ticket.h ../core/log.h ../core/misc.h
dbbase.o: dbbase.h dbconn.h dbtextstream.h ../core/textstream.h ../core/log.h
dbbase.o: ../core/error.h ../core/log.h
dbconn.o: dbconn.h dbtextstream.h ../core/textstream.h ../core/log.h
dbconn.o: ../core/error.h ../core/log.h
dbitemcolumns.o: dbitemcolumns.h ../core/item.h dbbase.h dbconn.h
dbitemcolumns.o: dbtextstream.h ../core/textstream.h
dbitemquery.o: dbitemquery.h ../core/item.h
dbtextstream.o: dbtextstream.h ../core/textstream.h

1
db/Makefile.o.dep Executable file
View File

@ -0,0 +1 @@
o = db.o dbbase.o dbconn.o dbitemcolumns.o dbitemquery.o dbtextstream.o

1424
db/db.cpp

File diff suppressed because it is too large Load Diff

169
db/db.h
View File

@ -7,43 +7,41 @@
*
*/
#ifndef headerfilecmslucoredb
#define headerfilecmslucoredb
#ifndef headerfile_winix_db_db
#define headerfile_winix_db_db
#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"
#include "dbbase.h"
#include "dbitemquery.h"
#include "dbitemcolumns.h"
#include "core/item.h"
#include "core/user.h"
#include "core/group.h"
#include "core/thread.h"
#include "core/error.h"
#include "core/dircontainer.h"
#include "core/ugcontainer.h"
#include "core/ticket.h"
class Db
class Db : public DbBase
{
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);
void WaitForConnection();
bool CheckUser(const std::string & login, const std::string & password, long & user_id);
Error AddUser(User & user, const std::string & password);
@ -54,91 +52,9 @@ public:
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 sel_html_template; // template
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;
sel_html_template= 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_tab, const ItemQuery & item_query);
void GetItems(std::vector<long> & item_tab, const ItemQuery & item_query);
void GetItems(std::vector<Item> & item_tab, const DbItemQuery & item_query);
void GetItems(std::vector<long> & item_tab, const DbItemQuery & item_query);
// !! pobiera tylko jeden item (cos wymyslec innego z nazwa albo argumentem)
@ -171,12 +87,6 @@ public:
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);
@ -197,24 +107,9 @@ public:
protected:
PGconn * pg_conn;
std::string db_database, db_user, db_pass;
bool close_at_end;
void SetDbParameters();
void Close();
bool AssertConnection(bool put_log = true, bool throw_if_no_connection = true);
DbTextStream query, query_create_url;
std::string temp_url;
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);
@ -227,24 +122,15 @@ protected:
void CheckAllUrlSubjectModifyItem(Item & item);
PGresult * GetItemsQuery(const ItemQuery & iq, bool skip_other_sel = false);
PGresult * GetItemsQuery(const DbItemQuery & 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, html_template;
void SetColumns(PGresult * r);
void SetItem(PGresult * r, long row, Item & item);
};
// !! tymczasowo
// bedzie wszystko w osobnym pluginie
struct TicketColumns
{
int id, dir_id, parent_id, type, status, priority, category, expected, progress, item_id;
@ -253,10 +139,7 @@ protected:
void SetTicket(PGresult * r, long row, Ticket & ticket);
};
}; // class Db
};
#endif

View File

@ -1,99 +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");
html_template = PQfnumber(r, "template");
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( html_template != -1 ) item.html_template = Db::AssertValue(r, row, html_template);
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) );
}

301
db/dbbase.cpp Executable file
View File

@ -0,0 +1,301 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "dbbase.h"
#include "core/log.h"
#include "core/error.h"
#include <stdlib.h>
#include <limits.h>
#include <limits>
DbBase::DbBase()
{
db_conn = 0;
log_queries = false;
}
void DbBase::SetConn(DbConn * conn)
{
db_conn = conn;
}
void DbBase::SetConn(DbConn & conn)
{
db_conn = &conn;
}
DbConn * DbBase::GetConn()
{
return db_conn;
}
void DbBase::LogQueries(bool log_q)
{
log_queries = log_q;
}
PGresult * DbBase::AssertQuery(const char * q)
{
if( log_queries )
log << log1 << "Db: executing query: " << q << logend;
bool bad_query = false;
PGresult * r = PQexec(db_conn->GetPgConn(), q);
if( !r )
{
bad_query = true;
if( PQstatus(db_conn->GetPgConn()) != CONNECTION_OK )
{
db_conn->AssertConnection();
r = PQexec(db_conn->GetPgConn(), q);
if( r )
bad_query = false;
}
}
if( bad_query )
{
log << log1 << "Db: Problem with this query: \"" << q << '\"' << logend;
log << log1 << "Db: " << PQerrorMessage(db_conn->GetPgConn()) << logend;
throw Error(WINIX_ERR_DB_INCORRECT_QUERY);
}
return r;
}
PGresult * DbBase::AssertQuery(const std::string & q)
{
return AssertQuery(q.c_str());
}
PGresult * DbBase::AssertQuery(const DbTextStream & query)
{
return AssertQuery(query.CStr());
}
void DbBase::AssertResult(PGresult * r, ExecStatusType t)
{
if( PQresultStatus(r) != t )
{
log << "Db: Incorrect result status: " << PQerrorMessage(db_conn->GetPgConn()) << logend;
throw Error(WINIX_ERR_DB_INCORRENT_RESULT_STATUS);
}
}
int DbBase::AssertColumn(PGresult * r, const char * column_name)
{
int c = PQfnumber(r, column_name);
if( c == -1 )
{
log << log1 << "Db: there is no column: " << column_name << logend;
throw Error(WINIX_ERR_DB_NO_COLUMN);
}
return c;
}
const char * DbBase::AssertValue(PGresult * r, int row, int col)
{
const char * res = PQgetvalue(r, row, col);
if( !res )
{
log << log1 << "Db: there is no such an item in the result, row:" << row << ", col:" << col << logend;
throw Error(WINIX_ERR_NO_ITEM);
}
return res;
}
long DbBase::AssertValueLong(PGresult * r, int row, int col)
{
return strtol( AssertValue(r, row, col), 0, 10 );
}
int DbBase::AssertValueInt(PGresult * r, int row, int col)
{
return (int)strtol( AssertValue(r, row, col), 0, 10 );
}
unsigned long DbBase::AssertValueULong(PGresult * r, int row, int col)
{
return strtoul( AssertValue(r, row, col), 0, 10 );
}