// Multiple HTTP authentication implementations
// most notably the modern OAUTH, but also supports PLAIN, DIGEST

typedef struct OAUTH {
	char *auth_type;
	int state;
	int sooner;					// do not send an empty request first (slight secureity risk for Digest Auth)

	char *user;					// ALL
	char *pass;					// BASIC and DIGEST only

	char *stored_digest;		// DIGEST only

	char *timestamp;			// DIGEST and OAUTH
	char *nonce;				// DIGEST and OAUTH
	
	char *auth_token;			// OAUTH only
	char *token_secret;			// OAUTH only

	char *consumer_key;			// OAUTH only
	char *app_secret;			// OAUTH only
	char *signature;			// OAUTH only
	char *signature_method;		// OAUTH only

} OAuth;

enum { OA_UNREQUESTED, OA_REQUESTED, OA_REDIRECT_RECEIVED, OA_ACCESS_RECEIVED };

OAuth *oa_new();
OAuth *oa_new_basic(char *user, char*pass);
OAuth *oa_new_digest(char *user, char*pass);
OAuth *oa_new_oauth(char *user, char*consumer_key, char*app_secret, char *auth_token, char*token_secret);

int oa_free(OAuth **x);
int oa_auth_sooner(OAuth *oa, int sooner);

int oa_auth_cb(void *param, char*challenge, char*method, char*url, char *header, int bfsz);
int oa_valid(OAuth *oa);
int oa_basic_auth(OAuth *oa, char *header, int bfsz);
int oa_digest_auth(OAuth *oa, char*challenge, char*method, char*url, char *digest);
int oa_oauth_auth(OAuth *oa, char*challenge, char*method, char*url, char *digest);

int oa_assign_request_token(OAuth *oa, char *token_secret, char *oauth_token, char *uid);

int oa_generate_signature(OAuth *oa, char *sig);
int oa_oauth_prepare(OAuth *oa, char*consumer_key, char*app_secret);
