예제 #1
0
  int RequestProcessor::process(request_prefix_hides_by_proxy *req,
      request_prefix_hides_by_proxy *&post_req) {
    int ret = TAIR_RETURN_SUCCESS;
    vector<tair_client_api*> *clients = invalid_loader->get_client_list(req->group_name);
    if (clients != NULL) {
      data_entry pkey;
      tair_dataentry_set mkey_set;
      tair_dataentry_set failed_key_set;
      if (req->key != NULL) {
        mkey_set.insert(req->key);
        split_key(req->key, &pkey, NULL);
      } else if (req->key_list != NULL) {
        tair_dataentry_set::iterator itr = req->key_list->begin();
        split_key(*itr, &pkey, NULL);
        while (itr != req->key_list->end()) {
          mkey_set.insert(*itr);
          ++itr;
        }
      }

      for (size_t i = 0; i < clients->size(); ++i) {
        tair_client_api *client = clients->at(i);
        key_code_map_t key_code_map;
        if ((ret = client->hides(req->area, mkey_set, key_code_map)) != TAIR_RETURN_SUCCESS) {
          key_code_map_t::iterator itr = key_code_map.begin();
          while (itr != key_code_map.end()) {
            if (itr->second != TAIR_RETURN_DATA_NOT_EXIST && itr->second != TAIR_RETURN_DATA_EXPIRED) {
              data_entry *mkey = new data_entry();
              merge_key(pkey, *itr->first, *mkey);
              std::vector<std::string> servers;
              client->get_server_with_key(*mkey, servers);
              log_error("[FATAL ERROR] PrefixHidesFailure: Group %s, DataServer %s.",
                  req->group_name, servers[0].c_str());

              if (failed_key_set.insert(mkey).second == false) {
                delete mkey;
              }
            }
            ++itr;
          }
          defree(key_code_map);
        }
      }
      if (!failed_key_set.empty()) {
        post_req = new request_prefix_hides_by_proxy();
        post_req->set_group_name(req->group_name);
        post_req->area = req->area;
        tair_dataentry_set::iterator itr = failed_key_set.begin();
        while (itr != failed_key_set.end()) {
          post_req->add_key(*itr++);
        }
      }
      ret = TAIR_RETURN_SUCCESS;
      mkey_set.clear();
    } else {
      log_error("[FATAL ERROR] cannot find clients, group %s not added, or still loading", req->group_name);
      ret = TAIR_RETURN_INVAL_CONN_ERROR;
    }
    return ret;
  }
