|
|
@@ -35,6 +35,9 @@
|
|
|
#include <poll.h>
|
|
|
#include <signal.h>
|
|
|
|
|
|
+#include <readline/readline.h>
|
|
|
+#include <readline/history.h>
|
|
|
+
|
|
|
#include <klist.h>
|
|
|
#include <vcc/vcc.h>
|
|
|
#include <vcc/version.h>
|
|
|
@@ -65,7 +68,7 @@ int fd;
|
|
|
int rate;
|
|
|
|
|
|
char usrname[USRNAME_SIZE];
|
|
|
-struct klist_node *banned_people;
|
|
|
+struct klist_node banned_people = KLIST_NODE_INIT(&banned_people);
|
|
|
|
|
|
extern int current_sid;
|
|
|
|
|
|
@@ -145,11 +148,27 @@ int parse_args(char **argv, int *port, char **ip) {
|
|
|
return got_usrname;
|
|
|
}
|
|
|
|
|
|
+int do_handle_command(char *buf) {
|
|
|
+ add_history(buf);
|
|
|
+
|
|
|
+ if (*buf == '-')
|
|
|
+ do_cmd(buf);
|
|
|
+
|
|
|
+ else if (*buf != '\n') {
|
|
|
+ send_msg(buf, usrname);
|
|
|
+ pretty_new_msg(usrname, buf, current_sid);
|
|
|
+ }
|
|
|
+
|
|
|
+ pretty_prompt(usrname);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
struct pollfd fds[2];
|
|
|
struct vcc_request *req;
|
|
|
- char *buf, *msg, *ip = "124.223.105.230", *t;
|
|
|
+ char *buf, *msg, *ip = "124.223.105.230";
|
|
|
char key[64], iv[64];
|
|
|
int n, size, port = VCC_PORT, got_usrname;
|
|
|
|
|
|
@@ -182,9 +201,6 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
crypt_init(key, iv);
|
|
|
|
|
|
- banned_people = malloc(sizeof(struct klist_node));
|
|
|
- klist_init(banned_people);
|
|
|
-
|
|
|
fds[0].fd = 0;
|
|
|
fds[0].events = POLLIN;
|
|
|
fds[0].revents = 0;
|
|
|
@@ -195,7 +211,7 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
rate = DEFAULT_RATE;
|
|
|
|
|
|
- if (unlikely(!(buf = malloc(MSG_SIZE))) || unlikely(!(t = malloc(MSG_SIZE)))) {
|
|
|
+ if (unlikely(!(buf = malloc(MSG_SIZE)))) {
|
|
|
fprintf(stderr, "*** malloc() failed\n");
|
|
|
|
|
|
return 1;
|
|
|
@@ -227,34 +243,8 @@ int main(int argc, char **argv) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (fds[0].revents & POLLIN) {
|
|
|
- /* read keyboard */
|
|
|
-
|
|
|
- memset(buf, 0, MSG_SIZE);
|
|
|
-
|
|
|
- if (read(0, buf, MSG_SIZE) < 0) {
|
|
|
- perror("read()");
|
|
|
-
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (*buf == '-')
|
|
|
- do_cmd(buf);
|
|
|
-
|
|
|
- else if (*buf != '\n') {
|
|
|
- memcpy(t, buf, MSG_SIZE);
|
|
|
-
|
|
|
- if (unlikely(encrypt(buf)))
|
|
|
- continue;
|
|
|
-
|
|
|
- send_msg(buf, usrname);
|
|
|
- decrypt(buf);
|
|
|
-
|
|
|
- pretty_new_msg(usrname, t, current_sid);
|
|
|
- }
|
|
|
-
|
|
|
- pretty_prompt(usrname);
|
|
|
- }
|
|
|
+ if (fds[0].revents & POLLIN)
|
|
|
+ rl_callback_read_char();
|
|
|
|
|
|
if (fds[1].revents & POLLIN) {
|
|
|
size = read(fd, req, REQ_SIZE);
|
|
|
@@ -280,12 +270,12 @@ int main(int argc, char **argv) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (strcmp(req->usrname, "system"))
|
|
|
- decrypt(msg);
|
|
|
-
|
|
|
- if (is_user_banned(req->usrname))
|
|
|
+ if (unlikely(is_user_banned(req->usrname)))
|
|
|
continue;
|
|
|
|
|
|
+ if (ntohl(req->flags) & FLAG_ENCRYPTED)
|
|
|
+ decrypt(msg);
|
|
|
+
|
|
|
pretty_new_msg(req->usrname, msg, ntohl(req->session));
|
|
|
pretty_prompt(usrname);
|
|
|
}
|