Exemplo n.º 1
0
int connman_session_config_update(struct connman_session *session)
{
	struct session_info *info = session->info;
	GSList *allowed_bearers;
	char *allowed_interface;
	int err;

	DBG("session %p", session);

	/*
	 * We update all configuration even though only one entry
	 * might have changed. We can still optimize this later.
	 */

	if (session->id_type != session->policy_config->id_type) {
		cleanup_firewall_session(session);
		err = init_firewall_session(session);
		if (err < 0) {
			connman_session_destroy(session);
			return err;
		}

		session->id_type = session->policy_config->id_type;
	}

	apply_policy_on_bearers(
		session->policy_config->allowed_bearers,
		session->user_allowed_bearers,
		&allowed_bearers);

	allowed_interface = apply_policy_on_interface(
		session->policy_config->allowed_interface,
		session->user_allowed_interface);

	if (session->active)
		set_active_session(session, false);

	session->active = false;
	session_deactivate(session);

	g_slist_free(info->config.allowed_bearers);
	info->config.allowed_bearers = allowed_bearers;

	g_free(info->config.allowed_interface);
	info->config.allowed_interface = allowed_interface;

	session_activate(session);

	info->config.type = apply_policy_on_type(
				session->policy_config->type,
				info->config.type);

	info->config.roaming_policy = session->policy_config->roaming_policy;

	info->config.ecall = session->policy_config->ecall;
	if (info->config.ecall)
		ecall_session = session;

	info->config.priority = session->policy_config->priority;

	session_notify(session);

	return 0;
}
Exemplo n.º 2
0
/*
 * Parses a map file
 * Given the path to a map file, returns a new map struct
 * The struct must be freed once it's done being used
 */
ALLEGRO_MAP *al_open_map(const char *dir, const char *filename)
{
    xmlDoc *doc;
    xmlNode *root;
    ALLEGRO_MAP *map;

    unsigned i, j;

    ALLEGRO_PATH *cwd = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    ALLEGRO_PATH *resources = al_clone_path(cwd);
    ALLEGRO_PATH *maps = al_create_path(dir);

    al_join_paths(resources, maps);
    if (!al_change_directory(al_path_cstr(resources, ALLEGRO_NATIVE_PATH_SEP))) {
        fprintf(stderr, "Error: failed to change directory in al_parse_map().");
    }

    al_destroy_path(resources);
    al_destroy_path(maps);

    // Read in the data file
    doc = xmlReadFile(filename, NULL, 0);
    if (!doc) {
        fprintf(stderr, "Error: failed to parse map data: %s\n", filename);
        return NULL;
    }

    // Get the root element, <map>
    root = xmlDocGetRootElement(doc);

    // Get some basic info
    map = MALLOC(ALLEGRO_MAP);
    map->width = atoi(get_xml_attribute(root, "width"));
    map->height = atoi(get_xml_attribute(root, "height"));
    map->tile_width = atoi(get_xml_attribute(root, "tilewidth"));
    map->tile_height = atoi(get_xml_attribute(root, "tileheight"));
    map->orientation = g_strdup(get_xml_attribute(root, "orientation"));
    map->tile_layer_count = 0;
    map->object_layer_count = 0;

    // Get the tilesets
    GSList *tilesets = get_children_for_name(root, "tileset");
    map->tilesets = NULL;

    GSList *tileset_item = tilesets;
    while (tileset_item) {
        xmlNode *tileset_node = (xmlNode*)tileset_item->data;
        tileset_item = g_slist_next(tileset_item);

        ALLEGRO_MAP_TILESET *tileset = MALLOC(ALLEGRO_MAP_TILESET);
        tileset->firstgid = atoi(get_xml_attribute(tileset_node, "firstgid"));
        tileset->tilewidth = atoi(get_xml_attribute(tileset_node, "tilewidth"));
        tileset->tileheight = atoi(get_xml_attribute(tileset_node, "tileheight"));
        tileset->name = g_strdup(get_xml_attribute(tileset_node, "name"));

        // Get this tileset's image
        xmlNode *image_node = get_first_child_for_name(tileset_node, "image");
        tileset->width = atoi(get_xml_attribute(image_node, "width"));
        tileset->height = atoi(get_xml_attribute(image_node, "height"));
        tileset->source = g_strdup(get_xml_attribute(image_node, "source"));
        tileset->bitmap = al_load_bitmap(tileset->source);

        // Get this tileset's tiles
        GSList *tiles = get_children_for_name(tileset_node, "tile");
        tileset->tiles = NULL;

        GSList *tile_item = tiles;
        while (tile_item) {
            xmlNode *tile_node = (xmlNode*)tile_item->data;
            tile_item = g_slist_next(tile_item);

            ALLEGRO_MAP_TILE *tile = MALLOC(ALLEGRO_MAP_TILE);
            tile->id = tileset->firstgid + atoi(get_xml_attribute(tile_node, "id"));
            tile->tileset = tileset;
            tile->bitmap = NULL;

            // Get this tile's properties
            tile->properties = parse_properties(tile_node);

            // TODO: add a destructor
            tileset->tiles = g_slist_prepend(tileset->tiles, tile);
        }

        g_slist_free(tiles);
        //tileset->tiles = g_slist_reverse(tileset->tiles);

        // TODO: add a destructor
        map->tilesets = g_slist_prepend(map->tilesets, tileset);
    }

    g_slist_free(tilesets);
    //map->tilesets = g_slist_reverse(map->tilesets);

    // Create the map's master list of tiles
    cache_tile_list(map);

    // Get the layers
    GSList *layers = get_children_for_either_name(root, "layer", "objectgroup");
    map->layers = NULL;

    GSList *layer_item = layers;
    while (layer_item) {
        xmlNode *layer_node = (xmlNode*)layer_item->data;
        layer_item = g_slist_next(layer_item);

        ALLEGRO_MAP_LAYER *layer = MALLOC(ALLEGRO_MAP_LAYER);
        layer->name = g_strdup(get_xml_attribute(layer_node, "name"));
        layer->properties = parse_properties(layer_node);

        char *layer_visible = get_xml_attribute(layer_node, "visible");
        layer->visible = (layer_visible != NULL ? atoi(layer_visible) : 1);

        char *layer_opacity = get_xml_attribute(layer_node, "opacity");
        layer->opacity = (layer_opacity != NULL ? atof(layer_opacity) : 1.0);

        if (!strcmp((const char*)layer_node->name, "layer")) {
            layer->type = TILE_LAYER;
            layer->width = atoi(get_xml_attribute(layer_node, "width"));
            layer->height = atoi(get_xml_attribute(layer_node, "height"));
            decode_layer_data(get_first_child_for_name(layer_node, "data"), layer);

            // Create any missing tile objects
            for (i = 0; i<layer->height; i++) {
                for (j = 0; j<layer->width; j++) {
                    char id = al_get_single_tile_id(layer, j, i);

                    if (id == 0) {
                        continue;
                    }

                    ALLEGRO_MAP_TILE *tile = al_get_tile_for_id(map, id);
                    if (!tile) {
                        // wasn't defined in the map file, presumably because it had no properties
                        tile = MALLOC(ALLEGRO_MAP_TILE);
                        tile->id = id;
                        tile->properties = g_hash_table_new(NULL, NULL);
                        tile->tileset = NULL;
                        tile->bitmap = NULL;

                        // locate its tilemap
                        GSList *tilesets = map->tilesets;
                        ALLEGRO_MAP_TILESET *tileset_ref;
                        while (tilesets) {
                            ALLEGRO_MAP_TILESET *tileset = (ALLEGRO_MAP_TILESET*)tilesets->data;
                            tilesets = g_slist_next(tilesets);
                            if (tileset->firstgid <= id) {
                                if (!tile->tileset || tileset->firstgid > tile->tileset->firstgid) {
                                    tileset_ref = tileset;
                                }
                            }

                        }

                        tile->tileset = tileset_ref;
                        tileset_ref->tiles = g_slist_prepend(tileset_ref->tiles, tile);
                        g_hash_table_insert(map->tiles, GINT_TO_POINTER(tile->id), tile);
                    }

                    // create this tile's bitmap if it hasn't been yet
                    if (!tile->bitmap) {
                        ALLEGRO_MAP_TILESET *tileset = tile->tileset;
                        int id = tile->id - tileset->firstgid;
                        int width = tileset->width / tileset->tilewidth;
                        int x = (id % width) * tileset->tilewidth;
                        int y = (id / width) * tileset->tileheight;
                        tile->bitmap = al_create_sub_bitmap(
                                tileset->bitmap,
                                x, y,
                                tileset->tilewidth,
                                tileset->tileheight);
                    }
                }
            }
            map->tile_layer_count++;
            map->tile_layers = g_slist_prepend(map->tile_layers, layer);
        } else if (!strcmp((const char*)layer_node->name, "objectgroup")) {
            layer->type = OBJECT_LAYER;
            layer->objects = NULL;
            layer->object_count = 0;
            // TODO: color?
            GSList *objects = get_children_for_name(layer_node, "object");
            GSList *object_item = objects;
            while (object_item) {
                xmlNode *object_node = (xmlNode*)object_item->data;
                object_item = g_slist_next(object_item);

                ALLEGRO_MAP_OBJECT *object = MALLOC(ALLEGRO_MAP_OBJECT);
                object->layer = layer;
                object->name = g_strdup(get_xml_attribute(object_node, "name"));
                object->type = g_strdup(get_xml_attribute(object_node, "type"));
                object->x = atoi(get_xml_attribute(object_node, "x"));
                object->y = atoi(get_xml_attribute(object_node, "y"));

                char *object_width = get_xml_attribute(object_node, "width");
                object->width = (object_width ? atoi(object_width) : 0);

                char *object_height = get_xml_attribute(object_node, "height");
                object->height = (object_height ? atoi(object_height) : 0);

                char *gid = get_xml_attribute(object_node, "gid");
                if (gid) {
                    object->gid = atoi(gid);
                }

                char *object_visible = get_xml_attribute(object_node, "visible");
                object->visible = (object_visible ? atoi(object_visible) : 1);

                // Get the object's properties
                object->properties = parse_properties(object_node);
                layer->objects = g_slist_prepend(layer->objects, object);
                layer->object_count++;
            }
            map->object_layer_count++;
            map->object_layers = g_slist_prepend(map->object_layers, layer);
        } else {
            fprintf(stderr, "Error: found invalid layer node \"%s\"\n", layer_node->name);
            continue;
        }

        map->layers = g_slist_prepend(map->layers, layer);
    }

    g_slist_free(layers);

    // If any objects have a tile gid, cache their image
    layer_item = map->layers;
    while (layer_item) {
        ALLEGRO_MAP_LAYER *layer = (ALLEGRO_MAP_LAYER*)layer_item->data;
        layer_item = g_slist_next(layer_item);
        if (layer->type != OBJECT_LAYER) {
            continue;
        }

        GSList *objects = layer->objects;
        while (objects) {
            ALLEGRO_MAP_OBJECT *object = (ALLEGRO_MAP_OBJECT*)objects->data;
            objects = g_slist_next(objects);
            if (!object->gid) {
                continue;
            }

            object->bitmap = al_get_tile_for_id(map, object->gid)->bitmap;
            object->width = map->tile_width;
            object->height = map->tile_height;
        }
    }

    xmlFreeDoc(doc);
    al_change_directory(al_path_cstr(cwd, ALLEGRO_NATIVE_PATH_SEP));

    return map;
}
Exemplo n.º 3
0
GtkWidget*
gtr_torrent_options_dialog_new (GtkWindow * parent, TrCore * core, tr_ctor * ctor)
{
    const char *     str;
    GtkWidget *      w;
    GtkWidget *      d;
    GtkGrid        * grid;
    int              row;
    GtkWidget *      l;
    GtkWidget *      source_chooser;
    struct OpenData * data;
    bool             flag;
    GSList *         list;
    GSList *         walk;

    /* make the dialog */
    d = gtk_dialog_new_with_buttons (_("Torrent Options"), parent,
                                     GTK_DIALOG_DESTROY_WITH_PARENT,
                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                     GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                     NULL);
    gtk_dialog_set_default_response (GTK_DIALOG (d),
                                     GTK_RESPONSE_ACCEPT);
    gtk_dialog_set_alternative_button_order (GTK_DIALOG (d),
                                             GTK_RESPONSE_ACCEPT,
                                             GTK_RESPONSE_CANCEL,
                                             -1);

    if (tr_ctorGetDownloadDir (ctor, TR_FORCE, &str))
        g_assert_not_reached ();
    g_assert (str);

    data = g_new0 (struct OpenData, 1);
    data->core = core;
    data->ctor = ctor;
    data->filename = g_strdup (tr_ctorGetSourceFile (ctor));
    data->downloadDir = g_strdup (str);
    data->file_list = gtr_file_list_new (core, 0);
    str = _("Mo_ve .torrent file to the trash");
    data->trash_check = gtk_check_button_new_with_mnemonic (str);
    str = _("_Start when added");
    data->run_check = gtk_check_button_new_with_mnemonic (str);

    w = data->priority_combo = gtr_priority_combo_new ();
    gtr_priority_combo_set_value (GTK_COMBO_BOX (w), TR_PRI_NORMAL);

    g_signal_connect (G_OBJECT (d), "response",
                      G_CALLBACK (addResponseCB), data);

    row = 0;
    grid = GTK_GRID (gtk_grid_new ());
    gtk_container_set_border_width (GTK_CONTAINER (grid), GUI_PAD_BIG);
    gtk_grid_set_row_spacing (grid, GUI_PAD);
    gtk_grid_set_column_spacing (grid, GUI_PAD_BIG);

    // "torrent file" row
    l = gtk_label_new_with_mnemonic (_("_Torrent file:"));
    gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
    gtk_grid_attach (grid, l, 0, row, 1, 1);
    w = gtk_file_chooser_button_new (_("Select Source File"),
                                     GTK_FILE_CHOOSER_ACTION_OPEN);
    source_chooser = w;
    gtk_widget_set_hexpand (w, TRUE);
    gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
    gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
    addTorrentFilters (GTK_FILE_CHOOSER (w));
    g_signal_connect (w, "selection-changed",
                      G_CALLBACK (sourceChanged), data);

    // "destination folder" row
    row++;
    l = gtk_label_new_with_mnemonic (_("_Destination folder:"));
    gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
    gtk_grid_attach (grid, l, 0, row, 1, 1);
    w = gtk_file_chooser_button_new (_("Select Destination Folder"),
                                     GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
    if (!gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w),
                                              data->downloadDir))
        g_warning ("couldn't select '%s'", data->downloadDir);
    list = get_recent_destinations ();
    for (walk = list; walk; walk = walk->next)
        gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (w), walk->data, NULL);
    g_slist_free (list);
    gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
    gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
    g_signal_connect (w, "selection-changed",
                      G_CALLBACK (downloadDirChanged), data);

    row++;
    l = data->freespace_label = gtr_freespace_label_new (core, data->downloadDir);
    gtk_widget_set_margin_bottom (l, GUI_PAD_BIG);
    gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f);
    gtk_grid_attach (grid, l, 0, row, 2, 1);


    // file list row
    row++;
    w = data->file_list;
    gtk_widget_set_vexpand (w, TRUE);
    gtk_widget_set_size_request (w, 466u, 300u);
    gtk_grid_attach (grid, w, 0, row, 2, 1);

    // torrent priority row
    row++;
    l = gtk_label_new_with_mnemonic (_("Torrent _priority:"));
    gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
    gtk_grid_attach (grid, l, 0, row, 1, 1);
    w = data->priority_combo;
    gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
    gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);

    // torrent priority row
    row++;
    w = data->run_check;
    if (tr_ctorGetPaused (ctor, TR_FORCE, &flag))
        g_assert_not_reached ();
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), !flag);
    gtk_grid_attach (grid, w, 0, row, 2, 1);

    // "trash .torrent file" row
    row++;
    w = data->trash_check;
    if (tr_ctorGetDeleteSource (ctor, &flag))
        g_assert_not_reached ();
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), flag);
    gtk_grid_attach (grid, w, 0, row, 2, 1);

    /* trigger sourceChanged, either directly or indirectly,
     * so that it creates the tor/gtor objects */
    w = source_chooser;
    if (data->filename)
        gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), data->filename);
    else
        sourceChanged (GTK_FILE_CHOOSER_BUTTON (w), data);

    gtr_dialog_set_content (GTK_DIALOG (d), GTK_WIDGET (grid));
    w = gtk_dialog_get_widget_for_response (GTK_DIALOG (d), GTK_RESPONSE_ACCEPT);
    gtk_widget_grab_focus (w);
    return d;
}
Exemplo n.º 4
0
/*
 * mono_arch_get_call_filter:
 *
 * Returns a pointer to a method which calls an exception filter. We
 * also use this function to call finally handlers (we pass NULL as 
 * @exc object in this case).
 */
