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
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
CC ?= gcc
PKGCONFIG = $(shell which pkg-config)
DEBUG_CFLAGS = \
-Wall \
-Wstrict-prototypes \
-Werror=missing-prototypes \
-Werror=implicit-function-declaration \
-Werror=init-self \
-Werror=format-security -Werror=format=2
CFLAGS = $(shell $(PKGCONFIG) --cflags gio-2.0)
LIBS = $(shell $(PKGCONFIG) --libs gio-2.0)
LIBXML2_CFLAGS = $(shell $(PKGCONFIG) --cflags libxml-2.0)
Expand Down Expand Up @@ -30,6 +37,9 @@ clean:
rm -f $(TESTS)
rm -f *.o

check: all run-tests
./run-tests

gitignore: Makefile
( echo "*~" ; \
echo "*.o" ; \
Expand All @@ -42,7 +52,7 @@ gitignore: Makefile
PHONY = gitignore

%.o: %.c
$(CC) -c -o $(@F) $(CFLAGS) $<
$(CC) -c -o $(@F) $(DEBUG_CFLAGS) $(CFLAGS) $<

test-axing-parser-async: Makefile $(OBJS) test-axing-parser-async.o
$(CC) -o $(@F) $(LIBS) $(OBJS) $(addsuffix .o,$(@F))
Expand Down
141 changes: 80 additions & 61 deletions axing-dtd-schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

#include "axing-dtd-schema.h"

struct _AxingDtdSchemaPrivate {
typedef struct {
char *doctype;
char *public;
char *system;
GHashTable *general_entities;
GHashTable *parameter_entities;
GHashTable *notations;
};
} AxingDtdSchemaPrivate;

typedef struct {
char *name;
Expand All @@ -55,29 +55,27 @@ static void axing_dtd_schema_class_init (AxingDtdSchemaClass *klass);
static void axing_dtd_schema_dispose (GObject *object);
static void axing_dtd_schema_finalize (GObject *object);

G_DEFINE_TYPE (AxingDtdSchema, axing_dtd_schema, G_TYPE_OBJECT);
G_DEFINE_TYPE_WITH_PRIVATE (AxingDtdSchema, axing_dtd_schema, G_TYPE_OBJECT)

static void
axing_dtd_schema_init (AxingDtdSchema *dtd)
{
dtd->priv = G_TYPE_INSTANCE_GET_PRIVATE (dtd, AXING_TYPE_DTD_SCHEMA,
AxingDtdSchemaPrivate);
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);

/* Use data->name as key, owned by data, so no key_destroy_func */
dtd->priv->general_entities = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify) entity_data_free);
dtd->priv->parameter_entities = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify) entity_data_free);
dtd->priv->notations = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify) entity_data_free);
priv->general_entities = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify) entity_data_free);
priv->parameter_entities = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify) entity_data_free);
priv->notations = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify) entity_data_free);
}

static void
axing_dtd_schema_class_init (AxingDtdSchemaClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);

g_type_class_add_private (klass, sizeof (AxingDtdSchemaPrivate));

object_class->dispose = axing_dtd_schema_dispose;
object_class->finalize = axing_dtd_schema_finalize;
}
Expand All @@ -92,12 +90,16 @@ static void
axing_dtd_schema_finalize (GObject *object)
{
AxingDtdSchema *dtd = AXING_DTD_SCHEMA (object);
g_free (dtd->priv->doctype);
g_free (dtd->priv->public);
g_free (dtd->priv->system);
g_hash_table_destroy (dtd->priv->general_entities);
g_hash_table_destroy (dtd->priv->parameter_entities);
g_hash_table_destroy (dtd->priv->notations);
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);

g_free (priv->doctype);
g_free (priv->public);
g_free (priv->system);

g_hash_table_destroy (priv->general_entities);
g_hash_table_destroy (priv->parameter_entities);
g_hash_table_destroy (priv->notations);

