*
* $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
condition *cnd = NULL, *cnd_ref = NULL;
_cnd_class *cls = NULL;
char* id = NULL;
+
/* check if hash table is already initialized */
_cnd_init();
+
/* get class structure for this id */
- if((cls = (_cnd_class*)g_hash_table_lookup(classes, class_id)) == NULL)
+ if((cls = (_cnd_class*)g_hash_table_lookup(classes, class_id)) == NULL) {
+ g_warning("cnd_new: Couldn't find class ID \"%s\"", class_id);
return NULL;
+ }
+
/* initialize the basic structure */
- if((cnd_ref = (condition*)malloc(sizeof(condition))) == NULL) return NULL;
+ if((cnd_ref = (condition*)g_malloc(sizeof(condition))) == NULL) return NULL;
cnd_ref->user_data = NULL;
cnd_ref->eval_func = cls->eval_func;
cnd_ref->reset_func = cls->reset_func;
- /* copy the class id */
- if((id = (char*)malloc(strlen(class_id)+1)) == NULL){
- free(cnd_ref);
- return NULL;
- }
- strcpy(id, class_id);
- cnd_ref->class_id = id;
+
+ cnd_ref->class_id = g_strdup(class_id);
+
/* perform class specific initialization */
va_start(ap, class_id);
cnd = (cls->constr_func)(cnd_ref, ap);
va_end(ap);
+
/* check for successful construction */
if(cnd == NULL){
- free(cnd_ref);
- free(id);
+ g_free(cnd_ref);
+ g_free(id);
}
return cnd;
} /* END cnd_new() */
void cnd_delete(condition *cnd){
_cnd_class *cls = NULL;
- const char* class_id = cnd->class_id;
+ const char* class_id;
/* check for valid pointer */
if(cnd == NULL) return;
+
+ class_id = cnd->class_id;
/* check if hash table is already initialized */
_cnd_init();
/* get the condition class */
/* call class specific destructor */
if(cls != NULL) (cls->destr_func)(cnd);
/* free memory */
- free(cnd->class_id);
+ g_free(cnd->class_id);
/* free basic structure */
- free(cnd);
+ g_free(cnd);
} /* END cnd_delete() */
gboolean cnd_eval(condition *cnd, ...){
/* check if hash table is already initialized */
_cnd_init();
/* check for unique class id */
- if((cls = (_cnd_class*)g_hash_table_lookup(classes, class_id)) != NULL)
+ if((cls = (_cnd_class*)g_hash_table_lookup(classes, class_id)) != NULL) {
+ g_warning("cnd_register_class: Duplicate class ID \"%s\"", class_id);
return FALSE;
+ }
/* GHashTable keys need to be persistent for the lifetime of the hash
table. Allocate memory and copy the class id which we use as key. */
- if((key = (char*)malloc(strlen(class_id)+1)) == NULL) return FALSE;
- strcpy(key, class_id);
+ key = g_strdup(class_id);
/* initialize class structure */
- if((cls = (_cnd_class*)malloc(sizeof(_cnd_class))) == NULL){
- free(key);
+ if((cls = (_cnd_class*)g_malloc(sizeof(_cnd_class))) == NULL){
+ g_free(key);
return FALSE;
}
cls->constr_func = constr_func;
/* remove constructor from hash table */
g_hash_table_remove(classes, class_id);
/* free the key */
- free(pkey);
+ g_free(pkey);
pkey = NULL;
/* free the value */
- free(cls);
+ g_free(cls);
} /* END cnd_unregister_class() */
/*
char* key_value = (char*)key;
if(strcmp(class_id, key_value) == 0) pkey = key;
} /* END _cnd_find_hash_key_for_class_id() */
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 2
+ * tab-width: 2
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=2 tabstop=2 expandtab
+ * :indentSize=2:tabSize=2:noTabs=true:
+ */