Browse code

acc: use acc.time_mode to save cdrs in gmtime

- reuse acc.time_mode modparam for cdr entries, storing start_time and
end_time in gmtime if time_mode is 4.

GH #1358

Carlos Cruz authored on 14/12/2017 15:33:04
Showing 1 changed files
... ...
@@ -64,6 +64,7 @@
64 64
 
65 65
 #define TIME_STR_BUFFER_SIZE 20
66 66
 #define TIME_BUFFER_LENGTH 256
67
+#define TIME_STRING_FORMAT "%Y-%m-%d %H:%M:%S"
67 68
 
68 69
 struct dlg_binds dlgb;
69 70
 struct acc_extra* cdr_extra = NULL;
... ...
@@ -141,6 +142,8 @@ static int db_write_cdr( struct dlg_cell* dialog,
141 142
 	long long_val;
142 143
 	double double_val;
143 144
 	char * end;
145
+	struct tm *t;
146
+	char cdr_time_format_buf[MAX_CDR_CORE][TIME_STR_BUFFER_SIZE];
144 147
 
145 148
 	if(acc_cdrs_table.len<=0)
146 149
 		return 0;
... ...
@@ -182,13 +185,24 @@ static int db_write_cdr( struct dlg_cell* dialog,
182 185
 				VAL_STR(db_cdr_vals+i) = cdr_value_array[i];
183 186
 				break;
184 187
 			case TYPE_DATE:
185
-				VAL_TYPE(db_cdr_vals+i)=DB1_DATETIME;
186 188
 				VAL_NULL(db_cdr_vals+i)=0;
187 189
 				if(string2time(&cdr_value_array[i], &timeval_val) < 0) {
188 190
 					LM_ERR("failed to convert string to timeval.\n");
189 191
 					goto error;
190 192
 				}
191
-				VAL_TIME(db_cdr_vals+i) = timeval_val.tv_sec;
193
+				if (acc_time_mode==4) {
194
+					VAL_TYPE(db_cdr_vals+i)=DB1_STRING;
195
+					t = gmtime(&timeval_val.tv_sec);
196
+					/* Convert time_t structure to format accepted by the database */
197
+					if (strftime(cdr_time_format_buf[i], TIME_STR_BUFFER_SIZE, TIME_STRING_FORMAT, t) <= 0) {
198
+						cdr_time_format_buf[i][0] = '\0';
199
+					}
200
+
201
+					VAL_STRING(db_cdr_vals+i) = cdr_time_format_buf[i];
202
+				} else {
203
+					VAL_TYPE(db_cdr_vals+i)=DB1_DATETIME;
204
+					VAL_TIME(db_cdr_vals+i) = timeval_val.tv_sec;
205
+				}
192 206
 				break;
193 207
 			case TYPE_DOUBLE:
194 208
 				VAL_TYPE(db_cdr_vals+i)=DB1_DOUBLE;