/* Find the current conversation or make a new one if required */
static ts2_conversation* ts2_get_conversation(packet_info *pinfo)
{
    conversation_t *conversation;
    ts2_conversation *conversation_data;
    conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
    if(conversation)
    {

        conversation_data = (ts2_conversation*)conversation_get_proto_data(conversation, proto_ts2);
    }
    else
    {
        conversation_data = g_mem_chunk_alloc(conv_vals);
        conversation_data->last_inorder_server_frame=0; /* sequence number should never be zero so we can use this as an initial number */
        conversation_data->last_inorder_client_frame=0;
        conversation_data->server_port=pinfo->srcport;
        conversation_data->server_frag_size=0;
        conversation_data->server_frag_num=0;
        conversation_data->client_frag_size=0;
        conversation_data->client_frag_num=0;
        conversation = conversation_new(pinfo->fd->num,  &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
        conversation_add_proto_data(conversation, proto_ts2, (void *)conversation_data);
    }
    return conversation_data;
}
Beispiel #2
0
int	main(int argc, char *argv[])
{
	GMemChunk *chunk;	//定义内存块
	gchar *mem[10];	//定义指向原子的指针数组
	gint i, j;
	//创建内存块
	chunk = g_mem_chunk_new("Test MemChunk", 5, 50, G_ALLOC_AND_FREE);
				//名称,原子的长度, 内存块的长度,类型
	for(i=0; i<10; i++)
	{
		//创建对象
		//mem[i] = g_chunk_new(gchar, chunk);
		mem[i] = (gchar*)g_mem_chunk_alloc(chunk);
		for(j=0; j<5; j++)
		{
			mem[i][j] = 'A' + j;//为内存块中的指针赋值
		}
	}
	
	g_mem_chunk_print(chunk);	//显示内存块信息
	for(i=0; i<10; i++)
	{
		g_print("%s\t",mem[i]);//显示内存块中的内容
	}
	
	for(i=0; i<10; i++)
	{
		g_mem_chunk_free(chunk,mem[i]); //释放所有分配的内存
	}
	g_mem_chunk_destroy(chunk);
}
Beispiel #3
0
static LINE_REC *create_line(GUI_WINDOW_REC *gui, int level)
{
	LINE_REC *rec;

	g_return_val_if_fail(gui != NULL, NULL);
	g_return_val_if_fail(gui->cur_text != NULL, NULL);

	rec = g_mem_chunk_alloc(gui->line_chunk);
	rec->text = gui->cur_text->buffer+gui->cur_text->pos;
	rec->level = GPOINTER_TO_INT(level);
	rec->time = time(NULL);

	mark_temp_eol(gui->cur_text);
	gui->cur_text->lines++;

	gui->last_color = -1;
	gui->last_flags = 0;

	if (gui->temp_line != NULL) {
		int pos = g_list_index(gui->lines, gui->temp_line);
		gui->lines = g_list_insert(gui->lines, rec, pos+1);
		gui->temp_line = rec;
	} else {
		gui->cur_line = rec;
		gui->lines = g_list_append(gui->lines, rec);
		if (gui->startline == NULL) {
			/* first line */
			gui->startline = gui->lines;
			gui->bottom_startline = gui->lines;
		}
	}
	return rec;
}
Beispiel #4
0
static TEXT_CHUNK_REC *text_chunk_create(TEXT_BUFFER_REC *buffer)
{
	TEXT_CHUNK_REC *rec;
	unsigned char *buf, *ptr, **pptr;

	rec = g_mem_chunk_alloc(text_chunk);
	rec->pos = 0;
	rec->refcount = 0;

	if (buffer->cur_line != NULL && buffer->cur_line->text != NULL) {
		/* create a link to new block from the old block */
		buf = buffer->cur_text->buffer + buffer->cur_text->pos;
		*buf++ = 0; *buf++ = (char) LINE_CMD_CONTINUE;

		/* we want to store pointer to beginning of the new text
		   block to char* buffer. this probably isn't ANSI-C
		   compatible, and trying this without the pptr variable
		   breaks at least NetBSD/Alpha, so don't go "optimize"
		   it :) */
		ptr = rec->buffer; pptr = &ptr;
		memcpy(buf, pptr, sizeof(unsigned char *));
	} else {
		/* just to be safe */
		mark_temp_eol(rec);
	}

	buffer->cur_text = rec;
	buffer->text_chunks = g_slist_append(buffer->text_chunks, rec);
	return rec;
}
Beispiel #5
0
/* new pdu in this stream */
static stream_pdu_t *stream_new_pdu(stream_t *stream)
{
    stream_pdu_t *pdu;
    pdu = g_mem_chunk_alloc(pdus);
    pdu -> fd_head = NULL;
    pdu -> pdu_number = stream -> pdu_counter++;
    pdu -> id = pdu_counter++;
    return pdu;
}
Beispiel #6
0
/* insert function */
static stream_pdu_fragment_t *fragment_hash_insert( const stream_t *stream, guint32 framenum, guint32 offset,
						    guint32 length)
{
    fragment_key_t *key;
    stream_pdu_fragment_t *val;

    key = g_mem_chunk_alloc(fragment_keys);
    key->stream = stream;
    key->framenum = framenum;
    key->offset = offset;

    val = g_mem_chunk_alloc(fragment_vals);
    val->len = length;
    val->pdu = NULL;
    val->final_fragment = FALSE;

    g_hash_table_insert(fragment_hash, key, val);
    return val;
}
Beispiel #7
0
static stream_t *stream_hash_insert_conv( const struct conversation *conv, int p2p_dir )
{
    stream_key_t *key;

    key = g_mem_chunk_alloc(stream_keys);
    key->is_circuit = FALSE;
    key->circ.conv = conv;
    key->p2p_dir = p2p_dir;

    return new_stream(key);
}
Beispiel #8
0
/* insert function */
static stream_t *stream_hash_insert_circ( const struct circuit *circuit, int p2p_dir )
{
    stream_key_t *key;

    key = g_mem_chunk_alloc(stream_keys);
    key->is_circuit = TRUE;
    key->circ.circuit = circuit;
    key->p2p_dir = p2p_dir;

    return new_stream(key);
}
Beispiel #9
0
static gpointer
gsk_ftp_message_alloc ()
{
  gpointer rv;
  G_LOCK (ftp_message_chunk)
  if (ftp_msg_chunk == NULL)
    ftp_msg_chunk = g_mem_chunk_create (_GskFtpMessage, 16, G_ALLOC_AND_FREE);
  rv = g_mem_chunk_alloc (ftp_msg_chunk);
  G_UNLOCK (ftp_message_chunk);
  return rv;
}
Beispiel #10
0
static stream_t *new_stream( stream_key_t *key )
{
    stream_t *val;
    
    val = g_mem_chunk_alloc(streams);
    val -> key = key;
    val -> pdu_counter = 0;
    val -> current_pdu = NULL;
    val -> lastfrag_framenum = 0;
    val -> lastfrag_offset = 0;
    g_hash_table_insert(stream_hash, key, val);

    return val;
}
Beispiel #11
0
static LINE_REC *textbuffer_line_create(TEXT_BUFFER_REC *buffer)
{
	LINE_REC *rec;

	if (buffer->cur_text == NULL)
                text_chunk_create(buffer);

	rec = g_mem_chunk_alloc(line_chunk);
        rec->refcount = 1;
	rec->text = buffer->cur_text->buffer + buffer->cur_text->pos;

	buffer->cur_text->refcount++;
        return rec;
}
Beispiel #12
0
static LINE_REC *create_line(GUI_WINDOW_REC *gui, int level)
{
	g_return_val_if_fail(gui != NULL, NULL);
	g_return_val_if_fail(gui->cur_text != NULL, NULL);

	gui->cur_line = g_mem_chunk_alloc(gui->line_chunk);
	gui->cur_line->text = gui->cur_text->buffer+gui->cur_text->pos;
	gui->cur_line->level = GPOINTER_TO_INT(level);
	gui->cur_line->time = time(NULL);

	mark_temp_eol(gui->cur_text);

	gui->last_color = -1;
	gui->last_flags = 0;

	gui->lines = g_list_append(gui->lines, gui->cur_line);
	if (gui->startline == NULL) {
                /* first line */
		gui->startline = gui->lines;
		gui->bottom_startline = gui->lines;
	}
	return gui->cur_line;
}