1
- /*
2
- +----------------------------------------------------------------------+
3
- | PHP Version 5 |
4
- +----------------------------------------------------------------------+
5
- | Copyright (c) 1997-2013 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: Johann Zelger <jz@techdivision.com |
16
- +----------------------------------------------------------------------+
17
- */
1
+ /**
2
+ * appserver.c
3
+ *
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the Open Software License (OSL 3.0)
7
+ * that is available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ */
10
+
11
+ /**
12
+ * A php extension for the appserver project (http://appserver.io)
13
+ *
14
+ * It provides various functionality for usage within the appserver runtime.
15
+ *
16
+ * @copyright Copyright (c) 2013 <info@techdivision.com> - TechDivision GmbH
17
+ * @license http://opensource.org/licenses/osl-3.0.php
18
+ * Open Software License (OSL 3.0)
19
+ * @author Johann Zelger <jz@techdivision.com>
20
+ */
18
21
19
22
#ifdef HAVE_CONFIG_H
20
23
#include "config.h"
@@ -69,32 +72,40 @@ ZEND_GET_MODULE(appserver)
69
72
#endif
70
73
71
74
72
- static void appserver_header_remove_with_prefix ( appserver_llist * headers , char * prefix , int prefix_len TSRMLS_DC )
75
+ static void appserver_llist_string_destor ( void * data )
73
76
{
74
- appserver_llist_element * le ;
75
- char * header ;
77
+ char * s = data ;
76
78
77
- for (le = APPSERVER_LLIST_HEAD (APPSERVER_GLOBALS (headers )); le != NULL ;) {
78
- header = APPSERVER_LLIST_VALP (le );
79
+ if (s ) {
80
+ free (s );
81
+ }
82
+ }
79
83
80
- if ((strlen (header ) > prefix_len + 1 ) && (header [prefix_len ] == ':' ) && (strncasecmp (header , prefix , prefix_len ) == 0 )) {
81
- appserver_llist_element * current = le ;
84
+ static void appserver_header_remove_by_prefix (appserver_llist * headers , char * prefix , int prefix_len TSRMLS_DC )
85
+ {
86
+ appserver_llist_item * item ;
87
+ char * header ;
82
88
83
- le = APPSERVER_LLIST_NEXT (le );
84
- appserver_llist_remove (headers , current , NULL );
85
- } else {
86
- le = APPSERVER_LLIST_NEXT (le );
89
+ // iterate through items
90
+ for (item = APPSERVER_GLOBALS (headers )-> head ; item != NULL ; item = item -> next ) {
91
+ // get value from item
92
+ header = item -> ptr ;
93
+ // check if prefix was found
94
+ if ((strlen (header ) > prefix_len + 1 ) && (header [prefix_len ] == ':' ) && (strncasecmp (header , prefix , prefix_len ) == 0 )) {
95
+ appserver_llist_item * current = item ;
96
+ // delete header
97
+ appserver_llist_del (headers , current );
87
98
}
88
99
}
89
100
}
90
101
91
102
static int appserver_header_handler (sapi_header_struct * h AS_SAPI_HEADER_OP_DC , sapi_headers_struct * s TSRMLS_DC )
92
103
{
93
104
if (APPSERVER_GLOBALS (headers )) {
94
- #if PHP_VERSION_ID >= 50300
95
105
switch (op ) {
106
+
96
107
case SAPI_HEADER_ADD :
97
- appserver_llist_insert_next (APPSERVER_GLOBALS (headers ), APPSERVER_LLIST_TAIL ( APPSERVER_GLOBALS ( headers )) , strdup (h -> header ));
108
+ appserver_llist_add (APPSERVER_GLOBALS (headers ), NULL , strdup (h -> header ));
98
109
break ;
99
110
100
111
case SAPI_HEADER_REPLACE : {
@@ -104,16 +115,16 @@ static int appserver_header_handler(sapi_header_struct *h AS_SAPI_HEADER_OP_DC,
104
115
char save = * colon_offset ;
105
116
106
117
* colon_offset = '\0' ;
107
- appserver_header_remove_with_prefix (APPSERVER_GLOBALS (headers ), h -> header , strlen (h -> header ) TSRMLS_CC );
118
+ appserver_header_remove_by_prefix (APPSERVER_GLOBALS (headers ), h -> header , strlen (h -> header ) TSRMLS_CC );
108
119
* colon_offset = save ;
109
120
}
110
121
111
- appserver_llist_insert_next (APPSERVER_GLOBALS (headers ), APPSERVER_LLIST_TAIL ( APPSERVER_GLOBALS ( headers )) , strdup (h -> header ));
122
+ appserver_llist_add (APPSERVER_GLOBALS (headers ), NULL , strdup (h -> header ));
112
123
}
113
124
break ;
114
125
115
126
case SAPI_HEADER_DELETE_ALL :
116
- appserver_llist_empty (APPSERVER_GLOBALS (headers ), NULL );
127
+ appserver_llist_clear (APPSERVER_GLOBALS (headers ));
117
128
break ;
118
129
119
130
case SAPI_HEADER_DELETE :
@@ -123,18 +134,18 @@ static int appserver_header_handler(sapi_header_struct *h AS_SAPI_HEADER_OP_DC,
123
134
break ;
124
135
125
136
}
126
- #else
127
- appserver_llist_insert_next (APPSERVER_GLOBALS (headers ), APPSERVER_LLIST_TAIL (APPSERVER_GLOBALS (headers )), strdup (h -> header ));
128
- #endif
129
137
}
130
138
131
- if (appserver_orig_header_handler ) {
132
- return appserver_orig_header_handler (h AS_SAPI_HEADER_OP_CC , s TSRMLS_CC );
133
- }
139
+ // Disables the orig header handler to avoid headers_sent check.
140
+
141
+ // if (appserver_orig_header_handler) {
142
+ // return appserver_orig_header_handler(h AS_SAPI_HEADER_OP_CC, s TSRMLS_CC);
143
+ // }
134
144
135
145
return SAPI_HEADER_ADD ;
136
146
}
137
147
148
+
138
149
static void php_appserver_shutdown_globals (zend_appserver_globals * appserver_globals TSRMLS_DC )
139
150
{
140
151
@@ -143,26 +154,16 @@ static void php_appserver_shutdown_globals (zend_appserver_globals *appserver_gl
143
154
static void php_appserver_init_globals (zend_appserver_globals * appserver_globals )
144
155
{
145
156
146
- /* Override header generation in SAPI
157
+ /* Override header generation in SAPI */
147
158
if (sapi_module .header_handler != appserver_header_handler ) {
148
159
appserver_orig_header_handler = sapi_module .header_handler ;
149
160
sapi_module .header_handler = appserver_header_handler ;
150
161
}
151
- */
152
162
153
163
appserver_globals -> headers = NULL ;
154
164
155
165
}
156
166
157
- static void appserver_llist_string_dtor (void * dummy , void * elem )
158
- {
159
- char * s = elem ;
160
-
161
- if (s ) {
162
- free (s );
163
- }
164
- }
165
-
166
167
PHP_MSHUTDOWN_FUNCTION (appserver )
167
168
{
168
169
/* uncomment this line if you have INI entries
@@ -191,7 +192,7 @@ PHP_MINIT_FUNCTION(appserver)
191
192
PHP_RINIT_FUNCTION (appserver )
192
193
{
193
194
194
- APPSERVER_GLOBALS (headers ) = appserver_llist_alloc ( appserver_llist_string_dtor );
195
+ APPSERVER_GLOBALS (headers ) = appserver_llist_allocate ( appserver_llist_string_destor );
195
196
196
197
return SUCCESS ;
197
198
}
@@ -214,12 +215,12 @@ PHP_MINFO_FUNCTION(appserver)
214
215
215
216
PHP_FUNCTION (appserver_get_headers )
216
217
{
217
- appserver_llist_element * le ;
218
- char * string ;
218
+ appserver_llist_item * header_item ;
219
+ char * string ;
219
220
220
221
array_init (return_value );
221
- for (le = APPSERVER_LLIST_HEAD ( APPSERVER_GLOBALS (headers )); le != NULL ; le = APPSERVER_LLIST_NEXT ( le ) ) {
222
- string = APPSERVER_LLIST_VALP ( le ) ;
222
+ for (header_item = APPSERVER_GLOBALS (headers )-> head ; header_item != NULL ; header_item = header_item -> next ) {
223
+ string = header_item -> ptr ;
223
224
add_next_index_string (return_value , string , 1 );
224
225
}
225
226
}
0 commit comments