#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 BUFFER 4096 |
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 | ( | ) |
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 | ( | ) |
void display_row4 | ( | char | fname[100] | ) |
void display_row6 | ( | ) |
void exitClient | ( | int | fd, | |
fd_set * | readfds, | |||
char | fd_array[], | |||
int * | num_clients | |||
) |
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.
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 | ( | ) |
void photo | ( | char * | MSG | ) |
void Read | ( | ) |
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 | ( | ) |
void startPhoto | ( | char * | MSG | ) |
char allNames[100][100] |
Definition at line 37 of file Server.c.
Referenced by acceptPhoto(), history(), loginFn(), message(), photo(), reject(), and startPhoto().
MYSQL* connection1 |
Definition at line 21 of file Server.c.
Referenced by close_properly(), connectToDB(), findFriends(), history(), loginFn(), main(), message(), newFn(), and sendMsg().
int fd |
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 friends[100] |
char list[200] |
char loginName[100] |
Definition at line 37 of file Server.c.
Referenced by chat_Page(), createButton_clicked(), display_row(), loginFn(), main(), mainPage(), send_clicked(), sendPhoto(), sendReq_clicked(), signout_clicked(), subButton_clicked(), and view_clicked().
char msg[MSG_SIZE+1] |
Definition at line 36 of file Server.c.
Referenced by cont(), createButton_clicked(), loginFn(), main(), message(), newFn(), sendPhoto(), sendReq_clicked(), signout_clicked(), subButton_clicked(), and view_clicked().
char newMsg[200] |
int num = 0 |
Definition at line 38 of file Server.c.
Referenced by chat_Page(), cont(), display_row2(), insertAll(), insertCombo(), loginFn(), main(), removeFrnd(), send_clicked(), and sendMsg().
int num_clients = 0 |
Definition at line 27 of file Server.c.
Referenced by acceptPhoto(), display_row2(), display_row4(), history(), loginFn(), main(), message(), photo(), reject(), and startPhoto().
int ONLINE[100] |
Definition at line 38 of file Server.c.
Referenced by display_row2(), exitClient(), history(), loginFn(), main(), and message().
int opened[100] |
char password[100] |
Definition at line 37 of file Server.c.
Referenced by display_row(), loginFn(), and subButton_clicked().
int present |
MYSQL_RES* result |
char SId[10] |
MYSQL_ROW sqlrow |
Definition at line 23 of file Server.c.
Referenced by display_row(), display_row2(), display_row3(), display_row4(), display_row6(), findFriends(), history(), loginFn(), and sendMsg().
int success = 0 |
int value = 0 |