gpointer
mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
{
	guint8* start;
	guint8 *code;
	MonoJumpInfo *ji = NULL;
	GSList *unwind_ops = NULL;
	guint kMaxCodeSize = NACL_SIZE (64, 128);

	/* call_filter (MonoContext *ctx, unsigned long eip) */
	start = code = mono_global_codeman_reserve (kMaxCodeSize);

	x86_push_reg (code, X86_EBP);
	x86_mov_reg_reg (code, X86_EBP, X86_ESP, 4);
	x86_push_reg (code, X86_EBX);
	x86_push_reg (code, X86_EDI);
	x86_push_reg (code, X86_ESI);

	/* load ctx */
	x86_mov_reg_membase (code, X86_EAX, X86_EBP, 8, 4);
	/* load eip */
	x86_mov_reg_membase (code, X86_ECX, X86_EBP, 12, 4);
	/* save EBP */
	x86_push_reg (code, X86_EBP);

	/* set new EBP */
	x86_mov_reg_membase (code, X86_EBP, X86_EAX,  G_STRUCT_OFFSET (MonoContext, ebp), 4);
	/* restore registers used by global register allocation (EBX & ESI) */
	x86_mov_reg_membase (code, X86_EBX, X86_EAX,  G_STRUCT_OFFSET (MonoContext, ebx), 4);
	x86_mov_reg_membase (code, X86_ESI, X86_EAX,  G_STRUCT_OFFSET (MonoContext, esi), 4);
	x86_mov_reg_membase (code, X86_EDI, X86_EAX,  G_STRUCT_OFFSET (MonoContext, edi), 4);

	/* align stack and save ESP */
	x86_mov_reg_reg (code, X86_EDX, X86_ESP, 4);
	x86_alu_reg_imm (code, X86_AND, X86_ESP, -MONO_ARCH_FRAME_ALIGNMENT);
	g_assert (MONO_ARCH_FRAME_ALIGNMENT >= 8);
	x86_alu_reg_imm (code, X86_SUB, X86_ESP, MONO_ARCH_FRAME_ALIGNMENT - 8);
	x86_push_reg (code, X86_EDX);

	/* call the handler */
	x86_call_reg (code, X86_ECX);

	/* restore ESP */
	x86_pop_reg (code, X86_ESP);

	/* restore EBP */
	x86_pop_reg (code, X86_EBP);

	/* restore saved regs */
	x86_pop_reg (code, X86_ESI);
	x86_pop_reg (code, X86_EDI);
	x86_pop_reg (code, X86_EBX);
	x86_leave (code);
	x86_ret (code);

	nacl_global_codeman_validate(&start, kMaxCodeSize, &code);

	if (info)
		*info = mono_tramp_info_create ("call_filter", start, code - start, ji, unwind_ops);
	else {
		GSList *l;

		for (l = unwind_ops; l; l = l->next)
			g_free (l->data);
		g_slist_free (unwind_ops);
	}

	g_assert ((code - start) < kMaxCodeSize);
	return start;
}
Exemplo n.º 5
0
static void msn_logout( struct im_connection *ic )
{
	struct msn_data *md = ic->proto_data;
	GSList *l;
	int i;
	
	if( md )
	{
		/** Disabling MSN ft support for now.
		while( md->filetransfers ) {
			imcb_file_canceled( md->filetransfers->data, "Closing connection" );
		}
		*/
		
		msn_ns_close( md->ns );
		
		while( md->switchboards )
			msn_sb_destroy( md->switchboards->data );
		
		msn_msgq_purge( ic, &md->msgq );
		msn_soapq_flush( ic, FALSE );
		
		for( i = 0; i < sizeof( md->tokens ) / sizeof( md->tokens[0] ); i ++ )
			g_free( md->tokens[i] );
		g_free( md->lock_key );
		g_free( md->pp_policy );
		g_free( md->uuid );
		
		while( md->groups )
		{
			struct msn_group *mg = md->groups->data;
			g_free( mg->id );
			g_free( mg->name );
			g_free( mg );
			md->groups = g_slist_remove( md->groups, mg );
		}
		
		g_free( md->profile_rid );
		
		if( md->domaintree )
			g_tree_destroy( md->domaintree );
		md->domaintree = NULL;
		
		while( md->grpq )
		{
			struct msn_groupadd *ga = md->grpq->data;
			g_free( ga->group );
			g_free( ga->who );
			g_free( ga );
			md->grpq = g_slist_remove( md->grpq, ga );
		}
		
		g_free( md );
	}
	
	for( l = ic->permit; l; l = l->next )
		g_free( l->data );
	g_slist_free( ic->permit );
	
	for( l = ic->deny; l; l = l->next )
		g_free( l->data );
	g_slist_free( ic->deny );
	
	msn_connections = g_slist_remove( msn_connections, ic );
}
Exemplo n.º 6
0
void read_xmms_config() {
	int  count;
	/*char tempname[100];*/
	char *tempname = (char *)malloc(sizeof(char)*100);
	gchar *path;
	gchar *ext;
	mcs_handle_t *config;

	DPRINT (__DEBUG_GENERAL__,"Starting to read xmms config");

	// empty cover search list, the plugin is probably initialized twice by the user
	g_slist_free (cdcover_config.cover_searchpaths);
	cdcover_config.cover_searchpaths = NULL;

	// empty extension search list, the plugin is probably initialized twice by the user
	g_slist_free (cdcover_config.cover_extensions);
	cdcover_config.cover_extensions = NULL;

	config = aud_cfg_db_open ();
	if (config) {
		// Window position
		aud_cfg_db_get_bool (config,PLUGIN_NAME,"savewindowpos",&cdcover_config.save_window_pos);
		aud_cfg_db_get_int  (config,PLUGIN_NAME,"windowposx",&cdcover_config.winpos_x);
		aud_cfg_db_get_int  (config,PLUGIN_NAME,"windowposy",&cdcover_config.winpos_y);

		// Aspect ratio
		aud_cfg_db_get_bool (config,PLUGIN_NAME,"aspectratio",&cdcover_config.preserve_aspectratio);

		// Skin
		if (!aud_cfg_db_get_string  (config,PLUGIN_NAME,"skinpath",&cdcover_config.skin_path)) {
			cdcover_config.skin_path = NULL;
		}

		// Read in the paths
		sprintf (tempname,"path1");
		count=1;
		while (aud_cfg_db_get_string (config,PLUGIN_NAME,tempname,&path)) {
			// save the pointer to this resource string in the list
			cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path);
			//printf("Got path '%s' with var %s\n", path, tempname);
			// construct next path variable
			count++;
			sprintf (tempname,"path%d",count);
		}
		// Where we able to read any search paths ?
		if (g_slist_length(cdcover_config.cover_searchpaths)==0) {
			// Some default paths to start with
			// Allocate memory, so we can free it on shutdown
			//printf("No paths found, populating with defaults\n");
			gchar *path1 = g_strconcat ("?PATH?/cover.jpg",NULL);
			gchar *path2 = g_strconcat ("?PATH?/?BASE?.jpg",NULL);
			gchar *path3 = g_strconcat ("?PATH?/media/?FILENAME?.jpg",NULL);
			gchar *path4 = g_strconcat ("?PATH?/*.jpg",NULL);
			cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path1);
			cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path2);
			cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path3);
			cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path4);
		}

		// Read in the extensions
		sprintf (tempname,"ext1");
		count=1;
		while (aud_cfg_db_get_string (config,PLUGIN_NAME,tempname,&ext)) {
			// save the pointer to this resource string in the list
			cdcover_config.cover_extensions = g_slist_append (cdcover_config.cover_extensions,ext);
			//printf("Got ext '%s' with var %s\n", ext, tempname);
			// construct next path variable
			count++;
			sprintf (tempname,"ext%d",count);
		}
		// Were we able to read any extensions?
		if (g_slist_length(cdcover_config.cover_extensions)==0) {
			// Some default extensions to start with
			// Allocate memory, so we can free it on shutdown
			//printf("No extensions found, populating with defaults\n");
			gchar *ext1 = g_strconcat ("png",NULL);
			gchar *ext2 = g_strconcat ("jpg",NULL);
			gchar *ext3 = g_strconcat ("gif",NULL);
			cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext1);
			cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext2);
			cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext3);
		}

		// Free config handle
		aud_cfg_db_close (config);
	} else {
		DPRINT (__DEBUG_GENERAL__,"Cannot open config file");
	}
}
Exemplo n.º 7
0
void
gimp_text_buffer_get_iter_at_index (GimpTextBuffer *buffer,
                                    GtkTextIter    *iter,
                                    gint            index,
                                    gboolean        layout_index)
{
  GtkTextIter  start;
  GtkTextIter  end;
  gchar       *string;

  g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));

  gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);

  string = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer),
                                     &start, &end, TRUE);

  if (layout_index)
    {
      gchar *my_string = string;
      gint   my_index  = 0;
      gchar *tmp;

      do
        {
          GSList *tags = gtk_text_iter_get_tags (&start);
          GSList *list;

          tmp = g_utf8_next_char (my_string);
          my_index += (tmp - my_string);
          my_string = tmp;

          for (list = tags; list; list = g_slist_next (list))
            {
              GtkTextTag *tag = list->data;

              if (g_list_find (buffer->kerning_tags, tag))
                {
                  index = MAX (0, index - WORD_JOINER_LENGTH);

                  break;
                }
            }

          g_slist_free (tags);

          gtk_text_iter_forward_char (&start);

          /* We might have moved too far */
          if (gtk_text_iter_compare (&start, &end) > 0)
            start = end;
        }
      while (my_index < index &&
             ! gtk_text_iter_equal (&start, &end));
    }

  string[index] = '\0';

  gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), iter,
                                      g_utf8_strlen (string, -1));

  g_free (string);
}
Exemplo n.º 8
0
static void sig_message_quit(SERVER_REC *server, const char *nick,
			     const char *address, const char *reason)
{
	WINDOW_REC *window;
	GString *chans;
	GSList *tmp, *windows;
	char *print_channel;
	int once, count;

	if (ignore_check(server, nick, address, NULL, reason, MSGLEVEL_QUITS))
		return;

	print_channel = NULL;
	once = settings_get_bool("show_quit_once");

	count = 0; windows = NULL;
	chans = g_string_new(NULL);
	for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
		CHANNEL_REC *rec = tmp->data;

		if (!nicklist_find(rec, nick))
			continue;

		if (ignore_check(server, nick, address, rec->name,
				 reason, MSGLEVEL_QUITS)) {
			count++;
			continue;
		}

		if (print_channel == NULL ||
		    active_win->active == (WI_ITEM_REC *) rec)
			print_channel = rec->name;

		if (once)
			g_string_sprintfa(chans, "%s,", rec->name);
		else {
			window = window_item_window((WI_ITEM_REC *) rec);
			if (g_slist_find(windows, window) == NULL) {
				windows = g_slist_append(windows, window);
				printformat(server, rec->name, MSGLEVEL_QUITS,
					    TXT_QUIT, nick, address, reason,
					    rec->name);
			}
		}
		count++;
	}
	g_slist_free(windows);

	if (!once) {
		/* check if you had query with the nick and
		   display the quit there too */
		QUERY_REC *query = query_find(server, nick);
		if (query != NULL) {
			printformat(server, nick, MSGLEVEL_QUITS,
				    TXT_QUIT, nick, address, reason, "");
		}
	}

	if (once || count == 0) {
		if (chans->len > 0)
			g_string_truncate(chans, chans->len-1);
		printformat(server, print_channel, MSGLEVEL_QUITS,
			    count <= 1 ? TXT_QUIT : TXT_QUIT_ONCE,
			    nick, address, reason, chans->str);
	}
	g_string_free(chans, TRUE);
}
Exemplo n.º 9
0
int 
main (int argc, char *argv[]) 
{
	int err, i;
	GNOME_Pilot_Survival survive;
	GError *error;
	GList *pilots = NULL;
	GOptionContext *option_context;
        
	bindtextdomain (PACKAGE, GNOMELOCALEDIR);
	textdomain (PACKAGE);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

	if (argc<2) {
		g_message ("usage : %s [--now|--later] [--pilot PDA] [FILE ...]", argv[0]);
		exit (1);
	}

	option_context = g_option_context_new (PACKAGE);
	g_option_context_add_main_entries (option_context, options, NULL);
	if (!g_option_context_parse(option_context, &argc, &argv, &error)) {
		g_error (_("Error parsing commandline arguments: %s"), error->message);
		exit (1);
	}

	gtk_init (&argc, &argv);

	gpc = GNOME_PILOT_CLIENT (gnome_pilot_client_new ());
	g_object_ref_sink (G_OBJECT (gpc));
	g_signal_connect (G_OBJECT (gpc),"completed_request", G_CALLBACK(gpilotd_request_completed), NULL);
	gnome_pilot_client_connect_to_daemon (gpc);

	if (pilot_arg!=NULL) {
		pilots = g_list_append (pilots, g_strdup (pilot_arg));
	} else {
		err = gnome_pilot_client_get_pilots (gpc, &pilots);
		if (err !=GPILOTD_OK || pilots == NULL) {
			g_warning (_("Unable to get PDA names"));
			show_warning_dialog (_("Unable to get PDA names"));
			exit (1);
		}
	}

	notfailed = failed = handles = NULL;

	survive = GNOME_Pilot_IMMEDIATE;
	if (later) survive = GNOME_Pilot_PERSISTENT;
	
	i=0;

	while (filenames && filenames[i]!=NULL) {
		gint err;
		err = gnome_pilot_client_install_file (gpc,
						       pilots->data, /* get first pilot */
						       filenames[i],
						       survive,
						       0,
						       &handle);
		if (err == GPILOTD_OK) {
			handles = g_slist_prepend (handles,GINT_TO_POINTER(handle));
			notfailed = g_slist_prepend (notfailed, (void *) filenames[i]);
		} else {
			failed = g_slist_prepend (failed, (void *) filenames[i]);
		}
		i++;
	}

	if (!later) {
		gchar *message;
		
		message = NULL;
		if (failed != NULL) {
			GSList *e;
			message = g_strdup (_("Following files failed :\n"));
			for (e=failed;e;e = g_slist_next (e)) {
				gchar *tmp;
				tmp = g_strconcat (message,"\t- ", e->data,"\n", NULL);
				g_free (message);
				message = tmp;
			}
			g_slist_free (failed);
		}
		{
			GSList *e;
			if (message == NULL)
				message = g_strdup_printf (_("Installing to %s:\n"), (char*)pilots->data);
			else {
				gchar *tmp;
				tmp = g_strconcat (message,"\nInstalling to ", 
						   (char*)pilots->data, ":\n", NULL);
				g_free (message);
				message = tmp;
			}
			for (e=notfailed;e;e = g_slist_next (e)) {
				gchar *tmp;
				tmp = g_strconcat (message,"\t- ", e->data,"\n", NULL);
				g_free (message);
				message = tmp;
			}
			g_slist_free (notfailed);
		}
		{
			gchar *tmp;
			gchar *info;

			if (handles == NULL) 
				info = g_strdup (_("No files to install"));
			else {
				
				info = g_strdup (_("Press synchronize on the cradle to install\n" 
						  " or cancel the operation."));
                                err = gnome_pilot_client_conduit (gpc,
                                                            pilots->data,
                                                            "File",
                                                            GNOME_Pilot_CONDUIT_DEFAULT,
                                                            survive,
                                                            0,
                                                            &handle);
			}
						
			tmp = g_strconcat (message==NULL?"":message,
					  "\n",
					  info,
					  NULL);
			g_free (message);
			g_free (info);
			message = tmp;
		}
		dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
		    GTK_MESSAGE_OTHER, GTK_BUTTONS_CANCEL, "%s",
		    message);
		gint response = gtk_dialog_run(GTK_DIALOG(dialog));
		if (dialog != NULL) /* if not destroyed by callback */
			gtk_widget_destroy(dialog);
		if (response == GTK_RESPONSE_CANCEL) {
			GSList *e;
			for (e=handles;e;e = g_slist_next (e)) {
				gnome_pilot_client_remove_request
				    (gpc,GPOINTER_TO_INT(e->data));  
			}
			g_slist_free (handles);
		}
		g_free (message);
	}

	g_object_unref (G_OBJECT (gpc));

	return 0;
}
static void
remove_button_clicked_callback (GtkWidget *button,
                                void      *data)
{
        GladeXML         *xml;
        GtkWidget        *dialog;
        GtkListStore     *tree = NULL;
        GtkTreeSelection *selection;
        GtkWidget        *treeview;
        GConfClient      *client;
        GSList           *filenames = NULL;
        GSList           *tmp = NULL;
        GSList           *loaded_files = NULL;

        dialog = data;

        xml = g_object_get_data (G_OBJECT (dialog), "treeview1");
        treeview = glade_xml_get_widget (xml, "treeview1");

        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
        gtk_tree_selection_selected_foreach (selection,
                                             get_selected_files_func,
                                             &filenames);

        if (!filenames)
                return;

        /* Remove the selected file */

        client = gconf_client_get_default ();

        loaded_files = gconf_client_get_list (client,
                                              LOADED_FILES_KEY,
                                              GCONF_VALUE_STRING,
                                              NULL);
        loaded_files = remove_string_from_list (loaded_files, (char *)filenames->data);

        gconf_client_set_list (client,
                               LOADED_FILES_KEY,
                               GCONF_VALUE_STRING,
                               loaded_files,
                               NULL);
        g_object_unref (client);

        tree = g_object_get_data (G_OBJECT (dialog), "tree");

        gtk_list_store_clear (tree);
        tmp = loaded_files;
        while (tmp != NULL) {
                GtkTreeIter iter;
                gtk_list_store_append (tree, &iter);
                gtk_list_store_set (tree, &iter,
                                    0,
                                    (char *)tmp->data,
                                    -1);
                tmp = tmp->next;
        }

        g_slist_foreach (loaded_files, (GFunc) g_free, NULL);
        g_slist_free (loaded_files);
}
static void
load_button_clicked_callback (GtkWidget *button,
                              void      *data)
{
        GtkWidget        *dialog;
        GtkListStore     *tree = NULL;
        GtkTreeSelection *selection;
        GtkWidget        *treeview;
        GSList           *filenames = NULL;
        GSList           *tmp = NULL;
        GSList           *loaded_files = NULL;
        GConfClient      *client;

        dialog = data;

        treeview = g_object_get_data (G_OBJECT (dialog),
                                      "loaded-treeview");
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
        gtk_tree_selection_selected_foreach (selection,
                                             get_selected_files_func,
                                             &filenames);

        if (!filenames)
                return;

        /* Add the files to left-tree-view */
        client = gconf_client_get_default ();

        loaded_files = gconf_client_get_list (client,
                                              LOADED_FILES_KEY,
                                              GCONF_VALUE_STRING,
                                              NULL);
        tmp = loaded_files;
        while (tmp != NULL) {
                if (strcmp (tmp->data, (char *)filenames->data) == 0)
                        return;;

                tmp = tmp->next;

        }

        loaded_files = g_slist_append (loaded_files, (char *)filenames->data);
        gconf_client_set_list (client,
                               LOADED_FILES_KEY,
                               GCONF_VALUE_STRING,
                               loaded_files,
                               NULL);

        g_object_unref (client);

        tree = g_object_get_data (G_OBJECT (dialog), "tree");

        gtk_list_store_clear (tree);
        tmp = loaded_files;
        while (tmp != NULL) {
                GtkTreeIter iter;
                gtk_list_store_append (tree, &iter);
                gtk_list_store_set (tree, &iter,
                                    0,
                                    (char *)tmp->data,
                                    -1);
                tmp = tmp->next;
        }
        g_slist_foreach (loaded_files, (GFunc) g_free, NULL);
        g_slist_free (loaded_files);
}
Exemplo n.º 12
0
void window_item_create(WI_ITEM_REC *item, int automatic)
{
	WINDOW_REC *window;
        WINDOW_BIND_REC *bind;
	GSList *tmp, *sorted;
	int clear_waiting, reuse_unused_windows;

	g_return_if_fail(item != NULL);

	reuse_unused_windows = settings_get_bool("reuse_unused_windows");

	clear_waiting = TRUE;
	window = NULL;
        sorted = windows_get_sorted();
	for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
		WINDOW_REC *rec = tmp->data;

                /* is item bound to this window? */
		if (item->server != NULL) {
			bind = window_bind_find(rec, item->server->tag,
						item->visible_name);
			if (bind != NULL) {
                                if (!bind->sticky)
					window_bind_destroy(rec, bind);
				window = rec;
				clear_waiting = FALSE;
				break;
			}
		}

		/* use this window IF:
		     - reuse_unused_windows is ON
		     - window has no existing items
		     - window has no name
		     - window has no sticky binds (/LAYOUT SAVEd)
		     - we already haven't found "good enough" window,
		       except if
                         - this is the active window
                         - old window had some temporary bounds and this
			   one doesn't
		     */
		if (reuse_unused_windows && rec->items == NULL &&
		    rec->name == NULL && !window_bind_has_sticky(rec) &&
		    (window == NULL || rec == active_win ||
		     window->bound_items != NULL))
			window = rec;
	}
        g_slist_free(sorted);

        if (window == NULL && !settings_get_bool("autocreate_windows")) {
                /* never create new windows automatically */
                window = active_win;
        }

	if (window == NULL) {
		/* create new window to use */
		if (settings_get_bool("autocreate_split_windows")) {
			signal_emit("gui window create override", 1,
				    GINT_TO_POINTER(MAIN_WINDOW_TYPE_SPLIT));
		}
		window = window_create(item, automatic);
	} else {
		/* use existing window */
		window_item_add(window, item, automatic);
	}

	if (clear_waiting)
                window_bind_remove_unsticky(window);
}
Exemplo n.º 13
0
static void session_activate(struct connman_session *session)
{
	GHashTableIter iter;
	gpointer key, value;

	if (!service_hash)
		return;

	if (policy && policy->get_service_for_session) {
		struct connman_service *service;
		struct connman_service_info *info;
		GSList *service_list = NULL;
		enum connman_service_state state = CONNMAN_SESSION_STATE_DISCONNECTED;

		g_hash_table_iter_init(&iter, service_hash);

		while (g_hash_table_iter_next(&iter, &key, &value)) {
			struct connman_service_info *info = value;
			state = connman_service_get_state(info->service);

			if (is_session_connected(session, state))
				service_list = g_slist_prepend(service_list,
							       info->service);
		}

		service_list = g_slist_reverse(service_list);
		service = policy->get_service_for_session(session, service_list);

		if (service) {
			info = g_hash_table_lookup(service_hash, service);
			DBG("session %p add service %p", session, info->service);

			info->sessions = g_slist_prepend(info->sessions,
							session);
			session->service = info->service;
			update_session_state(session);
		}

		g_slist_free(service_list);
		return;
	}

	g_hash_table_iter_init(&iter, service_hash);
	while (g_hash_table_iter_next(&iter, &key, &value)) {
		struct connman_service_info *info = value;
		enum connman_service_state state;

		state = connman_service_get_state(info->service);

		if (is_session_connected(session, state) &&
				session_match_service(session, info->service)) {
			DBG("session %p add service %p", session, info->service);

			info->sessions = g_slist_prepend(info->sessions,
							session);
			session->service = info->service;
			update_session_state(session);

			return;
		}
	}

	session_notify(session);
}
Exemplo n.º 14
0
static DBusMessage *change_session(DBusConnection *conn,
					DBusMessage *msg, void *user_data)
{
	struct connman_session *session = user_data;
	struct session_info *info = session->info;
	DBusMessageIter iter, value;
	const char *name;
	const char *val;
	GSList *allowed_bearers;
	int err;

	DBG("session %p", session);
	if (!dbus_message_iter_init(msg, &iter))
		return __connman_error_invalid_arguments(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __connman_error_invalid_arguments(msg);

	dbus_message_iter_get_basic(&iter, &name);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
		return __connman_error_invalid_arguments(msg);

	dbus_message_iter_recurse(&iter, &value);

	switch (dbus_message_iter_get_arg_type(&value)) {
	case DBUS_TYPE_ARRAY:
		if (g_str_equal(name, "AllowedBearers")) {
			err = parse_bearers(&value, &allowed_bearers);
			if (err < 0)
				return __connman_error_failed(msg, -err);

			if (session->active)
				set_active_session(session, false);

			session->active = false;
			session_deactivate(session);
			update_session_state(session);

			g_slist_free(info->config.allowed_bearers);
			session->user_allowed_bearers = allowed_bearers;

			apply_policy_on_bearers(
					session->policy_config->allowed_bearers,
					session->user_allowed_bearers,
					&info->config.allowed_bearers);

			session_activate(session);
		} else {
			goto err;
		}
		break;
	case DBUS_TYPE_STRING:
		if (g_str_equal(name, "ConnectionType")) {
			dbus_message_iter_get_basic(&value, &val);
			info->config.type = apply_policy_on_type(
				session->policy_config->type,
				connman_session_parse_connection_type(val));
		} else if (g_str_equal(name, "AllowedInterface")) {
			dbus_message_iter_get_basic(&value, &val);
			if (session->active)
				set_active_session(session, false);

			session->active = false;
			session_deactivate(session);
			update_session_state(session);

			g_free(session->user_allowed_interface);
			/* empty string means allow any interface */
			if (!g_strcmp0(val, ""))
				session->user_allowed_interface = NULL;
			else
				session->user_allowed_interface = g_strdup(val);

			info->config.allowed_interface = apply_policy_on_interface(
				session->policy_config->allowed_interface,
				session->user_allowed_interface);

			session_activate(session);
		} else {
			goto err;
		}
		break;
	case DBUS_TYPE_BOOLEAN:
		if (g_str_equal(name, "SourceIPRule")) {
			dbus_bool_t source_ip_rule;
			dbus_message_iter_get_basic(&value, &source_ip_rule);

			info->config.source_ip_rule = source_ip_rule;
			update_session_state(session);
		} else {
			goto err;
		}
		break;
	default:
		goto err;
	}

	session_notify(session);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);

err:
	return __connman_error_invalid_arguments(msg);
}
Exemplo n.º 15
0
void
sp_sel_trans_ungrab (SPSelTrans * seltrans)
{
	SPItem * item;
	const GSList * l;
	gchar tstr[80];
	NRPointD p;
	unsigned int updh;

	g_return_if_fail (seltrans->grabbed);

	updh = TRUE;
	if (!seltrans->empty && seltrans->changed) {
		l = sp_selection_item_list (SP_DT_SELECTION (seltrans->desktop));

		tstr[79] = '\0';

		while (l != NULL) {
			item = SP_ITEM (l->data);
			/* fixme: We do not have to set it here (Lauris) */
			if (seltrans->show == SP_SELTRANS_SHOW_OUTLINE) {
				NRMatrixF i2d, i2dnew;
				sp_item_i2d_affine (item, &i2d);
				nr_matrix_multiply_ffd (&i2dnew, &i2d, &seltrans->current);
				sp_item_set_i2d_affine (item, &i2dnew);
			}
			if (seltrans->transform == SP_SELTRANS_TRANSFORM_OPTIMIZE) {
				sp_item_write_transform (item, SP_OBJECT_REPR (item), &item->transform);
				/* because item/repr affines may be out of sync, invoke reread */
				/* fixme: We should test equality to avoid unnecessary rereads */
				/* fixme: This probably is not needed (Lauris) */
				sp_object_read_attr (SP_OBJECT (item), "transform");
			} else {
				if (sp_svg_transform_write (tstr, 79, &item->transform)) {
					sp_repr_set_attr (SP_OBJECT (item)->repr, "transform", tstr);
				} else {
					sp_repr_set_attr (SP_OBJECT (item)->repr, "transform", NULL);
				}
			}
			l = l->next;
		}
		p = seltrans->center;
		seltrans->center.x = NR_MATRIX_DF_TRANSFORM_X (&seltrans->current, p.x, p.y);
		seltrans->center.y = NR_MATRIX_DF_TRANSFORM_Y (&seltrans->current, p.x, p.y);
		
		sp_document_done (SP_DT_DOCUMENT (seltrans->desktop));
		sp_selection_changed (SP_DT_SELECTION (seltrans->desktop));

		updh = FALSE;
	}

	if (seltrans->items) {
		int i;
		for (i = 0; i < seltrans->nitems; i++) sp_object_unref (SP_OBJECT (seltrans->items[i]), NULL);
		nr_free (seltrans->items);
		seltrans->items = NULL;
	}
	if (seltrans->transforms) {
		nr_free (seltrans->transforms);
		seltrans->transforms = NULL;
	}
	seltrans->nitems = 0;

	seltrans->grabbed = FALSE;
	seltrans->show_handles = TRUE;
	
	sp_canvas_item_hide (seltrans->norm);
	sp_canvas_item_hide (seltrans->grip);

        if (seltrans->show == SP_SELTRANS_SHOW_OUTLINE) {
		sp_canvas_item_hide (seltrans->l1);
		sp_canvas_item_hide (seltrans->l2);
		sp_canvas_item_hide (seltrans->l3);
		sp_canvas_item_hide (seltrans->l4);
	}

	sp_sel_trans_update_volatile_state (seltrans);
	if (updh) sp_sel_trans_update_handles (seltrans);
	if (seltrans->stamp_cache) {
		g_slist_free(seltrans->stamp_cache);
		seltrans->stamp_cache = NULL;
	}

}
Exemplo n.º 16
0
void
pixmap_save_cb(GtkWidget *w, gpointer pixmap_ptr _U_)
{
	GtkWidget *save_as_w;
#if GTK_CHECK_VERSION(2,22,0)
	surface_info_t *surface_info = (surface_info_t *)g_object_get_data(G_OBJECT(w), "surface-info");
#else
	GdkPixmap *pixmap = (GdkPixmap *)g_object_get_data(G_OBJECT(w), "pixmap");
#endif
	GdkPixbuf *pixbuf;
	GdkPixbufFormat *pixbuf_format;
	GtkWidget *main_vb, *save_as_type_hb, *type_lb, *type_cm;
	GSList *file_formats,*ffp;
	GdkWindow *parent;

	gchar *format_name;
	guint format_index = 0;
	guint default_index = 0;

	gchar *filename, *file_type;
	GError *error = NULL;
	gboolean ret;
	GtkWidget *msg_dialog;

#if GTK_CHECK_VERSION(2,22,0)
	pixbuf = gdk_pixbuf_get_from_surface (surface_info->surface,
		0, 0, surface_info->width, surface_info->height);
#else
	pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL,
					      0, 0, 0, 0, -1, -1);
