ftp.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * lwftp.h : a lightweight FTP client using raw API of LWIP
  3. *
  4. * Copyright (c) 2014 GEZEDO
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  19. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  21. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  23. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  26. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. * OF SUCH DAMAGE.
  28. *
  29. * Author: Laurent GONZALEZ <lwip@gezedo.com>
  30. *
  31. */
  32. #ifndef __IAP_FTP_H__
  33. #define __IAP_FTP_H__
  34. #include "lwip/opt.h"
  35. #include "lwip/ip.h"
  36. #include "settings_api.h"
  37. enum lwftp_results {
  38. LWFTP_RESULT_OK=0,
  39. LWFTP_RESULT_ERR_UNKNOWN, /** Unknown error */
  40. LWFTP_RESULT_ERR_CONNECT, /** Connection to server failed */
  41. LWFTP_RESULT_ERR_HOSTNAME, /** Failed to resolve server hostname */
  42. LWFTP_RESULT_ERR_CLOSED, /** Connection unexpectedly closed by remote server */
  43. LWFTP_RESULT_ERR_TIMEOUT, /** Connection timed out (server didn't respond in time) */
  44. LWFTP_RESULT_ERR_SRVR_RESP /** Server responded with an unknown response code */
  45. };
  46. /** LWFTP control connection state */
  47. typedef enum {
  48. LWFTP_CLOSED=0,
  49. LWFTP_CONNECTED,
  50. LWFTP_USER_SENT,
  51. LWFTP_PASS_SENT,
  52. LWFTP_TYPE_SENT,
  53. LWFTP_PASV_SENT,
  54. LWFTP_RETR_SENT,
  55. LWFTP_STOR_SENT,
  56. LWFTP_XFERING,
  57. LWFTP_QUIT,
  58. LWFTP_QUIT_SENT,
  59. LWFTP_CLOSING,
  60. } lwftp_state_t;
  61. /** LWFTP session structure */
  62. typedef struct {
  63. // User interface
  64. FTP_Update_t *settings;
  65. void *data_handle;
  66. unsigned (*data_source)(void*, const char**, unsigned);
  67. unsigned (*data_sink)(void*, const char*, unsigned);
  68. void (*done_fn)(void*, int);
  69. // Internal data
  70. lwftp_state_t control_state;
  71. lwftp_state_t target_state;
  72. lwftp_state_t data_state;
  73. struct tcp_pcb *control_pcb;
  74. struct tcp_pcb *data_pcb;
  75. char *error;
  76. } lwftp_session_t;
  77. extern lwftp_session_t ftpcfg;
  78. // LWFTP API
  79. err_t lwftp_store(lwftp_session_t *s);
  80. void start_ftp_client(lwftp_session_t *s);
  81. char *get_ftp_progress(void);
  82. #endif