예제 #1
0
파일: gbinding.c 프로젝트: UIKit0/glib
static void
on_source_notify (GObject    *gobject,
                  GParamSpec *pspec,
                  GBinding   *binding)
{
  const gchar *p_name;
  GValue from_value = G_VALUE_INIT;
  GValue to_value = G_VALUE_INIT;
  gboolean res;

  if (binding->is_frozen)
    return;

  p_name = g_intern_string (pspec->name);

  if (p_name != binding->source_property)
    return;

  g_value_init (&from_value, G_PARAM_SPEC_VALUE_TYPE (binding->source_pspec));
  g_value_init (&to_value, G_PARAM_SPEC_VALUE_TYPE (binding->target_pspec));

  g_object_get_property (binding->source, binding->source_pspec->name, &from_value);

  res = binding->transform_s2t (binding,
                                &from_value,
                                &to_value,
                                binding->transform_data);
  if (res)
    {
      binding->is_frozen = TRUE;

      g_param_value_validate (binding->target_pspec, &to_value);
      g_object_set_property (binding->target, binding->target_pspec->name, &to_value);

      binding->is_frozen = FALSE;
    }

  g_value_unset (&from_value);
  g_value_unset (&to_value);
}
예제 #2
0
/****************************************************************************
  Message Handler: can_do_timeout(func, timeout)
 ****************************************************************************/
int msg_can_do_timeout(Client *cli, unsigned char *arg, int argsize)
{
    unsigned char *args[2];
    parse_args(args, 2, arg, argsize);

    if (strlen((char*)args[0]) > MAX_FUNCTION_LEN) {
        g_warning("[%s] function name too long", cli->id);
        return -1;
    }

    const gchar *func = g_intern_string((char*)args[0]);
    int timeout = atol((char*)args[1]);
    // printf(">> [%s] = %.8x\n", arg, func);

    #if DEBUG
    g_debug("[%s] can_do_timeout %s %d", cli->id, func, timeout);
    #endif

    register_ability(cli, func, timeout);

    return 0;
}
예제 #3
0
/****************************************************************************
  Message Handler: can_do(func) / cant_do(func)
 ****************************************************************************/
int msg_can_do(Client *cli, unsigned char *arg, int argsize, gboolean cant)
{
    if (argsize > MAX_FUNCTION_LEN) {
        g_warning("[%s] function name too long", cli->id);
        return -1;
    }

    const gchar *func = g_intern_string((char*)arg);
    // printf(">> [%s] = %.8x\n", arg, func);

    #if DEBUG
    if (cant) g_debug("[%s] cant_do %s", cli->id, func);
    else g_debug("[%s] can_do %s", cli->id, func);
    #endif

    if (cant)
        unregister_ability(cli, func);
    else
        register_ability(cli, func, -1);

    return 0;
}
예제 #4
0
static void
plugin_loader_create_blacklist_plugin (GstPluginLoader * l,
    PendingPluginEntry * entry)
{
  GstPlugin *plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);

  plugin->filename = g_strdup (entry->filename);
  plugin->file_mtime = entry->file_mtime;
  plugin->file_size = entry->file_size;
  plugin->flags |= GST_PLUGIN_FLAG_BLACKLISTED;

  plugin->basename = g_path_get_basename (plugin->filename);
  plugin->desc.name = g_intern_string (plugin->basename);
  plugin->desc.description = "Plugin for blacklisted file";
  plugin->desc.version = "0.0.0";
  plugin->desc.license = "BLACKLIST";
  plugin->desc.source = plugin->desc.license;
  plugin->desc.package = plugin->desc.license;
  plugin->desc.origin = plugin->desc.license;

  GST_DEBUG ("Adding blacklist plugin '%s'", plugin->desc.name);
  gst_registry_add_plugin (l->registry, plugin);
}
예제 #5
0
파일: prefs.c 프로젝트: JazzGirl/metacity
const char*
meta_prefs_get_workspace_name (int i)
{
    const char *name;

    g_return_val_if_fail (i >= 0, NULL);

    if (!workspace_names ||
            g_strv_length (workspace_names) < (guint)i + 1 ||
            !*workspace_names[i])
    {
        char *generated_name = g_strdup_printf (_("Workspace %d"), i + 1);
        name = g_intern_string (generated_name);
        g_free (generated_name);
    }
    else
        name = workspace_names[i];

    meta_topic (META_DEBUG_PREFS,
                "Getting name of workspace %d: \"%s\"\n", i, name);

    return name;
}
예제 #6
0
/**
 * rest_xml_node_find:
 * @start: a #RestXmlNode
 * @tag: the name of a node
 *
 * Searches for the first child node of @start named @tag.
 *
 * Returns: the first child node, or %NULL if it doesn't exist.
 */
RestXmlNode *
rest_xml_node_find (RestXmlNode *start,
                    const gchar *tag)
{
  RestXmlNode *node;
  RestXmlNode *tmp;
  GQueue stack = G_QUEUE_INIT;
  GList *children, *l;
  const char *tag_interned;

  g_return_val_if_fail (start, NULL);
  g_return_val_if_fail (tag != NULL, NULL);
  g_return_val_if_fail (start->ref_count > 0, NULL);

  tag_interned = g_intern_string (tag);

  g_queue_push_head (&stack, start);

  while ((node = g_queue_pop_head (&stack)) != NULL)
  {
    if ((tmp = g_hash_table_lookup (node->children, tag_interned)) != NULL)
    {
      g_queue_clear (&stack);
      return tmp;
    }

    children = g_hash_table_get_values (node->children);
    for (l = children; l; l = l->next)
    {
      g_queue_push_head (&stack, l->data);
    }
    g_list_free (children);
  }

  g_queue_clear (&stack);
  return NULL;
}
예제 #7
0
static const gchar *
find_supported_credentials (UmRealmKerberosMembership *membership,
                            const gchar *owner)
{
        const gchar *cred_owner;
        const gchar *cred_type;
        GVariant *supported;
        GVariantIter iter;

        supported = um_realm_kerberos_membership_get_supported_join_credentials (membership);
        g_return_val_if_fail (supported != NULL, NULL);

        g_variant_iter_init (&iter, supported);
        while (g_variant_iter_loop (&iter, "(&s&s)", &cred_type, &cred_owner)) {
                if (g_str_equal (owner, cred_owner)) {
                        if (g_str_equal (cred_type, "ccache") ||
                            g_str_equal (cred_type, "password")) {
                                return g_intern_string (cred_type);
                        }
                }
        }

        return NULL;
}
예제 #8
0
const char *
nmp_utils_udev_get_driver (GUdevDevice *device)
{
	GUdevDevice *parent = NULL, *grandparent = NULL;
	const char *driver, *subsys;

	driver = g_udev_device_get_driver (device);
	if (driver)
		goto out;

	/* Try the parent */
	parent = g_udev_device_get_parent (device);
	if (parent) {
		driver = g_udev_device_get_driver (parent);
		if (!driver) {
			/* Try the grandparent if it's an ibmebus device or if the
			 * subsys is NULL which usually indicates some sort of
			 * platform device like a 'gadget' net interface.
			 */
			subsys = g_udev_device_get_subsystem (parent);
			if (   (g_strcmp0 (subsys, "ibmebus") == 0)
			    || (subsys == NULL)) {
				grandparent = g_udev_device_get_parent (parent);
				if (grandparent)
					driver = g_udev_device_get_driver (grandparent);
			}
		}
	}
	g_clear_object (&parent);
	g_clear_object (&grandparent);

out:
	/* Intern the string so we don't have to worry about memory
	 * management in NMPlatformLink. */
	return g_intern_string (driver);
}
예제 #9
0
static void
clutter_backend_real_init_events (ClutterBackend *backend)
{
  const char *input_backend = NULL;

  input_backend = g_getenv ("CLUTTER_INPUT_BACKEND");
  if (input_backend != NULL)
    input_backend = g_intern_string (input_backend);

#ifdef CLUTTER_INPUT_OSX
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_OSX) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_OSX)))
    {
      _clutter_backend_osx_events_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_WIN32
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WIN32) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_WIN32)))
    {
      _clutter_backend_win32_events_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_X11
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_X11)))
    {
      _clutter_backend_x11_events_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_GDK
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_GDK) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_GDK)))
    {
      _clutter_backend_gdk_events_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_EVDEV
  /* Evdev can be used regardless of the windowing system */
  if (input_backend != NULL &&
      strcmp (input_backend, CLUTTER_INPUT_EVDEV) == 0)
    {
      _clutter_events_evdev_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_TSLIB
  /* Tslib can be used regardless of the windowing system */
  if (input_backend != NULL &&
      strcmp (input_backend, CLUTTER_INPUT_TSLIB) == 0)
    {
      _clutter_events_tslib_init (backend);
    }
  else
#endif
#ifdef CLUTTER_INPUT_WAYLAND
  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WAYLAND) &&
      (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_WAYLAND)))
    {
      _clutter_events_wayland_init (backend);
    }
  else
#endif
  if (input_backend != NULL)
    {
      if (input_backend != I_(CLUTTER_INPUT_NULL))
        g_error ("Unrecognized input backend '%s'", input_backend);
    }
  else
    g_error ("Unknown input backend");
}
예제 #10
0
/**
 * gst_element_register:
 * @plugin: (allow-none): #GstPlugin to register the element with, or NULL for
 *     a static element (note that passing NULL only works in GStreamer 0.10.13
 *     and later)
 * @name: name of elements of this type
 * @rank: rank of element (higher rank means more importance when autoplugging)
 * @type: GType of element to register
 *
 * Create a new elementfactory capable of instantiating objects of the
 * @type and add the factory to @plugin.
 *
 * Returns: TRUE, if the registering succeeded, FALSE on error
 */