#endif
	if(!pixbuf) {
		simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
			      "%sCould not get image from graph%s",
			      simple_dialog_primary_start(),
			      simple_dialog_primary_end());
		return;
	}

	save_as_w = file_selection_new("Wireshark: Save Graph As ...",
				       FILE_SELECTION_SAVE);
	gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(save_as_w), TRUE);

	/* Container for each row of widgets */
	main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
	file_selection_set_extra_widget(save_as_w, main_vb);
	gtk_widget_show(main_vb);

	save_as_type_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
	gtk_box_pack_start(GTK_BOX(main_vb), save_as_type_hb, FALSE, FALSE, 0);
	gtk_widget_show(save_as_type_hb);

	type_lb = gtk_label_new("File type: ");
	gtk_box_pack_start(GTK_BOX(save_as_type_hb), type_lb, FALSE, FALSE, 0);
	gtk_widget_show(type_lb);

	type_cm = gtk_combo_box_text_new();
	gtk_box_pack_start(GTK_BOX(save_as_type_hb), type_cm, FALSE, FALSE, 0);

	/* List all of the file formats the gdk-pixbuf library supports */
	file_formats = gdk_pixbuf_get_formats();
	ffp = file_formats;
	while(ffp) {
		pixbuf_format = (GdkPixbufFormat *)ffp->data;
		if (gdk_pixbuf_format_is_writable(pixbuf_format)) {
			format_name = gdk_pixbuf_format_get_name(pixbuf_format);
			 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(type_cm),
						  format_name);
			if (!(g_ascii_strcasecmp(format_name, "png")))
				default_index = format_index;
			format_index++;
		}
		ffp = g_slist_next(ffp);
	}
	g_slist_free(file_formats);

	gtk_combo_box_set_active(GTK_COMBO_BOX(type_cm), default_index);
	gtk_widget_show(type_cm);

	gtk_widget_show(save_as_w);
	window_present(save_as_w);
	parent = gtk_widget_get_parent_window(w);
	gdk_window_set_transient_for(gtk_widget_get_window(save_as_w), parent);

	/*
	 * Loop until the user either selects a file or gives up.
	 */
	for (;;) {
		if (gtk_dialog_run(GTK_DIALOG(save_as_w)) != GTK_RESPONSE_ACCEPT) {
			/* They clicked "Cancel" or closed the dialog or.... */
			window_destroy(save_as_w);
			return;
		}

		filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(save_as_w));

		/* Perhaps the user specified a directory instead of a file.
		   Check whether they did. */
		if (test_for_directory(filename) == EISDIR) {
			/* It's a directory - set the file selection box to display that
			   directory, and leave the selection box displayed. */
			set_last_open_dir(filename);
			g_free(filename);
			file_selection_set_current_folder(save_as_w,
							  get_last_open_dir());
			gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(save_as_w), "");
			continue;
		}

		file_type = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(type_cm));
		ret = gdk_pixbuf_save(pixbuf, filename, file_type, &error, NULL);
		g_free(filename);
		g_free(file_type);

		if (!ret) {
			msg_dialog = gtk_message_dialog_new(GTK_WINDOW(save_as_w),
                                          GTK_DIALOG_DESTROY_WITH_PARENT,
                                          GTK_MESSAGE_ERROR,
                                          GTK_BUTTONS_OK,
                                          "%s", error->message);
			gtk_dialog_run(GTK_DIALOG(msg_dialog));
			gtk_widget_destroy(msg_dialog);
			continue;
		}

		window_destroy(save_as_w);
		return;
	}
}
Exemplo n.º 17
0
static void
write_network_to_xml (const gchar *id,
                      EmpathyIrcNetwork *network,
                      xmlNodePtr root)
{
  xmlNodePtr network_node, servers_node;
  GSList *servers, *l;
  gchar *name, *charset;

  if (!network->user_defined)
    /* no need to write this network to the XML */
    return;

  network_node = xmlNewChild (root, NULL, "network", NULL);
  xmlNewProp (network_node, "id", id);

  if (network->dropped)
    {
      xmlNewProp (network_node, "dropped", "1");
      return;
    }

  g_object_get (network,
      "name", &name,
      "charset", &charset,
      NULL);
  xmlNewProp (network_node, "name", name);
  xmlNewProp (network_node, "network_charset", charset);
  g_free (name);
  g_free (charset);

  servers = empathy_irc_network_get_servers (network);

  servers_node = xmlNewChild (network_node, NULL, "servers", NULL);
  for (l = servers; l != NULL; l = g_slist_next (l))
    {
      EmpathyIrcServer *server;
      xmlNodePtr server_node;
      gchar *address, *tmp;
      guint port;
      gboolean ssl;

      server = l->data;

      server_node = xmlNewChild (servers_node, NULL, "server", NULL);

      g_object_get (server,
          "address", &address,
          "port", &port,
          "ssl", &ssl,
          NULL);

      xmlNewProp (server_node, "address", address);

      tmp = g_strdup_printf ("%u", port);
      xmlNewProp (server_node, "port", tmp);
      g_free (tmp);

      xmlNewProp (server_node, "ssl", ssl ? "TRUE": "FALSE");

      g_free (address);
    }

  /* free the list */
  g_slist_foreach (servers, (GFunc) g_object_unref, NULL);
  g_slist_free (servers);
}
Exemplo n.º 18
0
void
gaim_connection_destroy(GaimConnection *gc)
{
	GaimAccount *account;
	GSList *buddies, *tmp;
#if 0
	GList *wins;
#endif
	GaimPluginProtocolInfo *prpl_info = NULL;
	gboolean remove = FALSE;

	g_return_if_fail(gc != NULL);

	account = gaim_connection_get_account(gc);

	gaim_debug_info("connection", "Disconnecting connection %p\n", gc);

	if (gaim_connection_get_state(gc) != GAIM_CONNECTING)
		remove = TRUE;

	gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc);

	while (gc->buddy_chats)
	{
		GaimConversation *b = gc->buddy_chats->data;

		gc->buddy_chats = g_slist_remove(gc->buddy_chats, b);
		gaim_conv_chat_left(GAIM_CONV_CHAT(b));
	}

	update_keepalive(gc, FALSE);

	gaim_proxy_connect_cancel_with_handle(gc);

	prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
	if (prpl_info->close)
		(prpl_info->close)(gc);

	/* Clear out the proto data that was freed in the prpl close method*/
	buddies = gaim_find_buddies(account, NULL);
	for (tmp = buddies; tmp; tmp = tmp->next) {
		GaimBuddy *buddy = tmp->data;
		buddy->proto_data = NULL;
	}
	g_slist_free(buddies);

	connections = g_list_remove(connections, gc);

	gaim_connection_set_state(gc, GAIM_DISCONNECTED);

	if (remove)
		gaim_blist_remove_account(account);

	gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc);

