aboutsummaryrefslogtreecommitdiff
path: root/project/dclib
diff options
context:
space:
mode:
Diffstat (limited to 'project/dclib')
-rw-r--r--project/dclib/dclib-basics.c65
-rw-r--r--project/dclib/dclib-basics.h7
-rw-r--r--project/dclib/dclib-debug.c2
-rw-r--r--project/dclib/dclib-file.c12
-rw-r--r--project/dclib/dclib-file.h11
-rw-r--r--project/dclib/dclib-network.c4
-rw-r--r--project/dclib/dclib-tables.c6
-rw-r--r--project/dclib/dclib-types.h18
-rw-r--r--project/dclib/lib-mkw.c18
-rw-r--r--project/dclib/lib-mkw.h16
10 files changed, 146 insertions, 13 deletions
diff --git a/project/dclib/dclib-basics.c b/project/dclib/dclib-basics.c
index 8da7c5b..025a460 100644
--- a/project/dclib/dclib-basics.c
+++ b/project/dclib/dclib-basics.c
@@ -11475,7 +11475,7 @@ void Sha1Hex2Bin ( sha1_hash_t bin, ccp src, ccp end )
DASSERT(src);
uint i;
- for ( i = 0; i < 20; i++ )
+ for ( i = 0; i < sizeof(sha1_hash_t); i++ )
bin[i] = ScanDigits(&src,end,16,2,0);
}
@@ -11492,6 +11492,26 @@ void Sha1Bin2Hex ( sha1_hex_t hex, cvp bin )
//-----------------------------------------------------------------------------
+void Sha1B642Bin ( sha1_hash_t bin, ccp src, ccp end )
+{
+ DASSERT(bin);
+ DASSERT(src);
+
+ DecodeBase64((char*)bin,sizeof(sha1_hash_t),src,end-src,0,true,0);
+}
+
+//-----------------------------------------------------------------------------
+
+void Sha1Bin2B64 ( sha1_b64_t b64, cvp bin )
+{
+ DASSERT(b64);
+ DASSERT(bin);
+
+ EncodeBase64(b64,sizeof(sha1_b64_t),bin,sizeof(sha1_hash_t),0,false,0,0);
+}
+
+//-----------------------------------------------------------------------------
+
ccp GetSha1Hex ( cvp bin )
{
DASSERT(bin);
@@ -11503,6 +11523,49 @@ ccp GetSha1Hex ( cvp bin )
///////////////////////////////////////////////////////////////////////////////
+void Sha1SizeHex2Bin ( sha1_size_hash_t *bin, ccp src, ccp end )
+{
+ DASSERT(bin);
+ DASSERT(src);
+
+ char *dest = (char*)&bin;
+ for ( int i = 0; i < sizeof(sha1_size_hash_t); i++ )
+ *dest++ = ScanDigits(&src,end,16,2,0);
+}
+
+//-----------------------------------------------------------------------------
+
+void Sha1SizeBin2Hex ( sha1_size_hex_t hex, cvp bin )
+{
+ DASSERT(hex);
+ DASSERT(bin);
+
+ snprintf(hex,sizeof(sha1_hex_t),"%08x%08x%08x%08x%08x%08x",
+ be32(bin), be32(bin+4), be32(bin+8), be32(bin+12), be32(bin+16), be32(bin+20) );
+}
+
+//-----------------------------------------------------------------------------
+
+void Sha1SizeB642Bin ( sha1_size_hash_t *bin, ccp src, ccp end )
+{
+ DASSERT(bin);
+ DASSERT(src);
+
+ DecodeBase64((char*)bin,sizeof(sha1_size_hash_t),src,end-src,0,true,0);
+}
+
+//-----------------------------------------------------------------------------
+
+void Sha1SizeBin2B64 ( sha1_size_b64_t b64, cvp bin )
+{
+ DASSERT(b64);
+ DASSERT(bin);
+
+ EncodeBase64(b64,sizeof(sha1_size_b64_t),bin,sizeof(sha1_hash_t),0,false,0,0);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
void * dc_memrchr ( cvp src, int ch, size_t size )
{
if ( !src || !size )
diff --git a/project/dclib/dclib-basics.h b/project/dclib/dclib-basics.h
index ce835f5..80e174c 100644
--- a/project/dclib/dclib-basics.h
+++ b/project/dclib/dclib-basics.h
@@ -7598,10 +7598,17 @@ static inline uint CreateUniqueIdNBO(void) { return htonl(CreateUniqueIdN(1)); }
void Sha1Hex2Bin ( sha1_hash_t bin, ccp src, ccp end );
void Sha1Bin2Hex ( sha1_hex_t hex, cvp bin );
+void Sha1B642Bin ( sha1_hash_t bin, ccp src, ccp end );
+void Sha1Bin2B64 ( sha1_b64_t b64, cvp bin );
// return CircBuf()
ccp GetSha1Hex ( cvp bin );
+void Sha1SizeHex2Bin ( sha1_size_hash_t *bin, ccp src, ccp end );
+void Sha1SizeBin2Hex ( sha1_size_hex_t hex, cvp bin );
+void Sha1SizeB642Bin ( sha1_size_hash_t *bin, ccp src, ccp end );
+void Sha1SizeBin2B64 ( sha1_size_b64_t b64, cvp bin );
+
///////////////////////////////////////////////////////////////////////////////
static uint snprintfS ( char *buf, size_t size, ccp format, ... )
diff --git a/project/dclib/dclib-debug.c b/project/dclib/dclib-debug.c
index a3af57f..f3a2471 100644
--- a/project/dclib/dclib-debug.c
+++ b/project/dclib/dclib-debug.c
@@ -108,6 +108,7 @@ ccp GetErrorName
case ERR_CANT_RENAME: return "CAN'T RENAME FILE";
case ERR_CANT_CLOSE: return "CAN'T CLOSE FILE";
case ERR_CANT_CONNECT: return "CAN'T CONNECT";
+ case ERR_FILE_TOO_BIG: return "FILE TOO BIG";
case ERR_CANT_OPEN: return "CAN'T OPEN FILE";
case ERR_CANT_APPEND: return "CAN'T APPEND FILE";
case ERR_CANT_CREATE: return "CAN'T CREATE FILE";
@@ -229,6 +230,7 @@ ccp GetErrorText
case ERR_CANT_RENAME: return "Can't rename file";
case ERR_CANT_CLOSE: return "Can't close file";
case ERR_CANT_CONNECT: return "Can't connect";
+ case ERR_FILE_TOO_BIG: return "Can't open, because file is too big";
case ERR_CANT_OPEN: return "Can't open file";
case ERR_CANT_APPEND: return "Can't open file for appending";
case ERR_CANT_CREATE: return "Can't create file";
diff --git a/project/dclib/dclib-file.c b/project/dclib/dclib-file.c
index 081fac2..9a00260 100644
--- a/project/dclib/dclib-file.c
+++ b/project/dclib/dclib-file.c
@@ -1195,6 +1195,7 @@ enumError CloseFile
{
if (!f->is_stdio)
{
+ PRINT0("close fd=%d\n",fileno(f->f));
if ( fclose(f->f) && f->max_err <= ERR_WARNING )
f->max_err = ERROR1(ERR_WRITE_FAILED,
"Error while closing file: %s\n",f->fname);
@@ -1253,7 +1254,7 @@ enumError OpenFile
FileMode_t file_mode, // open modes
off_t limit, // >0: don't open, if file size > limit
ccp limit_message // NULL or a with LF terminated text.
- // It is printed after the message.
+ // It is printed behind the error message.
)
{
DASSERT(f);
@@ -1365,12 +1366,12 @@ enumError OpenFile
// be tolerant, if both values produce same text
if (strcmp(sbuf,lbuf))
{
- if ( !(f->fmode & FM_SILENT) )
- ERROR0(ERR_CANT_OPEN,
- "File too large (size=%s, limit=%s): %s\n%s",
+ if ( !(f->fmode & (FM_SILENT|FM_SILENT_ON_LIMIT)) )
+ ERROR0(ERR_FILE_TOO_BIG,
+ "File too big (size=%s, limit=%s): %s\n%s",
sbuf, lbuf, fname,
limit_message ? limit_message : "" );
- return f->max_err = ERR_CANT_OPEN;
+ return f->max_err = ERR_FILE_TOO_BIG;
}
}
@@ -1379,6 +1380,7 @@ enumError OpenFile
ccp omode = GetFileOpenMode(false,f->fmode);
f->f = fopen(fname,omode);
+ PRINT0("open fd=%d : %s\n",fileno(f->f),fname);
TRACE("OpenFile(%s,%s) : [%s], %p\n",
fname, omode, GetFileModeStatus(0,0,f->fmode,1), f->f );
diff --git a/project/dclib/dclib-file.h b/project/dclib/dclib-file.h
index 2e1a209..592463e 100644
--- a/project/dclib/dclib-file.h
+++ b/project/dclib/dclib-file.h
@@ -112,7 +112,8 @@ typedef enum FileMode_t
{
FM_TEST = 0x00001, // test mode, don't modify any file
FM_SILENT = 0x00002, // suppress error messages
- FM_IGNORE = 0x00004, // ignore, if no file on OpenFile()
+ FM_SILENT_ON_LIMIT = 0x00004, // be silent if file limit reached
+ FM_IGNORE = 0x00008, // ignore, if no file on OpenFile()
// and return ERR_NOT_EXISTS
FM_MODIFY = 0x00010, // open file for reading and writing
@@ -132,8 +133,11 @@ typedef enum FileMode_t
FM_TOUCH = 0x40000, // touch file (set timestamp) on close
FM_TEMP = 0x80000, // temporary file: remove file on close
+
+ // relevant for OpenFile()
FM_M_OPEN = FM_TEST
| FM_SILENT
+ | FM_SILENT_ON_LIMIT
| FM_IGNORE
| FM_MODIFY
| FM_STDIO
@@ -142,6 +146,7 @@ typedef enum FileMode_t
| FM_TCP
| FM_TEMP,
+ // relevant for CreateFile()
FM_M_CREATE = FM_TEST
| FM_SILENT
| FM_MODIFY
@@ -401,7 +406,7 @@ enumError OpenFile
FileMode_t file_mode, // open modes
off_t limit, // >0: don't open, if file size > limit
ccp limit_message // NULL or a with LF terminated text.
- // It is printed after the message.
+ // It is printed behind the error message.
);
//-----------------------------------------------------------------------------
@@ -1696,7 +1701,7 @@ typedef struct CpuStatus_t
u64 iowait; // 5: time waiting for I/O to complete (not reliable).
u64 irq; // 6..7: Time servicing (soft-)interrupts.
u64 virtual; // 8..10: time for virtual os.
- u64 unknown; // 11...: time for future extentions
+ u64 unknown; // 11...: time for future extensions
int running_proc; // currently runnable processes
int total_proc; // currently total processes
diff --git a/project/dclib/dclib-network.c b/project/dclib/dclib-network.c
index 8593e49..f98f486 100644
--- a/project/dclib/dclib-network.c
+++ b/project/dclib/dclib-network.c
@@ -402,12 +402,16 @@ bool SplitIP ( SplitIP_t *sip, ccp addr )
? StringCopySM(sip->name,sizeof(sip->name),addr,slash-addr)
: StringCopyS(sip->name,sizeof(sip->name),addr);
+ #if 0
if ( end_name > sip->name && end_name[-1] == '.' )
{
// remove trailing point if not a valid IPv4 (domains only)
if ( CheckIP4(sip->name,end_name-sip->name) <= CIP4_INVALID )
*--end_name = 0;
}
+ #else
+ MARK_USED(end_name);
+ #endif
ccp point = strchr(sip->name,'.');
if (point)
diff --git a/project/dclib/dclib-tables.c b/project/dclib/dclib-tables.c
index 9395169..909e06a 100644
--- a/project/dclib/dclib-tables.c
+++ b/project/dclib/dclib-tables.c
@@ -452,6 +452,8 @@ const sizeof_info_t sizeof_info_linux[] =
SIZEOF_INFO_TITLE("Linux C types")
SIZEOF_INFO_ENTRY(size_t)
+ //SIZEOF_INFO_ENTRY(ssize_t)
+ SIZEOF_INFO_ENTRY(off_t)
SIZEOF_INFO_ENTRY(time_t)
SIZEOF_INFO_ENTRY(struct timeval)
SIZEOF_INFO_ENTRY(struct timespec)
@@ -507,7 +509,11 @@ const sizeof_info_t sizeof_info_dclib[] =
SIZEOF_INFO_ENTRY(exmem_dest_t)
SIZEOF_INFO_ENTRY(sha1_hash_t)
SIZEOF_INFO_ENTRY(sha1_hex_t)
+ SIZEOF_INFO_ENTRY(sha1_b64_t)
SIZEOF_INFO_ENTRY(sha1_id_t)
+ SIZEOF_INFO_ENTRY(sha1_size_hash_t)
+ SIZEOF_INFO_ENTRY(sha1_size_hex_t)
+ SIZEOF_INFO_ENTRY(sha1_size_b64_t)
SIZEOF_INFO_ENTRY(uuid_text_t)
SIZEOF_INFO_ENTRY(CircBuf_t)
SIZEOF_INFO_ENTRY(FastBuf_t)
diff --git a/project/dclib/dclib-types.h b/project/dclib/dclib-types.h
index 2ef0de7..d8c15bd 100644
--- a/project/dclib/dclib-types.h
+++ b/project/dclib/dclib-types.h
@@ -257,6 +257,8 @@ typedef enum enumError
ERR_CANT_CLOSE,
ERU_CANT_CONNECT,
ERR_CANT_CONNECT,
+ ERU_FILE_TOO_BIG,
+ ERR_FILE_TOO_BIG,
ERU_CANT_OPEN,
ERR_CANT_OPEN,
ERU_CANT_APPEND,
@@ -311,8 +313,6 @@ typedef enum enumError
ERU_FATAL_00,
ERU_FATAL_01,
ERU_FATAL_02,
- ERU_FATAL_03,
- ERU_FATAL_04,
ERU_FATAL_XX,
ERU_OUT_OF_MEMORY,
@@ -451,11 +451,23 @@ intx_t;
struct mem_t;
typedef struct mem_t mem_t;
-// [[sha1_hash_t]] [[sha1_hex_t]] [[sha1_id_t]]
+// [[sha1_hash_t]] [[sha1_hex_t]] [[sha1_b64_t]] [[sha1_id_t]]
typedef u8 sha1_hash_t[20];
typedef char sha1_hex_t[41]; // 40 chars + NULL
+typedef char sha1_b64_t[28]; // 27 chars + NULL
typedef u8 sha1_id_t[9]; // 8*chars + NULL
+// [[sha1_size_hash_t]] [[sha1_size_hex_t]] [[sha1_size_b64_t]]
+typedef struct sha1_size_hash_t
+{
+ sha1_hash_t hash; // SHA1 checksum (binary)
+ u32 size; // size of data (big endian)
+}
+__attribute__ ((packed)) sha1_size_hash_t;
+
+typedef char sha1_size_hex_t[49]; // 48 chars + NULL
+typedef char sha1_size_b64_t[33]; // 32 chars + NULL
+
// [[uuid_buf_t]] [[uuid_text_t]]
typedef u8 uuid_buf_t[16];
typedef char uuid_text_t[37]; // "12345678-1234-1234-1234-123456789012" + NULL
diff --git a/project/dclib/lib-mkw.c b/project/dclib/lib-mkw.c
index da955a1..64a5d47 100644
--- a/project/dclib/lib-mkw.c
+++ b/project/dclib/lib-mkw.c
@@ -1811,6 +1811,24 @@ ccp GetLecodeRandomInfo ( uint slot, ccp return_on_err )
: return_on_err;
}
+///////////////////////////////////////////////////////////////////////////////
+
+ccp GetMkwExtraInfo ( uint slot, ccp return_on_err )
+{
+ _Static_assert( MKW_N_EXTRA == 5,"GetMkwExtraInfo()");
+ static ccp info[] =
+ {
+ "Extra: Galaxy Colosseum",
+ "Extra: Winning scene",
+ "Extra: Losing scene",
+ "Extra: Luigi Circuit (Credits)",
+ "Extra: Broken losing scene",
+ };
+
+ return IsMkwExtra(slot)
+ ? info[ slot - MKW_EXTRA_BEG ]
+ : return_on_err;
+}
//
///////////////////////////////////////////////////////////////////////////////
diff --git a/project/dclib/lib-mkw.h b/project/dclib/lib-mkw.h
index b0d7558..37ad862 100644
--- a/project/dclib/lib-mkw.h
+++ b/project/dclib/lib-mkw.h
@@ -90,6 +90,13 @@ enum mkw_consts_t // some constants
MKW_ORIGINAL_END = MKW_ARENA_END,
+ //--- original extra slots
+
+ MKW_EXTRA_BEG = 0x36,
+ MKW_EXTRA_END = 0x3b,
+ MKW_N_EXTRA = MKW_EXTRA_END - MKW_EXTRA_BEG,
+
+
//--- LE-CODE random tracks
MKW_LE_RANDOM_BEG = 0x3d,
@@ -101,6 +108,7 @@ enum mkw_consts_t // some constants
MKW_LE_RANDOM_END,
MKW_N_LE_RANDOM = MKW_LE_RANDOM_END - MKW_LE_RANDOM_BEG,
+
//--- LE-CODE extended slots
MKW_LE_SLOT_BEG = 0x44,
@@ -108,7 +116,7 @@ enum mkw_consts_t // some constants
MKW_N_LE_SLOT = MKW_LE_SLOT_END - MKW_LE_SLOT_BEG,
- //--- special slots (LE-CODE randon included)
+ //--- special slots (LE-CODE random included)
MKW_SPECIAL_BEG = MKW_ORIGINAL_END,
MKW_SPECIAL_END = MKW_LE_SLOT_BEG,
@@ -123,6 +131,8 @@ enum mkw_consts_t // some constants
//-----------------------------------------------------------------------------
+ccp GetMkwExtraInfo ( uint slot, ccp return_on_err );
+
ccp GetLecodeRandomName ( uint slot, ccp return_on_err );
ccp GetLecodeRandomInfo ( uint slot, ccp return_on_err );
@@ -147,11 +157,15 @@ static inline bool IsMkwOriginal ( uint tid )
static inline bool IsMkwCustom ( uint tid )
{ return tid >= MKW_ARENA_END; }
+static inline bool IsMkwExtra ( uint tid )
+ { return tid >= MKW_EXTRA_BEG && tid < MKW_EXTRA_END; }
+
static inline bool IsLecodeRandom ( uint tid )
{ return tid >= MKW_LE_RANDOM_BEG && tid < MKW_LE_RANDOM_END; }
static inline bool IsValidLecodeSlot ( uint tid )
{ return tid < MKW_ARENA_END
+ || tid >= MKW_EXTRA_BEG && tid < MKW_EXTRA_END
|| tid >= MKW_LE_SLOT_BEG && tid < MKW_LE_SLOT_END
|| tid >= MKW_LE_RANDOM_BEG && tid < MKW_LE_RANDOM_END; }