Example #1
0
static void
start_element (GMarkupParseContext *context,
	       const gchar         *element_name,
	       const gchar        **attribute_names,
	       const gchar        **attribute_values,
	       gpointer             user_data,
	       GError             **error)
{
        AppConfigInfo* app_config = (AppConfigInfo*) user_data;

        if (strcmp (element_name, "configuration") == 0) {
                app_config->configuration_count++;
                return;
        }
        if (strcmp (element_name, "startup") == 0) {
                app_config->startup_count++;
                return;
        }

        if (app_config->configuration_count != 1 || app_config->startup_count != 1)
                return;

        if (strcmp (element_name, "requiredRuntime") == 0) {
                app_config->required_runtime = get_attribute_value (attribute_names, attribute_values, "version");
        } else if (strcmp (element_name, "supportedRuntime") == 0) {
                char *version = get_attribute_value (attribute_names, attribute_values, "version");
                app_config->supported_runtimes = g_slist_append (app_config->supported_runtimes, version);
        }
}
Example #2
0
static void
end_element (GMarkupParseContext *context,
             const gchar *element_name,
             gpointer user_data,
             GError **error)
{
  TextTableParseInfo *info = user_data;

  pop_attribute_value (&info->gettext_domain);
  pop_attribute_value (&info->schema_id);
  pop_attribute_value (&info->key_name);

  if (info->string)
    {
      GHashTable *source_table = NULL;
      const gchar *gettext_domain;
      const gchar *schema_id;
      const gchar *key_name;

      gettext_domain = get_attribute_value (info->gettext_domain);
      schema_id = get_attribute_value (info->schema_id);
      key_name = get_attribute_value (info->key_name);

      if (g_str_equal (element_name, "summary"))
        source_table = info->summaries;
      else if (g_str_equal (element_name, "description"))
        source_table = info->descriptions;

      if (source_table && schema_id && key_name)
        {
          GHashTable *schema_table;
          gchar *normalised;

          schema_table = g_hash_table_lookup (source_table, schema_id);

          if (schema_table == NULL)
            {
              schema_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
              g_hash_table_insert (source_table, g_strdup (schema_id), schema_table);
            }

          normalised = normalise_whitespace (info->string->str);

          if (gettext_domain)
            {
              gchar *translated;

              translated = g_strdup (g_dgettext (gettext_domain, normalised));
              g_free (normalised);
              normalised = translated;
            }

          g_hash_table_insert (schema_table, g_strdup (key_name), normalised);
        }

      g_string_free (info->string, TRUE);
      info->string = NULL;
    }
}
Example #3
0
PKCS11_EC_PublicKey::PKCS11_EC_PublicKey(Session& session, ObjectHandle handle)
   : Object(session, handle)
   {
   secure_vector<uint8_t> ec_parameters = get_attribute_value(AttributeType::EcParams);
   m_domain_params = EC_Group(unlock(ec_parameters));
   m_public_key = decode_public_point(get_attribute_value(AttributeType::EcPoint), m_domain_params.get_curve());
   m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
   }
Example #4
0
XAttrManager::attributes_t XAttrManager::get_attributes_list()
{
	std::vector<std::string> attributes;
	std::vector<std::string>::iterator it;

	attributes = get_xattr_list();

	attributes_t result;

	for (it = attributes.begin(); it != attributes.end(); it++)
	{
		std::string attr_value = get_attribute_value(*it);

		result[*it] = attr_value;
	}

	return result;
}
Example #5
0
Pvoid_t atom_tokenize(const char * atom) {
	Pvoid_t features = NULL;

	if (atom) {
		xmlDocPtr doc = xmlParseDoc(BAD_CAST atom);
		if (doc) {
			xmlXPathContextPtr context = xmlXPathNewContext(doc);
			xmlXPathRegisterNs(context, BAD_CAST "atom", BAD_CAST "http://www.w3.org/2005/Atom");

			char *html = get_element_value(context, "/atom:entry/atom:content/text()");
			if (html) {
				features = html_tokenize_into_features(html, features);
				xmlFree(html);
			}

			char *title = get_element_value(context, "/atom:entry/atom:title/text()");
			if (title) {
				features = tokenize_text(title, strlen(title), features);
				xmlFree(title);
			}

			char *author = get_element_value(context, "/atom:entry/atom:author/atom:name/text()");
			if (author) {
				features = add_token(author, features);
				xmlFree(author);
			}

			char *link = get_attribute_value(context, "/atom:entry/atom:link[@rel='alternate']", "href");
			if (link) {
				features = tokenize_uri(link, features);
				xmlFree(link);
			}

			xmlXPathFreeContext(context);
		}

		xmlFreeDoc(doc);
	}

	return features;
}
Example #6
0
/*
 * Parse AndroidManifest from buffer, return a list of class names that are referenced
 */
