Beispiel #1
0
/*
 * Cache the TCP data of an SKB.
 */
unsigned int tcp_cache_deoptim(pDeduplicator pd, __u8 *ippacket) {
	struct iphdr *iph = NULL;
	struct tcphdr *tcph = NULL;
	__u16 datasize = 0; /* Store the size of the TCP data. */
	__u8 *tcpdata = NULL; /* Starting location for the TCP data. */
	char message[LOGSZ];

	if (DEBUG_DEDUPLICATION == true) {
		sprintf(message, "[CACHE DEOPTIM]: Entering into TCP CACHING \n");
		logger(LOG_INFO, message);
	}

	if ((ippacket != NULL)) { // If the skb or state_decompress is NULL abort compression.
		iph = (struct iphdr *) ippacket; // Access ip header.

		if ((iph->protocol == IPPROTO_TCP)) { // If this is not a TCP segment abort compression.
			tcph = (struct tcphdr *) (((u_int32_t *) ippacket) + iph->ihl); // Access tcp header.
			datasize = (__u16)(ntohs(iph->tot_len) - iph->ihl * 4) - tcph->doff* 4;
			tcpdata = (__u8 *) tcph + tcph->doff * 4; // Find starting location of the TCP data.

			if (datasize > 0) {

				if (DEBUG_DEDUPLICATION == true) {
					sprintf(message, "[CACHE DEOPTIM]: IP Packet ID %u\n", ntohs(iph->id));
					logger(LOG_INFO, message);
				}
				// Cache the packet content
#ifdef BASIC
				cache(tcpdata, datasize);
#endif

#ifdef ROLLING
				update_caches(pd, tcpdata, datasize);
#endif


				if (DEBUG_DEDUPLICATION == true) {
					sprintf( message, "[CACHE DEOPTIM] Cached packet \n");
					logger(LOG_INFO, message);
				}
				return OK;
			}
		}
	}
	return ERROR;
}
static void
compute_size(GtkCellRenderer      *cell,
             GtkWidget            *widget,
             GdkRectangle         *cell_area,
             /* content rect relative to cell area */
             GdkRectangle         *content_rect_p,
             /* individual items relative to content_rect.x, content_rect.y */
             GdkRectangle         *photo_rect_p,
             GdkRectangle         *name_rect_p,
             GdkRectangle         *song_rect_p,
             GdkRectangle         *artist_rect_p,
             GdkRectangle         *note_rect_p)
{
    HippoPersonRenderer *renderer;
    PangoRectangle prect;
    GdkRectangle content_rect;
    GdkRectangle photo_rect;
    GdkRectangle name_rect;
    GdkRectangle song_rect;
    GdkRectangle artist_rect;
    GdkRectangle note_rect;
    int padded_width;
    int padded_height;
    int photo_margin;

    renderer = HIPPO_PERSON_RENDERER(cell);

    update_caches(renderer, widget);

    /* First get all the sizes, then compute positions */

    if (renderer->photo) {
        photo_rect.width = PHOTO_SIZE;
        photo_rect.height = PHOTO_SIZE;
        photo_margin = PHOTO_MARGIN_RIGHT;
    } else {
        photo_rect.width = 0;
        photo_rect.height = 0;
        photo_margin = 0;
    }
    
    note_rect.width = NOTE_SIZE;
    note_rect.height = NOTE_SIZE;

    pango_layout_get_pixel_extents(renderer->name_layout, NULL, &prect);
    name_rect.width = prect.width;
    name_rect.height = prect.height;
    
    pango_layout_get_pixel_extents(renderer->song_layout, NULL, &prect);
    song_rect.width = prect.width;
    song_rect.height = prect.height;    

    pango_layout_get_pixel_extents(renderer->artist_layout, NULL, &prect);
    artist_rect.width = prect.width;
    artist_rect.height = prect.height;    

    /* now positions */

    photo_rect.x = 0;
    photo_rect.y = 0;
    
    name_rect.x = photo_rect.x + photo_rect.width + photo_margin;
    name_rect.y = 0;
    
    note_rect.x = name_rect.x;
    note_rect.y = name_rect.y + name_rect.height + NAME_MARGIN_BOTTOM;
    
    song_rect.x = note_rect.x + note_rect.y + NOTE_MARGIN_RIGHT;
    song_rect.y = note_rect.y;
    
    artist_rect.x = song_rect.x;
    artist_rect.y = song_rect.y + song_rect.height + SONG_MARGIN_BOTTOM;

    /* Now compute content rect by union of all other rects, then 
     * translate to be relative to the cell
     */
    content_rect.x = 0;
    content_rect.y = 0;
    content_rect.width = 0;
    content_rect.height = 0;

    gdk_rectangle_union(&content_rect, &photo_rect, &content_rect);    
    gdk_rectangle_union(&content_rect, &name_rect, &content_rect);
    gdk_rectangle_union(&content_rect, &note_rect, &content_rect);
    gdk_rectangle_union(&content_rect, &song_rect, &content_rect);    
    gdk_rectangle_union(&content_rect, &artist_rect, &content_rect);

    if (photo_rect.height < content_rect.height) {
        /* center photo rect vertically */
        photo_rect.y = (content_rect.height - photo_rect.height) / 2;
    }

    padded_width  = (int) cell->xpad * 2 + content_rect.width;
    padded_height = (int) cell->ypad * 2 + content_rect.height;

    if (cell_area && content_rect.width > 0 && content_rect.height > 0) {
        content_rect.x = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
                            1.0 - cell->xalign : cell->xalign) * 
                            (cell_area->width - padded_width - cell->xpad * 2));
        content_rect.x = MAX (content_rect.x, 0) + cell->xpad;

        content_rect.y = (cell->yalign *
                           (cell_area->height - padded_height - 2 * cell->ypad));
        content_rect.y = MAX (content_rect.y, 0) + cell->ypad;
    }
    
    content_rect.width = padded_width;
    content_rect.height = padded_height;
    
#define OUT(what) do { if (what ## _p) { * what ## _p = what; }  } while(0)
    OUT(content_rect);
    OUT(photo_rect);
    OUT(name_rect);
    OUT(song_rect);
    OUT(artist_rect);
    OUT(note_rect);
}