Esempio n. 1
0
static void
scenario_summary (WorkbookControl *wbc,
		  Sheet           *sheet,
		  GSList          *results,
		  Sheet           **new_sheet)
{
	summary_cb_t cb;
	GList        *cur;
	GList        *scenarios = sheet->scenarios;

	/* Initialize: Currently only new sheet output supported. */
	dao_init_new_sheet (&cb.dao);
	dao_prepare_output (wbc, &cb.dao, _("Scenario Summary"));

	/* Titles. */
	dao_set_cell (&cb.dao, 1, 1, _("Current Values"));
	dao_set_cell (&cb.dao, 0, 2, _("Changing Cells:"));

	/* Go through all scenarios. */
	cb.row     = 0;
	cb.names   = g_hash_table_new (g_str_hash, g_str_equal);
	cb.sheet   = sheet;
	cb.results = results;
	for (cb.col = 0, cur = scenarios; cur != NULL; cb.col++,
		     cur = cur->next) {
		GnmScenario *s = cur->data;

		/* Scenario name. */
		dao_set_cell (&cb.dao, 2 + cb.col, 1, s->name);

		scenario_for_each_value (s, (ScenarioValueCB) summary_cb, &cb);
	}

	/* Set the alignment of names of the changing cells to be right. */
	dao_set_align (&cb.dao, 0, 3, 0, 2 + cb.row, GNM_HALIGN_RIGHT,
		       GNM_VALIGN_BOTTOM);

	/* Result cells. */
	if (results != NULL)
		scenario_summary_res_cells (wbc, results, &cb);

	/* Destroy the hash table. */
	g_hash_table_foreach (cb.names, (GHFunc) rm_fun_cb, NULL);
	g_hash_table_destroy (cb.names);

	/* Clean up the report output. */
	dao_set_bold (&cb.dao, 0, 0, 0, 2 + cb.row);
	dao_autofit_columns (&cb.dao);
	dao_set_cell (&cb.dao, 0, 0, _("Scenario Summary"));

	dao_set_colors (&cb.dao, 0, 0, cb.col + 1, 1,
			gnm_color_new_go (GO_COLOR_WHITE),
			gnm_color_new_go (DARK_GRAY));
	dao_set_colors (&cb.dao, 0, 2, 0, 2 + cb.row,
			gnm_color_new_go (GO_COLOR_BLACK),
			gnm_color_new_go (LIGHT_GRAY));

	dao_set_align (&cb.dao, 1, 1, cb.col + 1, 1, GNM_HALIGN_RIGHT,
		       GNM_VALIGN_BOTTOM);

	*new_sheet = cb.dao.sheet;
}
Esempio n. 2
0
static void server_init(IRC_SERVER_REC *server)
{
	IRC_SERVER_CONNECT_REC *conn;
	char *address, *ptr, *username, *cmd;
	GTimeVal now;

	g_return_if_fail(server != NULL);

	conn = server->connrec;

	if (conn->proxy != NULL && conn->proxy_password != NULL &&
	    *conn->proxy_password != '\0') {
		cmd = g_strdup_printf("PASS %s", conn->proxy_password);
		irc_send_cmd_now(server, cmd);
		g_free(cmd);
	}

	if (conn->proxy != NULL && conn->proxy_string != NULL) {
		cmd = g_strdup_printf(conn->proxy_string, conn->address, conn->port);
		irc_send_cmd_now(server, cmd);
		g_free(cmd);
	}

	if (conn->password != NULL && *conn->password != '\0') {
                /* send password */
		cmd = g_strdup_printf("PASS %s", conn->password);
		irc_send_cmd_now(server, cmd);
		g_free(cmd);
	}

        /* send nick */
	cmd = g_strdup_printf("NICK %s", conn->nick);
	irc_send_cmd_now(server, cmd);
	g_free(cmd);

	/* send user/realname */
	address = server->connrec->address;
        ptr = strrchr(address, ':');
	if (ptr != NULL) {
		/* IPv6 address .. doesn't work here, use the string after
		   the last : char */
		address = ptr+1;
		if (*address == '\0')
			address = "x";
	}

	username = g_strdup(conn->username);
	ptr = strchr(username, ' ');
	if (ptr != NULL) *ptr = '\0';

	cmd = g_strdup_printf("USER %s %s %s :%s", username, username, address, conn->realname);
	irc_send_cmd_now(server, cmd);
	g_free(cmd);
	g_free(username);

	if (conn->proxy != NULL && conn->proxy_string_after != NULL) {
		cmd = g_strdup_printf(conn->proxy_string_after, conn->address, conn->port);
		irc_send_cmd_now(server, cmd);
		g_free(cmd);
	}

	server->isupport = g_hash_table_new((GHashFunc) g_istr_hash,
					    (GCompareFunc) g_istr_equal);

	/* set the standards */
	g_hash_table_insert(server->isupport, g_strdup("CHANMODES"), g_strdup("beI,k,l,imnpst"));
	g_hash_table_insert(server->isupport, g_strdup("PREFIX"), g_strdup("(ohv)@%+"));

	server->cmdcount = 0;

	/* prevent the queue from sending too early, we have a max cut off of 120 secs */
	/* this will reset to 1 sec after we get the 001 event */
	g_get_current_time(&now);
	memcpy(&((IRC_SERVER_REC *)server)->wait_cmd, &now, sizeof(GTimeVal));
	((IRC_SERVER_REC *)server)->wait_cmd.tv_sec += 120;
}
static void
rb_removable_media_manager_init (RBRemovableMediaManager *mgr)
{
	RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (mgr);

	priv->volume_mapping = g_hash_table_new (NULL, NULL);
	priv->mount_mapping = g_hash_table_new (NULL, NULL);
	priv->device_mapping = g_hash_table_new_full (uint64_hash, uint64_equal, g_free, NULL);

	/*
	 * Monitor new (un)mounted file systems to look for new media;
	 * we watch for both volumes and mounts because for some devices,
	 * we don't require the volume to actually be mounted.
	 *
	 * both pre-unmount and unmounted callbacks are registered because it is
	 * better to do it before the unmount, but sometimes we don't get those
	 * (e.g. someone pressing the eject button on a cd drive). If we get the
	 * pre-unmount signal, the corresponding unmounted signal is ignored
	 */
	priv->volume_monitor = g_object_ref (g_volume_monitor_get ());

	priv->volume_added_id = g_signal_connect_object (priv->volume_monitor,
							 "volume-added",
							 G_CALLBACK (volume_added_cb),
							 mgr, 0);
	priv->volume_removed_id = g_signal_connect_object (priv->volume_monitor,
							   "volume-removed",
							   G_CALLBACK (volume_removed_cb),
							   mgr, 0);
	priv->mount_added_id = g_signal_connect_object (priv->volume_monitor,
							"mount-added",
							G_CALLBACK (mount_added_cb),
							mgr, 0);
	priv->mount_pre_unmount_id = g_signal_connect_object (priv->volume_monitor,
							      "mount-pre-unmount",
							      G_CALLBACK (mount_removed_cb),
							      mgr, 0);
	priv->mount_removed_id = g_signal_connect_object (priv->volume_monitor,
							  "mount-removed",
							  G_CALLBACK (mount_removed_cb),
							  mgr, 0);

#if defined(HAVE_GUDEV)
	/*
	 * Monitor udev device events - we're only really interested in events
	 * for USB devices.
	 */
	{
		const char * const subsystems[] = { "usb", NULL };
		priv->gudev_client = g_udev_client_new (subsystems);
	}

	priv->uevent_id = g_signal_connect_object (priv->gudev_client,
						   "uevent",
						   G_CALLBACK (uevent_cb),
						   mgr, 0);
#endif

	/* enable debugging of media player device lookups if requested */
	if (rb_debug_matches ("mpid", "")) {
		mpid_enable_debug (TRUE);
	}
}
Esempio n. 4
0
static void
gdict_sidebar_init (GdictSidebar *sidebar)
{
  GdictSidebarPrivate *priv;
  GtkWidget *hbox;
  GtkWidget *select_hbox;
  GtkWidget *select_button;
  GtkWidget *close_button;
  GtkWidget *arrow;

  sidebar->priv = priv = GDICT_SIDEBAR_GET_PRIVATE (sidebar);

  /* we store all the pages inside the list, but we keep
   * a pointer inside the hash table for faster look up
   * times; what's inside the table will be destroyed with
   * the list, so there's no need to supply the destroy
   * functions for keys and values.
   */
  priv->pages = NULL;
  priv->pages_by_id = g_hash_table_new (g_str_hash, g_str_equal);

  /* top option menu */
  hbox = gtk_hbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (sidebar), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);
  priv->hbox = hbox;

  select_button = gtk_toggle_button_new ();
  gtk_button_set_relief (GTK_BUTTON (select_button), GTK_RELIEF_NONE);
  g_signal_connect (select_button, "button-press-event",
		    G_CALLBACK (gdict_sidebar_select_button_press_cb),
		    sidebar);
  g_signal_connect (select_button, "key-press-event",
		    G_CALLBACK (gdict_sidebar_select_key_press_cb),
		    sidebar);
  priv->select_button = select_button;

  select_hbox = gtk_hbox_new (FALSE, 0);
  
  priv->label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (select_hbox), priv->label, FALSE, FALSE, 0);
  gtk_widget_show (priv->label);

  arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
  gtk_box_pack_end (GTK_BOX (select_hbox), arrow, FALSE, FALSE, 0);
  gtk_widget_show (arrow);

  gtk_container_add (GTK_CONTAINER (select_button), select_hbox);
  gtk_widget_show (select_hbox);

  gtk_box_pack_start (GTK_BOX (hbox), select_button, TRUE, TRUE, 0);
  gtk_widget_show (select_button);

  close_button = gtk_button_new ();
  gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
  gtk_button_set_image (GTK_BUTTON (close_button),
		        gtk_image_new_from_stock (GTK_STOCK_CLOSE,
						  GTK_ICON_SIZE_SMALL_TOOLBAR));
  g_signal_connect (close_button, "clicked",
		    G_CALLBACK (gdict_sidebar_close_clicked_cb),
		    sidebar);
  gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
  gtk_widget_show (close_button);
  priv->close_button = close_button;

  sidebar->priv->menu = gtk_menu_new ();
  g_signal_connect (sidebar->priv->menu, "deactivate",
		    G_CALLBACK (gdict_sidebar_menu_deactivate_cb),
		    sidebar);
  gtk_menu_attach_to_widget (GTK_MENU (sidebar->priv->menu),
		  	     GTK_WIDGET (sidebar),
			     gdict_sidebar_menu_detach_cb);
  gtk_widget_show (sidebar->priv->menu);

  sidebar->priv->notebook = gtk_notebook_new ();
  gtk_notebook_set_show_border (GTK_NOTEBOOK (sidebar->priv->notebook), FALSE);
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (sidebar->priv->notebook), FALSE);
  gtk_box_pack_start (GTK_BOX (sidebar), sidebar->priv->notebook, TRUE, TRUE, 6);
  gtk_widget_show (sidebar->priv->notebook);
}
Esempio n. 5
0
static void
load_from_metadata(
    gpointer data,
    gpointer user_data
    )
{
    const char* fully_qualified_prefix = data;
    GtkgEvasSprite* ev = user_data;
    char* full_buffer;
    char* filen;
    char* edb_prefix = 0;
    char* p = 0;
    E_DB_File* edb = 0;
    gboolean loaded=1;
    GHashTable* hash_args = 0;
    char* strbuf1 = 0;
    
    
    g_return_if_fail(ev != NULL);
	g_return_if_fail(fully_qualified_prefix!= NULL);
    g_return_if_fail(GTK_IS_GEVAS_SPRITE(ev));

    if( ev->metadata_load_loaded )
    {
        return;
    }
    
/*     printf("SPRITE load_from_metadata() fully_qualified_prefix: %s\n", */
/*            fully_qualified_prefix); */

/*     printf("SPRITE load_from_metadata() ev->metadata_load_postfix:%s\n", */
/*            ev->metadata_load_postfix); */
    
    
    if( strlen( fully_qualified_prefix ))
    {
        full_buffer = g_strconcat( fully_qualified_prefix,
                                   "/", ev->metadata_load_postfix,0 );
    }
    else
    {
        full_buffer = g_strdup(ev->metadata_load_postfix);
    }


/*     printf("full_buffer:%s\n",full_buffer ); */
    filen = strbuf1 = url_file_name_part_new( full_buffer );
    hash_args       = url_args_to_hash( full_buffer );

    g_free(full_buffer);

    filen = gevas_trim_prefix("file:",filen);
    edb_prefix = url_args_lookup_str(hash_args, "prefix", "" );
    
/*     printf("load_from_metadata() filen      :%s\n",filen); */
/*     printf("load_from_metadata() edb_prefix :%s\n",edb_prefix); */
    
    
    edb = e_db_open(filen);

    if( edb )
    {
        gint  idx   = 0;
        gint  count = 0;
        char* t     = 0;
        int   rc    = 0;
        gint  n     = 0;

/*         printf("load_from_metadata() loaded edb\n"); */


        t  = g_strconcat( edb_prefix, "/Count",0 );
        rc = e_db_int_get(edb, t, &count);
        g_free(t);

        if( rc == 1 )
        {

/*             printf("load_from_metadata() count:%d\n",count); */
        
   
            for( idx = 0; loaded && idx < count ; idx++ )
            {
                GtkgEvasImage* o = gevasimage_new();
                char* image_name = 0;

                t = g_strdup_printf("%s/%d/Location",edb_prefix,idx);
/*                 printf("load_from_metadata() image_name comes from loc:%s\n",t); */
                image_name=e_db_str_get(edb, t);
                g_free(t);

/*                 printf("load_from_metadata() image_name:%s\n",image_name); */

                if(!(o = gevasimage_new_from_metadata( GEVAS(ev), image_name )))
                {
                    loaded=0;
                }
                else
                {
                    gevas_obj_collection_add( ev->col, GTK_GEVASOBJ(o) );
                }
                
                g_free(image_name);
            }
            
            if(loaded && !(idx < count))
            {
                char* p = edb_prefix;
                GHashTable* def_hash_args = g_hash_table_new( g_str_hash, g_str_equal );
                
                ev->metadata_load_loaded = 1;

                edb_to_hash_int( edb, def_hash_args, "default_frame_delay", p, 0 );
                edb_to_hash_int( edb, def_hash_args, "x", p, 0 );
                edb_to_hash_int( edb, def_hash_args, "y", p, 0 );
                edb_to_hash_int( edb, def_hash_args, "visible", p, 0 );
                edb_to_hash_int( edb, def_hash_args, "play_forever", p, 0 );

                setup_attribs( ev, def_hash_args );
                setup_attribs( ev, hash_args );

                hash_str_str_clean( def_hash_args );
            }
            e_db_close(edb);
        }
        
    }
    

    hash_str_str_clean( hash_args );
    g_free(strbuf1);

}
Esempio n. 6
0
static GString *
metadata_create_static (MetaBuilder *builder,
			guint32 *random_tag_out)
{
  GString *out;
  GHashTable *hash, *key_hash;
  GHashTableIter iter;
  char *key;
  GList *keys, *l;
  GHashTable *strings;
  guint32 index;
  guint32 attributes_pointer;
  gint64 time_t_min;
  gint64 time_t_max;
  guint32 random_tag, root_name;

  out = g_string_new (NULL);

  /* HEADER */
  g_string_append_c (out, 0xda);
  g_string_append_c (out, 0x1a);
  g_string_append_c (out, 'm');
  g_string_append_c (out, 'e');
  g_string_append_c (out, 't');
  g_string_append_c (out, 'a');

  /* VERSION */
  g_string_append_c (out, MAJOR_VERSION);
  g_string_append_c (out, MINOR_VERSION);

  append_uint32 (out, 0, NULL); /* Rotated */
  random_tag = g_random_int ();
  *random_tag_out = random_tag;
  append_uint32 (out, random_tag, NULL);
  append_uint32 (out, 0, &builder->root_pointer);
  append_uint32 (out, 0, &attributes_pointer);

  time_t_min = 0;
  time_t_max = 0;
  metafile_collect_times (builder->root, &time_t_min, &time_t_max);

  /* Store the base as the min value in use minus one so that
     0 is free to mean "not defined" */
  time_t_min = time_t_min - 1;

  /* Pick the base as the minimum, unless that leads to
     a 32bit overflow */
  if (time_t_max - time_t_min > G_MAXUINT32)
    time_t_min = time_t_max - G_MAXUINT32;
  builder->time_t_base = time_t_min;
  append_int64 (out, builder->time_t_base);

  /* Collect and sort all used keys */
  hash = g_hash_table_new (g_str_hash, g_str_equal);
  metafile_collect_keywords (builder->root, hash);
  g_hash_table_iter_init (&iter, hash);
  keys = NULL;
  while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL))
    keys = g_list_prepend (keys, key);
  g_hash_table_destroy (hash);
  keys = g_list_sort (keys, (GCompareFunc)strcmp);

  /* Write keys to file and collect mapping for keys */
  set_uint32 (out, attributes_pointer, out->len);
  key_hash = g_hash_table_new (g_str_hash, g_str_equal);
  strings = string_block_begin ();
  append_uint32 (out, g_list_length (keys), NULL);
  for (l = keys, index = 0; l != NULL; l = l->next, index++)
    {
      key = l->data;
      append_string (out, key, strings);
      g_hash_table_insert (key_hash, key, GUINT_TO_POINTER (index));
    }
  string_block_end (out, strings);

  /* update root pointer */
  set_uint32 (out, builder->root_pointer, out->len);

  /* Root name */
  append_uint32 (out, 0, &root_name);

  /* Root child pointer */
  append_uint32 (out, 0, &builder->root->children_pointer);

  /* Root metadata pointer */
  append_uint32 (out, 0, &builder->root->metadata_pointer);

  /* Root last changed */
  append_uint32 (out, builder->root->last_changed, NULL);

  /* Root name */
  set_uint32 (out, root_name, out->len);
  g_string_append_len (out, "/", 2);

  /* Pad to 32bit */
  while (out->len % 4 != 0)
    g_string_append_c (out, 0);

  write_children (out, builder);
  write_metadata (out, builder, key_hash);

  g_hash_table_destroy (key_hash);
  g_list_free (keys);

  return out;
}
Esempio n. 7
0
static void
bookmarks_load_hash(struct bookmarks *this_) {
	struct bookmark_item_priv *b_item;
	struct item *item;
	struct attr attr;
	struct coord c;
	char *pos,*finder;
	char *copy_helper;

	if (this_->mr) {
		map_rect_destroy(this_->mr);
	}
	this_->mr=map_rect_new(this_->bookmark, NULL);

	this_->bookmarks_hash=g_hash_table_new(g_str_hash, g_str_equal);
	this_->root=g_new0(struct bookmark_item_priv,1);
	this_->root->type=type_none;
	this_->root->parent=NULL;
	this_->root->children=NULL;
	bookmarks_move_root(this_);

	while ((item=map_rect_get_item(this_->mr))) {
		if (item->type != type_bookmark && item->type != type_bookmark_folder ) continue;
		if (!item_attr_get(item, attr_path, &attr)) {
			item_attr_get(item, attr_label, &attr);
		}
		item_coord_get(item, &c, 1);

		b_item=g_new0(struct bookmark_item_priv,1);
		b_item->c.x=c.x;
		b_item->c.y=c.y;
		b_item->label=g_strdup(attr.u.str);
		b_item->type=item->type;
		b_item->item=*item;

		//Prepare position
		bookmarks_move_root(this_);
		finder=b_item->label;
		while ((pos=strchr(finder,'/'))) {
			*pos=0x00;
			dbg(1,"Found path entry: %s\n",finder);
			if (!bookmarks_move_down(this_,finder)) {
				struct bookmark_item_priv *path_item=g_new0(struct bookmark_item_priv,1);
				path_item->type=type_bookmark_folder;
				path_item->parent=this_->current;
				path_item->children=NULL;
				path_item->label=g_strdup(finder);

				this_->current->children=g_list_append(this_->current->children,path_item);
				this_->current=path_item;
				g_hash_table_insert(this_->bookmarks_hash,b_item->label,path_item);
				this_->bookmarks_list=g_list_append(this_->bookmarks_list,path_item);
			}
			finder+=strlen(finder)+1;
		}
		copy_helper=g_strdup(finder);
		free(b_item->label);
		b_item->label=copy_helper;
		b_item->parent=this_->current;

		g_hash_table_insert(this_->bookmarks_hash,b_item->label,b_item);
		this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);
		this_->current->children=g_list_append(this_->current->children,b_item);
		this_->current->children=g_list_first(this_->current->children);
		dbg(1,"Added %s to %s and current list now %u long\n",b_item->label,this_->current->label,g_list_length(this_->current->children));
	}
	bookmarks_move_root(this_);
}
static void
get_locale_infos (GtkWidget *chooser)
{
  CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
  GHashTable *layouts_with_locale;
  LocaleInfo *info;
  gchar **locale_ids;
  gchar **locale;
  GList *list, *l;

  priv->locales = g_hash_table_new_full (g_str_hash, g_str_equal,
                                         NULL, locale_info_free);
  priv->locales_by_language = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                     g_free, (GDestroyNotify) g_hash_table_destroy);

  layouts_with_locale = g_hash_table_new (g_str_hash, g_str_equal);

  locale_ids = gnome_get_all_locales ();
  for (locale = locale_ids; *locale; ++locale)
    {
      gchar *lang_code, *country_code;
      gchar *simple_locale;
      gchar *tmp;
      const gchar *type = NULL;
      const gchar *id = NULL;

      if (!gnome_parse_locale (*locale, &lang_code, &country_code, NULL, NULL))
        continue;

      simple_locale = g_strdup_printf ("%s_%s.utf8", lang_code, country_code);
      if (g_hash_table_contains (priv->locales, simple_locale))
        {
          g_free (simple_locale);
          g_free (country_code);
          g_free (lang_code);
          continue;
        }

      info = g_new0 (LocaleInfo, 1);
      info->id = simple_locale; /* Take ownership */
      info->name = gnome_get_language_from_locale (simple_locale, NULL);
      info->unaccented_name = cc_util_normalize_casefold_and_unaccent (info->name);
      tmp = gnome_get_language_from_locale (simple_locale, "C");
      info->untranslated_name = cc_util_normalize_casefold_and_unaccent (tmp);
      g_free (tmp);

      g_hash_table_replace (priv->locales, simple_locale, info);
      add_locale_to_table (priv->locales_by_language, lang_code, info);

      if (gnome_get_input_source_from_locale (simple_locale, &type, &id) &&
          g_str_equal (type, INPUT_SOURCE_TYPE_XKB))
        {
          add_default_widget (chooser, info, type, id);
          g_hash_table_add (layouts_with_locale, (gpointer) id);
        }

      /* We don't own these ids */
      info->layout_widgets_by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                          NULL, g_object_unref);
      info->engine_widgets_by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                          NULL, g_object_unref);

      list = gnome_xkb_info_get_layouts_for_language (priv->xkb_info, lang_code);
      add_widgets_to_table (chooser, info, list, INPUT_SOURCE_TYPE_XKB, id);
      add_ids_to_set (layouts_with_locale, list);
      g_list_free (list);

      list = gnome_xkb_info_get_layouts_for_country (priv->xkb_info, country_code);
      add_widgets_to_table (chooser, info, list, INPUT_SOURCE_TYPE_XKB, id);
      add_ids_to_set (layouts_with_locale, list);
      g_list_free (list);

      g_free (lang_code);
      g_free (country_code);
    }
  g_strfreev (locale_ids);

  /* Add a "Other" locale to hold the remaining input sources */
  info = g_new0 (LocaleInfo, 1);
  info->id = g_strdup ("");
  info->name = g_strdup (_("Other"));
  info->unaccented_name = g_strdup ("");
  info->untranslated_name = g_strdup ("");
  g_hash_table_replace (priv->locales, info->id, info);

  info->layout_widgets_by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                      NULL, g_object_unref);
  info->engine_widgets_by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                      NULL, g_object_unref);

  list = gnome_xkb_info_get_all_layouts (priv->xkb_info);
  for (l = list; l; l = l->next)
    if (!g_hash_table_contains (layouts_with_locale, l->data))
      add_widget_other (chooser, INPUT_SOURCE_TYPE_XKB, l->data);

  g_list_free (list);

  g_hash_table_destroy (layouts_with_locale);
}
Esempio n. 9
0
void
nemo_create_thumbnail (NemoFile *file)
{
	time_t file_mtime = 0;
	NemoThumbnailInfo *info;
	NemoThumbnailInfo *existing_info;
	GList *existing, *node;

	nemo_file_set_is_thumbnailing (file, TRUE);

	info = g_new0 (NemoThumbnailInfo, 1);
	info->image_uri = nemo_file_get_uri (file);
	info->mime_type = nemo_file_get_mime_type (file);
	
	/* Hopefully the NemoFile will already have the image file mtime,
	   so we can just use that. Otherwise we have to get it ourselves. */
	if (file->details->got_file_info &&
	    file->details->file_info_is_up_to_date &&
	    file->details->mtime != 0) {
		file_mtime = file->details->mtime;
	} else {
		get_file_mtime (info->image_uri, &file_mtime);
	}
	
	info->original_file_mtime = file_mtime;


#ifdef DEBUG_THUMBNAILS
	g_message ("(Main Thread) Locking mutex\n");
#endif
	pthread_mutex_lock (&thumbnails_mutex);
	
	/*********************************
	 * MUTEX LOCKED
	 *********************************/

	if (thumbnails_to_make_hash == NULL) {
		thumbnails_to_make_hash = g_hash_table_new (g_str_hash,
							    g_str_equal);
	}

	/* Check if it is already in the list of thumbnails to make. */
	existing = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri);
	if (existing == NULL) {
		/* Add the thumbnail to the list. */
#ifdef DEBUG_THUMBNAILS
		g_message ("(Main Thread) Adding thumbnail: %s\n",
			   info->image_uri);
#endif
		g_queue_push_tail ((GQueue *)&thumbnails_to_make, info);
		node = g_queue_peek_tail_link ((GQueue *)&thumbnails_to_make);
		g_hash_table_insert (thumbnails_to_make_hash,
				     info->image_uri,
				     node);
		/* If the thumbnail thread isn't running, and we haven't
		   scheduled an idle function to start it up, do that now.
		   We don't want to start it until all the other work is done,
		   so the GUI will be updated as quickly as possible.*/
		if (thumbnail_thread_is_running == FALSE &&
		    thumbnail_thread_starter_id == 0) {
			thumbnail_thread_starter_id = g_idle_add_full (G_PRIORITY_LOW, thumbnail_thread_starter_cb, NULL, NULL);
		}
	} else {
#ifdef DEBUG_THUMBNAILS
		g_message ("(Main Thread) Updating non-current mtime: %s\n",
			   info->image_uri);
#endif
		/* The file in the queue might need a new original mtime */
		existing_info = existing->data;
		existing_info->original_file_mtime = info->original_file_mtime;
		free_thumbnail_info (info);
	}   

	/*********************************
	 * MUTEX UNLOCKED
	 *********************************/

