1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
33
34
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;
51 };
52
53 struct _php_stream_context {
54 php_stream_notifier *notifier;
55 zval options;
56 zend_resource *res;
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
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
123
124
125
126
127
128