예제 #2
0
static void interpret_text_settings(const ds::cfg::Settings &s, std::unordered_map<std::string, ds::cfg::Text>& out) {
	// Do the name first, because that determines whether an entry exists.
	s.forEachTextKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && right == "name") {
			std::string		v = s.getText(key, 0, ds::EMPTY_SZ);
			if (!v.empty()) {
				if (out.empty()) {
					out[left] = ds::cfg::Text(v, left, 10.0f, 1.0f, ci::ColorA(1.0f, 1.0f, 1.0f, 1.0f));
				} else {
					auto	found = out.find(left);
					if (found != out.end()) {
						found->second.mFont = v;
					} else {
						out[left] = ds::cfg::Text(v, left, 10.0f, 1.0f, ci::ColorA(1.0f, 1.0f, 1.0f, 1.0f));
					}
				}
			}
		}
	});

	// Floats (size, leading)
	s.forEachFloatKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "size") found->second.mSize = s.getFloat(key, 0, found->second.mSize);
				else if (right == "leading") found->second.mLeading = s.getFloat(key, 0, found->second.mLeading);
			}
		}
	});

	// Color (color)
	s.forEachColorAKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "color") found->second.mColor = s.getColorA(key, 0, found->second.mColor);
			}
		}
	});

	// Text (alignment)
	s.forEachTextKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "alignment") {
					found->second.mAlignment = ds::ui::Alignment::fromString(s.getText(key, 0, ""));
				}
			}
		}
	});

}
예제 #3
0
static void read_nine_patch_cfg(const std::string& path, std::unordered_map<std::string, ds::cfg::NinePatch>& out) {
	ds::cfg::Settings		s;
	s.readFrom(path, false);

	// Do the type first, because that determines whether an entry exists.
	s.forEachTextKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && right == "type") {
			ds::cfg::NinePatch::Type type = type_from(s.getText(key, 0, ds::EMPTY_SZ));
			if (type != ds::cfg::NinePatch::EMPTY) {
				if (out.empty()) {
					out[left] = ds::cfg::NinePatch(type);
				} else {
					auto	found = out.find(left);
					if (found != out.end()) {
						found->second.mType = type;
					} else {
						out[left] = ds::cfg::NinePatch(type);
					}
				}
			}
		}
	});

	// Floats
	s.forEachFloatKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				found->second.mStore.setFloat(right, s.getFloat(key, 0, 0.0f));
			}
		}
	});

	// Color (color)
	s.forEachColorAKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				found->second.mStore.setColorA(right, s.getColorA(key, 0, ci::ColorA()));
			}
		}
	});

	// Strings (everything but type)
	s.forEachTextKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty() && right != "type") {
			auto			found = out.find(left);
			if (found != out.end()) {
				found->second.mStore.setString(right, s.getText(key, 0, ""));
			}
		}
	});
}
예제 #4
0
static int prune_p(void *rock,
		   const char *key, size_t keylen,
		   const char *data, size_t datalen __attribute__((unused)))
{
    struct prunerock *prock = (struct prunerock *) rock;
    time_t mark, *expmark = NULL;
    duplicate_key_t dkey = DUPLICATE_INITIALIZER;
    int r;

    prock->count++;

    r = split_key(key, keylen, &dkey);
    if (r) return 1;	/* broken record, want to prune it */

    /* grab the rcpt, make sure its a mailbox and lookup its expire time */
    if (prock->expire_table && dkey.to[0] && dkey.to[0] != '.') {
	expmark = (time_t *) hash_lookup(dkey.to, prock->expire_table);
    }

    /* grab the mark */
    memcpy(&mark, data, sizeof(time_t));

    /* check if we should prune this entry */
    return (mark < (expmark ? *expmark : prock->expmark));
}
예제 #5
0
 bool set(const std::string &key, int value) const {
     HKEY hKey;
     DWORD disp;
     std::string path;
     std::string name;
     split_key(key, path, name);
     LONG ret = RegCreateKeyEx(HKEY_CURRENT_USER, path.c_str(), 0, "AESKULAP", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
     if( ret != ERROR_SUCCESS )
     {
         RegCloseKey(hKey);
         return false;
     }
     ret = RegSetValueEx(hKey, name.c_str(), 0, REG_DWORD, (BYTE*)&value, sizeof(value));
     RegCloseKey(hKey);
     return ret==ERROR_SUCCESS;
 }
예제 #6
0
 std::string get_string(const std::string &dir) const {
     HKEY hKey;
     DWORD ret;
     DWORD type;
     DWORD len;
     char val[512];
     std::string retval;
     std::string key, name;
     split_key(dir, key, name);
     ret = RegOpenKeyEx(HKEY_CURRENT_USER, key.c_str(), 0, KEY_READ, &hKey);
     if( ret!=ERROR_SUCCESS )
         return "";
     len = sizeof(val);
     ret = RegQueryValueEx(hKey, name.c_str(), NULL, &type, (BYTE*)val, &len);
     if( ret!=ERROR_SUCCESS || type != REG_SZ)
         retval = "";
     else
         retval = val;
     RegCloseKey(hKey);
     return retval;
 }
예제 #7
0
 int get_int(const std::string &dir) const {
     HKEY hKey;
     DWORD ret;
     DWORD type;
     DWORD len;
     DWORD val;
     int retval;
     std::string key, name;
     split_key(dir, key, name);
     ret = RegOpenKeyEx(HKEY_CURRENT_USER, key.c_str(), 0, KEY_READ, &hKey);
     if( ret!=ERROR_SUCCESS )
         return -1;
     len = sizeof(val);
     type=REG_DWORD;
     ret = RegQueryValueEx(hKey, name.c_str(), NULL, &type, (BYTE*)&val, &len);
     if( ret!=ERROR_SUCCESS || type != REG_DWORD )
         retval = -1;
     else
         retval = val;
     RegCloseKey(hKey);
     return retval;
 }
예제 #8
0
static int find_cb(void *rock, const char *key, size_t keylen,
		   const char *data, size_t datalen)
{
    struct findrock *frock = (struct findrock *) rock;
    duplicate_key_t dkey = DUPLICATE_INITIALIZER;
    time_t mark;
    unsigned long uid = 0;
    int r;

    r = split_key(key, keylen, &dkey);
    if (r) return 0;	/* ignore broken records */

    /* make sure its a mailbox */
    if (dkey.to[0] == '.') return 0;

    /* grab the mark and uid */
    memcpy(&mark, data, sizeof(time_t));
    if (datalen > (int) sizeof(mark))
	memcpy(&uid, data + sizeof(mark), sizeof(unsigned long));

    r = (*frock->proc)(&dkey, mark, uid, frock->rock);

    return r;
}