Moved the send_http_error_message() and indicate_http_error()
functions into the htmlerror.c file, and recoded them to use the new variable substitution system. [Steven Young]
This commit is contained in:
		
							parent
							
								
									badd237fe6
								
							
						
					
					
						commit
						a46bfdc2e0
					
				
							
								
								
									
										71
									
								
								src/utils.c
									
									
									
									
									
								
							
							
						
						
									
										71
									
								
								src/utils.c
									
									
									
									
									
								
							@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: utils.c,v 1.36 2002-12-04 17:06:14 rjkaes Exp $
 | 
					/* $Id: utils.c,v 1.37 2003-03-13 21:34:38 rjkaes Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Misc. routines which are used by the various functions to handle strings
 | 
					 * Misc. routines which are used by the various functions to handle strings
 | 
				
			||||||
 * and memory allocation and pretty much anything else we can think of. Also,
 | 
					 * and memory allocation and pretty much anything else we can think of. Also,
 | 
				
			||||||
@ -65,75 +65,6 @@ send_http_message(struct conn_s *connptr, int http_code,
 | 
				
			|||||||
	return safe_write(connptr->client_fd, message, message_len);
 | 
						return safe_write(connptr->client_fd, message, message_len);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Display an error to the client.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
int
 | 
					 | 
				
			||||||
send_http_error_message(struct conn_s *connptr)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	static char *message = \
 | 
					 | 
				
			||||||
		"<html><head><title>%s</title></head>\r\n" \
 | 
					 | 
				
			||||||
		"<body>\r\n" \
 | 
					 | 
				
			||||||
		"<font size=\"+2\">Cache Error!</font><br>\r\n" \
 | 
					 | 
				
			||||||
		"An error of type %d occurred: %s\r\n" \
 | 
					 | 
				
			||||||
		"<hr>\r\n" \
 | 
					 | 
				
			||||||
		"<font size=\"-1\"><em>Generated by %s (%s)</em></font>\r\n" \
 | 
					 | 
				
			||||||
		"</body></html>\r\n\r\n";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	char *message_buffer;
 | 
					 | 
				
			||||||
	char *tmpbuf;
 | 
					 | 
				
			||||||
	size_t size = (1024 * 8);	/* start with 8 KB */
 | 
					 | 
				
			||||||
	ssize_t n;
 | 
					 | 
				
			||||||
	int ret;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	message_buffer = safemalloc(size);
 | 
					 | 
				
			||||||
	if (!message_buffer)
 | 
					 | 
				
			||||||
		return -1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	 * Build a new line. Keep increasing the size until the line fits.
 | 
					 | 
				
			||||||
	 * See the write_message() function in sock.c for more information.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	while (1) {
 | 
					 | 
				
			||||||
		n = snprintf(message_buffer, size, message,
 | 
					 | 
				
			||||||
			     connptr->error_string, connptr->error_number,
 | 
					 | 
				
			||||||
			     connptr->error_string, PACKAGE, VERSION);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (n > -1 && n < size)
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (n > - 1)
 | 
					 | 
				
			||||||
			size = n + 1;
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
			size *= 2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if ((tmpbuf = saferealloc(message_buffer, size)) == NULL) {
 | 
					 | 
				
			||||||
			safefree(message_buffer);
 | 
					 | 
				
			||||||
			return -1;
 | 
					 | 
				
			||||||
		} else
 | 
					 | 
				
			||||||
			message_buffer = tmpbuf;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ret = send_http_message(connptr, connptr->error_number,
 | 
					 | 
				
			||||||
				connptr->error_string, message_buffer);
 | 
					 | 
				
			||||||
	safefree(message_buffer);
 | 
					 | 
				
			||||||
	return ret;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Add the error information to the conn structure.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
int
 | 
					 | 
				
			||||||
indicate_http_error(struct conn_s* connptr, int number, const char* string)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	connptr->error_string = safestrdup(string);
 | 
					 | 
				
			||||||
	if (!connptr->error_string)
 | 
					 | 
				
			||||||
		return -1;
 | 
					 | 
				
			||||||
	connptr->error_number = number;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Safely creates filename and returns the low-level file descriptor.
 | 
					 * Safely creates filename and returns the low-level file descriptor.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: utils.h,v 1.22 2002-12-04 17:06:14 rjkaes Exp $
 | 
					/* $Id: utils.h,v 1.23 2003-03-13 21:34:37 rjkaes Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * See 'utils.h' for a detailed description.
 | 
					 * See 'utils.h' for a detailed description.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@ -26,9 +26,6 @@ struct conn_s;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
extern int send_http_message(struct conn_s *connptr, int http_code,
 | 
					extern int send_http_message(struct conn_s *connptr, int http_code,
 | 
				
			||||||
			     const char *error_title, const char *message);
 | 
								     const char *error_title, const char *message);
 | 
				
			||||||
extern int send_http_error_message(struct conn_s *connptr);
 | 
					 | 
				
			||||||
extern int indicate_http_error(struct conn_s* connptr, int number,
 | 
					 | 
				
			||||||
			       const char *string);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern int pidfile_create(const char *path);
 | 
					extern int pidfile_create(const char *path);
 | 
				
			||||||
extern int create_file_safely(const char *filename, unsigned int truncate_file);
 | 
					extern int create_file_safely(const char *filename, unsigned int truncate_file);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user