gboolean
gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
    GType type)
{
  GstPluginFeature *existing_feature;
  GstRegistry *registry;
  GstElementFactory *factory;
  GType *interfaces;
  guint n_interfaces, i;
  GstElementClass *klass;
  GList *item;

  g_return_val_if_fail (name != NULL, FALSE);
  g_return_val_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT), FALSE);

  registry = gst_registry_get_default ();

  /* check if feature already exists, if it exists there is no need to update it
   * when the registry is getting updated, outdated plugins and all their
   * features are removed and readded.
   */
  existing_feature = gst_registry_lookup_feature (registry, name);
  if (existing_feature) {
    GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)",
        existing_feature, name);
    factory = GST_ELEMENT_FACTORY_CAST (existing_feature);
    factory->type = type;
    existing_feature->loaded = TRUE;
    g_type_set_qdata (type, _gst_elementclass_factory, factory);
    gst_object_unref (existing_feature);
    return TRUE;
  }

  factory =
      GST_ELEMENT_FACTORY_CAST (g_object_newv (GST_TYPE_ELEMENT_FACTORY, 0,
          NULL));
  gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
  GST_LOG_OBJECT (factory, "Created new elementfactory for type %s",
      g_type_name (type));

  /* provide info needed during class structure setup */
  g_type_set_qdata (type, _gst_elementclass_factory, factory);
  klass = GST_ELEMENT_CLASS (g_type_class_ref (type));
  if ((klass->details.longname == NULL) ||
      (klass->details.klass == NULL) || (klass->details.author == NULL))
    goto detailserror;

  factory->type = type;
  __gst_element_details_copy (&factory->details, &klass->details);
  if (klass->meta_data) {
    factory->meta_data = gst_structure_copy ((GstStructure *) klass->meta_data);
  } else {
    factory->meta_data = NULL;
  }
  for (item = klass->padtemplates; item; item = item->next) {
    GstPadTemplate *templ = item->data;
    GstStaticPadTemplate *newt;
    gchar *caps_string = gst_caps_to_string (templ->caps);

    newt = g_slice_new (GstStaticPadTemplate);
    newt->name_template = g_intern_string (templ->name_template);
    newt->direction = templ->direction;
    newt->presence = templ->presence;
    newt->static_caps.caps.refcount = 0;
    newt->static_caps.string = g_intern_string (caps_string);
    factory->staticpadtemplates =
        g_list_append (factory->staticpadtemplates, newt);

    g_free (caps_string);
  }
  factory->numpadtemplates = klass->numpadtemplates;

  /* special stuff for URI handling */
  if (g_type_is_a (type, GST_TYPE_URI_HANDLER)) {
    GstURIHandlerInterface *iface = (GstURIHandlerInterface *)
        g_type_interface_peek (klass, GST_TYPE_URI_HANDLER);

    if (!iface || (!iface->get_type && !iface->get_type_full) ||
        (!iface->get_protocols && !iface->get_protocols_full))
      goto urierror;
    if (iface->get_type)
      factory->uri_type = iface->get_type ();
    else if (iface->get_type_full)
      factory->uri_type = iface->get_type_full (factory->type);
    if (!GST_URI_TYPE_IS_VALID (factory->uri_type))
      goto urierror;
    if (iface->get_protocols)
      factory->uri_protocols = g_strdupv (iface->get_protocols ());
    else if (iface->get_protocols_full)
      factory->uri_protocols = iface->get_protocols_full (factory->type);
    if (!factory->uri_protocols)
      goto urierror;
  }

  interfaces = g_type_interfaces (type, &n_interfaces);
  for (i = 0; i < n_interfaces; i++) {
    __gst_element_factory_add_interface (factory, g_type_name (interfaces[i]));
  }
  g_free (interfaces);

  if (plugin && plugin->desc.name) {
    GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name;
    GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
    g_object_add_weak_pointer ((GObject *) plugin,
        (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
  } else {
    GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
    GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
  }
  gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
  GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;

  gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory));

  return TRUE;

  /* ERRORS */
urierror:
  {
    GST_WARNING_OBJECT (factory, "error with uri handler!");
    gst_element_factory_cleanup (factory);
    return FALSE;
  }

detailserror:
  {
    GST_WARNING_OBJECT (factory,
        "The GstElementDetails don't seem to have been set properly");
    gst_element_factory_cleanup (factory);
    return FALSE;
  }
}
예제 #11
0
/**
 * fm_deep_count_job_set_dest
 * @dc: a job to set the destination
 * @dev: UNIX device ID
 * @fs_id: (allow-none): filesystem id in gio format
 *
 * Sets destination for the job @dc that will be used when the job is
 * ran with any of flags FM_DC_JOB_SAME_FS or FM_DC_JOB_PREPARE_MOVE.
 * If @dev is 0 (and @fs_id is NULL) then destination device is non on
 * native filesystem.
 *
 * Since: 0.1.0
 */
