Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bsoutputxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "iolog.h"
#include "debugtrack.h"
#include "rand.h"
#include "xml.h"

#if CC_UNIX
#include <sys/types.h>
Expand Down
220 changes: 1 addition & 219 deletions bsx.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "mm.h"
#include "mmatomic.h"
#include "mmbitmap.h"
#include "xml.h"

/* For mkdir() */
#if CC_UNIX
Expand Down Expand Up @@ -78,225 +79,6 @@ static inline int intMax( int x, int y )
////


#define XML_CHAR_IS_DELIMITER(c) (((c)<=' ')||((c)=='<'))

int xmlStrParseInt( char *str, int64_t *retint )
{
int negflag;
char c;
int64_t workint;

if( !( str ) )
return 0;
negflag = 0;
if( *str == '-' )
negflag = 1;
str += negflag;

workint = 0;
for( ; ; str++ )
{
c = *str;
if( XML_CHAR_IS_DELIMITER( c ) )
break;
if( ( c < '0' ) || ( c > '9' ) )
return 0;
workint = ( workint * 10 ) + ( c - '0' );
}

if( negflag )
workint = -workint;
*retint = workint;
return 1;
}


int xmlStrParseFloat( char *str, float *retfloat )
{
char c;
int negflag;
double workdouble;
double decfactor;

if( !( str ) )
return 0;

negflag = 0;
if( *str == '-' )
negflag = 1;
str += negflag;

workdouble = 0.0;
for( ; ; str++ )
{
c = *str;
if( XML_CHAR_IS_DELIMITER( c ) )
goto done;
if( c == '.' )
break;
if( ( c < '0' ) || ( c > '9' ) )
return 0;
workdouble = ( workdouble * 10.0 ) + (double)( c - '0' );
}

str++;
decfactor = 0.1;
for( ; ; str++ )
{
c = *str;
if( XML_CHAR_IS_DELIMITER( c ) )
break;
if( ( c < '0' ) || ( c > '9' ) )
return 0;
workdouble += (double)( c - '0' ) * decfactor;
decfactor *= 0.1;
}

done:

if( negflag )
workdouble = -workdouble;
*retfloat = (float)workdouble;

return 1;
}


////



/* Build string with escape chars as required, returned string must be free()'d */
char *xmlEncodeEscapeString( char *string, int length, int *retlength )
{
char *dst, *dstbase;
unsigned char c;

dstbase = malloc( 6*length + 1 );
for( dst = dstbase ; length ; length--, string++ )
{
c = *string;
if( c == '&' )
{
dst[0] = '&';
dst[1] = 'a';
dst[2] = 'm';
dst[3] = 'p';
dst[4] = ';';
dst += 5;
}
else if( c == '<' )
{
dst[0] = '&';
dst[1] = 'l';
dst[2] = 't';
dst[3] = ';';
dst += 4;
}
else if( c == '>' )
{
dst[0] = '&';
dst[1] = 'g';
dst[2] = 't';
dst[3] = ';';
dst += 4;
}
else if( c == '"' )
{
dst[0] = '&';
dst[1] = 'q';
dst[2] = 'u';
dst[3] = 'o';
dst[4] = 't';
dst[5] = ';';
dst += 6;
}
else if( c == '\'' )
{
dst[0] = '&';
dst[1] = 'a';
dst[2] = 'p';
dst[3] = 'o';
dst[4] = 's';
dst[5] = ';';
dst += 6;
}
else
*dst++ = c;
}
*dst = 0;
if( retlength )
*retlength = (int)( dst - dstbase );

return dstbase;
}


/* Build string with decoded escape chars, returned string must be free()'d */
char *xmlDecodeEscapeString( char *string, int length, int *retlength )
{
int skip;
char *dst, *dstbase;
unsigned char c;

dstbase = malloc( length + 1 );
for( dst = dstbase ; length ; length -= skip, string += skip )
{
c = *string;
skip = 1;
if( c != '&' )
*dst++ = c;
else
{
if( !( --length ) )
goto error;
string++;
if( ccStrCmpSeq( string, "lt;", 3 ) )
{
*dst++ = '<';
skip = 3;
}
else if( ccStrCmpSeq( string, "gt;", 3 ) )
{
*dst++ = '>';
skip = 3;
}
else if( ccStrCmpSeq( string, "quot;", 4 ) )
{
*dst++ = '"';
skip = 4;
}
else if( ccStrCmpSeq( string, "amp;", 4 ) )
{
*dst++ = '&';
skip = 4;
}
else if( ccStrCmpSeq( string, "apos;", 4 ) )
{
*dst++ = '\'';
skip = 4;
}
else
{
*dst++ = '&';
skip = 0;
}
}
}
*dst = 0;
if( retlength )
*retlength = (int)( dst - dstbase );
return dstbase;

error:
free( dstbase );
return 0;
}


