本文整理汇总了C++中onion::Response::c_handler方法的典型用法代码示例。如果您正苦于以下问题:C++ Response::c_handler方法的具体用法?C++ Response::c_handler怎么用?C++ Response::c_handler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类onion::Response
的用法示例。
在下文中一共展示了Response::c_handler方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: render_to_response
onion_connection_status Onion::render_to_response(::Onion::template_f fn, const ::Onion::Dict& context, ::Onion::Response &res) {
ONION_DEBUG("Context: %s", context.toJSON().c_str());
onion_dict *d=onion_dict_dup( context.c_handler() );
fn(d, res.c_handler());
return OCS_PROCESSED;
}
示例2: getSettingKinectWrapped
/* Like 'search_file' */
onion_connection_status OnionServer::getSettingKinectWrapped(
Onion::Request &req, Onion::Response &res)
{
const char* path = onion_request_get_fullpath( req.c_handler() );
#ifdef VERBOSE
printf("Request of %s.\n",path);
#endif
std::string filename("./html/");
filename.append(path);
std::ifstream file(filename.c_str());
std::string line;
if( file.is_open()){
/* Create header with mime type and charset information for several file extensions.
* This is just a workaround. There should be an automatic mechanicm
* in libonion. */
int periodPos = filename.find_last_of('.');
std::string extension = filename.substr(periodPos+1);
std::string key("Content-Type");
std::string defaultType("text/html; charset: utf-8");
std::string mime = m_mimedict.get( extension , defaultType ) ;
res.setHeader(key,mime);
onion_response_write_headers(res.c_handler());// missing in cpp bindings?
//res.writeHeaders();//this was added by me...
try{
/*
res.write("json_kinect = ", 14);
const char* kinect = m_settingKinect.getConfig(true);
size_t len = strlen( kinect );
res.write(kinect, (int) len );
res.write(";\n", 2 );
*/
while (std::getline(file, line)) {
res.write( line.c_str(), line.size() );
res.write("\n", 1 );
}
}//catch ( const boost::iobase::failure &ex )
catch ( const std::exception & ex ){
std::cerr << "Can not read " << filename << std::endl;
res.write( ErrReadFailed.c_str(), ErrReadFailed.size());
}
}else{
res.write( ErrNotFound.c_str(), ErrNotFound.size());
}
return OCS_PROCESSED;
}
示例3: key
/*
Replace some template variables and send b9creator_settings.js
*/
onion_connection_status OnionServer::getB9CreatorSettingsWrapped(
Onion::Request &req, Onion::Response &res)
{
/*
std::string key("ONION_JSON");
std::string conf(m_b9CreatorSettings.getConfig());
Onion::Dict d;
d.add(key, conf, 0);
return b9creator_settings_js_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, "ONION_JSON",
m_b9CreatorSettings.getConfig(), 0);
return b9creator_settings_js_template(d, req.c_handler(), res.c_handler());
}
示例4: index_html
/*
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() );
}
示例5: index_html
/*
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() );
}
示例6: redirect
onion_connection_status Onion::redirect(const std::string& url, ::Onion::Request& req, ::Onion::Response& res)
{
return onion_shortcut_redirect(url.c_str(), req.c_handler(), res.c_handler());
}
示例7: extended_html_template
onion_connection_status extended_html_template(Onion::Request &req, Onion::Response &res){
extended_html_template(NULL,req.c_handler(), res.c_handler());
}