#if 0
	/* see comment later in file on if 0'd same code */
	/*
	 * XXX This is a hack! Remove this and replace it with a better event
	 *     notification system.
	 */
	for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) {
		GaimConvWindow *win = (GaimConvWindow *)wins->data;
		gaim_conversation_update(gaim_conv_window_get_conversation_at(win, 0),
								 GAIM_CONV_ACCOUNT_OFFLINE);
	}
#endif

	gaim_request_close_with_handle(gc);
	gaim_notify_close_with_handle(gc);

	gaim_debug_info("connection", "Destroying connection %p\n", gc);

	gaim_account_set_connection(account, NULL);

	g_free(gc->password);
	g_free(gc->display_name);

	if (gc->disconnect_timeout)
		gaim_timeout_remove(gc->disconnect_timeout);

	GAIM_DBUS_UNREGISTER_POINTER(gc);
	g_free(gc);
}
Exemplo n.º 19
0
void
gimp_text_buffer_insert (GimpTextBuffer *buffer,
                         const gchar    *text)
{
  GtkTextIter  iter, start;
  gint         start_offset;
  gboolean     insert_tags_set;
  GList       *insert_tags;
  GList       *remove_tags;
  GSList      *tags_off = NULL;

  g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));

  gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &iter,
                                    gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer)));

  start_offset = gtk_text_iter_get_offset (&iter);

  insert_tags_set = buffer->insert_tags_set;
  insert_tags     = buffer->insert_tags;
  remove_tags     = buffer->remove_tags;

  buffer->insert_tags_set = FALSE;
  buffer->insert_tags     = NULL;
  buffer->remove_tags     = NULL;

  tags_off = gtk_text_iter_get_toggled_tags (&iter, FALSE);

  gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));

  gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &iter, text, -1);

  gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &start,
                                      start_offset);

  if (insert_tags_set)
    {
      GList *list;

      for (list = remove_tags; list; list = g_list_next (list))
        {
          GtkTextTag *tag = list->data;

          gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (buffer), tag,
                                      &start, &iter);
        }

      for (list = insert_tags; list; list = g_list_next (list))
        {
          GtkTextTag *tag = list->data;

          gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), tag,
                                     &start, &iter);
        }
    }

  if (tags_off)
    {
      GSList *slist;

      for (slist = tags_off; slist; slist = g_slist_next (slist))
        {
          GtkTextTag *tag = slist->data;

          if (! g_list_find (remove_tags, tag) &&
              ! g_list_find (buffer->kerning_tags, tag))
            {
              gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), tag,
                                         &start, &iter);
            }
        }

      g_slist_free (tags_off);
    }

  g_list_free (remove_tags);
  g_list_free (insert_tags);

  gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
}
Exemplo n.º 20
0
Arquivo: gc.c Projeto: moander/mono
/* 
 * actually, we might want to queue the finalize requests in a separate thread,
 * but we need to be careful about the execution domain of the thread...
 */
