/**********************************************************************************/
/* scol v 4                                                                       */
/*                                                                                */
/* proxyhttp.h                                                                    */
/*                                                                                */
/* proxy http management (authentication, authorization, ...)                     */
/*                                                                                */
/* cryonetworks, loïc berthelot, jull 2001                                        */
/**********************************************************************************/


#ifndef _PROXY_HTTP_H
#define _PROXY_HTTP_H

#include "scolPrerequisites.h"
#define PROXYHTTP_SCOL_NETWORK_API    0x0F
#define PROXYHTTP_WININET_NETWORK_API 0xFF


#define PROXYHTTP_AUTHENTICATION_CHALLENGE_FIELD "Proxy-Authenticate: "
#define PROXYHTTP_BASIC_CHALLENGE                "Basic realm=\""


#define PROXYHTTP_BASIC_AUTHORIZATION_FIELD     "Proxy-Authorization: Basic "


// defcom to allow a scol machine to ask the main machine informations to authenticate the user by the http proxy
#define PROXYHTTP_DEFCOM_AUTHENTICATION_REQUEST "__@ProxyHttpRequestAuthentication"
// defcom to make the main machine give the authentication informations
#define PROXYHTTP_DEFCOM_AUTHENTICATION         "__@ProxyHttpAuthentication"



// the proxy has denied access because the user need to authenticate.
// ask the main machine the user informations : 
//     it will directly return those informations if they have already been asked
#define PROXYHTTP_NORMAL_MODE    0x00

// the proxy has denied access because the user authentication informations have been rejected
// force the main machine to ask again the user his informations
#define PROXYHTTP_FORCED_MODE    0x01

#define PROXYHTTP_PROCESS_AUTHORIZATIONS 0x50


#define PROXYHTTP_PROCESS_AUTHORIZED       0x01
#define PROXYHTTP_PROCESS_CANCELED         0x00














/***************************************************************/
/* scol v 4                                                    */
/*                                                             */
/* int PROXYHTTP_Authorization (mmachine m, SOCKET scksys)     */
/*                                                             */
/* re-send the request, in adding the proxy authentication     */
/* challenge in the header.                                    */
/*                                                             */
/***************************************************************/
int PROXYHTTP_Authorization (mmachine m, SOCKET scksys);






/*********************************************************/
/*                                                       */
/* int PROXYHTTP_SetAuthInfos (mmachine m, char* defcom) */
/*                                                       */
/* client machine receives authentication infos from     */
/* the main machine.                                     */
/*                                                       */
/*********************************************************/
int PROXYHTTP_SetAuthInfos (mmachine m, char* defcom);



void PROXYHTTP_ProcessAuthInfos();






/*****************************************************/
/*                                                   */
/* PROXYHTTP_GetAuthInfos (mmachine m, char *defcom) */
/*                                                   */
/* asks the user the http authentication infos,      */
/* if needed, and send them onto the master ch.      */
/*                                                   */
/*****************************************************/
int PROXYHTTP_GetAuthInfos (mmachine m, char *defcom);









/*************************************************************************************/
/*                                                                                   */
/* int PROXYHTTP_AskAuthInfos (mmachine m, int networkAPI, int handle, int force)    */
/*                                                                                   */
/* make the client machine ask the main machine the informations                     */
/* about http authentication.                                                        */
/*                                                                                   */
/* char* networkAPI <=> PROXYHTTP_SCOL_NETWORK_API or PROXYHTTP_WININET_NETWORK_API  */
/*                                                                                   */
/* int handle       <=> if PROXYHTTP_SCOL_NETWORK_API                                */
/*                         <=> SOCKET sck                                            */
/*					else if PROXYHTTP_WININET_NETWORK_API                            */
/*						   <=> DWORD threadid                                        */
/*                                                                                   */
/* int force   <=> 1 to make the scol engine force the dialog,                       */
/*                 0 let it determine if the dialog is necessary                     */
/*                                                                                   */
/*************************************************************************************/
int PROXYHTTP_AskAuthInfos (mmachine m, int networkAPI, int handle, int force);



char* PROXYHTTP_GetUname ();


char* PROXYHTTP_GetPword ();



char* PROXYHTTP_GetUserID();





/******************************************************************/
/*                                                                */
/* int PROXYHTTP_IsAuthorized ()                                  */
/*                                                                */
/* returns 1 if the scol machine has already got the http         */
/* authentication infos, 0 if not                                 */ 
/*                                                                */
/******************************************************************/
int PROXYHTTP_IsAuthorized ();






/******************************************************************/
/*                                                                */
/* int PROXYHTTP_IsAuthorizationRejected (char* request)          */
/*                                                                */
/* returns 1 if the scol machine has already got the http         */
/* authentication infos, 0 if not                                 */ 
/*                                                                */
/******************************************************************/
int PROXYHTTP_IsAuthorizationRejected (char* request);





/******************************************************************/
/*                                                                */
/* int PROXYHTTP_WININET_IsAuthenticated (HANDLE h)               */
/*                                                                */
/* check if a 407 HTTP error is contained in the header of proxy  */
/* http message.                                                  */
/*                                                                */
/* returns 1 if 407 error and basic authentication needed,        */
/* 0 if not.                                                      */
/*                                                                */
/******************************************************************/
int PROXYHTTP_WININET_IsAuthenticated (HANDLE h);



/******************************************************************/
/*                                                                */
/* int PROXYHTTP_IsAuthenticated (char* header, int headerSize)   */
/*                                                                */
/* check if a 407 HTTP error is contained in the header of proxy  */
/* http message.                                                  */
/*                                                                */
/* returns 1 if 407 error, 0 if not.                              */
/*                                                                */
/******************************************************************/
int PROXYHTTP_IsAuthenticated (char* header, int headerSize);









#endif