#ifdef DEBUG_THUMBNAILS
	g_message ("(Main Thread) Unlocking mutex\n");
#endif
	pthread_mutex_unlock (&thumbnails_mutex);
}
Esempio n. 10
0
GConfBackend* 
gconf_get_backend(const gchar* address, GError** err)
{
  GConfBackend* backend;
  gchar* name;
  gchar* why_invalid;

  if (loaded_backends == NULL)
    {
      loaded_backends = g_hash_table_new(g_str_hash, g_str_equal);
    }

  why_invalid = NULL;
  if (!gconf_address_valid (address, &why_invalid))
    {
      g_assert (why_invalid != NULL);
      gconf_set_error (err, GCONF_ERROR_BAD_ADDRESS, _("Bad address `%s': %s"),
		       address, why_invalid);
      g_free (why_invalid);
      return NULL;
    }

  name = gconf_address_backend(address);
      
  if (name == NULL)
    {
      gconf_set_error(err, GCONF_ERROR_BAD_ADDRESS, _("Bad address `%s'"), address);
      return NULL;
    }

  backend = g_hash_table_lookup(loaded_backends, name);

  if (backend != NULL)
    {
      /* Returning a "copy" */
      gconf_backend_ref(backend);
      g_free(name);
      return backend;
    }
  else
    {
      gchar* file;
          
      file = gconf_backend_file(address);
          
      if (file != NULL)
        {
          GModule* module;
          GConfBackendVTable* (*get_vtable)(void);

          if (!g_module_supported())
            g_error(_("GConf won't work without dynamic module support (gmodule)"));
              
          module = g_module_open(file, G_MODULE_BIND_LAZY);
              
          g_free(file);
          
          if (module == NULL)
            {
              gconf_set_error(err,
                              GCONF_ERROR_FAILED, _("Error opening module `%s': %s\n"),
                              name, g_module_error());
              g_free(name);
              return NULL;
            }

          if (!g_module_symbol(module, 
                               "gconf_backend_get_vtable", 
                               (gpointer*)&get_vtable))
            {
              gconf_set_error(err,
                              GCONF_ERROR_FAILED, _("Error initializing module `%s': %s\n"),
                              name, g_module_error());
              g_module_close(module);
              g_free(name);
              return NULL;
            }
          
          backend = g_new0(GConfBackend, 1);

          backend->module = module;

	  if (!gconf_backend_verify_vtable((*get_vtable)(), &backend->vtable, name, err))
	    {
	      g_module_close(module);
	      g_free(name);
	      g_free(backend);
	      return NULL;
	    }
              
          backend->name = name;

          g_hash_table_insert(loaded_backends, (gchar*)backend->name, backend);
          
          /* Returning a "copy" */
          gconf_backend_ref(backend);

          return backend;
        }
      else
        {
          gconf_set_error(err, GCONF_ERROR_FAILED,
                          _("Couldn't locate backend module for `%s'"), address);
          return NULL;
        }
    }
}
Esempio n. 11
0
/**
@brief iterate over active pane file list to check for matches
@param from the button, menu item etc which was activated
@param art action runtime data

@return TRUE if action completed successfully, else FALSE
*/
static gboolean _e2p_select_same (gpointer from, E2_ActionRuntime *art)
{
	E2_PaneRuntime *rt;
	ViewInfo *selview;
	GtkTreeModel *models;
	GtkTreeIter iters;

	rt = e2_pane_get_runtime (from, art->data, NULL);
	selview = (ViewInfo *)rt;
	WAIT_FOR_REFRESH(selview)
	models = selview->model;
	if (gtk_tree_model_get_iter_first (models, &iters))
	{	//it's not empty
		ViewInfo *othview;
		GtkTreeModel *modelo;
		GtkTreeSelection *sel;
		GList *selpaths, *rowpath;
		GHashTable *selitems;
		FileInfo *info;
		gboolean fullmatch, forward;
		const gchar *seps;

		e2_filelist_disable_refresh ();

		othview = (rt == curr_pane) ? &other_pane->view : &curr_pane->view;
		WAIT_FOR_REFRESH(othview)
		selpaths = gtk_tree_selection_get_selected_rows (othview->selection, &modelo);
		if (selpaths == NULL)
		{
			e2_filelist_enable_refresh ();
			return FALSE;
		}
		// art->action->data is NULL for full name-scan, non-NULL for partial
		fullmatch = (art->action->data == NULL);
		if (fullmatch)
		{	//warning prevention
			seps = NULL;
			forward = TRUE;
		}
		else
		{
			seps = e2_option_str_get ("selmatch-separators");
			if (seps != NULL && *seps == '\0')
			{
				fullmatch = TRUE;
				forward = TRUE;
			}
			else
				forward = e2_option_bool_get ("selmatch-start");
		}

		// Log the selected items, for quick lookup
		selitems = (fullmatch) ?
			g_hash_table_new (g_str_hash, g_str_equal):
			g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

		for (rowpath = selpaths; rowpath != NULL; rowpath = rowpath->next)
		{
			GtkTreePath *path;
			GtkTreeIter itero;
			path = (GtkTreePath *) rowpath->data;
			if (gtk_tree_model_get_iter (modelo, &itero, path))
			{
				gtk_tree_model_get (modelo, &itero, FINFO, &info, -1);
				if (fullmatch)
					g_hash_table_insert (selitems, info->filename, info); //no key dup, info must persist
				else
				{
					gchar c;
					gchar *target;
					if (forward)
					{
						for (target = info->filename; (c = *target) != '\0'; target++)
						{
							if (strchr (seps, c) != NULL) //assumes no UTF-8 chars
							{
								target = g_strndup (info->filename, target - info->filename);
								g_hash_table_insert (selitems, target, info);
								break;
							}
						}
						if (c == '\0')
							g_hash_table_insert (selitems, g_strdup (info->filename), info);
					}
					else
					{
						for (target = info->filename + strlen (info->filename) - 1 ;
							target >= info->filename; target--)
						{
							if (strchr (seps, *target) != NULL) //assumes no UTF-8 chars
							{
								target = g_strndup (info->filename, target - info->filename);
								g_hash_table_insert (selitems, target, info);
								break;
							}
						}
						if (target < info->filename)
							g_hash_table_insert (selitems, g_strdup (info->filename), info);
					}
				}
			}
			gtk_tree_path_free (path);
		}
		g_list_free (selpaths);

		sel = selview->selection;
		gtk_tree_selection_unselect_all (sel);	//start with clean slate
		do
		{
			gboolean partial;
			gchar *scan;

			gtk_tree_model_get (models, &iters, FINFO, &info, -1);
			//We only check for name, ignore other statbuf parameters
			partial = FALSE;
			scan = NULL;
			if (!fullmatch)
			{
				gchar c;
				if (forward)
				{
					for (scan = info->filename; (c = *scan) != '\0'; scan++)
					{
						if (strchr (seps, c) != NULL) //assumes no UTF-8 chars, too bad if different sep from other pane
						{
							partial = TRUE;
							break;
						}
					}
				}
				else
				{
					for (scan = info->filename + strlen (info->filename) - 1 ;
						scan >= info->filename; scan--)
					{
						c = *scan;
						if (strchr (seps, c) != NULL) //assumes no UTF-8 chars
						{
							partial = TRUE;
							break;
						}
					}
				}
			}
			if (partial)
				scan = g_strndup (info->filename, scan - info->filename);
			else
				scan = info->filename;
			if (g_hash_table_lookup (selitems, scan) != NULL)
				gtk_tree_selection_select_iter (sel, &iters);
			if (partial)
				g_free (scan);
		} while (gtk_tree_model_iter_next (models, &iters));

		g_hash_table_destroy (selitems);

		//ensure some part of selection is visible
		selpaths = gtk_tree_selection_get_selected_rows (sel, NULL);
		if (selpaths != NULL)
		{
			printd (DEBUG, "scroll to show selection");
			GtkTreePath *tpath = gtk_tree_path_copy ((GtkTreePath *)selpaths->data);
			//this kills other selections
			gtk_tree_view_set_cursor (GTK_TREE_VIEW (selview->treeview), tpath, NULL, FALSE);
			//so back again, and cleanup
			g_list_foreach (selpaths, (GFunc)_e2p_selsame_reselect, sel);
			g_list_free (selpaths);
			gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (selview->treeview), tpath,
					NULL, TRUE, 0.382, 0.0);
			gtk_tree_path_free (tpath);
		}

		e2_filelist_enable_refresh ();

		return TRUE;
	}
	return FALSE;
}
Esempio n. 12
0
/* if simulate==TRUE, return whether accel_path can be changed to
 * accel_key && accel_mods. otherwise, return whether accel_path
 * was actually changed.
 */