void
mono_gc_run_finalize (void *obj, void *data)
{
	MonoObject *exc = NULL;
	MonoObject *o;
#ifndef HAVE_SGEN_GC
	MonoObject *o2;
#endif
	MonoMethod* finalizer = NULL;
	MonoDomain *caller_domain = mono_domain_get ();
	MonoDomain *domain;
	RuntimeInvokeFunction runtime_invoke;
	GSList *l, *refs = NULL;

	o = (MonoObject*)((char*)obj + GPOINTER_TO_UINT (data));

	if (suspend_finalizers)
		return;

	domain = o->vtable->domain;

#ifndef HAVE_SGEN_GC
	mono_domain_finalizers_lock (domain);

	o2 = g_hash_table_lookup (domain->finalizable_objects_hash, o);

	refs = mono_gc_remove_weak_track_object (domain, o);

	mono_domain_finalizers_unlock (domain);

	if (!o2)
		/* Already finalized somehow */
		return;
#endif

	if (refs) {
		/*
		 * Support for GCHandles of type WeakTrackResurrection:
		 *
		 *   Its not exactly clear how these are supposed to work, or how their
		 * semantics can be implemented. We only implement one crucial thing:
		 * these handles are only cleared after the finalizer has ran.
		 */
		for (l = refs; l; l = l->next) {
			guint32 gchandle = GPOINTER_TO_UINT (l->data);

			mono_gchandle_set_target (gchandle, o);
		}

		g_slist_free (refs);
	}
		
	/* make sure the finalizer is not called again if the object is resurrected */
	object_register_finalizer (obj, NULL);

	if (o->vtable->klass == mono_defaults.internal_thread_class) {
		MonoInternalThread *t = (MonoInternalThread*)o;

		if (mono_gc_is_finalizer_internal_thread (t))
			/* Avoid finalizing ourselves */
			return;

		if (t->threadpool_thread && finalizing_root_domain) {
			/* Don't finalize threadpool threads when
			   shutting down - they're finalized when the
			   threadpool shuts down. */
			add_thread_to_finalize (t);
			return;
		}
	}

	if (o->vtable->klass->image == mono_defaults.corlib && !strcmp (o->vtable->klass->name, "DynamicMethod") && finalizing_root_domain) {
		/*
		 * These can't be finalized during unloading/shutdown, since that would
		 * free the native code which can still be referenced by other
		 * finalizers.
		 * FIXME: This is not perfect, objects dying at the same time as 
		 * dynamic methods can still reference them even when !shutdown.
		 */
		return;
	}

	if (mono_runtime_get_no_exec ())
		return;

	/* speedup later... and use a timeout */
	/* g_print ("Finalize run on %p %s.%s\n", o, mono_object_class (o)->name_space, mono_object_class (o)->name); */

	/* Use _internal here, since this thread can enter a doomed appdomain */
	mono_domain_set_internal (mono_object_domain (o));

	/* delegates that have a native function pointer allocated are
	 * registered for finalization, but they don't have a Finalize
	 * method, because in most cases it's not needed and it's just a waste.
	 */
	if (o->vtable->klass->delegate) {
		MonoDelegate* del = (MonoDelegate*)o;
		if (del->delegate_trampoline)
			mono_delegate_free_ftnptr ((MonoDelegate*)o);
		mono_domain_set_internal (caller_domain);
		return;
	}

	finalizer = mono_class_get_finalizer (o->vtable->klass);

#ifndef DISABLE_COM
	/* If object has a CCW but has no finalizer, it was only
	 * registered for finalization in order to free the CCW.
	 * Else it needs the regular finalizer run.
	 * FIXME: what to do about ressurection and suppression
	 * of finalizer on object with CCW.
	 */
	if (mono_marshal_free_ccw (o) && !finalizer) {
		mono_domain_set_internal (caller_domain);
		return;
	}
#endif

	/* 
	 * To avoid the locking plus the other overhead of mono_runtime_invoke (),
	 * create and precompile a wrapper which calls the finalize method using
	 * a CALLVIRT.
	 */
	if (!domain->finalize_runtime_invoke) {
		MonoMethod *invoke = mono_marshal_get_runtime_invoke (mono_class_get_method_from_name_flags (mono_defaults.object_class, "Finalize", 0, 0), TRUE);

		domain->finalize_runtime_invoke = mono_compile_method (invoke);
	}

	runtime_invoke = domain->finalize_runtime_invoke;

	mono_runtime_class_init (o->vtable);

	runtime_invoke (o, NULL, &exc, NULL);

	if (exc) {
		/* fixme: do something useful */
	}

	mono_domain_set_internal (caller_domain);
}
Exemplo n.º 21
0
static gboolean
mate_panel_applet_load_idle_handler (gpointer dummy)
{
	PanelObjectType    applet_type;
	MatePanelAppletToLoad *applet = NULL;
	PanelToplevel     *toplevel = NULL;
	PanelWidget       *panel_widget;
	GSList            *l;

	if (!mate_panel_applets_to_load) {
		mate_panel_applet_have_load_idle = FALSE;
		return FALSE;
	}

	for (l = mate_panel_applets_to_load; l; l = l->next) {
		applet = l->data;

		toplevel = panel_profile_get_toplevel_by_id (applet->toplevel_id);
		if (toplevel)
			break;
	}

	if (!l) {
		/* All the remaining applets don't have a panel */
		for (l = mate_panel_applets_to_load; l; l = l->next)
			free_applet_to_load (l->data);
		g_slist_free (mate_panel_applets_to_load);
		mate_panel_applets_to_load = NULL;
		mate_panel_applet_have_load_idle = FALSE;

		if (mate_panel_applets_loading == NULL) {
			/* unhide any potential initially hidden toplevel */
			mate_panel_applet_queue_initial_unhide_toplevels (NULL);
		}

		return FALSE;
	}

	mate_panel_applets_to_load = g_slist_delete_link (mate_panel_applets_to_load, l);
	mate_panel_applets_loading = g_slist_append (mate_panel_applets_loading, applet);

	panel_widget = panel_toplevel_get_panel_widget (toplevel);

	if (applet->right_stick) {
		if (!panel_widget->packed)
			applet->position = panel_widget->size - applet->position;
		else
			applet->position = -1;
	}

	/* We load applets asynchronously, so we specifically don't call
	 * mate_panel_applet_stop_loading() for this type. However, in case of
	 * failure during the load, we might call mate_panel_applet_stop_loading()
	 * synchronously, which will make us lose the content of the applet
	 * variable. So we save the type to be sure we always ignore the
	 * applets. */
	applet_type = applet->type;

	switch (applet_type) {
	case PANEL_OBJECT_APPLET:
		mate_panel_applet_frame_load_from_gsettings (
					panel_widget,
					applet->locked,
					applet->position,
					applet->id);
		break;
	case PANEL_OBJECT_DRAWER:
		drawer_load_from_gsettings (panel_widget,
					applet->locked,
					applet->position,
					applet->id);
		break;
	case PANEL_OBJECT_MENU:
		panel_menu_button_load_from_gsettings (panel_widget,
						   applet->locked,
						   applet->position,
						   TRUE,
						   applet->id);
		break;
	case PANEL_OBJECT_LAUNCHER:
		launcher_load_from_gsettings (panel_widget,
					  applet->locked,
					  applet->position,
					  applet->id);
		break;
	case PANEL_OBJECT_ACTION:
		panel_action_button_load_from_gsettings (
				panel_widget,
				applet->locked,
				applet->position,
				TRUE,
				applet->id);
		break;
	case PANEL_OBJECT_MENU_BAR:
		panel_menu_bar_load_from_gsettings (
				panel_widget,
				applet->locked,
				applet->position,
				TRUE,
				applet->id);
		break;
	case PANEL_OBJECT_SEPARATOR:
		panel_separator_load_from_gsettings (panel_widget,
						 applet->locked,
						 applet->position,
						 applet->id);
		break;
	default:
		g_assert_not_reached ();
		break;
	}

	/* Only the real applets will do a late stop_loading */
	if (applet_type != PANEL_OBJECT_APPLET)
		mate_panel_applet_stop_loading (applet->id);

	return TRUE;
}
Exemplo n.º 22
0
static void
dissect_file_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
{
	proto_item  *volatile ti = NULL;
	guint	     cap_len = 0, frame_len = 0;
	proto_tree  *volatile tree;
	proto_item  *item;
	const gchar *cap_plurality, *frame_plurality;

	tree=parent_tree;

	pinfo->current_proto = "File";

	/* if FILE is not referenced from any filters we don't need to worry about
	   generating any tree items.  */
	if(!proto_field_is_referenced(tree, proto_file)) {
		tree=NULL;
	} else {
		proto_tree *fh_tree;
		gboolean old_visible;

		/* Put in frame header information. */
		cap_len = tvb_length(tvb);
		frame_len = tvb_reported_length(tvb);

		cap_plurality = plurality(cap_len, "", "s");
		frame_plurality = plurality(frame_len, "", "s");

		ti = proto_tree_add_protocol_format(tree, proto_file, tvb, 0, -1,
		    "File record %u: %u byte%s",
		    pinfo->fd->num, frame_len, frame_plurality);
		proto_item_append_text(ti, ", %u byte%s",
		    cap_len, cap_plurality);

		fh_tree = proto_item_add_subtree(ti, ett_file);

		proto_tree_add_int(fh_tree, hf_file_ftap_encap, tvb, 0, 0, pinfo->fd->lnk_t);

		proto_tree_add_uint(fh_tree, hf_file_record_number, tvb, 0, 0, pinfo->fd->num);

		proto_tree_add_uint_format(fh_tree, hf_file_record_len, tvb,
					   0, 0, frame_len, "Record Length: %u byte%s (%u bits)",
					   frame_len, frame_plurality, frame_len * 8);

		ti = proto_tree_add_boolean(fh_tree, hf_file_marked, tvb, 0, 0,pinfo->fd->flags.marked);
		PROTO_ITEM_SET_GENERATED(ti);

		ti = proto_tree_add_boolean(fh_tree, hf_file_ignored, tvb, 0, 0,pinfo->fd->flags.ignored);
		PROTO_ITEM_SET_GENERATED(ti);

		if(proto_field_is_referenced(tree, hf_file_protocols)) {
			/* we are going to be using proto_item_append_string() on
			 * hf_frame_protocols, and we must therefore disable the
			 * TRY_TO_FAKE_THIS_ITEM() optimisation for the tree by
			 * setting it as visible.
			 *
			 * See proto.h for details.
			 */
			old_visible = proto_tree_set_visible(fh_tree, TRUE);
			ti = proto_tree_add_string(fh_tree, hf_file_protocols, tvb, 0, 0, "");
			PROTO_ITEM_SET_GENERATED(ti);
			proto_tree_set_visible(fh_tree, old_visible);
		}

		if(pinfo->fd->pfd != 0){
			proto_item *ppd_item;
			guint num_entries = g_slist_length(pinfo->fd->pfd);
			guint i;
			ppd_item = proto_tree_add_uint(fh_tree, hf_file_num_p_prot_data, tvb, 0, 0, num_entries);
			PROTO_ITEM_SET_GENERATED(ppd_item);
			for(i=0; i<num_entries; i++){
				proto_tree_add_text (fh_tree, tvb, 0, 0, "%s",p_get_proto_name_and_key(wmem_file_scope(), pinfo, i));
			}
		}

#if 0
		if (show_file_off) {
			proto_tree_add_int64_format_value(fh_tree, hf_frame_file_off, tvb,
						    0, 0, pinfo->fd->file_off,
						    "%" G_GINT64_MODIFIER "d (0x%" G_GINT64_MODIFIER "x)",
						    pinfo->fd->file_off, pinfo->fd->file_off);
		}
#endif

		if(pinfo->fd->color_filter != NULL) {
			const color_filter_t *color_filter = (const color_filter_t *)pinfo->fd->color_filter;
			item = proto_tree_add_string(fh_tree, hf_file_color_filter_name, tvb,
						     0, 0, color_filter->filter_name);
			PROTO_ITEM_SET_GENERATED(item);
			item = proto_tree_add_string(fh_tree, hf_file_color_filter_text, tvb,
						     0, 0, color_filter->filter_text);
			PROTO_ITEM_SET_GENERATED(item);
		}
	}

	if (pinfo->fd->flags.ignored) {
		/* Ignored package, stop handling here */
		col_set_str(pinfo->cinfo, COL_INFO, "<Ignored>");
		proto_tree_add_text (tree, tvb, 0, -1, "This record is marked as ignored");
		return;
	}

	/* Portable Exception Handling to trap Wireshark specific exceptions like BoundsError exceptions */
	TRY {
#ifdef _MSC_VER
		/* Win32: Visual-C Structured Exception Handling (SEH) to trap hardware exceptions
		   like memory access violations.
		   (a running debugger will be called before the except part below) */
                /* Note: A Windows "exceptional exception" may leave the kazlib's (Portable Exception Handling)
                   stack in an inconsistent state thus causing a crash at some point in the
                   handling of the exception.
                   See: https://www.wireshark.org/lists/wireshark-dev/200704/msg00243.html
                */
		__try {
#endif
			if (!dissector_try_uint(file_encap_dissector_table, pinfo->fd->lnk_t,
						tvb, pinfo, parent_tree)) {

				col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN");
				col_add_fstr(pinfo->cinfo, COL_INFO, "FTAP_ENCAP = %d",
					     pinfo->fd->lnk_t);
				call_dissector(data_handle,tvb, pinfo, parent_tree);
			}
#ifdef _MSC_VER
		} __except(EXCEPTION_EXECUTE_HANDLER /* handle all exceptions */) {
			switch(GetExceptionCode()) {
			case(STATUS_ACCESS_VIOLATION):
				show_exception(tvb, pinfo, parent_tree, DissectorError,
					       "STATUS_ACCESS_VIOLATION: dissector accessed an invalid memory address");
				break;
			case(STATUS_INTEGER_DIVIDE_BY_ZERO):
				show_exception(tvb, pinfo, parent_tree, DissectorError,
					       "STATUS_INTEGER_DIVIDE_BY_ZERO: dissector tried an integer division by zero");
				break;
			case(STATUS_STACK_OVERFLOW):
				show_exception(tvb, pinfo, parent_tree, DissectorError,
					       "STATUS_STACK_OVERFLOW: dissector overflowed the stack (e.g. endless loop)");
				/* XXX - this will have probably corrupted the stack,
				   which makes problems later in the exception code */
				break;
				/* XXX - add other hardware exception codes as required */
			default:
				show_exception(tvb, pinfo, parent_tree, DissectorError,
					       g_strdup_printf("dissector caused an unknown exception: 0x%x", GetExceptionCode()));
			}
		}
#endif
	}
	CATCH_BOUNDS_AND_DISSECTOR_ERRORS {
		show_exception(tvb, pinfo, parent_tree, EXCEPT_CODE, GET_MESSAGE);
	}
	ENDTRY;

    if(proto_field_is_referenced(tree, hf_file_protocols)) {
		wmem_strbuf_t *val = wmem_strbuf_new(wmem_packet_scope(), "");
		wmem_list_frame_t *frame;
		/* skip the first entry, it's always the "frame" protocol */
		frame = wmem_list_frame_next(wmem_list_head(pinfo->layers));
		if (frame) {
			wmem_strbuf_append(val, proto_get_protocol_filter_name(GPOINTER_TO_UINT(wmem_list_frame_data(frame))));
			frame = wmem_list_frame_next(frame);
		}
		while (frame) {
			wmem_strbuf_append_c(val, ':');
			wmem_strbuf_append(val, proto_get_protocol_filter_name(GPOINTER_TO_UINT(wmem_list_frame_data(frame))));
			frame = wmem_list_frame_next(frame);
		}
		proto_item_append_string(ti, wmem_strbuf_get_str(val));
	}

	/*  Call postdissectors if we have any (while trying to avoid another
	 *  TRY/CATCH)
	 */
	if (have_postdissector()) {
		TRY {
#ifdef _MSC_VER
			/* Win32: Visual-C Structured Exception Handling (SEH)
			   to trap hardware exceptions like memory access violations */
			/* (a running debugger will be called before the except part below) */
                        /* Note: A Windows "exceptional exception" may leave the kazlib's (Portable Exception Handling)
                           stack in an inconsistent state thus causing a crash at some point in the
                           handling of the exception.
                           See: https://www.wireshark.org/lists/wireshark-dev/200704/msg00243.html
                        */
			__try {
#endif
				call_all_postdissectors(tvb, pinfo, parent_tree);
#ifdef _MSC_VER
			} __except(EXCEPTION_EXECUTE_HANDLER /* handle all exceptions */) {
				switch(GetExceptionCode()) {
				case(STATUS_ACCESS_VIOLATION):
					show_exception(tvb, pinfo, parent_tree, DissectorError,
						       "STATUS_ACCESS_VIOLATION: dissector accessed an invalid memory address");
					break;
				case(STATUS_INTEGER_DIVIDE_BY_ZERO):
					show_exception(tvb, pinfo, parent_tree, DissectorError,
						       "STATUS_INTEGER_DIVIDE_BY_ZERO: dissector tried an integer division by zero");
					break;
				case(STATUS_STACK_OVERFLOW):
					show_exception(tvb, pinfo, parent_tree, DissectorError,
						       "STATUS_STACK_OVERFLOW: dissector overflowed the stack (e.g. endless loop)");
					/* XXX - this will have probably corrupted the stack,
					   which makes problems later in the exception code */
					break;
					/* XXX - add other hardware exception codes as required */
				default:
					show_exception(tvb, pinfo, parent_tree, DissectorError,
						       g_strdup_printf("dissector caused an unknown exception: 0x%x", GetExceptionCode()));
				}
			}
#endif
		}
		CATCH_BOUNDS_AND_DISSECTOR_ERRORS {
			show_exception(tvb, pinfo, parent_tree, EXCEPT_CODE, GET_MESSAGE);
		}
		ENDTRY;
	}

	tap_queue_packet(file_tap, pinfo, NULL);


	if (pinfo->frame_end_routines) {
		g_slist_foreach(pinfo->frame_end_routines, &call_file_record_end_routine, NULL);
		g_slist_free(pinfo->frame_end_routines);
		pinfo->frame_end_routines = NULL;
	}
}
Exemplo n.º 23
0
/*
 * get_throw_trampoline:
 *
 *  Generate a call to mono_x86_throw_exception/
 * mono_x86_throw_corlib_exception.
 * If LLVM is true, generate code which assumes the caller is LLVM generated code, 
 * which doesn't push the arguments.
 */
