Browse code

acc(k): Change time_from_string() signature in order to remove is_time_equal().

- Let time_from_string() accept pointer to target timeval struct and return
success/error state in int-typed return value.
- Change variable names in time_from_string().
- Remove is_time_equal() which was used for error checking only.
- Remove time_error struct which is now represented by return value from
time_from_string().

Timo Reimann authored on 27/09/2011 22:13:55
Showing 1 changed files
... ...
@@ -56,7 +56,6 @@ static const str start_id = { "st", 2};
56 56
 static const str end_id = { "et", 2};
57 57
 static const str duration_id = { "d", 1};
58 58
 static const str zero_duration = { "0", 1};
59
-static const struct timeval time_error = {0,0};
60 59
 static const char time_separator = {'.'};
61 60
 static const int milliseconds_max = 1000000;
62 61
 static const unsigned int time_buffer_length = 256;
... ...
@@ -70,19 +69,6 @@ static char cdr_type_array[ MAX_CDR_CORE + MAX_CDR_EXTRA];
70 70
 
71 71
 extern struct tm_binds tmb;
72 72
 
73
-/* compare two times */
74
-static int is_time_equal( struct timeval first_time,
75
-                          struct timeval second_time)
76
-{
77
-    if( first_time.tv_sec == second_time.tv_sec &&
78
-        first_time.tv_usec == second_time.tv_usec )
79
-    {
80
-        return 1;
81
-    }
82
-
83
-    return 0;
84
-}
85
-
86 73
 /* write all basic information to buffers(e.g. start-time ...) */
87 74
 static int cdr_core2strar( struct dlg_cell* dlg,
88 75
                            str* values,
... ...
@@ -194,29 +180,29 @@ static int write_cdr( struct dlg_cell* dialog,
194 194
     return 0;
195 195
 }
196 196
 
197
-/* convert a string into a timeb struct */
198
-static struct timeval time_from_string( str* time_value)
197
+/* convert a string into a timeval struct */
198
+static int time_from_string( str* time_str, struct timeval* time_value)
199 199
 {    
200 200
     char* dot_address = NULL;
201 201
     int dot_position = -1;
202 202
     char zero_terminated_value[TIME_STR_BUFFER_SIZE];
203 203
 
204
-    if( !time_value)
204
+    if( !time_str)
205 205
     {
206
-        LM_ERR( "time_value is empty!");
207
-        return time_error;
206
+        LM_ERR( "time_str is empty!");
207
+        return -1;
208 208
     }
209 209
     
210
-    if( time_value->len >= TIME_STR_BUFFER_SIZE)
210
+    if( time_str->len >= TIME_STR_BUFFER_SIZE)
211 211
     {
212
-        LM_ERR( "time_value is to long %d >= %d!", 
213
-		time_value->len, 
212
+        LM_ERR( "time_str is too long %d >= %d!",
213
+		time_str->len,
214 214
 		TIME_STR_BUFFER_SIZE);
215
-        return time_error;
215
+        return -1;
216 216
     }
217 217
     
218
-    memcpy( zero_terminated_value, time_value->s, time_value->len);
219
-    zero_terminated_value[time_value->len] = '\0';
218
+    memcpy( zero_terminated_value, time_str->s, time_str->len);
219
+    zero_terminated_value[time_str->len] = '\0';
220 220
     
221 221
     dot_address = strchr( zero_terminated_value, time_separator);
222 222
     
... ...
@@ -225,7 +211,7 @@ static struct timeval time_from_string( str* time_value)
225 225
         LM_ERR( "failed to find separator('%c') in '%s'!\n",
226 226
                 time_separator,
227 227
                 zero_terminated_value);
228
-        return time_error;
228
+        return -1;
229 229
     }
230 230
     
231 231
     dot_position = dot_address-zero_terminated_value + 1;
... ...
@@ -234,19 +220,19 @@ static struct timeval time_from_string( str* time_value)
234 234
         strchr(dot_address + 1, time_separator))
235 235
     {
236 236
         LM_ERR( "invalid time-string '%s'\n", zero_terminated_value);
237
-        return time_error;
237
+        return -1;
238 238
     }
239 239
     
240
-    time_res->tv_sec = strtol( zero_terminated_value, (char **)NULL, 10);
241
-    time_res->tv_usec = strtol( dot_address + 1, (char **)NULL, 10);
240
+    time_value->tv_sec = strtol( zero_terminated_value, (char **)NULL, 10);
241
+    time_value->tv_usec = strtol( dot_address + 1, (char **)NULL, 10);
242 242
     return 0;
243 243
 }
244 244
 
245 245
 /* set the duration in the dialog struct */
246 246
 static int set_duration( struct dlg_cell* dialog)
247 247
 {
248
-    struct timeval start_time = time_error;
249
-    struct timeval end_time = time_error;
248
+    struct timeval start_time;
249
+    struct timeval end_time;
250 250
     int milliseconds = -1;
251 251
     int seconds = -1;
252 252
     char buffer[ time_buffer_length];
... ...
@@ -259,13 +245,12 @@ static int set_duration( struct dlg_cell* dialog)
259 259
         return -1;
260 260
     }
261 261
 
262
-    start_time = time_from_string( dlgb.get_dlg_var( dialog, (str*)&start_id));
263
-    end_time  = time_from_string( dlgb.get_dlg_var( dialog, (str*)&end_id));
264
-
265
-    if( is_time_equal( start_time, time_error) ||
266
-        is_time_equal( end_time, time_error))
267
-    {
268
-        LM_ERR( "failed to extract time from start or/and end-time\n");
262
+    if ( time_from_string( dlgb.get_dlg_var( dialog, (str*)&start_id), &start_time) < 0) {
263
+        LM_ERR( "failed to extract start time\n");
264
+        return -1;
265
+    }
266
+    if ( time_from_string( dlgb.get_dlg_var( dialog, (str*)&end_id), &end_time) < 0) {
267
+        LM_ERR( "failed to extract end time\n");
269 268
         return -1;
270 269
     }
271 270