static gboolean
internal_change_entry (const gchar    *accel_path,
		       guint           accel_key,
		       GdkModifierType accel_mods,
		       gboolean        replace,
		       gboolean	       simulate)
{
  GSList *node, *slist, *win_list, *group_list, *replace_list = NULL;
  GHashTable *group_hm, *window_hm;
  gboolean change_accel, removable, can_change = TRUE, seen_accel = FALSE;
  GQuark entry_quark;
  AccelEntry *entry = accel_path_lookup (accel_path);

  /* not much todo if there's no entry yet */
  if (!entry)
    {
      if (!simulate)
	{
	  gtk_accel_map_add_entry (accel_path, 0, 0);
	  entry = accel_path_lookup (accel_path);
	  entry->accel_key = accel_key;
	  entry->accel_mods = accel_mods;
	  entry->changed = TRUE;

	  do_accel_map_changed (entry);
	}
      return TRUE;
    }

  /* if there's nothing to change, not much todo either */
  if (entry->accel_key == accel_key && entry->accel_mods == accel_mods)
    {
      if (!simulate)
	entry->changed = TRUE;
      return simulate ? TRUE : FALSE;
    }

  /* The no-change case has already been handled, so 
   * simulate doesn't make a difference here.
   */
  if (entry->lock_count > 0)
    return FALSE;

  /* nobody's interested, easy going */
  if (!entry->groups)
    {
      if (!simulate)
	{
	  entry->accel_key = accel_key;
	  entry->accel_mods = accel_mods;
	  entry->changed = TRUE;

	  do_accel_map_changed (entry);
	}
      return TRUE;
    }

  /* 1) fetch all accel groups affected by this entry */
  entry_quark = g_quark_try_string (entry->accel_path);
  group_hm = g_hash_table_new (NULL, NULL);
  window_hm = g_hash_table_new (NULL, NULL);
  for (slist = entry->groups; slist; slist = slist->next)
    g_hash_table_insert (group_hm, slist->data, slist->data);

  /* 2) collect acceleratables affected */
  group_list = g_hash_table_slist_values (group_hm);
  for (slist = group_list; slist; slist = slist->next)
    {
      GtkAccelGroup *group = slist->data;

      for (node = _gtk_accel_group_get_accelerables (group); node; node = node->next)
	g_hash_table_insert (window_hm, node->data, node->data);
    }
  g_slist_free (group_list);

  /* 3) include all accel groups used by acceleratables */
  win_list = g_hash_table_slist_values (window_hm);
  g_hash_table_destroy (window_hm);
  for (slist = win_list; slist; slist = slist->next)
    for (node = gtk_accel_groups_from_object (slist->data); node; node = node->next)
      g_hash_table_insert (group_hm, node->data, node->data);
  group_list = g_hash_table_slist_values (group_hm);
  g_hash_table_destroy (group_hm);
  
  /* 4) walk the acceleratables and figure whether they occupy accel_key&accel_mods */
  if (accel_key)
    for (slist = win_list; slist; slist = slist->next)
      if (GTK_IS_WINDOW (slist->data))	/* bad kludge in lack of a GtkAcceleratable */
	if (_gtk_window_query_nonaccels (slist->data, accel_key, accel_mods))
	  {
	    seen_accel = TRUE;
	    break;
	  }
  removable = !seen_accel;
  
  /* 5) walk all accel groups and search for locks */
  if (removable)
    for (slist = group_list; slist; slist = slist->next)
      {
	GtkAccelGroup *group = slist->data;
	GtkAccelGroupEntry *ag_entry;
	guint i, n;
	
	n = 0;
	ag_entry = entry->accel_key ? gtk_accel_group_query (group, entry->accel_key, entry->accel_mods, &n) : NULL;
	for (i = 0; i < n; i++)
	  if (ag_entry[i].accel_path_quark == entry_quark)
	    {
	      can_change = !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
	      if (!can_change)
		goto break_loop_step5;
	    }
	
	n = 0;
	ag_entry = accel_key ? gtk_accel_group_query (group, accel_key, accel_mods, &n) : NULL;
	for (i = 0; i < n; i++)
	  {
	    seen_accel = TRUE;
	    removable = !gtk_accel_group_get_is_locked (group) && !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
	    if (!removable)
	      goto break_loop_step5;
	    if (ag_entry[i].accel_path_quark)
	      replace_list = g_slist_prepend (replace_list, GUINT_TO_POINTER (ag_entry[i].accel_path_quark));
	  }
      }
 break_loop_step5:
  
  /* 6) check whether we can remove existing accelerators */
  if (removable && can_change)
    for (slist = replace_list; slist; slist = slist->next)
      if (!internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, TRUE))
	{
	  removable = FALSE;
	  break;
	}
  
  /* 7) check conditions and proceed if possible */
  change_accel = can_change && (!seen_accel || (removable && replace));
  
  if (change_accel && !simulate)
    {
      /* ref accel groups */
      for (slist = group_list; slist; slist = slist->next)
	g_object_ref (slist->data);

      /* 8) remove existing accelerators */
      for (slist = replace_list; slist; slist = slist->next)
	internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, FALSE);

      /* 9) install new accelerator */
      entry->accel_key = accel_key;
      entry->accel_mods = accel_mods;
      entry->changed = TRUE;

      for (slist = group_list; slist; slist = slist->next)
	_gtk_accel_group_reconnect (slist->data, g_quark_from_string (entry->accel_path));

      /* unref accel groups */
      for (slist = group_list; slist; slist = slist->next)
	g_object_unref (slist->data);

      do_accel_map_changed (entry);
    }
  g_slist_free (replace_list);
  g_slist_free (group_list);
  g_slist_free (win_list);

  return change_accel;
}
Esempio n. 13
0
void
_gtk_accel_map_init (void)
{
  if (accel_entry_ht == NULL)
    accel_entry_ht = g_hash_table_new (accel_entry_hash, accel_entry_equal);
}
Esempio n. 14
0
async_network_constructor(void)
{
    tasks_ht = g_hash_table_new(g_direct_hash, g_direct_equal);
    pthread_mutex_init(&lock, NULL);
}
Esempio n. 15
0
int taint_debug(int argc, char** argv)
{
    int infd = 0;
    struct taint_op top;
    long taint_ops = 0;
    struct stat buf;
    int rc;
    loff_t bytes_read = 0;

    char* group_dir;
    char taint_structures_filename[256];
    char results_filename[256];
    char filenames_filename[256];
    char options_filename[256];
    char tokens_filename[256];
    char debug_filename[256];

    if (argc < 2) {
        usage();
    }

    group_dir = argv[1];
    snprintf(taint_structures_filename, 256, "%s/taint_structures", group_dir);
    snprintf(results_filename, 256, "%s/dataflow.result", group_dir);
    snprintf(filenames_filename, 256, "%s/filenames", group_dir);
    snprintf(options_filename, 256, "%s/options", group_dir);
    snprintf(tokens_filename, 256, "%s/tokens", group_dir);
    snprintf(debug_filename, 256, "%s/trace_taint_ops", group_dir);

    leaf_node_table = g_hash_table_new(g_direct_hash, g_direct_equal);
    merge_node_table = g_hash_table_new(g_direct_hash, g_direct_equal);
    merge_index_table = g_hash_table_new(g_int64_hash, g_int64_equal);

    option_info_table = g_hash_table_new(g_direct_hash, g_direct_equal);
    filename_table = g_hash_table_new(g_direct_hash, g_direct_equal);

    taint_operations_table = g_hash_table_new(g_direct_hash, g_direct_equal);

    read_tokens(tokens_filename, option_info_table);
    read_filename_mappings(filenames_filename, filename_table);

    parse_taint_structures(taint_structures_filename,
                            leaf_node_table,
                            merge_node_table,
                            merge_index_table);


    infd = open(debug_filename, O_RDONLY | O_LARGEFILE);
    if (infd < 0) {
        fprintf(stderr, "could not open %s, rc %d, errno %d\n", debug_filename, infd, errno);
        exit(-1);
    }
    rc = fstat(infd, &buf);
    if (rc == -1) {
        fprintf(stderr, "could not stat debug file: %s, errno %d\n", debug_filename, errno);
        exit(-1);
    }

    while(bytes_read < buf.st_size) {
        bytes_read += read_taint_op_extended(infd, &top, 0);

        g_hash_table_insert(taint_operations_table,
                                GINT_TO_POINTER(top.taint_op),
                                GINT_TO_POINTER(1));

        taint_ops++;
        if (taint_ops % 1000000 == 0) {
            fprintf(stdout, "num taint ops %ld\n", taint_ops);
        }
    }
    fprintf(stdout, "debug done\n");

    print_unique_taint_ops(taint_operations_table);   

    return 0;
}
Esempio n. 16
0
static void
gftp_read_bookmarks (char *global_data_path)
{
  char *tempstr, *temp1str, buf[255], *curpos;
  gftp_config_vars * global_entry;
  gftp_bookmarks_var * newentry;
  FILE *bmfile;
  size_t len;
  int line;

  if ((tempstr = gftp_expand_path (NULL, BOOKMARKS_FILE)) == NULL)
    {
      printf (_("gFTP Error: Bad bookmarks file name %s\n"), BOOKMARKS_FILE);
      exit (EXIT_FAILURE);
    }

  if (access (tempstr, F_OK) == -1)
    {
      temp1str = g_strdup_printf ("%s/bookmarks", global_data_path);
      if (access (temp1str, F_OK) == -1)
	{
	  printf (_("Warning: Cannot find master bookmark file %s\n"),
		  temp1str);
	  g_free (temp1str);
	  return;
	}
      copyfile (temp1str, tempstr);
      g_free (temp1str);
    }

  if ((bmfile = fopen (tempstr, "r")) == NULL)
    {
      printf (_("gFTP Error: Cannot open bookmarks file %s: %s\n"), tempstr,
	      g_strerror (errno));
      exit (EXIT_FAILURE);
    }
  g_free (tempstr);

  line = 0;
  newentry = NULL;
  while (fgets (buf, sizeof (buf), bmfile))
    {
      len = strlen (buf);
      if (len > 0 && buf[len - 1] == '\n')
        buf[--len] = '\0';
      if (len > 0 && buf[len - 1] == '\r')
        buf[--len] = '\0';
      line++;

      if (*buf == '[')
	{
	  newentry = g_malloc0 (sizeof (*newentry));
          for (; buf[len - 1] == ' ' || buf[len - 1] == ']'; buf[--len] = '\0');
	  newentry->path = g_strdup (buf + 1);
	  newentry->isfolder = 0;
	  gftp_add_bookmark (newentry);
	}
      else if (strncmp (buf, "hostname", 8) == 0 && newentry)
	{
	  curpos = buf + 9;
	  if (newentry->hostname)
	    g_free (newentry->hostname);
	  newentry->hostname = g_strdup (curpos);
	}
      else if (strncmp (buf, "port", 4) == 0 && newentry)
	newentry->port = strtol (buf + 5, NULL, 10);
      else if (strncmp (buf, "protocol", 8) == 0 && newentry)
	{
	  curpos = buf + 9;
	  if (newentry->protocol)
	    g_free (newentry->protocol);
	  newentry->protocol = g_strdup (curpos);
	}
      else if (strncmp (buf, "remote directory", 16) == 0 && newentry)
	{
	  curpos = buf + 17;
	  if (newentry->remote_dir)
	    g_free (newentry->remote_dir);
	  newentry->remote_dir = g_strdup (curpos);
	}
      else if (strncmp (buf, "local directory", 15) == 0 && newentry)
	{
	  curpos = buf + 16;
	  if (newentry->local_dir)
	    g_free (newentry->local_dir);
	  newentry->local_dir = g_strdup (curpos);
	}
      else if (strncmp (buf, "username", 8) == 0 && newentry)
	{
	  curpos = buf + 9;
	  if (newentry->user)
	    g_free (newentry->user);
	  newentry->user = g_strdup (curpos);
	}
      else if (strncmp (buf, "password", 8) == 0 && newentry)
	{
	  curpos = buf + 9;
	  if (newentry->pass)
	    g_free (newentry->pass);

	  /* Always try to descramble passords. If the password is not
             scrambled, descramble_password returns the string unchanged */
	  newentry->pass = gftp_descramble_password (curpos);
	  newentry->save_password = *newentry->pass != '\0';
	}
      else if (strncmp (buf, "account", 7) == 0 && newentry)
	{
	  curpos = buf + 8;
	  if (newentry->acct)
	    g_free (newentry->acct);
	  newentry->acct = g_strdup (curpos);
	}
      else if (*buf == '#' || *buf == '\0')
        continue;
      else
        {
          if ((curpos = strchr (buf, '=')) == NULL)
            continue;
          *curpos = '\0';

          if ((global_entry = g_hash_table_lookup (gftp_global_options_htable,
                                                   buf)) == NULL ||
               gftp_option_types[global_entry->otype].read_function == NULL)
            {
	      printf (_("gFTP Warning: Skipping line %d in bookmarks file: %s\n"),
                      line, buf);
              continue;
            }

          if (newentry->local_options_hash == NULL)
            newentry->local_options_hash = g_hash_table_new (string_hash_function,
                                                             string_hash_compare);

          newentry->num_local_options_vars++;
          newentry->local_options_vars = g_realloc (newentry->local_options_vars,
                                                    (gulong) sizeof (gftp_config_vars) * newentry->num_local_options_vars);

          memcpy (&newentry->local_options_vars[newentry->num_local_options_vars - 1], global_entry, 
                  sizeof (newentry->local_options_vars[newentry->num_local_options_vars - 1]));

          newentry->local_options_vars[newentry->num_local_options_vars - 1].flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
          newentry->local_options_vars[newentry->num_local_options_vars - 1].value = NULL;

          if (gftp_option_types[global_entry->otype].read_function (curpos + 1,
                                &newentry->local_options_vars[newentry->num_local_options_vars - 1], line) != 0)
            {
	      printf (_("gFTP Warning: Skipping line %d in bookmarks file: %s\n"),
                      line, buf);
              continue;
            }

          g_hash_table_insert (newentry->local_options_hash, newentry->local_options_vars[newentry->num_local_options_vars - 1].key, &newentry->local_options_vars[newentry->num_local_options_vars - 1]);
        }
    }
}
Esempio n. 17
0
static GHashTable *
string_block_begin (void)
{
  return g_hash_table_new (g_str_hash, g_str_equal);
}
Esempio n. 18
0
void init_home_maps()
{
	all_home = g_hash_table_new(g_int64_hash, g_int64_equal);
}
Esempio n. 19
0
static void
create_channel_cb (GObject *acr,
    GAsyncResult *res,
    gpointer user_data)
{
  GSimpleAsyncResult *simple = user_data;
  CreateTubeData *data;
  GSocketListener *listener = NULL;
  gchar *dir;
  GSocket *socket = NULL;
  GSocketAddress *socket_address = NULL;
  GValue *address;
  GHashTable *parameters;
  GError *error = NULL;

  data = g_simple_async_result_get_op_res_gpointer (simple);

  if (g_cancellable_is_cancelled (data->op_cancellable))
    {
      g_object_unref (simple);
      return;
    }

  data->channel = tp_account_channel_request_create_and_handle_channel_finish (
      TP_ACCOUNT_CHANNEL_REQUEST (acr), res, NULL, &error);
   if (data->channel == NULL)
    goto OUT;

  data->invalidated_id = g_signal_connect (data->channel, "invalidated",
      G_CALLBACK (create_tube_channel_invalidated_cb), simple);

  /* We are client side, but we have to offer a socket... So we offer an unix
   * socket on which the service side can connect. We also create an IPv4 socket
   * on which the ssh client can connect. When both sockets are connected,
   * we can forward all communications between them. */

  listener = g_socket_listener_new ();

  /* Create temporary file for our unix socket */
  dir = g_build_filename (g_get_tmp_dir (), "telepathy-ssh-XXXXXX", NULL);
  dir = mkdtemp (dir);
  data->unix_path = g_build_filename (dir, "unix-socket", NULL);
  g_free (dir);

  /* Create the unix socket, and listen for connection on it */
  socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM,
      G_SOCKET_PROTOCOL_DEFAULT, &error);
  if (socket == NULL)
    goto OUT;
  socket_address = g_unix_socket_address_new (data->unix_path);
  if (!g_socket_bind (socket, socket_address, FALSE, &error))
    goto OUT; 
  if (!g_socket_listen (socket, &error))
    goto OUT;
  if (!g_socket_listener_add_socket (listener, socket, NULL, &error))
    goto OUT;

  g_socket_listener_accept_async (listener, data->op_cancellable,
    create_tube_socket_connected_cb, g_object_ref (simple));

  /* Offer the socket */
  address = tp_address_variant_from_g_socket_address (socket_address,
      TP_SOCKET_ADDRESS_TYPE_UNIX, &error);
  if (address == NULL)
    goto OUT;
  parameters = g_hash_table_new (NULL, NULL);
  data->offer_call = tp_cli_channel_type_stream_tube_call_offer (data->channel,
      -1,
      TP_SOCKET_ADDRESS_TYPE_UNIX, address,
      TP_SOCKET_ACCESS_CONTROL_LOCALHOST, parameters,
      create_tube_offer_cb, g_object_ref (simple), g_object_unref, NULL);
  tp_g_value_slice_free (address);
  g_hash_table_unref (parameters);

