Example #1
0
int64_t f_extract(CArrRef var_array, int extract_type /* = EXTR_OVERWRITE */,
                  CStrRef prefix /* = "" */) {
  bool reference = extract_type & EXTR_REFS;
  extract_type &= ~EXTR_REFS;

  VarEnv* v = g_vmContext->getVarEnv();
  if (!v) return 0;
  int count = 0;
  for (ArrayIter iter(var_array); iter; ++iter) {
    String name = iter.first();
    StringData* nameData = name.get();
    switch (extract_type) {
      case EXTR_SKIP:
        if (v->lookup(nameData) != NULL) {
          continue;
        }
        break;
      case EXTR_IF_EXISTS:
        if (v->lookup(nameData) == NULL) {
          continue;
        }
        break;
      case EXTR_PREFIX_SAME:
        if (v->lookup(nameData) != NULL) {
          name = prefix + "_" + name;
        }
        break;
      case EXTR_PREFIX_ALL:
        name = prefix + "_" + name;
        break;
      case EXTR_PREFIX_INVALID:
        if (!is_valid_var_name(nameData->data(), nameData->size())) {
          name = prefix + "_" + name;
        }
        break;
      case EXTR_PREFIX_IF_EXISTS:
        if (v->lookup(nameData) == NULL) {
          continue;
        }
        name = prefix + "_" + name;
        break;
      default:
        break;
    }
    nameData = name.get();
    // skip invalid variable names, as in PHP
    if (!is_valid_var_name(nameData->data(), nameData->size())) {
      continue;
    }
    g_vmContext->setVar(nameData, iter.nvSecond(), reference);
    count++;
  }
  return count;
}
Example #2
0
bool Event_au_slide_stream_target_process(
        const Audio_unit* au,
        const Au_params* au_params,
        Au_state* au_state,
        Master_params* master_params,
        Channel* channel,
        Device_states* dstates,
        const Event_params* params)
{
    rassert(au != NULL);
    rassert(au_params != NULL);
    rassert(au_state != NULL);
    rassert(master_params != NULL);
    rassert(channel != NULL);
    rassert(dstates != NULL);
    rassert(params != NULL);
    rassert(params->arg != NULL);
    rassert(params->arg->type == VALUE_TYPE_FLOAT);

    const char* stream_name =
        Active_names_get(channel->parent.active_names, ACTIVE_CAT_STREAM);

    if ((stream_name == NULL) || !is_valid_var_name(stream_name))
        return false;

    Device_state* dstate = get_target_dstate(au, dstates, stream_name);
    if (dstate == NULL)
        return true;

    Stream_pstate_slide_target(dstate, params->arg->value.float_type);

    return true;
}
Example #3
0
static bool modify_extract_name(VarEnv* v,
                                String& name,
                                int64_t extract_type,
                                const String& prefix) {
  switch (extract_type) {
  case EXTR_SKIP:
    if (v->lookup(name.get()) != nullptr) {
      return false;
    }
    break;
  case EXTR_IF_EXISTS:
    if (v->lookup(name.get()) == nullptr) {
      return false;
    }
    break;
  case EXTR_PREFIX_SAME:
    if (v->lookup(name.get()) != nullptr) {
      name = prefix + "_" + name;
    }
    break;
  case EXTR_PREFIX_ALL:
    name = prefix + "_" + name;
    break;
  case EXTR_PREFIX_INVALID:
    if (!is_valid_var_name(name.get()->data(), name.size())) {
      name = prefix + "_" + name;
    }
    break;
  case EXTR_PREFIX_IF_EXISTS:
    if (v->lookup(name.get()) == nullptr) {
      return false;
    }
    name = prefix + "_" + name;
    break;
  default:
    break;
  }

  // skip invalid variable names, as in PHP
  return is_valid_var_name(name.get()->data(), name.size());
}
Example #4
0
Env_var* new_Env_var(Value_type type, const char* name)
{
    rassert((type == VALUE_TYPE_BOOL) || (type == VALUE_TYPE_INT) ||
            (type == VALUE_TYPE_FLOAT) || (type == VALUE_TYPE_TSTAMP));
    rassert(name != NULL);
    rassert(is_valid_var_name(name));

    Env_var* var = memory_alloc_item(Env_var);
    if (var == NULL)
        return NULL;

    strcpy(var->name, name);
    var->value.type = type;

    return var;
}
Example #5
0
static bool read_expressions_def(Streader* sr, const char* key, void* userdata)
{
    rassert(sr != NULL);
    rassert(key != NULL);
    rassert(userdata != NULL);

    Au_expressions* ae = userdata;

    if (string_eq(key, "default_note_expr"))
    {
        char expr[KQT_VAR_NAME_MAX + 1] = "";
        if (!Streader_read_string(sr, KQT_VAR_NAME_MAX + 1, expr))
            return false;

        if ((expr[0] != '\0') && !is_valid_var_name(expr))
        {
            Streader_set_error(sr, "Invalid default note expression: %s", expr);
            return false;
        }

        strcpy(ae->default_note_expr, expr);
    }
    else if (string_eq(key, "expressions"))
    {
        if (!Streader_read_dict(sr, read_expressions, ae))
        {
            rassert(Streader_is_error_set(sr));
            return false;
        }
    }
    else
    {
        Streader_set_error(sr, "Unexpected key in expression specification: %s", key);
        return false;
    }

    return true;
}
Example #6
0
static bool read_expressions(Streader* sr, const char* key, void* userdata)
{
    rassert(sr != NULL);
    rassert(key != NULL);
    rassert(userdata != NULL);

    Au_expressions* ae = userdata;

    if (!is_valid_var_name(key))
    {
        Streader_set_error(sr, "Invalid expression name: %s", key);
        return false;
    }

    Entry* entry = memory_alloc_item(Entry);
    if (entry == NULL)
        return false;

    strcpy(entry->name, key);

    Param_proc_filter* filter = new_Param_proc_filter(sr);
    if (filter == NULL)
    {
        memory_free(entry);
        return false;
    }

    entry->filter = filter;

    if (!AAtree_ins(ae->entries, entry))
    {
        del_Param_proc_filter(filter);
        memory_free(entry);
        return false;
    }

    return true;
}
Example #7
0
bool StringData::isValidVariableName() const {
  return is_valid_var_name(data(), size());
}
Example #8
0
static bool modify_extract_name(VarEnv* v,
                                String& name,
                                int64_t extract_type,
                                const String& prefix) {
  switch (extract_type) {
  case EXTR_SKIP:
    if (v->lookup(name.get()) != nullptr) {
      return false;
    }
    break;
  case EXTR_IF_EXISTS:
    if (v->lookup(name.get()) == nullptr) {
      return false;
    } else {
      goto namechecks;
    }
    break;
  case EXTR_PREFIX_SAME:
    if (v->lookup(name.get()) != nullptr) {
      name = prefix + "_" + name;
    } else {
      goto namechecks;
    }
    break;
  case EXTR_PREFIX_ALL:
    name = prefix + "_" + name;
    break;
  case EXTR_PREFIX_INVALID:
    if (!is_valid_var_name(name.get()->data(), name.size())) {
      name = prefix + "_" + name;
    } else {
      goto namechecks;
    }
    break;
  case EXTR_PREFIX_IF_EXISTS:
    if (v->lookup(name.get()) == nullptr) {
      return false;
    }
    name = prefix + "_" + name;
    break;
  case EXTR_OVERWRITE:
    namechecks:
    if (name == s_GLOBALS) {
      return false;
    }
    if (name == s_this) {
      // Only disallow $this when inside a non-static method, or a static method
      // that has defined $this (matches Zend)
      auto const func = arGetContextFunc(GetCallerFrame());

      if (func && func->isMethod() && v->lookup(s_this.get()) != nullptr) {
        return false;
      }
    }
  default:
    break;
  }

  // skip invalid variable names, as in PHP
  return is_valid_var_name(name.get()->data(), name.size());
}
Example #9
0
bool StringData::isValidVariableName() const {
  // Not involved in further string construction/mutation; no taint pickup
  StringSlice s = slice();
  return is_valid_var_name(s.ptr, s.len);
}
Example #10
0
Env_var* new_Env_var_from_string(Streader* sr)
{
    rassert(sr != NULL);

    if (Streader_is_error_set(sr))
        return NULL;

    char type_name[16] = "";
    char name[KQT_VAR_NAME_MAX] = "";

    if (!Streader_readf(
                sr,
                "[%s,%s,",
                READF_STR(16, type_name),
                READF_STR(KQT_VAR_NAME_MAX, name)))
        return NULL;

    if (!is_valid_var_name(name))
    {
        Streader_set_error(
                sr,
                "Illegal variable name %s"
                    " (Variable names may only contain"
                    " lower-case letters and underscores"
                    " (and digits as other than first characters))",
                name);
        return NULL;
    }

    Value* value = VALUE_AUTO;

    if (string_eq(type_name, "bool"))
    {
        value->type = VALUE_TYPE_BOOL;
        Streader_read_bool(sr, &value->value.bool_type);
    }
    else if (string_eq(type_name, "int"))
    {
        value->type = VALUE_TYPE_INT;
        Streader_read_int(sr, &value->value.int_type);
    }
    else if (string_eq(type_name, "float"))
    {
        value->type = VALUE_TYPE_FLOAT;
        Streader_read_float(sr, &value->value.float_type);
    }
    else if (string_eq(type_name, "timestamp"))
    {
        value->type = VALUE_TYPE_TSTAMP;
        Streader_read_tstamp(sr, &value->value.Tstamp_type);
    }
    else
    {
        Streader_set_error(
                sr,
                "Invalid type of environment variable %s: %s",
                name,
                type_name);
        return NULL;
    }

    if (!Streader_match_char(sr, ']'))
        return NULL;

    Env_var* var = new_Env_var(value->type, name);
    if (var == NULL)
    {
        Streader_set_memory_error(
                sr, "Could not allocate memory for environment variable");
        return NULL;
    }

    Env_var_set_value(var, value);

    return var;
}