/share/dexatek/Service/HTTPd.h

https://bitbucket.org/DexaSamTsai/dxdoorcam_development · C Header · 174 lines · 106 code · 39 blank · 29 comment · 0 complexity · f80a3704bbfd37e4814e3d30fe96c142 MD5 · raw file

  1. /*!
  2. * @file HTTPd.h
  3. * @version 0.01
  4. * @author Sam Tsai
  5. */
  6. # ifndef __HTTP_D_H__
  7. # define __HTTP_D_H__
  8. //==========================================================================
  9. // Include File
  10. //==========================================================================
  11. # include "Headers.h"
  12. //==========================================================================
  13. // Type Define
  14. //==========================================================================
  15. //==========================================================================
  16. // Media Frame Type Declaration
  17. //==========================================================================
  18. //==========================================================================
  19. // Error Type Definition
  20. //==========================================================================
  21. //==========================================================================
  22. // Structure
  23. //==========================================================================
  24. # define MAX_RTSP_URI_LENGTH 256
  25. typedef enum {
  26. WEB_AUTH_TYPE_NONE = 0,
  27. WEB_AUTH_TYPE_DIGEST = 0x01,
  28. WEB_AUTH_TYPE_BASE64 = 0x02,
  29. WEB_AUTH_TYPE_MAX,
  30. } WEB_AUTH_TYPE;
  31. //==========================================================================
  32. // Type Define
  33. //==========================================================================
  34. # define NET_ERR_DISCONNECT -1
  35. # define NET_ERR_CONNECT_FAIL -2
  36. # define NET_ERR_CONNECT_TIMEOUT -3
  37. # define NET_ERR_SEND_DATA_FAIL -4
  38. # define NET_ERR_RECV_DATA_FAIL -5
  39. # define NET_ERR_DISCONNECT_FROM_REMOTE -6
  40. # define NET_ERR_STREAM_PARSE_ERROR -7
  41. # define NET_ERR_RECV_TIMEOUT -8
  42. # define NET_ERR_IGNORE -9
  43. # define NET_ERR_UNSUPPORT -10
  44. # define NET_ERR_HANDSHAKING_ERROR -11
  45. # define NET_ERR_NO_RESOURCE -51
  46. # define NET_ERR_INDEX_ERROR -52
  47. # define NET_ERR_HTTP_PARSER_FAIL -53
  48. # define NET_ERR_MAGIC_NUM_ERROR -54
  49. # define NET_ERR_BAD_REQUEST -400
  50. # define NET_ERR_UNAUTHORIZED -401
  51. # define NET_ERR_NOT_FOUND -404
  52. # define NET_ERR_UNSUPPORTED_MEDIA_TYPE -415
  53. # define NET_ERR_UNSUPPORTED_TRANSPORT -461
  54. # define NET_ERR_SERVICE_UNAVAILABLE -503
  55. # define NET_DISCONNECT -600
  56. //==========================================================================
  57. // Httpd
  58. //==========================================================================
  59. typedef void * HttpdHandle;
  60. typedef struct {
  61. char server_name[ 128 ];
  62. char root[ 128 ];
  63. char homepage[ 128 ];
  64. u16 http_port;
  65. u16 https_port;
  66. u32 auth_type;
  67. } Httpd_ServerContext;
  68. typedef struct {
  69. char url[ MAX_NAME_LENGTH + 4 ];
  70. void *cgi_handle;
  71. int auth_enabled;
  72. int ( *cgi_get ) ( HttpdHandle, int ); // httpd_handle, fd
  73. int ( *cgi_post ) ( HttpdHandle, int ); // httpd_handle, fd
  74. } Httpd_CGIContext;
  75. typedef enum {
  76. WEB_VIRTUAL_FILE_STATUS_NONE = 0,
  77. WEB_VIRTUAL_FILE_STATUS_DATA_IN,
  78. WEB_VIRTUAL_FILE_STATUS_CONN,
  79. WEB_VIRTUAL_FILE_STATUS_DISCONN,
  80. WEB_VIRTUAL_FILE_STATUS_MAX,
  81. } WEB_VIRTUAL_FILE_STATUS;
  82. typedef int ( *Webs_GetVFile ) ( void * ); // fd
  83. typedef int ( *Webs_PutVFile ) ( void *, u8 *, int ); // fd, data, size
  84. typedef int ( *Webs_CloseVFile ) ( void * ); // fd
  85. typedef struct {
  86. char filename[ 128 ];
  87. Webs_GetVFile get;
  88. Webs_CloseVFile get_close;
  89. Webs_PutVFile post;
  90. Webs_CloseVFile post_close;
  91. int auth_enabled;
  92. } web_vfile_t;
  93. typedef int ( *HTTP_RESULT ) ( void *, int, int ); // Custom Data, status, size,
  94. typedef struct {
  95. char *ip;
  96. u16 port;
  97. char *uri;
  98. char *host;
  99. char *username;
  100. char *password;
  101. void *custom;
  102. u8 *data;
  103. int data_len;
  104. u8 *post_data;
  105. int post_data_len;
  106. HTTP_RESULT result;
  107. } web_http_t;
  108. typedef struct {
  109. char *field;
  110. char *value;
  111. } web_param_t;
  112. //==========================================================================
  113. // APIs
  114. //==========================================================================
  115. extern const char *
  116. Httpd_GetHeaderField( HttpdHandle handle, char *field );
  117. extern const char *
  118. Httpd_GetCGIField( HttpdHandle handle, char *field );
  119. extern int
  120. Httpd_SendHttpHeader( HttpdHandle handle, char *url, int code );
  121. extern int
  122. Httpd_SendResponse( HttpdHandle handle, char *url, char *data, int size );
  123. extern int
  124. Httpd_RecvHttpHeader( HttpdHandle handle );
  125. extern int
  126. Httpd_RecvData( HttpdHandle handle, u8 **data );
  127. extern int
  128. Httpd_RegCGIService( Httpd_CGIContext *context );
  129. extern int
  130. Httpd_SetContext( Httpd_ServerContext *context );
  131. extern int
  132. Httpd_AddLocation( char *location );
  133. extern int
  134. Httpd_ServerStart( Httpd_ServerContext *context );
  135. # endif // __HTTP_D_H__