Correcting some subtle things

This commit is contained in:
Thomas Touhey 2017-07-05 20:22:07 +02:00
parent 036314140e
commit 4e4bfcb279
19 changed files with 120 additions and 95 deletions

View File

@ -82,6 +82,10 @@ dist: mrproper
getversion:
@echo $(VERSION)
# Check if is indev.
isindev:
@$(if $(INDEV),echo $(INDEV),true)
# Get the maintainer.
getmaintainer:
@echo "$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>"

7
configure vendored
View File

@ -7,6 +7,7 @@ cd "$(dirname $0)"
[ -f Makefile.cfg ] && mv Makefile.cfg Makefile.cfg.tmp
name="$(make -s getname)"
version="$(make -s getversion)"
indev="$(make -s isindev)"
maintainer="$(make -s getmaintainer)"
[ -f Makefile.cfg.tmp ] && mv Makefile.cfg.tmp Makefile.cfg
@ -30,9 +31,11 @@ loglevel=none # none, info, warn, error, fatal
# Installation directories
root=''
prefix='${root}/opt/p7-project'
[ x"$indev" != x ] && prefix='${root}/opt/p7-project' \
|| prefix='${root}/usr'
prefix_set=
hprefix='${root}/opt/p7-project'
[ x"$indev" != x ] && hprefix='${root}/opt/p7-project' \
|| hprefix='${root}/usr'
bindir='${prefix}/bin'
hbindir='${hprefix}/bin'
libdir='${prefix}/lib'"$platform"

View File

@ -28,5 +28,5 @@
# include "libcasio/link.h"
# include "libcasio/file.h"
# include "libcasio/mcs.h"
# include "libcasio/utils.h"
# include "libcasio/char.h"
#endif /* LIBCASIO_H */

View File

@ -1,5 +1,5 @@
/* ****************************************************************************
* libcasio/encoding.h -- libcasio character encoding.
* libcasio/char.h -- libcasio character encoding.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
@ -16,11 +16,11 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LIBCASIO_ENCODING_H
# define LIBCASIO_ENCODING_H
#ifndef LIBCASIO_CHAR_H
# define LIBCASIO_CHAR_H
# include "cdefs.h"
typedef int casio_encode_string_t OF((void *casio__dest,
typedef int casio_encode_t OF((void *casio__dest,
const void *casio__data, size_t *casio__size));
CASIO_EXTERN int CASIO_EXPORT casio_register_conv
@ -31,4 +31,4 @@ CASIO_EXTERN int CASIO_EXPORT casio_encode_string
OF((void *casio__dest, const void *casio__data,
size_t *casio__size));
#endif /* LIBCASIO_ENCODING_H */
#endif /* LIBCASIO_CHAR_H */

View File

@ -59,10 +59,13 @@ typedef unsigned int casio_openmode_t;
# define CASIO_OPENMODE_READ 0x0001 /* the stream is readable. */
# define CASIO_OPENMODE_WRITE 0x0002 /* the stream is writable. */
# define CASIO_OPENMODE_SEEK 0x0004 /* the stream is seekable. */
# define CASIO_OPENMODE_SERIAL 0x0008 /* the stream has serial ops. */
# define CASIO_OPENMODE_SCSI 0x0010 /* the stream has SCSI ops. */
# define CASIO_OPENMODE_USB 0x0020 /* the stream has USB ops. */
# define CASIO_OPENMODE_TRUNC 0x0004 /* the file will be truncated. */
# define CASIO_OPENMODE_APPEND 0x0008 /* will append to the file. */
# define CASIO_OPENMODE_SEEK 0x0010 /* the stream is seekable. */
# define CASIO_OPENMODE_SERIAL 0x0020 /* the stream has serial ops. */
# define CASIO_OPENMODE_SCSI 0x0040 /* the stream has SCSI ops. */
# define CASIO_OPENMODE_USB 0x0080 /* the stream has USB ops. */
/* Here is the offset type, to move within a stream: */
@ -278,7 +281,7 @@ CASIO_EXTERN int CASIO_EXPORT casio_comlist
/* Open and close a stream. */
CASIO_EXTERN int CASIO_EXPORT casio_open
CASIO_EXTERN int CASIO_EXPORT casio_open_stream
OF((casio_stream_t **casio__stream, casio_openmode_t mode,
void *casio__cookie, const casio_streamfuncs_t *casio__callbacks));
CASIO_EXTERN int CASIO_EXPORT casio_close

