/* Replace some template variables (filename of last config) call index_html_template */ int index_html(void *data, onion_request *req, onion_response *res, void* foo, void* datafree) { // printf("Pointer in callback: %p %p %p)\n",data,p,datafree); onion_dict *d=onion_dict_new(); if( data != NULL){ onion_dict_add(d, "LAST_SETTING_FILENAME",((JsonConfig*)data)->getString("lastSetting"),0); } return index_html_template(d, req, res); }
void t05_context(){ INIT_LOCAL(); Onion::Dict dict(defaultContext()); ONION_DEBUG("Render"); // This is important as otemplate templates need ownership as they // will free the pointer. These way we use the internal refcount to avoid double free. onion_dict_dup(dict.c_handler()); index_html_template(dict.c_handler()); END_LOCAL(); }
/* Replace some template variables (filename of last config) call index_html_template */ onion_connection_status OnionServer::index_html( Onion::Request &req, Onion::Response &res) { /* Problem: This cause double free of mem because * onion_dict_free will called twice: in index_html_template and deconstructor. * Onion::Dict d; std::string key("LAST_SETTING_FILENAME"); d.add(key,m_b9CreatorSettings.m_configFilename,0); return index_html_template(d.c_handler(), req.c_handler(), res.c_handler() ); */ onion_dict *d=onion_dict_new();//will free'd in template call onion_dict_add( d, "LAST_SETTING_FILENAME", m_b9CreatorSettings.m_configFilename.c_str(), 0); return index_html_template(d, req.c_handler(), res.c_handler() ); }
/* Replace some template variables (filename of last config) call index_html_template */ onion_connection_status OnionServer::index_html( Onion::Request &req, Onion::Response &res) { /* Issue note: The following cause double free of mem because * onion_dict_free will called twice: in index_html_template and deconstructor. * Onion::Dict d; std::string key("LAST_SETTING_FILENAME"); d.add(key,m_settingKinect.m_configFilename,0); return index_html_template(d.c_handler(), req.c_handler(), res.c_handler() ); => Thus, use pointer, but do not free here. */ onion_dict *d=onion_dict_new();//will free'd in template call onion_dict_add( d, "LAST_SETTING_FILENAME", m_settingKinect.m_configFilename.c_str(), 0); return index_html_template(d, req.c_handler(), res.c_handler() ); }