//
// File : socks.h
//
// manage socks protocol (4 and 5)
//
// by Loïc Berthelot, CryoNetworks, june 2001

#ifndef _SOCKS_H_
#define _SOCKS_H_

#include "scolPrerequisites.h"
#include "socket.h"

/************************************************************************/
/*                                                                      */
/*            C O N S T A N T      V A L U E S                          */
/*                                                                      */
/************************************************************************/


/* SOCKS generic error codes                                            */
#define SOCKS_SUCCESS               0 // the socket is connected to the server
#define SOCKS_ERROR_NO_PROXY        1 // there is no proxysocks defined!
#define SOCKS_ERROR_VERSION         2 // the proxysocks version is not defined!
#define SOCKS_ERROR_CONNECT_PROXY   3 // could not connect socket to proxy

/* SOCKS 4 specific error codes                                         */
#define SOCKS4_ERROR_REQ_COMMAND    4 // could not send the command request
#define SOCKS4_ERROR_ACK_COMMAND    5 // ccould not receive acknowledgement of the command request from proxy
#define SOCKS4_ERROR_REQ_REJECTED   6 // proxy socks has rejected the command request

/* SOCKS 5 specific error codes                                         */
#define SOCKS5_ERROR_REQ_AUTH_METHODS  7 // could not send request for authentication methods enumeration
#define SOCKS5_ERROR_ACK_AUTH_METHODS  8 // could not receive authentication methods enumeration from proxy
#define SOCKS5_ERROR_AUTH_METHODS      9 // unable to manage authentication method the proxy socks asked
#define SOCKS5_ERROR_AUTH_REQUIRED    10 // access rejected. Authentication needed
#define SOCKS5_ERROR_REQ_AUTH         11 // could not send authentication to proxy
#define SOCKS5_ERROR_ACK_AUTH         12 // could not receive aknowledgement of the authentication from proxy
#define SOCKS5_ERROR_AUTH_REJECTED    13 // authentication failed
#define SOCKS5_ERROR_REQ_COMMAND      14 // could not send the command request
#define SOCKS5_ERROR_ACK_COMMAND      15 // could not receive the aknowledgement of the command request from proxy
#define SOCKS5_ERROR_COMMAND          16 // proxy socks has been unable to process the command request


#define NB_SOCKS_ERROR 17















/************************************************************************/
/*                                                                      */
/*            E X T E R N A L     B O D Y                               */
/*                                                                      */
/************************************************************************/



// set the protocole version <=> 4 or 5
// returns non-zero value if newValue is not 4 or 5
// returns 0 if ok
int SOCKSsetVersion (int newValue);

// set the authentication flag
// <=> 1 if authentication needed, 0 if not
// returns non-zero value if newValue is not 0 or 1
// returns 0 if ok
int SOCKSsetAuthentication (int newValue);

// set the socks5 username 
// returns 0 if ok, non-zero value if not (username too long)
int SOCKSsetUsername (char* newUname);

// set the socks5 password
// returns 0 if ok, non-zero value if not (password too long)
int SOCKSsetPassword (char* newPword);



/*******************************************************************/
/* scol v 4                                                        */
/*                                                                 */
/* int SOCKSformatMessage (int errorClass, char* buf, int bufSize) */
/*                                                                 */
/* fills the characters buffer with the error message              */
/* corresponding to the errorClass code given as parameter.        */
/*                                                                 */
/* returns 0 if success,                                           */
/* needed size if fail (buffer too small)                          */
/*                                                                 */
/*******************************************************************/

int SOCKSformatMessage (int errorClass, char* buf, int bufSize);









/************************************************************************************/
/* scol v 4                                                                         */
/*                                                                                  */
/* int SOCKSconnect (SOCKET sock, unsigned long INETaddr, unsigned short TCPIPport) */
/*                                                                                  */
/* connect the socket 'sock' to a server, addressed by 'addr',                      */
/* on port 'port', through a proxy socks. This function determines                  */
/* the version of socks protocol to use.                                            */
/* server's address is given as inet adress,                                        */
/* and port is given as TCP/IP byte order.                                          */
/*                                                                                  */
/* returns 0 if success, non-zero code if fail. error codes are                     */
/* defined in socks.h                                                               */
/*                                                                                  */
/************************************************************************************/

int SOCKSconnect (SOCKET sock, unsigned long INETaddr, unsigned short TCPIPport);



#endif