LTP GCOV extension - code coverage report
Current view: directory - ext/standard - quot_print.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 76
Code covered: 0.0 % Executed lines: 0
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 5                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2007 The PHP Group                                |
       6                 :    +----------------------------------------------------------------------+
       7                 :    | This source file is subject to version 3.01 of the PHP license,      |
       8                 :    | that is bundled with this package in the file LICENSE, and is        |
       9                 :    | available through the world-wide-web at the following url:           |
      10                 :    | http://www.php.net/license/3_01.txt                                  |
      11                 :    | If you did not receive a copy of the PHP license and are unable to   |
      12                 :    | obtain it through the world-wide-web, please send a note to          |
      13                 :    | license@php.net so we can mail you a copy immediately.               |
      14                 :    +----------------------------------------------------------------------+
      15                 :    | Author: Kirill Maximov <kir@actimind.com>                            |
      16                 :    +----------------------------------------------------------------------+
      17                 :  */
      18                 : 
      19                 : /* $Id: quot_print.c,v 1.29.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */
      20                 : 
      21                 : #include <stdlib.h>
      22                 : 
      23                 : #ifdef HAVE_UNISTD_H
      24                 : #include <unistd.h>
      25                 : #endif
      26                 : #include <string.h>
      27                 : #include <errno.h>
      28                 : 
      29                 : #include "php.h"
      30                 : #include "quot_print.h"
      31                 : 
      32                 : #include <stdio.h>
      33                 : 
      34                 : /*
      35                 : *  Converting HEX char to INT value
      36                 : */
      37                 : static char php_hex2int(int c)
      38               0 : {
      39               0 :         if (isdigit(c)) {
      40               0 :                 return c - '0';
      41                 :         }
      42               0 :         else if (c >= 'A' && c <= 'F') {
      43               0 :                 return c - 'A' + 10;
      44                 :         }
      45               0 :         else if (c >= 'a' && c <= 'f') {
      46               0 :                 return c - 'a' + 10;
      47                 :         }
      48                 :         else {
      49               0 :                 return -1;
      50                 :         }
      51                 : }
      52                 : 
      53                 : PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length, int replace_us_by_ws)
      54               0 : {
      55                 :         register unsigned int i;
      56                 :         register unsigned const char *p1;
      57                 :         register unsigned char *p2;
      58                 :         register unsigned int h_nbl, l_nbl;
      59                 : 
      60                 :         size_t decoded_len, buf_size;
      61                 :         unsigned char *retval;
      62                 : 
      63                 :         static unsigned int hexval_tbl[256] = {
      64                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 32, 16, 64, 64, 16, 64, 64,
      65                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      66                 :                 32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      67                 :                  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 64, 64, 64, 64, 64, 64,
      68                 :                 64, 10, 11, 12, 13, 14, 15, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      69                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      70                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      71                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      72                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      73                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      74                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      75                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      76                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      77                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      78                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      79                 :                 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
      80                 :         };
      81                 : 
      82               0 :         if (replace_us_by_ws) {
      83               0 :                 replace_us_by_ws = '_';
      84                 :         }
      85                 : 
      86               0 :         i = length, p1 = str; buf_size = length;
      87                 : 
      88               0 :         while (i > 1 && *p1 != '\0') {
      89               0 :                 if (*p1 == '=') {
      90               0 :                         buf_size -= 2;
      91               0 :                         p1++;
      92               0 :                         i--;
      93                 :                 }
      94               0 :                 p1++;
      95               0 :                 i--;
      96                 :         }
      97                 : 
      98               0 :         retval = emalloc(buf_size + 1);
      99               0 :         i = length; p1 = str; p2 = retval;
     100               0 :         decoded_len = 0;
     101                 : 
     102               0 :         while (i > 0 && *p1 != '\0') {
     103               0 :                 if (*p1 == '=') {
     104               0 :                         i--, p1++;
     105               0 :                         if (i == 0 || *p1 == '\0') {
     106                 :                                 break;
     107                 :                         }
     108               0 :                         h_nbl = hexval_tbl[*p1];
     109               0 :                         if (h_nbl < 16) {
     110                 :                                 /* next char should be a hexadecimal digit */
     111               0 :                                 if ((--i) == 0 || (l_nbl = hexval_tbl[*(++p1)]) >= 16) {
     112               0 :                                         efree(retval);
     113               0 :                                         return NULL;
     114                 :                                 }
     115               0 :                                 *(p2++) = (h_nbl << 4) | l_nbl, decoded_len++;
     116               0 :                                 i--, p1++;
     117               0 :                         } else if (h_nbl < 64) {
     118                 :                                 /* soft line break */
     119               0 :                                 while (h_nbl == 32) {
     120               0 :                                         if (--i == 0 || (h_nbl = hexval_tbl[*(++p1)]) == 64) {
     121               0 :                                                 efree(retval);
     122               0 :                                                 return NULL;
     123                 :                                         }
     124                 :                                 }
     125               0 :                                 if (p1[0] == '\r' && i >= 2 && p1[1] == '\n') {
     126               0 :                                         i--, p1++;
     127                 :                                 }
     128               0 :                                 i--, p1++;
     129                 :                         } else {
     130               0 :                                 efree(retval);
     131               0 :                                 return NULL;
     132                 :                         }
     133                 :                 } else {
     134               0 :                         *(p2++) = (replace_us_by_ws == *p1 ? '\x20': *p1);
     135               0 :                         i--, p1++, decoded_len++;
     136                 :                 }
     137                 :         }
     138                 : 
     139               0 :         *p2 = '\0';
     140               0 :         *ret_length = decoded_len;
     141               0 :         return retval;
     142                 : }
     143                 : 
     144                 : 
     145                 : /*
     146                 : *
     147                 : * Decoding  Quoted-printable string.
     148                 : *
     149                 : */
     150                 : /* {{{ proto string quoted_printable_decode(string str)
     151                 :    Convert a quoted-printable string to an 8 bit string */
     152                 : PHP_FUNCTION(quoted_printable_decode)
     153               0 : {
     154                 :         zval **arg1;
     155                 :         char *str_in, *str_out;
     156               0 :         int i = 0, j = 0, k;
     157                 : 
     158               0 :         if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
     159               0 :                 WRONG_PARAM_COUNT;
     160                 :         }
     161               0 :         convert_to_string_ex(arg1);
     162                 :     
     163               0 :         if (Z_STRLEN_PP(arg1) == 0) {
     164                 :                 /* shortcut */
     165               0 :                 RETURN_EMPTY_STRING();
     166                 :         }
     167                 : 
     168               0 :         str_in = Z_STRVAL_PP(arg1);
     169               0 :         str_out = emalloc(Z_STRLEN_PP(arg1) + 1);
     170               0 :         while (str_in[i]) {
     171               0 :                 switch (str_in[i]) {
     172                 :                 case '=':
     173               0 :                         if (str_in[i + 1] && str_in[i + 2] && 
     174                 :                                 isxdigit((int) str_in[i + 1]) && 
     175                 :                                 isxdigit((int) str_in[i + 2]))
     176                 :                         {
     177               0 :                                 str_out[j++] = (php_hex2int((int) str_in[i + 1]) << 4) 
     178                 :                                                 + php_hex2int((int) str_in[i + 2]);
     179               0 :                                 i += 3;
     180                 :                         } else  /* check for soft line break according to RFC 2045*/ {
     181               0 :                                 k = 1;
     182               0 :                                 while (str_in[i + k] && ((str_in[i + k] == 32) || (str_in[i + k] == 9))) {
     183                 :                                         /* Possibly, skip spaces/tabs at the end of line */
     184               0 :                                         k++;
     185                 :                                 }
     186               0 :                                 if (!str_in[i + k]) {
     187                 :                                         /* End of line reached */
     188               0 :                                         i += k;
     189                 :                                 }
     190               0 :                                 else if ((str_in[i + k] == 13) && (str_in[i + k + 1] == 10)) {
     191                 :                                         /* CRLF */
     192               0 :                                         i += k + 2;
     193                 :                                 }
     194               0 :                                 else if ((str_in[i + k] == 13) || (str_in[i + k] == 10)) {
     195                 :                                         /* CR or LF */
     196               0 :                                         i += k + 1;
     197                 :                                 }
     198                 :                                 else {
     199               0 :                                         str_out[j++] = str_in[i++];
     200                 :                                 }
     201                 :                         }
     202               0 :                         break;
     203                 :                 default:
     204               0 :                         str_out[j++] = str_in[i++];
     205                 :                 }
     206                 :         }
     207               0 :         str_out[j] = '\0';
     208                 :     
     209               0 :         RETVAL_STRINGL(str_out, j, 0);
     210                 : }
     211                 : /* }}} */
     212                 : 
     213                 : /*
     214                 :  * Local variables:
     215                 :  * tab-width: 4
     216                 :  * c-basic-offset: 4
     217                 :  * End:
     218                 :  * vim600: sw=4 ts=4 fdm=marker
     219                 :  * vim<600: sw=4 ts=4
     220                 :  */

Generated by: LTP GCOV extension version 1.5