bool Database::db_deleteVal(Node *root) { Node* ptrConj = root->rightSon; Node* ptrExpr = nullptr; Node* columnDef = nullptr; vector<Node*> columnWithIndex; vector<Node*> columnWithoutIndex; try { m_catMgr.assertNonExistTable(root->strval); while (ptrConj != nullptr) { // now support 'and' only. // ptrExpr->operation <= OP_OR equals to // ptrExpr->operation == OP_AND || OP_OR if (ptrConj->operation == OP_AND) { // column name put in the left side ptrExpr = ptrConj->leftSon; } else { ptrExpr = ptrConj; // end here ptrConj = ptrConj->rightSon; } m_catMgr.assertNonExistColumn(root->strval, ptrExpr->leftSon->strval); columnDef = m_catMgr.get_column_def(root->strval, ptrExpr->leftSon->strval); if (m_catMgr.ifexist_index_on_column(root->strval, ptrExpr->leftSon->strval)) { columnWithIndex.push_back(ptrExpr); } else { columnWithoutIndex.push_back(ptrExpr); } // check type if (CHECK_TYPE(columnDef->operation, ptrExpr->rightSon->strval)) throw TypeMismatchException(string("at column ")+string(ptrExpr->leftSon->strval)); ptrConj = ptrConj->rightSon; } } catch (TableNonExistException) { fprintf(stderr, "Error: no such table: %s\n", root->strval); return false; } catch (ColumnNonExistException) { fprintf(stderr, "Error: table %s has no column named %s\n",\ root->strval, ptrExpr->leftSon->strval); return false; } catch (TypeMismatchException e) { fprintf(stderr, "Error: type mismatch: %s\n", e.columnName.c_str()); return false; } int returnVal; Node *ptrColumn = m_catMgr.get_column_def(root->strval); if (root->rightSon == nullptr) { returnVal = m_recMgr.delete_all_record(root->strval); while(ptrColumn != nullptr) { if (m_catMgr.ifexist_index_on_column(root->strval, ptrColumn->strval)) { m_idxMgr.delete_all_idx(root->strval, ptrColumn->strval); } ptrColumn = ptrColumn->leftSon; } } else { vector<CursePair> cursor; size_t tmpSize = columnWithIndex.size(); for (auto it : columnWithIndex) { if (it == columnWithIndex[0]) m_idxMgr.select_record_raw(root->strval, it->leftSon->strval, it, cursor); else m_idxMgr.select_record(root->strval, it->leftSon->strval, it, cursor); } for (auto it : columnWithoutIndex) { if (tmpSize == 0 && it == columnWithoutIndex[0]) m_recMgr.select_record_raw(root->strval, columnDef, it, cursor); else m_recMgr.select_record(root->strval, columnDef, it, cursor); } returnVal = m_recMgr.delete_record(root->strval, cursor); while(ptrColumn != nullptr) { if (m_catMgr.ifexist_index_on_column(root->strval, ptrColumn->strval)) { m_idxMgr.delete_entry_idx(root->strval, ptrColumn->strval, cursor); } ptrColumn = ptrColumn->leftSon; } } // delete index // for (auto it : something from cat?) // { //// TO-DO // m_idxMgr.delete_all_on_column(table, column, cursor); // } printf("Query OK, %d rows affected\n", returnVal); return true; }
static void CHECK_FLOAT (Lisp_Object x) { CHECK_TYPE (FLOATP (x), Qfloatp, x); }
bool Database::db_insertVal(Node *root) { Node *columnDef = nullptr; Node *ptrDef = nullptr; Node *ptrData = root->leftSon; try { m_catMgr.assertNonExistTable(root->strval); ptrDef = columnDef = m_catMgr.get_column_def(root->strval); while (ptrData != nullptr) { if (ptrDef == nullptr) { throw TypeMismatchException("too many values"); } if (CHECK_TYPE(ptrDef->operation, ptrData->strval)) { throw TypeMismatchException(string("at column ")+string(ptrDef->strval)); } if (m_catMgr.if_unique_key(root->strval, ptrDef->strval)) { // v:tableName v:columnName if (m_catMgr.ifexist_index_on_column(root->strval, ptrDef->strval)) { m_idxMgr.assertMultipleKey(root->strval, ptrDef->strval, ptrData); } else { // rec need column name& column offset :v m_recMgr.assertMultipleKey(root->strval, ptrDef->strval, columnDef, ptrData); } } ptrData = ptrData->leftSon; ptrDef = ptrDef->leftSon; } if (ptrDef != nullptr) { throw TypeMismatchException("too many values"); } } catch (TableNonExistException) { fprintf(stderr, "Error: no such table: %s\n", root->strval); return false; } catch (MultipleKeyException e) { fprintf(stderr, "Error: UNIQUE constraint failed: %s\n", e.name.c_str()); return false; } catch (TypeMismatchException e) { fprintf(stderr, "Error: type mismatch: %s\n", e.columnName.c_str()); return false; } vector<CursePair> cursor; cursor.push_back(m_recMgr.new_entry_record(root)); ptrDef = columnDef; ptrData = root->leftSon; while(ptrDef != nullptr) { if (m_catMgr.ifexist_index_on_column(root->strval, ptrDef->strval)) { ptrData->operation = ptrDef->operation; m_idxMgr.new_entry_idx(root->strval, ptrDef->strval, ptrData, cursor); } ptrDef = ptrDef->leftSon; ptrData = ptrData->leftSon; } // currently print 1 printf("Query OK, 1 rows affected\n"); return true; }
bool Database::db_selectVal(Node *root) { // |¯¯¯¯¯¯¯¯| // | root | // |________| // v(R) // |¯¯¯¯¯¯¯¯| // |AND(...)| // |________| // v v // |¯¯¯¯¯¯¯¯| |¯¯¯¯¯¯¯¯| // | cmp(op)| | cmp(op)| // |________| |________| // v v // column val Node* ptrConj = root->rightSon; Node* ptrExpr = nullptr; Node* columnDef = nullptr; vector<Node*> columnWithIndex; vector<Node*> columnWithoutIndex; try { m_catMgr.assertNonExistTable(root->strval); while (ptrConj != nullptr) { // now support 'and' only. // ptrExpr->operation <= OP_OR equals to // ptrExpr->operation == OP_AND || OP_OR if (ptrConj->operation == OP_AND) { // column name put in the left side ptrExpr = ptrConj->leftSon; } else { ptrExpr = ptrConj; // end here ptrConj = ptrConj->rightSon; } m_catMgr.assertNonExistColumn(root->strval, ptrExpr->leftSon->strval); columnDef = m_catMgr.get_column_def(root->strval, ptrExpr->leftSon->strval); ptrExpr->leftSon->operation = columnDef->operation; if (m_catMgr.ifexist_index_on_column(root->strval, ptrExpr->leftSon->strval)) { columnWithIndex.push_back(ptrExpr); } else { columnWithoutIndex.push_back(ptrExpr); } // check type if (CHECK_TYPE(columnDef->operation, ptrExpr->rightSon->strval)) throw TypeMismatchException(string("at column ")+string(ptrExpr->leftSon->strval)); ptrConj = ptrConj->rightSon; } } catch (TableNonExistException) { fprintf(stderr, "Error: no such table: %s\n", root->strval); return false; } catch (ColumnNonExistException) { fprintf(stderr, "Error: table %s has no column named %s\n",\ root->strval, ptrExpr->leftSon->strval); return false; } catch (TypeMismatchException e) { fprintf(stderr, "Error: type mismatch: %s\n", e.columnName.c_str()); return false; } columnDef = m_catMgr.get_column_def(root->strval); if (root->rightSon == nullptr) // currently support select * m_recMgr.print_all_record(root->strval, columnDef); else { vector<CursePair> cursor; size_t tmpSize = columnWithIndex.size(); for (auto it : columnWithIndex) { if (it == columnWithIndex[0]) m_idxMgr.select_record_raw(root->strval, it->leftSon->strval, it, cursor); else m_idxMgr.select_record(root->strval, it->leftSon->strval, it, cursor); } for (auto it : columnWithoutIndex) { if (tmpSize == 0 && it == columnWithoutIndex[0]) m_recMgr.select_record_raw(root->strval, columnDef, it, cursor); else m_recMgr.select_record(root->strval, columnDef, it, cursor); } m_recMgr.print_select_record(root->strval, columnDef, cursor); } // always print 0 printf("Query OK, 0 rows affected\n"); return true; }
static void json_check_utf8 (Lisp_Object string) { CHECK_TYPE (utf8_string_p (string), Qutf_8_string_p, string); }
static void CHECK_MARKER (Lisp_Object x) { CHECK_TYPE (MARKERP (x), Qmarkerp, x); }
static struct EvalError *check_stdproc( enum StandardProcedure stdproc, struct Expression *args, size_t n) { switch (stdproc) { case S_APPLY:; Arity arity; if (!expression_arity(&arity, args[0])) { return new_eval_error_expr(ERR_TYPE_OPERATOR, args[0]); } size_t length; if (!count_list(&length, args[n-1])) { return new_syntax_error(args[n-1]); } size_t n_args = length + n - 2; if (!arity_allows(arity, n_args)) { return new_arity_error(arity, n_args); } break; case S_MACRO: if (args[0].type != E_STDPROCEDURE && args[0].type != E_PROCEDURE) { return new_type_error(E_PROCEDURE, args, 0); } break; case S_NUM_EQ: case S_NUM_LT: case S_NUM_GT: case S_NUM_LE: case S_NUM_GE: case S_ADD: case S_SUB: case S_MUL: case S_EXPT: case S_INTEGER_TO_CHAR: case S_NUMBER_TO_STRING: for (size_t i = 0; i < n; i++) { CHECK_TYPE(E_NUMBER, i); } break; case S_DIV: case S_REMAINDER: case S_MODULO: for (size_t i = 0; i < n; i++) { CHECK_TYPE(E_NUMBER, i); if (i > 0 && args[i].number == 0) { // This is not technically a type error, but this is the // earliest and most convenient place to catch it. return new_eval_error(ERR_DIV_ZERO); } } break; case S_CAR: case S_CDR: case S_SET_CAR: case S_SET_CDR: CHECK_TYPE(E_PAIR, 0); break; case S_STRING_LENGTH: case S_STRING_EQ: case S_STRING_LT: case S_STRING_GT: case S_STRING_LE: case S_STRING_GE: case S_STRING_COPY: case S_STRING_APPEND: case S_STRING_TO_SYMBOL: case S_STRING_TO_NUMBER: case S_LOAD: for (size_t i = 0; i < n; i++) { CHECK_TYPE(E_STRING, i); } break; case S_MAKE_STRING: CHECK_TYPE(E_NUMBER, 0); CHECK_TYPE(E_CHARACTER, 1); if (args[0].number < 0) { return new_eval_error_expr(ERR_NEGATIVE_SIZE, args[0]); } break; case S_STRING_REF: CHECK_TYPE(E_STRING, 0); CHECK_TYPE(E_NUMBER, 1); CHECK_RANGE(0, 1); break; case S_STRING_SET: CHECK_TYPE(E_STRING, 0); CHECK_TYPE(E_NUMBER, 1); CHECK_TYPE(E_CHARACTER, 2); CHECK_RANGE(0, 1); break; case S_SUBSTRING: CHECK_TYPE(E_STRING, 0); CHECK_TYPE(E_NUMBER, 1); CHECK_TYPE(E_NUMBER, 2); CHECK_RANGE(0, 1); CHECK_RANGE(0, 2); break; case S_STRING_FILL: CHECK_TYPE(E_STRING, 0); CHECK_TYPE(E_CHARACTER, 1); break; case S_CHAR_EQ: case S_CHAR_LT: case S_CHAR_GT: case S_CHAR_LE: case S_CHAR_GE: case S_CHAR_TO_INTEGER: for (size_t i = 0; i < n; i++) { CHECK_TYPE(E_CHARACTER, i); } break; case S_SYMBOL_TO_STRING: CHECK_TYPE(E_SYMBOL, 0); break; default: break; } return NULL; }
bool GetValue(HKEY RootKey, const wchar_t* SubKey, const wchar_t* Name, T& Value, REGSAM Sam = 0) { CHECK_TYPE(T); key Key(RootKey, SubKey, KEY_QUERY_VALUE | Sam); return Key && GetValue(Key.Key(), Name, Value); }
static int parse_item(lua_State* L, const char** p_format, va_list* p_va, int value_index, BOOL in_tablep, BOOL* p_optionalp) { const char* format = *p_format; L_RETRY: format = STRSKIP(format, WHITESPACES); switch (*format) { default: lua_pushfstring(L, "format item `%c(%d)' is not valid", SANITIZE_CHAR(*format), *format); return FAILURE; case 'n': CONVERT_NUMBER(L, *p_va, value_index, lua_Number); break; case 'b': CONVERT_NUMBER(L, *p_va, value_index, char); break; case 'h': CONVERT_NUMBER(L, *p_va, value_index, short); break; case 'i': CONVERT_NUMBER(L, *p_va, value_index, int); break; case 'l': CONVERT_NUMBER(L, *p_va, value_index, long); break; case 'B': CONVERT_NUMBER(L, *p_va, value_index, unsigned char); break; case 'H': CONVERT_NUMBER(L, *p_va, value_index, unsigned short); break; case 'I': CONVERT_NUMBER(L, *p_va, value_index, unsigned int); break; case 'L': CONVERT_NUMBER(L, *p_va, value_index, unsigned long); break; case 's': CHECK_TYPE(L, value_index, LUA_TSTRING); /* FALLTHRU */ case 'z': { const char** string; size_t* length = NULL; string = va_arg(*p_va, const char**); if (*(format+1) == '#') { length = va_arg(*p_va, size_t*); format++; } if (lua_isstring(L, value_index)) { *string = lua_tolstring(L, value_index, length); } else if (!lua_toboolean(L, value_index)) { /*nil-or-false?*/ *string = NULL; if (length != NULL) *length = 0; } else { lua_pushfstring(L, "type mismatch (expected %s/nil/false, but got %s)", lua_typename(L, LUA_TSTRING), luaL_typename(L, value_index)); return FAILURE; } } break; case 'Q': { BOOL* p_boolean; p_boolean = va_arg(*p_va, BOOL*); *p_boolean = lua_toboolean(L, value_index); } break; case 'u': /* FALLTHRU */ case 'U': { void** userdata; CHECK_TYPE(L, value_index, ((*format == 'U') ? LUA_TUSERDATA : LUA_TLIGHTUSERDATA)); userdata = va_arg(*p_va, void**); *userdata = lua_touserdata(L, value_index); } break; case 'O': { int* index; if (in_tablep) { lua_pushstring(L, "format item `O' is not available in `{...}"); return FAILURE; } if (*(format+1) == '/') { int type; switch (*(format+2)) { default: lua_pushfstring(L, "type `%c(%d)' for `O/<type>' is not valid", SANITIZE_CHAR(*(format+2)), *(format+2)); return FAILURE; case 'N': type = LUA_TNIL; break; case 'n': type = LUA_TNUMBER; break; case 's': type = LUA_TSTRING; break; case 'f': type = LUA_TFUNCTION; break; case 'Q': type = LUA_TBOOLEAN; break; case 'u': type = LUA_TLIGHTUSERDATA; break; case 'U': type = LUA_TUSERDATA; break; case 't': type = LUA_TTABLE; break; case 'T': type = LUA_TTHREAD; break; } CHECK_TYPE(L, value_index, type); format += 2; } index = va_arg(*p_va, int*); *index = value_index; } break; case '{': CHECK_TYPE(L, value_index, LUA_TTABLE); format++; if (parse_table(L, &format, p_va, value_index) != SUCCESS) return FAILURE; break; case '|': if (in_tablep) { lua_pushstring(L, "optional argument `|' is not available in `{...}"); return FAILURE; } *p_optionalp = TRUE; format++; goto L_RETRY; }
static SCM extract_arg (char format_char, SCM arg, void *argp, const char *func_name, int position) { switch (format_char) { case 's': { char **arg_ptr = (char **) argp; CHECK_TYPE (gdbscm_is_true (scm_string_p (arg)), arg, position, func_name, _("string")); *arg_ptr = gdbscm_scm_to_c_string (arg).release (); break; } case 't': { int *arg_ptr = (int *) argp; /* While in Scheme, anything non-#f is "true", we're strict. */ CHECK_TYPE (gdbscm_is_bool (arg), arg, position, func_name, _("boolean")); *arg_ptr = gdbscm_is_true (arg); break; } case 'i': { int *arg_ptr = (int *) argp; CHECK_TYPE (scm_is_signed_integer (arg, INT_MIN, INT_MAX), arg, position, func_name, _("int")); *arg_ptr = scm_to_int (arg); break; } case 'u': { int *arg_ptr = (int *) argp; CHECK_TYPE (scm_is_unsigned_integer (arg, 0, UINT_MAX), arg, position, func_name, _("unsigned int")); *arg_ptr = scm_to_uint (arg); break; } case 'l': { long *arg_ptr = (long *) argp; CHECK_TYPE (scm_is_signed_integer (arg, LONG_MIN, LONG_MAX), arg, position, func_name, _("long")); *arg_ptr = scm_to_long (arg); break; } case 'n': { unsigned long *arg_ptr = (unsigned long *) argp; CHECK_TYPE (scm_is_unsigned_integer (arg, 0, ULONG_MAX), arg, position, func_name, _("unsigned long")); *arg_ptr = scm_to_ulong (arg); break; } case 'L': { LONGEST *arg_ptr = (LONGEST *) argp; CHECK_TYPE (scm_is_signed_integer (arg, INT64_MIN, INT64_MAX), arg, position, func_name, _("LONGEST")); *arg_ptr = gdbscm_scm_to_longest (arg); break; } case 'U': { ULONGEST *arg_ptr = (ULONGEST *) argp; CHECK_TYPE (scm_is_unsigned_integer (arg, 0, UINT64_MAX), arg, position, func_name, _("ULONGEST")); *arg_ptr = gdbscm_scm_to_ulongest (arg); break; } case 'O': { SCM *arg_ptr = (SCM *) argp; *arg_ptr = arg; break; } default: gdb_assert_not_reached ("invalid argument format character"); } return SCM_BOOL_F; }
TEST_F(Test_Event, GetInstance) { CHECK_TYPE(-1, MetaEvent_Text); CHECK_TYPE(-2, SystemEvent); CHECK_TYPE(-3, SystemEvent); CHECK_TYPE(-4, SystemEvent); CHECK_TYPE(-5, SystemEvent); CHECK_TYPE(-6, SystemEvent); CHECK_TYPE(-7, SystemEvent); CHECK_TYPE(-8, SystemEvent); CHECK_TYPE(-9, SystemEvent); CHECK_TYPE(-10, SystemEvent); CHECK_TYPE(-11, SystemEvent); CHECK_TYPE(-12, SystemEvent); CHECK_TYPE(-13, SystemEvent); CHECK_TYPE(-14, SystemEvent); CHECK_TYPE(-15, SystemEvent); CHECK_TYPE(-16, SystemEvent); CHECK_TYPE(-17, MidiEvent); CHECK_TYPE(0, MidiEvent); CHECK_TYPE(1, MidiEvent); CHECK_TYPE(239, MidiEvent); }
TEST_F(Test_MetaEvent, GetInstance) { CHECK_THROW(-1); CHECK_TYPE(0, MetaEvent_Text); CHECK_TYPE(1, MetaEvent_Text); CHECK_TYPE(2, MetaEvent_Text); CHECK_TYPE(3, MetaEvent_Text); CHECK_TYPE(4, MetaEvent_Text); CHECK_TYPE(5, MetaEvent_Text); CHECK_TYPE(6, MetaEvent_Text); CHECK_TYPE(7, MetaEvent_Text); CHECK_THROW(8); CHECK_THROW(15); CHECK_THROW(25); CHECK_THROW(31); CHECK_TYPE(32, MetaEvent_Skip); CHECK_TYPE(33, MetaEvent_Skip); CHECK_THROW(34); CHECK_THROW(46); CHECK_TYPE(47, MetaEvent_EndTrack); CHECK_THROW(48); CHECK_THROW(80); CHECK_TYPE(81, MetaEvent_Tempo); CHECK_THROW(82); CHECK_THROW(83); CHECK_TYPE(84, MetaEvent_Skip); CHECK_THROW(85); CHECK_THROW(87); CHECK_TYPE(88, MetaEvent_Skip); CHECK_TYPE(89, MetaEvent_KeySign); CHECK_THROW(90); CHECK_THROW(126); CHECK_TYPE(127, MetaEvent_Skip); CHECK_THROW(128); }
static int virLockManagerLockDaemonLoadConfig(const char *configFile) { virConfPtr conf; virConfValuePtr p; if (access(configFile, R_OK) == -1) { if (errno != ENOENT) { virReportSystemError(errno, _("Unable to access config file %s"), configFile); return -1; } return 0; } if (!(conf = virConfReadFile(configFile, 0))) return -1; #define CHECK_TYPE(name,typ) if (p && p->type != (typ)) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ "%s: %s: expected type " #typ, \ configFile, (name)); \ virConfFree(conf); \ return -1; \ } p = virConfGetValue(conf, "auto_disk_leases"); CHECK_TYPE("auto_disk_leases", VIR_CONF_LONG); if (p) driver->autoDiskLease = p->l; p = virConfGetValue(conf, "file_lockspace_dir"); CHECK_TYPE("file_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->fileLockSpaceDir); if (VIR_STRDUP(driver->fileLockSpaceDir, p->str) < 0) { virConfFree(conf); return -1; } } p = virConfGetValue(conf, "lvm_lockspace_dir"); CHECK_TYPE("lvm_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->lvmLockSpaceDir); if (VIR_STRDUP(driver->lvmLockSpaceDir, p->str) < 0) { virConfFree(conf); return -1; } } p = virConfGetValue(conf, "scsi_lockspace_dir"); CHECK_TYPE("scsi_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->scsiLockSpaceDir); if (VIR_STRDUP(driver->scsiLockSpaceDir, p->str) < 0) { virConfFree(conf); return -1; } } p = virConfGetValue(conf, "require_lease_for_disks"); CHECK_TYPE("require_lease_for_disks", VIR_CONF_LONG); if (p) driver->requireLeaseForDisks = p->l; else driver->requireLeaseForDisks = !driver->autoDiskLease; virConfFree(conf); return 0; }
int handlDefine(Meta_Vector & wordVector, size_t index) { int step = CHECK_SPACE; int curLine = wordVector[index].line; int defineType; for(size_t i=index+2; i < wordVector.size(); i++) { Meta_Struct meta = wordVector[i]; if (meta.line != curLine) break; if (meta.type == TYPE_SPECIAL && meta.data.chr[0] == '/') { int commentType; int ret = handleSlash(wordVector, i, commentType); if (ret > 0) { if (wordVector[i-1].line == meta.line && wordVector[i-1].type == TYPE_SPACE && wordVector[i+ret+1].line == meta.line && wordVector[i+ret+1].type == TYPE_SPACE) ret++; i += ret; // printf("skip %d after comment\n", ret); continue; } } #define CHECK_TYPE(_type) \ if (meta.type != _type) { \ printf("[%d]expect type %s after \"#define\", but actually type is %d(%s)\n", \ meta.pos, getTypeName(_type), meta.type, getTypeName(meta.type)); \ return -DEFINE_FMT_ERROR; \ } switch (step) { case CHECK_SPACE: CHECK_TYPE(TYPE_SPACE); step = CHECK_WORD; break; case CHECK_WORD: CHECK_TYPE(TYPE_WORD); printf("define name is: %s\n", meta.data.str); step = CHECK_TYPE; break; case CHECK_TYPE: if (meta.type == TYPE_SPACE) { printf("define type is constant\n"); defineType = TYPE_CONSTANT; } else if (meta.type == TYPE_SPECIAL && meta.data.chr[0] == '(') { printf("define type is function\n"); defineType = TYPE_FUNCTION; } else { printf("define type error\n"); return -1; } step = CHECK_NONE; break; } } return 0; char defineStr[1024] = {'\0'}; int defineStrLen = 0; bool addSpace = false; // #define A if (index + 3 >= wordVector.size() || wordVector[index+3].line != curLine){ restoreLine(wordVector, index, defineStr); printf("Line %d is not a full define statement:%s\n", curLine, defineStr); return 0; } if (wordVector[index+4].line != curLine) { if (wordVector[index+3].type == TYPE_WORD) printf("Line %d is a NULL constant define: %s\n", curLine, wordVector[index+3].data.str); else { restoreLine(wordVector, index, defineStr); printf("Line %d is not a valid NULL constant define statement:%s\n", curLine, defineStr); } return 0; } else{ if (wordVector[index+4].data.chr[0] == '('){ defineType = TYPE_FUNCTION; } else if (wordVector[index+4].type == TYPE_SPACE){ defineType = TYPE_CONSTANT; } else{ restoreLine(wordVector, index, defineStr); printf("Line %d is not a valid define statement:%s\n", curLine, defineStr); return 0; } } if (defineType == TYPE_CONSTANT){ bool isLineComment = false; // skip '#', "define", space, constant define and space for(size_t i=index+5; i < wordVector.size(); i++) { Meta_Struct meta = wordVector[i]; if (meta.line != curLine) break; if (isLineComment) { isLineComment = false; if (meta.data.chr[0] == '/'){ // printf("comment occurs at pos %d\n", meta.pos); defineStrLen--; defineStr[defineStrLen] = '\0'; break; } } if (meta.data.chr[0] == '\\'){ if (wordVector[i-1].type == TYPE_SPECIAL && wordVector[i-1].data.chr[0] == '\\'){ // printf("it's already escaped with this slash.\n"); } else { bool nextline = false; char escapeChar = '\0'; handleBackSlash(wordVector, i, nextline, escapeChar); } } if (meta.data.chr[0] == '/'){ isLineComment = true; } if (meta.type == TYPE_SPACE){ if (addSpace == false) { addSpace = true; } } else{ if (addSpace == true) { addSpace = false; strcat(defineStr, wordVector[i-1].data.str); defineStrLen += wordVector[i-1].len; } if (meta.type == TYPE_WORD) strcat(defineStr, meta.data.str); else strcat(defineStr, meta.data.chr); defineStrLen += meta.len; } } if (defineStrLen == 0) printf("Line %d is a NULL constant define: %s\n", curLine, wordVector[index+3].data.str); else printf("Line %d is a constant define: %s, value is %s, len is %d\n", curLine, wordVector[index+3].data.str, defineStr, defineStrLen); } else{ // restoreLine(wordVector, index, defineStr); // printf("%s\n", defineStr); bool needNextLine = false; // skip '#', "define", space, function define and () for(size_t i=index+3; i < wordVector.size(); i++) { Meta_Struct meta = wordVector[i]; if (meta.line != curLine){ if (needNextLine){ curLine = meta.line; needNextLine = false; } else break; } if (meta.type == TYPE_SPACE){ if (addSpace == false) { addSpace = true; } } else{ if (addSpace == true) { addSpace = false; strcat(defineStr, wordVector[i-1].data.str); defineStrLen += wordVector[i-1].len; } if (meta.type == TYPE_WORD) strcat(defineStr, meta.data.str); else{ if (meta.data.chr[0] == '\\'){ strcat(defineStr, "\n"); needNextLine = true; } else strcat(defineStr, meta.data.chr); } defineStrLen += meta.len; } } printf("Line %d is a function define:\n%s\n", curLine, defineStr); } return 0; }
int qemudLoadDriverConfig(struct qemud_driver *driver, const char *filename) { virConfPtr conf; virConfValuePtr p; char *user; char *group; int i; /* Setup critical defaults */ driver->securityDefaultConfined = true; driver->securityRequireConfined = false; driver->dynamicOwnership = 1; driver->clearEmulatorCapabilities = 1; if (!(driver->vncListen = strdup("127.0.0.1"))) { virReportOOMError(); return -1; } driver->remotePortMin = QEMU_REMOTE_PORT_MIN; driver->remotePortMax = QEMU_REMOTE_PORT_MAX; if (!(driver->vncTLSx509certdir = strdup(SYSCONFDIR "/pki/libvirt-vnc"))) { virReportOOMError(); return -1; } if (!(driver->spiceListen = strdup("127.0.0.1"))) { virReportOOMError(); return -1; } if (!(driver->spiceTLSx509certdir = strdup(SYSCONFDIR "/pki/libvirt-spice"))) { virReportOOMError(); return -1; } #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R /* For privileged driver, try and find hugepage mount automatically. * Non-privileged driver requires admin to create a dir for the * user, chown it, and then let user configure it manually */ if (driver->privileged && !(driver->hugetlbfs_mount = virFileFindMountPoint("hugetlbfs"))) { if (errno != ENOENT) { virReportSystemError(errno, "%s", _("unable to find hugetlbfs mountpoint")); return -1; } } #endif if (!(driver->lockManager = virLockManagerPluginNew("nop", NULL, 0))) return -1; driver->keepAliveInterval = 5; driver->keepAliveCount = 5; /* Just check the file is readable before opening it, otherwise * libvirt emits an error. */ if (access (filename, R_OK) == -1) { VIR_INFO("Could not read qemu config file %s", filename); return 0; } conf = virConfReadFile (filename, 0); if (!conf) { return -1; } #define CHECK_TYPE(name,typ) if (p && p->type != (typ)) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ "%s: %s: expected type " #typ, \ filename, (name)); \ virConfFree(conf); \ return -1; \ } p = virConfGetValue (conf, "vnc_auto_unix_socket"); CHECK_TYPE ("vnc_auto_unix_socket", VIR_CONF_LONG); if (p) driver->vncAutoUnixSocket = p->l; p = virConfGetValue (conf, "vnc_tls"); CHECK_TYPE ("vnc_tls", VIR_CONF_LONG); if (p) driver->vncTLS = p->l; p = virConfGetValue (conf, "vnc_tls_x509_verify"); CHECK_TYPE ("vnc_tls_x509_verify", VIR_CONF_LONG); if (p) driver->vncTLSx509verify = p->l; p = virConfGetValue (conf, "vnc_tls_x509_cert_dir"); CHECK_TYPE ("vnc_tls_x509_cert_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->vncTLSx509certdir); if (!(driver->vncTLSx509certdir = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "vnc_listen"); CHECK_TYPE ("vnc_listen", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->vncListen); if (!(driver->vncListen = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "vnc_password"); CHECK_TYPE ("vnc_password", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->vncPassword); if (!(driver->vncPassword = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "security_driver"); if (p && p->type == VIR_CONF_LIST) { size_t len; virConfValuePtr pp; /* Calc lenght and check items */ for (len = 0, pp = p->list; pp; len++, pp = pp->next) { if (pp->type != VIR_CONF_STRING) { VIR_ERROR(_("security_driver be a list of strings")); virConfFree(conf); return -1; } } if (VIR_ALLOC_N(driver->securityDriverNames, len + 1) < 0) { virReportOOMError(); virConfFree(conf); return -1; } for (i = 0, pp = p->list; pp; i++, pp = pp->next) { driver->securityDriverNames[i] = strdup(pp->str); if (driver->securityDriverNames == NULL) { virReportOOMError(); virConfFree(conf); return -1; } } driver->securityDriverNames[len] = NULL; } else { CHECK_TYPE ("security_driver", VIR_CONF_STRING); if (p && p->str) { if (VIR_ALLOC_N(driver->securityDriverNames, 2) < 0 || !(driver->securityDriverNames[0] = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } driver->securityDriverNames[1] = NULL; } } p = virConfGetValue (conf, "security_default_confined"); CHECK_TYPE ("security_default_confined", VIR_CONF_LONG); if (p) driver->securityDefaultConfined = p->l; p = virConfGetValue (conf, "security_require_confined"); CHECK_TYPE ("security_require_confined", VIR_CONF_LONG); if (p) driver->securityRequireConfined = p->l; p = virConfGetValue (conf, "vnc_sasl"); CHECK_TYPE ("vnc_sasl", VIR_CONF_LONG); if (p) driver->vncSASL = p->l; p = virConfGetValue (conf, "vnc_sasl_dir"); CHECK_TYPE ("vnc_sasl_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->vncSASLdir); if (!(driver->vncSASLdir = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "spice_tls"); CHECK_TYPE ("spice_tls", VIR_CONF_LONG); if (p) driver->spiceTLS = p->l; p = virConfGetValue (conf, "spice_tls_x509_cert_dir"); CHECK_TYPE ("spice_tls_x509_cert_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->spiceTLSx509certdir); if (!(driver->spiceTLSx509certdir = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "spice_listen"); CHECK_TYPE ("spice_listen", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->spiceListen); if (!(driver->spiceListen = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "spice_password"); CHECK_TYPE ("spice_password", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->spicePassword); if (!(driver->spicePassword = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "remote_display_port_min"); CHECK_TYPE ("remote_display_port_min", VIR_CONF_LONG); if (p) { if (p->l < QEMU_REMOTE_PORT_MIN) { /* if the port is too low, we can't get the display name * to tell to vnc (usually subtract 5900, e.g. localhost:1 * for port 5901) */ virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_display_port_min: port must be greater than or equal to %d"), filename, QEMU_REMOTE_PORT_MIN); virConfFree(conf); return -1; } driver->remotePortMin = p->l; } p = virConfGetValue (conf, "remote_display_port_max"); CHECK_TYPE ("remote_display_port_max", VIR_CONF_LONG); if (p) { if (p->l > QEMU_REMOTE_PORT_MAX || p->l < driver->remotePortMin) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_display_port_max: port must be between the minimal port and %d"), filename, QEMU_REMOTE_PORT_MAX); virConfFree(conf); return -1; } /* increasing the value by 1 makes all the loops going through the bitmap (i = remotePortMin; i < remotePortMax; i++), work as expected. */ driver->remotePortMax = p->l + 1; } if (driver->remotePortMin > driver->remotePortMax) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_display_port_min: min port must not be greater than max port"), filename); virConfFree(conf); return -1; } p = virConfGetValue (conf, "user"); CHECK_TYPE ("user", VIR_CONF_STRING); if (!(user = strdup(p && p->str ? p->str : QEMU_USER))) { virReportOOMError(); virConfFree(conf); return -1; } if (virGetUserID(user, &driver->user) < 0) { VIR_FREE(user); virConfFree(conf); return -1; } VIR_FREE(user); p = virConfGetValue (conf, "group"); CHECK_TYPE ("group", VIR_CONF_STRING); if (!(group = strdup(p && p->str ? p->str : QEMU_GROUP))) { virReportOOMError(); virConfFree(conf); return -1; } if (virGetGroupID(group, &driver->group) < 0) { VIR_FREE(group); virConfFree(conf); return -1; } VIR_FREE(group); p = virConfGetValue (conf, "dynamic_ownership"); CHECK_TYPE ("dynamic_ownership", VIR_CONF_LONG); if (p) driver->dynamicOwnership = p->l; p = virConfGetValue (conf, "cgroup_controllers"); CHECK_TYPE ("cgroup_controllers", VIR_CONF_LIST); if (p) { virConfValuePtr pp; for (i = 0, pp = p->list; pp; ++i, pp = pp->next) { int ctl; if (pp->type != VIR_CONF_STRING) { VIR_ERROR(_("cgroup_controllers must be a list of strings")); virConfFree(conf); return -1; } ctl = virCgroupControllerTypeFromString(pp->str); if (ctl < 0) { VIR_ERROR(_("Unknown cgroup controller '%s'"), pp->str); virConfFree(conf); return -1; } driver->cgroupControllers |= (1 << ctl); } } else { driver->cgroupControllers = (1 << VIR_CGROUP_CONTROLLER_CPU) | (1 << VIR_CGROUP_CONTROLLER_DEVICES) | (1 << VIR_CGROUP_CONTROLLER_MEMORY) | (1 << VIR_CGROUP_CONTROLLER_BLKIO) | (1 << VIR_CGROUP_CONTROLLER_CPUSET) | (1 << VIR_CGROUP_CONTROLLER_CPUACCT); } for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) { if (driver->cgroupControllers & (1 << i)) { VIR_INFO("Configured cgroup controller '%s'", virCgroupControllerTypeToString(i)); } } p = virConfGetValue (conf, "cgroup_device_acl"); CHECK_TYPE ("cgroup_device_acl", VIR_CONF_LIST); if (p) { int len = 0; virConfValuePtr pp; for (pp = p->list; pp; pp = pp->next) len++; if (VIR_ALLOC_N(driver->cgroupDeviceACL, 1+len) < 0) { virReportOOMError(); virConfFree(conf); return -1; } for (i = 0, pp = p->list; pp; ++i, pp = pp->next) { if (pp->type != VIR_CONF_STRING) { VIR_ERROR(_("cgroup_device_acl must be a list of strings")); virConfFree(conf); return -1; } driver->cgroupDeviceACL[i] = strdup (pp->str); if (driver->cgroupDeviceACL[i] == NULL) { virReportOOMError(); virConfFree(conf); return -1; } } driver->cgroupDeviceACL[i] = NULL; } p = virConfGetValue (conf, "save_image_format"); CHECK_TYPE ("save_image_format", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->saveImageFormat); if (!(driver->saveImageFormat = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "dump_image_format"); CHECK_TYPE ("dump_image_format", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->dumpImageFormat); if (!(driver->dumpImageFormat = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "auto_dump_path"); CHECK_TYPE ("auto_dump_path", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->autoDumpPath); if (!(driver->autoDumpPath = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "auto_dump_bypass_cache"); CHECK_TYPE ("auto_dump_bypass_cache", VIR_CONF_LONG); if (p) driver->autoDumpBypassCache = true; p = virConfGetValue (conf, "auto_start_bypass_cache"); CHECK_TYPE ("auto_start_bypass_cache", VIR_CONF_LONG); if (p) driver->autoStartBypassCache = true; p = virConfGetValue (conf, "hugetlbfs_mount"); CHECK_TYPE ("hugetlbfs_mount", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->hugetlbfs_mount); if (!(driver->hugetlbfs_mount = strdup(p->str))) { virReportOOMError(); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "mac_filter"); CHECK_TYPE ("mac_filter", VIR_CONF_LONG); if (p && p->l) { driver->macFilter = p->l; if (!(driver->ebtables = ebtablesContextNew("qemu"))) { driver->macFilter = 0; virReportSystemError(errno, _("failed to enable mac filter in '%s'"), __FILE__); virConfFree(conf); return -1; } if ((errno = networkDisableAllFrames(driver))) { virReportSystemError(errno, _("failed to add rule to drop all frames in '%s'"), __FILE__); virConfFree(conf); return -1; } } p = virConfGetValue (conf, "relaxed_acs_check"); CHECK_TYPE ("relaxed_acs_check", VIR_CONF_LONG); if (p) driver->relaxedACS = p->l; p = virConfGetValue (conf, "vnc_allow_host_audio"); CHECK_TYPE ("vnc_allow_host_audio", VIR_CONF_LONG); if (p) driver->vncAllowHostAudio = p->l; p = virConfGetValue (conf, "clear_emulator_capabilities"); CHECK_TYPE ("clear_emulator_capabilities", VIR_CONF_LONG); if (p) driver->clearEmulatorCapabilities = p->l; p = virConfGetValue (conf, "allow_disk_format_probing"); CHECK_TYPE ("allow_disk_format_probing", VIR_CONF_LONG); if (p) driver->allowDiskFormatProbing = p->l; p = virConfGetValue (conf, "set_process_name"); CHECK_TYPE ("set_process_name", VIR_CONF_LONG); if (p) driver->setProcessName = p->l; p = virConfGetValue(conf, "max_processes"); CHECK_TYPE("max_processes", VIR_CONF_LONG); if (p) driver->maxProcesses = p->l; p = virConfGetValue(conf, "max_files"); CHECK_TYPE("max_files", VIR_CONF_LONG); if (p) driver->maxFiles = p->l; p = virConfGetValue (conf, "lock_manager"); CHECK_TYPE ("lock_manager", VIR_CONF_STRING); if (p && p->str) { char *lockConf; virLockManagerPluginUnref(driver->lockManager); if (virAsprintf(&lockConf, "%s/libvirt/qemu-%s.conf", SYSCONFDIR, p->str) < 0) { virReportOOMError(); virConfFree(conf); return -1; } if (!(driver->lockManager = virLockManagerPluginNew(p->str, lockConf, 0))) VIR_ERROR(_("Failed to load lock manager %s"), p->str); VIR_FREE(lockConf); } p = virConfGetValue(conf, "max_queued"); CHECK_TYPE("max_queued", VIR_CONF_LONG); if (p) driver->max_queued = p->l; p = virConfGetValue(conf, "keepalive_interval"); CHECK_TYPE("keepalive_interval", VIR_CONF_LONG); if (p) driver->keepAliveInterval = p->l; p = virConfGetValue(conf, "keepalive_count"); CHECK_TYPE("keepalive_count", VIR_CONF_LONG); if (p) driver->keepAliveCount = p->l; virConfFree (conf); return 0; }
bool GetValue(HKEY Key, const string& Name, T& Value) { CHECK_TYPE(T); return GetValue(Key, Name.data(), Value); }
int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, const char *filename) { virConfPtr conf = NULL; virConfValuePtr p; int ret = -1; size_t i; /* Just check the file is readable before opening it, otherwise * libvirt emits an error. */ if (access(filename, R_OK) == -1) { VIR_INFO("Could not read qemu config file %s", filename); return 0; } if (!(conf = virConfReadFile(filename, 0))) goto cleanup; #define CHECK_TYPE(name,typ) \ if (p && p->type != (typ)) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ "%s: %s: expected type " #typ, \ filename, (name)); \ goto cleanup; \ } #define GET_VALUE_LONG(NAME, VAR) \ p = virConfGetValue(conf, NAME); \ CHECK_TYPE(NAME, VIR_CONF_LONG); \ if (p) \ VAR = p->l; #define GET_VALUE_BOOL(NAME, VAR) \ p = virConfGetValue(conf, NAME); \ CHECK_TYPE(NAME, VIR_CONF_LONG); \ if (p) \ VAR = p->l != 0; #define GET_VALUE_STR(NAME, VAR) \ p = virConfGetValue(conf, NAME); \ CHECK_TYPE(NAME, VIR_CONF_STRING); \ if (p && p->str) { \ VIR_FREE(VAR); \ if (VIR_STRDUP(VAR, p->str) < 0) \ goto cleanup; \ } GET_VALUE_BOOL("vnc_auto_unix_socket", cfg->vncAutoUnixSocket); GET_VALUE_BOOL("vnc_tls", cfg->vncTLS); GET_VALUE_BOOL("vnc_tls_x509_verify", cfg->vncTLSx509verify); GET_VALUE_STR("vnc_tls_x509_cert_dir", cfg->vncTLSx509certdir); GET_VALUE_STR("vnc_listen", cfg->vncListen); GET_VALUE_STR("vnc_password", cfg->vncPassword); GET_VALUE_BOOL("vnc_sasl", cfg->vncSASL); GET_VALUE_STR("vnc_sasl_dir", cfg->vncSASLdir); GET_VALUE_BOOL("vnc_allow_host_audio", cfg->vncAllowHostAudio); GET_VALUE_BOOL("nographics_allow_host_audio", cfg->nogfxAllowHostAudio); p = virConfGetValue(conf, "security_driver"); if (p && p->type == VIR_CONF_LIST) { size_t len; virConfValuePtr pp; /* Calc length and check items */ for (len = 0, pp = p->list; pp; len++, pp = pp->next) { if (pp->type != VIR_CONF_STRING) { virReportError(VIR_ERR_CONF_SYNTAX, "%s", _("security_driver must be a list of strings")); goto cleanup; } } if (VIR_ALLOC_N(cfg->securityDriverNames, len + 1) < 0) goto cleanup; for (i = 0, pp = p->list; pp; i++, pp = pp->next) { if (VIR_STRDUP(cfg->securityDriverNames[i], pp->str) < 0) goto cleanup; } cfg->securityDriverNames[len] = NULL; } else { CHECK_TYPE("security_driver", VIR_CONF_STRING); if (p && p->str) { if (VIR_ALLOC_N(cfg->securityDriverNames, 2) < 0) goto cleanup; if (VIR_STRDUP(cfg->securityDriverNames[0], p->str) < 0) goto cleanup; cfg->securityDriverNames[1] = NULL; } } GET_VALUE_BOOL("security_default_confined", cfg->securityDefaultConfined); GET_VALUE_BOOL("security_require_confined", cfg->securityRequireConfined); GET_VALUE_BOOL("spice_tls", cfg->spiceTLS); GET_VALUE_STR("spice_tls_x509_cert_dir", cfg->spiceTLSx509certdir); GET_VALUE_BOOL("spice_sasl", cfg->spiceSASL); GET_VALUE_STR("spice_sasl_dir", cfg->spiceSASLdir); GET_VALUE_STR("spice_listen", cfg->spiceListen); GET_VALUE_STR("spice_password", cfg->spicePassword); GET_VALUE_LONG("remote_websocket_port_min", cfg->webSocketPortMin); if (cfg->webSocketPortMin < QEMU_WEBSOCKET_PORT_MIN) { /* if the port is too low, we can't get the display name * to tell to vnc (usually subtract 5700, e.g. localhost:1 * for port 5701) */ virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_websocket_port_min: port must be greater " "than or equal to %d"), filename, QEMU_WEBSOCKET_PORT_MIN); goto cleanup; } GET_VALUE_LONG("remote_websocket_port_max", cfg->webSocketPortMax); if (cfg->webSocketPortMax > QEMU_WEBSOCKET_PORT_MAX || cfg->webSocketPortMax < cfg->webSocketPortMin) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_websocket_port_max: port must be between " "the minimal port and %d"), filename, QEMU_WEBSOCKET_PORT_MAX); goto cleanup; } if (cfg->webSocketPortMin > cfg->webSocketPortMax) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_websocket_port_min: min port must not be " "greater than max port"), filename); goto cleanup; } GET_VALUE_LONG("remote_display_port_min", cfg->remotePortMin); if (cfg->remotePortMin < QEMU_REMOTE_PORT_MIN) { /* if the port is too low, we can't get the display name * to tell to vnc (usually subtract 5900, e.g. localhost:1 * for port 5901) */ virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_display_port_min: port must be greater " "than or equal to %d"), filename, QEMU_REMOTE_PORT_MIN); goto cleanup; } GET_VALUE_LONG("remote_display_port_max", cfg->remotePortMax); if (cfg->remotePortMax > QEMU_REMOTE_PORT_MAX || cfg->remotePortMax < cfg->remotePortMin) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_display_port_max: port must be between " "the minimal port and %d"), filename, QEMU_REMOTE_PORT_MAX); goto cleanup; } if (cfg->remotePortMin > cfg->remotePortMax) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: remote_display_port_min: min port must not be " "greater than max port"), filename); goto cleanup; } GET_VALUE_LONG("migration_port_min", cfg->migrationPortMin); if (cfg->migrationPortMin <= 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: migration_port_min: port must be greater than 0"), filename); goto cleanup; } GET_VALUE_LONG("migration_port_max", cfg->migrationPortMax); if (cfg->migrationPortMax > 65535 || cfg->migrationPortMax < cfg->migrationPortMin) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: migration_port_max: port must be between " "the minimal port %d and 65535"), filename, cfg->migrationPortMin); goto cleanup; } p = virConfGetValue(conf, "user"); CHECK_TYPE("user", VIR_CONF_STRING); if (p && p->str && virGetUserID(p->str, &cfg->user) < 0) goto cleanup; p = virConfGetValue(conf, "group"); CHECK_TYPE("group", VIR_CONF_STRING); if (p && p->str && virGetGroupID(p->str, &cfg->group) < 0) goto cleanup; GET_VALUE_BOOL("dynamic_ownership", cfg->dynamicOwnership); p = virConfGetValue(conf, "cgroup_controllers"); CHECK_TYPE("cgroup_controllers", VIR_CONF_LIST); if (p) { cfg->cgroupControllers = 0; virConfValuePtr pp; for (i = 0, pp = p->list; pp; ++i, pp = pp->next) { int ctl; if (pp->type != VIR_CONF_STRING) { virReportError(VIR_ERR_CONF_SYNTAX, "%s", _("cgroup_controllers must be a " "list of strings")); goto cleanup; } if ((ctl = virCgroupControllerTypeFromString(pp->str)) < 0) { virReportError(VIR_ERR_CONF_SYNTAX, _("Unknown cgroup controller '%s'"), pp->str); goto cleanup; } cfg->cgroupControllers |= (1 << ctl); } } p = virConfGetValue(conf, "cgroup_device_acl"); CHECK_TYPE("cgroup_device_acl", VIR_CONF_LIST); if (p) { int len = 0; virConfValuePtr pp; for (pp = p->list; pp; pp = pp->next) len++; if (VIR_ALLOC_N(cfg->cgroupDeviceACL, 1+len) < 0) goto cleanup; for (i = 0, pp = p->list; pp; ++i, pp = pp->next) { if (pp->type != VIR_CONF_STRING) { virReportError(VIR_ERR_CONF_SYNTAX, "%s", _("cgroup_device_acl must be a " "list of strings")); goto cleanup; } if (VIR_STRDUP(cfg->cgroupDeviceACL[i], pp->str) < 0) goto cleanup; } cfg->cgroupDeviceACL[i] = NULL; } GET_VALUE_STR("save_image_format", cfg->saveImageFormat); GET_VALUE_STR("dump_image_format", cfg->dumpImageFormat); GET_VALUE_STR("snapshot_image_format", cfg->snapshotImageFormat); GET_VALUE_STR("auto_dump_path", cfg->autoDumpPath); GET_VALUE_BOOL("auto_dump_bypass_cache", cfg->autoDumpBypassCache); GET_VALUE_BOOL("auto_start_bypass_cache", cfg->autoStartBypassCache); GET_VALUE_STR("hugetlbfs_mount", cfg->hugetlbfsMount); GET_VALUE_STR("bridge_helper", cfg->bridgeHelperName); GET_VALUE_BOOL("mac_filter", cfg->macFilter); GET_VALUE_BOOL("relaxed_acs_check", cfg->relaxedACS); GET_VALUE_BOOL("clear_emulator_capabilities", cfg->clearEmulatorCapabilities); GET_VALUE_BOOL("allow_disk_format_probing", cfg->allowDiskFormatProbing); GET_VALUE_BOOL("set_process_name", cfg->setProcessName); GET_VALUE_LONG("max_processes", cfg->maxProcesses); GET_VALUE_LONG("max_files", cfg->maxFiles); GET_VALUE_STR("lock_manager", cfg->lockManagerName); GET_VALUE_LONG("max_queued", cfg->maxQueuedJobs); GET_VALUE_LONG("keepalive_interval", cfg->keepAliveInterval); GET_VALUE_LONG("keepalive_count", cfg->keepAliveCount); GET_VALUE_LONG("seccomp_sandbox", cfg->seccompSandbox); GET_VALUE_STR("migration_address", cfg->migrationAddress); ret = 0; cleanup: virConfFree(conf); return ret; }
bool GetValue(HKEY RootKey, const wchar_t* SubKey, const string& Name, T& Value, REGSAM Sam = 0) { CHECK_TYPE(T); return GetValue(RootKey, SubKey, Name.data(), Value, Sam); }
int lxcLoadDriverConfig(virLXCDriverPtr driver) { char *filename; virConfPtr conf; virConfValuePtr p; driver->securityDefaultConfined = false; driver->securityRequireConfined = false; /* Set the container configuration directory */ if (VIR_STRDUP(driver->configDir, LXC_CONFIG_DIR) < 0) goto error; if (VIR_STRDUP(driver->stateDir, LXC_STATE_DIR) < 0) goto error; if (VIR_STRDUP(driver->logDir, LXC_LOG_DIR) < 0) goto error; if (VIR_STRDUP(driver->autostartDir, LXC_AUTOSTART_DIR) < 0) goto error; if (VIR_STRDUP(filename, SYSCONFDIR "/libvirt/lxc.conf") < 0) goto error; /* Avoid error from non-existant or unreadable file. */ if (access(filename, R_OK) == -1) goto done; conf = virConfReadFile(filename, 0); if (!conf) goto done; #define CHECK_TYPE(name,typ) if (p && p->type != (typ)) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ "%s: %s: expected type " #typ, \ filename, (name)); \ virConfFree(conf); \ return -1; \ } p = virConfGetValue(conf, "log_with_libvirtd"); CHECK_TYPE("log_with_libvirtd", VIR_CONF_LONG); if (p) driver->log_libvirtd = p->l; p = virConfGetValue(conf, "security_driver"); CHECK_TYPE("security_driver", VIR_CONF_STRING); if (p && p->str) { if (VIR_STRDUP(driver->securityDriverName, p->str) < 0) { virConfFree(conf); return -1; } } p = virConfGetValue(conf, "security_default_confined"); CHECK_TYPE("security_default_confined", VIR_CONF_LONG); if (p) driver->securityDefaultConfined = p->l; p = virConfGetValue(conf, "security_require_confined"); CHECK_TYPE("security_require_confined", VIR_CONF_LONG); if (p) driver->securityRequireConfined = p->l; #undef CHECK_TYPE virConfFree(conf); done: VIR_FREE(filename); return 0; error: return -1; }