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

Validator: hide id from public deregister_tag

In preparation to the entire removal of ids, the method for removing
tags, was rewritten in order to avoid depending on them.
parent 5e304a27
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ long_line_behaviour=1
long_line_column=72
[files]
current_page=54
current_page=33
FILE_NAME_0=139;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2FREADME;0;8
FILE_NAME_1=134;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitignore;0;8
FILE_NAME_2=1737;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fconfigure.ac;0;8
......@@ -61,8 +61,8 @@ FILE_NAME_28=1867;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_29=3036;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8
FILE_NAME_30=1159;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.h;0;8
FILE_NAME_31=1111;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_html.h;0;8
FILE_NAME_32=14059;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_33=1148;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_32=15982;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_33=1600;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_34=1124;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag_data.h;0;8
FILE_NAME_35=16395;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.c;0;8
FILE_NAME_36=1051;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.h;0;8
......
......@@ -91,6 +91,12 @@ copy_tags (/*@special@*/ struct SH_Validator * copy,
/*@modifies fileSystem@*/
/*@modifies status@*/;
static inline
void
free_tag (struct tag_info tag)
/*@modifies tag.name@*/
/*@releases tag.name@*/;
static inline
void
free_tags (/*@special@*/ struct SH_Validator * validator)
......@@ -148,7 +154,8 @@ get_tag_id_by_name (const struct SH_Validator * validator,
static inline
bool
remove_tag (struct SH_Validator * validator, Tag id,
remove_tag (struct SH_Validator * validator,
const size_t index,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies validator->tag_n@*/
/*@modifies validator->tags@*/
......@@ -353,6 +360,16 @@ copy_tags (/*@special@*/ struct SH_Validator * copy,
return TRUE;
}
static inline
void
free_tag (struct tag_info tag)
/*@modifies tag.name@*/
/*@releases tag.name@*/
{
free (tag.name);
return;
}
static inline
void
free_tags (/*@special@*/ struct SH_Validator * validator)
......@@ -363,7 +380,7 @@ free_tags (/*@special@*/ struct SH_Validator * validator)
for (index = 0; index < validator->tag_n; index++)
{
free (validator->tags[index].name);
free_tag (validator->tags[index]);
}
free (validator->tags);
......@@ -577,7 +594,8 @@ remove_tag_for_all_attrs (struct SH_Validator * validator,
static inline
bool
remove_tag (struct SH_Validator * validator, Tag id,
remove_tag (struct SH_Validator * validator,
const size_t index,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies validator->tag_n@*/
/*@modifies validator->tags@*/
......@@ -586,62 +604,49 @@ remove_tag (struct SH_Validator * validator, Tag id,
/*@modifies fileSystem@*/
/*@modifies status@*/
{
size_t index;
struct tag_info tag;
struct tag_info * new_tags;
#define tags validator->tags
#define tag_n validator->tag_n
for (index = 0; index < tag_n; index++)
if (id == tags[index].id)
/* preserve data, as realloc may fail */
tag = validator->tags[index];
/* clear all references of this tag */
if (!remove_tag_for_all_attrs (validator, tag.name, status))
{
struct tag_info * new_tags;
char * name;
return FALSE;
}
/* don't free name yet, as realloc may fail */
name = tags[index].name;
for (size_t i = index; i < validator->tag_n-1; i++)
{
validator->tags[i] = validator->tags[i+1];
}
/* clear all references of this tag */
if (!remove_tag_for_all_attrs (validator, name, status))
{
return FALSE;
}
new_tags = realloc (validator->tags, sizeof (struct tag_info)
* (validator->tag_n - 1));
if (NULL == new_tags)
{
set_status (status, E_ALLOC, 3, "realloc failed");
for (size_t i = index; i < tag_n-1; i++)
for (size_t i = validator->tag_n-1; i > index; i++)
{
tags[i] = tags[i+1];
validator->tags[i] = validator->tags[i-1];
}
new_tags = realloc (tags, sizeof (struct tag_info)
* (tag_n - 1));
if (NULL == new_tags)
{
set_status (status, E_ALLOC, 3, "realloc failed");
for (size_t i = tag_n-1; i > index; i++)
{
tags[i] = tags[i-1];
}
validator->tags[index] = tag;
/* bad code to silence splint, should never be executed. */
#ifdef S_SPLINT_S
new_tags = (void *) 0x12345;
new_tags = (void *) 0x12345;
#endif
return FALSE;
}
free (name);
return FALSE;
}
tags = new_tags;
tag_n--;
free_tag (tag);
set_success (status);
return TRUE;
}
#undef tags
#undef tag_n
validator->tags = new_tags;
validator->tag_n--;
set_status (status, E_VALUE, 44, "unknown Tag id");
return FALSE;
set_success (status);
return TRUE;
}
......@@ -682,7 +687,7 @@ SH_Validator_register_tag (struct SH_Validator * validator,
bool
SH_Validator_deregister_tag (struct SH_Validator * validator,
Tag id,
const char * tag,
/*@null@*/ /*@out@*/
struct SH_Status * status)
/*@modifies validator->tag_n@*/
......@@ -692,5 +697,14 @@ SH_Validator_deregister_tag (struct SH_Validator * validator,
/*@modifies fileSystem@*/
/*@modifies status@*/
{
return remove_tag (validator, id, status);
size_t index;
if (!find_tag (validator, tag, &index))
{
/* TODO: define whether this is an error */
set_status (status, E_VALUE, 3, "no such tag");
return FALSE;
}
return remove_tag (validator, index, status);
}
......@@ -55,7 +55,7 @@ SH_Validator_register_tag (SH_Validator * validator,
bool
SH_Validator_deregister_tag (SH_Validator * validator,
Tag id,
const char * tag,
/*@null@*/ /*@out@*/
struct SH_Status * status)
/*@modifies validator@*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment