Exemplo n.º 1
0
int
does_filter_use_ra (filter_t *filter)
{
    internal_t *r_internal, *a_internal;

    g_assert(filter->kind == FILTER_MATHMAP);

    r_internal = lookup_internal(filter->v.mathmap.internals, "r", 1);
    a_internal = lookup_internal(filter->v.mathmap.internals, "a", 1);
    g_assert(r_internal != NULL && a_internal != NULL);

    return r_internal->is_used || a_internal->is_used;
}
Exemplo n.º 2
0
exprtree*
make_var (scanner_ident_t *name_ident)
{
    char *name = name_ident->str;
    scanner_region_t region = name_ident->region;
    tuple_info_t info;
    exprtree *tree = 0;

    if (lookup_internal(the_mathmap->current_filter->v.mathmap.internals, name, 0) != 0)
    {
	tree = alloc_exprtree();

	tree->type = EXPR_INTERNAL;
	tree->val.internal = lookup_internal(the_mathmap->current_filter->v.mathmap.internals, name, 0);
	tree->result = make_tuple_info(nil_tag_number, 1);
	tree->region = region;
    }
    else if (lookup_variable_macro(name, &info) != 0)
    {
	macro_function_t function = lookup_variable_macro(name, &info);

	tree = function(0);
	tree->region = name_ident->region;
    }
    else if (lookup_userval(the_mathmap->current_filter->userval_infos, name) != 0)
    {
	userval_info_t *info = lookup_userval(the_mathmap->current_filter->userval_infos, name);

	tree = make_userval(info, 0, region);
    }
    else if (lookup_variable(the_mathmap->current_filter->v.mathmap.variables, name, &info) != 0)
    {
	variable_t *var = lookup_variable(the_mathmap->current_filter->v.mathmap.variables, name, &info);

	return make_var_exprtree(var, info, region);
    }
    else
    {
	sprintf(error_string, _("Undefined variable %s."), name);
	error_region = region;
	JUMP(1);
    }

    return tree;
}
Exemplo n.º 3
0
int
does_filter_use_t (filter_t *filter)
{
    internal_t *t_internal;

    g_assert(filter->kind == FILTER_MATHMAP);

    t_internal = lookup_internal(filter->v.mathmap.internals, "t", 1);
    g_assert(t_internal != NULL);

    return t_internal->is_used;
}
Exemplo n.º 4
0
void
register_args_as_uservals (filter_t *filter, arg_decl_t *arg_decls)
{
    arg_decl_t *decl;

    for (decl = arg_decls; decl != NULL; decl = decl->next)
	if (lookup_internal(filter->v.mathmap.internals, decl->name, TRUE) != NULL
	    || lookup_variable_macro(decl->name, NULL) != NULL)
	{
	    sprintf(error_string, _("Argument `%s' has the same name as an internal variable."), decl->name);
	    error_region = decl->region;
	    JUMP(1);
	}

    g_assert(filter->userval_infos == NULL && filter->num_uservals == 0);

    filter->userval_infos = arg_decls_to_uservals(filter, arg_decls);
    filter->num_uservals = count_userval_infos(filter->userval_infos);
}
Exemplo n.º 5
0
exprtree*
make_assignment (scanner_ident_t *name_ident, exprtree *value)
{
    char *name = name_ident->str;
    scanner_region_t region = name_ident->region;
    exprtree *tree = alloc_exprtree();
    variable_t *var = lookup_variable(the_mathmap->current_filter->v.mathmap.variables, name, &tree->result);

    if (var == NULL)
    {
	if (lookup_internal(the_mathmap->current_filter->v.mathmap.internals, name, TRUE) != NULL
	    || lookup_variable_macro(name, NULL) != NULL)
	{
	    sprintf(error_string, _("Cannot assign to internal variable `%s'."), name);
	    error_region = region;
	    JUMP(1);
	}
	if (lookup_userval(the_mathmap->current_filter->userval_infos, name) != NULL)
	{
	    sprintf(error_string, _("Cannot assign to filter argument `%s'."), name);
	    error_region = region;
	    JUMP(1);
	}

	var = register_variable(&the_mathmap->current_filter->v.mathmap.variables, name, value->result);
	tree->result = value->result;
    }

    if (tree->result.number != value->result.number || tree->result.length != value->result.length)
    {
	sprintf(error_string, _("Variable %s is being assigned two different types."), name);
	error_region = region;
	JUMP(1);
    }

    tree->type = EXPR_ASSIGNMENT;
    tree->val.assignment.var = var;
    tree->val.assignment.value = value;
    tree->region = region;

    return tree;
}
Exemplo n.º 6
0
GSocketConnectable *
cockpit_channel_parse_connectable (CockpitChannel *self,
                                   gchar **possible_name,
                                   gboolean *local_address)
{
  const gchar *problem = "protocol-error";
  GSocketConnectable *connectable = NULL;
  const gchar *unix_path;
  const gchar *internal;
  const gchar *address;
  JsonObject *options;
  gboolean local = FALSE;
  GError *error = NULL;
  const gchar *host;
  gint64 port;

  options = self->priv->open_options;
  if (!cockpit_json_get_string (options, "unix", NULL, &unix_path))
    {
      g_warning ("invalid \"unix\" option in channel");
      goto out;
    }
  if (!cockpit_json_get_int (options, "port", G_MAXINT64, &port))
    {
      g_warning ("invalid \"port\" option in channel");
      goto out;
    }
  if (!cockpit_json_get_string (options, "internal", NULL, &internal))
    {
      g_warning ("invalid \"internal\" option in channel");
      goto out;
    }
  if (!cockpit_json_get_string (options, "address", NULL, &address))
    {
      g_warning ("invalid \"address\" option in channel");
      goto out;
    }

  if (port != G_MAXINT64 && unix_path)
    {
      g_warning ("cannot specify both \"port\" and \"unix\" options");
      goto out;
    }
  else if (port != G_MAXINT64)
    {
      if (port <= 0 || port > 65535)
        {
          g_warning ("received invalid \"port\" option");
          goto out;
        }

      if (address)
        {
          connectable = g_network_address_new (address, port);
          host = address;

          /* This isn't perfect, but matches the use case. Specify address => non-local */
          local = FALSE;
        }
      else if (cockpit_bridge_local_address)
        {
          connectable = g_network_address_parse (cockpit_bridge_local_address, port, &error);
          host = cockpit_bridge_local_address;
          local = TRUE;
        }
      else
        {
          connectable = cockpit_loopback_new (port);
          host = "localhost";
          local = TRUE;
        }

      if (error != NULL)
        {
          g_warning ("couldn't parse local address: %s: %s", host, error->message);
          problem = "internal-error";
          goto out;
        }
      else
        {
          if (possible_name)
            *possible_name = g_strdup_printf ("%s:%d", host, (gint)port);
        }
    }
  else if (unix_path)
    {
      if (possible_name)
        *possible_name = g_strdup (unix_path);
      connectable = G_SOCKET_CONNECTABLE (g_unix_socket_address_new (unix_path));
      local = FALSE;
    }
  else if (internal)
    {
      gboolean reg = lookup_internal (internal, &connectable);

      if (!connectable)
        {
          if (!reg)
            g_warning ("couldn't find internal address: %s", internal);

          problem = "not-found";
          goto out;
        }

      if (possible_name)
        *possible_name = g_strdup (internal);
      connectable = g_object_ref (connectable);
      local = FALSE;
    }
  else
    {
      g_warning ("no \"port\" or \"unix\" or other address option for channel");
      goto out;
    }

  problem = NULL;

out:
  g_clear_error (&error);
  if (problem)
    {
      cockpit_channel_close (self, problem);
      if (connectable)
        g_object_unref (connectable);
      connectable = NULL;
    }
  else
    {
      if (local_address)
        *local_address = local;
    }
  return connectable;
}