示例#1
0
// Similar to the session function, this will keep looping until it has read a line form a socket descriptor. It takes 
// the socket explicitly. This function is used by the message sending code.
int network_readline(int socket_descriptor, char *buffer, sizer_t buffer_length, sizer_t *line_length, sizer_t *buffered_bytes) {

	char *place;
	int readin;
	int characters = 0;
	
	#ifdef DEBUG_FRAMEWORK
	if (socket_descriptor < 0 || buffer == NULL || buffer_length == 0 || line_length == NULL || buffered_bytes == NULL) {
		lavalog("Invalid data passed in.");
		return -1;
	}
	#endif
	
	// Check to see if there are characters already in the buffer, and move them.
	if (*line_length < *buffered_bytes) {
		move_bytes(buffer, buffer + *line_length, *buffered_bytes - *line_length);
		*buffered_bytes -= *line_length;
		characters = complete_line(buffer, *buffered_bytes);
	}
	else {
		*buffered_bytes = 0;
	}
		
	// Reset the current line counter, and advance the place holder to where we are supposed to write.
	*line_length = 0;
	place = buffer + *buffered_bytes;
	
	while (continue_processing(0) && !characters && buffer_length > *buffered_bytes) {
	
		readin = read(socket_descriptor, place, buffer_length - *buffered_bytes);
			
		if (readin < 0) {
			#ifdef DEBUG_FRAMEWORK
			lavalog("Received an error while reading from the socket. {errno = %i}", errno);
			#endif
			return -1;
		}
		else {
			*buffered_bytes += readin;
			place += readin;
		}
		
		// Check whether we have a complete line to return yet.
		characters = complete_line(buffer, *buffered_bytes);
	}
	
	// Tell the session how many characters are on the current line.
	if (buffer_length <= *buffered_bytes) {
		return -1;
	}
	else {
		*line_length = characters;
	}

	return characters;
}
示例#2
0
/* Move the cursor (action signal) */
static gboolean tilem_disasm_view_move_cursor(GtkTreeView *tv,
                                              GtkMovementStep step,
                                              gint count)
{
	TilemDisasmView *dv;

	g_return_val_if_fail(TILEM_IS_DISASM_VIEW(tv), FALSE);
	dv = TILEM_DISASM_VIEW(tv);

	if (!dv->dbg->emu->calc)
		return FALSE;

	switch (step) {
	case GTK_MOVEMENT_DISPLAY_LINES:
		if (count < 0) {
			if (move_up_lines(dv, -count))
				return TRUE;
		}
		else {
			if (move_down_lines(dv, count))
				return TRUE;
		}
		break;

	case GTK_MOVEMENT_PARAGRAPHS:
	case GTK_MOVEMENT_PARAGRAPH_ENDS:
	case GTK_MOVEMENT_PAGES:
		if (count < 0)
			move_up_pages(dv, -count);
		else
			move_down_pages(dv, count);
		return TRUE;

	case GTK_MOVEMENT_BUFFER_ENDS:
		move_bytes(dv, count * 0x4000);
		return TRUE;

	case GTK_MOVEMENT_LOGICAL_POSITIONS:
	case GTK_MOVEMENT_VISUAL_POSITIONS:
	case GTK_MOVEMENT_WORDS:
	case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
	case GTK_MOVEMENT_HORIZONTAL_PAGES:
	default:
		break;
	}

	return (*GTK_TREE_VIEW_CLASS(parent_class)->move_cursor)(tv, step, count);
}
示例#3
0
// This function takes a buffer and reads from the network. It will detect
// SSL sessions, and read from an SSL struct if one is found.
int session_read(session_common_t *session) {
	
	int readin;
	
	#ifdef DEBUG_FRAMEWORK
	if (session == NULL) {
		lavalog("Passed an invalid pointer. This should never happen.");
		return -1;
	}
	#endif
	
	// Check to see if there are characters already in the buffer, and move them.
	if (session->current_line < session->buffered_bytes) {
		move_bytes(session->in_buffer, session->in_buffer + session->current_line, session->buffered_bytes - session->current_line);
		session->buffered_bytes -= session->current_line;
	}
	else {
		session->buffered_bytes = 0;
	}
	
	// Perform the read.
	if (session->ssl) {
		readin = ssl_read(session->ssl, session->in_buffer + session->buffered_bytes, config.in_buffer - session->buffered_bytes);
	}
	else {
		readin = read(session->sock_descriptor, session->in_buffer + session->buffered_bytes, config.in_buffer - session->buffered_bytes);
	}
	
	#ifdef DEBUG_FRAMEWORK
	if (readin < 0) {
		lavalog("Received an error while reading from the socket. {errorno = %i}", errno);
	}
	#endif
	
	// Let the customer know the actual amount of data in the buffer.
	if (readin >= 0 && session->buffered_bytes != 0) {
		readin += session->buffered_bytes;
	}
	
	// Reset the counters.
	if (session->current_line || session->buffered_bytes) {
		session->current_line = 0;
		session->buffered_bytes = 0;
	}
	
	return readin;
}
示例#4
0
/* Scroll view by a fixed number of bytes. */
void tilem_disasm_view_scroll_bytes(TilemDisasmView *dv, int n)
{
	g_return_if_fail(TILEM_IS_DISASM_VIEW(dv));
	move_bytes(dv, n);
}
示例#5
0
// This function takes a buffer and reads from the network. It will detect
// SSL sessions, and read from an SSL struct if one is found.
int session_readline(session_common_t *session) {
	
	char *place;
	int readin;
	int characters = 0;
	int length = config.in_buffer;

	#ifdef DEBUG_FRAMEWORK
	if (session == NULL) {
		lavalog("Passed an invalid pointer. This should never happen.");
		return -1;
	}
	#endif
	
	// Check to see if there are characters already in the buffer, and move them.
	if (session->current_line < session->buffered_bytes) {
		move_bytes(session->in_buffer, session->in_buffer + session->current_line, session->buffered_bytes - session->current_line);
		session->buffered_bytes -= session->current_line;
		characters = complete_line(session->in_buffer, session->buffered_bytes);
	}
	else {
		session->buffered_bytes = 0;
	}
		
	// Reset the current line counter, and advance the place holder to where we are supposed to write.
	session->current_line = 0;
	place = session->in_buffer + session->buffered_bytes;
	
	while (continue_processing(0) == 1 && !characters && length > session->buffered_bytes) {
	
		if (session->ssl) {
			readin = ssl_read(session->ssl, place, length - session->buffered_bytes);
		}
		else {
			readin = read(session->sock_descriptor, place, length - session->buffered_bytes);
		}
			
		if (readin < 0) {
			#ifdef DEBUG_FRAMEWORK
			lavalog("Received an error while reading from the socket.");
			#endif
			return -1;
		}
		else {
			session->buffered_bytes += readin;
			place += readin;
		}
		
		// Check whether we have a complete line to return yet.
		characters = complete_line(session->in_buffer, session->buffered_bytes);
	}
	
	// Tell the session how many characters are on the current line.
	if (length <= session->buffered_bytes) {
		return -1;
	}
	else {
		session->current_line = characters;
	}
	
	return characters;
}