View File

@ -1,34 +0,0 @@
/* ****************************************************************************
* libcasio/utils.h -- libcasio utilities.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LIBCASIO_UTILS_H
# define LIBCASIO_UTILS_H 1
# include "cdefs.h"
/* ASCII-HEX, ASCII-DEC utilities */
CASIO_EXTERN void CASIO_EXPORT casio_putascii
OF((unsigned char *casio__p, unsigned long casio__i, int casio__n));
CASIO_EXTERN unsigned long CASIO_EXPORT casio_getascii
OF((const unsigned char *casio__p, int casio__n));
CASIO_EXTERN unsigned long CASIO_EXPORT casio_getdec
OF((unsigned long casio__h));
CASIO_EXTERN unsigned long CASIO_EXPORT casio_gethex
OF((unsigned long casio__d));
#endif /* LIBCASIO_UTILS_H */

View File

@ -1,5 +1,5 @@
/* ****************************************************************************
* encoding/encoding.h -- libcasio internal macros for string encoding.
* char/char.h -- libcasio internal macros for string encoding.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
@ -16,10 +16,10 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LOCAL_ENCODING_H
# define LOCAL_ENCODING_H 1
#ifndef LOCAL_CHAR_H
# define LOCAL_CHAR_H 1
# include "../internals.h"
#endif /* LOCAL_ENCODING_H */
#endif /* LOCAL_CHAR_H */

View File