void fm_deep_count_job_set_dest(FmDeepCountJob* dc, dev_t dev, const char* fs_id)
{
    dc->dest_dev = dev;
    if(fs_id)
        dc->dest_fs_id = g_intern_string(fs_id);
}
static void
parse_text (GMarkupParseContext * ctx, const gchar * text, gsize text_len,
    gpointer user_data, GError ** err)
{
  License *license = user_data;
  const gchar *element_name, *found;
  int i;

  element_name = g_markup_parse_context_get_element (ctx);
  for (i = 0; i < G_N_ELEMENTS (tag_map); ++i) {
    if (strcmp (element_name, tag_map[i].element_name) == 0)
      break;
  }

  if (i == G_N_ELEMENTS (tag_map))
    g_error ("Unexpected tag '%s'\n", element_name);

  switch (tag_map[i].element_tag) {
    case TAG_CC_LICENSE:
    case TAG_CC_JURISDICTION:
    case TAG_CC_LEGALCODE:
    case TAG_DC_CREATOR:
    case TAG_CC_PROHIBITS:
    case TAG_CC_REQUIRES:
    case TAG_CC_PERMITS:
    case TAG_RDF_RDF:
    case TAG_RDF_DESCRIPTION:
      break;
    case TAG_DC_TITLE:
      if (license->titles == NULL) {
        license->titles = g_hash_table_new (g_str_hash, g_str_equal);
      }
      g_hash_table_insert (license->titles, (gpointer) license->cur_lang,
          (gpointer) g_intern_string (text));
      break;
    case TAG_DC_DESCRIPTION:{
      gchar *txt = g_strdup (text);

      if (license->descriptions == NULL) {
        license->descriptions = g_hash_table_new (g_str_hash, g_str_equal);
      }
      g_strdelimit (txt, "\n", ' ');
      g_hash_table_insert (license->descriptions, (gpointer) license->cur_lang,
          (gpointer) g_intern_string (txt));
      g_free (txt);
      break;
    }
    case TAG_DCQ_HAS_VERSION:
      /* we assume one version per license */
      g_assert (license->version == NULL);
      license->version = g_strdup (text);
      found = strstr (known_versions, license->version);
      if (found == NULL || found[strlen (license->version)] != '/')
        g_error ("Unexpected version '%s', please add to table.", text);
      break;
    case TAG_CC_DEPRECATED_ON:
      license->deprecated = TRUE;
      break;
    case TAG_DC_SOURCE:        // FIXME
    default:
      g_print ("text (%s) (%s): '%s'\n", element_name, license->cur_lang, text);
  }
}
예제 #13
0
void
dax_dom_element_setAttributeNS (DaxDomElement  *self,
                                const gchar    *namespace_uri,
                                const gchar    *qualified_name,
                                const gchar    *value,
                                GError        **err)
{
    const gchar *local_name, *interned_ns;
    guint prefix_len = 0;

    interned_ns = g_intern_string (namespace_uri);

    /* search of a ASCII char in a UTF-8 string */
    local_name = strchr (qualified_name, ':');
    if (local_name) {
        gssize max = local_name - qualified_name;
        prefix_len = g_utf8_strlen (qualified_name, max);
    }

    /* the qualifiedName has a prefix and the namespaceURI is null */
    if (G_UNLIKELY (local_name != NULL && namespace_uri == NULL)) {
        g_warning ("NAMESPACE_ERR1");
        /* FIXME: raise NAMESPACE_ERR */
        return;
    }

    /* the qualifiedName has a prefix that is "xml" and the namespaceURI is
     * different from "http://www.w3.org/XML/1998/namespace" */
    if (G_UNLIKELY (local_name && strncmp (qualified_name, "xml:", 4) == 0 &&
                    interned_ns != xml_ns ))
    {
        g_warning ("NAMESPACE_ERR2");
        /* FIXME: raise NAMESPACE_ERR */
        return;
    }

    /* the qualifiedName or its prefix is "xmlns" and the namespaceURI is
     * different from "http://www.w3.org/2000/xmlns/" */
    if (G_UNLIKELY (interned_ns != xmlns_ns &&
                    ((local_name &&
                      strncmp (qualified_name, "xmlns:", 6) == 0) ||
                     strcmp (qualified_name, "xmlns") == 0)))
    {
        g_warning ("NAMESPACE_ERR3");
        /* FIXME: raise NAMESPACE_ERR */
        return;
    }

    /* the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the
     * qualifiedName nor its prefix is "xmlns" */
    if (G_UNLIKELY (interned_ns == xmlns_ns &&
                    (local_name &&
                      strncmp (qualified_name, "xmlns:", 6) != 0) &&
                     strcmp (qualified_name, "xmlns") == 0))
    {
        g_warning ("NAMESPACE_ERR4");
        /* FIXME: raise NAMESPACE_ERR */
        return;
    }

    if (interned_ns == NULL) {
        dax_dom_element_set_attribute (self, qualified_name, value, err);
        return;
    }

    if (interned_ns == DAX_DOM_NODE (self)->namespace_uri) {
        if (local_name == NULL)
            dax_dom_element_set_attribute (self, qualified_name, value, err);
        else
            dax_dom_element_set_attribute (self, local_name, value, err);
        return;
    }

    /* handle the rest, xmlns attributes, ev:event, ... */
    dax_dom_element_set_attribute_foreign (self,
                                           interned_ns,
                                           qualified_name,
                                           value,
                                           err);
}
예제 #14
0
파일: pinpoint.c 프로젝트: bpeel/pinpoint
void
pp_parse_slides (PinPointRenderer *renderer,
                 const char       *slide_src)
{
    const char *p;
    int         slideno     = 0;
    gboolean    done        = FALSE;
    gboolean    startofline = TRUE;
    gboolean    gotconfig   = FALSE;
    GString    *slide_str   = g_string_new ("");
    GString    *setting_str = g_string_new ("");
    GString    *notes_str   = g_string_new ("");
    GList      *s;
    PinPointPoint *point, *next_point;

    if (renderer->source)
    {
        gboolean start_of_line = TRUE;
        int pos;
        int lineno=0;
        /* compute slide no that has changed */
        for (pos = 0, slideno = 0;
                slide_src[pos] &&
                renderer->source[pos] &&
                slide_src[pos]==renderer->source[pos]
                ; pos ++)
        {
            switch (slide_src[pos])
            {
            case '\n':
                start_of_line = TRUE;
                lineno++;
                break;
            case '-':
                if (start_of_line)
                    slideno++;
            default:
                start_of_line = FALSE;
            }
        }
        slideno-=1;
        g_free (renderer->source);
    }
    renderer->source = g_strdup (slide_src);

    for (s = pp_slides; s; s = s->next)
        pin_point_free (renderer, s->data);

    g_list_free (pp_slides);
    pp_slides = NULL;
    point = pin_point_new (renderer);

    /* parse the slides, constructing lists of slide/point objects
     */
    for (p = slide_src; *p; p++)
    {
        switch (*p)
        {
        case '\\': /* escape the next char */
            p++;
            startofline = FALSE;
            if (*p)
                g_string_append_c (slide_str, *p);
            break;
        case '\n':
            startofline = TRUE;
            g_string_append_c (slide_str, *p);
            break;
        case '-': /* slide seperator */
close_last_slide:
            if (startofline)
            {
                next_point = pin_point_new (renderer);

                g_string_assign (setting_str, "");
                while (*p && *p!='\n')  /* until newline */
                {
                    g_string_append_c (setting_str, *p);
                    p++;
                }
                parse_config (next_point, setting_str->str);

                if (!gotconfig)
                {
                    parse_config (&default_point, slide_str->str);
                    /* copy the default point except the per-slide allocated
                     * data (void *) */
                    memcpy (point, &default_point,
                            sizeof (PinPointPoint) - sizeof (void *));
                    parse_config (point, setting_str->str);
                    gotconfig = TRUE;
                    g_string_assign (slide_str, "");
                    g_string_assign (setting_str, "");
                    g_string_assign (notes_str, "");
                }
                else
                {
                    if (point->bg && point->bg[0])
                    {
                        char *filename = g_strdup (point->bg);
                        int i = 0;

                        while (filename[i])
                        {
                            filename[i] = tolower(filename[i]);
                            i++;
                        }

                        if (strcmp (filename, "camera") == 0)
                            point->bg_type = PP_BG_CAMERA;
                        else if (str_has_video_suffix (filename))
                            point->bg_type = PP_BG_VIDEO;
                        else if (g_str_has_suffix (filename, ".svg"))
                            point->bg_type = PP_BG_SVG;
                        else if (pp_is_color (point->bg))
                            point->bg_type = PP_BG_COLOR;
                        else
                            point->bg_type = PP_BG_IMAGE;
                        g_free (filename);
                    }

                    {
                        char *str = slide_str->str;

                        /* trim newlines from start and end. ' ' can be used in the
                         * insane case that you actually want blank lines before or
                         * after the text of a slide */
                        while (*str == '\n') str++;
                        while ( slide_str->str[strlen(slide_str->str)-1]=='\n')
                            slide_str->str[strlen(slide_str->str)-1]='\0';

                        point->text = g_intern_string (str);
                    }
                    if (notes_str->str[0])
                        point->speaker_notes = g_strdup (notes_str->str);

                    renderer->make_point (renderer, point);

                    g_string_assign (slide_str, "");
                    g_string_assign (setting_str, "");
                    g_string_assign (notes_str, "");

                    pp_slides = g_list_append (pp_slides, point);
                    point = next_point;
                }
            }
            else
            {
                g_string_append_c (slide_str, *p);
            }
            break;
        case '#': /* comment */
            if (startofline)
            {
                const char *end = p + 1;
                while (*end != '\n' && *end != '\0')
                {
                    g_string_append_c (notes_str, *end);
                    end++;
                }
                if (end)
                {
                    g_string_append_c (notes_str, '\n');
                    p = end;
                    break;
                }
            }
        /* flow through */
        default:
            startofline = FALSE;
            g_string_append_c (slide_str, *p);
            break;
        }
    }

    if (!done)
    {
        done = TRUE;
        goto close_last_slide;
    }

    g_string_free (slide_str, TRUE);
    g_string_free (setting_str, TRUE);
    g_string_free (notes_str, TRUE);

    if (g_list_nth (pp_slides, slideno))
        pp_slidep = g_list_nth (pp_slides, slideno);
    else
        pp_slidep = pp_slides;
}
예제 #15
0
파일: pinpoint.c 프로젝트: bpeel/pinpoint
static void
parse_setting (PinPointPoint *point,
               const char    *setting)
{
    /* C Preprocessor macros implemeting a mini language for interpreting
     * pinpoint key=value pairs
     */

#define START_PARSER if (0) {
#define DEFAULT      } else {
#define END_PARSER   }
#define IF_PREFIX(prefix) } else if (g_str_has_prefix (setting, prefix)) {
#define IF_EQUAL(string) } else if (g_str_equal (setting, string)) {
#define STRING  g_intern_string (strchr (setting, '=') + 1)
#define INT     atoi (strchr (setting, '=') + 1)
#define FLOAT   g_ascii_strtod (strchr (setting, '=') + 1, NULL)
#define RESOLUTION(r) parse_resolution (&r, strchr (setting, '=') + 1)
#define ENUM(r,t,s) \
  do { \
      int _i; \
      EnumDescription *_d = t##_desc; \
      r = _d[0].value; \
      for (_i = 0; _d[_i].name; _i++) \
        if (g_strcmp0 (_d[_i].name, s) == 0) \
          r = _d[_i].value; \
  } while (0)

    START_PARSER
    IF_PREFIX("stage-color=") point->stage_color = STRING;
    IF_PREFIX("font=")        point->font = STRING;
    IF_PREFIX("text-color=")  point->text_color = STRING;
    IF_PREFIX("text-align=")  ENUM(point->text_align, PPTextAlign, STRING);
    IF_PREFIX("shading-color=") point->shading_color = STRING;
    IF_PREFIX("shading-opacity=") point->shading_opacity = FLOAT;
    IF_PREFIX("duration=")   point->duration = FLOAT;
    IF_PREFIX("command=")    point->command = STRING;
    IF_PREFIX("transition=") point->transition = STRING;
    IF_PREFIX("camera-framerate=")  point->camera_framerate = INT;
    IF_PREFIX("camera-resolution=") RESOLUTION (point->camera_resolution);
    IF_EQUAL("fill")         point->bg_scale = PP_BG_FILL;
    IF_EQUAL("fit")          point->bg_scale = PP_BG_FIT;
    IF_EQUAL("stretch")      point->bg_scale = PP_BG_STRETCH;
    IF_EQUAL("unscaled")     point->bg_scale = PP_BG_UNSCALED;
    IF_EQUAL("center")       point->position = CLUTTER_GRAVITY_CENTER;
    IF_EQUAL("top")          point->position = CLUTTER_GRAVITY_NORTH;
    IF_EQUAL("bottom")       point->position = CLUTTER_GRAVITY_SOUTH;
    IF_EQUAL("left")         point->position = CLUTTER_GRAVITY_WEST;
    IF_EQUAL("right")        point->position = CLUTTER_GRAVITY_EAST;
    IF_EQUAL("top-left")     point->position = CLUTTER_GRAVITY_NORTH_WEST;
    IF_EQUAL("top-right")    point->position = CLUTTER_GRAVITY_NORTH_EAST;
    IF_EQUAL("bottom-left")  point->position = CLUTTER_GRAVITY_SOUTH_WEST;
    IF_EQUAL("bottom-right") point->position = CLUTTER_GRAVITY_SOUTH_EAST;
    IF_EQUAL("no-markup")    point->use_markup = FALSE;
    IF_EQUAL("markup")       point->use_markup = TRUE;
    DEFAULT                  point->bg = g_intern_string (setting);
    END_PARSER

    /* undefine the overrides, returning us to regular C */
#undef START_PARSER
#undef END_PARSER
#undef DEFAULT
#undef IF_PREFIX
#undef IF_EQUAL
#undef FLOAT
#undef STRING
#undef INT
#undef ENUM
#undef RESOLUTION
}
예제 #16
0
/****************************************************************************
  Message Handler: submit_job_*(func, uniq, arg)
 ****************************************************************************/
