|
|
@@ -263,13 +263,57 @@ int new_msg(char *msg, char *name, int session, int flags) {
|
|
|
do_hook_recv(msg, name, session);
|
|
|
|
|
|
if (*msg)
|
|
|
- pretty_new_msg(name, msg, session, flags);
|
|
|
+ pretty_new_msg(name, msg, ntohl(session), flags);
|
|
|
pretty_prompt(usrname);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
+int do_new_request(struct vcc_relay_header *hdr) {
|
|
|
+ struct vcc_request req;
|
|
|
+ int flags;
|
|
|
+ char *msg;
|
|
|
+
|
|
|
+ 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));
|
|
|
+
|
|
|
+ /* classical process */
|
|
|
+
|
|
|
+ if (ntohl(req.reqtype) == REQ_MSG_NEW) {
|
|
|
+ if (ntohl(req.flags) & FLAG_ENCRYPTED)
|
|
|
+ decrypt(req.msg);
|
|
|
+
|
|
|
+ new_msg(req.msg, req.usrname, req.session, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ do_bh(&req);
|
|
|
+ }
|
|
|
+
|
|
|
+ else {
|
|
|
+ if (ntohl(hdr->reqtype) == REQ_REL_NEW) {
|
|
|
+ flags = MSG_NEW_RELAY;
|
|
|
+
|
|
|
+ if (hdr->uid)
|
|
|
+ flags |= MSG_NEW_ONLY_VISIBLE;
|
|
|
+
|
|
|
+ msg = relay_get_msg(fd, hdr);
|
|
|
+ new_msg(msg, hdr->usrname, hdr->session, flags);
|
|
|
+
|
|
|
+ free(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ do_relay_bh(hdr);
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
int init_signal(void) {
|
|
|
struct sigaction act;
|
|
|
|
|
|
@@ -286,9 +330,9 @@ int main(int argc, char **argv) {
|
|
|
struct pollfd fds[2];
|
|
|
struct vcc_request *req;
|
|
|
struct vcc_relay_header *hdr;
|
|
|
- char *buf, *msg, *ip = VCC_DEFSERV;
|
|
|
+ char *buf, *ip = VCC_DEFSERV;
|
|
|
char key[64], iv[64];
|
|
|
- int n, size, port = VCC_PORT, flags;
|
|
|
+ int n, size, port = VCC_PORT;
|
|
|
|
|
|
(void) argc;
|
|
|
|
|
|
@@ -382,44 +426,7 @@ int main(int argc, char **argv) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- 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));
|
|
|
-
|
|
|
- /* classical process */
|
|
|
-
|
|
|
- if (ntohl(req->reqtype) == REQ_MSG_NEW) {
|
|
|
- if (ntohl(req->flags) & FLAG_ENCRYPTED)
|
|
|
- decrypt(req->msg);
|
|
|
-
|
|
|
- new_msg(req->msg, req->usrname, req->session, 0);
|
|
|
- }
|
|
|
-
|
|
|
- else
|
|
|
- do_bh(req);
|
|
|
-
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- else {
|
|
|
- if (ntohl(hdr->reqtype) == REQ_REL_NEW) {
|
|
|
- flags = MSG_NEW_RELAY;
|
|
|
-
|
|
|
- if (hdr->uid)
|
|
|
- flags |= MSG_NEW_ONLY_VISIBLE;
|
|
|
-
|
|
|
- msg = relay_get_msg(fd, hdr);
|
|
|
- new_msg(msg, hdr->usrname, hdr->session, flags);
|
|
|
-
|
|
|
- free(msg);
|
|
|
- }
|
|
|
-
|
|
|
- else
|
|
|
- do_relay_bh(hdr);
|
|
|
-
|
|
|
- continue;
|
|
|
- }
|
|
|
+ do_new_request(hdr);
|
|
|
}
|
|
|
}
|
|
|
|