Back to index

php5  5.3.10
php_stream_context.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Wez Furlong <wez@thebrainroom.com>                           |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 /* $Id: php_stream_context.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 /* Stream context and status notification related definitions */
00022 
00023 /* callback for status notifications */
00024 typedef void (*php_stream_notification_func)(php_stream_context *context,
00025               int notifycode, int severity,
00026               char *xmsg, int xcode,
00027               size_t bytes_sofar, size_t bytes_max,
00028               void * ptr TSRMLS_DC);
00029 
00030 #define PHP_STREAM_NOTIFIER_PROGRESS      1
00031 
00032 /* Attempt to fetch context from the zval passed,
00033    If no context was passed, use the default context
00034    The default context has not yet been created, do it now. */
00035 #define php_stream_context_from_zval(zcontext, nocontext) ( \
00036               (zcontext) ? zend_fetch_resource(&(zcontext) TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()) : \
00037               (nocontext) ? NULL : \
00038               FG(default_context) ? FG(default_context) : \
00039               (FG(default_context) = php_stream_context_alloc()) )
00040 
00041 #define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); zend_list_addref((context)->rsrc_id); }
00042 
00043 typedef struct _php_stream_notifier php_stream_notifier;
00044 
00045 struct _php_stream_notifier {
00046        php_stream_notification_func func;
00047        void (*dtor)(php_stream_notifier *notifier);
00048        void *ptr;
00049        int mask;
00050        size_t progress, progress_max; /* position for progress notification */
00051 };
00052 
00053 struct _php_stream_context {
00054        php_stream_notifier *notifier;
00055        zval *options;       /* hash keyed by wrapper family or specific wrapper */
00056        zval *links;  /* hash keyed by hostent for connection pooling */
00057        int rsrc_id;  /* used for auto-cleanup */
00058 };
00059 
00060 BEGIN_EXTERN_C()
00061 PHPAPI void php_stream_context_free(php_stream_context *context);
00062 PHPAPI php_stream_context *php_stream_context_alloc(void);
00063 PHPAPI int php_stream_context_get_option(php_stream_context *context,
00064               const char *wrappername, const char *optionname, zval ***optionvalue);
00065 PHPAPI int php_stream_context_set_option(php_stream_context *context,
00066               const char *wrappername, const char *optionname, zval *optionvalue);
00067 
00068 PHPAPI int php_stream_context_get_link(php_stream_context *context,
00069               const char *hostent, php_stream **stream);
00070 PHPAPI int php_stream_context_set_link(php_stream_context *context,
00071               const char *hostent, php_stream *stream);
00072 PHPAPI int php_stream_context_del_link(php_stream_context *context,
00073               php_stream *stream);
00074 
00075 PHPAPI php_stream_notifier *php_stream_notification_alloc(void);
00076 PHPAPI void php_stream_notification_free(php_stream_notifier *notifier);
00077 END_EXTERN_C()
00078 
00079 /* not all notification codes are implemented */
00080 #define PHP_STREAM_NOTIFY_RESOLVE         1
00081 #define PHP_STREAM_NOTIFY_CONNECT         2
00082 #define PHP_STREAM_NOTIFY_AUTH_REQUIRED          3
00083 #define PHP_STREAM_NOTIFY_MIME_TYPE_IS    4
00084 #define PHP_STREAM_NOTIFY_FILE_SIZE_IS    5
00085 #define PHP_STREAM_NOTIFY_REDIRECTED      6
00086 #define PHP_STREAM_NOTIFY_PROGRESS        7
00087 #define PHP_STREAM_NOTIFY_COMPLETED              8
00088 #define PHP_STREAM_NOTIFY_FAILURE         9
00089 #define PHP_STREAM_NOTIFY_AUTH_RESULT     10
00090 
00091 #define PHP_STREAM_NOTIFY_SEVERITY_INFO   0
00092 #define PHP_STREAM_NOTIFY_SEVERITY_WARN   1
00093 #define PHP_STREAM_NOTIFY_SEVERITY_ERR    2
00094 
00095 BEGIN_EXTERN_C()
00096 PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity,
00097               char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC);
00098 PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context);
00099 END_EXTERN_C()
00100 
00101 #define php_stream_notify_info(context, code, xmsg, xcode)     do { if ((context) && (context)->notifier) { \
00102        php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_INFO, \
00103                             (xmsg), (xcode), 0, 0, NULL TSRMLS_CC); } } while (0)
00104                      
00105 #define php_stream_notify_progress(context, bsofar, bmax) do { if ((context) && (context)->notifier) { \
00106        php_stream_notification_notify((context), PHP_STREAM_NOTIFY_PROGRESS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \
00107                      NULL, 0, (bsofar), (bmax), NULL TSRMLS_CC); } } while(0)
00108 
00109 #define php_stream_notify_progress_init(context, sofar, bmax) do { if ((context) && (context)->notifier) { \
00110        (context)->notifier->progress = (sofar); \
00111        (context)->notifier->progress_max = (bmax); \
00112        (context)->notifier->mask |= PHP_STREAM_NOTIFIER_PROGRESS; \
00113        php_stream_notify_progress((context), (sofar), (bmax)); } } while (0)
00114 
00115 #define php_stream_notify_progress_increment(context, dsofar, dmax) do { if ((context) && (context)->notifier && (context)->notifier->mask & PHP_STREAM_NOTIFIER_PROGRESS) { \
00116        (context)->notifier->progress += (dsofar); \
00117        (context)->notifier->progress_max += (dmax); \
00118        php_stream_notify_progress((context), (context)->notifier->progress, (context)->notifier->progress_max); } } while (0)
00119 
00120 #define php_stream_notify_file_size(context, file_size, xmsg, xcode) do { if ((context) && (context)->notifier) { \
00121        php_stream_notification_notify((context), PHP_STREAM_NOTIFY_FILE_SIZE_IS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \
00122                      (xmsg), (xcode), 0, (file_size), NULL TSRMLS_CC); } } while(0)
00123        
00124 #define php_stream_notify_error(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) {\
00125        php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_ERR, \
00126                      (xmsg), (xcode), 0, 0, NULL TSRMLS_CC); } } while(0)
00127        
00128 
00129 /*
00130  * Local variables:
00131  * tab-width: 4
00132  * c-basic-offset: 4
00133  * End:
00134  * vim600: sw=4 ts=4 fdm=marker
00135  * vim<600: sw=4 ts=4
00136  */