LCOV - code coverage report
Current view: top level - lib/util/charset - weird.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 0 59 0.0 %
Date: 2024-02-28 12:06:22 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    Samba module with developer tools
       4             :    Copyright (C) Andrew Tridgell 2001
       5             :    Copyright (C) Jelmer Vernooij 2002
       6             :    
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             :    
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             :    
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "replace.h"
      22             : #include "charset_proto.h"
      23             : 
      24             : #ifdef DEVELOPER
      25             : 
      26             : static struct {
      27             :         char from;
      28             :         const char *to;
      29             :         int len;
      30             : } weird_table[] = {
      31             :         {
      32             :                 .from = 'q',
      33             :                 .to   = "^q^",
      34             :                 .len  = 3,
      35             :         },
      36             :         {
      37             :                 .from = 'Q',
      38             :                 .to   = "^Q^",
      39             :                 .len  = 3,
      40             :         },
      41             :         {
      42             :                 .len = 0,
      43             :         }
      44             : };
      45             : 
      46           0 : size_t weird_pull(void *cd, const char **inbuf, size_t *inbytesleft,
      47             :                   char **outbuf, size_t *outbytesleft)
      48             : {
      49           0 :         while (*inbytesleft >= 1 && *outbytesleft >= 2) {
      50             :                 int i;
      51           0 :                 int done = 0;
      52           0 :                 for (i=0;weird_table[i].from;i++) {
      53           0 :                         if (strncmp((*inbuf), 
      54             :                                     weird_table[i].to, 
      55           0 :                                     weird_table[i].len) == 0) {
      56           0 :                                 if (*inbytesleft < weird_table[i].len) {
      57           0 :                                         abort();
      58             :                                 }
      59             : 
      60           0 :                                 (*outbuf)[0] = weird_table[i].from;
      61           0 :                                 (*outbuf)[1] = 0;
      62           0 :                                 (*inbytesleft)  -= weird_table[i].len;
      63           0 :                                 (*outbytesleft) -= 2;
      64           0 :                                 (*inbuf)  += weird_table[i].len;
      65           0 :                                 (*outbuf) += 2;
      66           0 :                                 done = 1;
      67           0 :                                 break;
      68             :                         }
      69             :                 }
      70           0 :                 if (done) continue;
      71           0 :                 (*outbuf)[0] = (*inbuf)[0];
      72           0 :                 (*outbuf)[1] = 0;
      73           0 :                 (*inbytesleft)  -= 1;
      74           0 :                 (*outbytesleft) -= 2;
      75           0 :                 (*inbuf)  += 1;
      76           0 :                 (*outbuf) += 2;
      77             :         }
      78             : 
      79           0 :         if (*inbytesleft > 0) {
      80           0 :                 errno = E2BIG;
      81           0 :                 return -1;
      82             :         }
      83             :         
      84           0 :         return 0;
      85             : }
      86             : 
      87           0 : size_t weird_push(void *cd, const char **inbuf, size_t *inbytesleft,
      88             :                   char **outbuf, size_t *outbytesleft)
      89             : {
      90           0 :         int ir_count=0;
      91             : 
      92           0 :         while (*inbytesleft >= 2 && *outbytesleft >= 1) {
      93             :                 int i;
      94           0 :                 int done=0;
      95           0 :                 for (i=0;weird_table[i].from;i++) {
      96           0 :                         if ((*inbuf)[0] == weird_table[i].from &&
      97           0 :                             (*inbuf)[1] == 0) {
      98           0 :                                 if (*outbytesleft < weird_table[i].len) {
      99           0 :                                         abort();
     100             :                                 }
     101           0 :                                 memcpy(*outbuf,
     102           0 :                                        weird_table[i].to,
     103           0 :                                        weird_table[i].len);
     104           0 :                                 (*inbytesleft)  -= 2;
     105           0 :                                 (*outbytesleft) -= weird_table[i].len;
     106           0 :                                 (*inbuf)  += 2;
     107           0 :                                 (*outbuf) += weird_table[i].len;
     108           0 :                                 done = 1;
     109           0 :                                 break;
     110             :                         }
     111             :                 }
     112           0 :                 if (done) continue;
     113             : 
     114           0 :                 (*outbuf)[0] = (*inbuf)[0];
     115           0 :                 if ((*inbuf)[1]) ir_count++;
     116           0 :                 (*inbytesleft)  -= 2;
     117           0 :                 (*outbytesleft) -= 1;
     118           0 :                 (*inbuf)  += 2;
     119           0 :                 (*outbuf) += 1;
     120             :         }
     121             : 
     122           0 :         if (*inbytesleft == 1) {
     123           0 :                 errno = EINVAL;
     124           0 :                 return -1;
     125             :         }
     126             : 
     127           0 :         if (*inbytesleft > 1) {
     128           0 :                 errno = E2BIG;
     129           0 :                 return -1;
     130             :         }
     131             :         
     132           0 :         return ir_count;
     133             : }
     134             : 
     135             : #else
     136             : void charset_weird_dummy(void);
     137             : void charset_weird_dummy(void)
     138             : {
     139             :         return;
     140             : }
     141             : 
     142             : #endif

Generated by: LCOV version 1.14