[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-03-05 Thread Moriyoshi Koizumi
moriyoshi   Wed Mar  5 12:51:33 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed a small leak in the convert filter code
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.29 php4/ext/standard/filters.c:1.30
--- php4/ext/standard/filters.c:1.29Sun Mar  2 03:39:01 2003
+++ php4/ext/standard/filters.c Wed Mar  5 12:51:33 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.29 2003/03/02 08:39:01 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.30 2003/03/05 17:51:33 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -1507,6 +1507,8 @@
if (out_buf_size - ocnt  0) {
new_bucket = php_stream_bucket_new(stream, out_buf, 
(out_buf_size - ocnt), 1, inst-persistent TSRMLS_CC);
php_stream_bucket_append(buckets_out, new_bucket TSRMLS_CC);
+   } else {
+   pefree(out_buf, inst-persistent);
}
} else {
while (buckets_in-head != NULL) {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-03-02 Thread Moriyoshi Koizumi
moriyoshi   Sun Mar  2 03:39:01 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed my silly mistake in the filter code
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.28 php4/ext/standard/filters.c:1.29
--- php4/ext/standard/filters.c:1.28Mon Feb 24 17:41:55 2003
+++ php4/ext/standard/filters.c Sun Mar  2 03:39:01 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.28 2003/02/24 22:41:55 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.29 2003/03/02 08:39:01 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -1445,7 +1445,7 @@
char *pd;
size_t ocnt;
 
-   if (buckets_in-head == NULL  buckets_in-tail == NULL) {
+   if (flags != PSFS_FLAG_NORMAL) {
/* flush operation */
 
out_buf_size = 64;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-02-24 Thread Moriyoshi Koizumi
moriyoshi   Mon Feb 24 17:41:55 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed string.strip_tags filter so it reflects the change on php_strip_tags 
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.27 php4/ext/standard/filters.c:1.28
--- php4/ext/standard/filters.c:1.27Tue Feb 18 19:12:23 2003
+++ php4/ext/standard/filters.c Mon Feb 24 17:41:55 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.27 2003/02/19 00:12:23 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.28 2003/02/24 22:41:55 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -214,9 +214,8 @@
bucket = php_stream_bucket_make_writeable(buckets_in-head TSRMLS_CC);
consumed = bucket-buflen;

-   php_strip_tags(bucket-buf, bucket-buflen, (inst-state), (char 
*)inst-allowed_tags, inst-allowed_tags_len);
+   bucket-buflen = php_strip_tags(bucket-buf, bucket-buflen, 
(inst-state), (char *)inst-allowed_tags, inst-allowed_tags_len);

-   bucket-buflen = strlen(bucket-buf); 
php_stream_bucket_append(buckets_out, bucket TSRMLS_CC);
}
 
@@ -232,6 +231,8 @@
assert(thisfilter-abstract != NULL);
 
php_strip_tags_filter_dtor((php_strip_tags_filter *)thisfilter-abstract);
+
+   pefree(thisfilter-abstract, ((php_strip_tags_filter 
*)thisfilter-abstract)-persistent);
 }
 
 static php_stream_filter_ops strfilter_strip_tags_ops = {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-02-18 Thread Moriyoshi Koizumi
moriyoshi   Tue Feb 18 18:22:49 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Revived convert filter codes
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.24 php4/ext/standard/filters.c:1.25
--- php4/ext/standard/filters.c:1.24Mon Feb 17 20:22:21 2003
+++ php4/ext/standard/filters.c Tue Feb 18 18:22:49 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.24 2003/02/18 01:22:21 wez Exp $ */
+/* $Id: filters.c,v 1.25 2003/02/18 23:22:49 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -1016,14 +1016,9 @@
 /* }}} */
 
 typedef struct _php_convert_filter {
-   php_conv *write_cd;
-   php_conv *read_cd;
+   php_conv *cd;
int persistent;
char *filtername;
-
-   /* ring buffer for read operation */
-   char read_buf[4096];
-   size_t read_buf_left;
 } php_convert_filter;
 
 #define PHP_CONV_BASE64_ENCODE 1
@@ -1303,40 +1298,22 @@
 #undef GET_BOOL_PROP
 
 static int php_convert_filter_ctor(php_convert_filter *inst,
-   int write_conv_mode, HashTable *write_conv_opts,
-   int read_conv_mode, HashTable *read_conv_opts,
+   int conv_mode, HashTable *conv_opts,
const char *filtername, int persistent)
 {
-   php_conv *write_cd = NULL;
-   php_conv *read_cd = NULL;
-
inst-persistent = persistent;
-
inst-filtername = pestrdup(filtername, persistent);
 
-   if ((write_cd = php_conv_open(write_conv_mode, write_conv_opts, persistent)) 
== NULL) {
-   goto out_failure;
-   }
-
-   if ((read_cd = php_conv_open(read_conv_mode, read_conv_opts, persistent)) == 
NULL) {
+   if ((inst-cd = php_conv_open(conv_mode, conv_opts, persistent)) == NULL) {
goto out_failure;
}
 
-   inst-write_cd = write_cd;
-   inst-read_cd = read_cd;
-
-   inst-read_buf_left = 0;
-
return SUCCESS;
 
 out_failure:
-   if (write_cd != NULL) {
-   php_conv_dtor(write_cd);
-   pefree(write_cd, persistent);
-   }
-   if (read_cd != NULL) {
-   php_conv_dtor(read_cd);
-   pefree(read_cd, persistent);
+   if (inst-cd != NULL) {
+   php_conv_dtor(inst-cd);
+   pefree(inst-cd, persistent);
}
if (inst-filtername != NULL) {
pefree(inst-filtername, persistent);
@@ -1346,14 +1323,9 @@
 
 static void php_convert_filter_dtor(php_convert_filter *inst)
 {
-   if (inst-write_cd != NULL) {
-   php_conv_dtor(inst-write_cd);
-   pefree(inst-write_cd, inst-persistent);
-   }
-
-   if (inst-read_cd != NULL) {
-   php_conv_dtor(inst-read_cd);
-   pefree(inst-read_cd, inst-persistent);
+   if (inst-cd != NULL) {
+   php_conv_dtor(inst-cd);
+   pefree(inst-cd, inst-persistent);
}
 
if (inst-filtername != NULL) {
@@ -1370,183 +1342,162 @@
int flags
TSRMLS_DC)
 {
-   php_stream_bucket *bucket;
+   php_stream_bucket *bucket, *new_bucket;
size_t consumed = 0;
php_conv_err_t err;
php_convert_filter *inst = (php_convert_filter *)thisfilter-abstract;
+   char *out_buf;
+   size_t out_buf_size;
+   char *pd;
+   size_t ocnt;
+
+   if (buckets_in-head == NULL  buckets_in-tail == NULL) {
+   /* flush operation */
+
+   out_buf_size = 64;
+   out_buf = pemalloc(out_buf_size, inst-persistent);
+   ocnt = out_buf_size;
+   pd = out_buf;
 
-   while (thisfilter-buffer.head || buckets_in-head) {
-   /* take head off buffer first, then input brigade */
-   bucket = thisfilter-buffer.head ? thisfilter-buffer.head : 
buckets_in-head;
-   php_stream_bucket_unlink(bucket TSRMLS_CC);
-
-#if 0
-   err = php_conv_convert(inst-write_cd, ... )
-
-   /* update consumed by the number of bytes just used */
-   
-   /* give output bucket to next in chain */
-   php_stream_bucket_append(buckets_out, bucket TSRMLS_CC);
-   
-   if (only used part of buffer) {
-   bucket *left, *right;
-   php_stream_buffer_split(bucket, left, right, used_len 
TSRMLS_CC);
-   php_stream_buffer_delref(left); /* delete the part we consumed 
*/
-   php_stream_buffer_append(filter-buffer, right TSRMLS_CC);
-   break;
-   }
-#endif
-   }
-
-   if (bytes_consumed) {
-   *bytes_consumed = consumed;
-   }
-   
-   return PSFS_PASS_ON;
-}
-
-
-
-
-#if 0
-static size_t strfilter_convert_write(php_stream *stream, php_stream_filter 
*thisfilter,
-   const char *buf, 

[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-17 Thread Moriyoshi Koizumi
moriyoshi   Fri Jan 17 04:04:03 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Significant speed enhancements. I was underestimating the power of recent
  CPUs :)
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.20 php4/ext/standard/filters.c:1.21
--- php4/ext/standard/filters.c:1.20Thu Jan 16 15:59:07 2003
+++ php4/ext/standard/filters.c Fri Jan 17 04:04:02 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.20 2003/01/16 20:59:07 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.21 2003/01/17 09:04:02 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -533,6 +533,7 @@
/* do nothing */
 }
 
+#define bmask(a) (0x  (16 - a))
 static php_conv_err_t php_conv_base64_decode_convert(php_conv_base64_decode *inst, 
const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p)
 {
php_conv_err_t err;
@@ -545,12 +546,6 @@
 
const static unsigned int nbitsof_pack = 8;
 
-   static unsigned int bmask[17] = {
-   0x, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f,
-   0x00ff, 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff,
-   0x
-   };
-
if (in_pp == NULL || in_left_p == NULL) {
if (inst-eos || inst-urem_nbits == 0) { 
return SUCCESS;
@@ -580,7 +575,7 @@
} else {
urem_nbits -= pack_bcnt;
pack |= (urem  urem_nbits);
-   urem = bmask[urem_nbits];
+   urem = bmask(urem_nbits);
pack_bcnt = 0;
}
if (pack_bcnt  0) {
@@ -606,7 +601,7 @@
} else {
urem_nbits = 6 - pack_bcnt;
pack |= (i  urem_nbits);
-   urem = i  bmask[urem_nbits];
+   urem = i  bmask(urem_nbits);
pack_bcnt = 0;
}
} else if (ustat) {
@@ -648,6 +643,7 @@
 
return err;
 }
+#undef bmask
 /* }}} */
 
 /* {{{ php_conv_qprint_encode */



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-17 Thread Moriyoshi Koizumi
moriyoshi   Fri Jan 17 15:00:33 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed a quoted printable decoder so that it would conform to RFC2045.
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.21 php4/ext/standard/filters.c:1.22
--- php4/ext/standard/filters.c:1.21Fri Jan 17 04:04:02 2003
+++ php4/ext/standard/filters.c Fri Jan 17 15:00:31 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.21 2003/01/17 09:04:02 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.22 2003/01/17 20:00:31 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -865,11 +865,20 @@
 
int scan_stat;
unsigned int next_char;
+   const char *lbchars;
+   int lbchars_dup;
+   size_t lbchars_len;
+   int persistent;
+   unsigned int lb_ptr;
+   unsigned int lb_cnt;
 } php_conv_qprint_decode;
 
 static void php_conv_qprint_decode_dtor(php_conv_qprint_decode *inst)
 {
-   /* do nothing */
+   assert(inst != NULL);
+   if (inst-lbchars_dup  inst-lbchars != NULL) {
+   pefree((void *)inst-lbchars, inst-persistent);
+   }
 }
 
 static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *inst, 
const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p)
@@ -878,9 +887,13 @@
size_t icnt, ocnt;
unsigned char *ps, *pd;
unsigned int scan_stat;
-   unsigned int v;
+   unsigned int next_char;
+   unsigned int lb_ptr, lb_cnt;
 
-   if (in_pp == NULL || in_left_p == NULL) {
+   lb_ptr = inst-lb_ptr;
+   lb_cnt = inst-lb_cnt;
+
+   if ((in_pp == NULL || in_left_p == NULL)  lb_cnt == lb_ptr) {
if (inst-scan_stat != 0) {
return PHP_CONV_ERR_UNEXPECTED_EOS;
}
@@ -892,12 +905,14 @@
pd = (unsigned char *)(*out_pp);
ocnt = *out_left_p;
scan_stat = inst-scan_stat;
+   next_char = inst-next_char;
 
-   v = 0;
-
-   for (;icnt  0; icnt--) {
+   for (;;) {
switch (scan_stat) {
case 0: {
+   if (icnt = 0) {
+   goto out;
+   }
if (*ps == '=') {
scan_stat = 1;
} else {
@@ -908,41 +923,104 @@
*(pd++) = *ps;
ocnt--;
}
+   ps++, icnt--;
} break;
 
-   case 1: case 2: {
-   unsigned int nbl = (*ps = 'A' ? *ps - 0x37 : *ps - 
0x30);
+   case 1: {
+   if (icnt = 0) {
+   goto out;
+   }
+   if (*ps == ' ' || *ps == '\t') {
+   scan_stat = 4;
+   ps++, icnt--;
+   break;
+   } else if (lb_cnt  inst-lbchars_len 
+   *ps == (unsigned 
+char)inst-lbchars[lb_cnt]) {
+   lb_cnt++;
+   scan_stat = 5;
+   ps++, icnt--;
+   break;
+   }
+   } /* break is missing intentionally */
+
+   case 2: {
+   unsigned int nbl;
+   
+   if (icnt = 0) {
+   goto out;
+   }
+   nbl = (*ps = 'A' ? *ps - 0x37 : *ps - 0x30);
 
if (nbl  15) {
err = PHP_CONV_ERR_INVALID_SEQ;
goto out;
}
-   v = (v  4) | nbl;
+   next_char = (next_char  4) | nbl;
 
scan_stat++;
-   if (scan_stat == 3) {
-   if (ocnt  1) {
-   inst-next_char = v;
-   err = PHP_CONV_ERR_TOO_BIG;
-   goto out;
-   }
-   *(pd++) = v;
-   ocnt--;
-   scan_stat = 0;
+   ps++, icnt--;
+   if 

[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-16 Thread Moriyoshi Koizumi
moriyoshi   Thu Jan 16 15:59:08 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Finally fixed a qp encoder bug that line break characters that appear exactly
  at the end of the chunk lost in the output.
  # I bet no more problems will occur in quoted-printable encoder.
  # But I recognised the counterpart is still buggy due to RFC2045-incompliance.
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.19 php4/ext/standard/filters.c:1.20
--- php4/ext/standard/filters.c:1.19Wed Jan 15 10:05:17 2003
+++ php4/ext/standard/filters.c Thu Jan 16 15:59:07 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.19 2003/01/15 15:05:17 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.20 2003/01/16 20:59:07 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -680,11 +680,11 @@
 }
 
 #define NEXT_CHAR(ps, icnt, lb_ptr, lb_cnt, lbchars) \
-   ((lb_cnt)  (lb_ptr) ? (lbchars)[(lb_cnt)] : *(ps)) 
+   ((lb_ptr)  (lb_cnt) ? (lbchars)[(lb_ptr)] : *(ps)) 
 
 #define CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt) \
-   if ((lb_cnt)  (lb_ptr)) { \
-   (lb_cnt)++; \
+   if ((lb_ptr)  (lb_cnt)) { \
+   (lb_ptr)++; \
} else { \
(lb_cnt) = (lb_ptr) = 0; \
--(icnt); \
@@ -703,7 +703,12 @@
int opts;
static char qp_digits[] = 0123456789ABCDEF;
 
-   if (in_pp == NULL || in_left_p == NULL) {
+   line_ccnt = inst-line_ccnt;
+   opts = inst-opts;
+   lb_ptr = inst-lb_ptr;
+   lb_cnt = inst-lb_cnt;
+
+   if ((in_pp == NULL || in_left_p == NULL)  (lb_ptr =lb_cnt)) {
return PHP_CONV_ERR_SUCCESS;
}
 
@@ -711,19 +716,13 @@
icnt = *in_left_p;
pd = (unsigned char *)(*out_pp);
ocnt = *out_left_p;
-   line_ccnt = inst-line_ccnt;
-   opts = inst-opts;
-   lb_ptr = inst-lb_ptr;
-   lb_cnt = inst-lb_cnt;
 
-   while (icnt  0) {
+   for (;;) {
if (!(opts  PHP_CONV_QPRINT_OPT_BINARY)  inst-lbchars != NULL  
inst-lbchars_len  0) {
/* look ahead for the line break chars to make a right decision
 * how to consume incoming characters */
 
-   if (*ps == inst-lbchars[lb_cnt]) {
-   ps++;
-   icnt--;
+   if (icnt  0  *ps == inst-lbchars[lb_cnt]) {
lb_cnt++;
 
if (lb_cnt = inst-lbchars_len) {
@@ -742,9 +741,14 @@
line_ccnt = inst-line_len;
lb_ptr = lb_cnt = 0;
}
+   ps++, icnt--;
continue;
}
}
+
+   if (lb_ptr = lb_cnt  icnt = 0) {
+   break;
+   } 
 
c = NEXT_CHAR(ps, icnt, lb_ptr, lb_cnt, inst-lbchars);
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-15 Thread Moriyoshi Koizumi
moriyoshi   Wed Jan 15 10:05:18 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed a qp encoder bug that the constructor sometimes fails if
  line-breaking mode is off. 
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.18 php4/ext/standard/filters.c:1.19
--- php4/ext/standard/filters.c:1.18Tue Jan 14 11:42:18 2003
+++ php4/ext/standard/filters.c Wed Jan 15 10:05:17 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.18 2003/01/14 16:42:18 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.19 2003/01/15 15:05:17 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -838,7 +838,7 @@
 
 static php_conv_err_t php_conv_qprint_encode_ctor(php_conv_qprint_encode *inst, 
unsigned int line_len, const char *lbchars, size_t lbchars_len, int lbchars_dup, int 
opts, int persistent)
 {
-   if (line_len  4) {
+   if (line_len  4  lbchars != NULL) {
return PHP_CONV_ERR_TOO_BIG;
}
inst-_super.convert_op = (php_conv_convert_func) 
php_conv_qprint_encode_convert;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-14 Thread Moriyoshi Koizumi
moriyoshi   Tue Jan 14 11:42:19 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Added a new option force-encode-first to the quoted-printable encoder
  as per Wez's request. If enabled, the encoder forcefully does qp
  tranformation on every first character of lines in incoming stream.
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.17 php4/ext/standard/filters.c:1.18
--- php4/ext/standard/filters.c:1.17Mon Jan 13 20:27:57 2003
+++ php4/ext/standard/filters.c Tue Jan 14 11:42:18 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.17 2003/01/14 01:27:57 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.18 2003/01/14 16:42:18 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -665,7 +665,8 @@
unsigned int lb_cnt;
 } php_conv_qprint_encode;
 
-#define PHP_CONV_QPRINT_OPT_BINARY 0x0001
+#define PHP_CONV_QPRINT_OPT_BINARY 0x0001
+#define PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST 0x0002
 
 static void php_conv_qprint_encode_dtor(php_conv_qprint_encode *inst);
 static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *inst, 
const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p);
@@ -772,7 +773,7 @@
line_ccnt--;
CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt);
}
-   } else if ((c = 33  c = 60) || (c = 62  c = 126)) { 
+   } else if ((!(opts  PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST) || 
+line_ccnt  inst-line_len)  ((c = 33  c = 60) || (c = 62  c = 126))) { 
if (line_ccnt  2) {
if (ocnt  inst-lbchars_len + 1) {
err = PHP_CONV_ERR_TOO_BIG;
@@ -1172,10 +1173,12 @@
 
if (options != NULL) {
int opt_binary = 0;
+   int opt_force_encode_first = 0;
 
GET_STR_PROP(options, lbchars, lbchars_len, 
line-break-chars, 0);
GET_UINT_PROP(options, line_len, line-length);
GET_BOOL_PROP(options, opt_binary, binary); 
+   GET_BOOL_PROP(options, opt_force_encode_first, 
+force-encode-first); 
 
if (line_len  4) {
if (lbchars != NULL) {
@@ -1189,6 +1192,7 @@
}
}
opts |= (opt_binary ? PHP_CONV_QPRINT_OPT_BINARY : 0);
+   opts |= (opt_force_encode_first ? 
+PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST : 0);
}
retval = pemalloc(sizeof(php_conv_qprint_encode), persistent);
if (lbchars != NULL) {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-14 Thread Wez Furlong
It should be noted that this is only necessary for lines beginning with
the string From  which some mtas will mangle in transit, thus
rendering digital signatures invalid.

--Wez.

On Tue, 14 Jan 2003, Moriyoshi Koizumi wrote:

 moriyoshi Tue Jan 14 11:42:19 2003 EDT

   Modified files:
 /php4/ext/standardfilters.c
   Log:
   Added a new option force-encode-first to the quoted-printable encoder
   as per Wez's request. If enabled, the encoder forcefully does qp
   tranformation on every first character of lines in incoming stream.


 Index: php4/ext/standard/filters.c
 diff -u php4/ext/standard/filters.c:1.17 php4/ext/standard/filters.c:1.18
 --- php4/ext/standard/filters.c:1.17  Mon Jan 13 20:27:57 2003
 +++ php4/ext/standard/filters.c   Tue Jan 14 11:42:18 2003
 @@ -17,7 +17,7 @@
 +--+
  */

 -/* $Id: filters.c,v 1.17 2003/01/14 01:27:57 moriyoshi Exp $ */
 +/* $Id: filters.c,v 1.18 2003/01/14 16:42:18 moriyoshi Exp $ */

  #include php.h
  #include php_globals.h
 @@ -665,7 +665,8 @@
   unsigned int lb_cnt;
  } php_conv_qprint_encode;

 -#define PHP_CONV_QPRINT_OPT_BINARY 0x0001
 +#define PHP_CONV_QPRINT_OPT_BINARY 0x0001
 +#define PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST 0x0002

  static void php_conv_qprint_encode_dtor(php_conv_qprint_encode *inst);
  static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *inst, 
const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p);
 @@ -772,7 +773,7 @@
   line_ccnt--;
   CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt);
   }
 - } else if ((c = 33  c = 60) || (c = 62  c = 126)) {
 + } else if ((!(opts  PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST) || 
line_ccnt  inst-line_len)  ((c = 33  c = 60) || (c = 62  c = 126))) {
   if (line_ccnt  2) {
   if (ocnt  inst-lbchars_len + 1) {
   err = PHP_CONV_ERR_TOO_BIG;
 @@ -1172,10 +1173,12 @@

   if (options != NULL) {
   int opt_binary = 0;
 + int opt_force_encode_first = 0;

   GET_STR_PROP(options, lbchars, lbchars_len, 
line-break-chars, 0);
   GET_UINT_PROP(options, line_len, line-length);
   GET_BOOL_PROP(options, opt_binary, binary);
 + GET_BOOL_PROP(options, opt_force_encode_first, 
force-encode-first);

   if (line_len  4) {
   if (lbchars != NULL) {
 @@ -1189,6 +1192,7 @@
   }
   }
   opts |= (opt_binary ? PHP_CONV_QPRINT_OPT_BINARY : 0);
 + opts |= (opt_force_encode_first ? 
PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST : 0);
   }
   retval = pemalloc(sizeof(php_conv_qprint_encode), persistent);
   if (lbchars != NULL) {



 --
 PHP CVS Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-13 Thread Moriyoshi Koizumi
moriyoshi   Mon Jan 13 05:21:41 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  . Implemented a common filter parameter parsing function.
  # For example base64-encode.line-break-chars=--,base64-decode.blah=foobar 
  # will be parsed and splitted into a zval array as
  # array(2) {
  #   [base64-encode]= 
  #   array(1) {
  # [line-break-chars]=
  # string(2) --
  #   }
  #   [base64-decode]=
  #   array(1) {
  # [blah] =
  # string(6) foobar
  #   }
  # }
  . Added automatic line-breaking feature for base64 encode filter. This 
can be turned on by putting a option entry base64-encode.line-length
to the filter parameters.
  
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.13 php4/ext/standard/filters.c:1.14
--- php4/ext/standard/filters.c:1.13Sun Jan 12 16:05:22 2003
+++ php4/ext/standard/filters.c Mon Jan 13 05:21:40 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.13 2003/01/12 21:05:22 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.14 2003/01/13 10:21:40 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -213,7 +213,9 @@
PHP_CONV_ERR_UNKNOWN,
PHP_CONV_ERR_TOO_BIG,
PHP_CONV_ERR_INVALID_SEQ,
-   PHP_CONV_ERR_UNEXPECTED_EOS
+   PHP_CONV_ERR_UNEXPECTED_EOS,
+   PHP_CONV_ERR_EXISTS,
+   PHP_CONV_ERR_NOT_FOUND
 } php_conv_err_t;
 
 typedef struct _php_conv php_conv;
@@ -235,6 +237,12 @@
 
unsigned char erem[3];
size_t erem_len;
+   unsigned int line_ccnt;
+   unsigned int line_len;
+   const char *lbchars;
+   int lbchars_dup;
+   size_t lbchars_len;
+   int persistent;
 } php_conv_base64_encode;
 
 static php_conv_err_t php_conv_base64_encode_convert(php_conv_base64_encode *inst, 
const char **in_p, size_t *in_left, char **out_p, size_t *out_left);
@@ -259,134 +267,219 @@
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
 };
 
-static php_conv_err_t php_conv_base64_encode_ctor(php_conv_base64_encode *inst)
+static php_conv_err_t php_conv_base64_encode_ctor(php_conv_base64_encode *inst, 
+unsigned int line_len, const char *lbchars, size_t lbchars_len, int lbchars_dup, int 
+persistent)
 {
inst-_super.convert_op = (php_conv_convert_func) 
php_conv_base64_encode_convert;
inst-_super.dtor = (php_conv_dtor_func) php_conv_base64_encode_dtor;
inst-erem_len = 0;
+   inst-line_ccnt = line_len;
+   inst-line_len = line_len;
+   if (lbchars != NULL) {
+   inst-lbchars = (lbchars_dup ? pestrdup(lbchars, persistent) : 
+lbchars);
+   inst-lbchars_len = lbchars_len;
+   } else {
+   inst-lbchars = NULL;
+   }
+   inst-lbchars_dup = lbchars_dup;
+   inst-persistent = persistent;
return SUCCESS;
 }
 
 static void php_conv_base64_encode_dtor(php_conv_base64_encode *inst)
 {
-   /* do nothing */
+   assert(inst != NULL);
+   if (inst-lbchars_dup  inst-lbchars != NULL) {
+   pefree((void *)inst-lbchars, inst-persistent);
+   }
 }
 
-static php_conv_err_t php_conv_base64_encode_convert(php_conv_base64_encode *inst, 
const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p)
+static php_conv_err_t php_conv_base64_encode_flush(php_conv_base64_encode *inst, 
+const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p)
 {
-   register size_t ocnt, icnt;
-   register unsigned char *ps, *pd;
-   size_t nbytes_written;
+   volatile php_conv_err_t err = PHP_CONV_ERR_SUCCESS;
+   register unsigned char *pd;
+   register size_t ocnt;
+   unsigned int line_ccnt;
 
pd = (unsigned char *)(*out_pp);
ocnt = *out_left_p;
-   nbytes_written = 0;
+   line_ccnt = inst-line_ccnt;
 
-   if (in_pp != NULL  in_left_p != NULL) { 
-   ps = (unsigned char *)(*in_pp);
-   icnt = *in_left_p;
-   
-   /* consume the remainder first */
-   switch (inst-erem_len) {
-   case 1:
-   if (icnt = 2) {
-   if (ocnt  4) {
-   return PHP_CONV_ERR_TOO_BIG;
-   }
-   *(pd++) = b64_tbl_enc[(inst-erem[0]  2)];
-   *(pd++) = b64_tbl_enc[(unsigned 
char)(inst-erem[0]  4) | (ps[0]  4)];
-   *(pd++) = b64_tbl_enc[(unsigned char)(ps[0]  
2) | (ps[1]  6)];
-   *(pd++) = b64_tbl_enc[ps[1]];
-   ocnt -= 4;
-   ps += 2;
-   icnt -= 2;
-   inst-erem_len = 0;
-

[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-13 Thread Moriyoshi Koizumi
moriyoshi   Mon Jan 13 06:00:24 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed a silly segfault bug caused by lack of strict type checking
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.14 php4/ext/standard/filters.c:1.15
--- php4/ext/standard/filters.c:1.14Mon Jan 13 05:21:40 2003
+++ php4/ext/standard/filters.c Mon Jan 13 06:00:22 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.14 2003/01/13 10:21:40 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.15 2003/01/13 11:00:22 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -1358,7 +1358,7 @@
memcpy(buf, node_name, node_name_len);
buf[node_name_len] = '\0';
 
-   if (zend_hash_find(Z_ARRVAL_P(node), 
buf, node_name_len + 1, (void **)z_tmp) != SUCCESS) {
+   if (zend_hash_find(Z_ARRVAL_P(node), 
+buf, node_name_len + 1, (void **)z_tmp) != SUCCESS || Z_TYPE_PP(z_tmp) != IS_ARRAY) {
zval *new_node;

MAKE_STD_ZVAL(new_node);
@@ -1456,10 +1456,14 @@
write_conv_opts = read_conv_opts = NULL;
 
if (strcasecmp(dot, base64-encode) == 0) {
-   if (options != NULL  zend_hash_find(Z_ARRVAL_P(options), 
base64-encode, sizeof(base64-encode), (void **)tmp_zval_pp) == SUCCESS) {
+   if (options != NULL 
+   zend_hash_find(Z_ARRVAL_P(options), base64-encode, 
+sizeof(base64-encode), (void **)tmp_zval_pp) == SUCCESS 
+   Z_TYPE_PP(tmp_zval_pp) == IS_ARRAY) {
write_conv_opts = Z_ARRVAL_PP(tmp_zval_pp); 
}
-   if (options != NULL  zend_hash_find(Z_ARRVAL_P(options), 
base64-decode, sizeof(base64-decode), (void **)tmp_zval_pp) == SUCCESS) {
+   if (options != NULL 
+   zend_hash_find(Z_ARRVAL_P(options), base64-decode, 
+sizeof(base64-decode), (void **)tmp_zval_pp) == SUCCESS 
+   Z_TYPE_PP(tmp_zval_pp) == IS_ARRAY) {
read_conv_opts = Z_ARRVAL_PP(tmp_zval_pp);  
}
if (php_convert_filter_ctor(inst,
@@ -1470,10 +1474,14 @@
}   
retval = php_stream_filter_alloc(strfilter_convert_ops, inst, 
persistent);
} else if (strcasecmp(dot, base64-decode) == 0) {
-   if (options != NULL  zend_hash_find(Z_ARRVAL_P(options), 
base64-decode, sizeof(base64-decode), (void **)tmp_zval_pp) == SUCCESS) {
+   if (options != NULL 
+   zend_hash_find(Z_ARRVAL_P(options), base64-decode, 
+sizeof(base64-decode), (void **)tmp_zval_pp) == SUCCESS 
+   Z_TYPE_PP(tmp_zval_pp) == IS_ARRAY) {
write_conv_opts = Z_ARRVAL_PP(tmp_zval_pp); 
}
-   if (options != NULL  zend_hash_find(Z_ARRVAL_P(options), 
base64-encode, sizeof(base64-encode), (void **)tmp_zval_pp) == SUCCESS) {
+   if (options != NULL 
+   zend_hash_find(Z_ARRVAL_P(options), base64-encode, 
+sizeof(base64-encode), (void **)tmp_zval_pp) == SUCCESS 
+   Z_TYPE_PP(tmp_zval_pp) == IS_ARRAY) {
read_conv_opts = Z_ARRVAL_PP(tmp_zval_pp);  
}
if (php_convert_filter_ctor(inst,
@@ -1484,7 +1492,9 @@
}   
retval = php_stream_filter_alloc(strfilter_convert_ops, inst, 
persistent);
} else if (strcasecmp(dot, quoted-printable-encode) == 0) {
-   if (options != NULL  zend_hash_find(Z_ARRVAL_P(options), 
quoted-printable-encode, sizeof(quoted-printable-encode), (void **)tmp_zval_pp) 
== SUCCESS) {
+   if (options != NULL 
+   zend_hash_find(Z_ARRVAL_P(options), quoted-printable-encode, 
+sizeof(quoted-printable-encode), (void **)tmp_zval_pp) == SUCCESS 
+   Z_TYPE_PP(tmp_zval_pp) == IS_ARRAY) {
write_conv_opts = Z_ARRVAL_PP(tmp_zval_pp); 
}
if (options != NULL  zend_hash_find(Z_ARRVAL_P(options), 
quoted-printable-decode, sizeof(quoted-printable-decode), (void **)tmp_zval_pp) 
== SUCCESS) {
@@ -1498,10 +1508,14 @@
}   
retval = php_stream_filter_alloc(strfilter_convert_ops, inst, 
persistent);
} else if (strcasecmp(dot, quoted-printable-decode) == 0) {
-   if (options != NULL  zend_hash_find(Z_ARRVAL_P(options), 
quoted-printable-decode, sizeof(quoted-printable-decode), (void **)tmp_zval_pp) 
== SUCCESS) {
+   

Re: [PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-13 Thread Wez Furlong
I am going to alter the API so that you can pass a zval directly to the
filter implementation; this will make the code so much simpler.

I mentioned this last week, and I'd feel happier if there was less code
to maintain, so please consider reverting the parameter parsing commit.

Sorry if this makes all your effort for nothing,

--Wez.


On Mon, 13 Jan 2003, Moriyoshi Koizumi wrote:

 moriyoshi Mon Jan 13 05:21:41 2003 EDT

   Modified files:
 /php4/ext/standardfilters.c
   Log:
   . Implemented a common filter parameter parsing function.
   # For example base64-encode.line-break-chars=--,base64-decode.blah=foobar
   # will be parsed and splitted into a zval array as
   # array(2) {
   #   [base64-encode]=
   #   array(1) {
   # [line-break-chars]=
   # string(2) --
   #   }
   #   [base64-decode]=
   #   array(1) {
   # [blah] =
   # string(6) foobar
   #   }
   # }
   . Added automatic line-breaking feature for base64 encode filter. This
 can be turned on by putting a option entry base64-encode.line-length
 to the filter parameters.





-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-13 Thread Moriyoshi Koizumi
On Mon, Jan 13, 2003 at 01:28:27PM +, Wez Furlong wrote:
 I am going to alter the API so that you can pass a zval directly to the
 filter implementation; this will make the code so much simpler.
 
 I mentioned this last week, and I'd feel happier if there was less code
 to maintain, so please consider reverting the parameter parsing commit.
 
 Sorry if this makes all your effort for nothing,

I took your ongoing work for the new API into account and I consider
my parameter parsing code temporary. I mean once the API is frozen, 
I'll throw mine away and use that instead.

Anyway I hope the trashed code would help somehow somewhere :)

Moriyoshi
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-13 Thread Moriyoshi Koizumi
moriyoshi   Mon Jan 13 20:23:36 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed quoted-printable encoder so that it produces RFC2045 complicant
  output. As per this specification requirement, the constructor now accepts
  three options: binary (boolean), line-len (uint), line-break-chars (string).
   
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.15 php4/ext/standard/filters.c:1.16
--- php4/ext/standard/filters.c:1.15Mon Jan 13 06:00:22 2003
+++ php4/ext/standard/filters.c Mon Jan 13 20:23:35 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.15 2003/01/13 11:00:22 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.16 2003/01/14 01:23:35 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -653,22 +653,53 @@
 /* {{{ php_conv_qprint_encode */
 typedef struct _php_conv_qprint_encode {
php_conv _super;
+
+   int opts;
+   unsigned int line_ccnt;
+   unsigned int line_len;
+   const char *lbchars;
+   int lbchars_dup;
+   size_t lbchars_len;
+   int persistent;
+   unsigned int lb_ptr;
+   unsigned int lb_cnt;
 } php_conv_qprint_encode;
 
+#define PHP_CONV_QPRINT_OPT_BINARY 0x0001
+
 static void php_conv_qprint_encode_dtor(php_conv_qprint_encode *inst);
 static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *inst, 
const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p);
 
 static void php_conv_qprint_encode_dtor(php_conv_qprint_encode *inst)
 {
-   /* do nothing */
+   assert(inst != NULL);
+   if (inst-lbchars_dup  inst-lbchars != NULL) {
+   pefree((void *)inst-lbchars, inst-persistent);
+   }
 }
 
+#define NEXT_CHAR(ps, icnt, lb_ptr, lb_cnt, lbchars) \
+   ((lb_cnt)  (lb_ptr) ? (lbchars)[(lb_cnt)] : *(ps)) 
+
+#define CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt) \
+   if ((lb_cnt)  (lb_ptr)) { \
+   (lb_cnt)++; \
+   } else { \
+   (lb_cnt) = (lb_ptr) = 0; \
+   --(icnt); \
+   (ps)++; \
+   }
+
 static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *inst, 
const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p)
 {
php_conv_err_t err = PHP_CONV_ERR_SUCCESS;
unsigned char *ps, *pd;
size_t icnt, ocnt;
unsigned int c;
+   unsigned int line_ccnt;
+   unsigned int lb_ptr;
+   unsigned int lb_cnt;
+   int opts;
static char qp_digits[] = 0123456789ABCDEF;
 
if (in_pp == NULL || in_left_p == NULL) {
@@ -679,18 +710,106 @@
icnt = *in_left_p;
pd = (unsigned char *)(*out_pp);
ocnt = *out_left_p;
- 
-   for (; icnt  0; icnt--, ps++) {
-   c = *ps;
+   line_ccnt = inst-line_ccnt;
+   opts = inst-opts;
+   lb_ptr = inst-lb_ptr;
+   lb_cnt = inst-lb_cnt;
+
+   while (icnt  0) {
+   if (!(opts  PHP_CONV_QPRINT_OPT_BINARY)  inst-lbchars != NULL  
+inst-lbchars_len  0) {
+   /* look ahead for the line break chars to make a right decision
+* how to consume incoming characters */
+
+   if (*ps == inst-lbchars[lb_cnt]) {
+   ps++;
+   icnt--;
+   lb_cnt++;
+
+   if (lb_cnt = inst-lbchars_len) {
+   unsigned int i;
+
+   if (ocnt  lb_cnt) {
+   lb_cnt--;
+   err = PHP_CONV_ERR_TOO_BIG;
+   break;
+   }
+
+   for (i = 0; i  lb_cnt; i++) {
+   *(pd++) = inst-lbchars[i];
+   ocnt--;
+   }
+   line_ccnt = inst-line_len;
+   lb_ptr = lb_cnt = 0;
+   }
+   continue;
+   }
+   }
+
+   c = NEXT_CHAR(ps, icnt, lb_ptr, lb_cnt, inst-lbchars);
+
+   if (!(opts  PHP_CONV_QPRINT_OPT_BINARY)  (c == '\t' || c == ' ')) {
+   if (line_ccnt  2  inst-lbchars != NULL) {
+   if (ocnt  inst-lbchars_len + 1) {
+   err = PHP_CONV_ERR_TOO_BIG;
+   break;
+   }
+
+   *(pd++) = '=';
+   ocnt--;
+   line_ccnt--;
 
-   if ((c = 33  c = 60) || (c = 62  c = 

[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-13 Thread Moriyoshi Koizumi
moriyoshi   Mon Jan 13 20:27:57 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed small memory leak that occurs when the invalid line length is passed
  to the qprint ctor.
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.16 php4/ext/standard/filters.c:1.17
--- php4/ext/standard/filters.c:1.16Mon Jan 13 20:23:35 2003
+++ php4/ext/standard/filters.c Mon Jan 13 20:27:57 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.16 2003/01/14 01:23:35 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.17 2003/01/14 01:27:57 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -1264,6 +1264,9 @@
if (read_cd != NULL) {
php_conv_dtor(read_cd);
pefree(read_cd, persistent);
+   }
+   if (inst-filtername != NULL) {
+   pefree(inst-filtername, persistent);
}
return FAILURE;
 }



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-12 Thread Moriyoshi Koizumi
moriyoshi   Sun Jan 12 07:48:13 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  . Updated quoted-printable filter by a neater implementation.
  . Changed emalloc family functions to pemalloc ones for persistent filters. 
  . Changed base64 and quoted-printable filter names to convert.base64-encode,
convert.base64-decode, convert.quoted-printable-encode, and
convert.quoted-printable-decode respectively for the consistency that
may be requested later.
  
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.9 php4/ext/standard/filters.c:1.10
--- php4/ext/standard/filters.c:1.9 Wed Jan  8 18:44:38 2003
+++ php4/ext/standard/filters.c Sun Jan 12 07:48:13 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.9 2003/01/08 23:44:38 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.10 2003/01/12 12:48:13 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -206,7 +206,7 @@
 };
 /* }}} */
 
-/* {{{ base64 stream filter implementation */
+/* {{{ base64 / quoted_printable stream filter implementation */
 
 typedef enum _php_conv_err_t {
PHP_CONV_ERR_SUCCESS = SUCCESS,
@@ -552,69 +552,258 @@
 }
 /* }}} */
 
-typedef struct _php_base64_filter {
+/* {{{ php_conv_qprint_encode */
+typedef struct _php_conv_qprint_encode {
+   php_conv _super;
+} php_conv_qprint_encode;
+
+static void php_conv_qprint_encode_dtor(php_conv_qprint_encode *inst);
+static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *inst, 
+const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p);
+
+static void php_conv_qprint_encode_dtor(php_conv_qprint_encode *inst)
+{
+   /* do nothing */
+}
+
+static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *inst, 
+const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p)
+{
+   php_conv_err_t err = PHP_CONV_ERR_SUCCESS;
+   unsigned char *ps, *pd;
+   size_t icnt, ocnt;
+   unsigned int c;
+   static char qp_digits[] = 0123456789ABCDEF;
+
+   if (in_pp == NULL || in_left_p == NULL) {
+   return PHP_CONV_ERR_SUCCESS;
+   }
+
+   ps = (unsigned char *)(*in_pp);
+   icnt = *in_left_p;
+   pd = (unsigned char *)(*out_pp);
+   ocnt = *out_left_p;
+ 
+   for (; icnt  0; icnt--, ps++) {
+   c = *ps;
+
+   if ((c = 33  c = 60) || (c = 62  c = 126)) { 
+   if (ocnt  1) {
+   err = PHP_CONV_ERR_TOO_BIG;
+   break;
+   }
+   *(pd++) = c;
+   ocnt--;
+   } else {
+   if (ocnt  3) {
+   err = PHP_CONV_ERR_TOO_BIG;
+   break;
+   }
+   *(pd++) = '=';
+   *(pd++) = qp_digits[(c  4)];
+   *(pd++) = qp_digits[(c  0x0f)]; 
+   ocnt -= 3;
+   }
+   }
+
+   *in_pp = (const char *)ps;
+   *in_left_p = icnt;
+   *out_pp = (char *)pd;
+   *out_left_p = ocnt; 
+
+   return err;
+}
+
+static php_conv_err_t php_conv_qprint_encode_ctor(php_conv_qprint_encode *inst)
+{
+   inst-_super.convert_op = (php_conv_convert_func) 
+php_conv_qprint_encode_convert;
+   inst-_super.dtor = (php_conv_dtor_func) php_conv_qprint_encode_dtor;
+   return PHP_CONV_ERR_SUCCESS;
+}
+/* }}} */
+
+/* {{{ php_conv_qprint_decode */
+typedef struct _php_conv_qprint_decode {
+   php_conv _super;
+
+   int scan_stat;
+   unsigned int next_char;
+} php_conv_qprint_decode;
+
+static void php_conv_qprint_decode_dtor(php_conv_qprint_decode *inst)
+{
+   /* do nothing */
+}
+
+static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *inst, 
+const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p)
+{
+   php_conv_err_t err = PHP_CONV_ERR_SUCCESS;
+   size_t icnt, ocnt;
+   unsigned char *ps, *pd;
+   unsigned int scan_stat;
+   unsigned int v;
+
+   if (in_pp == NULL || in_left_p == NULL) {
+   if (inst-scan_stat != 0) {
+   return PHP_CONV_ERR_UNEXPECTED_EOS;
+   }
+   return PHP_CONV_ERR_SUCCESS;
+   }
+
+   ps = (unsigned char *)(*in_pp);
+   icnt = *in_left_p;
+   pd = (unsigned char *)(*out_pp);
+   ocnt = *out_left_p;
+   scan_stat = inst-scan_stat;
+
+   v = 0;
+
+   for (;icnt  0; icnt--) {
+   switch (scan_stat) {
+   case 0: {
+   if (*ps == '=') {
+   scan_stat = 1;
+   } else {
+   if (ocnt  1) {
+ 

[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-12 Thread Moriyoshi Koizumi
moriyoshi   Sun Jan 12 08:41:35 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed error msg format so it correctly reports the actual filter name
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.10 php4/ext/standard/filters.c:1.11
--- php4/ext/standard/filters.c:1.10Sun Jan 12 07:48:13 2003
+++ php4/ext/standard/filters.c Sun Jan 12 08:41:35 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.10 2003/01/12 12:48:13 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.11 2003/01/12 13:41:35 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -869,15 +869,15 @@
break;
 
case PHP_CONV_ERR_UNKNOWN:
-   php_error(E_WARNING, stream filter(%s): 
unknown error, thisfilter-fops-label, err);
+   php_error(E_WARNING, stream filter (%s): 
+unknown error, inst-filtername, err);
return 0;
 
case PHP_CONV_ERR_INVALID_SEQ:
-   php_error(E_WARNING, stream filter(%s): 
invalid base64 sequence, thisfilter-fops-label, err);
+   php_error(E_WARNING, stream filter (%s): 
+invalid base64 sequence, inst-filtername, err);
return 0;

case PHP_CONV_ERR_UNEXPECTED_EOS:
-   php_error(E_WARNING, stream filter(%s): 
unexpected end of stream, thisfilter-fops-label, err);
+   php_error(E_WARNING, stream filter (%s): 
+unexpected end of stream, inst-filtername, err);
return 0;
 
default:
@@ -923,15 +923,15 @@
 
switch (err) {
case PHP_CONV_ERR_UNKNOWN:
-   php_error(E_WARNING, stream filter(%s): 
unknown error, thisfilter-fops-label, err);
+   php_error(E_WARNING, stream filter (%s): 
+unknown error, inst-filtername, err);
return 0;
 
case PHP_CONV_ERR_INVALID_SEQ:
-   php_error(E_WARNING, stream filter(%s): 
invalid base64 sequence, thisfilter-fops-label, err);
+   php_error(E_WARNING, stream filter (%s): 
+invalid base64 sequence, inst-filtername, err);
return 0;
 
case PHP_CONV_ERR_UNEXPECTED_EOS:
-   php_error(E_WARNING, stream filter(%s): 
unexpected end of stream, thisfilter-fops-label, err);
+   php_error(E_WARNING, stream filter (%s): 
+unexpected end of stream, inst-filtername, err);
return 0;
 
default:
@@ -968,7 +968,7 @@
out_p = bucket_buf;
out_left = sizeof(bucket_buf);
} else {
-   php_error(E_WARNING, stream filter(%s): 
unknown error, thisfilter-fops-label);
+   php_error(E_WARNING, stream filter (%s): 
+unknown error, inst-filtername);
return 0;
}
}



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-12 Thread Moriyoshi Koizumi
moriyoshi   Sun Jan 12 08:46:11 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed infinite loop bug when an invalid quoted-printable escape sequence
  appears in the streem.
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.11 php4/ext/standard/filters.c:1.12
--- php4/ext/standard/filters.c:1.11Sun Jan 12 08:41:35 2003
+++ php4/ext/standard/filters.c Sun Jan 12 08:46:11 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.11 2003/01/12 13:41:35 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.12 2003/01/12 13:46:11 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -675,7 +675,8 @@
unsigned int nbl = (*ps = 'A' ? *ps - 0x37 : *ps - 
0x30);
 
if (nbl  15) {
-   return 0;
+   err = PHP_CONV_ERR_INVALID_SEQ;
+   goto out;
}
v = (v  4) | nbl;
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-12 Thread Moriyoshi Koizumi
moriyoshi   Sun Jan 12 16:05:23 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Fixed a bug of the base64 decoder that a sequence of intervening
  characters that are supposed to be ignored by the decoder cause output
  corruption. 
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.12 php4/ext/standard/filters.c:1.13
--- php4/ext/standard/filters.c:1.12Sun Jan 12 08:46:11 2003
+++ php4/ext/standard/filters.c Sun Jan 12 16:05:22 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.12 2003/01/12 13:46:11 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.13 2003/01/12 21:05:22 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -526,9 +526,6 @@
}
if ((pack_bcnt | ustat) == 0) {
if (ocnt  1) {
-   urem |= (pack  urem_nbits);
-   urem_nbits += 8;
-
err = PHP_CONV_ERR_TOO_BIG;
break;
}
@@ -537,6 +534,14 @@
pack = 0;
pack_bcnt = nbitsof_pack;
}
+   }
+
+   if (urem_nbits = pack_bcnt) {
+   urem |= (pack  (urem_nbits - pack_bcnt));
+   urem_nbits += (nbitsof_pack - pack_bcnt);
+   } else {
+   urem |= (pack  (pack_bcnt - urem_nbits));
+   urem_nbits += (nbitsof_pack - pack_bcnt);
}
 
inst-urem = urem;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-07 Thread Moriyoshi Koizumi
moriyoshi   Tue Jan  7 17:53:42 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Instances should not be freed in dtor()...
  
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.7 php4/ext/standard/filters.c:1.8
--- php4/ext/standard/filters.c:1.7 Tue Jan  7 17:52:24 2003
+++ php4/ext/standard/filters.c Tue Jan  7 17:53:42 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.7 2003/01/07 22:52:24 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.8 2003/01/07 22:53:42 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -265,8 +265,7 @@
 
 static void php_base64_filter_dtor(php_base64_filter *inst)
 {
-   assert(inst != NULL);
-   efree(inst);
+   /* do nothing */
 }
 
 static size_t strfilter_base64_write(php_stream *stream, php_stream_filter 
*thisfilter,
@@ -448,6 +447,9 @@
 static void strfilter_base64_dtor(php_stream_filter *thisfilter TSRMLS_DC)
 {
php_base64_filter_dtor((php_base64_filter *)thisfilter-abstract);
+
+   assert(thisfilter-abstract != NULL);
+   efree(thisfilter-abstract);
 }
 
 static php_stream_filter_ops strfilter_base64_ops = {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-07 Thread Moriyoshi Koizumi
moriyoshi   Tue Jan  7 17:52:24 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Made error msg format more consistent
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.6 php4/ext/standard/filters.c:1.7
--- php4/ext/standard/filters.c:1.6 Mon Jan  6 20:41:18 2003
+++ php4/ext/standard/filters.c Tue Jan  7 17:52:24 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.6 2003/01/07 01:41:18 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.7 2003/01/07 22:52:24 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -375,7 +375,7 @@
 
if (!(i  0xc0)) {
if (ustat) {
-   php_error(E_WARNING, stream 
filter(stream.base64): invalid base64 sequence);
+   php_error(E_WARNING, stream filter(%s): 
+invalid base64 sequence, thisfilter-fops-label);
return 0;
}
if (6 = pack_bcnt) {
@@ -390,7 +390,7 @@
}
} else if (ustat) {
if (pack_bcnt == 8 || pack_bcnt == 2) {
-   php_error(E_WARNING, stream 
filter(stream.base64): unexpected end of stream);
+   php_error(E_WARNING, stream filter(%s): 
+unexpected end of stream, thisfilter-fops-label);
return 0;
}
}
@@ -547,7 +547,7 @@
unsigned int nbl = (*ps = 'A' ? *ps - 0x37 : *ps - 
0x30);
 
if (nbl  15) {
-   php_error(E_WARNING, stream 
filter(stream.quoted-printable): invalid character sequence); 
+   php_error(E_WARNING, stream filter(%s): 
+invalid character sequence, thisfilter-fops-label); 
return 0;
}
v = (v  4) | nbl;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-06 Thread Moriyoshi Koizumi
moriyoshi   Mon Jan  6 19:03:26 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Implemented string.base64 stream filter
  @- Implemented string.base64 stream filter. (Moriyoshi)
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.4 php4/ext/standard/filters.c:1.5
--- php4/ext/standard/filters.c:1.4 Mon Jan  6 00:22:06 2003
+++ php4/ext/standard/filters.c Mon Jan  6 19:03:25 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.4 2003/01/06 05:22:06 pollita Exp $ */
+/* $Id: filters.c,v 1.5 2003/01/07 00:03:25 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -206,6 +206,280 @@
 };
 /* }}} */
 
+/* {{{ base64 stream filter implementation */
+typedef struct _php_base64_filter
+{
+   unsigned char erem[3];
+   size_t erem_len;
+   unsigned int urem;
+   unsigned int urem_nbits;
+   unsigned int ustat;
+} php_base64_filter;
+
+static unsigned char b64_tbl_enc[256] = {
+   'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+   'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+   'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+   'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/',
+   'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+   'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+   'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+   'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/',
+   'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+   'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+   'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+   'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/',
+   'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+   'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+   'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+   'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
+};
+
+static unsigned int b64_tbl_unenc[256] = {
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
+   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64,128, 64, 64,
+   64,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
+   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
+   64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+   41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
+};
+
+
+static int php_base64_filter_ctor(php_base64_filter *inst)
+{
+   inst-erem_len = 0;
+   inst-urem_nbits = 0;
+   inst-ustat = 0;
+   return SUCCESS;
+}
+
+static void php_base64_filter_dtor(php_base64_filter *inst)
+{
+   assert(inst != NULL);
+   efree(inst);
+}
+
+static size_t strfilter_base64_write(php_stream *stream, php_stream_filter 
+*thisfilter,
+   const char *buf, size_t count TSRMLS_DC)
+{
+   register size_t chunk_left, bcnt;
+   register unsigned char *ps, *pd;
+   size_t nbytes_written;
+   char chunk[1024];
+   php_base64_filter *inst = (php_base64_filter *)thisfilter-abstract;
+
+   bcnt = count;
+   ps = (unsigned char *)buf;
+   pd = chunk;
+   chunk_left = sizeof(chunk);
+   nbytes_written = 0;
+ 
+   /* consume the remainder first */
+   switch (inst-erem_len) {
+   case 1:
+   if (bcnt = 2) {
+   *(pd++) = b64_tbl_enc[(inst-erem[0]  2)];
+   *(pd++) = b64_tbl_enc[(unsigned char)(inst-erem[0]  
+4) | (ps[0]  4)];
+   *(pd++) = b64_tbl_enc[(unsigned char)(ps[0]  2) | 
+(ps[1]  6)];
+   *(pd++) = b64_tbl_enc[ps[1]];
+   chunk_left -= 4;
+   ps += 2;
+   bcnt -= 2;
+   inst-erem_len = 0;
+   }
+   break;
+
+   case 2: 

[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-06 Thread Moriyoshi Koizumi
moriyoshi   Mon Jan  6 20:41:18 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Implemented quoted-printable stream filter
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.5 php4/ext/standard/filters.c:1.6
--- php4/ext/standard/filters.c:1.5 Mon Jan  6 19:03:25 2003
+++ php4/ext/standard/filters.c Mon Jan  6 20:41:18 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.5 2003/01/07 00:03:25 moriyoshi Exp $ */
+/* $Id: filters.c,v 1.6 2003/01/07 01:41:18 moriyoshi Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -480,6 +480,112 @@
 };
 /* }}} */
 
+/* {{{ quoted-printable stream filter implementation */
+
+static size_t strfilter_quoted_printable_write(php_stream *stream, php_stream_filter 
+*thisfilter,
+   const char *buf, size_t count TSRMLS_DC)
+{
+   char chunk[4096];
+   size_t chunk_len;
+   unsigned char *ps;
+   unsigned int bcnt;
+   static char qp_digits[] = 0123456789ABCDEF;
+
+   chunk_len = 0;
+
+   ps = (unsigned char *)buf;
+   for (bcnt = count; bcnt  0; bcnt--) {
+   unsigned int c = *(ps++);
+
+   if ((c = 33  c = 60) || (c = 62  c = 126)) { 
+   if (chunk_len = sizeof(chunk)) {
+   php_stream_filter_write_next(stream, thisfilter, 
+chunk, chunk_len);
+   chunk_len = 0;
+   }
+   chunk[chunk_len++] = c;
+   } else {
+   if (chunk_len  sizeof(chunk) - 3) {
+   php_stream_filter_write_next(stream, thisfilter, 
+chunk, chunk_len);
+   chunk_len = 0;
+   }
+   chunk[chunk_len++] = '=';
+   chunk[chunk_len++] = qp_digits[(c  4)];
+   chunk[chunk_len++] = qp_digits[(c  0x0f)]; 
+   }
+   }
+   php_stream_filter_write_next(stream, thisfilter, chunk, chunk_len);
+
+   return count;
+}
+
+static size_t strfilter_quoted_printable_read(php_stream *stream, php_stream_filter 
+*thisfilter,
+   char *buf, size_t count TSRMLS_DC)
+{
+   size_t nbytes_decoded;
+   size_t bcnt;
+   unsigned char *ps, *pd;
+   unsigned int scan_stat = (unsigned int)thisfilter-abstract;
+   unsigned int v;
+
+   bcnt = php_stream_filter_read_next(stream, thisfilter, buf, count);
+   nbytes_decoded = 0; 
+   ps = pd = (unsigned char *)buf;
+   v = 0;
+
+   for (;bcnt  0; bcnt--) {
+   switch (scan_stat) {
+   case 0:
+   if (*ps == '=') {
+   scan_stat = 1;
+   } else {
+   *(pd++) = *ps;
+   nbytes_decoded++;
+   }
+   break;
+
+   case 1: case 2: {
+   unsigned int nbl = (*ps = 'A' ? *ps - 0x37 : *ps - 
+0x30);
+
+   if (nbl  15) {
+   php_error(E_WARNING, stream 
+filter(stream.quoted-printable): invalid character sequence); 
+   return 0;
+   }
+   v = (v  4) | nbl;
+
+   scan_stat++;
+   if (scan_stat == 3) {
+   *(pd++) = v;
+   nbytes_decoded++;
+   scan_stat = 0;
+   }
+   }
+   }
+   ps++;
+   }
+   (unsigned int)thisfilter-abstract = scan_stat;
+   return nbytes_decoded;
+}
+
+static php_stream_filter_ops strfilter_quoted_printable_ops = {
+   strfilter_quoted_printable_write,
+   strfilter_quoted_printable_read,
+   commonfilter_nop_flush,
+   commonfilter_nop_eof,
+   NULL,
+   string.quoted-printable
+};
+
+static php_stream_filter *strfilter_quoted_printable_create(const char *filtername, 
+const char *filterparams,
+   int filterparamslen, int persistent TSRMLS_DC)
+{
+   return php_stream_filter_alloc(strfilter_quoted_printable_ops, 0, persistent);
+}
+
+static php_stream_filter_factory strfilter_quoted_printable_factory = {
+   strfilter_quoted_printable_create
+};
+/* }}} */
+
 static const struct {
php_stream_filter_ops *ops;
php_stream_filter_factory *factory;
@@ -488,6 +594,7 @@
{ strfilter_toupper_ops, strfilter_toupper_factory },
{ strfilter_tolower_ops, strfilter_tolower_factory },
{ strfilter_base64_ops, strfilter_base64_factory 

[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-05 Thread Sara Golemon
pollita Mon Jan  6 00:22:06 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Added string.toupper and string.tolower filters and generalized non-op filter methods
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.3 php4/ext/standard/filters.c:1.4
--- php4/ext/standard/filters.c:1.3 Wed Jan  1 07:36:06 2003
+++ php4/ext/standard/filters.c Mon Jan  6 00:22:06 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.3 2003/01/01 12:36:06 sebastian Exp $ */
+/* $Id: filters.c,v 1.4 2003/01/06 05:22:06 pollita Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -25,6 +25,18 @@
 #include ext/standard/file.h
 #include ext/standard/php_string.h
 
+/* {{{ common no-opperation methods */
+static int commonfilter_nop_flush(php_stream *stream, php_stream_filter *thisfilter, 
+int closing TSRMLS_DC)
+{
+   return php_stream_filter_flush_next(stream, thisfilter, closing);
+}
+
+static int commonfilter_nop_eof(php_stream *stream, php_stream_filter *thisfilter 
+TSRMLS_DC)
+{
+   return php_stream_filter_eof_next(stream, thisfilter);
+}
+/* }}} */
+
 /* {{{ rot13 stream filter implementation */
 static char rot13_from[] = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ;
 static char rot13_to[] = nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM;
@@ -63,21 +75,11 @@
return read;
 }
 
-static int strfilter_rot13_flush(php_stream *stream, php_stream_filter *thisfilter, 
int closing TSRMLS_DC)
-{
-   return php_stream_filter_flush_next(stream, thisfilter, closing);
-}
-
-static int strfilter_rot13_eof(php_stream *stream, php_stream_filter *thisfilter 
TSRMLS_DC)
-{
-   return php_stream_filter_eof_next(stream, thisfilter);
-}
-
 static php_stream_filter_ops strfilter_rot13_ops = {
strfilter_rot13_write,
strfilter_rot13_read,
-   strfilter_rot13_flush,
-   strfilter_rot13_eof,
+   commonfilter_nop_flush,
+   commonfilter_nop_eof,
NULL,
string.rot13
 };
@@ -93,11 +95,124 @@
 };
 /* }}} */
 
+/* {{{ string.toupper / string.tolower stream filter implementation */
+static char lowercase[] = abcdefghijklmnopqrstuvwxyz;
+static char uppercase[] = ABCDEFGHIJKLMNOPQRSTUVWXYZ;
+
+static size_t strfilter_toupper_write(php_stream *stream, php_stream_filter 
+*thisfilter,
+   const char *buf, size_t count TSRMLS_DC)
+{
+   char tmpbuf[1024];
+   size_t chunk;
+   size_t wrote = 0;
+
+   while (count  0) {
+   chunk = count;
+   if (chunk  sizeof(tmpbuf))
+   chunk = sizeof(tmpbuf);
+
+   PHP_STRLCPY(tmpbuf, buf, sizeof(tmpbuf), chunk);
+   buf += chunk;
+   count -= chunk;
+
+   php_strtr(tmpbuf, chunk, lowercase, uppercase, 26);
+   wrote += php_stream_filter_write_next(stream, thisfilter, tmpbuf, 
+chunk);
+   }
+
+   return wrote;
+}
+
+static size_t strfilter_tolower_write(php_stream *stream, php_stream_filter 
+*thisfilter,
+   const char *buf, size_t count TSRMLS_DC)
+{
+   char tmpbuf[1024];
+   size_t chunk;
+   size_t wrote = 0;
+
+   while (count  0) {
+   chunk = count;
+   if (chunk  sizeof(tmpbuf))
+   chunk = sizeof(tmpbuf);
+
+   PHP_STRLCPY(tmpbuf, buf, sizeof(tmpbuf), chunk);
+   buf += chunk;
+   count -= chunk;
+
+   php_strtr(tmpbuf, chunk, uppercase, lowercase, 26);
+   wrote += php_stream_filter_write_next(stream, thisfilter, tmpbuf, 
+chunk);
+   }
+
+   return wrote;
+}
+
+static size_t strfilter_toupper_read(php_stream *stream, php_stream_filter 
+*thisfilter,
+   char *buf, size_t count TSRMLS_DC)
+{
+   size_t read;
+
+   read = php_stream_filter_read_next(stream, thisfilter, buf, count);
+   php_strtr(buf, read, lowercase, uppercase, 26);
+
+   return read;
+}
+
+static size_t strfilter_tolower_read(php_stream *stream, php_stream_filter 
+*thisfilter,
+   char *buf, size_t count TSRMLS_DC)
+{
+   size_t read;
+
+   read = php_stream_filter_read_next(stream, thisfilter, buf, count);
+   php_strtr(buf, read, uppercase, lowercase, 26);
+
+   return read;
+}
+
+static php_stream_filter_ops strfilter_toupper_ops = {
+   strfilter_toupper_write,
+   strfilter_toupper_read,
+   commonfilter_nop_flush,
+   commonfilter_nop_eof,
+   NULL,
+   string.toupper
+};
+
+static php_stream_filter_ops strfilter_tolower_ops = {
+   strfilter_tolower_write,
+   strfilter_tolower_read,
+   commonfilter_nop_flush,
+   commonfilter_nop_eof,
+   NULL,
+   string.tolower
+};
+
+static php_stream_filter *strfilter_toupper_create(const char *filtername, const char 
+*filterparams,
+   int 

[PHP-CVS] cvs: php4 /ext/standard filters.c

2003-01-01 Thread Wez Furlong
wez Wed Jan  1 06:21:40 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c 
  Log:
  Tidy up
  
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.1 php4/ext/standard/filters.c:1.2
--- php4/ext/standard/filters.c:1.1 Wed Jan  1 06:04:44 2003
+++ php4/ext/standard/filters.c Wed Jan  1 06:21:40 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.1 2003/01/01 11:04:44 wez Exp $ */
+/* $Id: filters.c,v 1.2 2003/01/01 11:21:40 wez Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -97,9 +97,11 @@
php_stream_filter_factory *factory;
 } standard_filters[] = {
{ strfilter_rot13_ops, strfilter_rot13_factory },
+   /* additional filters to go here */
{ NULL, NULL }
 };
 
+/* {{{ filter MINIT and MSHUTDOWN */
 PHP_MINIT_FUNCTION(standard_filters)
 {
int i;
@@ -112,7 +114,6 @@
return FAILURE;
}
}
-
return SUCCESS;
 }
 
@@ -125,6 +126,7 @@
}
return SUCCESS;
 }
+/* }}} */
 
 /*
  * Local variables:



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard filters.c user_filters.c

2003-01-01 Thread Sebastian Bergmann
sebastian   Wed Jan  1 07:36:06 2003 EDT

  Modified files:  
/php4/ext/standard  filters.c user_filters.c 
  Log:
  Fix warnings.
  
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.2 php4/ext/standard/filters.c:1.3
--- php4/ext/standard/filters.c:1.2 Wed Jan  1 06:21:40 2003
+++ php4/ext/standard/filters.c Wed Jan  1 07:36:06 2003
@@ -17,12 +17,13 @@
+--+
 */
 
-/* $Id: filters.c,v 1.2 2003/01/01 11:21:40 wez Exp $ */
+/* $Id: filters.c,v 1.3 2003/01/01 12:36:06 sebastian Exp $ */
 
 #include php.h
 #include php_globals.h
 #include ext/standard/basic_functions.h
 #include ext/standard/file.h
+#include ext/standard/php_string.h
 
 /* {{{ rot13 stream filter implementation */
 static char rot13_from[] = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ;
Index: php4/ext/standard/user_filters.c
diff -u php4/ext/standard/user_filters.c:1.2 php4/ext/standard/user_filters.c:1.3
--- php4/ext/standard/user_filters.c:1.2Wed Jan  1 06:04:44 2003
+++ php4/ext/standard/user_filters.cWed Jan  1 07:36:06 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: user_filters.c,v 1.2 2003/01/01 11:04:44 wez Exp $ */
+/* $Id: user_filters.c,v 1.3 2003/01/01 12:36:06 sebastian Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -324,7 +324,6 @@
zval *obj, *zfilter;
zval func_name;
zval *retval = NULL;
-   zval **tmp; 

/* some sanity checks */
if (persistent) {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php