int control_process() { char* buffer = NULL; // 检查用户是否按下了按钮 if (cgiFormSubmitClicked("led1") == cgiFormSuccess) { // 调用 led 1 控制代码 control_led(0); } else if (cgiFormSubmitClicked("led2") == cgiFormSuccess) { // 调用 led 2 控制代码 control_led(1); } else if (cgiFormSubmitClicked("logout") == cgiFormSuccess) { // 退出登录 session_destroy(); cgiHeaderLocation(cgiScriptName); return 0; } // 输出 ContentType header // 作为 CGI 程序必须输出这个 header,否则会导致 500 错误 fprintf(cgiOut, "Pragma: no-cache\n"); cgiHeaderContentType("text/html"); buffer = read_template(g_control_template); if (buffer == NULL) { fprintf(cgiOut, "Warning: Can't read template file: %s.<br />\n", g_control_template); return -1; } fprintf(cgiOut, "%s", buffer); free(buffer); return 0; }
int main(int argc, char *argv[]) { bool success = true; if (argc < 3) { std::cerr << "Syntax error: use" << std::endl; std::cerr << argv[0] << " classname inputpath" << std::endl; return 1; } std::string modname(argv[1]); std::string inputpath(argv[2]); std::string ifname = inputpath + std::string("/") + modname + std::string("_tests.un"); std::string impl_fname = modname + std::string("_test_impls-tmp.F90"); std::string calls_fname = modname + std::string("_test_calls.F90"); std::string list_fname = modname + std::string("_tests.tests"); std::string mpilist_fname = modname + std::string("_tests.mpitests"); std::vector<std::string> input, output; try { success = success && read_template(ifname, input); success = success && replace_modname(modname, input); success = success && parse_impl(ifname, input, output); success = success && write_output(impl_fname, output); output.clear(); success = success && parse_calls(ifname, input, output); success = success && write_output(calls_fname, output); output.clear(); success = success && parse_list(ifname, input, output); success = success && write_output(list_fname, output); output.clear(); success = success && parse_mpilist(ifname, input, output); success = success && write_output(mpilist_fname, output); output.clear(); } catch (ParserException &ex) { std::cerr << "Caught exception: " << ex.getMsg() << std::endl; success = false; } catch (std::string &ex) { std::cerr << "Caught exception: " << ex << std::endl; success = false; } catch (...) { std::cerr << "Caught unknown exception." << std::endl; success = false; } return (success ? 0 : 1); }
ts_generator::ts_generator() : idl_template_(read_template("IDL")) { }
/** * 显示登录页面以及处理用户登录 */ int login_process() { char* username = NULL; char* password = NULL; char* buffer = NULL; int field_buffer_size = 0; REPLACEABLE_TAG_LIST tag_list = (REPLACEABLE_TAG_LIST) malloc( sizeof(REPLACEABLE_TAG) * 2); // 获取用户提交的用户名和密码,如果没有提交数据,则 username 和 password 为空字符串 cgiFormStringSpaceNeeded("username", &field_buffer_size); username = (char*) malloc(field_buffer_size); memset(username, 0, field_buffer_size); cgiFormString("username", username, field_buffer_size); cgiFormStringSpaceNeeded("password", &field_buffer_size); password = (char*) malloc(field_buffer_size); cgiFormString("password", password, field_buffer_size); if (strcmp(username, g_login_username) == 0 && strcmp(password, g_login_password) == 0) { // 登录验证通过,设置 session 数据后重定向浏览器 session_set("USERNAME", g_login_username); session_write_close(); cgiHeaderLocation(cgiScriptName); free(username); free(password); return 0; } // 输出 ContentType header // 作为 CGI 程序必须输出这个 header,否则会导致 500 错误 fprintf(cgiOut, "Pragma: no-cache\n"); cgiHeaderContentType("text/html"); // 显示登录页面 tag_list[0].tag = "{%ERROR_MESSAGE%}"; if (strlen(username) != 0 || strlen(password) != 0) { tag_list[0].value = "您输入的用户名或者密码错误。"; } else { tag_list[0].value = ""; } tag_list[1].tag = "{%USERNAME%}"; tag_list[1].value = username; buffer = read_template(g_login_template); if (buffer == NULL) { fprintf(cgiOut, "Warning: Can't read template file: %s.<br />\n", g_login_template); free(username); free(password); return -1; } parse_template(&buffer, tag_list, 2); fprintf(cgiOut, "%s", buffer); free(buffer); free(username); free(password); // session_destroy(); return 0; }