static gboolean local_validate (UmAccountDialog *self) { gboolean valid_login; gboolean valid_name; GtkWidget *entry; const gchar *name; gchar *tip; name = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (self->local_username)); valid_login = is_valid_username (name, &tip); entry = gtk_bin_get_child (GTK_BIN (self->local_username)); if (tip) { set_entry_validation_error (GTK_ENTRY (entry), tip); g_free (tip); } else { clear_entry_validation_error (GTK_ENTRY (entry)); } name = gtk_entry_get_text (GTK_ENTRY (self->local_name)); valid_name = is_valid_name (name); return valid_name && valid_login; }
static void check_name (gchar **primary_text, gchar **secondary_text, gpointer data) { OobsGroup *group = OOBS_GROUP (data); GtkWidget *widget; const gchar *name; widget = gst_dialog_get_widget (tool->main_dialog, "group_settings_name"); name = gtk_entry_get_text (GTK_ENTRY (widget)); if (strlen (name) < 1) { *primary_text = g_strdup (_("Group name is empty")); *secondary_text = g_strdup (_("A group name must be specified.")); } else if (is_group_root (group) && strcmp (name, "root") != 0) { *primary_text = g_strdup (_("Group name of the administrator group user should not be modified")); *secondary_text = g_strdup (_("This would leave the system unusable.")); } else if (!is_valid_name (name)) { *primary_text = g_strdup (_("Group name has invalid characters")); *secondary_text = g_strdup (_("Please set a valid group name consisting of " "a lower case letter followed by lower case " "letters and numbers.")); } else if (group_settings_dialog_group_is_new () && group_exists (name)) { *primary_text = g_strdup_printf (_("Group \"%s\" already exists"), name); *secondary_text = g_strdup (_("Please select a different user name.")); } }
static void name_map(char *OutName, BOOL need83, BOOL cache83, int default_case, int snum) { smb_ucs2_t *OutName_ucs2; magic_char = lp_magicchar(snum); DEBUG(5,("name_map( %s, need83 = %s, cache83 = %s)\n", OutName, need83 ? "True" : "False", cache83 ? "True" : "False")); if (push_ucs2_allocate(&OutName_ucs2, OutName) == (size_t)-1) { DEBUG(0, ("push_ucs2_allocate failed!\n")); return; } if( !need83 && !NT_STATUS_IS_OK(is_valid_name(OutName_ucs2, False, False))) need83 = True; /* check if it's already in 8.3 format */ if (need83 && !NT_STATUS_IS_OK(is_8_3_w(OutName_ucs2, False))) { char *tmp = NULL; /* mangle it into 8.3 */ if (cache83) tmp = SMB_STRDUP(OutName); to_8_3(OutName, default_case); if(tmp != NULL) { cache_mangled_name(OutName, tmp); SAFE_FREE(tmp); } } DEBUG(5,("name_map() ==> [%s]\n", OutName)); SAFE_FREE(OutName_ucs2); }
void account_create_operation::validate()const { FC_ASSERT( fee.amount >= 0 ); FC_ASSERT( is_valid_name( name ) ); FC_ASSERT( referrer_percent <= GRAPHENE_100_PERCENT ); FC_ASSERT( owner.num_auths() != 0 ); FC_ASSERT( owner.address_auths.size() == 0 ); FC_ASSERT( active.num_auths() != 0 ); FC_ASSERT( active.address_auths.size() == 0 ); FC_ASSERT( !owner.is_impossible(), "cannot create an account with an imposible owner authority threshold" ); FC_ASSERT( !active.is_impossible(), "cannot create an account with an imposible active authority threshold" ); options.validate(); if( extensions.value.owner_special_authority.valid() ) validate_special_authority( *extensions.value.owner_special_authority ); if( extensions.value.active_special_authority.valid() ) validate_special_authority( *extensions.value.active_special_authority ); if( extensions.value.buyback_options.valid() ) { FC_ASSERT( !(extensions.value.owner_special_authority.valid()) ); FC_ASSERT( !(extensions.value.active_special_authority.valid()) ); FC_ASSERT( owner == authority::null_authority() ); FC_ASSERT( active == authority::null_authority() ); size_t n_markets = extensions.value.buyback_options->markets.size(); FC_ASSERT( n_markets > 0 ); for( const asset_id_type m : extensions.value.buyback_options->markets ) { FC_ASSERT( m != extensions.value.buyback_options->asset_to_buy ); } } }
/** * g_dbus_is_interface_name: * @string: The string to check. * * Checks if @string is a valid D-Bus interface name. * * Returns: %TRUE if valid, %FALSE otherwise. * * Since: 2.26 */ gboolean g_dbus_is_interface_name (const gchar *string) { guint len; gboolean ret; const gchar *s; const gchar *end; g_return_val_if_fail (string != NULL, FALSE); ret = FALSE; len = strlen (string); if (G_UNLIKELY (len == 0 || len > 255)) goto out; s = string; end = s + len; if (G_UNLIKELY (*s == '.')) { /* can't start with a . */ goto out; } else if (G_UNLIKELY (!is_valid_initial_bus_name_character (*s, FALSE, FALSE))) goto out; ret = is_valid_name (s + 1, len - 1, FALSE, FALSE); out: return ret; }
/** * g_dbus_is_unique_name: * @string: The string to check. * * Checks if @string is a valid D-Bus unique bus name. * * Returns: %TRUE if valid, %FALSE otherwise. * * Since: 2.26 */ gboolean g_dbus_is_unique_name (const gchar *string) { gboolean ret; guint len; g_return_val_if_fail (string != NULL, FALSE); ret = FALSE; len = strlen (string); if (G_UNLIKELY (len == 0 || len > 255)) goto out; if (G_UNLIKELY (*string != ':')) goto out; if (G_UNLIKELY (!is_valid_name (string + 1, len - 1, TRUE, TRUE))) goto out; ret = TRUE; out: return ret; }
/* * drop a bucket with a specified name, * no return value, check log when you find something wrong */ void bucket_drop(const char *name) { if (!is_valid_name(name)) return; struct bucket *bucket; pthread_rwlock_wrlock(&rwlock); HASH_FIND_STR(buckets, name, bucket); if (bucket) { /* TODO: find and delete all data on hard disk belongs to this bucket */ /* TODO: find and delete all request in write queue belongs to this bucket */ while (bucket->tables) { HASH_DEL(bucket->tables, bucket->tables); } HASH_DEL(buckets, bucket); } // close_storage(bucket->bsp); char link_from[1024]; snprintf(link_from, sizeof(link_from), "%s.schema", name); if (unlink(link_from) != 0) log_error("unlink %s failed: %s", link_from, strerror(errno)); snprintf(link_from, sizeof(link_from), "%s/schema", name); if (unlink(link_from) != 0) log_error("unlink %s failed: %s", link_from, strerror(errno)); pthread_rwlock_unlock(&rwlock); }
void impl::Stats::add(const std::string& name, const StatBase& stat) { assert(_stats.find(name) == _stats.end()); assert(is_valid_name(name)); _stats[name] = &stat; }
/* static */ void GeneratorRegistry::register_factory(const std::string &name, std::unique_ptr<GeneratorFactory> factory) { user_assert(is_valid_name(name)) << "Invalid Generator name: " << name; GeneratorRegistry ®istry = get_registry(); std::lock_guard<std::mutex> lock(registry.mutex); internal_assert(registry.factories.find(name) == registry.factories.end()) << "Duplicate Generator name: " << name; registry.factories[name] = std::move(factory); }
static gboolean enterprise_validate (UmAccountDialog *self) { const gchar *name; gboolean valid_name; gboolean valid_domain; GtkTreeIter iter; name = gtk_entry_get_text (GTK_ENTRY (self->enterprise_login)); valid_name = is_valid_name (name); if (gtk_combo_box_get_active_iter (self->enterprise_domain, &iter)) { gtk_tree_model_get (gtk_combo_box_get_model (self->enterprise_domain), &iter, 0, &name, -1); } else { name = gtk_entry_get_text (self->enterprise_domain_entry); } valid_domain = is_valid_name (name); return valid_name && valid_domain; }
bool is_valid_user_name (const char *name) { /* * User names are limited by whatever utmp can * handle. */ if (strlen (name) > USER_NAME_MAX_LENGTH) { return false; } return is_valid_name (name); }
gboolean gis_account_page_enterprise_validate (GisAccountPageEnterprise *page) { const gchar *name; gboolean valid_name; gboolean valid_domain; GtkTreeIter iter; GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page); name = gtk_entry_get_text (GTK_ENTRY (priv->login)); valid_name = is_valid_name (name); if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->domain), &iter)) { gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (priv->domain)), &iter, 0, &name, -1); } else { name = gtk_entry_get_text (GTK_ENTRY (priv->domain_entry)); } valid_domain = is_valid_name (name); return valid_name && valid_domain; }
bool is_valid_group_name (const char *name) { /* * Arbitrary limit for group names. * HP-UX 10 limits to 16 characters */ if ( (GROUP_NAME_MAX_LENGTH > 0) && (strlen (name) > GROUP_NAME_MAX_LENGTH)) { return false; } return is_valid_name (name); }
/** * g_dbus_is_name: * @string: The string to check. * * Checks if @string is a valid D-Bus bus name (either unique or well-known). * * Returns: %TRUE if valid, %FALSE otherwise. * * Since: 2.26 */ gboolean g_dbus_is_name (const gchar *string) { guint len; gboolean ret; const gchar *s; g_return_val_if_fail (string != NULL, FALSE); ret = FALSE; len = strlen (string); if (G_UNLIKELY (len == 0 || len > 255)) goto out; s = string; if (*s == ':') { /* handle unique name */ if (!is_valid_name (s + 1, len - 1, TRUE, TRUE)) goto out; ret = TRUE; goto out; } else if (G_UNLIKELY (*s == '.')) { /* can't start with a . */ goto out; } else if (G_UNLIKELY (!is_valid_initial_bus_name_character (*s, FALSE, TRUE))) goto out; ret = is_valid_name (s + 1, len - 1, FALSE, TRUE); out: return ret; }
void GeneratorBase::build_params() { if (!params_built) { std::vector<void *> vf = ObjectInstanceRegistry::instances_in_range( this, size, ObjectInstanceRegistry::FilterParam); for (size_t i = 0; i < vf.size(); ++i) { Parameter *param = static_cast<Parameter *>(vf[i]); internal_assert(param != nullptr); user_assert(param->is_explicit_name()) << "Params in Generators must have explicit names: " << param->name(); user_assert(is_valid_name(param->name())) << "Invalid Param name: " << param->name(); for (const Argument& arg : filter_arguments) { user_assert(arg.name != param->name()) << "Duplicate Param name: " << param->name(); } Expr def, min, max; if (!param->is_buffer()) { def = param->get_scalar_expr(); min = param->get_min_value(); max = param->get_max_value(); } filter_arguments.push_back(Argument(param->name(), param->is_buffer() ? Argument::InputBuffer : Argument::InputScalar, param->type(), param->dimensions(), def, min, max)); } std::vector<void *> vg = ObjectInstanceRegistry::instances_in_range( this, size, ObjectInstanceRegistry::GeneratorParam); for (size_t i = 0; i < vg.size(); ++i) { GeneratorParamBase *param = static_cast<GeneratorParamBase *>(vg[i]); internal_assert(param != nullptr); user_assert(is_valid_name(param->name)) << "Invalid GeneratorParam name: " << param->name; user_assert(generator_params.find(param->name) == generator_params.end()) << "Duplicate GeneratorParam name: " << param->name; generator_params[param->name] = param; } params_built = true; } }
void declaration(ecc_context *ctx, const char *token) { ctx->lex_advance(ctx, str_nlen(token, TOKEN_MAX)); token = ctx->lex_look_ahead(ctx); if (!(is_valid_name(token))) { err_msg("token '"); err_msg(token); err_msg("' not a valid name\n"); die(); } ctx->stack_assign_name(ctx, token); token = ctx->lex_look_ahead(ctx); if (!(is_declaration(token))) { done_declaring(ctx); } }
static bool must_mangle(const char *name, const struct share_params *p) { smb_ucs2_t *name_ucs2 = NULL; NTSTATUS status; size_t converted_size; char magic_char; magic_char = lp_magicchar(p); if (!push_ucs2_talloc(NULL, &name_ucs2, name, &converted_size)) { DEBUG(0, ("push_ucs2_talloc failed!\n")); return False; } status = is_valid_name(name_ucs2, False, False); TALLOC_FREE(name_ucs2); return NT_STATUS_IS_OK(status); }
static bool must_mangle(const char *name, const struct share_params *p) { smb_ucs2_t *name_ucs2 = NULL; NTSTATUS status; size_t converted_size; if (!push_ucs2_talloc(NULL, &name_ucs2, name, &converted_size)) { DEBUG(0, ("push_ucs2_talloc failed!\n")); return False; } status = is_valid_name(name_ucs2, False, False); TALLOC_FREE(name_ucs2); /* We return true if we *must* mangle, so if it's * a valid name (status == OK) then we must return * false. Bug #6939. */ return !NT_STATUS_IS_OK(status); }
/* * returns a string containing all bucket name * returns NULL if it fails */ char *bucket_list(void) { /* load buckets from filesystem */ int size; int pos = 0; char *result; struct bucket *bucket; int len; DIR *dir = opendir("."); if (dir) { struct dirent *dirent; while ((dirent = readdir(dir))) { if ((dirent->d_type & DT_DIR) && is_valid_name(dirent->d_name)) bucket_get(dirent->d_name, CAN_RETURN_NULL); } closedir(dir); } pthread_rwlock_rdlock(&rwlock); size = len = 0; for (bucket = buckets; bucket; bucket = (struct bucket *)bucket->hh.next) { len = strlen(bucket->name) + 1; size += len; } result = slab_alloc(size); if (!result) return NULL; size = len = 0; for (bucket = buckets; bucket; bucket = (struct bucket *)bucket->hh.next) { len = strlen(bucket->name) + 1; size += len; memcpy(result + pos, bucket->name, len); pos = size; } pthread_rwlock_unlock(&rwlock); result[pos] = '\0'; return result; }
static NTSTATUS is_8_3_w(const smb_ucs2_t *fname, bool allow_wildcards) { smb_ucs2_t *pref = 0, *ext = 0; size_t plen; NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; if (!fname || !*fname) return NT_STATUS_INVALID_PARAMETER; if (strlen_w(fname) > 12) return NT_STATUS_UNSUCCESSFUL; if (strcmp_wa(fname, ".") == 0 || strcmp_wa(fname, "..") == 0) return NT_STATUS_OK; /* Name cannot start with '.' */ if (*fname == UCS2_CHAR('.')) return NT_STATUS_UNSUCCESSFUL; if (!NT_STATUS_IS_OK(is_valid_name(fname, allow_wildcards, True))) goto done; if (!NT_STATUS_IS_OK(mangle_get_prefix(fname, &pref, &ext, allow_wildcards))) goto done; plen = strlen_w(pref); if (strchr_wa(pref, '.')) goto done; if (plen < 1 || plen > 8) goto done; if (ext && (strlen_w(ext) > 3)) goto done; ret = NT_STATUS_OK; done: SAFE_FREE(pref); SAFE_FREE(ext); return ret; }
int schema_field_add(struct schema *schema, const char *name, bool is_signed, uint8_t nbits, bool is_primary_key) { if (schema->nfields == sizeof(schema->fields) / sizeof(schema->fields[0])) return -1; if (nbits > 64) return -5; if (nbits == 64 && is_signed) return -6; if (schema_field_get(schema, name)) return -2; if (!is_valid_name(name)) return -8; size_t name_len = strlen(name); struct field *field = &schema->fields[schema->nfields]; if (name_len + 1 > sizeof(field->name)) return -3; strcpy(field->name, name); field->is_signed = is_signed; field->offset = schema->nbits; field->nbits = nbits; if (is_primary_key && schema->primary_key_index != -1) return -7; field->is_primary_key = is_primary_key; if (is_primary_key) schema->primary_key_index = schema->nfields; schema->nbits += nbits; schema->nfields++; return 0; }
static bool hash_name_to_8_3(const char *in, char out[13], bool cache83, int default_case, const struct share_params *p) { smb_ucs2_t *in_ucs2 = NULL; size_t converted_size; char magic_char; magic_char = lp_magicchar(p); DEBUG(5,("hash_name_to_8_3( %s, cache83 = %s)\n", in, cache83 ? "True" : "False")); if (!push_ucs2_talloc(NULL, &in_ucs2, in, &converted_size)) { DEBUG(0, ("push_ucs2_talloc failed!\n")); return False; } /* If it's already 8.3, just copy. */ if (NT_STATUS_IS_OK(is_valid_name(in_ucs2, False, False)) && NT_STATUS_IS_OK(is_8_3_w(in_ucs2, False))) { TALLOC_FREE(in_ucs2); strlcpy(out, in, 13); return True; } TALLOC_FREE(in_ucs2); if (!to_8_3(magic_char, in, out, default_case)) { return False; } cache_mangled_name(out, in); DEBUG(5,("hash_name_to_8_3(%s) ==> [%s]\n", in, out)); return True; }
bool account_name_eq_lit_predicate::validate()const { return is_valid_name( name ); }
/* * returns a pointer to a schema, or NULL if fails */ static struct schema *schema_create_from_hash(uint64_t hash, const char *bucket_name) { struct schema *schema = NULL; char buf[1024]; snprintf(buf, sizeof(buf), "%s/schemas/%016"PRIx64, bucket_name, hash); log_notice("read schema from file [%s]", buf); FILE *f = fopen(buf, "r"); if (f == NULL) { // legacy file path snprintf(buf, sizeof(buf), "schemas/%016"PRIx64, hash); log_notice("read schema from file [%s]", buf); f = fopen(buf, "r"); } if (f == NULL) { log_notice("read schema failed"); return NULL; } schema = schema_create(); if (!schema) { log_error("can't create schema"); goto fail; } while (fgets(buf, sizeof(buf), f)) { char *saveptr; char *token = strtok_r(buf, " \n\r\t", &saveptr); uint8_t is_primary_key = 0; uint8_t is_signed = 0; char *name = NULL; uint16_t nbits = 0; if (strcmp(token, "upgrade_to") == 0) { token = next_token(&saveptr); if (token == NULL) goto fail; if (sscanf(token, "%"SCNx64, &schema->upgrade_to) != 1) goto fail; if (schema->upgrade_to == 0) goto fail; } else { /* backward compat */ if (strcmp(token, "field") == 0) token = next_token(&saveptr); while (token) { if (token[0] >= '1' && token[1] <= '9') nbits = atoi(token); else if (strcmp(token, "primary_key") == 0) is_primary_key = 1; else if (strcmp(token, "signed") == 0) is_signed = 1; else if (token[0] == '[') { // field name size_t len = strlen(token); if (token[len - 1] == ']') { token[len - 1] = '\0'; name = &token[1]; if (!is_valid_name(name)) goto fail; } else goto fail; } else goto fail; token = next_token(&saveptr); } int res = schema_field_add(schema, name, is_signed, nbits, is_primary_key); if (res != 0) goto fail; } } fclose(f); schema->hash = hash; return schema; fail: fclose(f); if (schema) slab_free(schema); log_error("schema file %016"PRIx64" is invalid", hash); return NULL; }
/* gather data from UI to internal representation */ bool TframTag::ValidateView() { PTAG_NAME name; PRTK_TAG tag; name = &m_TagName; tag = &m_Tag; try{ #undef cc #define cc(name) tag->s.Flags |= (chk##name->Checked ? TF_##name : 0); if( edtTagName->Text.Length() >sizeof(TAG_KEY) || !edtTagName->Text.Length() ){ m_Hint = "变量名不正确"; throw(-1); } if( !is_valid_name(edtTagName->Text.c_str()) ){ m_Hint = "变量名只能包含字母、数字和下划线"; throw(-3); } if(edtTagName->Text.Length() > sizeof(TAG_KEY)){ m_Hint = AnsiString("错误: 标签名不能超过 ") + IntToStr(sizeof(TAG_KEY)) + " 个字节"; throw(-3); } name->sname.tag = CTagName(edtTagName->Text.c_str()); tag->s.Device = CDeviceName(cmbDevice->Text.c_str()); tag->key = name->sname.tag; if(edtCName->Text.Length() > sizeof(tag->s.Description)){ m_Hint = "中文名太长(最长 " + AnsiString(sizeof(tag->s.Description)/2) + " 字)"; throw(-4); } strncpy(tag->s.Description, edtCName->Text.c_str(), sizeof(tag->s.Description)); tag->s.Description[sizeof(tag->s.Description) - 1] = 0; if(edtAddr->Text.Length() > sizeof(tag->s.Address)){ m_Hint = "地址太长(最长 " + AnsiString(sizeof(tag->s.Address)/2) + " 字)"; throw(-5); } strncpy(tag->s.Address, edtAddr->Text.c_str(), sizeof(tag->s.Address)); tag->s.Address[sizeof(tag->s.Address) - 1] = 0; tag->s.Flags = 0; switch(cmbType->ItemIndex){ case 0: set_value_type(tag->s.Flags, dt_bool); break; case 1: set_value_type(tag->s.Flags, dt_real4); break; case 2: set_value_type(tag->s.Flags, dt_real8); break; case 3: set_value_type(tag->s.Flags, dt_int8); break; case 4: set_value_type(tag->s.Flags, dt_int16); break; case 5: set_value_type(tag->s.Flags, dt_int32); break; case 6: set_value_type(tag->s.Flags, dt_int64); break; case 7: set_value_type(tag->s.Flags, dt_uint8); break; case 8: set_value_type(tag->s.Flags, dt_uint16); break; case 9: set_value_type(tag->s.Flags, dt_uint32); break; case 10: set_value_type(tag->s.Flags, dt_uint64); break; case 11: set_value_type(tag->s.Flags, dt_date); break; case 12: m_Hint = "不支持这个数据类型."; throw(-41); break; } cc(SaveToHistory); cc(Step); // collecting common analog attributes switch(get_value_type(tag->s.Flags)){ case dt_int8: case dt_int16: case dt_int32: case dt_int64: case dt_uint8: case dt_uint16: case dt_uint32: case dt_uint64: case dt_real4: case dt_real8: case dt_date: cc(HiHi); cc(Lo); cc(Hi); cc(LoLo); cc(Rate); strncpy( tag->s.AnalogMsg.EU, edtEU->Text.c_str(), sizeof(tag->s.AnalogMsg.EU) ); tag->s.AnalogMsg.EU[sizeof(tag->s.AnalogMsg.EU) - 1] = 0; break; case dt_bool: cc(On2Off); cc(Off2On); strncpy( tag->s.SwitchMsg.OnMsg, edtOnMessage->Text.c_str(), sizeof(tag->s.SwitchMsg.OnMsg) ); tag->s.SwitchMsg.OnMsg[sizeof(tag->s.SwitchMsg.OnMsg) - 1] = 0; strncpy( tag->s.SwitchMsg.OffMsg, edtOffMessage->Text.c_str(), sizeof(tag->s.SwitchMsg.OffMsg) ); tag->s.SwitchMsg.OffMsg[sizeof(tag->s.SwitchMsg.OffMsg) - 1] = 0; break; } #define get(msg, name, ignore_on_condition, _default_value)\ m_Hint = msg;\ if( !edt##name->Text.Length() ){\ if(ignore_on_condition){\ tag->s.flt##name = _default_value;\ }else{\ throw(-1);\ }\ }else{\ tag->s.flt##name = edt##name->Text.ToDouble();\ } #pragma warn -ccc #pragma warn -rch switch(get_value_type(tag->s.Flags)){ case dt_real4: case dt_real8: get("高高值不正确", HiHi, !chkHiHi->Checked, 0); get("低低值不正确", LoLo, !chkLoLo->Checked, 0); get("低值不正确", Lo, !chkLo->Checked, 0); get("高值不正确", Hi, !chkHi->Checked, 0); get("报警死区值不正确", AlarmDeadband, !(tag->s.Flags & 0xffffff00), 0); get("最大值不正确", MaxValue, false, 0); get("最小值不正确", MinValue, false, 0); get("速率报警阈值不正确", Rate, !chkRate->Checked, 0.1); break; case dt_int8: case dt_int16: case dt_int32: case dt_int64: case dt_uint8: case dt_uint16: case dt_uint32: case dt_uint64: get("速率报警阈值不正确", Rate, !chkRate->Checked, 0.1); #undef get #define get(msg, attrName, uiName, ignore_on_condition, _default_value)\ m_Hint = msg;\ if( !edt##uiName->Text.Length() ){\ if(ignore_on_condition){\ tag->s.##attrName = _default_value;\ }else{\ throw(-1);\ }\ }else{\ tag->s.attrName = edt##uiName->Text.ToDouble();\ } get("高高值不正确", u_hihi.i, HiHi, !chkHiHi->Checked, 0); get("低低值不正确", u_lolo.i, LoLo, !chkLoLo->Checked, 0); get("低值不正确", u_lo.i, Lo, !chkLo->Checked, 0); get("高值不正确", u_hi.i, Hi, !chkHi->Checked, 0); get("报警死区值不正确", u_deadband.i, AlarmDeadband, !(tag->s.Flags & 0xffffff00), 0); get("最大值不正确", u_max.i, MaxValue, false, 0); get("最小值不正确", u_min.i, MinValue, false, 0); break; } #pragma warn .ccc #pragma warn .rch if(get_value_type(tag->s.Flags) == dt_bool){ tag->s.AlarmRank = edtAlarmRank2->Text.ToInt(); }else{ tag->s.AlarmRank = edtAlarmRank->Text.ToInt(); } tag->s.Compressing = Compress_Const; tag->s.CompDev = StrToFloat(edtCompDev->Text); tag->s.CompMax = StrToInt(edtCompMax->Text); }catch(...){ return false; } m_Hint = "更新成功"; return true; }
/* * get a bucket with the specified name, * if it does not exits, create it implicitly, * returns a pointer to the bucket on success, * returns NULL if it fails */ struct bucket *bucket_get(const char *name, int flags) { if (!is_valid_name(name)) { log_warn("invalid bucket name: [%s]", name); return NULL; } struct bucket *bucket; pthread_rwlock_rdlock(&rwlock); int wrlocked = 0; again: HASH_FIND_STR(buckets, name, bucket); if (bucket == NULL) { if (wrlocked == 0) { pthread_rwlock_unlock(&rwlock); pthread_rwlock_wrlock(&rwlock); wrlocked = 1; goto again; } // find schema before malloc struct schema *schema = schema_get_latest(name); if (schema == NULL && (flags & CAN_RETURN_NULL)) goto done; if (mkdir(name, 0755) == -1) { log_error("mkdir failed: %s", strerror(errno)); if (errno != EEXIST) goto done; } bucket = (struct bucket *)slab_alloc(sizeof(struct bucket)); /* XXX: free the schema that no one can be sure if it's referenced by others */ if (!bucket) { log_error("can't alloc bucket %s", name); goto done; } memset(bucket, 0, sizeof(struct bucket)); pthread_rwlock_init(&bucket->rwlock, NULL); size_t namelen = strlen(name); char filename[namelen + 4]; memcpy(filename, name, namelen); memcpy(filename + namelen, ".db", 4); if (open_storage(filename, 100 * 1024 * 1024, &bucket->bsp) != 0) { log_error("open_storage failed"); pthread_rwlock_destroy(&bucket->rwlock); slab_free(bucket); pthread_rwlock_unlock(&rwlock); return NULL; } strncpy(bucket->name, name, sizeof(bucket->name)); bucket->schema = schema; bucket->tables = NULL; HASH_ADD_STR(buckets, name, bucket); if (schema) schema_save_to_file(schema, bucket->name); } done: pthread_rwlock_unlock(&rwlock); return bucket; }