int msg_submit_job(Client *cli, unsigned char *arg, int argsize, gboolean background, gboolean high)
{
    unsigned char *args[3];
    int last_arg_len = parse_args(args, 3, arg, argsize);

    int is_uniq = args[1][0] != 0;

    const gchar *func = g_intern_string((char*)args[0]);
    // printf(">> [%s] = %.8x\n", args[0], func);

    /* look for a duplicate job - if one exists, add to listeners */
    if (is_uniq) {
        UniqJobKey uk;
        uk.func = func;
        if (args[1][0] == '-' && args[1][1] == 0) {
            uk.uniq = args[2];
            uk.uniq_len = last_arg_len;
        } else {
            uk.uniq = args[1];
            uk.uniq_len = strlen((char*)args[1]);
        }
        Job *job = g_hash_table_lookup(g_uniq_jobs, &uk);
        if (job) {
            #if DEBUG
            g_debug("[%s] submit_job - merging %s:%s -> %s", cli->id, job->func, job->uniq, job->handle);
            #endif
            if (!job->background) {
                g_ptr_array_add_uniq(job->listeners, cli);
                client_listen_to(cli, job);
            }
            MemBlock *block = new_response(MSG_JOB_CREATED, strlen(job->handle), (unsigned char *)job->handle);
            client_send(cli, block);
            return 0;
        }
    }

    Job *job = job_new();
    generate_job_handle(job->handle);
    job->func = func;
    if (last_arg_len == 0)
        job->arg = (unsigned char *)"";
    else {
        job->arg = malloc(last_arg_len);
        memcpy(job->arg, args[2], last_arg_len);
    }
    job->arg_len = last_arg_len;
    job->background = background;
    if (!background) {
        g_ptr_array_add(job->listeners, cli);
    }
    g_hash_table_insert(g_jobs, job->handle, job);

    #if DEBUG
    g_debug("[%s] submit_job: %s, %s -> %s", cli->id, args[0], args[1], job->handle);
    #endif

    jobqueue_push(g_jobqueue, job, high);
    if (!background) {
        client_listen_to(cli, job);
    }

    job->is_uniq = is_uniq;
    if (is_uniq) {
        job->uniq = strdup((char*)args[1]);
        job->uniq_key.func = func;
        if (job->uniq[0] == '-' && job->uniq[1] == 0) {
            job->uniq_key.uniq = job->arg;
            job->uniq_key.uniq_len = job->arg_len;
        } else {
            job->uniq_key.uniq = (unsigned char *)job->uniq;
            job->uniq_key.uniq_len = strlen(job->uniq);
        }
        g_hash_table_insert(g_uniq_jobs, &job->uniq_key, job);
        #if DEBUG
        g_debug("[%s] \tadded uniq job %s", cli->id, job->handle);
        #endif
    }

    MemBlock *block = new_response(MSG_JOB_CREATED, strlen(job->handle), (unsigned char *)job->handle);
    client_send(cli, block);
    wake_up_sleepers(job->func);

    return 0;
}
예제 #17
0
static gboolean
ovirt_collection_refresh_from_xml(OvirtCollection *collection,
                                  RestXmlNode *root_node,
                                  GError **error)
{
    RestXmlNode *resources_node;
    RestXmlNode *node;
    GHashTable *resources;
    const char *resource_key;

    g_return_val_if_fail(OVIRT_IS_COLLECTION(collection), FALSE);
    g_return_val_if_fail(root_node != NULL, FALSE);
    g_return_val_if_fail((error == NULL) || (*error == NULL), FALSE);

    if (strcmp(root_node->name, collection->priv->collection_xml_name) != 0) {
        g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_PARSING_FAILED,
                    _("Got '%s' node, expected '%s'"), root_node->name,
                    collection->priv->collection_xml_name);
        return FALSE;
    }

    resource_key = g_intern_string(collection->priv->resource_xml_name);
    resources = g_hash_table_new_full(g_str_hash, g_str_equal,
                                      g_free, (GDestroyNotify)g_object_unref);
    resources_node = g_hash_table_lookup(root_node->children, resource_key);
    for (node = resources_node; node != NULL; node = node->next) {
        OvirtResource *resource;
        gchar *name;

        resource = ovirt_collection_new_resource_from_xml(collection, node, error);
        if (resource == NULL) {
            if ((error != NULL) && (*error != NULL)) {
                g_message("Failed to parse '%s' node: %s",
                          collection->priv->resource_xml_name, (*error)->message);
            } else {
                g_message("Failed to parse '%s' node",
                          collection->priv->resource_xml_name);
            }
            g_clear_error(error);
            continue;
        }
        g_object_get(G_OBJECT(resource), "name", &name, NULL);
        if (name == NULL) {
            g_message("'%s' resource had no name in its XML description",
                      collection->priv->resource_xml_name);
            g_object_unref(G_OBJECT(resource));
            continue;
        }
        if (g_hash_table_lookup(resources, name) != NULL) {
            g_message("'%s' resource with the same name ('%s') already exists",
                      collection->priv->resource_xml_name, name);
            g_object_unref(G_OBJECT(resource));
            g_free(name);
            continue;
        }
        g_hash_table_insert(resources, name, resource);
    }

    ovirt_collection_set_resources(OVIRT_COLLECTION(collection), resources);
    g_hash_table_unref(resources);

    return TRUE;
}
예제 #18
0
int req_parser_add_text(req_parser *r, const char *data, size_t len)
{
	const char *end;
	if (!g_utf8_validate(data, len, &end))
	{
		return REQ_PARSER_PARSE_INVALID_REQUEST;
	}

	int result = REQ_PARSER_PARSE_PARTIAL_REQUEST;

	int mode = (r->method == REQ_PARSER_METHOD_INVALID) ? MODE_REQUEST_LINE : MODE_HEADER_LINE;
	const gchar *headerQuark = NULL;

	char buf[HEADER_BUF_SIZE];
	const char *token_start = data;
	const char *i;
	for (i = data; (i < end) && *i; i = g_utf8_next_char(i))
	{
		result = REQ_PARSER_PARSE_PARTIAL_REQUEST;
		gunichar c = g_utf8_get_char(i);

		if (c == '\r')
		{
			i = g_utf8_next_char(i);
			c = g_utf8_get_char(i);
		}
		if ((c == '\n') && (*g_utf8_prev_char(i) != '\r'))
		{
			fprintf(stderr, "ERROR - Encountered a newline without a preceding carriage return.\n");
			req_parser_reset(r);
			return REQ_PARSER_PARSE_INVALID_REQUEST;
		}

		switch (mode)
		{
		case MODE_REQUEST_LINE:
			if (c == ' ')
			{
				if (r->method == REQ_PARSER_METHOD_INVALID)
				{
					if (strncmp("GET", token_start, 3) == 0) r->method = REQ_PARSER_METHOD_GET;
					else if (strncmp("HEAD", token_start, 4) == 0) r->method = REQ_PARSER_METHOD_HEAD;
					else if (strncmp("POST", token_start, 4) == 0) r->method = REQ_PARSER_METHOD_POST;
					else if (strncmp("OPTIONS", token_start, 7) == 0) r->method = REQ_PARSER_METHOD_OPTIONS;
					else
					{
						fprintf(stderr, "ERROR - Unknown method\n");
						req_parser_reset(r);
						return REQ_PARSER_PARSE_INVALID_REQUEST;
					}

					// skip over the separating space
					i = g_utf8_next_char(i);
					token_start = i;
				}
				else if (r->path == NULL)
				{
					parse_uri(r, token_start, (i - token_start));

					// skip over the separating space
					i = g_utf8_next_char(i);
					token_start = i;
				}
				else
				{
					fprintf(stderr, "ERROR - Too many spaces in request line\n");
					req_parser_reset(r);
					return REQ_PARSER_PARSE_INVALID_REQUEST;
				}
			}
			else if (c == '\n')
			{
				if (strncmp("HTTP/1.1", token_start, min(8, i - token_start)) != 0)
				{
					fprintf(stderr, "ERROR - Unsupported HTTP version\n");
					req_parser_reset(r);
					return REQ_PARSER_PARSE_INVALID_REQUEST;
				}
				token_start = NULL;
				mode = MODE_HEADER_LINE;
			}
			break;

		case MODE_HEADER_LINE:
			if (token_start == NULL)
			{
				token_start = i;
			}

			if ((token_start == i) && (c == '\n'))
			{
				result = REQ_PARSER_PARSE_OK;
				mode = MODE_REQUEST_BODY;
			}
			else if ((headerQuark == NULL) && (c == ':'))
			{
				memset(buf, 0, HEADER_BUF_SIZE);
				memcpy(buf, token_start, min((i - token_start), HEADER_BUF_SIZE - 1));
				headerQuark = g_intern_string(buf);
				token_start = NULL;

				// skip over the separating space
				i = g_utf8_next_char(i);
			}
			else if (c == '\n')
			{
				if (!r->headers)
				{
					r->headers = g_tree_new_full(quarkcmp, NULL, NULL, gstring_destroy_notify);
				}

				// Subtract one since we don't want the "\r" in the header
				g_tree_insert(r->headers, (gpointer)headerQuark, g_string_new_len(token_start, (i - token_start) - 1));
				token_start = NULL;
				headerQuark = NULL;
			}
			break;

		case MODE_REQUEST_BODY:
			if (r->body == NULL)
			{
				token_start = i;

				if (!r->headers)
				{
					r->headers = g_tree_new_full(quarkcmp, NULL, NULL, gstring_destroy_notify);
				}

				GString *length_header = g_tree_lookup(r->headers, g_intern_static_string("Content-Length"));
				if (length_header)
				{
					int length = atoi(length_header->str);
					size_t bytes_remaining = len - (data - i);

					if (bytes_remaining < (size_t)length)
					{
						fprintf(stderr, "ERROR - Body incomplete.\n");
						req_parser_reset(r);
						return REQ_PARSER_PARSE_INVALID_REQUEST;
					}

					r->body = g_string_new_len(i, length);
					i = i + length;
				}
				else
				{
					size_t length = len - (data - i);
					r->body = g_string_new_len(i, length);
					i = i + length;
				}
				result = REQ_PARSER_PARSE_OK;
			}
			else if (c == '\n')
			{
				result = REQ_PARSER_PARSE_OK;
			}
			break;
		}
	}

	r->status = result;
	return result;
}
예제 #19
0
파일: fm-dnd-dest.c 프로젝트: engla/libfm
gboolean fm_dnd_dest_drag_data_received(FmDndDest* dd, GdkDragContext *drag_context,
             gint x, gint y, GtkSelectionData *sel_data, guint info, guint time)
{
    FmList* files = NULL;
    GtkWidget *dest_widget = dd->widget;

    if(info ==  FM_DND_DEST_TARGET_FM_LIST)
    {
        if((sel_data->length >= 0) && (sel_data->format==8))
        {
            /* get the pointer */
            memcpy(&files, sel_data->data, sel_data->length);
            if(files)
                fm_list_ref(files);
            if(files)
            {
                FmFileInfo* fi = FM_FILE_INFO(fm_list_peek_head(files));
                /* get the device of the first dragged source file */
                if(fm_path_is_native(fi->path))
                    dd->src_dev = fi->dev;
                else
                    dd->src_fs_id = fi->fs_id;
            }
        }
    }
    else if(info == FM_DND_DEST_TARGET_URI_LIST)
    {
        if((sel_data->length >= 0) && (sel_data->format==8))
        {
            gchar **uris;
            uris = gtk_selection_data_get_uris( sel_data );
            files = fm_path_list_new_from_uris((const char **)uris);
            g_free(uris);
            if(files)
            {
                GFileInfo* inf;
                FmPath* path = FM_PATH(fm_list_peek_head(files));
                GFile* gf = fm_path_to_gfile(path);
                const char* attr = fm_path_is_native(path) ? G_FILE_ATTRIBUTE_UNIX_DEVICE : G_FILE_ATTRIBUTE_ID_FILESYSTEM;
                inf = g_file_query_info(gf, attr, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);
                g_object_unref(gf);

                if(fm_path_is_native(path))
                    dd->src_dev = g_file_info_get_attribute_uint32(inf, G_FILE_ATTRIBUTE_UNIX_DEVICE);
                else
                    dd->src_fs_id = g_intern_string(g_file_info_get_attribute_string(inf, G_FILE_ATTRIBUTE_ID_FILESYSTEM));
                g_object_unref(inf);
            }
        }
    }
    else if(info == FM_DND_DEST_TARGET_XDS) /* X direct save */
    {
        if( sel_data->format == 8 && sel_data->length == 1 && sel_data->data[0] == 'F')
        {
            gdk_property_change(GDK_DRAWABLE(drag_context->source_window),
                               xds_target_atom,
                               gdk_atom_intern_static_string("text/plain"), 8,
                               GDK_PROP_MODE_REPLACE, (const guchar *)"", 0);
        }
        else if(sel_data->format == 8 && sel_data->length == 1 && sel_data->data[0] == 'S')
        {
            /* XDS succeeds */
        }
        gtk_drag_finish(drag_context, TRUE, FALSE, time);
        return TRUE;
    }
    else
        return FALSE;

    /* remove previously cached source files. */
    if(G_UNLIKELY(dd->src_files))
    {
        fm_list_unref(dd->src_files);
        dd->src_files = NULL;
    }
    dd->src_files = files;
    dd->waiting_data = FALSE;
    dd->info_type = info;
    return TRUE;
}
예제 #20
0
gboolean load_config(const gchar *filename, RaucConfig **config, GError **error) {
	GError *ierror = NULL;
	RaucConfig *c = g_new0(RaucConfig, 1);
	gboolean res = FALSE;
	GKeyFile *key_file = NULL;
	gchar **groups;
	gsize group_count;
	GList *slotlist = NULL;
	GHashTable *slots = NULL;
	GList *l;

	key_file = g_key_file_new();

	res = g_key_file_load_from_file(key_file, filename, G_KEY_FILE_NONE, &ierror);
	if (!res) {
		g_propagate_error(error, ierror);
		goto free;
	}

	/* parse [system] section */
	c->system_compatible = g_key_file_get_string(key_file, "system", "compatible", &ierror);
	if (!c->system_compatible) {
		g_propagate_error(error, ierror);
		goto free;
	}
	c->system_bootloader = g_key_file_get_string(key_file, "system", "bootloader", NULL);

	c->mount_prefix = g_key_file_get_string(key_file, "system", "mountprefix", NULL);
	if (!c->mount_prefix) {
		g_debug("No mount prefix provided, using /mnt/rauc/ as default");
		c->mount_prefix = g_strdup("/mnt/rauc/");
	}

	if (g_strcmp0(c->system_bootloader, "grub") == 0) {
		c->grubenv_path = resolve_path(filename,
			g_key_file_get_string(key_file, "system", "grubenv", NULL));
		if (!c->grubenv_path) {
			g_debug("No grubenv path provided, using /boot/grub/grubenv as default");
			c->grubenv_path = g_strdup("/boot/grub/grubenv");
		}
	}

	/* parse [keyring] section */
	c->keyring_path = resolve_path(filename,
		g_key_file_get_string(key_file, "keyring", "path", NULL));

	/* parse [slot.*.#] sections */
	slots = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free_slot);

	groups = g_key_file_get_groups(key_file, &group_count);
	for (gsize i = 0; i < group_count; i++) {
		RaucSlot *slot = g_new0(RaucSlot, 1);
		gchar **groupsplit;

		groupsplit = g_strsplit(groups[i], ".", -1);

		/* We treat sections starting with "slot." as slots */
		if (g_str_equal(groupsplit[0], RAUC_SLOT_PREFIX)) {
			gchar* value;

			/* Assure slot strings consist of 3 parts, delimited by dots */
			if (g_strv_length(groupsplit) != 3) {
				g_set_error(
						error,
						R_CONFIG_ERROR,
						R_CONFIG_ERROR_INVALID_FORMAT,
						"Invalid slot name format");
				res = FALSE;
				goto free;
			}

			value = g_strconcat(groupsplit[1], ".", groupsplit[2], NULL);
			if (!value) {
				g_set_error(
						error,
						R_CONFIG_ERROR,
						R_CONFIG_ERROR_INVALID_FORMAT,
						"Invalid slot name");
				res = FALSE;
				goto free;
			}
			slot->name = g_intern_string(value);
			g_free(value);

			slot->sclass = g_intern_string(groupsplit[1]);

			value = resolve_path(filename,
				g_key_file_get_string(key_file, groups[i], "device", &ierror));
			if (!value) {
				g_propagate_error(error, ierror);
				res = FALSE;
				goto free;
			}
			slot->device = value;

			value = g_key_file_get_string(key_file, groups[i], "type", NULL);
			if (!value)
				value = g_strdup("raw");
			slot->type = value;

			value = g_key_file_get_string(key_file, groups[i], "bootname", NULL);
			if (!value)
				value = g_strdup(slot->name);
			slot->bootname = value;

			slot->readonly = g_key_file_get_boolean(key_file, groups[i], "readonly", NULL);

			g_hash_table_insert(slots, (gchar*)slot->name, slot);

		}
		g_strfreev(groupsplit);
	}

	/* Add parent pointers */
	slotlist = g_hash_table_get_keys(slots);
	for (l = slotlist; l != NULL; l = l->next) {
		RaucSlot *s;
		gchar* group_name;
		gchar* value;

		group_name = g_strconcat(RAUC_SLOT_PREFIX ".", l->data, NULL);
		value = g_key_file_get_string(key_file, group_name, "parent", NULL);
		g_free(group_name);
		if (!value)
			continue;

		s = g_hash_table_lookup(slots, value);
		if (!s) {
			g_print("Parent %s not found!\n", value);
			continue;
		}

		((RaucSlot*)g_hash_table_lookup(slots, l->data))->parent = s;

	}
	g_list_free(slotlist);

	c->slots = slots;

	g_strfreev(groups);

	res = TRUE;
