summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/Makefile.am4
-rw-r--r--ext/standard/basic_functions.c26
-rw-r--r--ext/standard/config.h.stub12
-rw-r--r--ext/standard/config.m4111
-rw-r--r--ext/standard/fsock.c2
-rw-r--r--ext/standard/mime.c249
-rw-r--r--ext/standard/mime.h8
-rw-r--r--ext/standard/php3_standard.h3
-rw-r--r--ext/standard/post.c498
-rw-r--r--ext/standard/post.h43
-rw-r--r--ext/standard/string.c2
-rw-r--r--ext/standard/var.c2
12 files changed, 930 insertions, 30 deletions
diff --git a/ext/standard/Makefile.am b/ext/standard/Makefile.am
index 7f6ed0f0b5..a78a0b99dc 100644
--- a/ext/standard/Makefile.am
+++ b/ext/standard/Makefile.am
@@ -7,5 +7,7 @@ libphpext_standard_a_SOURCES=\
html.c image.c info.c link.c mail.c math.c md5.c microtime.c \
pack.c pageinfo.c rand.c reg.c soundex.c string.c \
syslog.c type.c uniqid.c url.c iptc.c var.c quot_print.c \
- cyr_convert.c flock_compat.c crypt.c dl.c head.c
+ cyr_convert.c flock_compat.c crypt.c dl.c head.c mime.c post.c
+#number.o: number.c
+# $(CC) $(CFLAGS) -w@WARNING_LEVEL@ -c $< -o $@
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index bf0a5da21a..e2865ac83f 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -52,32 +52,6 @@
#include <strings.h>
#endif
#include "safe_mode.h"
-/*
-#include "functions/basic_functions.h"
-#include "functions/phpmath.h"
-#include "functions/php3_string.h"
-#include "functions/dns.h"
-#include "functions/md5.h"
-#include "functions/html.h"
-#include "functions/post.h"
-#include "functions/exec.h"
-#include "functions/info.h"
-#include "functions/url.h"
-#include "functions/datetime.h"
-#include "functions/fsock.h"
-#include "functions/image.h"
-#include "functions/php3_link.h"
-#include "functions/php3_filestat.h"
-#include "functions/microtime.h"
-#include "functions/pageinfo.h"
-#include "functions/uniqid.h"
-#include "functions/base64.h"
-#include "functions/php3_mail.h"
-#include "functions/php3_var.h"
-#include "functions/php3_iptc.h"
-#include "functions/quot_print.h"
-#include "functions/cyr_convert.h"
-*/
#if WIN32|WINNT
#include "win32/unistd.h"
#endif
diff --git a/ext/standard/config.h.stub b/ext/standard/config.h.stub
index 50703755eb..69ee82467f 100644
--- a/ext/standard/config.h.stub
+++ b/ext/standard/config.h.stub
@@ -1,2 +1,14 @@
/* Define if you have the crypt() function */
#define HAVE_CRYPT 1
+
+/* Define if you have and want to use libcrypt */
+#define HAVE_LIBCRYPT 0
+
+/* crypt capability checks */
+#undef PHP3_STD_DES_CRYPT
+#undef PHP3_EXT_DES_CRYPT
+#undef PHP3_MD5_CRYPT
+#undef PHP3_BLOWFISH_CRYPT
+
+/* Define if you have libdl (used for dynamic linking) */
+#define HAVE_LIBDL 0
diff --git a/ext/standard/config.m4 b/ext/standard/config.m4
index f44a1df39f..c20daccc4a 100644
--- a/ext/standard/config.m4
+++ b/ext/standard/config.m4
@@ -1,3 +1,114 @@
dnl $Id$ -*- sh -*-
+divert(1)
+
+dnl
+dnl Check for crypt() capabilities
+dnl
+AC_DEFUN(AC_CRYPT_CAP,[
+
+ AC_MSG_CHECKING([for standard DES crypt])
+ AC_TRY_RUN([
+main() {
+#if HAVE_CRYPT
+ exit (strcmp((char *)crypt("rasmuslerdorf","rl"),"rl.3StKT.4T8M"));
+#else
+ exit(0);
+#endif
+}],[
+ AC_DEFINE(PHP3_STD_DES_CRYPT,1)
+ AC_MSG_RESULT(yes)
+ ],[
+ AC_DEFINE(PHP3_STD_DES_CRYPT,0)
+ AC_MSG_RESULT(no)
+ ],[
+ AC_DEFINE(PHP3_STD_DES_CRYPT,1)
+ AC_MSG_RESULT(cannot check, guessing yes)
+ ])
+
+ AC_MSG_CHECKING([for extended DES crypt])
+ AC_TRY_RUN([
+main() {
+#if HAVE_CRYPT
+ exit (strcmp((char *)crypt("rasmuslerdorf","_J9..rasm"),"_J9..rasmBYk8r9AiWNc"));
+#else
+ exit(0);
+#endif
+}],[
+ AC_DEFINE(PHP3_EXT_DES_CRYPT,1)
+ AC_MSG_RESULT(yes)
+ ],[
+ AC_DEFINE(PHP3_EXT_DES_CRYPT,0)
+ AC_MSG_RESULT(no)
+ ],[
+ AC_DEFINE(PHP3_EXT_DES_CRYPT,0)
+ AC_MSG_RESULT(cannot check, guessing no)
+ ])
+
+ AC_MSG_CHECKING([for MD5 crypt])
+ AC_TRY_RUN([
+main() {
+#if HAVE_CRYPT
+ char salt[15], answer[40];
+
+ salt[0]='$'; salt[1]='1'; salt[2]='$';
+ salt[3]='r'; salt[4]='a'; salt[5]='s';
+ salt[6]='m'; salt[7]='u'; salt[8]='s';
+ salt[9]='l'; salt[10]='e'; salt[11]='$';
+ salt[12]='\0';
+ strcpy(answer,salt);
+ strcat(answer,"rISCgZzpwk3UhDidwXvin0");
+ exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
+#else
+ exit(0);
+#endif
+}],[
+ AC_DEFINE(PHP3_MD5_CRYPT,1)
+ AC_MSG_RESULT(yes)
+ ],[
+ AC_DEFINE(PHP3_MD5_CRYPT,0)
+ AC_MSG_RESULT(no)
+ ],[
+ AC_DEFINE(PHP3_MD5_CRYPT,0)
+ AC_MSG_RESULT(cannot check, guessing no)
+ ])
+
+ AC_MSG_CHECKING([for Blowfish crypt])
+ AC_TRY_RUN([
+main() {
+#if HAVE_CRYPT
+ char salt[25], answer[70];
+
+ salt[0]='$'; salt[1]='2'; salt[2]='a'; salt[3]='$'; salt[4]='0'; salt[5]='7'; salt[6]='$'; salt[7]='\0';
+ strcat(salt,"rasmuslerd");
+ strcpy(answer,salt);
+ strcpy(&answer[16],"O............gl95GkTKn53Of.H4YchXl5PwvvW.5ri");
+ exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
+#else
+ exit(0);
+#endif
+}],[
+ AC_DEFINE(PHP3_BLOWFISH_CRYPT,1)
+ AC_MSG_RESULT(yes)
+ ],[
+ AC_DEFINE(PHP3_BLOWFISH_CRYPT,0)
+ AC_MSG_RESULT(no)
+ ],[
+ AC_DEFINE(PHP3_BLOWFISH_CRYPT,0)
+ AC_MSG_RESULT(cannot check, guessing no)
+ ])
+])
+
+AC_CHECK_LIB(c, dlopen, [
+ # fake it
+ AC_DEFINE(HAVE_LIBDL) ], [
+ AC_CHECK_LIB(dl, dlopen, [
+ LIBS="-ldl $LIBS"
+ AC_DEFINE(HAVE_LIBDL) ], []) ])
+
+AC_CRYPT_CAP
+
+divert(3)
+
PHP_EXTENSION(standard)
+
diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c
index b664f03afb..6e210281cf 100644
--- a/ext/standard/fsock.c
+++ b/ext/standard/fsock.c
@@ -60,7 +60,7 @@
#include "base64.h"
#include "file.h"
-#include "functions/post.h"
+#include "post.h"
#include "url.h"
#include "fsock.h"
diff --git a/ext/standard/mime.c b/ext/standard/mime.c
new file mode 100644
index 0000000000..fdc794a87c
--- /dev/null
+++ b/ext/standard/mime.c
@@ -0,0 +1,249 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP HTML Embedded Scripting Language Version 3.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+ +----------------------------------------------------------------------+
+ | This program is free software; you can redistribute it and/or modify |
+ | it under the terms of one of the following licenses: |
+ | |
+ | A) the GNU General Public License as published by the Free Software |
+ | Foundation; either version 2 of the License, or (at your option) |
+ | any later version. |
+ | |
+ | B) the PHP License as published by the PHP Development Team and |
+ | included in the distribution in the file: LICENSE |
+ | |
+ | This program is distributed in the hope that it will be useful, |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ | GNU General Public License for more details. |
+ | |
+ | You should have received a copy of both licenses referred to here. |
+ | If you did not, or have any questions about PHP licensing, please |
+ | contact core@php.net. |
+ +----------------------------------------------------------------------+
+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+#ifdef THREAD_SAFE
+#include "tls.h"
+#endif
+#include <stdio.h>
+#include "php.h"
+#include "ext/standard/php3_standard.h"
+#include "post.h"
+#include "mime.h"
+#include "zend_globals.h"
+#include "php_globals.h"
+
+#ifndef THREAD_SAFE
+int le_uploads;
+extern HashTable list;
+#endif
+
+#define NEW_BOUNDARY_CHECK 1
+#define SAFE_RETURN { if (namebuf) efree(namebuf); if (filenamebuf) efree(filenamebuf); if (lbuf) efree(lbuf); return; }
+
+/*
+ * Split raw mime stream up into appropriate components
+ */
+void php3_mime_split(char *buf, int cnt, char *boundary, pval *http_post_vars PLS_DC)
+{
+ char *ptr, *loc, *loc2, *s, *name, *filename, *u, *fn;
+ int len, state = 0, Done = 0, rem, urem;
+ long bytes, max_file_size = 0;
+ char *namebuf=NULL, *filenamebuf=NULL, *lbuf=NULL;
+ FILE *fp;
+ int itype;
+ ELS_FETCH();
+
+ ptr = buf;
+ rem = cnt;
+ len = strlen(boundary);
+ while ((ptr - buf < cnt) && !Done) {
+ switch (state) {
+ case 0: /* Looking for mime boundary */
+ loc = memchr(ptr, *boundary, cnt);
+ if (loc) {
+ if (!strncmp(loc, boundary, len)) {
+
+ state = 1;
+ rem -= (loc - ptr) + len + 2;
+ ptr = loc + len + 2;
+ } else {
+ rem -= (loc - ptr) + 1;
+ ptr = loc + 1;
+ }
+ } else {
+ Done = 1;
+ }
+ break;
+ case 1: /* Check content-disposition */
+ if (strncasecmp(ptr, "Content-Disposition: form-data;", 31)) {
+ if (rem < 31) {
+ SAFE_RETURN;
+ }
+ php3_error(E_WARNING, "File Upload Mime headers garbled [%c%c%c%c%c]", *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3), *(ptr + 4));
+ SAFE_RETURN;
+ }
+ loc = memchr(ptr, '\n', rem);
+ name = strstr(ptr, " name=\"");
+ if (name && name < loc) {
+ name += 7;
+ s = memchr(name, '\"', loc - name);
+ if (!s) {
+ php3_error(E_WARNING, "File Upload Mime headers garbled [%c%c%c%c%c]", *name, *(name + 1), *(name + 2), *(name + 3), *(name + 4));
+ SAFE_RETURN;
+ }
+ if (namebuf) {
+ efree(namebuf);
+ }
+ namebuf = estrndup(name, s-name);
+ if (lbuf) {
+ efree(lbuf);
+ }
+ lbuf = emalloc(s-name + MAX(MAX(sizeof("_name"),sizeof("_size")),sizeof("_type")));
+ state = 2;
+ loc2 = memchr(loc + 1, '\n', rem);
+ rem -= (loc2 - ptr) + 1;
+ ptr = loc2 + 1;
+ } else {
+ php3_error(E_WARNING, "File upload error - no name component in content disposition");
+ SAFE_RETURN;
+ }
+ filename = strstr(s, " filename=\"");
+ if (filename && filename < loc) {
+ filename += 11;
+ s = memchr(filename, '\"', loc - filename);
+ if (!s) {
+ php3_error(E_WARNING, "File Upload Mime headers garbled [%c%c%c%c%c]", *filename, *(filename + 1), *(filename + 2), *(filename + 3), *(filename + 4));
+ SAFE_RETURN;
+ }
+ if (filenamebuf) {
+ efree(filenamebuf);
+ }
+ filenamebuf = estrndup(filename, s-filename);
+ sprintf(lbuf, "%s_name", namebuf);
+ s = strrchr(filenamebuf, '\\');
+ if (s && s > filenamebuf) {
+ SET_VAR_STRING(lbuf, estrdup(s + 1));
+ } else {
+ SET_VAR_STRING(lbuf, estrdup(filenamebuf));
+ }
+ state = 3;
+ if ((loc2 - loc) > 2) {
+ if (!strncasecmp(loc + 1, "Content-Type:", 13)) {
+ *(loc2 - 1) = '\0';
+ sprintf(lbuf, "%s_type", namebuf);
+ SET_VAR_STRING(lbuf, estrdup(loc + 15));
+ *(loc2 - 1) = '\n';
+ }
+ rem -= 2;
+ ptr += 2;
+ }
+ }
+ break;
+
+ case 2: /* handle form-data fields */
+ loc = memchr(ptr, *boundary, rem);
+ u = ptr;
+ while (loc) {
+ if (!strncmp(loc, boundary, len))
+ break;
+ u = loc + 1;
+ urem = rem - (loc - ptr) - 1;
+ loc = memchr(u, *boundary, urem);
+ }
+ if (!loc) {
+ php3_error(E_WARNING, "File Upload Field Data garbled");
+ SAFE_RETURN;
+ }
+ *(loc - 4) = '\0';
+
+ /* Magic function that figures everything out */
+ _php3_parse_gpc_data(ptr,namebuf,http_post_vars);
+
+ /* And a little kludge to pick out special MAX_FILE_SIZE */
+ itype = php3_check_ident_type(namebuf);
+ if (itype) {
+ u = strchr(namebuf, '[');
+ if (u)
+ *u = '\0';
+ }
+ if (!strcmp(namebuf, "MAX_FILE_SIZE")) {
+ max_file_size = atol(ptr);
+ }
+ if (itype) {
+ if (u)
+ *u = '[';
+ }
+ rem -= (loc - ptr);
+ ptr = loc;
+ state = 0;
+ break;
+
+ case 3: /* Handle file */
+ loc = memchr(ptr, *boundary, rem);
+ u = ptr;
+ while (loc) {
+ if (!strncmp(loc, boundary, len)
+#if NEW_BOUNDARY_CHECK
+ && (loc-2>buf && *(loc-2)=='-' && *(loc-1)=='-') /* ensure boundary is prefixed with -- */
+ && (loc-2==buf || *(loc-3)=='\n') /* ensure beginning of line */
+#endif
+ ) {
+ break;
+ }
+ u = loc + 1;
+ urem = rem - (loc - ptr) - 1;
+ loc = memchr(u, *boundary, urem);
+ }
+ if (!loc) {
+ php3_error(E_WARNING, "File Upload Error - No Mime boundary found after start of file header");
+ SAFE_RETURN;
+ }
+ fn = tempnam(PG(upload_tmp_dir), "php");
+ if ((loc - ptr - 4) > PG(upload_max_filesize)) {
+ php3_error(E_WARNING, "Max file size of %ld bytes exceeded - file [%s] not saved", PG(upload_max_filesize),namebuf);
+ bytes=0;
+ SET_VAR_STRING(namebuf, estrdup("none"));
+ } else if (max_file_size && ((loc - ptr - 4) > max_file_size)) {
+ php3_error(E_WARNING, "Max file size exceeded - file [%s] not saved", namebuf);
+ bytes = 0;
+ SET_VAR_STRING(namebuf, estrdup("none"));
+ } else if ((loc - ptr - 4) <= 0) {
+ bytes = 0;
+ SET_VAR_STRING(namebuf, estrdup("none"));
+ } else {
+ fp = fopen(fn, "w");
+ if (!fp) {
+ php3_error(E_WARNING, "File Upload Error - Unable to open temporary file [%s]", fn);
+ SAFE_RETURN;
+ }
+ bytes = fwrite(ptr, 1, loc - ptr - 4, fp);
+ fclose(fp);
+ php3_list_insert(fn,GLOBAL(le_uploads)); /* Tell PHP about the file so the destructor can unlink it later */
+ if (bytes < (loc - ptr - 4)) {
+ php3_error(E_WARNING, "Only %d bytes were written, expected to write %ld", bytes, loc - ptr - 4);
+ }
+ SET_VAR_STRING(namebuf, estrdup(fn));
+ }
+ sprintf(lbuf, "%s_size", namebuf);
+ SET_VAR_LONG(lbuf, bytes);
+ state = 0;
+ rem -= (loc - ptr);
+ ptr = loc;
+ break;
+ }
+ }
+ SAFE_RETURN;
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ext/standard/mime.h b/ext/standard/mime.h
new file mode 100644
index 0000000000..df5d78799f
--- /dev/null
+++ b/ext/standard/mime.h
@@ -0,0 +1,8 @@
+#ifndef _MIME_H
+#define _MIME_H
+
+#include "php_globals.h"
+
+extern void php3_mime_split(char *buf, int cnt, char *boundary, pval *http_post_vars PLS_DC);
+
+#endif
diff --git a/ext/standard/php3_standard.h b/ext/standard/php3_standard.h
index 77ccafb40f..a3920e30e7 100644
--- a/ext/standard/php3_standard.h
+++ b/ext/standard/php3_standard.h
@@ -62,6 +62,9 @@
#include "type.h"
#include "dl.h"
#include "php3_crypt.h"
+#include "head.h"
+#include "post.h"
+#include "mime.h"
#define standard_module_ptr basic_functions_module_ptr
diff --git a/ext/standard/post.c b/ext/standard/post.c
new file mode 100644
index 0000000000..224450990d
--- /dev/null
+++ b/ext/standard/post.c
@@ -0,0 +1,498 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP HTML Embedded Scripting Language Version 3.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+ +----------------------------------------------------------------------+
+ | This program is free software; you can redistribute it and/or modify |
+ | it under the terms of one of the following licenses: |
+ | |
+ | A) the GNU General Public License as published by the Free Software |
+ | Foundation; either version 2 of the License, or (at your option) |
+ | any later version. |
+ | |
+ | B) the PHP License as published by the PHP Development Team and |
+ | included in the distribution in the file: LICENSE |
+ | |
+ | This program is distributed in the hope that it will be useful, |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ | GNU General Public License for more details. |
+ | |
+ | You should have received a copy of both licenses referred to here. |
+ | If you did not, or have any questions about PHP licensing, please |
+ | contact core@php.net. |
+ +----------------------------------------------------------------------+
+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id: */
+#ifdef THREAD_SAFE
+#include "tls.h"
+#endif
+#include <stdio.h>
+#include "php.h"
+#include "php3_standard.h"
+#include "php_globals.h"
+
+#include "zend_globals.h"
+
+/*
+ * php3_getpost()
+ *
+ * This reads the post form data into a string.
+ * Remember to free this pointer when done with it.
+ */
+static char *php3_getpost(pval *http_post_vars PLS_DC)
+{
+ char *buf = NULL;
+ const char *ctype;
+#if MODULE_MAGIC_NUMBER > 19961007
+ char argsbuffer[HUGE_STRING_LEN];
+#else
+ int bytes;
+#endif
+ int length, cnt;
+ int file_upload = 0;
+ char *mb;
+ char boundary[100];
+ TLS_VARS;
+
+ ctype = GLOBAL(request_info).content_type;
+ if (!ctype) {
+ php3_error(E_WARNING, "POST Error: content-type missing");
+ return NULL;
+ }
+ if (strncasecmp(ctype, "application/x-www-form-urlencoded", 33) && strncasecmp(ctype, "multipart/form-data", 19)
+#if HAVE_FDFLIB
+ && strncasecmp(ctype, "application/vnd.fdf", 19)
+#endif
+ ) {
+ php3_error(E_WARNING, "Unsupported content-type: %s", ctype);
+ return NULL;
+ }
+ if (!strncasecmp(ctype, "multipart/form-data", 19)) {
+ file_upload = 1;
+ mb = strchr(ctype, '=');
+ if (mb) {
+ strncpy(boundary, mb + 1, sizeof(boundary));
+ } else {
+ php3_error(E_WARNING, "File Upload Error: No MIME boundary found");
+ php3_error(E_WARNING, "There should have been a \"boundary=something\" in the Content-Type string");
+ php3_error(E_WARNING, "The Content-Type string was: \"%s\"", ctype);
+ return NULL;
+ }
+ }
+ length = GLOBAL(request_info).content_length;
+ cnt = length;
+ buf = (char *) emalloc((length + 1) * sizeof(char));
+ if (!buf) {
+ php3_error(E_WARNING, "Unable to allocate memory in php3_getpost()");
+ return NULL;
+ }
+#if FHTTPD
+ memcpy(buf,req->databuffer,length);
+ buf[length]=0;
+#else
+#if MODULE_MAGIC_NUMBER > 19961007
+ if (should_client_block(GLOBAL(php3_rqst))) {
+ void (*handler) (int);
+ int dbsize, len_read, dbpos = 0;
+
+ hard_timeout("copy script args", GLOBAL(php3_rqst)); /* start timeout timer */
+ handler = signal(SIGPIPE, SIG_IGN); /* Ignore sigpipes for now */
+ while ((len_read = get_client_block(GLOBAL(php3_rqst), argsbuffer, HUGE_STRING_LEN)) > 0) {
+ if ((dbpos + len_read) > length)
+ dbsize = length - dbpos;
+ else
+ dbsize = len_read;
+ reset_timeout(GLOBAL(php3_rqst)); /* Make sure we don't timeout */
+ memcpy(buf + dbpos, argsbuffer, dbsize);
+ dbpos += dbsize;
+ }
+ signal(SIGPIPE, handler); /* restore normal sigpipe handling */
+ kill_timeout(GLOBAL(php3_rqst)); /* stop timeout timer */
+ }
+#else
+ cnt = 0;
+ do {
+#if APACHE
+ bytes = read_client_block(php3_rqst, buf + cnt, length - cnt);
+#endif
+#if CGI_BINARY
+ bytes = fread(buf + cnt, 1, length - cnt, stdin);
+#endif
+#if USE_SAPI
+ bytes = GLOBAL(sapi_rqst)->readclient(GLOBAL(sapi_rqst)->scid,buf + cnt, 1, length - cnt);
+#endif
+ cnt += bytes;
+ } while (bytes && cnt < length);
+#endif
+#endif
+ if (file_upload) {
+ php3_mime_split(buf, cnt, boundary, http_post_vars PLS_CC);
+ efree(buf);
+ return NULL;
+ }
+ buf[cnt] = '\0';
+
+#if HAVE_FDFLIB
+ if (!strncasecmp(ctype, "application/vnd.fdf", 19)) {
+ pval *postdata_ptr = (pval *) emalloc(sizeof(pval));
+
+ postdata_ptr->type = IS_STRING;
+ postdata_ptr->value.str.val = (char *) estrdup(buf);
+ postdata_ptr->value.str.len = cnt;
+ postdata_ptr->refcount=1;
+ postdata_ptr->is_ref=0;
+ _php3_hash_add(&GLOBAL(symbol_table), "HTTP_FDF_DATA", sizeof("HTTP_FDF_DATA"), postdata_ptr, sizeof(pval *),NULL);
+ }
+#endif
+ return (buf);
+}
+
+
+/*
+ * parse Get/Post/Cookie string and create appropriate variable
+ *
+ * This is a tad ugly because it was yanked out of the middle of
+ * the old TreatData function. This is a temporary measure filling
+ * the gap until a more flexible parser can be built to do this.
+ */
+void _php3_parse_gpc_data(char *val, char *var, pval *track_vars_array)
+{
+ int var_type;
+ char *ind, *tmp = NULL, *ret = NULL;
+ int var_len;
+ pval *entry;
+ ELS_FETCH();
+ PLS_FETCH();
+
+ var_type = php3_check_ident_type(var);
+ if (var_type == GPC_INDEXED_ARRAY) {
+ ind = php3_get_ident_index(var);
+ if (PG(magic_quotes_gpc)) {
+ ret = _php3_addslashes(ind, 0, NULL, 1);
+ } else {
+ ret = ind;
+ }
+ }
+ if (var_type & GPC_ARRAY) { /* array (indexed or not */
+ tmp = strchr(var, '[');
+ if (tmp) {
+ *tmp = '\0';
+ }
+ }
+ /* ignore leading spaces in the variable name */
+ while (*var && *var==' ') {
+ var++;
+ }
+ var_len = strlen(var);
+ if (var_len==0) { /* empty variable name, or variable name with a space in it */
+ return;
+ }
+
+ /* ensure that we don't have spaces or dots in the variable name (not binary safe) */
+ for (tmp=var; *tmp; tmp++) {
+ switch(*tmp) {
+ case ' ':
+ case '.':
+ *tmp='_';
+ break;
+ }
+ }
+
+ tmp = estrdup(val);
+ if (var_type & GPC_ARRAY) {
+ pval *arr1, *arr2;
+ pval **arr_ptr;
+
+ /* If the array doesn't exist, create it */
+ if (_php3_hash_find(EG(active_symbol_table), var, var_len+1, (void **) &arr_ptr) == FAILURE) {
+ arr1 = (pval *) emalloc(sizeof(pval));
+ arr1->refcount=1;
+ arr1->is_ref=0;
+ if (array_init(arr1)==FAILURE) {
+ return;
+ }
+ _php3_hash_update(EG(active_symbol_table), var, var_len+1, &arr1, sizeof(pval *), NULL);
+ if (track_vars_array) {
+ arr2 = (pval *) emalloc(sizeof(pval));
+ arr2->refcount=1;
+ arr2->is_ref=0;
+ if (array_init(arr2)==FAILURE) {
+ return;
+ }
+ _php3_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &arr2, sizeof(pval *),NULL);
+ }
+ } else {
+ if ((*arr_ptr)->type!=IS_ARRAY) {
+ if (--(*arr_ptr) > 0) {
+ *arr_ptr = (pval *) emalloc(sizeof(pval));
+ (*arr_ptr)->refcount=1;
+ (*arr_ptr)->is_ref=0;
+ } else {
+ pval_destructor(*arr_ptr);
+ }
+ if (array_init(*arr_ptr)==FAILURE) {
+ return;
+ }
+ if (track_vars_array) {
+ arr2 = (pval *) emalloc(sizeof(pval));
+ arr2->refcount=1;
+ arr2->is_ref=0;
+ if (array_init(arr2)==FAILURE) {
+ return;
+ }
+ _php3_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &arr2, sizeof(pval *),NULL);
+ }
+ }
+ arr1 = *arr_ptr;
+ if (track_vars_array && _php3_hash_find(track_vars_array->value.ht, var, var_len+1, (void **) &arr_ptr) == FAILURE) {
+ return;
+ }
+ arr2 = *arr_ptr;
+ }
+ /* Now create the element */
+ entry = (pval *) emalloc(sizeof(pval));
+ entry->refcount=1;
+ entry->is_ref=0;
+ if (PG(magic_quotes_gpc)) {
+ entry->value.str.val = _php3_addslashes(tmp, 0, &entry->value.str.len, 0);
+ } else {
+ entry->value.str.len = strlen(tmp);
+ entry->value.str.val = estrndup(tmp,entry->value.str.len);
+ }
+ entry->type = IS_STRING;
+
+ /* And then insert it */
+ if (ret) { /* indexed array */
+ if (php3_check_type(ret) == IS_LONG) {
+ _php3_hash_index_update(arr1->value.ht, atol(ret), &entry, sizeof(pval *),NULL); /* s[ret]=tmp */
+ if (track_vars_array) {
+ _php3_hash_index_update(arr2->value.ht, atol(ret), &entry, sizeof(pval *),NULL);
+ entry->refcount++;
+ }
+ } else {
+ _php3_hash_update(arr1->value.ht, ret, strlen(ret)+1, &entry, sizeof(pval *),NULL); /* s["ret"]=tmp */
+ if (track_vars_array) {
+ _php3_hash_update(arr2->value.ht, ret, strlen(ret)+1, &entry, sizeof(pval *),NULL);
+ entry->refcount++;
+ }
+ }
+ efree(ret);
+ ret = NULL;
+ } else { /* non-indexed array */
+ _php3_hash_next_index_insert(arr1->value.ht, &entry, sizeof(pval *),NULL);
+ if (track_vars_array) {
+ _php3_hash_next_index_insert(arr2->value.ht, &entry, sizeof(pval *),NULL);
+ entry->refcount++;
+ }
+ }
+ } else { /* we have a normal variable */
+ pval *entry = (pval *) emalloc(sizeof(pval));
+
+ if (PG(magic_quotes_gpc)) {
+ entry->value.str.val = _php3_addslashes(tmp, 0, &entry->value.str.len, 0);
+ } else {
+ entry->value.str.len = strlen(tmp);
+ entry->value.str.val = estrndup(tmp,entry->value.str.len);
+ }
+ entry->type = IS_STRING;
+ entry->refcount=1;
+ entry->is_ref=0;
+ _php3_hash_update(EG(active_symbol_table), var, var_len+1, (void *) &entry, sizeof(pval *),NULL);
+ if (track_vars_array) {
+ pval_copy_constructor(entry);
+ _php3_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &entry, sizeof(pval *),NULL);
+ }
+ }
+
+ if (tmp) efree(tmp);
+}
+
+
+void php3_treat_data(int arg, char *str)
+{
+ char *res = NULL, *var, *val;
+ pval *array_ptr;
+ ELS_FETCH();
+ PLS_FETCH();
+
+ switch (arg) {
+ case PARSE_POST:
+ case PARSE_GET:
+ case PARSE_COOKIE:
+ if (PG(track_vars)) {
+ array_ptr = (pval *) emalloc(sizeof(pval));
+ array_init(array_ptr);
+ array_ptr->refcount=1;
+ array_ptr->is_ref=0;
+ switch (arg) {
+ case PARSE_POST:
+ _php3_hash_add(&EG(symbol_table), "HTTP_POST_VARS", sizeof("HTTP_POST_VARS"), &array_ptr, sizeof(pval *),NULL);
+ break;
+ case PARSE_GET:
+ _php3_hash_add(&EG(symbol_table), "HTTP_GET_VARS", sizeof("HTTP_GET_VARS"), &array_ptr, sizeof(pval *),NULL);
+ break;
+ case PARSE_COOKIE:
+ _php3_hash_add(&EG(symbol_table), "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS"), &array_ptr, sizeof(pval *),NULL);
+ break;
+ }
+ } else {
+ array_ptr=NULL;
+ }
+ break;
+ default:
+ array_ptr=NULL;
+ break;
+ }
+
+ if (arg == PARSE_POST) {
+ res = php3_getpost(array_ptr PLS_CC);
+ } else if (arg == PARSE_GET) { /* Get data */
+ var = GLOBAL(request_info).query_string;
+ if (var && *var) {
+ res = (char *) estrdup(var);
+ }
+ } else if (arg == PARSE_COOKIE) { /* Cookie data */
+ var = (char *)GLOBAL(request_info).cookies;
+ if (var && *var) {
+ res = (char *) estrdup(var);
+ }
+ } else if (arg == PARSE_STRING) { /* String data */
+ res = str;
+ }
+ if (!res) {
+ return;
+ }
+
+ if (arg == PARSE_COOKIE) {
+ var = strtok(res, ";");
+ } else if (arg == PARSE_POST) {
+ var = strtok(res, "&");
+ } else {
+ var = strtok(res, PG(arg_separator));
+ }
+
+ while (var) {
+ val = strchr(var, '=');
+ if (val) { /* have a value */
+ *val++ = '\0';
+ /* FIXME: XXX: not binary safe, discards returned length */
+ _php3_urldecode(var, strlen(var));
+ _php3_urldecode(val, strlen(val));
+ _php3_parse_gpc_data(val,var,array_ptr);
+ }
+ if (arg == PARSE_COOKIE) {
+ var = strtok(NULL, ";");
+ } else if (arg == PARSE_POST) {
+ var = strtok(NULL, "&");
+ } else {
+ var = strtok(NULL, PG(arg_separator));
+ }
+ }
+ efree(res);
+}
+
+
+void php3_TreatHeaders(void)
+{
+#if APACHE
+#if MODULE_MAGIC_NUMBER > 19961007
+ const char *s = NULL;
+#else
+ char *s = NULL;
+#endif
+ char *t;
+ char *user, *type;
+ int len;
+ char *escaped_str;
+ PLS_FETCH();
+
+ if (GLOBAL(php3_rqst)->headers_in)
+ s = table_get(GLOBAL(php3_rqst)->headers_in, "Authorization");
+ if (!s)
+ return;
+
+ /* Check to make sure that this URL isn't authenticated
+ using a traditional auth module mechanism */
+ if (auth_type(GLOBAL(php3_rqst))) {
+ /*php3_error(E_WARNING, "Authentication done by server module\n");*/
+ return;
+ }
+ if (strcmp(t=getword(GLOBAL(php3_rqst)->pool, &s, ' '), "Basic")) {
+ /* Client tried to authenticate using wrong auth scheme */
+ php3_error(E_WARNING, "client used wrong authentication scheme (%s)", t);
+ return;
+ }
+ t = uudecode(GLOBAL(php3_rqst)->pool, s);
+#if MODULE_MAGIC_NUMBER > 19961007
+ user = getword_nulls_nc(GLOBAL(php3_rqst)->pool, &t, ':');
+#else
+ user = getword(GLOBAL(php3_rqst)->pool, &t, ':');
+#endif
+ type = "Basic";
+
+ if (user) {
+ if (PG(magic_quotes_gpc)) {
+ escaped_str = _php3_addslashes(user, 0, &len, 0);
+ SET_VAR_STRINGL("PHP_AUTH_USER", escaped_str, len);
+ } else {
+ SET_VAR_STRING("PHP_AUTH_USER", estrdup(user));
+ }
+ }
+ if (t) {
+ if (PG(magic_quotes_gpc)) {
+ escaped_str = _php3_addslashes(t, 0, &len, 0);
+ SET_VAR_STRINGL("PHP_AUTH_PW", escaped_str, len);
+ } else {
+ SET_VAR_STRING("PHP_AUTH_PW", estrdup(t));
+ }
+ }
+ if (type) {
+ if (PG(magic_quotes_gpc)) {
+ escaped_str = _php3_addslashes(type, 0, &len, 0);
+ SET_VAR_STRINGL("PHP_AUTH_TYPE", escaped_str, len);
+ } else {
+ SET_VAR_STRING("PHP_AUTH_TYPE", estrdup(type));
+ }
+ }
+#endif
+#if FHTTPD
+ int i,len;
+ struct rline *l;
+ char *type;
+ char *escaped_str;
+
+ if(req && req->remote_user){
+ for(i=0; i < req->nlines; i++){
+ l=req->lines+i;
+ if((l->paramc > 1)&&!strcasecmp(l->params[0], "REMOTE_PW")){
+ type = "Basic";
+ if (PG(magic_quotes_gpc)) {
+ escaped_str = _php3_addslashes(type, 0, &len, 0);
+ SET_VAR_STRINGL("PHP_AUTH_TYPE", escaped_str, len);
+ escaped_str = _php3_addslashes(l->params[1], 0, &len, 0);
+ SET_VAR_STRINGL("PHP_AUTH_PW", escaped_str, len);
+ escaped_str = _php3_addslashes(req->remote_user, 0, &len, 0);
+ SET_VAR_STRINGL("PHP_AUTH_USER", escaped_str, len);
+
+ } else {
+ SET_VAR_STRING("PHP_AUTH_TYPE", estrdup(type));
+ SET_VAR_STRING("PHP_AUTH_PW", estrdup(l->params[1]));
+ SET_VAR_STRING("PHP_AUTH_USER", estrdup(req->remote_user));
+ }
+ i=req->nlines;
+ }
+ }
+ }
+#endif
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ext/standard/post.h b/ext/standard/post.h
new file mode 100644
index 0000000000..37920a8978
--- /dev/null
+++ b/ext/standard/post.h
@@ -0,0 +1,43 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP HTML Embedded Scripting Language Version 3.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+ +----------------------------------------------------------------------+
+ | This program is free software; you can redistribute it and/or modify |
+ | it under the terms of one of the following licenses: |
+ | |
+ | A) the GNU General Public License as published by the Free Software |
+ | Foundation; either version 2 of the License, or (at your option) |
+ | any later version. |
+ | |
+ | B) the PHP License as published by the PHP Development Team and |
+ | included in the distribution in the file: LICENSE |
+ | |
+ | This program is distributed in the hope that it will be useful, |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ | GNU General Public License for more details. |
+ | |
+ | You should have received a copy of both licenses referred to here. |
+ | If you did not, or have any questions about PHP licensing, please |
+ | contact core@php.net. |
+ +----------------------------------------------------------------------+
+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#ifndef _POST_H
+#define _POST_H
+
+#define PARSE_POST 0
+#define PARSE_GET 1
+#define PARSE_COOKIE 2
+#define PARSE_STRING 3
+
+extern void php3_treat_data(int arg, char *str);
+extern void php3_TreatHeaders(void);
+extern void _php3_parse_gpc_data(char *, char *, pval *track_vars_array);
+
+#endif
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 43457ba44a..b05605275c 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -37,7 +37,7 @@
#include <stdio.h>
#include "php.h"
#include "reg.h"
-#include "functions/post.h"
+#include "post.h"
#include "php3_string.h"
#if HAVE_SETLOCALE
#include <locale.h>
diff --git a/ext/standard/var.c b/ext/standard/var.c
index a602ee0eb7..feb277c4c3 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -36,7 +36,7 @@
#include "php.h"
#include "fopen-wrappers.h"
#include "reg.h"
-#include "functions/post.h"
+#include "post.h"
#include "php3_string.h"
#if HAVE_SETLOCALE
#include <locale.h>