root/main/streams/php_stream_context.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */