Fix build by #if 0 out unused de_sgsap_tmsi() function.
[obnox/wireshark/wip.git] / conditions.c
index b9ae406f277930f755eadc5a8a98a39c1979baaa..831cd081543f2dd657b12d9b331859846bbfab25 100644 (file)
@@ -1,10 +1,10 @@
 /* conditions.c
  * Implementation for condition handler.
  *
- * $Id: conditions.c,v 1.3 2002/08/28 21:00:06 jmayer Exp $
+ * $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
@@ -47,7 +47,7 @@ typedef struct _cnd_class{
 } _cnd_class;
 
 /* helper function prototypes */
-static void _cnd_init();
+static void _cnd_init(void);
 static void _cnd_find_hash_key_for_class_id(gpointer, gpointer, gpointer);
 
 condition* cnd_new(const char* class_id, ...){
@@ -55,40 +55,44 @@ condition* cnd_new(const char* class_id, ...){
   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 */
@@ -96,9 +100,9 @@ void cnd_delete(condition *cnd){
   /* 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, ...){
@@ -139,15 +143,16 @@ gboolean cnd_register_class(const char* class_id,
   /* 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(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;
@@ -161,29 +166,29 @@ gboolean cnd_register_class(const char* class_id,
 
 static char* pkey = NULL;
 void cnd_unregister_class(const char* class_id){
-  char *key = (char*)class_id;
+  const char *key = (const char*)class_id;
   _cnd_class *cls = NULL;
   /* check if hash table is already initialized */
   _cnd_init();
   /* find the key for this class id and store it in 'pkey' */
   g_hash_table_foreach(classes,
                        _cnd_find_hash_key_for_class_id,
-                       key);
+                       (gpointer)key);
   /* find the class structure for this class id */
   cls = (_cnd_class*)g_hash_table_lookup(classes, class_id);
   /* 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() */
 
 /*
  * Initialize hash table.
  */
-static void _cnd_init(){
+static void _cnd_init(void){
   if(classes != NULL) return;
   /* create hash table, we use strings as keys */
   classes = g_hash_table_new(g_str_hash, g_str_equal);
@@ -201,5 +206,18 @@ void _cnd_find_hash_key_for_class_id(gpointer key,
                                      gpointer user_data){
   char* class_id = (char*)user_data;
   char* key_value = (char*)key;
-  if(strcmp(class_id, key_value) == 0) pkey = key;
+  if(strcmp(class_id, key_value) == 0) pkey = key_value;
 } /* END _cnd_find_hash_key_for_class_id() */
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 2
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=2 tabstop=8 expandtab
+ * :indentSize=2:tabSize=8:noTabs=true:
+ */