-
Notifications
You must be signed in to change notification settings - Fork 1
/
serv-client.h
167 lines (133 loc) · 3.58 KB
/
serv-client.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* Defines the common header types for both the server and the client */
/*
Copyright (C) <2010> <Sanket Agarwal>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define WM_MAX 500 // Welcome message size
#define M_MAX 500 // General message size
#define UN_MAX 20 // Username maxsize
#define PASS_MAX 20 // Password maximum size
#define CHAT_MAX 20 // Maximum users in a room
#define CHAT_ROOM_MAX 20 // Maximum chat rooms
#define BUDDIES_MAX 100
#define MSG_MAX 500
#define PKT_SIZE 1024 // Size in bytes
#define CRED_FN "uname.dat"
void show_menu();
enum BOOLEAN{
TRUE,
FALSE
};
enum LOGIN_RESULT{
NEW_CREATED,
SIGNED_IN_OR_PASS,
OLD_EXIST,
OLD_SIGNED_IN,
DO_NOT_EXIST
};
enum STATUS{
SIGNED_IN,
SIGNED_OUT
};
enum SERV_TYPE{
WM, /* Welcome message */
M, /* General Message */
LOGIN_RES, /* Login status */
BL_RES, /* Sends the buddy list */
LOGIN, /* Login Process */
CM, /* Chat Message */
IM_REQ_SERV, /* Instant Message */
CHAT_ROOM_CREAT, /* Start a new chat room on server */
CHAT_ROOM_JOINED, /* Acceptance to join chat room */
CHAT_MSG, /* Actual chat message packet */
ERR, /* Any error message */
IM_START_CONF, /* Confirms the client to start the IM */
SIGN_OUT_CONF, /* Confirms the sign out */
IM_RECV, /* Client receives an IM */
FILE_XFER_RECV /* File received by a client */
};
enum CLIENT_TYPE{
EXIST_USER, /* Exist user logon */
NEW_USER, /* New user logon */
GET_BL, /* Buddy List on server */
IM_REQ_CL, /* Request a client to start IM */
IM_ACK_CL, /* Acknowledge a IM request */
CHAT_ROOM_CREAT_REQ_CL, /* Request a chat room start */
CHAT_ROOM_JOIN_REQ_CL, /* Join a chat room */
CHAT_ROOM_SEND_MSG, /* Broadcasts the message to all the clients in that room */
IM_START_REQ, /* Requests a start of IM stanza */
SIGN_OUT_CL, /* Signs the client out */
IM_SEND, /* Sends an IM */
FILE_XFER_SEND /* File xfer protocol */
};
typedef struct _cred{
char u_name[UN_MAX];
char pass[PASS_MAX];
enum STATUS status;
int socket_id;
}Cred;
typedef struct _c_i_m{
Cred cr;
char msg[MSG_MAX];
}IM;
typedef struct _buddy_list{
Cred buddies[BUDDIES_MAX];
int tos;
}Buddy_List;
typedef struct _chat_message{
char msg[MSG_MAX];
}ChatMessage;
typedef struct _fx{
char *data[PKT_SIZE];
char file_name[100];
int pkt_no;
int pkt_data;
int file_size;
}FX;
typedef struct _serv_msg{
char wm[WM_MAX];
char m[M_MAX];
Cred b_l[BUDDIES_MAX];
ChatMessage cm;
IM im;
int b_l_tos;
enum SERV_TYPE type;
enum LOGIN_RESULT l_r;
FX fx;
}Serv_Msg;
typedef struct _client_msg{
Cred cr;
char chat_room_name[UN_MAX+10];
ChatMessage cm;
IM im;
enum CLIENT_TYPE type;
FX fx;
}Cl_Msg;
typedef struct _chat_room{
char name[UN_MAX+10];
Cred users[CHAT_MAX];
int no_users;
}ChatRoom;
typedef struct _chat_rooms{
ChatRoom chat_room[CHAT_ROOM_MAX];
int no_rooms;
}ChatRooms;
typedef struct _s_i_m{
Cred cr1;
Cred cr2;
int cr1_ent;
int cr2_ent;
}ServIM;
typedef struct _i_ms{
ServIM im_arr[CHAT_ROOM_MAX];
int tos;
}InstantMsgs;