Server.c File Reference

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <time.h>
#include <signal.h>
#include <mysql/mysql.h>

Go to the source code of this file.

Defines

#define BUFFER   4096
#define MSG_SIZE   200
#define MAX_CLIENTS   95
#define MYPORT   7400

Functions

void Read ()
void loginFn ()
void close_properly (int signal)
void exitClient (int fd, fd_set *readfds, char fd_array[], int *num_clients)
void display_row ()
void connectToDB ()
void newFn ()
void display_row2 ()
void findFriends ()
void display_row3 ()
void sendMsg ()
void message (char *MSG)
void display_row4 (char fname[100])
void display_row6 ()
void photo (char *MSG)
void startPhoto (char *MSG)
void history (char *MSG)
void acceptPhoto (char *MSG)
void reject (char *MSG)
int main (int argc, char *argv[])

Variables

MYSQL * connection1
MYSQL_RES * result
MYSQL_ROW sqlrow
int value = 0
int success = 0
int fd
int num_clients = 0
int id = 0
int FID [100]
char SId [10]
char list [200]
int listen_file_descriptor
int return1
char fd_array [MAX_CLIENTS]
char msg [MSG_SIZE+1]
char loginName [100]
char password [100]
char allNames [100][100]
int friends [100]
int num = 0
int ONLINE [100]
int opened [100]
int present
char newMsg [200]


Define Documentation

#define BUFFER   4096

Definition at line 13 of file Server.c.

Referenced by cont(), Read(), and subButton_clicked().

#define MAX_CLIENTS   95

Definition at line 15 of file Server.c.

Referenced by main().

#define MSG_SIZE   200

Definition at line 14 of file Server.c.

Referenced by main(), and sendMsg().

#define MYPORT   7400

Definition at line 16 of file Server.c.

Referenced by main().


Function Documentation

void acceptPhoto ( char *  MSG  ) 

This function decodes the message from the receiver client that he accepts the photo and sends the message to sender client.

Definition at line 558 of file Server.c.

References allNames, fd_array, and num_clients.

void close_properly ( int  signal  ) 

This function is used to close properly the server when ctrl+c/quit is entered.

Definition at line 47 of file Server.c.

References connection1.

Referenced by main().

void connectToDB (  ) 

This function connects to the database using mysql_real_connect() If connection fails displays error message.

Definition at line 108 of file Server.c.

References connection1.

Referenced by main().

void display_row (  ) 

This function checks the loginname and pasword entered by the user with data in the database.If it matches set success=0 else set success=1;

Definition at line 84 of file Server.c.

References loginName, password, SId, sqlrow, success, and value.

Referenced by loginFn().

void display_row2 (  ) 

This function finds online friends by comparing with the login info all clients.

Definition at line 175 of file Server.c.

References friends, num, num_clients, ONLINE, and sqlrow.

Referenced by findFriends().

void display_row3 (  ) 

Definition at line 219 of file Server.c.

References list, and sqlrow.

Referenced by sendMsg().

void display_row4 ( char  fname[100]  ) 

Definition at line 412 of file Server.c.

References num_clients, present, and sqlrow.

void display_row6 (  ) 

Definition at line 424 of file Server.c.

References newMsg, and sqlrow.

Referenced by history().

void exitClient ( int  fd,
fd_set *  readfds,
char  fd_array[],
int *  num_clients 
)

This function clears the leaving client when signout.

Definition at line 59 of file Server.c.

References ONLINE.

Referenced by main().

void findFriends (  ) 

This function identifies the friends who are online.

Definition at line 189 of file Server.c.

References connection1, display_row2(), result, and sqlrow.

Referenced by loginFn().

void history ( char *  MSG  ) 

This function retrieves the chatting history from the database and send the chatting history to the client.

Definition at line 494 of file Server.c.

References allNames, connection1, display_row6(), fd_array, newMsg, num_clients, ONLINE, result, and sqlrow.

void loginFn (  ) 

This function checks the loginname and password with the data in the database. If matches send "correct" msg to the client.If password does not matches send "check" message to the client.If user name does not matches send "wrong" message to the client.

Definition at line 268 of file Server.c.

References allNames, connection1, display_row(), fd, fd_array, findFriends(), id, loginName, msg, num, num_clients, ONLINE, password, result, sendMsg(), SId, sqlrow, success, and value.

Referenced by main().