@ -43,7 +43,8 @@ int CASIO_EXPORT casio_make_posix_path(void *cookie,
size_t nodesize = node->casio_pathnode_size;
/* Check that there is no forbidden characters. */
if (memchr(node->casio_pathnode_name, 0, nodesize)
if (nodesize > 255
|| memchr(node->casio_pathnode_name, 0, nodesize)
|| memchr(node->casio_pathnode_name, '/', nodesize))
return (casio_error_invalid);

View File

@ -24,62 +24,97 @@
#ifndef LIBCASIO_DISABLED_WINDOWS
/**
* validate_name:
* Validate element name.
* check_short:
* Check if is a short name.
*
* We'll check that names respect the short name formats, also called the 8.3.
* Folder names are 8 max chars, and file names are 8 max chars of name
* plus 3 max chars of extensions.
*
* TODO: check for filesystems supporting long file names.
* We'll check that names respect the short name formats, also called
* the 8.3 format (linked to how FAT store metadata).
*
* @arg name the name.
* @arg size the name size.
* @arg flags the validation flags.
* @return if it is validated (0 if not).
* @arg usize the name size.
* @return the error code (0 if ok).
*/
CASIO_LOCAL int validate_name(const char *name, size_t size,
unsigned int flags)
CASIO_LOCAL int check_short(const char *name, size_t usize)
{
int i;
const char *nm;
int i, size;
/* Check if is too much. */
if (usize > 11) return (casio_error_invalid);
size = (int)usize;
/* Check the short format. */
i = 8; if (i >= size) i = size;
/* - Look for the dot marking the extension. */
for (; i >= 0 && name[i] != '.'; i--);
if (i < 0) {
/* No extension; check if the file is 8 chars or under. */
if (size > 8) return (casio_error_invalid);
} else {
/* Check if there is a dot after the limit for the extension. */
if (memchr(&name[i], '.', size - i)) return (casio_error_invalid);
/* Check if the extension is longer than 3 chars. */
if (size > i + 3) return (casio_error_invalid);
/* Check if there are dots after the "main" dot, in the section
* where there shouldn't be. */
switch (i) {
case 8:
if (name[11] == '.')
return (casio_error_invalid);
/* FALLTHRU */
case 7:
if (name[10] == '.')
return (casio_error_invalid);
/* FALLTHRU */
case 6:
if (name[9] == '.')
return (casio_error_invalid);
break;
}
}
return (0);
}
/**
* check_name:
* Validate element name.
*
* TODO: check for filesystems supporting long file names.
*
* @arg name the name.
* @arg size the name size.
* @return the error code (0 if ok).
*/
CASIO_LOCAL int check_name(const char *name, size_t size)
{
int err; size_t i;
/* Check if is a valid short name. */
err = check_short(name, size);
if (err) return (err);
/* Look for reserved names. */
if (size == 3) {
if (!memcmp(name, "CON") || !memcmp(name, "PRN")
|| !memcmp(name, "AUX") || !memcmp(name, "NUL"))
return (0);
if (!memcmp(name, "CON", 3) || !memcmp(name, "PRN", 3)
|| !memcmp(name, "AUX", 3) || !memcmp(name, "NUL", 3))
return (casio_error_invalid);
} else if (size == 4) {
if ((!memcmp(name, "COM") && name[3] >= '1' && name[3] <= '9')
|| (!memcmp(name, "LPT") && name[3] >= '1' && name[3] <= '8'))
return (0);
if ((!memcmp(name, "COM", 3) && name[3] >= '1' && name[3] <= '9')
|| (!memcmp(name, "LPT", 3) && name[3] >= '1' && name[3] <= '8'))
return (casio_error_invalid);
}
/* Look for reserved characters. */
for (i = size; i; i--, name++) {
if (*name < 0x20 || memchr("<>:\"/\\|?*", *name, 9))
return (0);
return (casio_error_invalid);
}
/* We're good! */
return (1);
return (0);
}
/**
@ -93,9 +128,9 @@ CASIO_LOCAL int validate_name(const char *name, size_t size,
*/
int CASIO_EXPORT casio_make_windows_path(void *cookie,
void *ppath, casio_path_t *array)
void **ppath, casio_path_t *array)
{
size_t length = 0;
int err; size_t length = 0;
char *path;
casio_pathnode_t *node;
@ -113,12 +148,12 @@ int CASIO_EXPORT casio_make_windows_path(void *cookie,
if (!node) return (casio_error_invalid);
while (node) {
if (!validate_name(node->casio_pathnode_name,
node->casio_pathnode_size))
return (casio_error_invalid);
err = check_name((char*)node->casio_pathnode_name,
node->casio_pathnode_size);
if (err) return (err);
length += node->casio_pathnode_size;
node = node->casio_pathnode_size;
node = node->casio_pathnode_next;
if (node) length++; /* '\\' */
if (length > 259)
@ -127,7 +162,7 @@ int CASIO_EXPORT casio_make_windows_path(void *cookie,
/* Allocate the path. */
*ppath = casio_alloc(length + 1, 1);
path = *ppath; if (!path) return (casio_error_alloc);
path = (char*)*ppath; if (!path) return (casio_error_alloc);
/* Fill the path. */
if (array->casio_path_device) {

View File

@ -63,4 +63,16 @@ extern casio_uint32_t casio_checksum32 OF((void *casio__mem,
extern int casio_getext OF((const char *casio__path,
char *casio__buf, size_t casio__n));
/* ASCII-HEX, ASCII-DEC utilities */
CASIO_EXTERN void CASIO_EXPORT casio_putascii
OF((unsigned char *casio__p, unsigned long casio__i, int casio__n));
CASIO_EXTERN unsigned long CASIO_EXPORT casio_getascii
OF((const unsigned char *casio__p, int casio__n));
CASIO_EXTERN unsigned long CASIO_EXPORT casio_getdec
OF((unsigned long casio__h));
CASIO_EXTERN unsigned long CASIO_EXPORT casio_gethex
OF((unsigned long casio__d));
#endif /* LOCAL_INTERNALS_H */

View File

@ -348,5 +348,5 @@ int CASIO_EXPORT casio_seven_open_data_stream(casio_stream_t **stream,
}
/* initialize the stream */
return (casio_open(stream, mode, cookie, &seven_data_callbacks));
return (casio_open_stream(stream, mode, cookie, &seven_data_callbacks));
}

View File

@ -98,5 +98,5 @@ int CASIO_EXPORT casio_open_csum32(casio_stream_t **stream,
/* Initialize da stream. */
openmode = casio_get_openmode(original) & CASIO_OPENMODE_READ;
return (casio_open(stream, openmode, cookie, &csum32_callbacks));
return (casio_open_stream(stream, openmode, cookie, &csum32_callbacks));
}

View File

@ -244,7 +244,7 @@ int CASIO_EXPORT casio_open_stream_file(casio_stream_t **stream,
cookie->_wstream = wstream;
/* initialize the stream */
return (casio_open(stream, mode, cookie, &casio_file_callbacks));
return (casio_open_stream(stream, mode, cookie, &casio_file_callbacks));
fail:
if (rstream && rstream_cl) fclose(rstream);
if (wstream != rstream && wstream_cl) fclose(wstream);

View File

@ -171,7 +171,7 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream)
cookie->_end = -1;
/* final call. */
return (casio_open(stream, openmode,
return (casio_open_stream(stream, openmode,
cookie, &casio_libusb_callbacks));
fail:
if (cookie) casio_free(cookie);

View File

@ -102,7 +102,7 @@ int CASIO_EXPORT casio_open_limited(casio_stream_t **stream,
cookie->_left = size;
/* initialize da stream */
return (casio_open(stream,
return (casio_open_stream(stream,
casio_get_openmode(original) & CASIO_OPENMODE_READ,
cookie, &casio_limited_callbacks));
}

View File

@ -163,6 +163,6 @@ int CASIO_EXPORT casio_open_memory(casio_stream_t **stream,
cookie->_offset = 0;
/* initialize da stream */
return (casio_open(stream, CASIO_OPENMODE_READ, cookie,
return (casio_open_stream(stream, CASIO_OPENMODE_READ, cookie,
&casio_memory_callbacks));
}

View File

@ -139,7 +139,7 @@ int CASIO_EXPORT casio_open_stream_fd(casio_stream_t **stream,
readfd, writefd));
/* final call */
return (casio_open(stream, mode, cookie,
return (casio_open_stream(stream, mode, cookie,
&casio_streams_callbacks));
fail:
if (readfd >= 0 && closeread)

View File

@ -94,7 +94,7 @@ int CASIO_EXPORT casio_opencom_windows(casio_stream_t **stream,
/* initialize for real */
mode = CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE | CASIO_OPENMODE_SERIAL;
return (casio_open(stream, mode, cookie, &casio_windows_callbacks));
return (casio_open_stream(stream, mode, cookie, &casio_windows_callbacks));
fail:
if (fhandle != INVALID_HANDLE_VALUE) CloseHandle(fhandle);
if (cookie) casio_free(cookie);

View File

@ -21,7 +21,7 @@
{ if (CASIO__COND) {err = CASIO__ERR; goto fail;}}
/**
* casio_open:
* casio_open_stream:
* Open a libcasio stream.
*
* @arg pstream the stream to open.
@ -31,8 +31,9 @@
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_open(casio_stream_t **pstream, casio_openmode_t mode,
void *cookie, const casio_streamfuncs_t *callbacks)
int CASIO_EXPORT casio_open_stream(casio_stream_t **pstream,
casio_openmode_t mode, void *cookie,
const casio_streamfuncs_t *callbacks)
{
int err; casio_stream_t *stream = NULL;
casio_streamfuncs_t *c;