static guint8*
get_throw_trampoline (const char *name, gboolean rethrow, gboolean llvm, gboolean corlib, gboolean llvm_abs, gboolean resume_unwind, MonoTrampInfo **info, gboolean aot)
{
	guint8 *start, *code;
	int i, stack_size, stack_offset, arg_offsets [5], regs_offset;
	MonoJumpInfo *ji = NULL;
	GSList *unwind_ops = NULL;
	guint kMaxCodeSize = NACL_SIZE (128, 256);

	start = code = mono_global_codeman_reserve (kMaxCodeSize);

	stack_size = 128;

	/* 
	 * On apple, the stack is misaligned by the pushing of the return address.
	 */
	if (!llvm && corlib)
		/* On OSX, we don't generate alignment code to save space */
		stack_size += 4;
	else
		stack_size += MONO_ARCH_FRAME_ALIGNMENT - 4;

	/*
	 * The stack looks like this:
	 * <pc offset> (only if corlib is TRUE)
	 * <exception object>/<type token>
	 * <return addr> <- esp (unaligned on apple)
	 */

	mono_add_unwind_op_def_cfa (unwind_ops, (guint8*)NULL, (guint8*)NULL, X86_ESP, 4);
	mono_add_unwind_op_offset (unwind_ops, (guint8*)NULL, (guint8*)NULL, X86_NREG, -4);

	/* Alloc frame */
	x86_alu_reg_imm (code, X86_SUB, X86_ESP, stack_size);
	mono_add_unwind_op_def_cfa_offset (unwind_ops, code, start, stack_size + 4);

	arg_offsets [0] = 0;
	arg_offsets [1] = 4;
	arg_offsets [2] = 8;
	arg_offsets [3] = 12;
	regs_offset = 16;

	/* Save registers */
	for (i = 0; i < X86_NREG; ++i)
		if (i != X86_ESP)
			x86_mov_membase_reg (code, X86_ESP, regs_offset + (i * 4), i, 4);
	/* Calculate the offset between the current sp and the sp of the caller */
	if (llvm) {
		/* LLVM doesn't push the arguments */
		stack_offset = stack_size + 4;
	} else {
		if (corlib) {
			/* Two arguments */
			stack_offset = stack_size + 4 + 8;
#ifdef __APPLE__
			/* We don't generate stack alignment code on osx to save space */
#endif
		} else {
			/* One argument + stack alignment */
			stack_offset = stack_size + 4 + 4;
#ifdef __APPLE__
			/* Pop the alignment added by OP_THROW too */
			stack_offset += MONO_ARCH_FRAME_ALIGNMENT - 4;
#else
			if (mono_do_x86_stack_align)
				stack_offset += MONO_ARCH_FRAME_ALIGNMENT - 4;
#endif
		}
	}
	/* Save ESP */
	x86_lea_membase (code, X86_EAX, X86_ESP, stack_offset);
	x86_mov_membase_reg (code, X86_ESP, regs_offset + (X86_ESP * 4), X86_EAX, 4);

	/* Set arg1 == regs */
	x86_lea_membase (code, X86_EAX, X86_ESP, regs_offset);
	x86_mov_membase_reg (code, X86_ESP, arg_offsets [0], X86_EAX, 4);
	/* Set arg2 == exc/ex_token_index */
	if (resume_unwind)
		x86_mov_reg_imm (code, X86_EAX, 0);
	else
		x86_mov_reg_membase (code, X86_EAX, X86_ESP, stack_size + 4, 4);
	x86_mov_membase_reg (code, X86_ESP, arg_offsets [1], X86_EAX, 4);
	/* Set arg3 == eip */
	if (llvm_abs)
		x86_alu_reg_reg (code, X86_XOR, X86_EAX, X86_EAX);
	else
		x86_mov_reg_membase (code, X86_EAX, X86_ESP, stack_size, 4);
	x86_mov_membase_reg (code, X86_ESP, arg_offsets [2], X86_EAX, 4);
	/* Set arg4 == rethrow/pc_offset */
	if (resume_unwind) {
		x86_mov_membase_imm (code, X86_ESP, arg_offsets [3], 0, 4);
	} else if (corlib) {
		x86_mov_reg_membase (code, X86_EAX, X86_ESP, stack_size + 8, 4);
		if (llvm_abs) {
			/* 
			 * The caller is LLVM code which passes the absolute address not a pc offset,
			 * so compensate by passing 0 as 'ip' and passing the negated abs address as
			 * the pc offset.
			 */
			x86_neg_reg (code, X86_EAX);
		}
		x86_mov_membase_reg (code, X86_ESP, arg_offsets [3], X86_EAX, 4);
	} else {
		x86_mov_membase_imm (code, X86_ESP, arg_offsets [3], rethrow, 4);
	}
	/* Make the call */
	if (aot) {
		// This can be called from runtime code, which can't guarantee that
		// ebx contains the got address.
		// So emit the got address loading code too
		code = mono_arch_emit_load_got_addr (start, code, NULL, &ji);
		code = mono_arch_emit_load_aotconst (start, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, corlib ? "mono_x86_throw_corlib_exception" : "mono_x86_throw_exception");
		x86_call_reg (code, X86_EAX);
	} else {
		x86_call_code (code, resume_unwind ? (gpointer)(mono_x86_resume_unwind) : (corlib ? (gpointer)mono_x86_throw_corlib_exception : (gpointer)mono_x86_throw_exception));
	}
	x86_breakpoint (code);

	nacl_global_codeman_validate(&start, kMaxCodeSize, &code);

	g_assert ((code - start) < kMaxCodeSize);

	if (info)
		*info = mono_tramp_info_create (name, start, code - start, ji, unwind_ops);
	else {
		GSList *l;

		for (l = unwind_ops; l; l = l->next)
			g_free (l->data);
		g_slist_free (unwind_ops);
	}

	return start;
}
Exemplo n.º 24
0
void g_str_slist_free(GSList * list)
{
    g_slist_foreach(list, (GFunc) g_free, NULL);
    g_slist_free(list);
}
Exemplo n.º 25
0
gchar *
gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc, 
				  GdaServerOperation *op, GError **error)
{
	GString *string;
	const GValue *value;
	gboolean hasfields = FALSE;
	gint nrows;
	gint i;
	gboolean first;
	GSList *pkfields = NULL; /* list of GValue* composing the pkey */
	gint nbpkfields = 0;
	gchar *sql = NULL;
	gchar *tmp;

	string = g_string_new ("CREATE ");
	value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_TEMP");
	if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
		g_string_append (string, "TEMP ");
	g_string_append (string, "TABLE ");

	tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
							  "/TABLE_DEF_P/TABLE_NAME", error);
	if (!tmp) {
		g_string_free (string, TRUE);
		return NULL;
	}

	g_string_append (string, tmp);
	g_free (tmp);
	g_string_append (string, " (");
		
	/* FIELDS */
	GdaServerOperationNode *node;

	node = gda_server_operation_get_node_info (op, "/FIELDS_A");
	g_assert (node);

	/* finding if there is a composed primary key */
	nrows = gda_data_model_get_n_rows (node->model);
	for (i = 0; i < nrows; i++) {
		value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_PKEY/%d", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
			tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
									  "/FIELDS_A/@COLUMN_NAME/%d", error, i);
			if (!tmp) {
				g_string_free (string, TRUE);
				return NULL;
			}

			pkfields = g_slist_append (pkfields, tmp);
			nbpkfields ++;
		}
	}

	/* manually defined fields */
	first = TRUE;
	for (i = 0; i < nrows; i++) {
		hasfields = TRUE;
		if (first) 
			first = FALSE;
		else
			g_string_append (string, ", ");

		tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
								  "/FIELDS_A/@COLUMN_NAME/%d", error, i);
		if (!tmp) {
			g_string_free (string, TRUE);
			return NULL;
		}

		g_string_append (string, tmp);
		g_free (tmp);
		g_string_append_c (string, ' ');

		value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_AUTOINC/%d", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
			g_string_append (string, "serial");
		else {
			value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_TYPE/%d", i);
			g_string_append (string, g_value_get_string (value));
		}

		value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_SIZE/%d", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_UINT)) {
			g_string_append_printf (string, "(%d", g_value_get_uint (value));

			value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_SCALE/%d", i);
			if (value && G_VALUE_HOLDS (value, G_TYPE_UINT))
				g_string_append_printf (string, ",%d)", g_value_get_uint (value));
			else
				g_string_append (string, ")");
		}

		value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_DEFAULT/%d", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
			const gchar *str = g_value_get_string (value);
			if (str && *str) {
				g_string_append (string, " DEFAULT ");
				g_string_append (string, str);
			}
		}

		value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NNUL/%d", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
			g_string_append (string, " NOT NULL");

		value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_UNIQUE/%d", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
			g_string_append (string, " UNIQUE");

		if (nbpkfields == 1) {
			value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_PKEY/%d", i);
			if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
				g_string_append (string, " PRIMARY KEY");
		}

		value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_CHECK/%d", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
			const gchar *str = g_value_get_string (value);
			if (str && *str) {
				g_string_append (string, " CHECK (");
				g_string_append (string, str);
				g_string_append_c (string, ')');
			}
		}
	}

	/* LIKE inheritance */
	nrows = gda_server_operation_get_sequence_size (op, "/TABLE_PARENTS_S");
	for (i = 0; i < nrows; i++) {
		value = gda_server_operation_get_value_at (op, "/TABLE_PARENTS_S/%d/TABLE_PARENT_COPY", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && !g_value_get_boolean (value)) {
			tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
									  "/TABLE_PARENTS_S/%d/TABLE_PARENT_TABLE",
									  error, i);
			if (!tmp) {
				g_string_free (string, TRUE);
				return NULL;
			}

			hasfields = TRUE;
			if (first) 
				first = FALSE;
			else
				g_string_append (string, ", ");

			g_string_append (string, "LIKE ");
			g_string_append (string, tmp);
			value = gda_server_operation_get_value_at (op, 
								   "/TABLE_PARENTS_S/%d/TABLE_PARENT_COPY_DEFAULTS", i);
			if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && 
			    g_value_get_boolean (value))
				g_string_append (string, " INCLUDING DEFAULTS");
			g_free (tmp);
		}
	}

	/* composed primary key */
	if (nbpkfields > 1) {
		GSList *list;

		g_string_append (string, ", PRIMARY KEY (");
		for (list = pkfields; list; list = list->next) {
			if (list != pkfields)
				g_string_append (string, ", ");
			g_string_append (string, (gchar*) list->data);
		}
		g_string_append_c (string, ')');
	}
	g_slist_foreach (pkfields, (GFunc) g_free, NULL);
	g_slist_free (pkfields);

	/* foreign keys */
	first = TRUE;
	node = gda_server_operation_get_node_info (op, "/FKEY_S");
	if (node) {
		nrows = gda_server_operation_get_sequence_size (op, "/FKEY_S");
		for (i = 0; i < nrows; i++) {
			gint nbfields = 0;
			gint j;

			g_string_append (string, ", FOREIGN KEY (");
			node = gda_server_operation_get_node_info (op, "/FKEY_S/%d/FKEY_FIELDS_A", i);
			if (!node || ((nbfields = gda_data_model_get_n_rows (node->model)) == 0)) {
				g_string_free (string, TRUE);
				g_set_error (error, GDA_SERVER_OPERATION_ERROR,
					     GDA_SERVER_OPERATION_INCORRECT_VALUE_ERROR,
					     "%s",
					     _("No field specified in foreign key constraint"));
				return NULL;
			}
			else {
				for (j = 0; j < nbfields; j++) {
					if (j != 0)
						g_string_append (string, ", ");
					tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
											  "/FKEY_S/%d/FKEY_FIELDS_A/@FK_FIELD/%d",
											  error, i, j);
					if (tmp) {
						g_string_append (string, tmp);
						g_free (tmp);
					}
					else {
						g_string_free (string, TRUE);
						return NULL;
					}
				}
			}
			g_string_append (string, ") REFERENCES ");

			tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
									  "/FKEY_S/%d/FKEY_REF_TABLE", error, i);
			if (tmp) {
				g_string_append (string, tmp);
				g_free (tmp);
			}
			else {
				g_string_free (string, TRUE);
				return NULL;
			}

			g_string_append (string, " (");
			for (j = 0; j < nbfields; j++) {
				if (j != 0)
					g_string_append (string, ", ");
				tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
										  "/FKEY_S/%d/FKEY_FIELDS_A/@FK_REF_PK_FIELD/%d",
										  error, i, j);
				if (tmp) {
					g_string_append (string, tmp);
					g_free (tmp);
				}
				else {
					g_string_free (string, TRUE);
					return NULL;
				}
			}
			g_string_append_c (string, ')');
			value = gda_server_operation_get_value_at (op, "/FKEY_S/%d/FKEY_MATCH_TYPE", i);
			if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
				g_string_append_printf (string, " %s", g_value_get_string (value));
			value = gda_server_operation_get_value_at (op, "/FKEY_S/%d/FKEY_ONUPDATE", i);
			if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
				g_string_append_printf (string, " ON UPDATE %s", g_value_get_string (value));
			value = gda_server_operation_get_value_at (op, "/FKEY_S/%d/FKEY_ONDELETE", i);
			if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
				g_string_append_printf (string, " ON DELETE %s", g_value_get_string (value));
			value = gda_server_operation_get_value_at (op, "/FKEY_S/%d/FKEY_DEFERRABLE", i);
			if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
				g_string_append_printf (string, " %s", g_value_get_string (value));
		}
	}

	g_string_append (string, ")");

	/* INHERITS */
	first = TRUE;
	nrows = gda_server_operation_get_sequence_size (op, "/TABLE_PARENTS_S");
	for (i = 0; i < nrows; i++) {
		value = gda_server_operation_get_value_at (op, "/TABLE_PARENTS_S/%d/TABLE_PARENT_COPY", i);
		if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
			tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
									  "/TABLE_PARENTS_S/%d/TABLE_PARENT_TABLE",
									  error, i);
			if (tmp) {
				hasfields = TRUE;
				if (first) {
					g_string_append (string, " INHERITS ");
					first = FALSE;
				}
				else
					g_string_append (string, ", ");
				g_string_append (string, tmp);
				g_free (tmp);
			}
			else {
				g_string_free (string, TRUE);
				return NULL;
			}
		}
	}

	if (!hasfields) {
		g_string_free (string, TRUE);
		g_set_error (error, GDA_SERVER_OPERATION_ERROR,
                             GDA_SERVER_OPERATION_INCORRECT_VALUE_ERROR,
			     "%s", _("Table to create must have at least one row"));
		return NULL;
	}

	value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_WITH_OIDS");
	if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
		g_string_append (string, " WITH OIDS");

	sql = string->str;
	g_string_free (string, FALSE);

	return sql;
}
Exemplo n.º 26
0
void
p_slist_free_full(GSList *items, GDestroyNotify free_func)
{
    g_slist_foreach (items, (GFunc) free_func, NULL);
    g_slist_free (items);
}
Exemplo n.º 27
0
/*
 * Decodes map data from a <data> node
 */
