ソースを参照

vcc: use relay as the method of -ls, and create interfaces.h

intirain 4 年 前
親
コミット
3cb81d304d
13 ファイル変更、130 行追加、90 行削除
  1. 2 2
      Makefile
  2. 7 30
      cmd.c
  3. 1 1
      crypt.c
  4. 77 0
      include/vcc/interfaces.h
  5. 2 2
      include/vcc/version.h
  6. 1 1
      intiauth.c
  7. 14 28
      main.c
  8. 1 0
      plugins.c
  9. 1 2
      plugins/robot/robot.c
  10. 1 2
      plugins/script/script.c
  11. 1 5
      pretty.c
  12. 1 6
      robot.c
  13. 21 11
      vcc.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 22
-VCC_PATCH 		= 1
+VCC_MINOR 		= 23
+VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 
 # change this to '/usr/share/' or '/opt/vcc/' etc

+ 7 - 30
cmd.c

@@ -41,7 +41,7 @@
 #include <vcc/plugin.h>
 #include <vcc/version.h>
 #include <vcc/pretty.h>
-
+#include <vcc/interfaces.h>
 
 
 int do_cmd_help(int, char **);
@@ -64,25 +64,6 @@ int do_cmd_prem(int, char **);
 int do_cmd_ml(int, char **);
 int do_cmd_rl(int, char **);
 
-int handle_command(char *);
-int read_msg(struct vcc_request *);
-int vcc_create_session(char *name);
-int get_user_info(char *usrname);
-int incr_score(char *username, int incr);
-int send_msg(char *msg, char *s);
-int send_msg_encrypted(char *msg, char *s);
-int encrypt(char *s);
-
-extern struct klist_node banned_people;
-extern char usrname[];
-extern int rate;
-extern int current_sid;
-extern int self_level;
-
-int get_users(void);
-int get_sessions(void);
-int join_session(int sid);
-int send_relay_msg(const char *, const char *, const char *);
 
 int did_warn = 0;
 
@@ -259,23 +240,19 @@ int do_cmd_ls(int argc, char **argv) {
 }
 
 
