Client Class Reference

List of all members.

Public Member Functions

 Client (UserIf *)
 ~Client ()
int initSSL ()
int setpassword (const char *p)
int loadCertificates ()
int openConnection ()
int startSSL (unsigned char *, int *len)
int stopSSL (unsigned char *, int *len)
int registerToServer (unsigned char *, int *len)
int unregisterOnServer (unsigned char *, int len)
int initiateChatSession (int destClient)
int terminateChatSession ()
int getActiveUserList (ClientInfo *&clientList, int *len)
int receiveData (unsigned char *data, int len)
int sendData (unsigned char *data, int len)
int getAccountStatus (ClientInfo *client)
void * listener (void *)
void * worker (void *)
int isconnected ()

Constructor & Destructor Documentation

Client::Client ( UserIf myUi  ) 

Client constructor: Takes the User interface object and uses it to initialize class attribute of same type.

Parameters:
UserIf object of user interface class
Client::~Client (  ) 

Client desctructor: Kill session and listener thread.


Member Function Documentation

int Client::getActiveUserList ( ClientInfo *&  cList,
int *  len 
)

getActiveUserList: creates a request to get active user list from server and waits for its reply. Recieved information is used to populate the client list, which is then returned back to the calling function.

If not present, creates the listener thread. From now on , all SSL read operations are handled by the listener thread.

Currently, behaviour is unknown if the clients closes a chat session and tries to restart it. And out parameters are not being used now as well.

Parameters:
cList [out]
len [out]
int Client::initiateChatSession ( int  destClient  ) 

initiateChatSession: Creates a call begin packet for destination client and writes it on ssl channel. destClient value should be valid. For all invalid values, connection attempt will fail.

Parameters:
destClient 
int Client::initSSL (  ) 

initSSL : initializes the SSL library and context.

int Client::isconnected (  ) 

isconnected: checks if a chat session with other client is active.

void * Client::listener ( void *   ) 

listener: waits on a blocking read call and handles all the packets coming from server. It can handle call request packets on both sides ie call initiator and call receiver, data packets and termination packets. Different packets are processed differently here. As a result of processing, ssl write and/or ui write or any other processing function may be called.

FUTURE: Extend it to handle all possible packets for example: register request replies, user list replies, etc. And handle all ssl read operations in this function.

int Client::loadCertificates (  ) 

loadCertificates: Loads the certificate from certificate file and extract information from it. Can be expanded to get public and private keys and store them for assymetric encryption.

int Client::openConnection (  ) 

openConnection: Opens a raw socket connection to server

Returns:
0 on success and 1 on failure
int Client::receiveData ( unsigned char *  data,
int  len 
)

receiveData: It handles the data coming form the server side. This checks if the packets received are for key establishment for data exchange.

All normal data packets are encrypted when received therefore, they are decrypted here and then forwarded to the UI for display.

Parameters:
data buffer of either plain text or encrypted data .
len length of buffer in bytes
int Client::registerToServer ( unsigned char *  response,
int *  len 
)

registerToServer: sends the registration request to server and waits for its response. A successful response from server, contains the unique client Id assigned by the server. This clientID is saved in client attributes. And used for all further communications, during this client<-->server session. out parameters are not being used at the moment. :(

Parameters:
response [out]stores the reponse of server for the register request.
len [out]this function sets length of the response buffer.
Returns:
0 on success and 1 on failure
int Client::sendData ( unsigned char *  data,
int  len 
)

sendData: This function is used by UI during chat session to send data to the other end. It creates the packet for data and sends it.

Every data packet is encrypted before it is written into the packet.

Parameters:
data buffer of plain text data as given from UI
len length of buffer in bytes
int Client::setpassword ( const char *  passwd  ) 

setpassword: To set the password for accessing certificate. In debug version *this is used primariry for automating extraction of private key from *certificate using a passphrase. Not to be used like this in the release version.

Parameters:
password is the passphrase for getting private key from certificate
Returns:
length of password in case of success or in failure.
int Client::startSSL ( unsigned char *  response,
int *  len 
)

startSSL: creates SSL connection on the opened socket connection. In this debug version, this function sends a test "Ahoj" message to server and receives it reply back. This function increases the testability to observe the data from server, thus verifying the connection establishment.

Parameters:
response [out] stores the reponse of server for the Ahoj message.
len [out] this function sets length of the response buffer.
Returns:
0 on success and 1 on failure
int Client::stopSSL ( unsigned char *  response,
int *  len 
)

stopSSL: Will send a Termination request to server and wait for its response. This response is observable.

Parameters:
response [out]
len [out]
void * Client::worker ( void *   ) 

For further extension and organised code. Sorry no time to reorgnise!


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines

Generated on 2 Dec 2014 by  doxygen 1.6.1