Browse Source

ktp: ktp_msg_preform(), KTP_STATUSes

Serj Kalichev 2 years ago
parent
commit
2ca5738fc5
3 changed files with 27 additions and 4 deletions
  1. 9 0
      klish/ktp.h
  2. 16 0
      klish/ktp/ktp.c
  3. 2 4
      klish/ktp/ktpd_session.c

+ 9 - 0
klish/ktp.h

@@ -38,12 +38,21 @@ typedef enum {
 } ktp_param_e;
 
 
+// Status field. Bitmap
+#define KTP_STATUS_NONE  (uint32_t)0x00000000
+#define KTP_STATUS_ERROR (uint32_t)0x00000001
+
+#define KTP_STATUS_IS_ERROR(status) (status & KTP_STATUS_ERROR)
+
+
 C_DECL_BEGIN
 
 int ktp_connect_unix(const char *sun_path);
 void ktp_disconnect(int fd);
 int ktp_accept(int listen_sock);
 
+faux_msg_t *ktp_msg_preform(ktp_cmd_e cmd, uint32_t status);
+
 C_DECL_END
 
 #endif // _klish_ktp_h

+ 16 - 0
klish/ktp/ktp.c

@@ -11,6 +11,7 @@
 #include <sys/un.h>
 
 #include <faux/str.h>
+#include <faux/msg.h>
 #include <klish/ktp.h>
 
 #include "private.h"
@@ -63,3 +64,18 @@ int ktp_accept(int listen_sock)
 
 	return new_conn;
 }
+
+
+faux_msg_t *ktp_msg_preform(ktp_cmd_e cmd, uint32_t status)
+{
+	faux_msg_t *msg = NULL;
+
+	msg = faux_msg_new(KTP_MAGIC, KTP_MAJOR, KTP_MINOR);
+	assert(msg);
+	if (!msg)
+		return NULL;
+	faux_msg_set_cmd(msg, cmd);
+	faux_msg_set_status(msg, status);
+
+	return msg;
+}

+ 2 - 4
klish/ktp/ktpd_session.c

@@ -48,8 +48,7 @@ static bool_t ktpd_session_send_error(ktpd_session_t *session,
 	if (!session)
 		return BOOL_FALSE;
 
-	msg = faux_msg_new(KTP_MAGIC, KTP_MAJOR, KTP_MINOR);
-	faux_msg_set_cmd(msg, cmd);
+	msg = ktp_msg_preform(cmd, KTP_STATUS_ERROR);
 	if (error)
 		faux_msg_add_param(msg, KTP_PARAM_ERROR, error, strlen(error));
 	faux_msg_send_async(msg, session->async);
@@ -116,8 +115,7 @@ printf("LINE: %s\n", line);
 	}
 	kpargv_free(pargv);
 
-	emsg = faux_msg_new(KTP_MAGIC, KTP_MAJOR, KTP_MINOR);
-	faux_msg_set_cmd(emsg, KTP_CMD_ACK);
+	emsg = ktp_msg_preform(KTP_CMD_ACK, KTP_STATUS_NONE);
 	faux_msg_send_async(emsg, session->async);
 	faux_msg_free(emsg);