static void decode_layer_data(xmlNode *data_node, ALLEGRO_MAP_LAYER *layer)
{
    char *str = g_strstrip((char *)data_node->children->content);
    int datalen = layer->width * layer->height;
    layer->data = (char *)calloc(datalen, sizeof(char));

    char *encoding = get_xml_attribute(data_node, "encoding");
    if (!encoding) {
        int i = 0;
        GSList *tiles = get_children_for_name(data_node, "tile");
        GSList *tile_item = tiles;
        while (tile_item) {
            xmlNode *tile_node = (xmlNode*)tile_item->data;
            tile_item = g_slist_next(tile_item);
            char *gid = get_xml_attribute(tile_node, "gid");
            layer->data[i] = atoi(gid);
            i++;
        }

        g_slist_free(tiles);
    }
    else if (!strcmp(encoding, "base64")) {
        // decompress
        gsize rawlen;
        unsigned char *rawdata = g_base64_decode(str, &rawlen);

        // check the compression
        char *compression = get_xml_attribute(data_node, "compression");
        if (compression != NULL) {
            if (strcmp(compression, "zlib") && strcmp(compression, "gzip")) {
                fprintf(stderr, "Error: unknown compression format '%s'\n", compression);
                return;
            }

            // set up files used by zlib to decompress the data
            ALLEGRO_PATH *srcpath;
            ALLEGRO_FILE *datasrc = al_make_temp_file("XXXXXX", &srcpath);
            al_fwrite(datasrc, rawdata, rawlen);
            al_fseek(datasrc, 0, ALLEGRO_SEEK_SET);
            //al_fclose(datasrc);
            //datasrc = al_fopen(al_path_cstr(srcpath, ALLEGRO_NATIVE_PATH_SEP), "rb");
            ALLEGRO_FILE *datadest = al_make_temp_file("XXXXXX", NULL);

            // decompress and print an error if it failed
            int status = inf(datasrc, datadest);
            if (status)
                zerr(status);

            // flush data and get the file length
            al_fflush(datadest);
            int len = al_fsize(datadest);

            // read in the file
            al_fseek(datadest, 0, ALLEGRO_SEEK_SET);
            char *data = (char *)calloc(len, sizeof(char));
            if (al_fread(datadest, data, len) != len) {
                fprintf(stderr, "Error: failed to read in map data\n");
                return;
            }

            // every tile id takes 4 bytes
            int i;
            for (i = 0; i<len; i += 4) {
                int tileid = 0;
                tileid |= data[i];
                tileid |= data[i+1] << 8;
                tileid |= data[i+2] << 16;
                tileid |= data[i+3] << 24;

                layer->data[i/4] = tileid;
            }
            /*  printf("layer dimensions: %dx%d, data length = %d\n",
                        layer->width, layer->height, len); */

            al_destroy_path(srcpath);
            al_fclose(datasrc);
            al_fclose(datadest);
            al_free(data);
        }
        else {
            // TODO: verify that this still works
            int i;
            for (i = 0; i<rawlen; i += 4) {
                int tileid = 0;
                tileid |= rawdata[i];
                tileid |= rawdata[i+1] << 8;
                tileid |= rawdata[i+2] << 16;
                tileid |= rawdata[i+3] << 24;

                layer->data[i/4] = tileid;
            }
        }

        g_free(rawdata);
    }
    else if (!strcmp(encoding, "csv")) {
        int i;
        for (i = 0; i<datalen; i++) {
            char *id = strtok((i == 0 ? str : NULL), ",");
            layer->data[i] = atoi(id);
        }
    }
    else {
        fprintf(stderr, "Error: unknown encoding format '%s'\n", encoding);
    }
}
Exemplo n.º 28
0
void
mu_script_info_list_destroy (GSList *lst)
{
	g_slist_foreach (lst, (GFunc)script_info_destroy, NULL);
	g_slist_free    (lst);
}
Exemplo n.º 29
0
static void
status_menu_clear_status_message_dialog_run (StatusMenu *self)
{
    GtkTreeIter iter, liter;

    GSList *conf_list [3] = { NULL, NULL, NULL };
    GtkWidget *dialog = NULL;
    GtkWidget *vbox = NULL;
    GtkWidget *frame = NULL;
    GtkWidget *tree_view = NULL;

    GdkPixbuf *pixbuf = NULL;
    GtkTreeSelection *selection = NULL;
    GtkListStore *list_store = NULL;
    GtkCellRenderer *renderer = NULL;
    GtkTreeViewColumn *column = NULL;
    GtkWidget *label = NULL;

    bool found = false;
    bool close = false;
    int response = 0;
    int i = 0;
    gchar *message = NULL;
    gchar *presence = NULL;
    gchar *status = NULL;

    // Current status
    presence = gm_conf_get_string (PERSONAL_DATA_KEY "short_status");
    status = gm_conf_get_string (PERSONAL_DATA_KEY "long_status");

    // Build the dialog
    dialog = gtk_dialog_new_with_buttons (_("Custom Message"),
                                          self->priv->parent,
                                          (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
                                          GTK_STOCK_DELETE,
                                          GTK_RESPONSE_APPLY,
                                          GTK_STOCK_CLOSE,
                                          GTK_RESPONSE_CLOSE,
                                          NULL);
    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
    gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_DELETE);

    vbox = gtk_vbox_new (false, 0);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, false, false, 2);


    label = gtk_label_new (_("Delete custom messages:"));
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (vbox), label, false, false, 2);

    list_store = gtk_list_store_new (3,
                                     GDK_TYPE_PIXBUF,
                                     G_TYPE_STRING,
                                     G_TYPE_INT);
    tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
    g_object_unref (list_store);
    gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), false);

    column = gtk_tree_view_column_new ();
    renderer = gtk_cell_renderer_pixbuf_new ();
    gtk_tree_view_column_pack_start (column, renderer, FALSE);
    gtk_tree_view_column_set_attributes (column, renderer,
                                         "pixbuf", 0,
                                         NULL);

    renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_column_pack_start (column, renderer, FALSE);
    gtk_tree_view_column_set_attributes (column, renderer,
                                         "text", 1,
                                         NULL);
    gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

    frame = gtk_frame_new (NULL);
    gtk_container_add (GTK_CONTAINER (frame), tree_view);
    gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 2);

    if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->list_store), &iter)) {

        do {

            gtk_tree_model_get (GTK_TREE_MODEL (self->priv->list_store), &iter,
                                COL_MESSAGE_TYPE, &i, -1);

            if (i == TYPE_CUSTOM_ONLINE || i == TYPE_CUSTOM_AWAY || i == TYPE_CUSTOM_DND) {

                gtk_tree_model_get (GTK_TREE_MODEL (self->priv->list_store), &iter,
                                    COL_ICON, &pixbuf,
                                    COL_MESSAGE, &message,
                                    -1);
                gtk_list_store_append (GTK_LIST_STORE (list_store), &liter);
                gtk_list_store_set (GTK_LIST_STORE (list_store), &liter,
                                    COL_ICON, pixbuf,
                                    COL_MESSAGE, message,
                                    COL_MESSAGE_TYPE, i,
                                    -1);
                g_free (message);
                g_object_unref (pixbuf);
            }

        } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->list_store), &iter));
    }

    // Select the first iter
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
    if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
        gtk_tree_selection_select_iter (selection, &iter);

    gtk_widget_show_all (dialog);
    while (!close) {
        response = gtk_dialog_run (GTK_DIALOG (dialog));

        switch (response)
        {
        case GTK_RESPONSE_APPLY:
            if (gtk_tree_selection_get_selected (selection, NULL, &iter))
                gtk_list_store_remove (GTK_LIST_STORE (list_store), &iter);
            if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
                gtk_tree_selection_select_iter (selection, &iter);
            else
                close = true;
            break;

        case GTK_RESPONSE_CLOSE:
        default:
            close = true;
        }
    }

    if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter)) {

        do {

            gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
                                1, &message,
                                2, &i, -1);
            if (status && message && !strcmp (status, message))
                found = true;

            conf_list[i - NUM_STATUS_TYPES - 1] = g_slist_append (conf_list[i - NUM_STATUS_TYPES - 1], g_strdup (message));
            g_free (message);
        } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter));
    }

    for (int j = 0 ; j < 3 ; j++) {
        gm_conf_set_string_list (status_types_keys[j], conf_list[j]);
        g_slist_foreach (conf_list[j], (GFunc) g_free, NULL);
        g_slist_free (conf_list[j]);
    }

    if (!found) {
        // Reset current config
        self->priv->personal_details->set_presence_info ("online", "");
    }

    gtk_widget_destroy (dialog);
}
Exemplo n.º 30
0
/*
 * Analyze a JPEG file according to the command-line options.
 */