-int do_cmd_ls_bh(struct vcc_request *req) {
+int do_cmd_ls_bh(struct vcc_relay_header *req) {
 	int n, i;
-
-	n = ntohl(req->uid);
+	char *msg;
 
 	clear_line();
-
-	if (unlikely(ntohl(req->reqtype) != REQ_CTL_USRS)) {
-		fprintf(stderr, "--- do_cmd_ls_bh: bad package. \n");
-
-		return 1;
-	}
+	n = ntohl(req->uid);
+	msg = relay_get_msg(fd, req);
 
 	for (i = 0; i < n; i++) 
-		printf("%s\n", req->msg + i * USRNAME_SIZE);
+		printf("%s\n", msg + i * USRNAME_SIZE);
 
 	pretty_prompt(usrname);
+	free(msg);
 
 	return 0;
 }

+ 1 - 1
crypt.c

@@ -29,7 +29,7 @@
 #include <vcc/plugin.h>
 #include <vcc/version.h>
 #include <vcc/pretty.h>
-
+#include <vcc/interfaces.h>
 
 /* maybe because of that i'm not good at crypting (in fact, i even don't 
  * know eular etc. ), i think the libgcrypt is the most ****ingest library 

+ 77 - 0
include/vcc/interfaces.h

@@ -0,0 +1,77 @@
+/* vcc/include/vcc/interfaces.h 
+ * 
+ * This file is part of vcc. 
+ * 
+ * vcc 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. 
+ * 
+ * vcc 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 vcc. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#ifndef __VCC_INTERFACES_H
+#define __VCC_INTERFACES_H
+
+#include <sys/types.h>
+#include <vcc/vcc.h>
+
+int vcc_login(char *, char *);
+int do_intiauth(void);
+
+int send_msg(const char *msg, const char *usrname);
+int send_msg_encrypted(const char *msg, const char *s);
+int send_relay_msg(const char *, const char *, const char *);
+int read_msg(struct vcc_request *buf);
+char *relay_get_msg(int fd, struct vcc_relay_header *);
+
+int is_user_banned(char *);
+
+int show_algo_info(void);
+int crypt_init(void *key, void *iv);
+int encrypt(char *);
+int decrypt(char *);
+
+int do_cmd(char *s);
+int do_bh(struct vcc_request *);
+int do_relay_bh(struct vcc_relay_header *);
+int do_cmd_lself(int, char **);
+
+int init_socket(const char *server_addr, int server_port);
+int handle_command(char *);
+int do_handle_command(char *);
+
+int get_user_info(char *usrname);
+int get_users(void);
+int incr_score(char *username, int incr);
+int vcc_create_session(char *name);
+int get_sessions(void);
+int join_session(int sid);
+
+int robot_new_msg(struct vcc_request *);
+
+int vcc_login_bh(struct vcc_request *);
+int do_cmd_ls_bh(struct vcc_relay_header *);
+int do_cmd_lsse_bh(struct vcc_request *);
+int do_cmd_uinfo_bh(struct vcc_request *);
+int do_cmd_incr_bh(struct vcc_request *);
+
+extern int fd;
+extern struct klist_node banned_people;
+extern char usrname[];
+extern int rate;
+extern int current_sid;
+extern int self_level;
+extern int crypt_disabled;
+
+#endif
+

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.22.1 Thu Jun  2 09:14:28 PM CST 2022 root"
-#define VCC_SEMVER "vcc 1.22.1-rc "
+#define VCC_VERSION "VCC 1.23.0 Fri Jun  3 05:09:58 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.23.0-rc "

+ 1 - 1
intiauth.c

@@ -29,9 +29,9 @@
 #include <vcc/vcc.h>
 #include <vcc/plugin.h>
 #include <vcc/version.h>
+#include <vcc/interfaces.h>
 
 
-extern char usrname[];
 int ia_login(char *session);
 
 int do_intiauth(void) {

+ 14 - 28
main.c

@@ -46,30 +46,12 @@
 #include <vcc/pretty.h>
 #include <vcc/defserv.h>
 #include <vcc/config.h>
+#include <vcc/interfaces.h>
 
 
 /* we tried to use libreadline, but after using that, we feel strange 
  * because... because of what? i don't know. */
 
-int vcc_login(char *, char *);
-
-int send_msg(const char *msg, const char *usrname);
-int read_msg(struct vcc_request *buf);
-int get_msgs(void);
-int is_user_banned(char *);
-char *relay_get_msg(int fd, struct vcc_relay_header *);
-int do_intiauth(void);
-
-int show_algo_info(void);
-int crypt_init(void *key, void *iv);
-int encrypt(char *);
-int decrypt(char *);
-
-int do_cmd(char *s);
-int do_bh(struct vcc_request *);
-int do_cmd_lself(int, char **);
-
-int init_socket(const char *server_addr, int server_port);
 
 int 		fd;
 
@@ -84,9 +66,6 @@ int 		mode = MODE_NORMAL;
 char usrname[USRNAME_SIZE];
 struct klist_node banned_people = KLIST_NODE_INIT(&banned_people);
 
-extern int crypt_disabled;
-extern int current_sid;
-
 static char const *help_msg = {
 	"Usage: vcc [-auprh] [server]\n"
 	"Options: \n"
@@ -441,15 +420,22 @@ int main(int argc, char **argv) {
 			}
 
 			else {
-				flags = MSG_NEW_RELAY;
+				if (ntohl(hdr->reqtype) == REQ_REL_NEW) {
+					flags = MSG_NEW_RELAY;
 
-				if (hdr->uid) 
-					flags |= MSG_NEW_ONLY_VISIBLE;
+					if (hdr->uid) 
+						flags |= MSG_NEW_ONLY_VISIBLE;
 
-				msg = relay_get_msg(fd, hdr);
-				new_msg(msg, hdr->usrname, hdr->session, flags);
+					msg = relay_get_msg(fd, hdr);
+					new_msg(msg, hdr->usrname, hdr->session, flags);
 
-				free(msg);
+					free(msg);
+				}
+
+				else 
+					do_relay_bh(hdr);
+
+				continue;
 			}
 		}
 	}