std::unordered_set<std::string> extract_classes_from_manifest(const std::string& manifest_contents) {

  // Tags
  android::String16 activity("activity");
  android::String16 activity_alias("activity-alias");
  android::String16 application("application");
  android::String16 provider("provider");
  android::String16 receiver("receiver");
  android::String16 service("service");
  android::String16 instrumentation("instrumentation");

  // Attributes
  android::String16 authorities("authorities");
  android::String16 name("name");
  android::String16 target_activity("targetActivity");

  android::ResXMLTree parser;
  parser.setTo(manifest_contents.data(), manifest_contents.size());

  std::unordered_set<std::string> result;

  if (parser.getError() != android::NO_ERROR) {
    return result;
  }

  android::ResXMLParser::event_code_t type;
  do {
    type = parser.next();
    if (type == android::ResXMLParser::START_TAG) {
      size_t len;
      android::String16 tag(parser.getElementName(&len));
      if (tag == activity ||
          tag == application ||
          tag == provider ||
          tag == receiver ||
          tag == service ||
          tag == instrumentation) {

        std::string classname = get_attribute_value(parser, name);
        if (classname.size()) {
          result.insert(dotname_to_dexname(classname));
        }

        if (tag == provider) {
          std::string text = get_attribute_value(parser, authorities);
          size_t start = 0;
          size_t end = 0;
          while ((end = text.find(';', start)) != std::string::npos) {
              result.insert(dotname_to_dexname(text.substr(start, end - start)));
              start = end + 1;
          }
          result.insert(dotname_to_dexname(text.substr(start)));
        }
      } else if (tag == activity_alias) {
        std::string classname = get_attribute_value(parser, target_activity);
        if (classname.size()) {
          result.insert(dotname_to_dexname(classname));
        }
      }
    }
  } while (type != android::ResXMLParser::BAD_DOCUMENT &&
           type != android::ResXMLParser::END_DOCUMENT);

  return result;
}
static void
parse_start_element_cb (GMarkupParseContext *context,
			const char *element_name,
			const char **attribute_names,
			const char **attribute_values,
			gpointer data,
			GError **error)
{
  struct parse_state *state;
  int line, col;

  state = data;
  g_markup_parse_context_get_position (context, &line, &col);

  switch (state->state)
    {
    case STATE_START:
      if (EQ (element_name, ELEMENT_TOPLEVEL))
	{
	  const char *version_str;

	  state->state = STATE_IN_TOPLEVEL;

	  version_str = get_attribute_value (attribute_names, attribute_values, ATTRIBUTE_VERSION);
	  if (!version_str)
	    state->version = -1;
	  else
	    if (sscanf (version_str, "%d", &state->version) != 1 || state->version < 0)
	      state->version = -1;
	}
      else
	{
	  state->state = STATE_ERROR;
	  g_set_error (error,
		       G_MARKUP_ERROR,
		       G_MARKUP_ERROR_UNKNOWN_ELEMENT,
		       _("Line %d, column %d: expected \"%s\" at the toplevel, but found \"%s\" instead"),
		       line,
		       col,
		       ELEMENT_TOPLEVEL,
		       element_name);
	}
      break;

    case STATE_END:
      g_assert_not_reached ();
      break;

    case STATE_ERROR:
      g_assert_not_reached ();
      break;

    case STATE_IN_TOPLEVEL:
      if (EQ (element_name, ELEMENT_LOCATION))
	{
	  const char *location_mode_str;

	  state->state = STATE_IN_LOCATION;

	  location_mode_str = get_attribute_value (attribute_names, attribute_values, ATTRIBUTE_MODE);
	  if (!location_mode_str)
	    set_missing_attribute_error (state, line, col, ATTRIBUTE_MODE, error);
	  else if (EQ (location_mode_str, MODE_PATH_BAR))
	    state->settings->location_mode = LOCATION_MODE_PATH_BAR;
	  else if (EQ (location_mode_str, MODE_FILENAME_ENTRY))
	    state->settings->location_mode = LOCATION_MODE_FILENAME_ENTRY;
	  else
	    {
	      state->state = STATE_ERROR;
	      g_set_error (error,
			   G_MARKUP_ERROR,
			   G_MARKUP_ERROR_INVALID_CONTENT,
			   _("Line %d, column %d: expected \"%s\" or \"%s\", but found \"%s\" instead"),
			   line,
			   col,
			   MODE_PATH_BAR,
			   MODE_FILENAME_ENTRY,
			   location_mode_str);
	    }
	}
      else if (EQ (element_name, ELEMENT_SHOW_HIDDEN))
	{
	  const char *value_str;

	  state->state = STATE_IN_SHOW_HIDDEN;

	  value_str = get_attribute_value (attribute_names, attribute_values, ATTRIBUTE_VALUE);

	  if (!value_str)
	    set_missing_attribute_error (state, line, col, ATTRIBUTE_VALUE, error);
	  else if (EQ (value_str, VALUE_TRUE))
	    state->settings->show_hidden = TRUE;
	  else if (EQ (value_str, VALUE_FALSE))
	    state->settings->show_hidden = FALSE;
	  else
	    {
	      state->state = STATE_ERROR;
	      g_set_error (error,
			   G_MARKUP_ERROR,
			   G_MARKUP_ERROR_INVALID_CONTENT,
			   _("Line %d, column %d: expected \"%s\" or \"%s\", but found \"%s\" instead"),
			   line,
			   col,
			   VALUE_FALSE,
			   VALUE_TRUE,
			   value_str);
	    }
	}
      else if (EQ (element_name, ELEMENT_EXPAND_FOLDERS))
	{
	  const char *value_str;

	  state->state = STATE_IN_EXPAND_FOLDERS;

	  value_str = get_attribute_value (attribute_names, attribute_values, ATTRIBUTE_VALUE);

	  if (!value_str)
	    set_missing_attribute_error (state, line, col, ATTRIBUTE_VALUE, error);
	  else if (EQ (value_str, VALUE_TRUE))
	    state->settings->expand_folders = TRUE;
	  else if (EQ (value_str, VALUE_FALSE))
	    state->settings->expand_folders = FALSE;
	  else
	    {
	      state->state = STATE_ERROR;
	      g_set_error (error,
			   G_MARKUP_ERROR,
			   G_MARKUP_ERROR_INVALID_CONTENT,
			   _("Line %d, column %d: expected \"%s\" or \"%s\", but found \"%s\" instead"),
			   line,
			   col,
			   VALUE_FALSE,
			   VALUE_TRUE,
			   value_str);
	    }
	}
      else
	set_unexpected_element_error (state, line, col, element_name, error);

      break;

    case STATE_IN_LOCATION:
    case STATE_IN_SHOW_HIDDEN:
      set_unexpected_element_error (state, line, col, element_name, error);
      break;

    default:
      g_assert_not_reached ();
    }
}
Example #8
0
void changetopfishfocus(topview * t, float *x, float *y,
			float *z, int num_foci)
{

    gvcolor_t cl;
    focus_t *fs = t->fisheyeParams.fs;
    int i;
    int closest_fine_node;
    int cur_level = 0;

    Hierarchy *hp = t->fisheyeParams.h;
    refresh_old_values(t);
    fs->num_foci = num_foci;
    for (i = 0; i < num_foci; i++) {
	find_closest_active_node(hp, x[i], y[i], &closest_fine_node);
	fs->foci_nodes[i] = closest_fine_node;
	fs->x_foci[i] =
	    hp->geom_graphs[cur_level][closest_fine_node].x_coord;
	fs->y_foci[i] =
	    hp->geom_graphs[cur_level][closest_fine_node].y_coord;
    }


    view->Topview->fisheyeParams.repos.width =
	(int) (view->bdxRight - view->bdxLeft);
    view->Topview->fisheyeParams.repos.height =
	(int) (view->bdyTop - view->bdyBottom);

    colorxlate(get_attribute_value
	       ("topologicalfisheyefinestcolor", view,
		view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
    view->Topview->fisheyeParams.srcColor.R = (float) cl.u.RGBA[0];
    view->Topview->fisheyeParams.srcColor.G = (float) cl.u.RGBA[1];
    view->Topview->fisheyeParams.srcColor.B = (float) cl.u.RGBA[2];
    colorxlate(get_attribute_value
	       ("topologicalfisheyecoarsestcolor", view,
		view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
    view->Topview->fisheyeParams.tarColor.R = (float) cl.u.RGBA[0];
    view->Topview->fisheyeParams.tarColor.G = (float) cl.u.RGBA[1];
    view->Topview->fisheyeParams.tarColor.B = (float) cl.u.RGBA[2];



    sscanf(agget
	   (view->g[view->activeGraph],
	    "topologicalfisheyedistortionfactor"), "%lf",
	   &view->Topview->fisheyeParams.repos.distortion);
    sscanf(agget
	   (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
	   "%d", &view->Topview->fisheyeParams.level.num_fine_nodes);
    sscanf(agget
	   (view->g[view->activeGraph],
	    "topologicalfisheyecoarseningfactor"), "%lf",
	   &view->Topview->fisheyeParams.level.coarsening_rate);
    sscanf(agget
	   (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
	   "%d", &view->Topview->fisheyeParams.hier.dist2_limit);
    sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
	   "%d", &view->Topview->fisheyeParams.animate);




    set_active_levels(hp, fs->foci_nodes, fs->num_foci, &(t->fisheyeParams.level));


    positionAllItems(hp, fs, &(t->fisheyeParams.repos));

    view->Topview->fisheyeParams.animate = 1;

    if (t->fisheyeParams.animate) {
	view->active_frame = 0;
	g_timer_start(view->timer);
    }

}
Example #9
0
/* To use:
 * double* x_coords; // initial x coordinates
 * double* y_coords; // initial y coordinates
 * focus_t* fs;
 * int ne;
 * v_data* graph = makeGraph (topview*, &ne);
 * hierarchy = makeHier(topview->NodeCount, ne, graph, x_coords, y_coords);
 * freeGraph (graph);
 * fs = initFocus (topview->Nodecount); // create focus set
 */
void prepare_topological_fisheye(Agraph_t* g,topview * t)
{
    double *x_coords = N_NEW(t->Nodecount, double);	// initial x coordinates
    double *y_coords = N_NEW(t->Nodecount, double);	// initial y coordinates
    focus_t *fs;
    int ne;
    int i;
    int closest_fine_node;
    int cur_level = 0;
    Hierarchy *hp;
    ex_vtx_data *gg;
    gvcolor_t cl;
    Agnode_t *np;

    v_data *graph = makeGraph(g, &ne);

//      t->fisheyeParams.animate=1;   //turn the animation on
    i=0;
    for (np = agfstnode(g); np; np = agnxtnode(g, np)) 
    {
	x_coords[i]=ND_A(np).x;
	y_coords[i]=ND_A(np).y;
	i++;
    }
    hp = t->fisheyeParams.h =
	makeHier(agnnodes(g), ne, graph, x_coords, y_coords,
		 &(t->fisheyeParams.hier));
    freeGraph(graph);
    free(x_coords);
    free(y_coords);

    fs = t->fisheyeParams.fs = initFocus(agnnodes(g));	// create focus set
    gg = hp->geom_graphs[0];

    closest_fine_node = 0;	/* first node */
    fs->num_foci = 1;
    fs->foci_nodes[0] = closest_fine_node;
    fs->x_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].x_coord;
    fs->y_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].y_coord;

    view->Topview->fisheyeParams.repos.width =
	(int) (view->bdxRight - view->bdxLeft);
    view->Topview->fisheyeParams.repos.height =
	(int) (view->bdyTop - view->bdyBottom);
    view->Topview->fisheyeParams.repos.rescale = Polar;

    //topological fisheye 

    colorxlate(get_attribute_value
	       ("topologicalfisheyefinestcolor", view,
		view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
    view->Topview->fisheyeParams.srcColor.R = (float) cl.u.RGBA[0];
    view->Topview->fisheyeParams.srcColor.G = (float) cl.u.RGBA[1];
    view->Topview->fisheyeParams.srcColor.B = (float) cl.u.RGBA[2];
    colorxlate(get_attribute_value
	       ("topologicalfisheyecoarsestcolor", view,
		view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
    view->Topview->fisheyeParams.tarColor.R = (float) cl.u.RGBA[0];
    view->Topview->fisheyeParams.tarColor.G = (float) cl.u.RGBA[1];
    view->Topview->fisheyeParams.tarColor.B = (float) cl.u.RGBA[2];


    sscanf(agget
	   (view->g[view->activeGraph],
	    "topologicalfisheyedistortionfactor"), "%lf",
	   &view->Topview->fisheyeParams.repos.distortion);
    sscanf(agget
	   (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
	   "%d", &view->Topview->fisheyeParams.level.num_fine_nodes);
    sscanf(agget
	   (view->g[view->activeGraph],
	    "topologicalfisheyecoarseningfactor"), "%lf",
	   &view->Topview->fisheyeParams.level.coarsening_rate);
    sscanf(agget
	   (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
	   "%d", &view->Topview->fisheyeParams.hier.dist2_limit);
    sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
	   "%d", &view->Topview->fisheyeParams.animate);

    set_active_levels(hp, fs->foci_nodes, fs->num_foci, &(t->fisheyeParams.level));
    positionAllItems(hp, fs, &(t->fisheyeParams.repos));
    refresh_old_values(t);

/* fprintf (stderr, "No. of active nodes = %d\n", count_active_nodes(hp)); */

}
Example #10
0
static void
theme_parser_start_element (GMarkupParseContext  *context,
                            const gchar          *element_name,
                            const gchar         **attribute_names,
                            const gchar         **attribute_values,
                            gpointer              user_data,
                            GError              **error)
{
  const gchar *prop_value;
  Theme *theme = THEME (user_data);
  ThemePrivate *priv = theme->priv;

  if (!g_strcmp0 (element_name, "theme")) {
    prop_value = get_attribute_value ("name", attribute_names, attribute_values);
    priv->name = g_strdup (prop_value);
  } else if (!g_strcmp0 (element_name, "icon")) {
    gchar *src;
    GdkPixbuf *pixbuf;
    gint alpha = 255;

    src = g_build_filename (theme->priv->path, 
                            get_attribute_value ("src", attribute_names, attribute_values),
                            NULL);

    prop_value = get_attribute_value ("alpha", attribute_names, attribute_values);

    if (prop_value != NULL)
      alpha = CLAMP (atoi (prop_value), 0, 255);

    if (theme->priv->tile_width == 0) {
      pixbuf = gdk_pixbuf_new_from_file (src, NULL);
      if (pixbuf != NULL) {
        theme->priv->tile_width = gdk_pixbuf_get_width (pixbuf);
        theme->priv->tile_height = gdk_pixbuf_get_height (pixbuf);
        g_object_unref (pixbuf);
      }
    }

    theme_add_image (theme, src, alpha);

    g_free (src);
  } else if (!g_strcmp0 (element_name, "animstep")) {
    priv->animstep = atoi (get_attribute_value ("dist", attribute_names, 
                                                    attribute_values));
  } else if (!g_strcmp0 (element_name, "bgcolor")) {
    /* handle background color */
    prop_value = get_attribute_value ("color", attribute_names, attribute_values);
    gdk_rgba_parse (&(priv->bg_color), prop_value);
  } else if (!g_strcmp0 (element_name, "bgcolor_rgb")) {
    /* handle rgb color node */
    prop_value = get_attribute_value ("red", attribute_names, attribute_values);
    priv->bg_color.red = (atof (prop_value) / 255.0) * 65536;
    prop_value = get_attribute_value ("blue", attribute_names, attribute_values);
    priv->bg_color.blue = (atof (prop_value) / 255.0) * 65536;
    prop_value = get_attribute_value ("green", attribute_names, attribute_values);
    priv->bg_color.green = (atof (prop_value) / 255.0) * 65536;
  } else if (!g_strcmp0 (element_name, "decor")) {
    gchar *src;
    const gchar *base;
    GQuark base_id;
    GQuark decor_id;
    gint alpha = 255;

    src = g_build_filename (theme->priv->path, 
                            get_attribute_value ("src", attribute_names, attribute_values),
                            NULL);

    prop_value = get_attribute_value ("alpha", attribute_names, attribute_values);
    if (prop_value != NULL) {
      alpha = CLAMP (atoi (prop_value), 0, 255);
    }

    decor_id = theme_add_image (theme, src, alpha);
    g_free (src);

    base = get_attribute_value ("base", attribute_names, attribute_values);
    if (base == NULL)
      return;

    base_id = g_quark_from_string (base);
    theme_add_image_decoration (theme, base_id, decor_id);
  }
}
Example #11
0
PKCS11_EC_PrivateKey::PKCS11_EC_PrivateKey(Session& session, ObjectHandle handle)
   : Object(session, handle), m_domain_params(), m_public_key()
   {
   secure_vector<uint8_t> ec_parameters = get_attribute_value(AttributeType::EcParams);
   m_domain_params = EC_Group(unlock(ec_parameters));
   }
Example #12
0
std::vector<std::string> XAttrManager::get_xattr_list() throw (XAttrManagerException)
{
	std::vector<std::string> result;

    int size = listxattr(_filename.c_str(), NULL, 0);

    // Assume at first that the length of every element will be at most 30 chars
	size = size*30;
	char* buffer = new char[size];

	int num_elems;
	num_elems = listxattr(_filename.c_str(), buffer, size);

	while ((num_elems == -1) && (errno == ERANGE))
	{
		delete[] buffer;
		size = size*2;
		buffer = new char[size];
		num_elems = listxattr(_filename.c_str(), buffer, size);
	}

	// num_elems == -1 && errno != ERANGE
	if (num_elems == -1)
	{
		delete[] buffer;
		throw XAttrManagerException(Glib::locale_to_utf8(strerror(errno)));
	}

	for (int begin = 0, current = 0; current < num_elems; current++)
	{
		if (buffer[current] == '\0')
		{
			// Get the value
			std::string attr_name(&buffer[begin]);

            // Some filesystems give too small results
            if (attr_name.size() > 5)
            {
                std::string prefix =  attr_name.substr(0, 5);
                std::string postfix = attr_name.substr(5);

                // Check the prefix, we only want user_xattr
                if (prefix == "user.")
                {
                    bool is_empty = false;

                    try
                    {
                        std::string attribute_value = get_attribute_value(postfix);
                    }
                    catch (XAttrManagerException e)
                    {
                        is_empty = true;
                    }

                    if (!is_empty)
                    {
                        result.push_back(postfix);
                    }
                }
            }
			
			begin = current + 1;
		}
	}
	
	delete[] buffer;

	return result;
}
Example #13
0
void XAttrManager::change_attribute_name(std::string old_attr_name, std::string new_attr_name)
{
	std::string attribute_value = get_attribute_value(old_attr_name);
	add_attribute(new_attr_name, attribute_value);
	remove_attribute(old_attr_name);
}
Example #14
0
PKCS11_X509_Certificate::PKCS11_X509_Certificate(Session& session, ObjectHandle handle)
   : Object(session, handle), X509_Certificate(unlock(get_attribute_value(AttributeType::Value)))
   {
   }