Hello,

> addChild(&rssFeed);
you should not use addChild with objects created on stack.
addChild must be applied to dynamicaly allocated objects.

You should create resource, wApp->addChild(resource) to prevent memory leak
of resouce object. Then set internal path.

But for RSS, you should not bind resource object to application at all.
Create server-wide  resource, call server->addResource. In handleRequest,
determine domain and use correct database connection object. You can
pre-create database connections in pools (one pool per each domain).
Database session object would be created and destroyed in handleRequest
(make it a stack object).

Something like std::map<domain, dbo connection pool>.
Make sure you do not change this global object (map) from handleRequest,
because multiple simultaneous handleRequest calls may exist. That is why it
is important to create all pools before start of event loop.

On Mon, Mar 10, 2014 at 3:13 AM, Jeffrey Scott Flesher Gmail <
jeffrey.scott.fles...@gmail.com> wrote:

>  I am trying to write a CMS, my idea of how to handle multiple domains
> was to create an XML file which I read in the constructor of home in the
> wt-home example, so it uses the env.hostName() to get the name of the key
> id, if it fails to find a key id, it will use a default or just return a
> 404 error, so I do not see a security risk here, all that a user can do by
> modifying the header, is to return the wrong results, unless they knew the
> keys, all they would get is a default page or 404 error.
>
> File looks like this:
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <domains>
>     <domain id="default" path="/home/path/default" title="Title"
> user="userName" password="Password" port="5432" dbname="dbName"
> rssTitle="blog Title" rssURL="http://tdl.domain.com/wt/blog";
> rssDescription="Description of rss feed"></domain>
>     <domain id="localhost" path="/home/path/localhost" title="Title"
> user="userName" password="Password" port="5432" dbname="dbName"
> rssTitle="blog Title" rssURL="http://localhost/wt/blog";
> rssDescription="Description of rss feed"></domain>
>     <domain id="tdl.domain.com" path="/home/path/tdl.domain.com"
> title="Title" user="userName" password="Password" port="5432"
> dbname="dbName"  rssTitle="blog Title" rssURL="
> http://tdl.domain.com/wt/blog"; rssDescription="Description of rss
> feed"></domain>
> </domains>
>
> This file is stored in appRoot, so its not accessible to the public, and
> where database details will work for any support database type.
>
> I read the results into a struct called MyCmsDomain which I use use to
> create the database connection and rssFeed:
>         QString filePath = appRoot().c_str();
>         filePath.append("domains.xml");
>         if (!readDomains(env.hostName().c_str(), filePath))
>         {
>             if (!readDomains("default", filePath))
>             {
>                 return; // this should give a blank screen, how to fix,
> just a 404 error
>             }
>         }
> ...
> #ifdef POSTGRES
>         // Wt::Dbo::SqlConnectionPool *blogDb
>         blogDb_ = BlogSession::createConnectionPool("user=" +
> MyCmsDomain.user + " password=" + MyCmsDomain.password + " port=" +
> MyCmsDomain.port + " dbname=" + MyCmsDomain.dbname);
> ...
>
> BlogRSSFeed rssFeed(*blogDb_, MyCmsDomain.rssTitle, MyCmsDomain.rssURL,
> MyCmsDomain.rssDescription);
>
> I don't see any examples of using addChild, how do I do this exactly?
>
> addChild(&rssFeed);
>
> > Use WResource::setInternalPath to set internal path for this resource.
> internalPathChanged().connect(this, &BlogRSSFeed::handleRequest);
> handleRequest is the only function, and does not appear to have the right
> parameters, do I need another one to handle this?
>
> Not sure how this would work, can you give me an example?
>
> Thanks for all the help.
>
>
> On Mon, 2014-03-10 at 02:00 +0400, Nagaev Boris wrote:
>
> Hello!
> > How do I bind the resource to the session, is there a function like> 
> > addResource that does the same thing?
> You can do this using application->addChild(resource) (this makes
> application to delete resource when it is deleted, normal memory
> management). Use WResource::setInternalPath to set internal path for
> this resouce. Please note the resouce will be available only from
> current session in this case.
> > In my case I use the environment env.hostName() to get the database> 
> > connection, so this causes me to change where I need to add this resource.
> env.hostName() is hostname passed in Host HTTP header. Why do you need
> it to connect to your database? Using Host header to determine
> database address may be dangerous, since everyone can tamper with Host
> header making your Wt application to connect to wrong database server.
> Wt application should know database connection parameters itself.
>
> On Mon, Mar 10, 2014 at 1:39 AM, Jeffrey Scott Flesher Gmail
> <jeffrey.scott.fles...@gmail.com> wrote:>> If you want session-specific 
> resource, you should bind it to session>> (parent with application object and 
> use WResource::url() to get URL.> How do I bind the resource to the session, 
> is there a function like> addResource that does the same thing?>>>> If you 
> need database session for you resource, this session object should>> be 
> created along with the resource.> In my case I use the environment 
> env.hostName() to get the database> connection, so this causes me to change 
> where I need to add this resource.>> Thanks for any help.>>> On Sun, 
> 2014-03-09 at 11:23 +0400, Nagaev Boris wrote:>> Hello,>> at least, you 
> should not change WServer from WApplication. Methods> addResource and 
> addEntryPoint should be called before server start> (WServer::start()). If 
> you want session-specific resource, you should> bind it to session (parent 
> with application object and use> WResource::url() to get URL. If you want 
> server-global resource, you> should initialize it and bind to server using 
> addResource BEFORE> server start. If you need database session for you 
> resource, this> session object should be created along with the resource.>> 
> Regards,> Boris Nagaev>>> On Sun, Mar 9, 2014 at 4:50 AM, Jeffrey Scott 
> Flesher Gmail> <jeffrey.scott.fles...@gmail.com> wrote:>> Moving the code in 
> example wt-home from main into the home which is>> derived>> from 
> WApplication, in order to setup the database based on URL, I found>> this>> 
> crashes the system randomly, here is the Code:>>>> BlogRSSFeed 
> rssFeed(*blogDb_, "Witty Wizard blog",>> "http://wittywizard.org/wt/blog";, 
> "Witty Wizard Content Management System>> (CMS)");>> 
> env.server()->addResource(&rssFeed, "/wt/blog/feed/");>>>> Is this the 
> correct way to call addResource from the Constructor of home?>>>> Thanks for 
> any help.>>>>>>>> 
> ------------------------------------------------------------------------------>>
>  Subversion Kills Productivity. Get off Subversion & Make the Move to>> 
> Perforce.>> With Perforce, you get hassle-free workflows. Merge that actually 
> works.>> Faster operations. Version large binaries.  Built-in WAN 
> optimization and>> the>> freedom to use Git, Perforce or both. Make the move 
> to Perforce.>>>> 
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk>>
>  _______________________________________________>> witty-interest mailing 
> list>> witty-interest@lists.sourceforge.net>> 
> https://lists.sourceforge.net/lists/listinfo/witty-interest>>>> 
> ------------------------------------------------------------------------------>
>  Subversion Kills Productivity. Get off Subversion & Make the Move to> 
> Perforce.> With Perforce, you get hassle-free workflows. Merge that actually 
> works.> Faster operations. Version large binaries.  Built-in WAN optimization 
> and> the> freedom to use Git, Perforce or both. Make the move to Perforce.> 
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk> 
> _______________________________________________> witty-interest mailing list> 
> witty-interest@lists.sourceforge.net> 
> https://lists.sourceforge.net/lists/listinfo/witty-interest>>> 
> ------------------------------------------------------------------------------>
>  Subversion Kills Productivity. Get off Subversion & Make the Move to> 
> Perforce.> With Perforce, you get hassle-free workflows. Merge that actually 
> works.> Faster operations. Version large binaries.  Built-in WAN optimization 
> and> the> freedom to use Git, Perforce or both. Make the move to Perforce.> 
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk> 
> _______________________________________________> witty-interest mailing list> 
> witty-interest@lists.sourceforge.net> 
> https://lists.sourceforge.net/lists/listinfo/witty-interest>
>
> ------------------------------------------------------------------------------
> Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
> With Perforce, you get hassle-free workflows. Merge that actually works.
> Faster operations. Version large binaries.  Built-in WAN optimization and the
> freedom to use Git, Perforce or both. Make the move to 
> Perforce.http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
> _______________________________________________
> witty-interest mailing 
> listwitty-interest@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/witty-interest
>
>
>
> ------------------------------------------------------------------------------
> Subversion Kills Productivity. Get off Subversion & Make the Move to
> Perforce.
> With Perforce, you get hassle-free workflows. Merge that actually works.
> Faster operations. Version large binaries.  Built-in WAN optimization and
> the
> freedom to use Git, Perforce or both. Make the move to Perforce.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
> _______________________________________________
> witty-interest mailing list
> witty-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
>
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to