int main ( int  argc,
char *  argv[] 
)

Used to create a tcp messenger server. Note that it will work only for ipv4 servers.

Returns:
zero to calling program on success, else 1.
Parameters:
argc number of command line arguments passed to the program including program name itself.
argv array of command line arguments.

Definition at line 614 of file Server.c.

References close_properly(), connection1, connectToDB(), exitClient(), fd, fd_array, friends, history, loginFn(), loginName, MAX_CLIENTS, message(), msg, MSG_SIZE, MYPORT, newFn(), num, num_clients, ONLINE, photo(), port, result, and startPhoto().

void message ( char *  MSG  ) 

This function decodes the chatting message from the client Saves the message information in the database.

Definition at line 365 of file Server.c.

References allNames, connection1, fd_array, msg, num_clients, and ONLINE.

Referenced by main().

void newFn (  ) 

This function inserts the new user detaiks into the database table Login.It returns login already exist if user already exist

Definition at line 139 of file Server.c.

References connection1, fd, and msg.

Referenced by main().

void photo ( char *  MSG  ) 

This function receives the photo from the sender client and sends to the receiver client.

Definition at line 436 of file Server.c.

References allNames, fd_array, and num_clients.

Referenced by main().

void Read (  ) 

It reads the message from the server.

Definition at line 1029 of file Client.c.

References BUFFER, r, Rmsg, and sockfd.

Referenced by subButton_clicked().

void reject ( char *  MSG  ) 

This function decodes the message from the receiver client that he rejects the photo and sends the message to sender client.

Definition at line 584 of file Server.c.

References allNames, fd_array, and num_clients.

void sendMsg (  ) 

Retrieves the login name of clients who are logged in and sends the the message to client.

Definition at line 230 of file Server.c.

References connection1, display_row3(), fd, friends, list, MSG_SIZE, num, result, and sqlrow.

Referenced by loginFn().

void startPhoto ( char *  MSG  ) 

This function receives the accept/reject message from the sender client and sends to the receiver client.

Definition at line 466 of file Server.c.

References allNames, fd_array, and num_clients.

Referenced by main().


Variable Documentation

char allNames[100][100]

Definition at line 37 of file Server.c.

Referenced by acceptPhoto(), history(), loginFn(), message(), photo(), reject(), and startPhoto().

MYSQL* connection1

int fd

Definition at line 26 of file Server.c.

Referenced by loginFn(), main(), newFn(), and sendMsg().

char fd_array[MAX_CLIENTS]

Used to store File descriptors of all the clients

Definition at line 35 of file Server.c.

Referenced by acceptPhoto(), history(), loginFn(), main(), message(), photo(), reject(), and startPhoto().

int FID[100]

Definition at line 27 of file Server.c.

int friends[100]

Definition at line 38 of file Server.c.

Referenced by cont(), display_row2(), main(), and sendMsg().

int id = 0

Definition at line 27 of file Server.c.

Referenced by loginFn().

char list[200]

Definition at line 28 of file Server.c.

Referenced by display_row3(), and sendMsg().

Definition at line 29 of file Server.c.

char loginName[100]

char msg[MSG_SIZE+1]

char newMsg[200]

Definition at line 41 of file Server.c.

Referenced by display_row6(), and history().

int num = 0

int num_clients = 0

int ONLINE[100]

Definition at line 38 of file Server.c.

Referenced by display_row2(), exitClient(), history(), loginFn(), main(), and message().

int opened[100]

Definition at line 38 of file Server.c.

Referenced by chat_Page(), and main().

char password[100]

Definition at line 37 of file Server.c.

Referenced by display_row(), loginFn(), and subButton_clicked().

int present

Definition at line 39 of file Server.c.

Referenced by display_row4().

MYSQL_RES* result

Definition at line 22 of file Server.c.

Referenced by findFriends(), history(), loginFn(), main(), and sendMsg().

int return1

Definition at line 30 of file Server.c.

char SId[10]

Definition at line 28 of file Server.c.

Referenced by display_row(), and loginFn().

MYSQL_ROW sqlrow

int success = 0

Definition at line 25 of file Server.c.

Referenced by display_row(), and loginFn().

int value = 0

Definition at line 25 of file Server.c.

Referenced by display_row(), and loginFn().


Generated on Wed Apr 7 16:48:16 2010 by  doxygen 1.5.8