php_stream_context.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 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. /* $Id$ */
  19. /* Stream context and status notification related definitions */
  20. /* callback for status notifications */
  21. typedef void (*php_stream_notification_func)(php_stream_context *context,
  22. int notifycode, int severity,
  23. char *xmsg, int xcode,
  24. size_t bytes_sofar, size_t bytes_max,
  25. void * ptr TSRMLS_DC);
  26. #define PHP_STREAM_NOTIFIER_PROGRESS 1
  27. /* Attempt to fetch context from the zval passed,
  28. If no context was passed, use the default context
  29. The default context has not yet been created, do it now. */
  30. #define php_stream_context_from_zval(zcontext, nocontext) ( \
  31. (zcontext) ? zend_fetch_resource(&(zcontext) TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context(TSRMLS_C)) : \
  32. (nocontext) ? NULL : \
  33. FG(default_context) ? FG(default_context) : \
  34. (FG(default_context) = php_stream_context_alloc(TSRMLS_C)) )
  35. #define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); zend_list_addref((context)->rsrc_id); }
  36. typedef struct _php_stream_notifier php_stream_notifier;
  37. struct _php_stream_notifier {
  38. php_stream_notification_func func;
  39. void (*dtor)(php_stream_notifier *notifier);
  40. void *ptr;
  41. int mask;
  42. size_t progress, progress_max; /* position for progress notification */
  43. };
  44. struct _php_stream_context {
  45. php_stream_notifier *notifier;
  46. zval *options; /* hash keyed by wrapper family or specific wrapper */
  47. int rsrc_id; /* used for auto-cleanup */
  48. };
  49. BEGIN_EXTERN_C()
  50. PHPAPI void php_stream_context_free(php_stream_context *context);
  51. PHPAPI php_stream_context *php_stream_context_alloc(TSRMLS_D);
  52. PHPAPI int php_stream_context_get_option(php_stream_context *context,
  53. const char *wrappername, const char *optionname, zval ***optionvalue);
  54. PHPAPI int php_stream_context_set_option(php_stream_context *context,
  55. const char *wrappername, const char *optionname, zval *optionvalue);
  56. PHPAPI php_stream_notifier *php_stream_notification_alloc(void);
  57. PHPAPI void php_stream_notification_free(php_stream_notifier *notifier);
  58. END_EXTERN_C()
  59. /* not all notification codes are implemented */
  60. #define PHP_STREAM_NOTIFY_RESOLVE 1
  61. #define PHP_STREAM_NOTIFY_CONNECT 2
  62. #define PHP_STREAM_NOTIFY_AUTH_REQUIRED 3
  63. #define PHP_STREAM_NOTIFY_MIME_TYPE_IS 4
  64. #define PHP_STREAM_NOTIFY_FILE_SIZE_IS 5
  65. #define PHP_STREAM_NOTIFY_REDIRECTED 6
  66. #define PHP_STREAM_NOTIFY_PROGRESS 7
  67. #define PHP_STREAM_NOTIFY_COMPLETED 8
  68. #define PHP_STREAM_NOTIFY_FAILURE 9
  69. #define PHP_STREAM_NOTIFY_AUTH_RESULT 10
  70. #define PHP_STREAM_NOTIFY_SEVERITY_INFO 0
  71. #define PHP_STREAM_NOTIFY_SEVERITY_WARN 1
  72. #define PHP_STREAM_NOTIFY_SEVERITY_ERR 2
  73. BEGIN_EXTERN_C()
  74. PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity,
  75. char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC);
  76. PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context);
  77. END_EXTERN_C()
  78. #define php_stream_notify_info(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) { \
  79. php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_INFO, \
  80. (xmsg), (xcode), 0, 0, NULL TSRMLS_CC); } } while (0)
  81. #define php_stream_notify_progress(context, bsofar, bmax) do { if ((context) && (context)->notifier) { \
  82. php_stream_notification_notify((context), PHP_STREAM_NOTIFY_PROGRESS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \
  83. NULL, 0, (bsofar), (bmax), NULL TSRMLS_CC); } } while(0)
  84. #define php_stream_notify_progress_init(context, sofar, bmax) do { if ((context) && (context)->notifier) { \
  85. (context)->notifier->progress = (sofar); \
  86. (context)->notifier->progress_max = (bmax); \
  87. (context)->notifier->mask |= PHP_STREAM_NOTIFIER_PROGRESS; \
  88. php_stream_notify_progress((context), (sofar), (bmax)); } } while (0)
  89. #define php_stream_notify_progress_increment(context, dsofar, dmax) do { if ((context) && (context)->notifier && (context)->notifier->mask & PHP_STREAM_NOTIFIER_PROGRESS) { \
  90. (context)->notifier->progress += (dsofar); \
  91. (context)->notifier->progress_max += (dmax); \
  92. php_stream_notify_progress((context), (context)->notifier->progress, (context)->notifier->progress_max); } } while (0)
  93. #define php_stream_notify_file_size(context, file_size, xmsg, xcode) do { if ((context) && (context)->notifier) { \
  94. php_stream_notification_notify((context), PHP_STREAM_NOTIFY_FILE_SIZE_IS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \
  95. (xmsg), (xcode), 0, (file_size), NULL TSRMLS_CC); } } while(0)
  96. #define php_stream_notify_error(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) {\
  97. php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_ERR, \
  98. (xmsg), (xcode), 0, 0, NULL TSRMLS_CC); } } while(0)
  99. /*
  100. * Local variables:
  101. * tab-width: 4
  102. * c-basic-offset: 4
  103. * End:
  104. * vim600: sw=4 ts=4 fdm=marker
  105. * vim<600: sw=4 ts=4
  106. */