// Error-code semantics boost::system::error_code load(parse_options parse_opts, boost::system::error_code& ec , char** base_environment = NULL, bool is_command_line = true) { // Parse just the environment first, then check the user // isn't trying to upload more data than we want to let them. // Define `BOOST_CGI_POST_MAX` to set the maximum content-length // allowed. if (parse_opts & parse_env) { //this->service.load(this->implementation, parse_env, ec); //if (content_length() >= BOOST_CGI_POST_MAX) // ec = common::error::max_post_exceeded; this->service.load(this->implementation, parse_opts, ec); if (ec) return ec; // Load the environment passed by the user. if (base_environment) this->service.load_environment( this->implementation, base_environment , is_command_line); if (parse_opts & parse_env) env.set(env_vars(this->implementation.vars_)); if (parse_opts & parse_get_only) get.set(get_vars(this->implementation.vars_)); if (parse_opts & parse_post_only) { post.set(post_vars(this->implementation.vars_)); uploads.set(upload_vars(this->implementation.vars_)); } if ((parse_opts & parse_cookies) == parse_cookies) { cookies.set(cookie_vars(this->implementation.vars_)); } if ((parse_opts & parse_form_only) == parse_form_only) { common::name rm(request_method().c_str()); form.set(rm == "POST" ? post.impl() : get.impl()); } #ifdef BOOST_CGI_ENABLE_SESSIONS if (parse_opts & parse_session_only) { if (!!cookies && cookies.count(BOOST_CGI_SESSION_COOKIE_NAME)) session.id(cookies[BOOST_CGI_SESSION_COOKIE_NAME]); else if (traits::auto_start_session) session.id(this->service.make_session_id()); if (!session.id().empty()) this->service.session_manager().load(session); } #endif // BOOST_CGI_ENABLE_SESSIONS } return ec; }
int main (int argc, char *argv[]) { char *file_name = "/dev/query"; int fd; enum { e_get = 0, e_clr, e_set, } option; if (argc == 1) option = e_get; else if (argc == 2) { if (strcmp(argv[1], "-g") == 0) { option = e_get; } else if (strcmp(argv[1], "-c") == 0) { option = e_clr; } else if (strcmp(argv[1], "-s") == 0) { option = e_set; } else { fprintf (stderr, "Usage: %s [-g | -c | -s]\n", argv[0]); return -1; } } else { fprintf (stderr, "Usage: %s [-g | -c | -s] \n", argv[0]); return -1; } if (fd == -1) { perror ("query_apss open"); return 2; } switch (option) { case e_get : get_vars (fd); break; case e_clr : clr_vars (fd); break; case e_set : get_set (fd); break; default: break; } close (fd); return 0; }
int main(int argc, char* argv[]) { std::vector<std::string> pragma_values; SgProject* proj = frontend(argc,argv); ROSE_ASSERT(proj != NULL); SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj); SgFunctionDefinition* mainDef = mainDefDecl->get_definition(); Rose_STL_Container<SgNode*> pragmaList = NodeQuery::querySubTree(proj,V_SgPragmaDeclaration); for (Rose_STL_Container<SgNode*>::iterator i = pragmaList.begin(); i != pragmaList.end(); i++) { SgPragmaDeclaration* prg = isSgPragmaDeclaration(*i); std::string prag_string = get_pragma_string(prg); if (isSMTGeneral(prag_string)) { std::string parsed = parseSMTGeneral(prag_string); std::cout << ";;SMTGeneral command found: " << parsed << std::endl; //continue; } else { //std::cout << "SMTGeneral command not found" << std::endl; std::string pos; pos = get_position(prag_string); if (pos == "define") { std::cout << "define:\n"; std::vector<std::pair<std::string, std::string> > pragma_values = get_vars(prag_string); for (std::vector<std::pair<std::string,std::string> >::iterator j = pragma_values.begin(); j != pragma_values.end(); j++) { std::cout << (*j).first << " " << (*j).second << std::endl; } } else if (pos == "assume") { std::cout << "assume:\n"; std::vector<std::string> assumptions = get_assumptions(prag_string); for (std::vector<std::string>::iterator i = assumptions.begin(); i != assumptions.end(); i++) { std::cout << (*i) << std::endl; } } else if (pos == "begin" || pos == "end") { std::cout << "position: " << pos << std::endl; } else { ROSE_ASSERT(false); } } } return 0; }
static ngx_int_t init(ngx_conf_t *cf) { if(!get_vars) { return NGX_OK; } for (auto v = get_vars(); v->name.len; ++v) { var_type var = ngx_add_variable(cf, &v->name, v->flags); NgxException::fail(!var); var.handler(v->get_handler, v->data); } return NGX_OK; }
static int hext_daq_initialize ( const DAQ_Config_t* cfg, void** handle, char* errBuf, size_t errMax) { FileImpl* impl = calloc(1, sizeof(*impl)); if ( !impl ) { snprintf(errBuf, errMax, "%s: failed to allocate the ipfw context", DAQ_NAME); return DAQ_ERROR_NOMEM; } impl->snaplen = cfg->snaplen ? cfg->snaplen : DEF_BUF_SZ; impl->dlt = DLT_USER; if ( !get_vars(impl, cfg, errBuf, errMax) ) { free(impl); return DAQ_ERROR; } if ( cfg->name ) { if ( !(impl->name = strdup(cfg->name)) ) { snprintf(errBuf, errMax, "%s: failed to allocate the filename", DAQ_NAME); free(impl); return DAQ_ERROR_NOMEM; } } if ( !(impl->buf = malloc(impl->snaplen)) ) { snprintf(errBuf, errMax, "%s: failed to allocate the ipfw buffer", DAQ_NAME); hext_daq_shutdown(impl); return DAQ_ERROR_NOMEM; } impl->state = DAQ_STATE_INITIALIZED; *handle = impl; return DAQ_SUCCESS; }
static ast::Exp* get_exp(void) { ast::Exp* exp; // std::cerr << "get_exp at pos " << (buf - initial_buf) << std::endl; int code = get_uint8(); // std::cerr << " code = " << code << std::endl; Location *loc = get_location(); int is_verbose = get_bool(); int is_break = get_bool(); int is_breakable = get_bool(); int is_return = get_bool(); int is_returnable = get_bool(); int is_continue = get_bool(); int is_continuable = get_bool(); switch(code){ case 1: { std::list<ast::Exp *>* l_body = get_exps(); exp = new ast::SeqExp(*loc, *l_body); break; } case 2: { std::wstring* s = get_wstring(); exp = new ast::StringExp(*loc, *s); break; } case 3: { std::wstring* s = get_wstring(); exp = new ast::CommentExp(*loc, s); break; } case 4: { ast::IntExp::Prec prec = get_IntExp_Prec(); int value = get_int32(); exp = new ast::IntExp(*loc, prec, value); break; } case 5: { double d = get_double(); exp = new ast::FloatExp(*loc, d); break; } case 6: { double d = get_double(); exp = new ast::DoubleExp(*loc,d); break; } case 7: { bool b = get_bool(); exp = new ast::BoolExp(*loc, b); break; } case 8: { exp = new ast::NilExp(*loc); break; } case 9: { symbol::Symbol *name = get_Symbol(); exp = new ast::SimpleVar(*loc, *name); break; } case 10: { exp = new ast::ColonVar(*loc); break; } case 11: { exp = new ast::DollarVar(*loc); break; } case 12: { std::list<ast::Var*>* vars = get_vars(); exp = new ast::ArrayListVar(*loc, *vars); break; } case 13: { ast::Exp *head = get_exp(); ast::Exp *tail = get_exp(); exp = new ast::FieldExp(*loc, *head, *tail); break; } case 14: { ast::IfExp::Kind kind = get_IfExp_Kind(); bool has_else = get_bool(); ast::Exp* test = get_exp(); ast::Exp* _then = get_exp(); ast::IfExp* ifexp; if( has_else ){ ast::Exp* _else = get_exp(); ifexp = new ast::IfExp(*loc, *test, *_then, *_else); } else { ifexp = new ast::IfExp(*loc, *test, *_then); } ifexp->kind_set(kind); exp = ifexp; break; } case 15: { Location *try_location = get_location(); Location *catch_location = get_location(); std::list<ast::Exp *>* try_exps = get_exps(); std::list<ast::Exp *>* catch_exps = get_exps(); ast::SeqExp *_try = new ast::SeqExp(*try_location, *try_exps); ast::SeqExp *_catch = new ast::SeqExp(*catch_location, *catch_exps); exp = new ast::TryCatchExp(*loc, *_try, *_catch); break; } case 16: { ast::Exp* test = get_exp(); ast::Exp* body = get_exp(); exp = new ast::WhileExp(*loc, *test, *body); break; } case 17: { Location *vardec_location = get_location(); ast::VarDec* vardec = get_VarDec(vardec_location); ast::Exp* body = get_exp(); exp = new ast::ForExp(*loc, *vardec, *body); break; } case 18: { exp = new ast::BreakExp(*loc); break; } case 19: { exp = new ast::ContinueExp(*loc); break; } case 20: { bool is_global = get_bool(); if( is_global ){ exp = new ast::ReturnExp(*loc); } else { ast::Exp* returnExp_exp = get_exp(); exp = new ast::ReturnExp(*loc, returnExp_exp); } break; } case 21: { bool has_default = get_bool(); ast::SeqExp * default_case = NULL; if( has_default ){ Location *default_case_location = get_location(); std::list<ast::Exp *>* default_case_exps = get_exps(); default_case = new ast::SeqExp(*default_case_location, *default_case_exps); } ast::Exp* select = get_exp(); int nitems = get_uint32(); std::list<ast::CaseExp*> *cases = new std::list<ast::CaseExp*>; for(int i = 0; i < nitems; i++){ Location *case_location = get_location(); Location *body_location = get_location(); ast::Exp* test = get_exp(); std::list<ast::Exp *>* body_exps = get_exps(); ast::SeqExp *body = new ast::SeqExp(*body_location, *body_exps); ast::CaseExp* _case = new ast::CaseExp(*case_location, *test, *body); cases->push_back(_case); } if( has_default ){ exp = new ast::SelectExp(*loc, *select, *cases, *default_case); } else { exp = new ast::SelectExp(*loc, *select, *cases); } break; } /* SHOULD NEVER HAPPEN case 22: { exp = new ast::CaseExp(*loc); break; } */ case 23: { std::list<ast::MatrixLineExp *>* lines = get_MatrixLines(); exp = new ast::CellExp(*loc, *lines); break; } case 24: { std::list<ast::Exp *>* exps = get_exps(); exp = new ast::ArrayListExp(*loc, *exps); break; } case 25: { std::list<ast::Exp *>* exps = get_exps(); exp = new ast::AssignListExp(*loc, *exps); break; } case 26: { ast::Exp* notexp = get_exp(); exp = new ast::NotExp(*loc, *notexp); break; } case 27: { ast::TransposeExp::Kind kind = get_TransposeExp_Kind(); ast::Exp* _exp = get_exp(); exp = new ast::TransposeExp(*loc, *_exp, kind); break; } case 28: { exp = get_VarDec(loc); break; } case 29: { symbol::Symbol* name = get_Symbol(); Location *args_loc = get_location(); Location *returns_loc = get_location(); ast::Exp* body = get_exp(); std::list <ast::Var*>* args_list = get_vars(); std::list <ast::Var*>* returns_list = get_vars(); ast::ArrayListVar *args = new ast::ArrayListVar(*args_loc, *args_list); ast::ArrayListVar *returns = new ast::ArrayListVar(*returns_loc, *returns_list); exp = new ast::FunctionDec(*loc, *name, *args, *returns, *body); break; } case 30: { ast::Exp* _start = get_exp(); ast::Exp* _step = get_exp(); ast::Exp* _end = get_exp(); exp = new ast::ListExp(*loc, *_start, *_step, *_end); break; } case 31: { ast::Exp* _left = get_exp(); ast::Exp* _right = get_exp(); exp = new ast::AssignExp(*loc, *_left, *_right); break; } case 32: { ast::OpExp::Kind kind = get_OpExp_Kind(); ast::OpExp::Oper oper = get_OpExp_Oper(); ast::Exp *left = get_exp(); ast::Exp *right = get_exp(); ast::OpExp *_opexp = new ast::OpExp(*loc, *left, oper, *right); exp = _opexp; _opexp->kind_set(kind); break; } case 33: { ast::OpExp::Kind kind = get_OpExp_Kind(); ast::OpExp::Oper oper = get_OpExp_Oper(); ast::Exp *left = get_exp(); ast::Exp *right = get_exp(); ast::LogicalOpExp *_opexp = new ast::LogicalOpExp(*loc, *left, oper, *right); exp = _opexp; _opexp->kind_set(kind); break; } case 34: { std::list<ast::MatrixLineExp *>* lines = get_MatrixLines(); exp = new ast::MatrixExp(*loc, *lines); break; } case 35: { ast::Exp* name = get_exp(); std::list<ast::Exp *> * args = get_exps(); exp = new ast::CallExp(*loc, *name, *args); break; } /* SHOULD NEVER HAPPEN case 36: { exp = new ast::MatrixLineExp(*loc); break; } */ case 37: { ast::Exp* name = get_exp(); std::list<ast::Exp *>* args = get_exps(); exp = new ast::CellCallExp(*loc, *name, *args); break; } default: std::cerr << "Unknown code " << code << std::endl; exit(2); } exp->set_verbose(is_verbose); if(is_break) exp->break_set(); if(is_breakable) exp->breakable_set(); if(is_return) exp->return_set(); if(is_returnable) exp->returnable_set(); if(is_continue) exp->continue_set(); if(is_continuable) exp->continuable_set(); return exp; }
/* @details -# scan the incoming message for the command and requested path -# start the return message with a "{" -# if both a command and request is present -# if the command is "GET" -# if the path is "/" call get_top_page -# else if the path starts with "/vars" call get_vars -# else if the path starts with "/commands" call get_commands -# else create an error message reply -# else if the command is "POST" do something at some point. -# else create an error message reply -# else create an error message reply -# close the return message with a "}" -# create the http header for the reply message -# call tc_write to send the reply message */ void Trick::JSONVariableServerThread::parse_request() { // Need to protect against buffer overflow char command[32] ; char path[512] ; std::stringstream ss ; std::stringstream body ; int ret ; ret = sscanf(incoming_msg, "%s %s", command , path) ; body << "{" << std::endl ; if ( ret == 2 ) { //std::cout << "command = " << command << std::endl ; //std::cout << "path = " << path << std::endl ; if ( ! strcmp(command, "GET") ) { if ( ! strcmp(path, "/") ) { // send the top page ret = get_top_page(body) ; } else if ( ! strncmp(path, "/vars", 5)) { // get list of variables or value ret = get_vars(body, &path[5]) ; } else if ( ! strncmp(path, "/commands", 9)) { // get list of commands ret = get_commands(body, &path[9]) ; } else { ret = 404 ; body << " \"name\" : \"" << path << "\" ," << std::endl ; body << " \"message\" : \"Not Found\"" << std::endl ; } } else if ( ! strcmp( command, "POST") ) { //TODO: Allow setting variable values with POST. ret = 405 ; body << " \"verb\" : \"" << command << "\" ," << std::endl ; body << " \"message\" : \"Method not allowed\"" << std::endl ; } else { ret = 405 ; body << " \"verb\" : \"" << command << "\" ," << std::endl ; body << " \"message\" : \"Method not allowed\"" << std::endl ; } } else { ret = 400 ; body << " \"message\" : \"Bad Request\"" << std::endl ; } body << "}" << std::endl ; ss << "HTTP/1.1 " << ret ; switch (ret) { case 200: ss << " OK" ; break ; case 400: ss << " Bad Request" ; break ; case 404: ss << " Not Found" ; break ; case 405: ss << " Method Not Allowed" ; break ; default: ss << " Unknown" ; break ; } ss << std::endl ; ss << "Content-Type: application/json" << std::endl ; ss << "Content-Length: " << body.str().size() << std::endl << std::endl ; ss << body.str() ; //std::cout << ss.str() ; tc_write(&connection, (char *)ss.str().c_str() , ss.str().size()) ; }
/** * Initialization function for the library. */ EXTCAN_API int init(const char *str) { return get_vars(str); }
SEXP copy_vars(SEXP target, SEXP source) { return set_vars(target, get_vars(source)); }
int main(int argc, char *argv[]) { char *file_name = "/dev/battery"; int fd; enum { e_get, e_clr, e_set } option; if (argc == 1) { option = e_get; } else if (argc == 2) { if (strcmp(argv[1], "-g") == 0) { option = e_get; } else if (strcmp(argv[1], "-c") == 0) { option = e_clr; } else if (strcmp(argv[1], "-s") == 0) { option = e_set; } else { fprintf(stderr, "Usage: %s [-g | -c | -s]\n", argv[0]); return 1; } } else { fprintf(stderr, "Usage: %s [-g | -c | -s]\n", argv[0]); return 1; } fd = open(file_name, O_RDWR); if (fd == -1) { perror("query_apps open"); return 2; } switch (option) { case e_get: get_vars(fd); break; case e_clr: disable_charging(fd); break; case e_set: enable_charge(fd); break; default: break; } close (fd); return 0; }