#include "offline_opt.h" #include #include #include #include #include #include #include #include "../scanner_manager.h" // for version #include "user.h" static std::string device_opt_json[] = { "{\"company\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u5236\\u9020\\u5546\",\"desc\":\"\\u8bbe\\u5907\\u5236\\u9020\\u5546\",\"type\":\"string\",\"fix-id\":34891,\"readonly\":true,\"size\":128,\"auto\":false,\"cur\":\"0\",\"default\":\"0\"},\"copyright\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u7248\\u672c\\u4fe1\\u606f\",\"desc\":\"\\u7248\\u6743\\u58f0\\u660e\\u7b49\\u4fe1\\u606f\",\"type\":\"string\",\"fix-id\":34892,\"readonly\":true,\"size\":128,\"auto\":false,\"cur\":\"0\",\"default\":\"0\"},\"co-url\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u516c\\u53f8\\u7f51\\u5740\",\"desc\":\"\\u516c\\u53f8\\u5b98\\u7f51\\u6216\\u552e\\u540e\\u670d\\u52a1\\u7f51\\u7ad9\\u5730\\u5740\",\"type\":\"string\",\"fix-id\":34893,\"readonly\":true,\"size\":256,\"auto\":false,\"cur\":\"0\",\"default\":\"0\"},\"co-tel\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u516c\\u53f8\\u7535\\u8bdd\",\"desc\":\"\\u516c\\u53f8\\u8054\\u7cfb\\u7535\\u8bdd\",\"type\":\"string\",\"fix-id\":34894,\"readonly\":true,\"size\":129,\"auto\":false,\"cur\":\"0\",\"default\":\"0\"},\"co-addr\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u516c\\u53f8\\u5730\\u5740\",\"desc\":\"\\u516c\\u53f8\\u5730\\u5740\",\"type\":\"string\",\"fix-id\":34895,\"readonly\":true,\"size\":128,\"auto\":false,\"cur\":\"0\",\"default\":\"0\"},\"co-gps\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u516c\\u53f8GPS\",\"desc\":\"\\u516c\\u53f8\\u5730\\u56fe\\u5730\\u5740\",\"type\":\"string\",\"fix-id\":34896,\"readonly\":true,\"size\":256,\"auto\":false,\"cur\":\"0\",\"default\":\"0\"},\"drv-ver\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u9a71\\u52a8\\u7248\\u672c\\u53f7\",\"desc\":\"PC\\u7aef\\u9a71\\u52a8\\u7a0b\\u5e8f\\u7248\\u672c\",\"type\":\"string\",\"fix-id\":34890,\"readonly\":true,\"size\":48,\"auto\":false,\"cur\":\"0\",\"default\":\"0\"},\"login\":{\"cat\":\"advanced\",\"group\":\"\\u7528\\u6237\",\"title\":\"\\u767b\\u5f55\",\"desc\":\"\\u7528\\u6237\\u767b\\u5f55\\u64cd\\u4f5c\",\"type\":\"string\",\"fix-id\":39168,\"visible\":1,\"size\":64,\"auto\":false,\"cur\":\"false\",\"default\":\"false\"},\"logout\":{\"cat\":\"advanced\",\"group\":\"\\u7528\\u6237\",\"title\":\"\\u767b\\u51fa\",\"desc\":\"\\u7528\\u6237\\u767b\\u51fa\\u64cd\\u4f5c\",\"type\":\"string\",\"fix-id\":39169,\"visible\":1,\"size\":64,\"auto\":false,\"cur\":\"false\",\"default\":\"false\"},\"drv-log\":{\"cat\":\"advanced\",\"group\":\"\\u7528\\u6237\",\"title\":\"\\u9a71\\u52a8\\u65e5\\u5fd7\",\"desc\":\"PC\\u7aef\\u9a71\\u52a8\\u5de5\\u4f5c\\u65e5\\u5fd7\",\"type\":\"string\",\"fix-id\":39171,\"visible\":1,\"size\":256,\"auto\":false,\"ownread\":true,\"cur\":\"0\",\"default\":\"0\"}}" }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // offline_opts ... offline_opts::offline_opts(hguser* user) : user_(user) { int hh = 0, hl = 0, lh = 0, ll = 0; hg_scanner_mgr::get_version(&hh, &hl, &lh, &ll); drv_ver_ = std::to_string(hh) + "." + std::to_string(hl) + "." + std::to_string(lh) + "." + std::to_string(ll); init(); set_where("offline_opts"); } offline_opts::~offline_opts() { } void offline_opts::init(void) { gb_json* child = nullptr, * jsn = new gb_json(); std::string text(""); for (auto& v : device_opt_json) text += v; jsn->attach_text(&text[0]); #define INIT_SIMPLE_VAL(n, v) \ jsn->get_value(SANE_STD_OPT_NAME_##n, child); \ if (child) \ { \ child->set_value("cur", v); \ child->set_value("default", v); \ \ child->release(); \ } INIT_SIMPLE_VAL(MANUFACTURER , COMPANY_NAME); INIT_SIMPLE_VAL(CO_URL , BRAND_COMPANY_URL); INIT_SIMPLE_VAL(CO_TEL , BRAND_COMPANY_TEL); INIT_SIMPLE_VAL(CO_ADDR , BRAND_COMPANY_ADDRESS); INIT_SIMPLE_VAL(CO_GPS , BRAND_URL_GPS); INIT_SIMPLE_VAL(COPYRIGHT , BRAND_COPYRIGHT); INIT_SIMPLE_VAL(DRIVER_VERSION , drv_ver_.c_str()); text = std::move(jsn->to_string()); set_opt_json_text(&text[0]); jsn->release(); } std::string offline_opts::get_value(const char* name, void* value, int* err) { std::string ret(""); if (IS_SANE_OPT(name, DRIVER_LOG)) { if (user_ && user_->has_privilege(USER_PRIVILEGE_LOCAL_MGR)) { int e = utils::copy_log_file_to((char*)value); ret = (char*)value; if (err) *err = e; } else if (err) *err = SCANNER_ERR_ACCESS_DENIED; } else if (err) *err = SCANNER_ERR_NO_DATA; return ret; } int offline_opts::set_value(const char* name, void* value) { int ret = SCANNER_ERR_NO_DATA; if (IS_SANE_OPT(name, DRIVER_LOG)) { if (user_ && user_->has_privilege(USER_PRIVILEGE_LOCAL_MGR)) { ret = utils::clear_log_file(); } else { ret = SCANNER_ERR_ACCESS_DENIED; } } else if (IS_SANE_OPT(name, LOGIN) || IS_SANE_OPT(name, LOGOUT)) { char* n = (char*)value, * pwd = n + 32; scanner_err ret = IS_SANE_OPT(name, LOGIN) ? (scanner_err)user_->login(n, pwd) : (scanner_err)user_->logout(n, pwd); if (ret == SCANNER_ERR_OK) ret = SCANNER_ERR_RELOAD_OPT_PARAM; } else if (IS_SANE_OPT(name, MANUFACTURER) || IS_SANE_OPT(name, CO_URL) || IS_SANE_OPT(name, CO_TEL) || IS_SANE_OPT(name, CO_ADDR) || IS_SANE_OPT(name, CO_GPS) || IS_SANE_OPT(name, COPYRIGHT) || IS_SANE_OPT(name, DRIVER_VERSION) ) ret = SCANNER_ERR_ACCESS_DENIED; return ret; } void offline_opts::enable(const char* name, bool able) { }