瀏覽代碼

Execute session init/fini for plugins

Serj Kalichev 1 年之前
父節點
當前提交
6632305934
共有 2 個文件被更改,包括 21 次插入1 次删除
  1. 0 1
      klish/kscheme.h
  2. 21 0
      klish/ktp/ktpd_session.c

+ 0 - 1
klish/kscheme.h

@@ -31,7 +31,6 @@ bool_t kscheme_init_session_plugins(kscheme_t *scheme, kcontext_t *context,
 bool_t kscheme_fini_session_plugins(kscheme_t *scheme, kcontext_t *context,
 	faux_error_t *error);
 
-
 // PLUGINs
 faux_list_t *kscheme_plugins(const kscheme_t *scheme);
 bool_t kscheme_add_plugins(kscheme_t *scheme, kplugin_t *plugin);

+ 21 - 0
klish/ktp/ktpd_session.c

@@ -114,9 +114,20 @@ ktpd_session_t *ktpd_session_new(int sock, kscheme_t *scheme,
 
 void ktpd_session_free(ktpd_session_t *ktpd)
 {
+	kcontext_t *context = NULL;
+	kscheme_t *scheme = NULL;
+
 	if (!ktpd)
 		return;
 
+	// fini session for plugins
+	scheme = ksession_scheme(ktpd->session);
+	context = kcontext_new(KCONTEXT_TYPE_PLUGIN_FINI);
+	kcontext_set_session(context, ktpd->session);
+	kcontext_set_scheme(context, scheme);
+	kscheme_fini_session_plugins(scheme, context, NULL);
+	kcontext_free(context);
+
 	kexec_free(ktpd->exec);
 	ksession_free(ktpd->session);
 	faux_free(ktpd->hdr);
@@ -253,6 +264,8 @@ static bool_t ktpd_session_process_auth(ktpd_session_t *ktpd, faux_msg_t *msg)
 	socklen_t len = sizeof(ucred);
 	int sock = -1;
 	char *user = NULL;
+	kcontext_t *context = NULL;
+	kscheme_t *scheme = NULL;
 
 	assert(ktpd);
 	assert(msg);
@@ -275,6 +288,14 @@ static bool_t ktpd_session_process_auth(ktpd_session_t *ktpd, faux_msg_t *msg)
 	ksession_set_user(ktpd->session, user);
 	faux_str_free(user);
 
+	// init session for plugins
+	scheme = ksession_scheme(ktpd->session);
+	context = kcontext_new(KCONTEXT_TYPE_PLUGIN_INIT);
+	kcontext_set_session(context, ktpd->session);
+	kcontext_set_scheme(context, scheme);
+	kscheme_init_session_plugins(scheme, context, NULL);
+	kcontext_free(context);
+
 	// Prepare ACK message
 	ack = ktp_msg_preform(cmd, status);
 	faux_msg_add_param(ack, KTP_PARAM_RETCODE, &retcode8bit, 1);