Use val_to_str_const().
[obnox/wireshark/wip.git] / capture_stop_conditions.c
index d86bf73245e1588f20c7afb04d6e6e3527979595..09ac5b7d4ab94810feb1bd0bd64bb1b0682b74cb 100644 (file)
@@ -1,22 +1,22 @@
 /* capture_stop_conditions.c
  * Implementation for 'stop condition handler'.
  *
- * $Id: capture_stop_conditions.c,v 1.1 2001/12/04 07:32:00 guy 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
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <time.h>
 #include <string.h>
 #include <stdlib.h>
-#include <sys/stat.h> 
+#include <sys/stat.h>
 #include <stdarg.h>
 #include "conditions.h"
 #include "capture_stop_conditions.h"
 
-/* predefined classes function prototypes */ 
+/* predefined classes function prototypes */
 static condition* _cnd_constr_timeout(condition*, va_list);
 static void _cnd_destr_timeout(condition*);
 static gboolean _cnd_eval_timeout(condition*, va_list);
@@ -52,12 +52,12 @@ void init_capture_stop_conditions(void){
                      _cnd_destr_capturesize,
                      _cnd_eval_capturesize,
                      _cnd_reset_capturesize);
-} /* END init_capture_stop_conditions() */ 
+} /* END init_capture_stop_conditions() */
 
 void cleanup_capture_stop_conditions(void){
   cnd_unregister_class(CND_CLASS_TIMEOUT);
   cnd_unregister_class(CND_CLASS_CAPTURESIZE);
-} /* END cleanup_capture_stop_conditions() */ 
+} /* END cleanup_capture_stop_conditions() */
 
 /*****************************************************************************/
 /* Predefined condition 'timeout'.                                           */
