Skip to content

Commit ce8fa32

Browse files
committed
refactored linked list implementation
corrected license information clean up and documentation
1 parent 6241738 commit ce8fa32

File tree

9 files changed

+376
-124
lines changed

9 files changed

+376
-124
lines changed

pecl/package2.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/ta
2525
<release>${release.stability}</release>
2626
<api>${api.stability}</api>
2727
</stability>
28-
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license>
28+
<license uri="http://www.php.net/license/3_01.txt">PHP 3.01</license>
2929
<notes>initital release</notes>
3030
<contents>
3131
<dir name="/">
@@ -64,7 +64,7 @@ xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/ta
6464
<api>beta</api>
6565
</stability>
6666
<date>2013-08-27</date>
67-
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license>
67+
<license uri="http://www.php.net/license/3_01.txt">PHP 3.01</license>
6868
<notes>initial release</notes>
6969
</release>
7070
</changelog>

php-ext-appserver.launch

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType">
3-
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
4-
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
5-
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="build/php-5.5.2/ext/appserver/appserver.php"/>
6-
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/php-5.5.2/sapi/cli/php"/>
7-
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="php-ext-appserver"/>
8-
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
9-
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
10-
<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/>
11-
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
12-
<listEntry value="/php-ext-appserver"/>
13-
</listAttribute>
14-
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
15-
<listEntry value="4"/>
16-
</listAttribute>
17-
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
18-
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
19-
</listAttribute>
20-
<stringAttribute key="provider" value="org.eclipse.linuxtools.profiling.provider.valgrind.cachegrind"/>
3+
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
4+
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
5+
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="build/php-5.5.2/ext/appserver/appserver.php"/>
6+
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/php-5.5.2/sapi/cli/php"/>
7+
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="php-ext-appserver"/>
8+
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
9+
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
10+
<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/>
11+
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
12+
<listEntry value="/php-ext-appserver"/>
13+
</listAttribute>
14+
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
15+
<listEntry value="4"/>
16+
</listAttribute>
17+
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
18+
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
19+
</listAttribute>
20+
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;&#10;"/>
21+
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
22+
<stringAttribute key="provider" value="org.eclipse.linuxtools.profiling.provider.valgrind.cachegrind"/>
2123
</launchConfiguration>

src/CREDITS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
appserver

src/LICENSE

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--------------------------------------------------------------------
2+
The PHP License, version 3.01
3+
Copyright (c) 1999 - 2012 The PHP Group. All rights reserved.
4+
--------------------------------------------------------------------
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, is permitted provided that the following conditions
8+
are met:
9+
10+
1. Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in
15+
the documentation and/or other materials provided with the
16+
distribution.
17+
18+
3. The name "PHP" must not be used to endorse or promote products
19+
derived from this software without prior written permission. For
20+
written permission, please contact group@php.net.
21+
22+
4. Products derived from this software may not be called "PHP", nor
23+
may "PHP" appear in their name, without prior written permission
24+
from group@php.net. You may indicate that your software works in
25+
conjunction with PHP by saying "Foo for PHP" instead of calling
26+
it "PHP Foo" or "phpfoo"
27+
28+
5. The PHP Group may publish revised and/or new versions of the
29+
license from time to time. Each version will be given a
30+
distinguishing version number.
31+
Once covered code has been published under a particular version
32+
of the license, you may always continue to use it under the terms
33+
of that version. You may also choose to use such covered code
34+
under the terms of any subsequent version of the license
35+
published by the PHP Group. No one other than the PHP Group has
36+
the right to modify the terms applicable to covered code created
37+
under this License.
38+
39+
6. Redistributions of any form whatsoever must retain the following
40+
acknowledgment:
41+
"This product includes PHP software, freely available from
42+
<http://www.php.net/software/>".
43+
44+
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
45+
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
46+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
48+
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
49+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55+
OF THE POSSIBILITY OF SUCH DAMAGE.
56+
57+
--------------------------------------------------------------------
58+
59+
This software consists of voluntary contributions made by many
60+
individuals on behalf of the PHP Group.
61+
62+
The PHP Group can be contacted via Email at group@php.net.
63+
64+
For more information on the PHP Group and the PHP project,
65+
please see <http://www.php.net>.
66+
67+
PHP includes the Zend Engine, freely available at
68+
<http://www.zend.com>.

src/appserver.c

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
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+
*/
1821

1922
#ifdef HAVE_CONFIG_H
2023
#include "config.h"
@@ -69,32 +72,40 @@ ZEND_GET_MODULE(appserver)
6972
#endif
7073