G_OBJECT_CLASS (axing_dtd_schema_parent_class)->finalize (object);
}

Expand All @@ -111,30 +113,36 @@ void
axing_dtd_schema_set_doctype (AxingDtdSchema *dtd,
const char *doctype)
{
g_return_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd));
if (dtd->priv->doctype)
g_free (dtd->priv->doctype);
dtd->priv->doctype = g_strdup (doctype);
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);

g_return_if_fail (AXING_IS_DTD_SCHEMA (dtd));

g_free (priv->doctype);
priv->doctype = g_strdup (doctype);
}

void
axing_dtd_schema_set_public_id (AxingDtdSchema *dtd,
const char *public)
{
g_return_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd));
if (dtd->priv->public)
g_free (dtd->priv->public);
dtd->priv->public = g_strdup (public);
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);

g_return_if_fail (AXING_IS_DTD_SCHEMA (dtd));

g_free (priv->public);
priv->public = g_strdup (public);
}

void
axing_dtd_schema_set_system_id (AxingDtdSchema *dtd,
const char *system)
{
g_return_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd));
if (dtd->priv->system)
g_free (dtd->priv->system);
dtd->priv->system = g_strdup (system);
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);

g_return_if_fail (AXING_IS_DTD_SCHEMA (dtd));

g_free (priv->system);
priv->system = g_strdup (system);
}

gboolean
Expand All @@ -143,7 +151,7 @@ axing_dtd_schema_add_element (AxingDtdSchema *dtd,
const char *content,
GError **error)
{
g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);
/* FIXME */
return FALSE;
}
Expand All @@ -154,7 +162,7 @@ axing_dtd_schema_add_attlist (AxingDtdSchema *dtd,
const char *attlist,
GError **error)
{
g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);
/* FIXME */
return FALSE;
}
Expand All @@ -165,18 +173,19 @@ axing_dtd_schema_add_entity (AxingDtdSchema *dtd,
const char *name,
const char *value)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);

if (g_hash_table_lookup (dtd->priv->general_entities, name))
if (g_hash_table_lookup (priv->general_entities, name))
return FALSE;

data = g_new0 (EntityData, 1);
data->name = g_strdup (name);
data->value = g_strdup (value);

g_hash_table_insert (dtd->priv->general_entities, data->name, data);
g_hash_table_insert (priv->general_entities, data->name, data);
return TRUE;
}

Expand All @@ -186,19 +195,20 @@ axing_dtd_schema_add_external_entity (AxingDtdSchema *dtd,
const char *public,
const char *system)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);

if (g_hash_table_lookup (dtd->priv->general_entities, name))
if (g_hash_table_lookup (priv->general_entities, name))
return FALSE;

data = g_new0 (EntityData, 1);
data->name = g_strdup (name);
data->public = g_strdup (public);
data->system = g_strdup (system);

g_hash_table_insert (dtd->priv->general_entities, data->name, data);
g_hash_table_insert (priv->general_entities, data->name, data);
return TRUE;
}

Expand All @@ -209,11 +219,12 @@ axing_dtd_schema_add_unparsed_entity (AxingDtdSchema *dtd,
const char *system,
const char *ndata)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);

if (g_hash_table_lookup (dtd->priv->general_entities, name))
if (g_hash_table_lookup (priv->general_entities, name))
return FALSE;

data = g_new0 (EntityData, 1);
Expand All @@ -222,7 +233,7 @@ axing_dtd_schema_add_unparsed_entity (AxingDtdSchema *dtd,
data->system = g_strdup (system);
data->ndata = g_strdup (ndata);

g_hash_table_insert (dtd->priv->general_entities, data->name, data);
g_hash_table_insert (priv->general_entities, data->name, data);
return TRUE;
}

Expand All @@ -231,18 +242,19 @@ axing_dtd_schema_add_parameter (AxingDtdSchema *dtd,
const char *name,
const char *value)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);

