PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext/stream/ext_stream.h

https://gitlab.com/alvinahmadov2/hhvm
C Header | 290 lines | 219 code | 45 blank | 26 comment | 0 complexity | 3ceadd9311c3092bbfc4617c12320a82 MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010-2015 Facebook, Inc. (http://www.facebook.com) |
  6. | Copyright (c) 1997-2010 The PHP Group |
  7. +----------------------------------------------------------------------+
  8. | This source file is subject to version 3.01 of the PHP license, |
  9. | that is bundled with this package in the file LICENSE, and is |
  10. | available through the world-wide-web at the following url: |
  11. | http://www.php.net/license/3_01.txt |
  12. | If you did not receive a copy of the PHP license and are unable to |
  13. | obtain it through the world-wide-web, please send a note to |
  14. | license@php.net so we can mail you a copy immediately. |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifndef incl_HPHP_EXT_STREAM_H_
  18. #define incl_HPHP_EXT_STREAM_H_
  19. #include "hphp/runtime/ext/extension.h"
  20. namespace HPHP {
  21. const int64_t k_PSFS_ERR_FATAL = 0;
  22. const int64_t k_PSFS_FEED_ME = 1;
  23. const int64_t k_PSFS_FLAG_FLUSH_CLOSE = 2;
  24. const int64_t k_PSFS_FLAG_FLUSH_INC = 1;
  25. const int64_t k_PSFS_FLAG_NORMAL = 0;
  26. const int64_t k_PSFS_PASS_ON = 2;
  27. const int64_t k_STREAM_CLIENT_CONNECT = 4;
  28. const int64_t k_STREAM_CLIENT_ASYNC_CONNECT = 2;
  29. const int64_t k_STREAM_CLIENT_PERSISTENT = 1;
  30. const int64_t k_STREAM_META_TOUCH = 1;
  31. const int64_t k_STREAM_META_OWNER_NAME = 2;
  32. const int64_t k_STREAM_META_OWNER = 3;
  33. const int64_t k_STREAM_META_GROUP_NAME = 4;
  34. const int64_t k_STREAM_META_GROUP = 5;
  35. const int64_t k_STREAM_META_ACCESS = 6;
  36. const int64_t k_STREAM_BUFFER_NONE = 0; /* unbuffered */
  37. const int64_t k_STREAM_BUFFER_LINE = 1; /* line buffered */
  38. const int64_t k_STREAM_BUFFER_FULL = 2; /* fully buffered */
  39. const int64_t k_STREAM_SERVER_BIND = 4;
  40. const int64_t k_STREAM_SERVER_LISTEN = 8;
  41. const int64_t k_STREAM_CRYPTO_METHOD_SSLv23_CLIENT = 7;
  42. const int64_t k_STREAM_CRYPTO_METHOD_SSLv23_SERVER = 6;
  43. const int64_t k_STREAM_CRYPTO_METHOD_SSLv2_CLIENT = 3;
  44. const int64_t k_STREAM_CRYPTO_METHOD_SSLv2_SERVER = 2;
  45. const int64_t k_STREAM_CRYPTO_METHOD_SSLv3_CLIENT = 5;
  46. const int64_t k_STREAM_CRYPTO_METHOD_SSLv3_SERVER = 4;
  47. const int64_t k_STREAM_CRYPTO_METHOD_TLS_CLIENT = 57;
  48. const int64_t k_STREAM_CRYPTO_METHOD_TLS_SERVER = 56;
  49. const int64_t k_STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT = 9;
  50. const int64_t k_STREAM_CRYPTO_METHOD_TLSv1_0_SERVER = 8;
  51. const int64_t k_STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT = 17;
  52. const int64_t k_STREAM_CRYPTO_METHOD_TLSv1_1_SERVER = 16;
  53. const int64_t k_STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT = 33;
  54. const int64_t k_STREAM_CRYPTO_METHOD_TLSv1_2_SERVER = 32;
  55. const int64_t k_STREAM_CRYPTO_METHOD_ANY_CLIENT = 63;
  56. const int64_t k_STREAM_CRYPTO_METHOD_ANY_SERVER = 62;
  57. const int64_t k_STREAM_ENFORCE_SAFE_MODE = 4;
  58. const int64_t k_STREAM_IGNORE_URL = 2;
  59. const int64_t k_STREAM_IPPROTO_ICMP = 1;
  60. const int64_t k_STREAM_IPPROTO_IP = 0;
  61. const int64_t k_STREAM_IPPROTO_RAW = 255;
  62. const int64_t k_STREAM_IPPROTO_TCP = 6;
  63. const int64_t k_STREAM_IPPROTO_UDP = 17;
  64. const int64_t k_STREAM_IS_URL = 1;
  65. const int64_t k_STREAM_MKDIR_RECURSIVE = 1;
  66. const int64_t k_STREAM_MUST_SEEK = 16;
  67. const int64_t k_STREAM_NOTIFY_AUTH_REQUIRED = 3;
  68. const int64_t k_STREAM_NOTIFY_AUTH_RESULT = 10;
  69. const int64_t k_STREAM_NOTIFY_COMPLETED = 8;
  70. const int64_t k_STREAM_NOTIFY_CONNECT = 2;
  71. const int64_t k_STREAM_NOTIFY_FAILURE = 9;
  72. const int64_t k_STREAM_NOTIFY_FILE_SIZE_IS = 5;
  73. const int64_t k_STREAM_NOTIFY_MIME_TYPE_IS = 4;
  74. const int64_t k_STREAM_NOTIFY_PROGRESS = 7;
  75. const int64_t k_STREAM_NOTIFY_REDIRECTED = 6;
  76. const int64_t k_STREAM_NOTIFY_RESOLVE = 1;
  77. const int64_t k_STREAM_NOTIFY_SEVERITY_ERR = 2;
  78. const int64_t k_STREAM_NOTIFY_SEVERITY_INFO = 0;
  79. const int64_t k_STREAM_NOTIFY_SEVERITY_WARN = 1;
  80. const int64_t k_STREAM_OOB = 1;
  81. const int64_t k_STREAM_PEEK = 2;
  82. const int64_t k_STREAM_PF_INET = 2;
  83. const int64_t k_STREAM_PF_INET6 = 10;
  84. const int64_t k_STREAM_PF_UNIX = 1;
  85. const int64_t k_STREAM_REPORT_ERRORS = 8;
  86. const int64_t k_STREAM_SHUT_RD = 0;
  87. const int64_t k_STREAM_SHUT_RDWR = 2;
  88. const int64_t k_STREAM_SHUT_WR = 1;
  89. const int64_t k_STREAM_SOCK_DGRAM = 2;
  90. const int64_t k_STREAM_SOCK_RAW = 3;
  91. const int64_t k_STREAM_SOCK_RDM = 4;
  92. const int64_t k_STREAM_SOCK_SEQPACKET = 5;
  93. const int64_t k_STREAM_SOCK_STREAM = 1;
  94. const int64_t k_STREAM_URL_STAT_LINK = 1;
  95. const int64_t k_STREAM_URL_STAT_QUIET = 2;
  96. const int64_t k_STREAM_USE_PATH = 1;
  97. ///////////////////////////////////////////////////////////////////////////////
  98. // stream context
  99. struct StreamContext final : ResourceData {
  100. DECLARE_RESOURCE_ALLOCATION_NO_SWEEP(StreamContext);
  101. CLASSNAME_IS("stream-context")
  102. const String& o_getClassNameHook() const override { return classnameof(); }
  103. StreamContext(const Array& options, const Array& params)
  104. : m_options(options), m_params(params) {
  105. }
  106. static bool validateOptions(const Variant& options);
  107. void setOption(const String& wrapper, const String& option,
  108. const Variant& value);
  109. void mergeOptions(const Array& options);
  110. Array getOptions() const;
  111. static bool validateParams(const Variant& params);
  112. void mergeParams(const Array& params);
  113. Array getParams() const;
  114. /*void vscan(IMarker& mark) const override {
  115. mark(m_options);
  116. mark(m_params);
  117. }*/
  118. private:
  119. static StaticString s_options_key;
  120. static StaticString s_notification_key;
  121. Array m_options;
  122. Array m_params;
  123. };
  124. Variant HHVM_FUNCTION(stream_context_create,
  125. const Variant& options = null_variant,
  126. const Variant& params = null_variant);
  127. Variant HHVM_FUNCTION(stream_context_get_options,
  128. const Resource& stream_or_context);
  129. bool HHVM_FUNCTION(stream_context_set_option,
  130. const Variant& stream_or_context,
  131. const Variant& wrapper,
  132. const Variant& option = null_variant,
  133. const Variant& value = null_variant);
  134. Variant HHVM_FUNCTION(stream_context_get_default,
  135. const Variant& options /* = null_variant */);
  136. Variant HHVM_FUNCTION(stream_context_get_params,
  137. const Resource& stream_or_context);
  138. bool HHVM_FUNCTION(stream_context_set_params,
  139. const Resource& stream_or_context,
  140. const Array& params);
  141. ///////////////////////////////////////////////////////////////////////////////
  142. Variant HHVM_FUNCTION(stream_copy_to_stream,
  143. const Resource& source,
  144. const Resource& dest,
  145. int maxlength = -1,
  146. int offset = 0);
  147. Variant HHVM_FUNCTION(stream_get_contents,
  148. const Resource& handle,
  149. int maxlen = -1,
  150. int offset = -1);
  151. Variant HHVM_FUNCTION(stream_get_line,
  152. const Resource& handle,
  153. int length = 0,
  154. const Variant& ending = null_variant);
  155. Variant HHVM_FUNCTION(stream_get_meta_data,
  156. const Resource& stream);
  157. Array HHVM_FUNCTION(stream_get_transports);
  158. Array HHVM_FUNCTION(stream_get_wrappers);
  159. bool HHVM_FUNCTION(stream_is_local,
  160. const Variant& stream_or_url);
  161. bool HHVM_FUNCTION(stream_register_wrapper,
  162. const String& protocol,
  163. const String& classname,
  164. int flags);
  165. bool HHVM_FUNCTION(stream_wrapper_register,
  166. const String& protocol,
  167. const String& classname,
  168. int flags);
  169. bool HHVM_FUNCTION(stream_wrapper_restore,
  170. const String& protocol);
  171. bool HHVM_FUNCTION(stream_wrapper_unregister,
  172. const String& protocol);
  173. Variant HHVM_FUNCTION(stream_resolve_include_path,
  174. const String& filename,
  175. const Variant& context = null_variant);
  176. Variant HHVM_FUNCTION(stream_select,
  177. VRefParam read,
  178. VRefParam write,
  179. VRefParam except,
  180. const Variant& vtv_sec,
  181. int tv_usec = 0);
  182. Object HHVM_FUNCTION(stream_await,
  183. const Resource& stream,
  184. int64_t events,
  185. double timeout = 0.0);
  186. bool HHVM_FUNCTION(stream_set_blocking,
  187. const Resource& stream,
  188. int mode);
  189. bool HHVM_FUNCTION(stream_set_timeout,
  190. const Resource& stream,
  191. int seconds,
  192. int microseconds = 0);
  193. int64_t HHVM_FUNCTION(stream_set_write_buffer,
  194. const Resource& stream,
  195. int buffer);
  196. int64_t HHVM_FUNCTION(set_file_buffer,
  197. const Resource& stream,
  198. int buffer);
  199. ///////////////////////////////////////////////////////////////////////////////
  200. // stream sockets: ext_socket has better implementation of socket functions
  201. Variant HHVM_FUNCTION(stream_socket_accept,
  202. const Resource& server_socket,
  203. double timeout = -1.0,
  204. VRefParam peername = uninit_null());
  205. Variant HHVM_FUNCTION(stream_socket_server,
  206. const String& local_socket,
  207. VRefParam errnum = uninit_null(),
  208. VRefParam errstr = uninit_null(),
  209. int flags = k_STREAM_SERVER_BIND|k_STREAM_SERVER_LISTEN,
  210. const Variant& context = null_variant);
  211. Variant HHVM_FUNCTION(stream_socket_client,
  212. const String& remote_socket,
  213. VRefParam errnum = uninit_null(),
  214. VRefParam errstr = uninit_null(),
  215. double timeout = -1.0,
  216. int flags = 0,
  217. const Variant& context = null_variant);
  218. bool HHVM_FUNCTION(stream_socket_enable_crypto,
  219. const Resource& socket,
  220. bool enable,
  221. int cryptotype,
  222. const Variant& sessionstream);
  223. Variant HHVM_FUNCTION(stream_socket_get_name,
  224. const Resource& handle,
  225. bool want_peer);
  226. Variant HHVM_FUNCTION(stream_socket_pair,
  227. int domain,
  228. int type,
  229. int protocol);
  230. Variant HHVM_FUNCTION(stream_socket_recvfrom,
  231. const Resource& socket,
  232. int length,
  233. int flags = 0,
  234. VRefParam address = uninit_null());
  235. Variant HHVM_FUNCTION(stream_socket_sendto,
  236. const Resource& socket,
  237. const String& data,
  238. int flags = 0,
  239. const Variant& address = null_variant);
  240. bool HHVM_FUNCTION(stream_socket_shutdown,
  241. const Resource& stream,
  242. int how);
  243. ///////////////////////////////////////////////////////////////////////////////
  244. }
  245. #endif // incl_HPHP_EXT_STREAM_H_