wac_download_http_receiver_api.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #ifndef NULLSOFT_WAC_DOWNLOAD_MANAGER_API_HTTP_RECEIVER_H
  2. #define NULLSOFT_WAC_DOWNLOAD_MANAGER_API_HTTP_RECEIVER_H
  3. #define PACKET_SIZE 16384
  4. #include "bfc/dispatch.h"
  5. #include "bfc/platform/types.h"
  6. #include "../wac_network/wac_network_dns_api.h"
  7. enum
  8. {
  9. HTTP_RECEIVER_STATUS_ERROR = -1,
  10. HTTP_RECEIVER_STATUS_CONNECTING = 0,
  11. HTTP_RECEIVER_STATUS_READING_HEADERS = 1,
  12. HTTP_RECEIVER_STATUS_READING_CONTENT = 2,
  13. };
  14. enum
  15. {
  16. HTTP_RECEIVER_RUN_ERROR = -1,
  17. HTTP_RECEIVER_RUN_OK = 0,
  18. HTTP_RECEIVER_RUN_CONNECTION_CLOSED = 1,
  19. };
  20. class NOVTABLE api_wac_download_manager_http_receiver : public Dispatchable
  21. {
  22. protected:
  23. api_wac_download_manager_http_receiver() {}
  24. ~api_wac_download_manager_http_receiver() {}
  25. public:
  26. void open( api_dns *dns = API_DNS_AUTODNS, size_t recvbufsize = PACKET_SIZE, const char *proxy = NULL );
  27. void addheader( const char *header );
  28. void AddHeaderValue( const char *header, const char *value );
  29. void reset_headers();
  30. char *getheader( char *headername );
  31. const char *getallheaders(); // double null terminated, null delimited list
  32. void connect( const char *url, int ver = 0, const char *requestmethod = "GET" );
  33. int run(); // see HTTPRECEIVER_RUN_* enum for return values
  34. int get_status(); // see HTTPRECEIVER_STATUS_* enum for return values
  35. int bytes_available();
  36. int get_bytes( void *buf, int len );
  37. int peek_bytes( void *buf, int len );
  38. uint64_t content_length();
  39. int getreplycode(); // returns 0 if none yet, otherwise returns http reply code.
  40. const char *GetReply();
  41. const char *geterrorstr();
  42. //api_connection *GetConnection();
  43. void AllowCompression();
  44. const char *get_url(); // might not be the same as what you passed in if a redirect happened
  45. void set_sendbufsize( int sendbufsize = PACKET_SIZE ); // call if you're going to POST or do any kind of bidirectional communications
  46. void set_accept_all_reply_codes();
  47. void set_persistent();
  48. DISPATCH_CODES
  49. {
  50. API_HTTPRECEIVER_OPEN = 10,
  51. API_HTTPRECEIVER_ADDHEADER = 20,
  52. API_HTTPRECEIVER_ADDHEADERVALUE = 30,
  53. API_HTTPRECEIVER_CONNECT = 40,
  54. API_HTTPRECEIVER_RUN = 50,
  55. API_HTTPRECEIVER_GETSTATUS = 60,
  56. API_HTTPRECEIVER_GETBYTESAVAILABLE = 70,
  57. API_HTTPRECEIVER_GETBYTES = 80,
  58. API_HTTPRECEIVER_PEEKBYTES = 90,
  59. API_HTTPRECEIVER_GETHEADER = 100,
  60. API_HTTPRECEIVER_GETCONTENTLENGTH = 110,
  61. API_HTTPRECEIVER_GETALLHEADERS = 120,
  62. API_HTTPRECEIVER_GETREPLYCODE = 130,
  63. API_HTTPRECEIVER_GETREPLY = 140,
  64. API_HTTPRECEIVER_GETERROR = 150,
  65. API_HTTPRECEIVER_GETCONNECTION = 160,
  66. API_HTTPRECEIVER_ALLOW_COMPRESSION = 170,
  67. API_HTTPRECEIVER_RESET_HEADERS = 180,
  68. API_HTTPRECEIVER_GET_URL = 190,
  69. API_HTTPRECEIVER_SET_SENDBUFSIZE = 200,
  70. API_HTTPRECEIVER_SET_ACCEPT_ALL_REPLY_CODES = 210,
  71. API_HTTPRECEIVER_SET_PERSISTENT = 220,
  72. };
  73. };
  74. inline void api_wac_download_manager_http_receiver::open( api_dns *dns, size_t recvbufsize, const char *proxy )
  75. {
  76. _voidcall( API_HTTPRECEIVER_OPEN, dns, recvbufsize, proxy );
  77. }
  78. inline void api_wac_download_manager_http_receiver::addheader( const char *header )
  79. {
  80. _voidcall( API_HTTPRECEIVER_ADDHEADER, header );
  81. }
  82. inline void api_wac_download_manager_http_receiver::AddHeaderValue( const char *header, const char *value )
  83. {
  84. _voidcall( API_HTTPRECEIVER_ADDHEADERVALUE, header, value );
  85. }
  86. inline void api_wac_download_manager_http_receiver::reset_headers()
  87. {
  88. _voidcall( API_HTTPRECEIVER_RESET_HEADERS );
  89. }
  90. inline char *api_wac_download_manager_http_receiver::getheader( char *headername )
  91. {
  92. return _call( API_HTTPRECEIVER_GETHEADER, (char *)NULL, headername );
  93. }
  94. inline const char *api_wac_download_manager_http_receiver::getallheaders()
  95. {
  96. return _call( API_HTTPRECEIVER_GETALLHEADERS, (const char *)NULL );
  97. }
  98. inline void api_wac_download_manager_http_receiver::connect( const char *url, int ver, const char *requestmethod )
  99. {
  100. _voidcall( API_HTTPRECEIVER_CONNECT, url, ver, requestmethod );
  101. }
  102. inline int api_wac_download_manager_http_receiver::run()
  103. {
  104. return _call( API_HTTPRECEIVER_RUN, (int)HTTP_RECEIVER_RUN_ERROR );
  105. }
  106. inline int api_wac_download_manager_http_receiver::get_status()
  107. {
  108. return _call( API_HTTPRECEIVER_GETSTATUS, (int)HTTP_RECEIVER_STATUS_ERROR );
  109. }
  110. inline int api_wac_download_manager_http_receiver::bytes_available()
  111. {
  112. return _call( API_HTTPRECEIVER_GETBYTESAVAILABLE, (int)0 );
  113. }
  114. inline int api_wac_download_manager_http_receiver::get_bytes( void *buf, int len )
  115. {
  116. return _call( API_HTTPRECEIVER_GETBYTES, (int)0, buf, len );
  117. }
  118. inline int api_wac_download_manager_http_receiver::peek_bytes( void *buf, int len )
  119. {
  120. return _call( API_HTTPRECEIVER_PEEKBYTES, (int)0, buf, len );
  121. }
  122. inline uint64_t api_wac_download_manager_http_receiver::content_length()
  123. {
  124. return _call( API_HTTPRECEIVER_GETCONTENTLENGTH, (uint64_t)0 );
  125. }
  126. inline int api_wac_download_manager_http_receiver::getreplycode()
  127. {
  128. return _call( API_HTTPRECEIVER_GETREPLYCODE, 0 );
  129. }
  130. inline const char *api_wac_download_manager_http_receiver::GetReply()
  131. {
  132. return _call( API_HTTPRECEIVER_GETREPLY, (const char *)NULL );
  133. }
  134. inline const char *api_wac_download_manager_http_receiver::geterrorstr()
  135. {
  136. return _call( API_HTTPRECEIVER_GETERROR, (const char *)NULL );
  137. }
  138. //inline api_connection *api_wac_download_manager_http_receiver::GetConnection()
  139. //{
  140. // return _call( API_HTTPRECEIVER_GETCONNECTION, (api_connection *)NULL );
  141. //}
  142. inline void api_wac_download_manager_http_receiver::AllowCompression()
  143. {
  144. _voidcall( API_HTTPRECEIVER_ALLOW_COMPRESSION );
  145. }
  146. inline const char *api_wac_download_manager_http_receiver::get_url()
  147. {
  148. return _call( API_HTTPRECEIVER_GET_URL, (const char *)0 );
  149. }
  150. inline void api_wac_download_manager_http_receiver::set_sendbufsize( int sendbufsize )
  151. {
  152. _voidcall( API_HTTPRECEIVER_SET_SENDBUFSIZE, sendbufsize );
  153. }
  154. inline void api_wac_download_manager_http_receiver::set_accept_all_reply_codes()
  155. {
  156. _voidcall( API_HTTPRECEIVER_SET_ACCEPT_ALL_REPLY_CODES );
  157. }
  158. inline void api_wac_download_manager_http_receiver::set_persistent()
  159. {
  160. _voidcall( API_HTTPRECEIVER_SET_PERSISTENT );
  161. }
  162. //////// {12475CD9-1BA3-4665-B395-F87DBF31E30F}
  163. //////static const GUID httpreceiverGUID =
  164. //////{ 0x12475cd9, 0x1ba3, 0x4665, { 0xb3, 0x95, 0xf8, 0x7d, 0xbf, 0x31, 0xe3, 0xf } };
  165. // {1683C6B7-1F6A-4C56-8496-525A3F5929D9}
  166. static const GUID httpreceiverGUID2 =
  167. { 0x1683c6b7, 0x1f6a, 0x4c56, { 0x84, 0x96, 0x52, 0x5a, 0x3f, 0x59, 0x29, 0xd9 } };
  168. #endif // !NULLSOFT_WAC_DOWNLOAD_MANAGER_API_HTTP_RECEIVER_H