static string authenticate(object request)
static string authenticate(Request request)
static string authenticate(object request){	int		stale;	mixed	*au_req, *au_res;	string	a1, ha1, a2, ha2;	string	password, realm, result, md5_result;	mapping	req_avp;	au_req = allocate(AU_STRUCT_SIZE);	au_req[AU_HEADER] = AU_REQ_HEADER;	if(get_au(request, au_req) == FALSE) {		SYSLOG("auth_request(): request: failed to parse header\n");		return nil;	}		if(au_req[AU_METHOD] != "Digest" || !map_sizeof(au_req[AU_AVP]) ) {		SYSLOG("auth_request(): request: wrong method or no attributes\n");		return nil;	}	req_avp = au_req[AU_AVP];	/* get password (crypt():ed) */	if( (password = get_password(req_avp[AU_ATT_USER])) == nil ) {		SYSLOG("auth_request(): could not fetch password\n");		return nil;	}/* TESTING TESTING */	password = "-";/* END OF */	/* TODO: SECURITY! Replace below with a real value */	realm =	"jorinde@dgd"; /* + request->get_header("Host");*/	a1 = req_avp[AU_ATT_USER]	+ ":" +		realm					+ ":" +		password;	ha1 = friendly_md5(a1);	a2 = request->get_command()	+ ":" +		/* This is GET, POST etc */		req_avp[AU_ATT_URI];	ha2 = friendly_md5(a2);	/* Check nonce */	stale = stale_nonce(req_avp[AU_ATT_NONCE]);	/* TODO: SECURITY! store nonce in application! Verify against that!	 * request->get_application()	 */	/* TODO: app.Context.Items["staleNonce"] = isNonceStale; */	if(req_avp[AU_ATT_QOP]) {		result = ha1					+	":" +				req_avp[AU_ATT_NONCE]	+	":" +				req_avp[AU_ATT_NC]		+	":" +				req_avp[AU_ATT_CNONCE]	+	":" +				req_avp[AU_ATT_QOP]		+	":" +				ha2;	} else {		result = ha1					+	":" +				req_avp[AU_ATT_NONCE]	+	":" +				ha2;	}	md5_result = friendly_md5(result);	SYSLOG("          AVP: " + make_string(req_avp) + "\n");	SYSLOG("   Digest got: '" + req_avp[AU_ATT_RESPONSE] + "'\n");	SYSLOG("Digest wanted: '" + md5_result + "'\n");	SYSLOG("Want (nohash): " + result + "\n");	SYSLOG("  Stale nonce: " + stale + "\n");	if(req_avp[AU_ATT_RESPONSE] == md5_result && !stale) {		return req_avp[AU_ATT_USER];	} else {		return nil;	}	/* Should not get here */	return nil;}