free:
	if (!res) {
		free_config(c);
		c = NULL;
	}
	g_key_file_free(key_file);
	*config = c;
	return res;
}
예제 #21
0
static gboolean
gtk_css_matcher_node_has_id (const GtkCssMatcher *matcher,
                             const char          *id)
{
  return gtk_css_node_get_id (matcher->node.node) == g_intern_string (id);
}
예제 #22
0
파일: config_file.c 프로젝트: ukleinek/rauc
gboolean load_config(const gchar *filename, RaucConfig **config, GError **error)
{
	GError *ierror = NULL;
	g_autoptr(RaucConfig) c = g_new0(RaucConfig, 1);
	gboolean res = FALSE;
	g_autoptr(GKeyFile) key_file = NULL;
	gchar **groups;
	gsize group_count;
	GList *slotlist = NULL;
	GHashTable *slots = NULL;
	GList *l;
	gchar *bootloader;
	const gchar **pointer;
	gboolean dtbvariant;
	gchar *variant_data;

	key_file = g_key_file_new();

	res = g_key_file_load_from_file(key_file, filename, G_KEY_FILE_NONE, &ierror);
	if (!res) {
		g_propagate_error(error, ierror);
		goto free;
	}

	/* parse [system] section */
	c->system_compatible = key_file_consume_string(key_file, "system", "compatible", &ierror);
	if (!c->system_compatible) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	bootloader = key_file_consume_string(key_file, "system", "bootloader", NULL);
	if (!bootloader) {
		g_set_error_literal(
				error,
				R_CONFIG_ERROR,
				R_CONFIG_ERROR_BOOTLOADER,
				"No bootloader selected in system config");
		res = FALSE;
		goto free;
	}

	pointer = &supported_bootloaders[0];
	while (*pointer) {
		if (g_strcmp0(bootloader, *pointer) == 0) {
			c->system_bootloader = bootloader;
			break;
		}
		pointer++;
	}

	if (!c->system_bootloader) {
		g_set_error(
				error,
				R_CONFIG_ERROR,
				R_CONFIG_ERROR_BOOTLOADER,
				"Unsupported bootloader '%s' selected in system config", bootloader);
		res = FALSE;
		goto free;
	}

	if (g_strcmp0(c->system_bootloader, "barebox") == 0) {
		c->system_bb_statename = key_file_consume_string(key_file, "system", "barebox-statename", NULL);
	}

	c->max_bundle_download_size = g_key_file_get_uint64(key_file, "system", "max-bundle-download-size", &ierror);
	if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
		g_debug("No value for key \"max-bundle-download-size\" in [system] defined "
				"- using default value of %d bytes.", DEFAULT_MAX_BUNDLE_DOWNLOAD_SIZE);
		c->max_bundle_download_size = DEFAULT_MAX_BUNDLE_DOWNLOAD_SIZE;
		g_clear_error(&ierror);
	} else if (ierror) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	if (c->max_bundle_download_size == 0) {
		g_set_error(
				error,
				R_CONFIG_ERROR,
				R_CONFIG_ERROR_MAX_BUNDLE_DOWNLOAD_SIZE,
				"Invalid value (%" G_GUINT64_FORMAT ") for key \"max-bundle-download-size\" in system config", c->max_bundle_download_size);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_key(key_file, "system", "max-bundle-download-size", NULL);

	c->mount_prefix = key_file_consume_string(key_file, "system", "mountprefix", NULL);
	if (!c->mount_prefix) {
		g_debug("No mount prefix provided, using /mnt/rauc/ as default");
		c->mount_prefix = g_strdup("/mnt/rauc/");
	}

	if (g_strcmp0(c->system_bootloader, "grub") == 0) {
		c->grubenv_path = resolve_path(filename,
				key_file_consume_string(key_file, "system", "grubenv", NULL));
		if (!c->grubenv_path) {
			g_debug("No grubenv path provided, using /boot/grub/grubenv as default");
			c->grubenv_path = g_strdup("/boot/grub/grubenv");
		}
	}

	c->activate_installed = g_key_file_get_boolean(key_file, "system", "activate-installed", &ierror);
	if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
		c->activate_installed = TRUE;
		g_clear_error(&ierror);
	} else if (ierror) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_key(key_file, "system", "activate-installed", NULL);

	c->system_variant_type = R_CONFIG_SYS_VARIANT_NONE;

	/* parse 'variant-dtb' key */
	dtbvariant = g_key_file_get_boolean(key_file, "system", "variant-dtb", &ierror);
	if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
		dtbvariant = FALSE;
		g_clear_error(&ierror);
	} else if (ierror) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_key(key_file, "system", "variant-dtb", NULL);
	if (dtbvariant)
		c->system_variant_type = R_CONFIG_SYS_VARIANT_DTB;

	/* parse 'variant-file' key */
	variant_data = key_file_consume_string(key_file, "system", "variant-file", &ierror);
	if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
		variant_data = NULL;
		g_clear_error(&ierror);
	} else if (ierror) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	if (variant_data) {
		if (c->system_variant_type != R_CONFIG_SYS_VARIANT_NONE) {
			g_set_error(
					error,
					R_CONFIG_ERROR,
					R_CONFIG_ERROR_INVALID_FORMAT,
					"Only one of the keys 'variant-file', variant-dtb','variant-name' is allowed");
			res = FALSE;
			goto free;
		}

		c->system_variant_type = R_CONFIG_SYS_VARIANT_FILE;
		c->system_variant = variant_data;
	}

	/* parse 'variant-name' key */
	variant_data = key_file_consume_string(key_file, "system", "variant-name", &ierror);
	if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
		variant_data = NULL;
		g_clear_error(&ierror);
	} else if (ierror) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	if (variant_data) {
		if (c->system_variant_type != R_CONFIG_SYS_VARIANT_NONE) {
			g_set_error(
					error,
					R_CONFIG_ERROR,
					R_CONFIG_ERROR_INVALID_FORMAT,
					"Only one of the keys 'variant-file', variant-dtb','variant-name' is allowed");
			res = FALSE;
			goto free;
		}

		c->system_variant_type = R_CONFIG_SYS_VARIANT_NAME;
		c->system_variant = variant_data;
	}

	c->statusfile_path = resolve_path(filename,
			key_file_consume_string(key_file, "system", "statusfile", NULL));
	if (!check_remaining_keys(key_file, "system", &ierror)) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_group(key_file, "system", NULL);

	/* parse [keyring] section */
	c->keyring_path = resolve_path(filename,
			key_file_consume_string(key_file, "keyring", "path", NULL));

	c->use_bundle_signing_time = g_key_file_get_boolean(key_file, "keyring", "use-bundle-signing-time", &ierror);
	if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) ||
	    g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) {
		c->use_bundle_signing_time = FALSE;
		g_clear_error(&ierror);
	} else if (ierror) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_key(key_file, "keyring", "use-bundle-signing-time", NULL);

	if (!check_remaining_keys(key_file, "keyring", &ierror)) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_group(key_file, "keyring", NULL);

	/* parse [casync] section */
	c->store_path = key_file_consume_string(key_file, "casync", "storepath", NULL);
	if (!check_remaining_keys(key_file, "casync", &ierror)) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_group(key_file, "casync", NULL);

	/* parse [autoinstall] section */
	c->autoinstall_path = resolve_path(filename,
			key_file_consume_string(key_file, "autoinstall", "path", NULL));
	if (!check_remaining_keys(key_file, "autoinstall", &ierror)) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_group(key_file, "autoinstall", NULL);

	/* parse [handlers] section */
	c->systeminfo_handler = resolve_path(filename,
			key_file_consume_string(key_file, "handlers", "system-info", NULL));

	c->preinstall_handler = resolve_path(filename,
			key_file_consume_string(key_file, "handlers", "pre-install", NULL));

	c->postinstall_handler = resolve_path(filename,
			key_file_consume_string(key_file, "handlers", "post-install", NULL));
	if (!check_remaining_keys(key_file, "handlers", &ierror)) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}
	g_key_file_remove_group(key_file, "handlers", NULL);

	/* parse [slot.*.#] sections */
	slots = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, r_free_slot);

	groups = g_key_file_get_groups(key_file, &group_count);
	for (gsize i = 0; i < group_count; i++) {
		RaucSlot *slot = g_new0(RaucSlot, 1);
		gchar **groupsplit;

		groupsplit = g_strsplit(groups[i], ".", -1);

		/* We treat sections starting with "slot." as slots */
		if (g_str_equal(groupsplit[0], RAUC_SLOT_PREFIX)) {
			gchar* value;

			/* Assure slot strings consist of 3 parts, delimited by dots */
			if (g_strv_length(groupsplit) != 3) {
				g_set_error(
						error,
						R_CONFIG_ERROR,
						R_CONFIG_ERROR_INVALID_FORMAT,
						"Invalid slot name format: %s", groups[i]);
				res = FALSE;
				goto free;
			}

			value = g_strconcat(groupsplit[1], ".", groupsplit[2], NULL);
			if (!value) {
				g_set_error(
						error,
						R_CONFIG_ERROR,
						R_CONFIG_ERROR_INVALID_FORMAT,
						"Invalid slot name");
				res = FALSE;
				goto free;
			}
			slot->name = g_intern_string(value);
			g_free(value);

			slot->description = key_file_consume_string(key_file, groups[i], "description", NULL);
			if (!slot->description)
				slot->description = g_strdup("");

			slot->sclass = g_intern_string(groupsplit[1]);

			value = resolve_path(filename,
					key_file_consume_string(key_file, groups[i], "device", &ierror));
			if (!value) {
				g_propagate_error(error, ierror);
				res = FALSE;
				goto free;
			}
			slot->device = value;

			value = key_file_consume_string(key_file, groups[i], "type", NULL);
			if (!value)
				value = g_strdup("raw");
			slot->type = value;

			value = key_file_consume_string(key_file, groups[i], "bootname", NULL);
			slot->bootname = value;

			slot->readonly = g_key_file_get_boolean(key_file, groups[i], "readonly", &ierror);
			if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
				slot->readonly = FALSE;
				g_clear_error(&ierror);
			} else if (ierror) {
				g_propagate_error(error, ierror);
				res = FALSE;
				goto free;
			}
			g_key_file_remove_key(key_file, groups[i], "readonly", NULL);

			slot->force_install_same = g_key_file_get_boolean(key_file, groups[i], "force-install-same", &ierror);
			if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
				g_clear_error(&ierror);
				/* try also deprecatet flag ignore-checksum */
				slot->force_install_same = g_key_file_get_boolean(key_file, groups[i], "ignore-checksum", &ierror);
				if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
					slot->force_install_same = FALSE;
					g_clear_error(&ierror);
				}
				else if (ierror) {
					g_propagate_error(error, ierror);
					res = FALSE;
					goto free;
				}
			}
			else if (ierror) {
				g_propagate_error(error, ierror);
				res = FALSE;
				goto free;
			}
			g_key_file_remove_key(key_file, groups[i], "force-install-same", NULL);
			g_key_file_remove_key(key_file, groups[i], "ignore-checksum", NULL);

			slot->extra_mount_opts = key_file_consume_string(key_file, groups[i], "extra-mount-opts", NULL);

			g_hash_table_insert(slots, (gchar*)slot->name, slot);
		}
		g_strfreev(groupsplit);
	}

	/* Add parent pointers */
	slotlist = g_hash_table_get_keys(slots);
	for (l = slotlist; l != NULL; l = l->next) {
		RaucSlot *s;
		g_autofree gchar* group_name = NULL;
		gchar* value;

		group_name = g_strconcat(RAUC_SLOT_PREFIX ".", l->data, NULL);
		value = key_file_consume_string(key_file, group_name, "parent", NULL);
		if (!value) {
			g_key_file_remove_group(key_file, group_name, NULL);
			continue;
		}

		s = g_hash_table_lookup(slots, value);
		if (!s) {
			g_set_error(
					error,
					R_CONFIG_ERROR,
					R_CONFIG_ERROR_PARENT,
					"Parent slot '%s' not found!", value);
			res = FALSE;
			goto free;
		}

		((RaucSlot*)g_hash_table_lookup(slots, l->data))->parent = s;


		if (!check_remaining_keys(key_file, group_name, &ierror)) {
			g_propagate_error(error, ierror);
			res = FALSE;
			goto free;
		}
		g_key_file_remove_group(key_file, group_name, NULL);
	}
	g_list_free(slotlist);

	c->slots = slots;

	if (!check_remaining_groups(key_file, &ierror)) {
		g_propagate_error(error, ierror);
		res = FALSE;
		goto free;
	}

	g_strfreev(groups);

	res = TRUE;