7174

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)
7376
{
74-
appserver_llist_element *le;
75-
char *header;
77+
char *s = data;
7678

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+
}
7983

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;
8288

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);
8798
}
8899
}
89100
}
90101

91102
static int appserver_header_handler(sapi_header_struct *h AS_SAPI_HEADER_OP_DC, sapi_headers_struct *s TSRMLS_DC)
92103
{
93104
if (APPSERVER_GLOBALS(headers)) {
94-
#if PHP_VERSION_ID >= 50300
95105
switch (op) {
106+
96107
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));
98109
break;
99110

100111
case SAPI_HEADER_REPLACE: {
@@ -104,16 +115,16 @@ static int appserver_header_handler(sapi_header_struct *h AS_SAPI_HEADER_OP_DC,
104115
char save = *colon_offset;
105116

106117
*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);
108119
*colon_offset = save;
109120
}
110121

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));
112123
}
113124
break;
114125

115126
case SAPI_HEADER_DELETE_ALL:
116-
appserver_llist_empty(APPSERVER_GLOBALS(headers), NULL);
127+
appserver_llist_clear(APPSERVER_GLOBALS(headers));
117128
break;
118129

119130
case SAPI_HEADER_DELETE:
@@ -123,18 +134,18 @@ static int appserver_header_handler(sapi_header_struct *h AS_SAPI_HEADER_OP_DC,
123134
break;
124135

125136
}
126-
#else
127-
appserver_llist_insert_next(APPSERVER_GLOBALS(headers), APPSERVER_LLIST_TAIL(APPSERVER_GLOBALS(headers)), strdup(h->header));
128-
#endif
129137
}
130138

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+
// }
134144

135145
return SAPI_HEADER_ADD;
136146
}
137147

148+
138149
static void php_appserver_shutdown_globals (zend_appserver_globals *appserver_globals TSRMLS_DC)
139150
{
140151

@@ -143,26 +154,16 @@ static void php_appserver_shutdown_globals (zend_appserver_globals *appserver_gl
143154
static void php_appserver_init_globals(zend_appserver_globals *appserver_globals)
144155
{
145156

146-
/* Override header generation in SAPI
157+
/* Override header generation in SAPI */
147158
if (sapi_module.header_handler != appserver_header_handler) {
148159
appserver_orig_header_handler = sapi_module.header_handler;
149160
sapi_module.header_handler = appserver_header_handler;
150161
}
151-
*/
152162

153163
appserver_globals->headers = NULL;
154164

155165
}
156166

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-
166167
PHP_MSHUTDOWN_FUNCTION(appserver)
167168
{
168169
/* uncomment this line if you have INI entries
@@ -191,7 +192,7 @@ PHP_MINIT_FUNCTION(appserver)
191192
PHP_RINIT_FUNCTION(appserver)
192193
{
193194

194-
APPSERVER_GLOBALS(headers) = appserver_llist_alloc(appserver_llist_string_dtor);
195+
APPSERVER_GLOBALS(headers) = appserver_llist_allocate(appserver_llist_string_destor);
195196

196197
return SUCCESS;
197198
}
@@ -214,12 +215,12 @@ PHP_MINFO_FUNCTION(appserver)
214215

215216
PHP_FUNCTION(appserver_get_headers)
216217
{
217-
appserver_llist_element *le;
218-
char *string;
218+
appserver_llist_item *header_item;
219+
char *string;
219220

220221
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;
223224
add_next_index_string(return_value, string, 1);
224225
}
225226
}

src/appserver.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
<?php
22

3+
/**
4+
* appserver.php
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Open Software License (OSL 3.0)
9+
* that is available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/osl-3.0.php
11+
*/
12+
13+
/**
14+
* A php test script show functionality of the extension
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+
*/
21+
322
header('X-Powered-By: appserver');
423
header('Location: http://www.google.de');
524

625
echo "SAPI_TYPE: " . PHP_SAPI;
726
echo PHP_EOL . "==========================================". PHP_EOL;
827

9-
echo "CALL headers_list()" . PHP_EOL;
10-
echo var_export(headers_list(), true);
11-
echo PHP_EOL . "==========================================". PHP_EOL;
12-
1328
echo "CALL appserver_get_headers()" . PHP_EOL;
1429
echo var_export(appserver_get_headers(), true);
1530
echo PHP_EOL . "==========================================". PHP_EOL;

0 commit comments

Comments
 (0)