ktp.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /** @file ktp.h
  2. *
  3. * @brief Klish Transfer Protocol
  4. */
  5. #ifndef _klish_ktp_h
  6. #define _klish_ktp_h
  7. #include <faux/msg.h>
  8. #define KTP_MAGIC 0x4b545020
  9. #define KTP_MAJOR 0x01
  10. #define KTP_MINOR 0x00
  11. typedef enum {
  12. KTP_NULL = '\0',
  13. KTP_STDIN = 'i',
  14. KTP_STDOUT = 'o',
  15. KTP_STDERR = 'e',
  16. KTP_CMD = 'c',
  17. KTP_CMD_ACK = 'C',
  18. KTP_COMPLETION = 'v',
  19. KTP_COMPLETION_ACK = 'V',
  20. KTP_HELP = 'h',
  21. KTP_HELP_ACK = 'H',
  22. KTP_NOTIFICATION = 'n',
  23. KTP_AUTH = 'a',
  24. KTP_AUTH_ACK = 'A',
  25. KTP_KEEPALIVE = 'k',
  26. KTP_STDOUT_CLOSE = 'O',
  27. } ktp_cmd_e;
  28. typedef enum {
  29. KTP_PARAM_NULL = '\0',
  30. KTP_PARAM_LINE = 'L',
  31. KTP_PARAM_PREFIX = 'P', // Same as line but differ by meaning
  32. KTP_PARAM_PROMPT = '$', // Same as line but differ by meaning
  33. KTP_PARAM_HOTKEY = 'H', // <key>'\0'<cmd>
  34. KTP_PARAM_WINCH = 'W', // <width><space><height>
  35. KTP_PARAM_ERROR = 'E',
  36. KTP_PARAM_RETCODE = 'R',
  37. } ktp_param_e;
  38. // Status field. Bitmap
  39. typedef enum {
  40. KTP_STATUS_NONE = (uint32_t)0x00000000,
  41. KTP_STATUS_ERROR = (uint32_t)0x00000001,
  42. KTP_STATUS_INCOMPLETED = (uint32_t)0x00000002,
  43. KTP_STATUS_TTY_STDIN = (uint32_t)0x00000100, // Client's stdin is tty
  44. KTP_STATUS_TTY_STDOUT = (uint32_t)0x00000200, // Client's stdout is tty
  45. KTP_STATUS_TTY_STDERR = (uint32_t)0x00000400, // Client's stderr is tty
  46. KTP_STATUS_NEED_STDIN = (uint32_t)0x00001000, // Server's cmd need stdin
  47. KTP_STATUS_INTERACTIVE = (uint32_t)0x00002000, // Server's stdout is for tty
  48. KTP_STATUS_DRY_RUN = (uint32_t)0x00010000,
  49. KTP_STATUS_EXIT = (uint32_t)0x80000000,
  50. } ktp_status_e;
  51. #define KTP_STATUS_IS_ERROR(status) (status & KTP_STATUS_ERROR)
  52. #define KTP_STATUS_IS_INCOMPLETED(status) (status & KTP_STATUS_INCOMPLETED)
  53. #define KTP_STATUS_IS_TTY_STDIN(status) (status & KTP_STATUS_TTY_STDIN)
  54. #define KTP_STATUS_IS_TTY_STDOUT(status) (status & KTP_STATUS_TTY_STDOUT)
  55. #define KTP_STATUS_IS_TTY_STDERR(status) (status & KTP_STATUS_TTY_STDERR)
  56. #define KTP_STATUS_IS_NEED_STDIN(status) (status & KTP_STATUS_NEED_STDIN)
  57. #define KTP_STATUS_IS_INTERACTIVE(status) (status & KTP_STATUS_INTERACTIVE)
  58. #define KTP_STATUS_IS_DRY_RUN(status) (status & KTP_STATUS_DRY_RUN)
  59. #define KTP_STATUS_IS_EXIT(status) (status & KTP_STATUS_EXIT)
  60. #endif // _klish_ktp_h