@@ -65,7 +65,7 @@ void cleanup_capture_stop_conditions(void){
 /* class id */
 const char* CND_CLASS_TIMEOUT = "cnd_class_timeout";
 
-/* structure that contains user supplied data for this condition */ 
+/* structure that contains user supplied data for this condition */
 typedef struct _cnd_timeout_dat{
   time_t start_time;
   gint32 timeout_s;
@@ -76,15 +76,15 @@ typedef struct _cnd_timeout_dat{
  * 'cnd_new()' in order to perform class specific initialization.
  *
  * parameter: cnd - Pointer to condition passed by 'cnd_new()'.
- *            ap  - Pointer to user supplied arguments list for this 
- *                  constructor.   
+ *            ap  - Pointer to user supplied arguments list for this
+ *                  constructor.
  * returns:   Pointer to condition - Construction was successful.
  *            NULL                 - Construction failed.
  */
 static condition* _cnd_constr_timeout(condition* cnd, va_list ap){
   cnd_timeout_dat *data = NULL;
   /* allocate memory */
-  if((data = (cnd_timeout_dat*)malloc(sizeof(cnd_timeout_dat))) == NULL)
+  if((data = (cnd_timeout_dat*)g_malloc(sizeof(cnd_timeout_dat))) == NULL)
     return NULL;
   /* initialize user data */
   data->start_time = time(NULL);
@@ -101,7 +101,7 @@ static condition* _cnd_constr_timeout(condition* cnd, va_list ap){
  */
 static void _cnd_destr_timeout(condition* cnd){
   /* free memory */
-  free(cnd_get_user_data(cnd));
+  g_free(cnd_get_user_data(cnd));
 } /* END _cnd_destr_timeout() */
 
 /*
@@ -109,18 +109,18 @@ static void _cnd_destr_timeout(condition* cnd){
  * 'cnd_eval()' in order to perform class specific condition checks.
  *
  * parameter: cnd - The inititalized timeout condition.
- *            ap  - Pointer to user supplied arguments list for this 
- *                  handler.   
+ *            ap  - Pointer to user supplied arguments list for this
+ *                  handler.
  * returns:   TRUE  - Condition is true.
  *            FALSE - Condition is false.
  */
-static gboolean _cnd_eval_timeout(condition* cnd, va_list ap){
+static gboolean _cnd_eval_timeout(condition* cnd, va_list ap _U_){
   cnd_timeout_dat* data = (cnd_timeout_dat*)cnd_get_user_data(cnd);
   gint32 elapsed_time;
   /* check timeout here */
-  if(data->timeout_s == 0) return FALSE; /* 0 == infinite */ 
-  elapsed_time = time(NULL) - data->start_time;
-  if(elapsed_time > data->timeout_s) return TRUE;
+  if(data->timeout_s == 0) return FALSE; /* 0 == infinite */
+  elapsed_time = (gint32) (time(NULL) - data->start_time);
+  if(elapsed_time >= data->timeout_s) return TRUE;
   return FALSE;
 } /* END _cnd_eval_timeout()*/
 
@@ -132,18 +132,18 @@ static gboolean _cnd_eval_timeout(condition* cnd, va_list ap){
  */
 static void _cnd_reset_timeout(condition *cnd){
   ((cnd_timeout_dat*)cnd_get_user_data(cnd))->start_time = time(NULL);
-} /* END _cnd_reset_timeout() */ 
+} /* END _cnd_reset_timeout() */
+
 
 /*****************************************************************************/
 /* Predefined condition 'max. capturesize'.                                  */
 
-/* class id */ 
+/* class id */
 const char* CND_CLASS_CAPTURESIZE = "cnd_class_capturesize";
 
-/* structure that contains user supplied data for this condition */ 
+/* structure that contains user supplied data for this condition */
 typedef struct _cnd_capturesize_dat{
-  guint32 max_capture_size;
+  long max_capture_size;
 }cnd_capturesize_dat;
 
 /*
@@ -151,18 +151,18 @@ typedef struct _cnd_capturesize_dat{
  * 'cnd_new()' in order to perform class specific initialization.
  *
  * parameter: cnd - Pointer to condition passed by 'cnd_new()'.
- *            ap  - Pointer to user supplied arguments list for this 
- *                  constructor.   
+ *            ap  - Pointer to user supplied arguments list for this
+ *                  constructor.
  * returns:   Pointer to condition - Construction was successful.
  *            NULL                 - Construction failed.
  */
 static condition* _cnd_constr_capturesize(condition* cnd, va_list ap){
   cnd_capturesize_dat *data = NULL;
   /* allocate memory */
-  if((data = (cnd_capturesize_dat*)malloc(sizeof(cnd_capturesize_dat))) == NULL)
+  if((data = (cnd_capturesize_dat*)g_malloc(sizeof(cnd_capturesize_dat))) == NULL)
     return NULL;
   /* initialize user data */
-  data->max_capture_size = va_arg(ap, guint32);
+  data->max_capture_size = va_arg(ap, long);
   cnd_set_user_data(cnd, (void*)data);
   return cnd;
 } /* END _cnd_constr_capturesize() */
@@ -175,7 +175,7 @@ static condition* _cnd_constr_capturesize(condition* cnd, va_list ap){
  */
 static void _cnd_destr_capturesize(condition* cnd){
   /* free memory */
-  free(cnd_get_user_data(cnd));
+  g_free(cnd_get_user_data(cnd));
 } /* END _cnd_destr_capturesize() */
 
 /*
@@ -183,16 +183,16 @@ static void _cnd_destr_capturesize(condition* cnd){
  * 'cnd_eval()' in order to perform class specific condition checks.
  *
  * parameter: cnd - The inititalized capturesize condition.
- *            ap  - Pointer to user supplied arguments list for this 
- *                  handler.   
+ *            ap  - Pointer to user supplied arguments list for this
+ *                  handler.
  * returns:   TRUE  - Condition is true.
  *            FALSE - Condition is false.
  */
 static gboolean _cnd_eval_capturesize(condition* cnd, va_list ap){
   cnd_capturesize_dat* data = (cnd_capturesize_dat*)cnd_get_user_data(cnd);
   /* check capturesize here */
-  if(data->max_capture_size == 0) return FALSE; /* 0 == infinite */ 
-  if(va_arg(ap, guint32) >= data->max_capture_size){
+  if(data->max_capture_size == 0) return FALSE; /* 0 == infinite */
+  if(va_arg(ap, long) >= data->max_capture_size){
     return TRUE;
   }
   return FALSE;
@@ -204,5 +204,5 @@ static gboolean _cnd_eval_capturesize(condition* cnd, va_list ap){
  *
  * parameter: cnd - Pointer to an initialized condition.
  */
-static void _cnd_reset_capturesize(condition *cnd){
-} /* END _cnd_reset_capturesize() */ 
+static void _cnd_reset_capturesize(condition *cnd _U_){
+} /* END _cnd_reset_capturesize() */