ktpd_session.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <unistd.h>
  6. #include <errno.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <sys/socket.h>
  11. #include <sys/un.h>
  12. #include <faux/str.h>
  13. #include <klish/ktp_session.h>
  14. #include "private.h"
  15. ktpd_session_t *ktpd_session_new(int sock)
  16. {
  17. ktpd_session_t *session = NULL;
  18. if (sock < 0)
  19. return NULL;
  20. session = faux_zmalloc(sizeof(*session));
  21. assert(session);
  22. if (!session)
  23. return NULL;
  24. // Init
  25. session->state = KTPD_SESSION_STATE_NOT_AUTHORIZED;
  26. session->net = faux_net_new();
  27. assert(session->net);
  28. faux_net_set_fd(session->net, sock);
  29. return session;
  30. }
  31. void ktpd_session_free(ktpd_session_t *session)
  32. {
  33. if (!session)
  34. return;
  35. faux_net_free(session->net);
  36. faux_free(session);
  37. }
  38. bool_t ktpd_session_connected(ktpd_session_t *session)
  39. {
  40. assert(session);
  41. if (!session)
  42. return BOOL_FALSE;
  43. if (KTPD_SESSION_STATE_DISCONNECTED == session->state)
  44. return BOOL_FALSE;
  45. return BOOL_TRUE;
  46. }
  47. int ktpd_session_get_socket(ktpd_session_t *session)
  48. {
  49. assert(session);
  50. if (!session)
  51. return BOOL_FALSE;
  52. return faux_net_get_fd(session->net);
  53. }
  54. #if 0
  55. static void ktpd_session_bad_socket(ktpd_session_t *session)
  56. {
  57. assert(session);
  58. if (!session)
  59. return;
  60. session->state = KTPD_SESSION_STATE_DISCONNECTED;
  61. }
  62. #endif