static string format_log(string format, object request, object response)
static string format_log(string format, Request request, Response response)
static string format_log(string format, object request, object response){	int i, x;	string *fmt, entry, token, tmp;	fmt = explode(format, "%");	entry = "";	for(i = 0; i < sizeof(fmt); i++) {		token = fmt[i];		if(token == "%") {			entry += "%";			continue;		}		switch(token[0]) {		case 'h' :			/* Remote host */			entry += request->get_client_ip_name() + token[1..];			break;		case 'l' :			/* TODO: Not supported. Remote logname (from inetd) */			entry += "-" + token[1..];			break;		case 'u' :			/* Remote httpd-user if authenticated */			if(!(tmp = request->get_authenticated())) tmp = "-";			entry += tmp + token[1..];			break;		case 'r' :			/* Entire first line of request */			entry += token[1..];			break;		case 't' :			/* Time TODO: Should be other time format */			entry += ctime(time()) + token[1..];			break;		case 'b' :			/* Bytes sent, excluding headers */			tmp = (response->get_header("Content-Length") ? 					response->get_header("Content-Length") : "0");			if(tmp == nil || tmp == "0") tmp = "-";			entry += tmp + token[1..];			break;		case 's' :			/* Status */			tmp = "" + response->get_status();			entry += tmp + token[1..];			break;		case '{' :			/* Get any request-header */			x = index_of(1, token, "}");			if(x != -1) {				tmp = request->get_header(token[1..x-1]);				if(tmp) entry += tmp; else entry += "-";				if(strlen(token) > x) {					entry += token[x + 1..];				}			} else {				/* ignore this */			}			break;		default :			break;		}	}	return entry;}