/****************************************************************************** * Ir_getKey ******************************************************************************/ Int Ir_getKey(Ir_Handle hIr, Ir_Key *key) { #ifdef CONFIG_CIR UInt16 buf; Int val; *key = 0; if (read(hIr->fd, &buf, sizeof(UInt16)) < 0) { if (errno != EAGAIN) { Dmai_err0("Unable to read from the CIR device\n"); return Dmai_EFAIL; } } else { if (buf != hIr->prev) { val = 0x3000 | ( buf & 0x07FF ); if (validateKey(val)) { *key = val; } hIr->prev = buf; } ioctl(hIr->fd, CIR_FLUSH); } return Dmai_EOK; #else Dmai_err0("not implemented\n"); return NULL; #endif }
void KVCRedisPtotocol::sendSetCommand(KVCConnection* conn, std::string key, std::string value, unsigned int expire){ std::string res; if (!(res = validateKey(key)).empty()) throw KVCIllegalArgumentException(res); std::string command = "SET " + quote(key) + " " + quote(value) + " EX " + KVCUtility::toString(expire) + "\r\n"; std::string tcpResult; conn->send(command); tcpResult = reciveFromConn(conn); if (str_left_cmp(tcpResult.c_str(), "+OK\r\n", tcpResult.length(), sizeof("+OK\r\n") - 1)) { return; } throw KVCRuntimeException(getRedisResult(tcpResult)); }
void KVCRedisPtotocol::sendDelCommand(KVCConnection* conn, std::string key){ std::string res; if (!(res = validateKey(key)).empty()) throw KVCIllegalArgumentException(res); std::string command = "DEL " + quote(key) + "\r\n"; std::string tcpResult; conn->send(command); tcpResult = reciveFromConn(conn); if (str_left_cmp(tcpResult.c_str(), "+OK\r\n", tcpResult.length(), sizeof("+OK\r\n") - 1) || str_left_cmp(tcpResult.c_str(), ":", tcpResult.length(), sizeof(":") - 1)) { return; } throw KVCRuntimeException(getRedisResult(tcpResult)); }
int TraditionalKeyGenerator::validate (std::string const& key, bool isRestore) { int res = globalCheck(key, isRestore); if (res != TRI_ERROR_NO_ERROR) { return res; } // validate user-supplied key if (! validateKey(key.c_str())) { return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD; } return TRI_ERROR_NO_ERROR; }
void KVCMCAsciiProtocol::sendDelCommand(KVCConnection* conn, std::string key) { std::string result; if (!(result = validateKey(key)).empty()) throw KVCIllegalArgumentException(result); std::string command = "delete " + key + "\r\n"; std::string tcpResult; conn->send(command); tcpResult = reciveFromConn(conn); if (str_left_cmp(tcpResult.c_str(), "OK", tcpResult.length(), sizeof("OK") - 1) || str_left_cmp(tcpResult.c_str(), "DELETED", tcpResult.length(), sizeof("DELETED") - 1)) return; else if (!(result = getMCReoult(tcpResult)).empty()) throw KVCRuntimeException(result); }
void KVCMCAsciiProtocol::sendSetCommand(KVCConnection* conn, std::string key, std::string value, unsigned int expire){ std::string result; if (!(result = validateKey(key)).empty()) throw KVCIllegalArgumentException(result); std::string command = "set " + key + " 0 " + KVCUtility::toString(expire) + " " + KVCUtility::toString(value.size()) + "\r\n" + value + "\r\n"; std::string tcpResult; conn->send(command); tcpResult = reciveFromConn(conn); if (str_left_cmp(tcpResult.c_str(), "OK", tcpResult.length(), sizeof("OK") - 1) || str_left_cmp(tcpResult.c_str(), "STORED", tcpResult.length(), sizeof("STORED") - 1)) { return; } else if (!(result = getMCReoult(tcpResult)).empty()){ throw KVCRuntimeException(result); } }
std::string KVCMCAsciiProtocol::sendGetCommand(KVCConnection* conn, std::string key){ std::string result; if (!(result = validateKey(key)).empty()) throw KVCIllegalArgumentException(result); std::string command = "get " + key + "\r\n"; std::string tcpResult; conn->send(command); tcpResult = reciveFromConn(conn); if (str_left_cmp(tcpResult.c_str(), "VALUE ", tcpResult.length(), sizeof("VALUE ") - 1)) { size_t line_end = tcpResult.find("\r\n"); while (true) { if (line_end <= 6) break; std::string mataString = tcpResult.substr(6, line_end - 6); std::vector<std::string> metaVector = split(mataString, " "); if (metaVector.size() < 3) break; size_t valueLen; try{ valueLen = atoll((metaVector[2]).c_str()); } catch (...) { throw KVCRuntimeException("Unknow response format, value length error. raw:'" + tcpResult + "'"); } std::string key = metaVector[0]; std::string value = tcpResult.substr(line_end + 2, valueLen); if (key.empty()) break; return value; } } else if (!(result = getMCReoult(tcpResult)).empty()){ throw KVCRuntimeException(result); } return ""; }
std::string KVCRedisPtotocol::sendGetCommand(KVCConnection* conn, std::string key){ std::string res; if (!(res = validateKey(key)).empty()) throw KVCIllegalArgumentException(res); std::string command = "GET " + quote(key) + "\r\n"; std::string tcpResult, value; conn->send(command); tcpResult = reciveFromConn(conn); size_t lineEnd = tcpResult.find("\r\n"); if (lineEnd == std::string::npos) throw KVCRuntimeException("Unknow response format"); if (str_left_cmp(tcpResult.c_str(), ":", tcpResult.length(), sizeof(":") - 1)) { value = tcpResult.substr(1, lineEnd - 1); return value; } else if (str_left_cmp(tcpResult.c_str(), "$", tcpResult.length(), sizeof("$") - 1)){ if (str_left_cmp(tcpResult.c_str(), "$-1", tcpResult.length(), sizeof("$-1") - 1)){ return ""; } else{ size_t valueLen; try{ valueLen = atoll((tcpResult.substr(1, lineEnd - 1)).c_str()); value = tcpResult.substr(lineEnd + 2, valueLen); if (value.length() != valueLen) throw KVCRuntimeException("Unknow response format, value missing"); } catch (std::invalid_argument& e) { throw KVCRuntimeException(("Unknow response format") + std::string().append(e.what())); } } return value; } throw KVCRuntimeException(getRedisResult(tcpResult)); }
int AutoIncrementKeyGenerator::validate (std::string const& key, bool isRestore) { int res = globalCheck(key, isRestore); if (res != TRI_ERROR_NO_ERROR) { return res; } // validate user-supplied key if (! validateKey(key.c_str())) { return TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD; } uint64_t intValue = triagens::basics::StringUtils::uint64(key); if (intValue > _lastValue) { MUTEX_LOCKER(_lock); // update our last value _lastValue = intValue; } return TRI_ERROR_NO_ERROR; }