static gboolean
analyze_file (gchar *filename)
{
  struct jpeg_decompress_struct  cinfo;
  struct my_error_mgr            jerr;
  FILE                          *f;
  gint                           i;
  gint                           num_quant_tables;
  GSList                        *source_list;

  if ((f = fopen (filename, "rb")) == NULL)
    {
      g_printerr ("Cannot open '%s'\n", filename);
      return FALSE;
    }

  if (option_summary)
    g_print ("%s:\n", filename);

  cinfo.err = jpeg_std_error (&jerr.pub);
  jerr.pub.error_exit = my_error_exit;
  if (setjmp (jerr.setjmp_buffer))
    {
      /* if we get here, the JPEG code has signaled an error. */
      jpeg_destroy_decompress (&cinfo);
      fclose (f);
      return FALSE;
    }
  jpeg_create_decompress (&cinfo);

  jpeg_stdio_src (&cinfo, f);

  jpeg_read_header (&cinfo, TRUE);

  num_quant_tables = 0;
  for (i = 0; i < 4; i++)
    if (cinfo.quant_tbl_ptrs[i])
      num_quant_tables++;

  source_list = detect_source (&cinfo, num_quant_tables);
  if (! source_list)
    {
      add_unknown_table (&cinfo, filename);
    }

  if (! option_unknown)
    {
      if (option_summary)
        print_summary (&cinfo, num_quant_tables);

      if (option_ctable)
        {
          g_print ("  {\n    /* %s */\n    \"?\", \"?\",\n    %hd, %hd,\n    %d,\n",
                   filename,
                   cinfo.comp_info[0].h_samp_factor,
                   cinfo.comp_info[0].v_samp_factor,
                   num_quant_tables);
          for (i = 0; i < 4; i++)
            if (cinfo.quant_tbl_ptrs[i])
              print_ctable (i, cinfo.quant_tbl_ptrs[i]->quantval,
                            (i < 3) && cinfo.quant_tbl_ptrs[i + 1]);
          g_print ("  },\n");
        }

      if (option_table_2cols)
        {
          print_table_2cols (0, cinfo.quant_tbl_ptrs[0]->quantval,
                             1, cinfo.quant_tbl_ptrs[1]->quantval);
          if (cinfo.quant_tbl_ptrs[2] || cinfo.quant_tbl_ptrs[3])
            print_table_2cols (2, cinfo.quant_tbl_ptrs[2]->quantval,
                               3, cinfo.quant_tbl_ptrs[3]->quantval);
        }
    }

  if (source_list)
    g_slist_free (source_list);

  jpeg_destroy_decompress (&cinfo);
  fclose (f);

  return TRUE;
}