OUT:

  if (error != NULL)
    create_tube_complete (simple, error);

  tp_clear_object (&listener);
  tp_clear_object (&socket);
  tp_clear_object (&socket_address);
  g_clear_error (&error);
  g_object_unref (simple);
}
Esempio n. 20
0
/*extern "C" */void __attribute__((constructor)) IFR_Init(void){
  signal(SIGINT, sigint);
  signal(SIGKILL, sigint);

  dbprintf(stderr,"Initializing IFR Runtime\n");

#ifdef IFRIT_ARRAY
  fprintf(stderr, "[IFRit] Array-based implementation in use.\n");
#endif

#ifdef IFRIT_HASH_TABLE
  fprintf(stderr, "[IFRit] Hash-table-based implementation in use.\n");
#endif

#ifdef SINGLE_THREADED_OPT
  fprintf(stderr, "[IFRit] Single-threaded optimization enabled.\n");
#endif

#ifdef THREAD_LOCAL_OPT
  fprintf(stderr, "[IFRit] Thread-local optimization enabled.\n");
#endif

#ifdef READ_SHARED_OPT
  fprintf(stderr, "[IFRit] Read-shared optimization enabled.\n");
#endif

#ifdef PROGRAM_POINT_OPT
  fprintf(stderr, "[IFRit] Program point optimization enabled.\n");
#endif

#ifdef CHECK_FOR_RACES
#ifdef VARG_MASK_BITS
  fprintf(stderr, "[IFRit] Partitioning global state into %d partitions.\n",
	  NUM_VARG_MASKS);
#endif
#else
  fprintf(stderr, "[IFRit] Not checking for races.\n");
#endif

  g_thread_init(NULL);
  
  pthread_mutex_init(&allThreadsLock, NULL);
  int i ;
  for(i = 0; i < MAX_THDS; i++){
    allThreads[i] = (pthread_t)0;
  }

  allThreads[0] = pthread_self();

#ifdef SINGLE_THREADED_OPT
  num_threads = 1;
#endif

#ifdef SAMPLING
  //Release allThreads to samplingAlarmThread
  pthread_create(&samplingAlarmThread,NULL,sample,NULL);
#else
  fprintf (stderr, "[IFRit] Sampling disabled.\n");
#endif

  pthread_key_create(&dkey,thd_dtr);

#ifdef CHECK_FOR_RACES
#ifdef USE_TBB
  ActiveMayWriteIFR = new IFRMapMap();
  ActiveMustWriteIFR = new IFRMap();
  fprintf(stderr, "[IFRit] Using TBB concurrent_hash_map.\n");
#else
#ifdef VARG_MASK_BITS
  for (i = 0; i < NUM_VARG_MASKS; i++) {
    pthread_mutex_init(&drMutex[i], NULL);
    ActiveMustWriteIFR[i] = g_hash_table_new(g_direct_hash,g_direct_equal);
    ActiveMayWriteIFR[i] = g_hash_table_new(g_direct_hash,g_direct_equal);
#ifdef VARG_MASK_COUNT
    partition_counters[i] = 0;
#endif
  }
#else
  pthread_mutex_init(&drMutex, NULL);
  ActiveMustWriteIFR = g_hash_table_new(g_direct_hash,g_direct_equal);
  ActiveMayWriteIFR = g_hash_table_new(g_direct_hash,g_direct_equal);
#endif
#endif
#endif

  //warningCount = 0;

#ifdef IFRIT_ARRAY
  curWIFRVar = 0;
  curRIFRVar = 0;
  maxWIFRVar = INIT_ACTIVE;
  maxRIFRVar = INIT_ACTIVE;
  myWIFRVars = (unsigned long *) calloc(INIT_ACTIVE , sizeof(unsigned long));
  myRIFRVars = (unsigned long *) calloc(INIT_ACTIVE , sizeof(unsigned long));
#endif

#ifdef IFRIT_HASH_TABLE
  myWriteIFRs = g_hash_table_new(g_direct_hash, g_direct_equal);
  myReadIFRs = g_hash_table_new(g_direct_hash, g_direct_equal);
#endif

  //wq = g_queue_new();
  //rq = g_queue_new();

#ifdef THREAD_LOCAL_OPT
  ThreadLocalTable = g_hash_table_new(g_direct_hash, g_direct_equal);
  pthread_mutex_init(&TLMutex, NULL);
#endif

#ifdef READ_SHARED_OPT
  ReadSharedTable = g_hash_table_new(g_direct_hash, g_direct_equal);
  pthread_mutex_init(&RSMutex, NULL);
#endif

  raceCheckIFR = new_ifr(pthread_self(), 0, 0, 0);

#ifdef PROGRAM_POINT_OPT
  PCTable = g_hash_table_new(g_direct_hash, g_direct_equal);
#endif
}
static gboolean
try_existing_instance (DBusGConnection *bus,
                       DBusGProxy *proxy,
                       const char *type,
                       gboolean create,
                       gboolean show,
                       const char *uuid)
{
	gboolean has_owner = FALSE;
	DBusGProxy *instance;
	GHashTable *args;
	GValue type_value = { 0, };
	GValue create_value = { 0, };
	GValue show_value = { 0, };
	GValue uuid_value = { 0, };
	gboolean success = FALSE;
	GError *error = NULL;

	if (!dbus_g_proxy_call (proxy, "NameHasOwner", NULL,
	                        G_TYPE_STRING, NM_CE_DBUS_SERVICE_NAME, G_TYPE_INVALID,
	                        G_TYPE_BOOLEAN, &has_owner, G_TYPE_INVALID))
		return FALSE;

	if (!has_owner)
		return FALSE;

	/* Send arguments to existing process */
	instance = dbus_g_proxy_new_for_name (bus,
	                                      NM_CE_DBUS_SERVICE_NAME,
	                                      "/",
	                                      NM_CE_DBUS_SERVICE_NAME);
	if (!instance)
		return FALSE;

	args = g_hash_table_new (g_str_hash, g_str_equal);
	if (type) {
		g_value_init (&type_value, G_TYPE_STRING);
		g_value_set_static_string (&type_value, type);
		g_hash_table_insert (args, ARG_TYPE, &type_value);
	}
	if (create) {
		g_value_init (&create_value, G_TYPE_BOOLEAN);
		g_value_set_boolean (&create_value, TRUE);
		g_hash_table_insert (args, ARG_CREATE, &create_value);
	}
	if (show) {
		g_value_init (&show_value, G_TYPE_BOOLEAN);
		g_value_set_boolean (&show_value, TRUE);
		g_hash_table_insert (args, ARG_SHOW, &show_value);
	}
	if (uuid) {
		g_value_init (&uuid_value, G_TYPE_STRING);
		g_value_set_static_string (&uuid_value, uuid);
		g_hash_table_insert (args, ARG_UUID, &uuid_value);
	}

	if (dbus_g_proxy_call (instance, "Start", &error,
	                       DBUS_TYPE_G_MAP_OF_VARIANT, args, G_TYPE_INVALID,
	                       G_TYPE_INVALID))
		success = TRUE;
	else
		g_warning ("%s: error calling start: %s", __func__, error->message);

	g_hash_table_destroy (args);
	g_object_unref (instance);
	return success;
}
Esempio n. 22
0
int main(int argc, char **argv)
{
        SaHpiSessionIdT sid = 0;
        GHashTable *h0 = g_hash_table_new(g_str_hash, g_str_equal),
                   *h1 = g_hash_table_new(g_str_hash, g_str_equal),
                   *h2 = g_hash_table_new(g_str_hash, g_str_equal);
        oHpiHandlerIdT hid0 = 0, hid1 = 0, hid2 = 0, next_id = 0;
        
        setenv("OPENHPI_CONF","./noconfig", 1);
        
        if (saHpiSessionOpen(1, &sid, NULL))
                return -1;
                
        if (oHpiPluginLoad("libdummy"))
                return -1;
                
        if (oHpiPluginLoad("libwatchdog"))
                return -1;
                
        /* Set configuration. */
        g_hash_table_insert(h0, "plugin", "libdummy");
        g_hash_table_insert(h0, "entity_root", "{SYSTEM_CHASSIS,1}");
        g_hash_table_insert(h0, "name", "test");
        g_hash_table_insert(h0, "addr", "0");
        
        g_hash_table_insert(h1, "plugin", "libwatchdog");
        g_hash_table_insert(h1, "entity_root", "{SYSTEM_CHASSIS,2}");
        g_hash_table_insert(h1, "addr", "0");
        
        g_hash_table_insert(h2, "plugin", "libdummy");
        g_hash_table_insert(h2, "entity_root", "{SYSTEM_CHASSIS,3}");
        g_hash_table_insert(h2, "name", "test");
        g_hash_table_insert(h2, "addr", "0");
        
        if (oHpiHandlerCreate(h0, &hid0) ||
            oHpiHandlerCreate(h1, &hid1) ||
            oHpiHandlerCreate(h2, &hid2))
                return -1;
                
        if (oHpiHandlerGetNext(0, &next_id) || next_id != 1)
                return -1;
                
        if (oHpiHandlerGetNext(1, &next_id) || next_id != 2)
                return -1;
                
        if (oHpiHandlerGetNext(2, &next_id) || next_id != 3)
                return -1;
                
        if (!oHpiHandlerGetNext(3, &next_id))
                return -1;
                
        if (oHpiHandlerDestroy(hid0) ||
            oHpiHandlerDestroy(hid1) ||
            oHpiHandlerDestroy(hid2))
                return -1;
                
        if (oHpiPluginUnload("libwatchdog"))
                return -1;
                
        
        return oHpiPluginUnload("libdummy");
}
static void
na_tray_manager_init (NaTrayManager *manager)
{
  manager->invisible = NULL;
  manager->socket_table = g_hash_table_new (NULL, NULL);
}
Esempio n. 24
0
/* Transport implementation */
int janus_pfunix_init(janus_transport_callbacks *callback, const char *config_path) {
	if(g_atomic_int_get(&stopping)) {
		/* Still stopping from before */
		return -1;
	}
	if(callback == NULL || config_path == NULL) {
		/* Invalid arguments */
		return -1;
	}

	/* This is the callback we'll need to invoke to contact the gateway */
	gateway = callback;

	/* Read configuration */
	char filename[255];
	g_snprintf(filename, 255, "%s/%s.cfg", config_path, JANUS_PFUNIX_PACKAGE);
	JANUS_LOG(LOG_VERB, "Configuration file: %s\n", filename);
	janus_config *config = janus_config_parse(filename);
	if(config != NULL) {
		/* Handle configuration */
		janus_config_print(config);

		janus_config_item *item = janus_config_get_item_drilldown(config, "general", "json");
		if(item && item->value) {
			/* Check how we need to format/serialize the JSON output */
			if(!strcasecmp(item->value, "indented")) {
				/* Default: indented, we use three spaces for that */
				json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
			} else if(!strcasecmp(item->value, "plain")) {
				/* Not indented and no new lines, but still readable */
				json_format = JSON_INDENT(0) | JSON_PRESERVE_ORDER;
			} else if(!strcasecmp(item->value, "compact")) {
				/* Compact, so no spaces between separators */
				json_format = JSON_COMPACT | JSON_PRESERVE_ORDER;
			} else {
				JANUS_LOG(LOG_WARN, "Unsupported JSON format option '%s', using default (indented)\n", item->value);
				json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
			}
		}

		/* First of all, initialize the socketpair for writeable notifications */
		if(socketpair(PF_LOCAL, SOCK_STREAM, 0, write_fd) < 0) {
			JANUS_LOG(LOG_FATAL, "Error creating socket pair for writeable events: %d, %s\n", errno, strerror(errno));
			return -1;
		}

		/* Setup the Janus API Unix Sockets server(s) */
		item = janus_config_get_item_drilldown(config, "general", "enabled");
		if(!item || !item->value || !janus_is_true(item->value)) {
			JANUS_LOG(LOG_WARN, "Unix Sockets server disabled (Janus API)\n");
		} else {
			item = janus_config_get_item_drilldown(config, "general", "path");
			char *pfname = (char *)(item && item->value ? item->value : "/tmp/ux-janusapi");
			item = janus_config_get_item_drilldown(config, "general", "type");
			const char *type = item && item->value ? item->value : "SOCK_SEQPACKET";
			dgram = FALSE;
			if(!strcasecmp(type, "SOCK_SEQPACKET")) {
				dgram = FALSE;
			} else if(!strcasecmp(type, "SOCK_DGRAM")) {
				dgram = TRUE;
			} else {
				JANUS_LOG(LOG_WARN, "Unknown type %s, assuming SOCK_SEQPACKET\n", type);
				type = "SOCK_SEQPACKET";
			}
			JANUS_LOG(LOG_INFO, "Configuring %s Unix Sockets server (Janus API)\n", type);
			pfd = janus_pfunix_create_socket(pfname, dgram);
		}
		/* Do the same for the Admin API, if enabled */
		item = janus_config_get_item_drilldown(config, "admin", "admin_enabled");
		if(!item || !item->value || !janus_is_true(item->value)) {
			JANUS_LOG(LOG_WARN, "Unix Sockets server disabled (Admin API)\n");
		} else {
			item = janus_config_get_item_drilldown(config, "admin", "admin_path");
			char *pfname = (char *)(item && item->value ? item->value : "/tmp/ux-janusadmin");
			item = janus_config_get_item_drilldown(config, "admin", "admin_type");
			const char *type = item && item->value ? item->value : "SOCK_SEQPACKET";
			if(!strcasecmp(type, "SOCK_SEQPACKET")) {
				admin_dgram = FALSE;
			} else if(!strcasecmp(type, "SOCK_DGRAM")) {
				admin_dgram = TRUE;
			} else {
				JANUS_LOG(LOG_WARN, "Unknown type %s, assuming SOCK_SEQPACKET\n", type);
				type = "SOCK_SEQPACKET";
			}
			JANUS_LOG(LOG_INFO, "Configuring %s Unix Sockets server (Admin API)\n", type);
			admin_pfd = janus_pfunix_create_socket(pfname, admin_dgram);
		}
	}
	janus_config_destroy(config);
	config = NULL;
	if(pfd < 0 && admin_pfd < 0) {
		JANUS_LOG(LOG_FATAL, "No Unix Sockets server started, giving up...\n");
		return -1;	/* No point in keeping the plugin loaded */
	}

	/* Create a couple of hashtables for all clients */
	clients = g_hash_table_new(NULL, NULL);
	clients_by_fd = g_hash_table_new(NULL, NULL);
	clients_by_path = g_hash_table_new(g_str_hash, g_str_equal);
	janus_mutex_init(&clients_mutex);

	/* Start the Unix Sockets service thread */
	GError *error = NULL;
	pfunix_thread = g_thread_try_new("pfunix thread", &janus_pfunix_thread, NULL, &error);
	if(!pfunix_thread) {
		g_atomic_int_set(&initialized, 0);
		JANUS_LOG(LOG_ERR, "Got error %d (%s) trying to launch the Unix Sockets thread...\n", error->code, error->message ? error->message : "??");
		return -1;
	}

	/* Done */
	g_atomic_int_set(&initialized, 1);
	JANUS_LOG(LOG_INFO, "%s initialized!\n", JANUS_PFUNIX_NAME);
	return 0;
}
Esempio n. 25
0
void
sprite_load_from_metadata_f(gevas_metadata_find_edb_data* d)
{
    sprite_load_from_metadata_data* data = (sprite_load_from_metadata_data*)d;
    E_DB_File* edb        = 0;
    const char* edb_prefix = 0;
    gboolean   loaded     = 1;
    GtkgEvasSprite* ev    = 0;

/*     printf("sprite_load_from_metadata() TOP\n"); */

    g_return_if_fail(d        != NULL);
    g_return_if_fail(data->ev != NULL);
    if(data->loaded)
        return;
    ev = data->ev;
    
    edb_prefix = url_args_lookup_str(d->hash_args, "prefix", "" );

/*     printf("sprite_load_from_metadata() edb_full_path:%s\n",d->edb_full_path); */
/*     printf("sprite_load_from_metadata() edb_prefix   :%s\n",edb_prefix); */

    
    /* load the data */
    if( edb = e_db_open( d->edb_full_path ))
    {
        gint  idx   = 0;
        gint  count = 0;
        char* t     = 0;
        gint  n     = 0;

        count = edb_lookup_int( edb, 0, "%s/%s", edb_prefix, "Count",0 );

        for( idx = 0; loaded && idx < count ; idx++ )
        {
            GtkgEvasImage* o = gevasimage_new();
            char* image_name = 0;

            image_name = edb_lookup_str( edb, "", "%s/%d/Location", edb_prefix, idx,0 );
/*             printf("load_from_metadata() image_name:%s\n",image_name); */

            if(!(o = gevasimage_new_from_metadata( GEVAS(ev), image_name )))
            {
                gevas_obj_collection_clear( ev->col );
                loaded=0;
            }
            else
            {
                gevas_obj_collection_add( ev->col, GTK_GEVASOBJ(o) );
            }
            g_free(image_name);
        }

        if(loaded && !(idx < count))
        {
            const char* p = edb_prefix;
            GHashTable* def_hash_args = g_hash_table_new( g_str_hash, g_str_equal );
                
            data->loaded = 1;

            edb_to_hash_int( edb, def_hash_args, "default_frame_delay", p, 0 );
            edb_to_hash_int( edb, def_hash_args, "x", p, 0 );
            edb_to_hash_int( edb, def_hash_args, "y", p, 0 );
            edb_to_hash_int( edb, def_hash_args, "visible", p, 0 );
            edb_to_hash_int( edb, def_hash_args, "play_forever", p, 0 );
            
            setup_attribs( ev, def_hash_args );
            setup_attribs( ev, d->hash_args );

            hash_str_str_clean( def_hash_args );
        }
        e_db_close(edb);
    }
    
    
}
Esempio n. 26
0
void on_connectdbok_clicked(GtkWidget *widget, gpointer user_data) {
	gchar	*host;
	gchar	*user;
	gchar	*password;
	gchar	*dbname;
	gchar	dbquery[200];
	gchar	dbstatus[1000];
	int	broken,found;
	xmlNodePtr node;

	host=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_host));
	user=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_user));
	password=gtk_entry_get_text(connectdb_password);
	dbname=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_database));

	broken=FALSE;

	mysql=mysql_init(NULL);
	if (!mysql_real_connect(mysql,host,user,password,NULL,0,NULL,0)) {
		error_dialog("Could not connect to Database");
		fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql));
		mysql_close(mysql);
		mysql=NULL;
	} else {
		sprintf(dbquery,"use %s",dbname);
		mysql_query(mysql,dbquery);
	
		if (mysql_errno(mysql)!=0) {
			switch (ok_cancel_dialog("The database does not exist.\nCreate a new one?")) {
				case 0:
					g_message("Creating new Database %s.\n",dbname);
					sprintf(dbquery,"create database %s",dbname);
					if (mysql_query(mysql,dbquery)!=0) {
						fprintf(stderr, "Failed to create database: Error: %s\n", mysql_error(mysql));
					}
					sprintf(dbquery,"use %s",dbname);
					if (mysql_query(mysql,dbquery)!=0) {
						fprintf(stderr, "Failed to use database: Error: %s\n", mysql_error(mysql));
					}
					break;
				case 1:
					broken=TRUE;
					break;
				default:
					broken=TRUE;
					break;
			}
		}
		
		if (broken==FALSE) {		
			sprintf(dbquery,"create table _TableNames (Name Text,TName Text,Comment Text)");
			mysql_query(mysql,dbquery);
			name_cache=g_hash_table_new(g_str_hash,g_str_equal);
			tname_cache=g_hash_table_new(g_str_hash,g_str_equal);
		
			sprintf(dbstatus,"Database: %s\nuser:     %s\nhost:     %s",dbname,user,host);
			gtk_label_set_text(database_status_label,dbstatus);
		// -------------------------------
			found=FALSE;
			node=global_configs_doc->children;
			while (node) {
				if (strcmp(node->name,"configurations")==0) {
					node=node->children;
					break;
				}
				node=node->next;
			}

			if (node) {
				while (node) {
					if (strcmp(node->name,"dbconfig")==0) {
						if (strcmp(xmlGetProp(node,"dbname"),dbname)==0) {
							found=TRUE;
							db_global_configs_node=node;
							break;
						}
					}
					node=node->next;
				}
			}
			if (!found) {
				db_global_configs_node=xmlNewNode(NULL,"dbconfig");
				xmlSetProp(db_global_configs_node,"dbname",dbname);
				xmlAddChild(global_configs_doc->children,db_global_configs_node);
			}
		// ---------------------------------
			found=FALSE;
			node=local_configs_doc->children;
			while (node) {
				if (strcmp(node->name,"configurations")==0) {
					node=node->children;
					break;
				}
				node=node->next;
			}

			if (node) {
				while (node) {
					if (strcmp(node->name,"dbconfig")==0) {
						if (strcmp(xmlGetProp(node,"dbname"),dbname)==0) {
							found=TRUE;
							db_local_configs_node=node;
							break;
						}
					}
					node=node->next;
				}
			}
			if (!found) {
				db_local_configs_node=xmlNewNode(NULL,"dbconfig");
				xmlSetProp(db_local_configs_node,"dbname",xmlEncodeEntitiesReentrant(local_configs_doc,dbname));
				xmlAddChild(local_configs_doc->children,db_local_configs_node);
			} else {
				gtk_widget_set_sensitive(GTK_WIDGET(connect_button),FALSE);
				gtk_widget_set_sensitive(GTK_WIDGET(disconnect_button),TRUE);
				gtk_widget_set_sensitive(GTK_WIDGET(add_category_button),TRUE);
			}
		// ---------------------------------
			gnome_dialog_close(connectdb_dialog);
			update_tablelist(mysql);

		}
	}
}
Esempio n. 27
0
static void
css_string_funcs_init (void)
{
  if (G_LIKELY (parse_funcs != NULL))
    return;

  parse_funcs = g_hash_table_new (NULL, NULL);
  to_string_funcs = g_hash_table_new (NULL, NULL);

  register_conversion_function (GDK_TYPE_RGBA,
                                rgba_value_parse,
                                rgba_value_to_string);
  register_conversion_function (GDK_TYPE_COLOR,
                                color_value_parse,
                                color_value_to_string);
  register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
                                symbolic_color_value_parse,
                                symbolic_color_value_to_string);
  register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
                                font_description_value_parse,
                                font_description_value_to_string);
  register_conversion_function (G_TYPE_BOOLEAN,
                                boolean_value_parse,
                                boolean_value_to_string);
  register_conversion_function (G_TYPE_INT,
                                int_value_parse,
                                int_value_to_string);
  register_conversion_function (G_TYPE_UINT,
                                uint_value_parse,
                                uint_value_to_string);
  register_conversion_function (G_TYPE_DOUBLE,
                                double_value_parse,
                                double_value_to_string);
  register_conversion_function (G_TYPE_FLOAT,
                                float_value_parse,
                                float_value_to_string);
  register_conversion_function (G_TYPE_STRING,
                                string_value_parse,
                                string_value_to_string);
  register_conversion_function (GTK_TYPE_THEMING_ENGINE,
                                theming_engine_value_parse,
                                theming_engine_value_to_string);
  register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
                                animation_description_value_parse,
                                animation_description_value_to_string);
  register_conversion_function (GTK_TYPE_BORDER,
                                border_value_parse,
                                border_value_to_string);
  register_conversion_function (GTK_TYPE_GRADIENT,
                                gradient_value_parse,
                                gradient_value_to_string);
  register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
                                pattern_value_parse,
                                NULL);
  register_conversion_function (GTK_TYPE_9SLICE,
                                slice_value_parse,
                                NULL);
  register_conversion_function (G_TYPE_ENUM,
                                enum_value_parse,
                                enum_value_to_string);
  register_conversion_function (G_TYPE_FLAGS,
                                flags_value_parse,
                                flags_value_to_string);
  register_conversion_function (G_TYPE_PTR_ARRAY,
                                bindings_value_parse,
                                bindings_value_to_string);
}
Esempio n. 28
0
void print_leaf_options(struct taint_creation_info* tci,
                            u_long taint,
                            int output_byte_offset,
                            GHashTable* leaf_node_table,
                            GHashTable* merge_node_table,
                            GHashTable* option_info_table,
                            GHashTable* filename_table)
{
    u_long new_addr;
    GHashTable* seen_indices;
    GQueue* queue;

    seen_indices = g_hash_table_new(g_direct_hash, g_direct_equal);
    queue = g_queue_new();

    assert(taint);
    assert(tci);

    if (g_hash_table_contains(leaf_node_table, (gpointer) taint)) {
        new_addr = (u_long) g_hash_table_lookup(leaf_node_table, (gpointer) taint);
    } else {
        new_addr = (u_long) g_hash_table_lookup(merge_node_table, (gpointer) taint);
    }
    if (!new_addr) {
        fprintf(stderr, "Could not find taint: %lu\n", (u_long) taint);
        return;
    }
    assert(new_addr);

    // Invariant: the addresses on the queue should always be the new addresses of the nodes
    g_queue_push_tail(queue, (gpointer) new_addr);
    while(!g_queue_is_empty(queue)) {
        struct taint_node* n;
        new_addr = (u_long) g_queue_pop_head(queue);
        assert(new_addr);

        if (g_hash_table_lookup(seen_indices, (gpointer) new_addr)) {
            continue;
        }
        g_hash_table_insert(seen_indices, (gpointer) new_addr, GINT_TO_POINTER(1));
        n = (struct taint_node *) new_addr;

        if (!n->parent1 && !n->parent2) { // leaf node
            char* filename = (char *) "--";
            struct token* tok;
            struct taint_leafnode* ln = (struct taint_leafnode *) n;
            
            // lookup option number to metadata describing that option
            tok = (struct token *) g_hash_table_lookup(option_info_table, GINT_TO_POINTER(ln->option));
            assert(tok);

            // resolve filenames
            if (g_hash_table_contains(filename_table, GINT_TO_POINTER(tok->fileno))) {
                filename = (char *) g_hash_table_lookup(filename_table, GINT_TO_POINTER(tok->fileno));
            }

            fprintf(stdout, "%llu %d %d %d %s",
                                tok->rg_id,
                                tok->record_pid,
                                tok->syscall_cnt,
                                tok->byte_offset,
                                filename);
            fprintf(stdout, "\n");
        } else {
            if (!g_hash_table_lookup(seen_indices, (gpointer) n->parent1)) {
                struct taint_node* p1;
                // lookup the address of the parent
                if (g_hash_table_contains(leaf_node_table, (gpointer) n->parent1)) {
                    p1 = (struct taint_node *) g_hash_table_lookup(leaf_node_table, (gpointer) n->parent1);
                } else {
                    p1 = (struct taint_node *) g_hash_table_lookup(merge_node_table, (gpointer) n->parent1);
                }
                assert(p1);
                // push the new address onto the queue
                g_queue_push_tail(queue, p1);
            }
            if (!g_hash_table_lookup(seen_indices, n->parent2)) {
                struct taint_node* p2;
                // lookup the address of the parent
                if (g_hash_table_contains(leaf_node_table, (gpointer) n->parent2)) {
                    p2 = (struct taint_node *) g_hash_table_lookup(leaf_node_table, (gpointer) n->parent2);
                } else {
                    p2 = (struct taint_node *) g_hash_table_lookup(merge_node_table, (gpointer) n->parent2);
                }
                assert(p2);
                // push the new address onto the queue
                g_queue_push_tail(queue, p2);
            }
        }
    }
    g_queue_free(queue);
    g_hash_table_destroy(seen_indices);
}
Esempio n. 29
0
extern mate_config* mate_make_config(const gchar* filename, int mate_hfid) {
	gint* ett;
	avp_init();

	matecfg = (mate_config *)g_malloc(sizeof(mate_config));

	matecfg->hfid_mate = mate_hfid;

	matecfg->fields_filter = g_string_new("");
	matecfg->protos_filter = g_string_new("");

	matecfg->dbg_facility = NULL;

	matecfg->mate_lib_path = g_strdup_printf("%s%c%s%c",get_datafile_dir(),DIR_SEP,DEFAULT_MATE_LIB_PATH,DIR_SEP);

	matecfg->pducfgs = g_hash_table_new(g_str_hash,g_str_equal);
	matecfg->gopcfgs = g_hash_table_new(g_str_hash,g_str_equal);
	matecfg->gogcfgs = g_hash_table_new(g_str_hash,g_str_equal);
	matecfg->transfs = g_hash_table_new(g_str_hash,g_str_equal);

	matecfg->pducfglist = g_ptr_array_new();
	matecfg->gops_by_pduname = g_hash_table_new(g_str_hash,g_str_equal);
	matecfg->gogs_by_gopname = g_hash_table_new(g_str_hash,g_str_equal);

	matecfg->ett_root = -1;

	matecfg->hfrs = g_array_new(FALSE,FALSE,sizeof(hf_register_info));
	matecfg->ett  = g_array_new(FALSE,FALSE,sizeof(gint*));

	matecfg->defaults.pdu.drop_unassigned = FALSE;
	matecfg->defaults.pdu.discard = FALSE;
	matecfg->defaults.pdu.last_extracted = FALSE;
	matecfg->defaults.pdu.match_mode = AVPL_STRICT;
	matecfg->defaults.pdu.replace_mode = AVPL_INSERT;

		/* gop prefs */
	matecfg->defaults.gop.expiration = -1.0f;
	matecfg->defaults.gop.idle_timeout = -1.0f;
	matecfg->defaults.gop.lifetime = -1.0f;
	matecfg->defaults.gop.pdu_tree_mode = GOP_FRAME_TREE;
	matecfg->defaults.gop.show_times = TRUE;
	matecfg->defaults.gop.drop_unassigned = FALSE;

		/* gog prefs */
	matecfg->defaults.gog.expiration = 5.0f;
	matecfg->defaults.gog.show_times = TRUE;
	matecfg->defaults.gog.gop_tree_mode = GOP_BASIC_TREE;

	/* what to dbgprint */
	matecfg->dbg_lvl = 0;
	matecfg->dbg_pdu_lvl = 0;
	matecfg->dbg_gop_lvl = 0;
	matecfg->dbg_gog_lvl = 0;

	matecfg->config_error = g_string_new("");

	ett = &matecfg->ett_root;
	g_array_append_val(matecfg->ett,ett);

	if ( mate_load_config(filename,matecfg) ) {
		analyze_config();
	} else {
		report_failure("MATE failed to configure!\n"
					   "It is recommended that you fix your config and restart Wireshark.\n"
					   "The reported error is:\n%s\n",matecfg->config_error->str);

		/* if (matecfg) destroy_mate_config(matecfg,FALSE); */
		matecfg = NULL;
		return NULL;
	}

	if (matecfg->fields_filter->len > 1) {
		g_string_erase(matecfg->fields_filter,0,2);
		g_string_erase(matecfg->protos_filter,0,2);
	} else {
		/*destroy_mate_config(matecfg,FALSE);*/
		matecfg = NULL;
		return NULL;
	}

	matecfg->tap_filter = g_strdup_printf("(%s) && (%s)",matecfg->protos_filter->str,matecfg->fields_filter->str);

	return matecfg;
}
Esempio n. 30
0
static void
userlist_init (Userlist *userlist)
{
	userlist->stores = g_hash_table_new (g_direct_hash, g_direct_equal);
}