if (g_hash_table_lookup (dtd->priv->parameter_entities, name))
if (g_hash_table_lookup (priv->parameter_entities, name))
return FALSE;

data = g_new0 (EntityData, 1);
data->name = g_strdup (name);
data->value = g_strdup (value);

g_hash_table_insert (dtd->priv->parameter_entities, data->name, data);
g_hash_table_insert (priv->parameter_entities, data->name, data);
return TRUE;
}

Expand All @@ -252,19 +264,20 @@ axing_dtd_schema_add_external_parameter (AxingDtdSchema *dtd,
const char *public,
const char *system)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);

if (g_hash_table_lookup (dtd->priv->parameter_entities, name))
if (g_hash_table_lookup (priv->parameter_entities, name))
return FALSE;

data = g_new0 (EntityData, 1);
data->name = g_strdup (name);
data->public = g_strdup (public);
data->system = g_strdup (system);

g_hash_table_insert (dtd->priv->parameter_entities, data->name, data);
g_hash_table_insert (priv->parameter_entities, data->name, data);
return TRUE;
}

Expand All @@ -274,36 +287,38 @@ axing_dtd_schema_add_notation (AxingDtdSchema *dtd,
const char *public,
const char *system)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);

/* FIXME: Unlike with other declarations, redefining a NOTATION
is a validity error. We cannot error out here, because this
function is called where we only care about well-formedness.
Possibly store this dup for later calls to validate().
*/
if (g_hash_table_lookup (dtd->priv->notations, name))
if (g_hash_table_lookup (priv->notations, name))
return FALSE;

data = g_new0 (EntityData, 1);
data->name = g_strdup (name);
data->public = g_strdup (public);
data->system = g_strdup (system);

g_hash_table_insert (dtd->priv->notations, data->name, data);
g_hash_table_insert (priv->notations, data->name, data);
return TRUE;
}

char *
axing_dtd_schema_get_entity (AxingDtdSchema *dtd,
const char *name)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), NULL);

data = (EntityData *) g_hash_table_lookup (dtd->priv->general_entities, name);
data = g_hash_table_lookup (priv->general_entities, name);

if (data == NULL)
return NULL;
Expand All @@ -315,11 +330,12 @@ char *
axing_dtd_schema_get_external_entity (AxingDtdSchema *dtd,
const char *name)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), NULL);

data = (EntityData *) g_hash_table_lookup (dtd->priv->general_entities, name);
data = g_hash_table_lookup (priv->general_entities, name);

if (data == NULL)
return NULL;
Expand All @@ -334,11 +350,12 @@ char *
axing_dtd_schema_get_unparsed_entity (AxingDtdSchema *dtd,
const char *name)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), NULL);

data = (EntityData *) g_hash_table_lookup (dtd->priv->general_entities, name);
data = g_hash_table_lookup (priv->general_entities, name);

if (data == NULL)
return NULL;
Expand All @@ -357,11 +374,12 @@ axing_dtd_schema_get_entity_full (AxingDtdSchema *dtd,
char **system,
char **ndata)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), FALSE);

data = (EntityData *) g_hash_table_lookup (dtd->priv->general_entities, name);
data = g_hash_table_lookup (priv->general_entities, name);

if (data == NULL)
return FALSE;
Expand All @@ -378,11 +396,12 @@ char *
axing_dtd_schema_get_parameter (AxingDtdSchema *dtd,
const char *name)
{
AxingDtdSchemaPrivate *priv = axing_dtd_schema_get_instance_private (dtd);
EntityData *data;

g_return_val_if_fail (dtd && AXING_IS_DTD_SCHEMA (dtd), FALSE);
g_return_val_if_fail (AXING_IS_DTD_SCHEMA (dtd), NULL);

data = (EntityData *) g_hash_table_lookup (dtd->priv->parameter_entities, name);
data = g_hash_table_lookup (priv->parameter_entities, name);

if (data == NULL)
return NULL;
Expand Down
Loading