2003-04-26 11:49:05 +00:00
/*
Unix SMB / CIFS implementation .
Samba module with developer tools
Copyright ( C ) Andrew Tridgell 2001
Copyright ( C ) Jelmer Vernooij 2002
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-04-26 11:49:05 +00:00
( at your option ) any later version .
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 the GNU General Public License
2007-07-10 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-04-26 11:49:05 +00:00
*/
2021-01-04 12:28:20 +01:00
# include "replace.h"
2011-09-19 19:13:21 -07:00
# include "charset_proto.h"
# ifdef DEVELOPER
2003-04-26 11:49:05 +00:00
static struct {
char from ;
2005-09-30 17:13:37 +00:00
const char * to ;
2003-04-26 11:49:05 +00:00
int len ;
} weird_table [ ] = {
2018-12-12 21:28:14 +01:00
{
. from = ' q ' ,
. to = " ^q^ " ,
. len = 3 ,
} ,
{
. from = ' Q ' ,
. to = " ^Q^ " ,
. len = 3 ,
} ,
{
. len = 0 ,
}
2003-04-26 11:49:05 +00:00
} ;
2011-09-19 19:13:21 -07:00
size_t weird_pull ( void * cd , const char * * inbuf , size_t * inbytesleft ,
char * * outbuf , size_t * outbytesleft )
2003-04-26 11:49:05 +00:00
{
while ( * inbytesleft > = 1 & & * outbytesleft > = 2 ) {
int i ;
int done = 0 ;
for ( i = 0 ; weird_table [ i ] . from ; i + + ) {
if ( strncmp ( ( * inbuf ) ,
weird_table [ i ] . to ,
weird_table [ i ] . len ) = = 0 ) {
if ( * inbytesleft < weird_table [ i ] . len ) {
2021-01-04 12:28:20 +01:00
abort ( ) ;
2003-04-26 11:49:05 +00:00
}
2021-01-04 12:28:20 +01:00
( * outbuf ) [ 0 ] = weird_table [ i ] . from ;
( * outbuf ) [ 1 ] = 0 ;
( * inbytesleft ) - = weird_table [ i ] . len ;
( * outbytesleft ) - = 2 ;
( * inbuf ) + = weird_table [ i ] . len ;
( * outbuf ) + = 2 ;
done = 1 ;
break ;
2003-04-26 11:49:05 +00:00
}
}
if ( done ) continue ;
( * outbuf ) [ 0 ] = ( * inbuf ) [ 0 ] ;
( * outbuf ) [ 1 ] = 0 ;
( * inbytesleft ) - = 1 ;
( * outbytesleft ) - = 2 ;
( * inbuf ) + = 1 ;
( * outbuf ) + = 2 ;
}
if ( * inbytesleft > 0 ) {
errno = E2BIG ;
return - 1 ;
}
return 0 ;
}
2011-09-19 19:13:21 -07:00
size_t weird_push ( void * cd , const char * * inbuf , size_t * inbytesleft ,
char * * outbuf , size_t * outbytesleft )
2003-04-26 11:49:05 +00:00
{
int ir_count = 0 ;
while ( * inbytesleft > = 2 & & * outbytesleft > = 1 ) {
int i ;
int done = 0 ;
for ( i = 0 ; weird_table [ i ] . from ; i + + ) {
if ( ( * inbuf ) [ 0 ] = = weird_table [ i ] . from & &
( * inbuf ) [ 1 ] = = 0 ) {
if ( * outbytesleft < weird_table [ i ] . len ) {
2021-01-04 12:28:20 +01:00
abort ( ) ;
2003-04-26 11:49:05 +00:00
}
2021-01-04 12:28:20 +01:00
memcpy ( * outbuf ,
weird_table [ i ] . to ,
weird_table [ i ] . len ) ;
( * inbytesleft ) - = 2 ;
( * outbytesleft ) - = weird_table [ i ] . len ;
( * inbuf ) + = 2 ;
( * outbuf ) + = weird_table [ i ] . len ;
done = 1 ;
break ;
2003-04-26 11:49:05 +00:00
}
}
if ( done ) continue ;
( * outbuf ) [ 0 ] = ( * inbuf ) [ 0 ] ;
if ( ( * inbuf ) [ 1 ] ) ir_count + + ;
( * inbytesleft ) - = 2 ;
( * outbytesleft ) - = 1 ;
( * inbuf ) + = 2 ;
( * outbuf ) + = 1 ;
}
if ( * inbytesleft = = 1 ) {
errno = EINVAL ;
return - 1 ;
}
if ( * inbytesleft > 1 ) {
errno = E2BIG ;
return - 1 ;
}
return ir_count ;
}
2011-09-19 19:13:21 -07:00
# else
void charset_weird_dummy ( void ) ;
void charset_weird_dummy ( void )
2003-04-26 11:49:05 +00:00
{
2011-09-19 19:13:21 -07:00
return ;
2003-04-26 11:49:05 +00:00
}
2011-09-19 19:13:21 -07:00
# endif