PasswordSender.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file PasswordSender.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Object used to send a password to a {@link PasswordListener} server.
  25. */
  26. #ifndef BADVPN_CLIENT_PASSWORDSENDER_H
  27. #define BADVPN_CLIENT_PASSWORDSENDER_H
  28. #include <stdint.h>
  29. #include <misc/debugerror.h>
  30. #include <system/BSocket.h>
  31. #include <base/DebugObject.h>
  32. #include <flow/SinglePacketSender.h>
  33. #include <flow/PacketStreamSender.h>
  34. #include <flowextra/StreamSocketSink.h>
  35. #include <nspr_support/BPRFileDesc.h>
  36. #include <nspr_support/PRStreamSink.h>
  37. /**
  38. * Handler function called when the password is sent, or an error occurs
  39. * on the socket.
  40. * The object must be freed from within this handler.
  41. *
  42. * @param user as in {@link PasswordSender_Init}
  43. * @param is_error whether the password was sent successfuly, or an error
  44. * occured on the socket. 0 means password sent, 1 means error.
  45. */
  46. typedef void (*PasswordSender_handler) (void *user, int is_error);
  47. /**
  48. * Object used to send a password to a {@link PasswordListener} server.
  49. */
  50. typedef struct {
  51. uint64_t password;
  52. int ssl;
  53. union {
  54. BSocket *plain_sock;
  55. BPRFileDesc *ssl_bprfd;
  56. };
  57. PasswordSender_handler handler;
  58. void *user;
  59. FlowErrorDomain domain;
  60. SinglePacketSender sps;
  61. PacketStreamSender pss;
  62. union {
  63. StreamSocketSink plain;
  64. PRStreamSink ssl;
  65. } sink;
  66. DebugObject d_obj;
  67. DebugError d_err;
  68. } PasswordSender;
  69. /**
  70. * Initializes the object.
  71. *
  72. * @param o the object
  73. * @param password password to send
  74. * @param ssl whether we are connected to the server using TLS. Must be 1 or 0.
  75. * @param plain_sock if not using TLS, the socket to send the password through. Nothing else
  76. * must be using this socket for sending.
  77. * @param ssl_bprfd if using TLS, the {@link BPRFileDesc} object for the SSL file descriptor
  78. * to send the password through. Nothing else must be using this SSL socket
  79. * for sending.
  80. * @param handler handler to call when the password is sent or an error occurs
  81. * @param user value to pass to handler
  82. * @param reactor reactor we live in
  83. */
  84. void PasswordSender_Init (PasswordSender *o, uint64_t password, int ssl, BSocket *plain_sock, BPRFileDesc *ssl_bprfd, PasswordSender_handler handler, void *user, BReactor *reactor);
  85. /**
  86. * Frees the object.
  87. *
  88. * @param o the object
  89. */
  90. void PasswordSender_Free (PasswordSender *o);
  91. #endif