free:
	if (res)
		*config = g_steal_pointer(&c);
	else
		*config = NULL;
	return res;
}
static void
parse_start (GMarkupParseContext * ctx, const gchar * element_name,
    const gchar ** attr_names, const gchar ** attr_vals,
    gpointer user_data, GError ** err)
{
  License *license = user_data;
  const gchar *ref = NULL;
  int i;

  for (i = 0; i < G_N_ELEMENTS (tag_map); ++i) {
    if (strcmp (element_name, tag_map[i].element_name) == 0)
      break;
  }

  if (i == G_N_ELEMENTS (tag_map))
    g_error ("Unexpected tag '%s'\n", element_name);

  if (tag_map[i].attribute == NULL)
    return;

  if (!g_markup_collect_attributes (element_name, attr_names, attr_vals,
          err, G_MARKUP_COLLECT_STRING, tag_map[i].attribute, &ref,
          G_MARKUP_COLLECT_INVALID)) {
    return;
  }

  switch (tag_map[i].element_tag) {
    case TAG_CC_LICENSE:
      if (!g_str_has_prefix (ref, "http://creativecommons.org/licenses/"))
        g_error ("Unexpected license reference: %s\n", ref);
      /* we assume one license per file, and CC license ref */
      g_assert (license->ref == NULL);
      license->ref = g_strdup (ref);
      break;
    case TAG_CC_JURISDICTION:
      if (!g_str_has_prefix (ref, "http://creativecommons.org/international/"))
        g_error ("Unknown license jurisdiction: %s\n", ref);
      /* we assume one jurisdiction per license */
      g_assert (license->jurisdiction == JURISDICTION_GENERIC);
      license->jurisdiction = ref_to_jurisdiction (ref);
      license->jurisdiction_suffix =
          g_strdup (ref + strlen ("http://creativecommons.org/international/"));
      break;
    case TAG_CC_LEGALCODE:
      if (!g_str_has_prefix (ref, "http://creativecommons.org/licenses/"))
        g_error ("Unexpected legalcode reference: %s\n", ref);
      /* we assume one legalcode per license */
      g_assert (license->legalcode == NULL);
      license->legalcode = g_strdup (ref);
      break;
    case TAG_DC_CREATOR:
      if (strcmp (ref, "http://creativecommons.org") == 0) {
        license->flags |= GST_TAG_LICENSE_CREATIVE_COMMONS_LICENSE;
      } else if (strcmp (ref, "http://fsf.org") == 0) {
        license->flags |= GST_TAG_LICENSE_FREE_SOFTWARE_FOUNDATION_LICENSE;
      } else {
        g_error ("Unknown license creator: %s\n", ref);
      }
      break;
    case TAG_CC_DEPRECATED_ON:
      break;
    case TAG_CC_PROHIBITS:
    case TAG_CC_REQUIRES:
    case TAG_CC_PERMITS:
      license->flags |= ref_to_flag (ref);
      break;
    case TAG_DC_TITLE:{
      gchar *cur_lang;

      cur_lang = g_strdelimit (g_strdup (ref), "-", '_');
      license->cur_lang = g_intern_string (cur_lang);
      if (!g_list_find_custom (langs, cur_lang, (GCompareFunc) strcmp))
        langs = g_list_prepend (langs, (gpointer) license->cur_lang);

      g_free (cur_lang);
      break;
    }
    case TAG_DC_DESCRIPTION:{
      gchar *cur_lang;

      cur_lang = g_strdelimit (g_strdup (ref), "-", '_');
      license->cur_lang = g_intern_string (cur_lang);
      if (!g_list_find_custom (langs, cur_lang, (GCompareFunc) strcmp))
        langs = g_list_prepend (langs, (gpointer) license->cur_lang);

      g_free (cur_lang);
      break;
    }
    case TAG_DCQ_IS_REPLACED_BY:
      /* we assume one replacer per license for now */
      g_assert (license->replaced_by == NULL);
      license->replaced_by = g_strdup (ref);
      break;
    case TAG_RDF_DESCRIPTION:
      if (!g_str_has_prefix (ref, "http://creativecommons.org/licenses/"))
        g_error ("Unexpected license reference: %s\n", ref);
      if (license->ref != NULL && strcmp (license->ref, ref) != 0) {
        gchar *f, *r = g_strdup (ref);

        /* work around bug in some of the RDFs ... */
        if ((f = strstr (r, "by-nc-nd"))) {
          memcpy (f, "by-nd-nc", 8);
        }
        if (strcmp (license->ref, r) != 0) {
          g_error ("rdf:Description chunk for other than current license");
        }
        g_free (r);
      }
      break;
    case TAG_DC_SOURCE:
      if (!g_str_has_prefix (ref, "http://creativecommons.org/licenses/"))
        g_error ("Unexpected source reference: %s\n", ref);
      /* we assume one source (for jurisdiction-specific versions) */
      g_assert (license->source == NULL);
      license->source = g_strdup (ref);
      break;
    default:
      g_printerr ("unhandled start tag: %s\n", element_name);
      break;
  }
}
예제 #24
0
gboolean _fm_file_ops_job_move_run(FmFileOpsJob* job)
{
    GFile *dest_dir;
    GFileInfo* inf;
    GList* l;
    GError* err = NULL;
    FmJob* fmjob = FM_JOB(job);
    dev_t dest_dev = 0;
    gboolean ret = TRUE;
    FmDeepCountJob* dc;
    FmPath *parent = NULL;
    FmFolder *df, *sf = NULL;

    /* get information of destination folder */
    g_return_val_if_fail(job->dest, FALSE);
    dest_dir = fm_path_to_gfile(job->dest);
_retry_query_dest_info:
    inf = g_file_query_info(dest_dir, G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL","
                                  G_FILE_ATTRIBUTE_UNIX_DEVICE","
                                  G_FILE_ATTRIBUTE_ID_FILESYSTEM","
                                  G_FILE_ATTRIBUTE_UNIX_DEVICE, 0,
                                  fm_job_get_cancellable(fmjob), &err);
    if(inf)
    {
        job->dest_fs_id = g_intern_string(g_file_info_get_attribute_string(inf, G_FILE_ATTRIBUTE_ID_FILESYSTEM));
        dest_dev = g_file_info_get_attribute_uint32(inf, G_FILE_ATTRIBUTE_UNIX_DEVICE); /* needed by deep count */
        g_object_unref(inf);
    }
    else
    {
        FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MODERATE);
        g_error_free(err);
        err = NULL;
        if(act == FM_JOB_RETRY)
            goto _retry_query_dest_info;
        else
        {
            g_object_unref(dest_dir);
            return FALSE;
        }
    }

    /* prepare the job, count total work needed with FmDeepCountJob */
    dc = fm_deep_count_job_new(job->srcs, FM_DC_JOB_PREPARE_MOVE);
    fm_deep_count_job_set_dest(dc, dest_dev, job->dest_fs_id);
    fm_job_run_sync(FM_JOB(dc));
    job->total = dc->total_size;

    if( fm_job_is_cancelled(FM_JOB(dc)) )
    {
        g_object_unref(dest_dir);
        g_object_unref(dc);
        return FALSE;
    }
    g_object_unref(dc);
    g_debug("total size to move: %llu, dest_fs: %s",
            (long long unsigned int)job->total, job->dest_fs_id);

    fm_file_ops_job_emit_prepared(job);
    /* suspend updates for destination */
    df = fm_folder_find_by_path(job->dest);
    if (df)
        fm_folder_block_updates(df);

    for(l = fm_path_list_peek_head_link(job->srcs); !fm_job_is_cancelled(fmjob) && l; l=l->next)
    {
        FmPath* path = FM_PATH(l->data);
        GFile* src = fm_path_to_gfile(path);
        GFile* dest;
        char* tmp_basename;

        /* do with updates for source */
        if (fm_path_get_parent(path) != parent && fm_path_get_parent(path) != NULL)
        {
            FmFolder *pf;

            pf = fm_folder_find_by_path(fm_path_get_parent(path));
            if (pf != sf)
            {
                if (sf)
                {
                    fm_folder_unblock_updates(sf);
                    g_object_unref(sf);
                }
                if (pf)
                    fm_folder_block_updates(pf);
                sf = pf;
            }
            else if (pf)
                g_object_unref(pf);
        }
        parent = fm_path_get_parent(path);
        if(g_file_is_native(src) && g_file_is_native(dest_dir))
            /* both are native */
            tmp_basename = NULL;
        else if(g_file_is_native(src)) /* move from native to virtual */
            tmp_basename = g_filename_to_utf8(fm_path_get_basename(path),
                                              -1, NULL, NULL, NULL);
            /* gvfs escapes it itself */
        else /* move from virtual to native/virtual */
            tmp_basename = fm_uri_subpath_to_native_subpath(fm_path_get_basename(path), NULL);
        dest = g_file_get_child(dest_dir,
                        tmp_basename ? tmp_basename : fm_path_get_basename(path));
        g_free(tmp_basename);

        if(!_fm_file_ops_job_move_file(job, src, NULL, dest, path, sf, df))
            ret = FALSE;
        g_object_unref(src);
        g_object_unref(dest);

        if(!ret)
            break;
    }
    /* restore updates for destination and source */
    if (df)
    {
        fm_folder_unblock_updates(df);
        g_object_unref(df);
    }
    if (sf)
    {
        fm_folder_unblock_updates(sf);
        g_object_unref(sf);
    }

    g_object_unref(dest_dir);
    return ret;
}
예제 #25
0
GList *
rut_infer_asset_tags (RutContext *ctx, GFileInfo *info, GFile *asset_file)
{
  GFile *assets_dir = g_file_new_for_path (ctx->assets_location);
  GFile *dir = g_file_get_parent (asset_file);
  char *basename;
  const char *content_type = g_file_info_get_content_type (info);
  char *mime_type = g_content_type_get_mime_type (content_type);
  const char *ext;
  GList *inferred_tags = NULL;

  while (dir && !g_file_equal (assets_dir, dir))
    {
      basename = g_file_get_basename (dir);
      inferred_tags =
        g_list_prepend (inferred_tags, (char *)g_intern_string (basename));
      g_free (basename);
      dir = g_file_get_parent (dir);
    }

  if (mime_type)
    {
      if (strncmp (mime_type, "image/", 6) == 0)
        inferred_tags =
          g_list_prepend (inferred_tags, (char *)g_intern_string ("image"));
      inferred_tags =
        g_list_prepend (inferred_tags, (char *)g_intern_string ("img"));

      if (rut_util_find_tag (inferred_tags, "normal-maps"))
        {
          inferred_tags =
            g_list_prepend (inferred_tags,
                            (char *)g_intern_string ("map"));
          inferred_tags =
            g_list_prepend (inferred_tags,
                            (char *)g_intern_string ("normal-map"));
          inferred_tags =
            g_list_prepend (inferred_tags,
                            (char *)g_intern_string ("bump-map"));
        }
      else if (rut_util_find_tag (inferred_tags, "alpha-masks"))
        {
          inferred_tags =
            g_list_prepend (inferred_tags,
                            (char *)g_intern_string ("alpha-mask"));
          inferred_tags =
            g_list_prepend (inferred_tags,
                            (char *)g_intern_string ("mask"));
        }
    }

  basename = g_file_get_basename (asset_file);
  ext = get_extension (basename);
  if (ext && strcmp (ext, "ply") == 0)
    {
      inferred_tags =
        g_list_prepend (inferred_tags, (char *)g_intern_string ("ply"));
      inferred_tags =
        g_list_prepend (inferred_tags, (char *)g_intern_string ("mesh"));
      inferred_tags =
        g_list_prepend (inferred_tags, (char *)g_intern_string ("model"));
    }
  g_free (basename);

  return inferred_tags;
}
예제 #26
0
static void
gtk_action_set_property (GObject         *object,
			 guint            prop_id,
			 const GValue    *value,
			 GParamSpec      *pspec)
{
  GtkAction *action;
  
  action = GTK_ACTION (object);

  switch (prop_id)
    {
    case PROP_NAME:
      action->private_data->name = g_intern_string (g_value_get_string (value));
      break;
    case PROP_LABEL:
      gtk_action_set_label (action, g_value_get_string (value));
      break;
    case PROP_SHORT_LABEL:
      gtk_action_set_short_label (action, g_value_get_string (value));
      break;
    case PROP_TOOLTIP:
      gtk_action_set_tooltip (action, g_value_get_string (value));
      break;
    case PROP_STOCK_ID:
      gtk_action_set_stock_id (action, g_value_get_string (value));
      break;
    case PROP_GICON:
      gtk_action_set_gicon (action, g_value_get_object (value));
      break;
    case PROP_ICON_NAME:
      gtk_action_set_icon_name (action, g_value_get_string (value));
      break;
    case PROP_VISIBLE_HORIZONTAL:
      gtk_action_set_visible_horizontal (action, g_value_get_boolean (value));
      break;
    case PROP_VISIBLE_VERTICAL:
      gtk_action_set_visible_vertical (action, g_value_get_boolean (value));
      break;
    case PROP_VISIBLE_OVERFLOWN:
      action->private_data->visible_overflown = g_value_get_boolean (value);
      break;
    case PROP_IS_IMPORTANT:
      gtk_action_set_is_important (action, g_value_get_boolean (value));
      break;
    case PROP_HIDE_IF_EMPTY:
      action->private_data->hide_if_empty = g_value_get_boolean (value);
      break;
    case PROP_SENSITIVE:
      gtk_action_set_sensitive (action, g_value_get_boolean (value));
      break;
    case PROP_VISIBLE:
      gtk_action_set_visible (action, g_value_get_boolean (value));
      break;
    case PROP_ACTION_GROUP:
      gtk_action_set_action_group (action, g_value_get_object (value));
      break;
    case PROP_ALWAYS_SHOW_IMAGE:
      gtk_action_set_always_show_image (action, g_value_get_boolean (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}
예제 #27
0
static void
soup_address_set_property (GObject *object, guint prop_id,
			   const GValue *value, GParamSpec *pspec)
{
	SoupAddressPrivate *priv = SOUP_ADDRESS_GET_PRIVATE (object);
	SoupAddressFamily family;
	struct sockaddr *sa;
	int len, port;

	/* This is a mess because the properties are mostly orthogonal,
	 * but g_object_constructor wants to set a default value for each
	 * of them.
	 */

	switch (prop_id) {
	case PROP_NAME:
		priv->name = g_value_dup_string (value);
		break;

	case PROP_FAMILY:
		family = g_value_get_enum (value);
		if (family == SOUP_ADDRESS_FAMILY_INVALID)
			return;
		g_return_if_fail (SOUP_ADDRESS_FAMILY_IS_VALID (family));
		g_return_if_fail (priv->sockaddr == NULL);

		priv->sockaddr = g_malloc0 (SOUP_ADDRESS_FAMILY_SOCKADDR_SIZE (family));
		SOUP_ADDRESS_SET_FAMILY (priv, family);
		SOUP_ADDRESS_SET_PORT (priv, htons (priv->port));
		priv->n_addrs = 1;
		break;

	case PROP_PORT:
		port = g_value_get_int (value);
		if (port == -1)
			return;
		g_return_if_fail (SOUP_ADDRESS_PORT_IS_VALID (port));

		priv->port = port;
		if (priv->sockaddr)
			SOUP_ADDRESS_SET_PORT (priv, htons (port));
		break;

	case PROP_PROTOCOL:
		priv->protocol = g_intern_string (g_value_get_string (value));
		break;

	case PROP_SOCKADDR:
		sa = g_value_get_pointer (value);
		if (!sa)
			return;
		g_return_if_fail (priv->sockaddr == NULL);

		len = SOUP_ADDRESS_FAMILY_SOCKADDR_SIZE (sa->sa_family);
		priv->sockaddr = g_memdup (sa, len);
		priv->n_addrs = 1;
		priv->port = ntohs (SOUP_ADDRESS_GET_PORT (priv));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
예제 #28
0
파일: table.c 프로젝트: gbl/vte
static void
_vte_table_addi(struct _vte_table *table,
		const unsigned char *original, gssize original_length,
		const char *pattern, gssize length,
		const char *result)
{
	int i;
	guint8 check;
	struct _vte_table *subtable;

	if (original_length == -1) {
		original_length = strlen((char *) original);
	}
	if (length == -1) {
		length = strlen(pattern);
	}

	/* If this is the terminal node, set the result. */
	if (length == 0) {
		if (table->result != NULL)
			_vte_debug_print (VTE_DEBUG_PARSE, 
					  "`%s' and `%s' are indistinguishable.\n",
					  table->result, result);

		table->result = g_intern_string(result);
		if (table->original != NULL) {
			g_free(table->original);
		}
		table->original = g_memdup(original, original_length);
		table->original_length = original_length;
		return;
	}

	/* All of the interesting arguments begin with '%'. */
	if (pattern[0] == '%') {
		/* Handle numeric parameters. */
		if (pattern[1] == 'd') {
			/* Create a new subtable. */
			if (table->table_number == NULL) {
				subtable = _vte_table_new();
				table->table_number = subtable;
			} else {
				subtable = table->table_number;
			}
			/* Add the rest of the string to the subtable. */
			_vte_table_addi(subtable, original, original_length,
					pattern + 2, length - 2,
					result);
			return;
		}

		/* Handle variable-length parameters. */
		if (pattern[1] == 'm') {
			/* Build the "new" original using the initial portion
			 * of the original string and what's left after this
			 * specifier. */
			{
				int initial;
				GByteArray *b;

				initial = original_length - length;
				b = g_byte_array_new();
				g_byte_array_set_size(b, 0);
				g_byte_array_append(b, original, initial);
				g_byte_array_append(b, (const guint8*)pattern + 2, length - 2);
				_vte_table_addi(table, b->data, b->len,
						(const char *)b->data + initial,
						b->len - initial,
						result);
				g_byte_array_free(b, TRUE);
			}
			/* Create a new subtable. */
			if (table->table_number_list == NULL) {
				subtable = _vte_table_new();
				table->table_number_list = subtable;
			} else {
				subtable = table->table_number_list;
			}
			/* Add the rest of the string to the subtable. */
			_vte_table_addi(subtable, original, original_length,
					pattern + 2, length - 2,
					result);
			return;
		}

		/* Handle string parameters. */
		if (pattern[1] == 's') {
			/* It must have a terminator. */
			g_assert(length >= 3);
			/* Create a new subtable. */
			if (table->table_string == NULL) {
				subtable = _vte_table_new();
				table->table_string = subtable;
			} else {
				subtable = table->table_string;
			}
			/* Add the rest of the string to the subtable. */
			_vte_table_addi(subtable, original, original_length,
					pattern + 2, length - 2,
					result);
			return;
		}

		/* Handle an escaped '%'. */
		if (pattern[1] == '%') {
			/* Create a new subtable. */
			if (table->table == NULL) {
				table->table = _vte_table_literal_new();
				subtable = _vte_table_new();
				table->table['%'] = subtable;
			} else
			if (table->table['%'] == NULL) {
				subtable = _vte_table_new();
				table->table['%'] = subtable;
			} else {
				subtable = table->table['%'];
			}
			/* Add the rest of the string to the subtable. */
			_vte_table_addi(subtable, original, original_length,
					pattern + 2, length - 2,
					result);
			return;
		}

		/* Handle a parameter character. */
		if (pattern[1] == '+') {
			/* It must have an addend. */
			g_assert(length >= 3);
			/* Fill in all of the table entries above the given
			 * character value. */
			for (i = pattern[2]; i < VTE_TABLE_MAX_LITERAL; i++) {
				/* Create a new subtable. */
				if (table->table == NULL) {
					table->table = _vte_table_literal_new();
					subtable = _vte_table_new();
					table->table[i] = subtable;
				} else
				if (table->table[i] == NULL) {
					subtable = _vte_table_new();
					table->table[i] = subtable;
				} else {
					subtable = table->table[i];
				}
				/* Add the rest of the string to the subtable. */
				_vte_table_addi(subtable,
						original, original_length,
						pattern + 3, length - 3,
						result);
			}
			/* Also add a subtable for higher characters. */
			if (table->table == NULL) {
				table->table = _vte_table_literal_new();
				subtable = _vte_table_new();
				table->table[0] = subtable;
			} else
			if (table->table[0] == NULL) {
				subtable = _vte_table_new();
				table->table[0] = subtable;
			} else {
				subtable = table->table[0];
			}
			/* Add the rest of the string to the subtable. */
			_vte_table_addi(subtable, original, original_length,
					pattern + 3, length - 3,
					result);
			return;
		}
	}

	/* A literal (or an unescaped '%', which is also a literal). */
	check = (guint8) pattern[0];
	g_assert(check < VTE_TABLE_MAX_LITERAL);
	if (table->table == NULL) {
		table->table = _vte_table_literal_new();
		subtable = _vte_table_new();
		table->table[check] = subtable;
	} else
	if (table->table[check] == NULL) {
		subtable = _vte_table_new();
		table->table[check] = subtable;
	} else {
		subtable = table->table[check];
	}

	/* Add the rest of the string to the subtable. */
	_vte_table_addi(subtable, original, original_length,
			pattern + 1, length - 1,
			result);
}