////


char *bsxReadString( char **readvalue, char *string, char *closestring )
{
int len, stringlen;
Expand Down
9 changes: 0 additions & 9 deletions bsx.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
* -----------------------------------------------------------------------------
*/

/* Build string with escape chars as required, returned string must be free()'d */
char *xmlEncodeEscapeString( char *string, int length, int *retlength );
/* Build string with decoded escape chars, returned string must be free()'d */
char *xmlDecodeEscapeString( char *string, int length, int *retlength );


////


typedef struct
{
/* ItemID (string) */
Expand Down
2 changes: 1 addition & 1 deletion compile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gcc -std=gnu99 -m64 cpuconf.c cpuinfo.c -O2 -s -o cpuconf
./cpuconf -h
gcc -std=gnu99 -m64 bricksync.c bricksyncconf.c bricksyncnet.c bricksyncinit.c bricksyncinput.c bsantidebug.c bsmessage.c bsmathpuzzle.c bsorder.c bsregister.c bsapihistory.c bstranslation.c bsevalgrade.c bsoutputxml.c bsorderdir.c bspriceguide.c bsmastermode.c bscheck.c bssync.c bsapplydiff.c bsfetchorderinv.c bsresolve.c bscatedit.c bsfetchinv.c bsfetchorderlist.c bsfetchset.c bscheckreg.c bsfetchpriceguide.c tcp.c vtlex.c cpuinfo.c antidebug.c mm.c mmhash.c mmbitmap.c cc.c ccstr.c debugtrack.c tcphttp.c oauth.c bricklink.c brickowl.c brickowlinv.c colortable.c json.c bsx.c bsxpg.c journal.c exclperm.c iolog.c crypthash.c cryptsha1.c rand.c bn512.c bn1024.c rsabn.c -O2 -s -fvisibility=hidden -o bricksync -lm -lpthread -lssl -lcrypto -DBS_VERSION_BUILDTIME=`date '+%s'`
gcc -std=gnu99 -m64 bricksync.c bricksyncconf.c bricksyncnet.c bricksyncinit.c bricksyncinput.c bsantidebug.c bsmessage.c bsmathpuzzle.c bsorder.c bsregister.c bsapihistory.c bstranslation.c bsevalgrade.c bsoutputxml.c bsorderdir.c bspriceguide.c bsmastermode.c bscheck.c bssync.c bsapplydiff.c bsfetchorderinv.c bsresolve.c bscatedit.c bsfetchinv.c bsfetchorderlist.c bsfetchset.c bscheckreg.c bsfetchpriceguide.c tcp.c vtlex.c cpuinfo.c antidebug.c mm.c mmhash.c mmbitmap.c cc.c ccstr.c debugtrack.c tcphttp.c oauth.c bricklink.c brickowl.c brickowlinv.c colortable.c json.c bsx.c bsxpg.c journal.c exclperm.c iolog.c crypthash.c cryptsha1.c rand.c bn512.c bn1024.c rsabn.c xml.c -O2 -s -fvisibility=hidden -o bricksync -lm -lpthread -lssl -lcrypto -DBS_VERSION_BUILDTIME=`date '+%s'`
2 changes: 1 addition & 1 deletion compile-win32.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cpuconf.exe -h
windres bricksync.rc -O coff -o bricksync.res
REM Added -Wno-implicit-function-declaration to avoid false positive compile warnings
REM Added to end to set BS_VERSION_BUILDTIME to dynamic build version in seconds from epoch -DBS_VERSION_BUILDTIME=`date '+%s'`
gcc -std=gnu99 -Wno-implicit-function-declaration -I./build-win32/ -L./build-win32/ -m32 bricksync.c bricksyncconf.c bricksyncnet.c bricksyncinit.c bricksyncinput.c bsantidebug.c bsmessage.c bsmathpuzzle.c bsorder.c bsregister.c bsapihistory.c bstranslation.c bsevalgrade.c bsoutputxml.c bsorderdir.c bspriceguide.c bsmastermode.c bscheck.c bssync.c bsapplydiff.c bsfetchorderinv.c bsresolve.c bscatedit.c bsfetchinv.c bsfetchorderlist.c bsfetchset.c bscheckreg.c bsfetchpriceguide.c tcp.c vtlex.c cpuinfo.c antidebug.c mm.c mmhash.c mmbitmap.c cc.c ccstr.c debugtrack.c tcphttp.c oauth.c bricklink.c brickowl.c brickowlinv.c colortable.c json.c bsx.c bsxpg.c journal.c exclperm.c iolog.c crypthash.c cryptsha1.c rand.c bn512.c bn1024.c rsabn.c bricksync.res -O2 -s -fvisibility=hidden -o bricksync -lm -lwsock32 -lws2_32 -lssl-1_1 -lcrypto-1_1 -DBS_VERSION_BUILDTIME=`date '+%s'`
gcc -std=gnu99 -Wno-implicit-function-declaration -I./build-win32/ -L./build-win32/ -m32 bricksync.c bricksyncconf.c bricksyncnet.c bricksyncinit.c bricksyncinput.c bsantidebug.c bsmessage.c bsmathpuzzle.c bsorder.c bsregister.c bsapihistory.c bstranslation.c bsevalgrade.c bsoutputxml.c bsorderdir.c bspriceguide.c bsmastermode.c bscheck.c bssync.c bsapplydiff.c bsfetchorderinv.c bsresolve.c bscatedit.c bsfetchinv.c bsfetchorderlist.c bsfetchset.c bscheckreg.c bsfetchpriceguide.c tcp.c vtlex.c cpuinfo.c antidebug.c mm.c mmhash.c mmbitmap.c cc.c ccstr.c debugtrack.c tcphttp.c oauth.c bricklink.c brickowl.c brickowlinv.c colortable.c json.c bsx.c bsxpg.c journal.c exclperm.c iolog.c crypthash.c cryptsha1.c rand.c bn512.c bn1024.c rsabn.c xml.c bricksync.res -O2 -s -fvisibility=hidden -o bricksync -lm -lwsock32 -lws2_32 -lssl-1_1 -lcrypto-1_1 -DBS_VERSION_BUILDTIME=`date '+%s'`
pause


Expand Down
2 changes: 1 addition & 1 deletion compile-win64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ cpuconf.exe -h
windres bricksync.rc -O coff -o bricksync.res
REM Added -Wno-implicit-function-declaration to avoid false positive compile warnings
REM Added to end to set BS_VERSION_BUILDTIME to dynamic build version in seconds from epoch -DBS_VERSION_BUILDTIME=`date '+%s'`
gcc -std=gnu99 -Wno-implicit-function-declaration -I./build-win64/ -L./build-win64/ -m64 bricksync.c bricksyncconf.c bricksyncnet.c bricksyncinit.c bricksyncinput.c bsantidebug.c bsmessage.c bsmathpuzzle.c bsorder.c bsregister.c bsapihistory.c bstranslation.c bsevalgrade.c bsoutputxml.c bsorderdir.c bspriceguide.c bsmastermode.c bscheck.c bssync.c bsapplydiff.c bsfetchorderinv.c bsresolve.c bscatedit.c bsfetchinv.c bsfetchorderlist.c bsfetchset.c bscheckreg.c bsfetchpriceguide.c tcp.c vtlex.c cpuinfo.c antidebug.c mm.c mmhash.c mmbitmap.c cc.c ccstr.c debugtrack.c tcphttp.c oauth.c bricklink.c brickowl.c brickowlinv.c colortable.c json.c bsx.c bsxpg.c journal.c exclperm.c iolog.c crypthash.c cryptsha1.c rand.c bn512.c bn1024.c rsabn.c bricksync.res -O2 -s -fvisibility=hidden -o bricksync -lm -lwsock32 -lws2_32 -lssl-1_1-x64 -lcrypto-1_1-x64 -DBS_VERSION_BUILDTIME=`date '+%s'`
gcc -std=gnu99 -Wno-implicit-function-declaration -I./build-win64/ -L./build-win64/ -m64 bricksync.c bricksyncconf.c bricksyncnet.c bricksyncinit.c bricksyncinput.c bsantidebug.c bsmessage.c bsmathpuzzle.c bsorder.c bsregister.c bsapihistory.c bstranslation.c bsevalgrade.c bsoutputxml.c bsorderdir.c bspriceguide.c bsmastermode.c bscheck.c bssync.c bsapplydiff.c bsfetchorderinv.c bsresolve.c bscatedit.c bsfetchinv.c bsfetchorderlist.c bsfetchset.c bscheckreg.c bsfetchpriceguide.c tcp.c vtlex.c cpuinfo.c antidebug.c mm.c mmhash.c mmbitmap.c cc.c ccstr.c debugtrack.c tcphttp.c oauth.c bricklink.c brickowl.c brickowlinv.c colortable.c json.c bsx.c bsxpg.c journal.c exclperm.c iolog.c crypthash.c cryptsha1.c rand.c bn512.c bn1024.c rsabn.c xml.c bricksync.res -O2 -s -fvisibility=hidden -o bricksync -lm -lwsock32 -lws2_32 -lssl-1_1-x64 -lcrypto-1_1-x64 -DBS_VERSION_BUILDTIME=`date '+%s'`

2 changes: 1 addition & 1 deletion compile32
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gcc -std=gnu99 -m32 cpuconf.c cpuinfo.c -O2 -s -o cpuconf
./cpuconf -h
gcc -std=gnu99 -m32 bricksync.c bricksyncconf.c bricksyncnet.c bricksyncinit.c bricksyncinput.c bsantidebug.c bsmessage.c bsmathpuzzle.c bsorder.c bsregister.c bsapihistory.c bstranslation.c bsevalgrade.c bsoutputxml.c bsorderdir.c bspriceguide.c bsmastermode.c bscheck.c bssync.c bsapplydiff.c bsfetchorderinv.c bsresolve.c bscatedit.c bsfetchinv.c bsfetchorderlist.c bsfetchset.c bscheckreg.c bsfetchpriceguide.c tcp.c vtlex.c cpuinfo.c antidebug.c mm.c mmhash.c mmbitmap.c cc.c debugtrack.c tcphttp.c oauth.c bricklink.c brickowl.c brickowlinv.c colortable.c json.c bsx.c bsxpg.c journal.c exclperm.c iolog.c crypthash.c cryptsha1.c rand.c bn512.c bn1024.c rsabn.c -O2 -s -fvisibility=hidden -o bricksync -lm -lpthread -lssl -lcrypto -DBS_VERSION_BUILDTIME=`date '+%s'`
gcc -std=gnu99 -m32 bricksync.c bricksyncconf.c bricksyncnet.c bricksyncinit.c bricksyncinput.c bsantidebug.c bsmessage.c bsmathpuzzle.c bsorder.c bsregister.c bsapihistory.c bstranslation.c bsevalgrade.c bsoutputxml.c bsorderdir.c bspriceguide.c bsmastermode.c bscheck.c bssync.c bsapplydiff.c bsfetchorderinv.c bsresolve.c bscatedit.c bsfetchinv.c bsfetchorderlist.c bsfetchset.c bscheckreg.c bsfetchpriceguide.c tcp.c vtlex.c cpuinfo.c antidebug.c mm.c mmhash.c mmbitmap.c cc.c debugtrack.c tcphttp.c oauth.c bricklink.c brickowl.c brickowlinv.c colortable.c json.c bsx.c bsxpg.c journal.c exclperm.c iolog.c crypthash.c cryptsha1.c rand.c bn512.c bn1024.c rsabn.c xml.c -O2 -s -fvisibility=hidden -o bricksync -lm -lpthread -lssl -lcrypto -DBS_VERSION_BUILDTIME=`date '+%s'`
27 changes: 27 additions & 0 deletions iolog.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "ccstr.h"
#include "mm.h"
#include "iolog.h"
#include "xml.h"

/* For mkdir() */
#if CC_UNIX
Expand Down Expand Up @@ -399,9 +400,33 @@ static void ioHandleColorCode( ioLog *log, int color )
return;
}

/* Interpret escaped XML entities in the given string in-place */
static void interpretXmlEntities( char *string )
{
char *targetstring, *sourcestring, *decodedstring;

decodedstring = xmlDecodeEscapeString( string, strlen( string ), 0 );

targetstring = decodedstring;
sourcestring = string;
for ( ; *targetstring ; targetstring++ )
{
/* Replace the original string with decoded characters */
*sourcestring++ = *targetstring;
}
for ( ; *sourcestring ; sourcestring++ )
{
/* Set residual characters in the input string to \0 */
*sourcestring = 0;
}

free( decodedstring );
}

static void ioPrintStdoutString( ioLog *log, char *string )
{
interpretXmlEntities( string );

int writelength, colorcode, endlinecount;
char *writebase;

Expand Down Expand Up @@ -445,6 +470,8 @@ static void ioPrintStdoutString( ioLog *log, char *string )

static void ioPrintFileString( ioLog *log, FILE *file, char *string )
{
interpretXmlEntities( string );

int writelength;
char *writebase;

Expand Down
Loading