Skip to content
Snippets Groups Projects
Commit 0aca3965 authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

Validator: added copy method

Copying a Validator could be useful if multiple html versions are to be
supported. Another use case is a blacklist XSS-Scanner.
parent 95ba8a94
Branches
Tags
No related merge requests found
......@@ -43,9 +43,9 @@ FILE_NAME_10=4671;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_11=3013;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8
FILE_NAME_12=3572;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.c;0;8
FILE_NAME_13=1833;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.h;0;8
FILE_NAME_14=1000;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8
FILE_NAME_15=1152;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.h;0;8
FILE_NAME_16=10227;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8
FILE_NAME_14=1520;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8
FILE_NAME_15=1503;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.h;0;8
FILE_NAME_16=3931;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8
FILE_NAME_17=1828;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.h;0;8
FILE_NAME_18=4232;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fstatus.h;0;8
FILE_NAME_19=1017;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Flog.h;0;4
......
......@@ -64,6 +64,38 @@ SH_Validator_new (/*@null@*/ /*@out@*/ struct SH_Status * status)
return validator;
}
/*@null@*/
struct SH_Validator *
SH_Validator_copy (const struct SH_Validator * validator,
/*@null@*/ /*@out@*/ struct SH_Status * status)
{
struct SH_Validator * copy;
copy = malloc (sizeof (struct SH_Validator));
if (copy == NULL)
{
set_status (status, E_ALLOC, 4,
"Memory allocation for "
"SH_Validator failed.\n");
return NULL;
}
if (!copy_tags (copy, validator, status))
{
/* dangerous call to silence splint, should never be executed. */
#ifdef S_SPLINT_S
free (copy->tags);
#endif
free (copy);
return NULL;
}
set_success (status);
return copy;
}
void
SH_Validator_free (/*@only@*/ struct SH_Validator * validator)
{
......
......@@ -52,6 +52,11 @@ struct SH_Validator
SH_Validator *
SH_Validator_new (/*@null@*/ /*@out@*/ struct SH_Status * status);
/*@null@*/
struct SH_Validator *
SH_Validator_copy (const SH_Validator * validator,
/*@null@*/ /*@out@*/ struct SH_Status * status);
void
SH_Validator_free (/*@only@*/ SH_Validator * validator);
......
......@@ -39,11 +39,21 @@ bool
init_tags (/*@out@*/ struct SH_Validator * validator,
/*@null@*/ /*@out@*/ struct SH_Status * status);
static inline
bool
copy_tags (/*@out@*/ struct SH_Validator * copy,
const struct SH_Validator * validator,
/*@null@*/ /*@out@*/ struct SH_Status * status);
static inline
void
free_tags (/*@special@*/ struct SH_Validator * validator)
/*@releases validator->tags@*/;
static inline
size_t
get_tag_number (const struct SH_Validator * validator);
static inline
Tag
add_tag (struct SH_Validator * validator,
......@@ -92,6 +102,87 @@ init_tags (/*@out@*/ struct SH_Validator * validator,
return TRUE;
}
static inline
bool
copy_tags (/*@out@*/ struct SH_Validator * copy,
const struct SH_Validator * validator,
/*@null@*/ /*@out@*/ struct SH_Status * status)
{
bool is_free;
size_t index;
size_t free_index;
size_t copy_index;
size_t tag_n;
tag_n = get_tag_number (validator);
/* The size calculation is save,
* because validator is already allocated. */
copy->tags = malloc ((tag_n + 1) * sizeof (struct tag_info));
if (copy->tags == NULL)
{
set_status (status, E_ALLOC, 5, "malloc failed");
return FALSE;
}
/* copy allocation info */
copy->tags[0].next = 0;
copy->tag_n = tag_n;
copy->last_tag = validator->last_tag;
/* copy data */
copy_index = 0;
for (index = 1; index <= validator->tag_n; index++)
{
/* if tag is not in the list of free blocks */
is_free = FALSE;
for (free_index = validator->tags[0].next;
free_index != 0;
free_index = validator->tags[free_index].next)
{
if (index == free_index)
{
is_free = TRUE;
break;
}
}
if (!is_free)
{
copy->tags[copy_index].data.id =
validator->tags[index].data.id;
copy->tags[copy_index].data.name = strdup (
validator->tags[index].data.name);
if (copy->tags[copy_index].data.name == NULL)
{
size_t index;
set_status (status, E_ALLOC, 5,
"strdup failed");
for (index = 0; index < copy_index;
index++)
{
free (copy->tags[index]
.data.name);
}
free (copy->tags);
return FALSE;
}
copy_index++;
}
}
return TRUE;
}
static inline void
free_tags (/*@special@*/ struct SH_Validator * validator)
/*@releases validator->tags@*/
......@@ -125,6 +216,44 @@ free_tags (/*@special@*/ struct SH_Validator * validator)
return;
}
static inline
size_t
get_tag_number (const struct SH_Validator * validator)
{
bool is_free;
size_t index;
size_t free_index;
size_t tag_n;
tag_n = 0;
for (index = 1; index <= validator->tag_n; index++)
{
/* if tag is not in the list of free blocks */
is_free = FALSE;
for (free_index = validator->tags[0].next;
free_index != 0;
free_index = validator->tags[free_index].next)
{
if (index == free_index)
{
is_free = TRUE;
break;
}
}
if (!is_free)
{
/* This addition is always save,
* because tag_n is always smaller than
* validator->tag_n and it is also of size_t. */
tag_n++;
}
}
return tag_n;
}
static inline
Tag
add_tag (struct SH_Validator * validator,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment