Browse Source

session: Fix session assertion

Serj Kalichev 2 years ago
parent
commit
42b42cf226
4 changed files with 13 additions and 2 deletions
  1. 6 1
      bin/klishd/klishd.c
  2. 4 0
      klish/ksession.h
  3. 1 1
      klish/ksession/ksession.c
  4. 2 0
      klish/ksession/ksession_parse.c

+ 6 - 1
bin/klishd/klishd.c

@@ -38,6 +38,7 @@
 #include <klish/kscheme.h>
 #include <klish/ischeme.h>
 #include <klish/kcontext.h>
+#include <klish/ksession.h>
 #include <klish/kdb.h>
 
 #include "private.h"
@@ -77,6 +78,7 @@ int main(int argc, char **argv)
 	int listen_unix_sock = -1;
 	ktpd_clients_t *clients = NULL;
 	kscheme_t *scheme = NULL;
+	ksession_t *session = NULL;
 	faux_error_t *error = faux_error_new();
 	faux_ini_t *config = NULL;
 
@@ -169,9 +171,12 @@ int main(int argc, char **argv)
 	kdb_deploy_scheme(deploy_db, scheme);
 	kdb_fini(deploy_db);
 	kdb_free(deploy_db);
-goto err; // Test purposes
 	}
 
+	session = ksession_new(scheme, NULL);
+	ksession_parse_line(session, "cmd m1 e1");
+goto err; // Test purposes
+
 	// Listen socket
 	syslog(LOG_DEBUG, "Create listen UNIX socket: %s\n", opts->unix_socket_path);
 	listen_unix_sock = create_listen_unix_sock(opts->unix_socket_path);

+ 4 - 0
klish/ksession.h

@@ -7,6 +7,7 @@
 #define _klish_ksession_h
 
 #include <klish/kscheme.h>
+#include <klish/kpath.h>
 
 #define KSESSION_STARTING_ENTRY "main"
 
@@ -21,6 +22,9 @@ void ksession_free(ksession_t *session);
 const kscheme_t *ksession_scheme(const ksession_t *session);
 kpath_t *ksession_path(const ksession_t *session);
 
+kpargv_t *ksession_parse_line(ksession_t *session, const char *line);
+
+
 C_DECL_END
 
 #endif // _klish_ksession_h

+ 1 - 1
klish/ksession/ksession.c

@@ -49,7 +49,7 @@ ksession_t *ksession_new(const kscheme_t *scheme, const char *start_entry)
 	else
 		entry_to_search = KSESSION_STARTING_ENTRY;
 	entry = kscheme_find_entry_by_path(scheme, entry_to_search);
-	if (entry)
+	if (!entry)
 		return NULL; // Can't find starting entry
 
 	session = faux_zmalloc(sizeof(*session));

+ 2 - 0
klish/ksession/ksession_parse.c

@@ -187,6 +187,8 @@ kpargv_t *ksession_parse_line(ksession_t *session, const char *line)
 
 	ksession_parse_arg(current_entry, &argv_iter, pargv);
 
+	printf("KKKKKKKKK %ld\n", kpargv_pargs_len(pargv));
+
 	if (kpargv_pargs_is_empty(pargv)) {
 		kpargv_free(pargv);
 		return NULL;