php_stream_context.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Wez Furlong <wez@thebrainroom.com> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* Stream context and status notification related definitions */
  19. /* callback for status notifications */
  20. typedef void (*php_stream_notification_func)(php_stream_context *context,
  21. int notifycode, int severity,
  22. char *xmsg, int xcode,
  23. size_t bytes_sofar, size_t bytes_max,
  24. void * ptr);
  25. #define PHP_STREAM_NOTIFIER_PROGRESS 1
  26. /* Attempt to fetch context from the zval passed,
  27. If no context was passed, use the default context
  28. The default context has not yet been created, do it now. */
  29. #define php_stream_context_from_zval(zcontext, nocontext) ( \
  30. (zcontext) ? zend_fetch_resource_ex(zcontext, "Stream-Context", php_le_stream_context()) : \
  31. (nocontext) ? NULL : \
  32. FG(default_context) ? FG(default_context) : \
  33. (FG(default_context) = php_stream_context_alloc()) )
  34. #define php_stream_context_to_zval(context, zval) { ZVAL_RES(zval, (context)->res); GC_ADDREF((context)->res); }
  35. typedef struct _php_stream_notifier php_stream_notifier;
  36. struct _php_stream_notifier {
  37. php_stream_notification_func func;
  38. void (*dtor)(php_stream_notifier *notifier);
  39. zval ptr;
  40. int mask;
  41. size_t progress, progress_max; /* position for progress notification */
  42. };
  43. struct _php_stream_context {
  44. php_stream_notifier *notifier;
  45. zval options; /* hash keyed by wrapper family or specific wrapper */
  46. zend_resource *res; /* used for auto-cleanup */
  47. };
  48. BEGIN_EXTERN_C()
  49. PHPAPI void php_stream_context_free(php_stream_context *context);
  50. PHPAPI php_stream_context *php_stream_context_alloc(void);
  51. PHPAPI zval *php_stream_context_get_option(php_stream_context *context,
  52. const char *wrappername, const char *optionname);
  53. PHPAPI int php_stream_context_set_option(php_stream_context *context,
  54. const char *wrappername, const char *optionname, zval *optionvalue);
  55. PHPAPI php_stream_notifier *php_stream_notification_alloc(void);
  56. PHPAPI void php_stream_notification_free(php_stream_notifier *notifier);
  57. END_EXTERN_C()
  58. /* not all notification codes are implemented */
  59. #define PHP_STREAM_NOTIFY_RESOLVE 1
  60. #define PHP_STREAM_NOTIFY_CONNECT 2
  61. #define PHP_STREAM_NOTIFY_AUTH_REQUIRED 3
  62. #define PHP_STREAM_NOTIFY_MIME_TYPE_IS 4
  63. #define PHP_STREAM_NOTIFY_FILE_SIZE_IS 5
  64. #define PHP_STREAM_NOTIFY_REDIRECTED 6
  65. #define PHP_STREAM_NOTIFY_PROGRESS 7
  66. #define PHP_STREAM_NOTIFY_COMPLETED 8
  67. #define PHP_STREAM_NOTIFY_FAILURE 9
  68. #define PHP_STREAM_NOTIFY_AUTH_RESULT 10
  69. #define PHP_STREAM_NOTIFY_SEVERITY_INFO 0
  70. #define PHP_STREAM_NOTIFY_SEVERITY_WARN 1
  71. #define PHP_STREAM_NOTIFY_SEVERITY_ERR 2
  72. BEGIN_EXTERN_C()
  73. PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity,
  74. char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr);
  75. PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context);
  76. END_EXTERN_C()
  77. #define php_stream_notify_info(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) { \
  78. php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_INFO, \
  79. (xmsg), (xcode), 0, 0, NULL); } } while (0)
  80. #define php_stream_notify_progress(context, bsofar, bmax) do { if ((context) && (context)->notifier) { \
  81. php_stream_notification_notify((context), PHP_STREAM_NOTIFY_PROGRESS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \
  82. NULL, 0, (bsofar), (bmax), NULL); } } while(0)
  83. #define php_stream_notify_progress_init(context, sofar, bmax) do { if ((context) && (context)->notifier) { \
  84. (context)->notifier->progress = (sofar); \
  85. (context)->notifier->progress_max = (bmax); \
  86. (context)->notifier->mask |= PHP_STREAM_NOTIFIER_PROGRESS; \
  87. php_stream_notify_progress((context), (sofar), (bmax)); } } while (0)
  88. #define php_stream_notify_progress_increment(context, dsofar, dmax) do { if ((context) && (context)->notifier && (context)->notifier->mask & PHP_STREAM_NOTIFIER_PROGRESS) { \
  89. (context)->notifier->progress += (dsofar); \
  90. (context)->notifier->progress_max += (dmax); \
  91. php_stream_notify_progress((context), (context)->notifier->progress, (context)->notifier->progress_max); } } while (0)
  92. #define php_stream_notify_file_size(context, file_size, xmsg, xcode) do { if ((context) && (context)->notifier) { \
  93. php_stream_notification_notify((context), PHP_STREAM_NOTIFY_FILE_SIZE_IS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \
  94. (xmsg), (xcode), 0, (file_size), NULL); } } while(0)
  95. #define php_stream_notify_error(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) {\
  96. php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_ERR, \
  97. (xmsg), (xcode), 0, 0, NULL); } } while(0)
  98. /*
  99. * Local variables:
  100. * tab-width: 4
  101. * c-basic-offset: 4
  102. * End:
  103. * vim600: sw=4 ts=4 fdm=marker
  104. * vim<600: sw=4 ts=4
  105. */