+ 1 - 0
plugins.c

@@ -40,6 +40,7 @@
 #include <vcc/plugin.h>
 #include <vcc/version.h>
 #include <vcc/pretty.h>
+#include <vcc/interfaces.h>
 
 
 extern struct plugin plg_hello, plg_robot, plg_m4, plg_script;

+ 1 - 2
plugins/robot/robot.c

@@ -27,10 +27,9 @@
 #include <vcc/pretty.h>
 #include <vcc/plugin.h>
 #include <vcc/version.h>
+#include <vcc/interfaces.h>
 
 
-int do_bh(struct vcc_request *);
-int send_msg(char *, char *);
 int robot_lslcn(char *s);
 int do_robot_cmd(char *s);
 

+ 1 - 2
plugins/script/script.c

@@ -27,10 +27,9 @@
 #include <vcc/pretty.h>
 #include <vcc/plugin.h>
 #include <vcc/version.h>
-
+#include <vcc/interfaces.h>
 
 int do_cmd_if(int argc, char **argv);
-int handle_command(char *s);
 
 struct cmdtable script_cmdtab[] = {
 	{ "-if", do_cmd_if, "-if condition then ... else ..." }, 

+ 1 - 5
pretty.c

@@ -28,12 +28,8 @@
 #include <vcc/version.h>
 #include <vcc/pretty.h>
 #include <vcc/plugin.h>
+#include <vcc/interfaces.h>
 
-extern int current_sid;
-extern char *usrname;
-
-/* main.c */
-void do_handle_command(char *);
 
 struct theme theme_def = {
 	.usrname = {

+ 1 - 6
robot.c

@@ -40,12 +40,7 @@
 #include <vcc/plugin.h>
 #include <vcc/version.h>
 #include <vcc/pretty.h>
-
-
-extern int fd;
-int vcc_login(char *, char *);
-int robot_new_msg(struct vcc_request *);
-
+#include <vcc/interfaces.h>
 
 int becomes_daemon(void) {
 	int pid, fd;

+ 21 - 11
vcc.c

@@ -38,21 +38,12 @@
 #include <vcc/vcc.h>
 #include <vcc/plugin.h>
 #include <vcc/version.h>
+#include <vcc/interfaces.h>
 
 #define clear_req(req) 	memset(req, 0, sizeof(*req))
 
-extern struct klist_node banned_people;
-extern int fd;
-extern char usrname[];
-
 int current_sid = 0;
 
-int vcc_login_bh(struct vcc_request *);
-int do_cmd_ls_bh(struct vcc_request *);
-int do_cmd_lsse_bh(struct vcc_request *);
-int do_cmd_uinfo_bh(struct vcc_request *);
-int do_cmd_incr_bh(struct vcc_request *);
-
 
 int init_socket(const char *server_addr, int server_port) {
 	struct sockaddr_in addr, server;
@@ -234,10 +225,13 @@ int do_bh(struct vcc_request *req) {
 
 		break;
 
+#if 0
+		/* obsolete, see do_relay_bh() */
 	case REQ_CTL_USRS:
 		do_cmd_ls_bh(req);
 
 		break;
+#endif
 
 	case REQ_CTL_SESS:
 		do_cmd_lsse_bh(req);
@@ -255,7 +249,23 @@ int do_bh(struct vcc_request *req) {
 		break;
 
 	default:
-//		fprintf(stderr, "*** unexpected packet type %d. \n", ntohl(req->reqtype));
+		fprintf(stderr, "*** unexpected packet type %d. \n", ntohl(req->reqtype));
+
+		break;
+	}
+
+	return 0;
+}
+
+int do_relay_bh(struct vcc_relay_header *req) {
+	switch (ntohl(req->reqtype)) {
+	case REQ_CTL_USRS:
+		do_cmd_ls_bh(req);
+
+		break;
+
+	default:
+		fprintf(stderr, "*** unexpected packet type %d. \n", ntohl(req->reqtype));
 
 		break;
 	}