|
@@ -36,6 +36,7 @@
|
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
|
#include <getopt.h>
|
|
#include <getopt.h>
|
|
|
#include <libintl.h>
|
|
#include <libintl.h>
|
|
|
|
|
+#include <limits.h>
|
|
|
|
|
|
|
|
#include <klist.h>
|
|
#include <klist.h>
|
|
|
#include <vcc/vcc.h>
|
|
#include <vcc/vcc.h>
|
|
@@ -50,11 +51,13 @@
|
|
|
/* we tried to use libreadline, but after using that, we feel strange
|
|
/* we tried to use libreadline, but after using that, we feel strange
|
|
|
* because... because of what? i don't know. */
|
|
* because... because of what? i don't know. */
|
|
|
|
|
|
|
|
|
|
+int vcc_login(char *, char *);
|
|
|
|
|
+
|
|
|
int send_msg(const char *msg, const char *usrname);
|
|
int send_msg(const char *msg, const char *usrname);
|
|
|
int read_msg(struct vcc_request *buf);
|
|
int read_msg(struct vcc_request *buf);
|
|
|
int get_msgs(void);
|
|
int get_msgs(void);
|
|
|
-int vcc_login(char *, char *);
|
|
|
|
|
int is_user_banned(char *);
|
|
int is_user_banned(char *);
|
|
|
|
|
+char *relay_get_msg(int fd, struct vcc_relay_header *);
|
|
|
|
|
|
|
|
int show_algo_info(void);
|
|
int show_algo_info(void);
|
|
|
int crypt_init(void *key, void *iv);
|
|
int crypt_init(void *key, void *iv);
|
|
@@ -278,6 +281,33 @@ void sigint_handler(int signr) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+int new_msg(char *msg, char *name, int session) {
|
|
|
|
|
+ char *p;
|
|
|
|
|
+
|
|
|
|
|
+ if (!strcmp(msg, "CQD")) {
|
|
|
|
|
+ pretty_cqd(name);
|
|
|
|
|
+ pretty_prompt(usrname);
|
|
|
|
|
+
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (unlikely(is_user_banned(name)))
|
|
|
|
|
+ return 1;
|
|
|
|
|
+
|
|
|
|
|
+ if (recv_hook)
|
|
|
|
|
+ if (unlikely(!(p = recv_hook(msg))))
|
|
|
|
|
+ return 1;
|
|
|
|
|
+
|
|
|
|
|
+ pretty_new_msg(usrname, msg, session);
|
|
|
|
|
+ pretty_prompt(usrname);
|
|
|
|
|
+
|
|
|
|
|
+ if (recv_hook)
|
|
|
|
|
+ free(p);
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
int init_signal(void) {
|
|
int init_signal(void) {
|
|
|
struct sigaction act;
|
|
struct sigaction act;
|
|
|
|
|
|
|
@@ -293,6 +323,7 @@ int init_signal(void) {
|
|
|
int main(int argc, char **argv) {
|
|
int main(int argc, char **argv) {
|
|
|
struct pollfd fds[2];
|
|
struct pollfd fds[2];
|
|
|
struct vcc_request *req;
|
|
struct vcc_request *req;
|
|
|
|
|
+ struct vcc_relay_header *hdr;
|
|
|
char *buf, *msg, *ip = VCC_DEFSERV;
|
|
char *buf, *msg, *ip = VCC_DEFSERV;
|
|
|
char key[64], iv[64];
|
|
char key[64], iv[64];
|
|
|
int n, size, port = VCC_PORT, got_usrname;
|
|
int n, size, port = VCC_PORT, got_usrname;
|
|
@@ -342,13 +373,19 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
init_signal();
|
|
init_signal();
|
|
|
|
|
|
|
|
- if (unlikely(!(buf = malloc(MSG_SIZE)))) {
|
|
|
|
|
|
|
+ if (unlikely(!(buf = malloc(PATH_MAX)))) {
|
|
|
|
|
+ fprintf(stderr, "*** malloc() failed\n");
|
|
|
|
|
+
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (unlikely(!(hdr = malloc(sizeof(struct vcc_relay_header))))) {
|
|
|
fprintf(stderr, "*** malloc() failed\n");
|
|
fprintf(stderr, "*** malloc() failed\n");
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (unlikely(!(req = malloc(REQ_SIZE)))) {
|
|
|
|
|
|
|
+ if (unlikely(!(req = malloc(sizeof(struct vcc_request ))))) {
|
|
|
fprintf(stderr, "*** malloc() failed\n");
|
|
fprintf(stderr, "*** malloc() failed\n");
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
@@ -368,14 +405,14 @@ int main(int argc, char **argv) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (fds[0].revents & POLLIN) {
|
|
if (fds[0].revents & POLLIN) {
|
|
|
- if (read(0, buf, MSG_SIZE) == -1)
|
|
|
|
|
|
|
+ if (read(0, buf, PATH_MAX) == -1)
|
|
|
continue;
|
|
continue;
|
|
|
|
|
|
|
|
do_handle_command(buf);
|
|
do_handle_command(buf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (fds[1].revents & POLLIN) {
|
|
if (fds[1].revents & POLLIN) {
|
|
|
- size = read(fd, req, REQ_SIZE);
|
|
|
|
|
|
|
+ size = read(fd, hdr, sizeof(struct vcc_relay_header));
|
|
|
|
|
|
|
|
if (unlikely(!size)) {
|
|
if (unlikely(!size)) {
|
|
|
fprintf(stderr, _("Server closed. \n"));
|
|
fprintf(stderr, _("Server closed. \n"));
|
|
@@ -383,36 +420,32 @@ int main(int argc, char **argv) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (ntohl(req->reqtype) != REQ_MSG_NEW) {
|
|
|
|
|
- do_bh(req);
|
|
|
|
|
|
|
+ if (ntohl(hdr->magic) == VCC_MAGIC) {
|
|
|
|
|
+ memcpy(req, hdr, sizeof(struct vcc_relay_header));
|
|
|
|
|
+ read(fd, (void *) req + sizeof(struct vcc_relay_header),
|
|
|
|
|
+ REQ_SIZE - sizeof(struct vcc_relay_header));
|
|
|
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /* classical process */
|
|
|
|
|
|
|
|
- msg = req->msg;
|
|
|
|
|
|
|
+ if (ntohl(req->reqtype) == REQ_MSG_NEW) {
|
|
|
|
|
+ if (ntohl(req->flags) & FLAG_ENCRYPTED)
|
|
|
|
|
+ decrypt(req->msg);
|
|
|
|
|
|
|
|
- if (!strcmp(msg, "CQD")) {
|
|
|
|
|
- pretty_cqd(req->usrname);
|
|
|
|
|
- pretty_prompt(usrname);
|
|
|
|
|
|
|
+ new_msg(req->msg, req->usrname, req->session);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ else
|
|
|
|
|
+ do_bh(req);
|
|
|
|
|
|
|
|
- if (unlikely(is_user_banned(req->usrname)))
|
|
|
|
|
continue;
|
|
continue;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (ntohl(req->flags) & FLAG_ENCRYPTED)
|
|
|
|
|
- decrypt(msg);
|
|
|
|
|
-
|
|
|
|
|
- if (recv_hook)
|
|
|
|
|
- if (unlikely(!(msg = recv_hook(msg))))
|
|
|
|
|
- continue;
|
|
|
|
|
-
|
|
|
|
|
- pretty_new_msg(req->usrname, msg, ntohl(req->session));
|
|
|
|
|
- pretty_prompt(usrname);
|
|
|
|
|
|
|
+ else {
|
|
|
|
|
+ msg = relay_get_msg(fd, hdr);
|
|
|
|
|
+ new_msg(msg, hdr->usrname, hdr->session);
|
|
|
|
|
|
|
|
- if (recv_hook)
|
|
|
|
|
free(msg);
|
|
free(msg);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|