2
* functions for dotfile handling (options, history, ...)
4
* This file is part of ANT (Ant is Not a Telephone)
6
* Copyright 2002, 2003 Roland Stigge
8
* ANT is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* ANT is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with ANT; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
* To add a new option, do the following:
25
* -> set default in session_init()
26
* -> add entry in settings_option_set()
27
* -> add entry in settings_options_write()
28
* -> of course, set it in gtksettings (also set_data()!) / whatever
29
* -> get it back in gtksettings_try()
32
/* regular GNU system includes */
37
#include <sys/types.h>
40
/* own header files */
44
#include "calleridparser.h"
49
#include "isdnlexer.h"
50
#include "isdnparser.h"
53
extern FILE *callerid_in;
54
int callerid_parse(void *session);
59
* sets an option for the specified session
61
* used as callback from yyparse()
63
void settings_option_set(session_t *session, char *option, char *value) {
64
int i_value = INT_MIN; /* set value to 0 or 1 if appropriate */
66
if (!strcmp(value, "0") || !strcasecmp(value, "false") ||
67
!strcasecmp(value, "off")) {
70
if (!strcmp(value, "1") || !strcasecmp(value, "true") ||
71
!strcasecmp(value, "on")) {
74
i_value = strtol(value, NULL, 0);
77
if (i_value != INT_MIN) {
78
if (!strcmp(option, "HistorySize")) {
79
session->dial_number_history_maxlen = i_value;
81
if (!strcmp(option, "CallerIDSize")) {
82
session->cid_num_max = i_value;
85
if (!strcmp(option, "SaveOptions")) {
86
session->option_save_options = (i_value == 0 ? 0 : 1);
89
if (!strcmp(option, "ExecOnIncoming")) {
90
free(session->exec_on_incoming);
91
session->exec_on_incoming = strdup(value);
93
if (!strcmp(option, "PopupOnIncoming")) {
94
session->option_popup = (i_value == 0 ? 0 : 1);
97
if (!strcmp(option, "RecordingFormat")) {
98
if (!strcasecmp(value, "aiff")) {
99
session->option_recording_format =
100
(session->option_recording_format & ~RECORDING_FORMAT_MAJOR)
101
| RECORDING_FORMAT_AIFF;
103
session->option_recording_format =
104
(session->option_recording_format & ~RECORDING_FORMAT_MAJOR)
105
| RECORDING_FORMAT_WAV;
108
if (!strcmp(option, "RecordingEncoding")) {
109
if (!strcasecmp(value, "s16")) {
110
session->option_recording_format =
111
(session->option_recording_format & ~RECORDING_FORMAT_MINOR)
112
| RECORDING_FORMAT_S16;
114
session->option_recording_format =
115
(session->option_recording_format & ~RECORDING_FORMAT_MINOR)
116
| RECORDING_FORMAT_ULAW;
120
if (!strncmp(option, "PresetName", 10)) {
121
int num = strtol(&option[10], NULL, 0);
122
if (0 <= num && num < SESSION_PRESET_SIZE) {
123
free(session->preset_names[num]);
124
session->preset_names[num] = strdup(value);
127
if (!strncmp(option, "PresetNumber", 12)) {
128
int num = strtol(&option[12], NULL, 0);
129
if (0 <= num && num < SESSION_PRESET_SIZE) {
130
free(session->preset_numbers[num]);
131
session->preset_numbers[num] = strdup(value);
135
if (!strcmp(option, "MergeIsdnlog")) {
136
session->option_calls_merge = (i_value == 0 ? 0 : 1);
138
if (!strcmp(option, "MergeIsdnlogDays")) {
139
session->option_calls_merge_max_days = i_value;
142
if (!strcmp(option, "AudioDeviceIn") &&
143
!strcmp(session->audio_device_name_in, "")) { /* may be overridden */
144
free(session->audio_device_name_in);
145
session->audio_device_name_in = strdup(value);
147
if (!strcmp(option, "AudioDeviceOut") &&
148
!strcmp(session->audio_device_name_out, "")) { /* may be overridden */
149
free(session->audio_device_name_out);
150
session->audio_device_name_out = strdup(value);
152
if (!strcmp(option, "ReleaseAudioDevices")) {
153
session->option_release_devices = (i_value == 0 ? 0 : 1);
155
if (!strcmp(option, "IdentifyingMSN") &&
156
!strcmp(session->msn, "")) { /* may be overridden */
158
session->msn = strdup(value);
160
if (!strcmp(option, "ListenOnMSNs") &&
161
!strcmp(session->msns, "")) { /* may be overridden */
163
session->msns = strdup(value);
167
if (!strcmp(option, "ShowCallerID")) {
168
session->option_show_callerid = (i_value == 0 ? 0 : 1);
170
if (!strcmp(option, "ShowLLCheckers")) {
171
session->option_show_llcheck = (i_value == 0 ? 0 : 1);
173
if (!strcmp(option, "ShowControlPad")) {
174
session->option_show_controlpad = (i_value == 0 ? 0 : 1);
176
if (!strcmp(option, "Muted")) {
177
session->option_muted = (i_value == 0 ? 0 : 1);
179
if (!strcmp(option, "RecordToFile")) {
180
session->option_record = (i_value == 0 ? 0 : 1);
182
if (!strcmp(option, "RecordLocalChannel")) {
183
session->option_record_local = (i_value == 0 ? 0 : 1);
185
if (!strcmp(option, "RecordRemoteChannel")) {
186
session->option_record_remote = (i_value == 0 ? 0 : 1);
193
* Read options from options file and isdn4linux config
195
* Here, we parse the config file and _change_ options. The defaults
196
* will be all set at init time
198
void settings_options_read(session_t *session) {
202
/* read isdn4linux config */
203
isdn_lexer_init(ISDN_CONFIG_FILENAME);
205
fprintf(stderr, "Warning: Couldn't read ISDN config file.\n");
207
isdn_tree_node_t* node;
212
printf("ISDN config file (%s) contents:\n", ISDN_CONFIG_FILENAME);
215
/* get calls file name if possible */
217
while (node != NULL) {
218
if (node->type == ISDN_NODE_TYPE_SECTION &&
219
!strcmp(node->name, "ISDNLOG"))
221
isdn_tree_node_t* entry = node->content.section;
223
while (entry != NULL ) {
224
if (entry->type == ISDN_NODE_TYPE_ENTRY &&
225
!strcmp(entry->name, "LOGFILE"))
227
if (isdn_calls_filename_from_config)
228
free(isdn_calls_filename_from_config);
229
isdn_calls_filename_from_config = strdup(entry->content.value);
240
if (!(homedir = get_homedir())) {
241
fprintf(stderr, "Warning: Couldn't get home dir.\n");
246
if (asprintf(&filename, "%s/." PACKAGE "/%s",
247
homedir, SETTINGS_OPTIONS_FILENAME) < 0)
250
"Warning: Couldn't allocate memory for options filename.\n");
254
isdn_lexer_init(filename);
256
fprintf(stderr, "Warning: No options file available.\n");
258
isdn_tree_node_t* node;
264
printf("Options file (%s) contents:\n", filename);
267
/* actually set options */
268
while (node != NULL) {
269
switch (node->type) {
270
case ISDN_NODE_TYPE_ENTRY:
272
printf("Setting \"%s\" to \"%s\"...\n",
273
node->name, node->content.value);
274
settings_option_set(session, node->name, node->content.value);
276
case ISDN_NODE_TYPE_SECTION:
277
fprintf(stderr, "Warning: Unexpected section \"%s\".\n", node->name);
279
case ISDN_NODE_TYPE_SUBSECTION:
281
"Warning: Unexpected subsection \"%s\".\n", node->name);
284
fprintf(stderr, "Unknown ISDN_NODE_TYPE\n");
296
* write options to options file (in dotfile directory)
298
void settings_options_write(session_t *session) {
304
if (!(homedir = get_homedir())) {
305
fprintf(stderr, "Warning: Couldn't get home dir.\n");
312
if (asprintf(&filename, "%s/." PACKAGE "/%s",
313
homedir, SETTINGS_OPTIONS_FILENAME) < 0) {
315
"Warning: Couldn't allocate memory for options filename.\n");
319
if ((f = fopen(filename, "w"))) {
320
fprintf(f, "# " PACKAGE " options file \n\n");
322
fprintf(f, "#\n# Number of dialed numbers to remember\n#\n");
323
fprintf(f, "HistorySize = %u\n\n", session->dial_number_history_maxlen);
325
fprintf(f, "#\n# Maximum number of rows Caller ID window\n#\n");
326
fprintf(f, "CallerIDSize = %u\n\n", session->cid_num_max);
328
fprintf(f, "#\n# Automatically save options on exit?\n#\n");
329
fprintf(f, "SaveOptions = %d\n\n", session->option_save_options);
331
fprintf(f, "#\n# Execute an arbitrary command on incoming call\n#\n");
332
fprintf(f, "ExecOnIncoming = \"%s\"\n\n", session->exec_on_incoming);
334
fprintf(f, "#\n# When activated, the main window will be pushed to "
335
"foreground\n# on incoming call\n#\n");
336
fprintf(f, "PopupOnIncoming = \"%d\"\n\n", session->option_popup);
338
fprintf(f, "#\n# Audio recording device\n#\n");
339
fprintf(f, "AudioDeviceIn = %s\n\n", session->audio_device_name_in);
341
fprintf(f, "#\n# Audio playback device, "
342
"may be the same as AudioDeviceIn\n#\n");
343
fprintf(f, "AudioDeviceOut = %s\n\n", session->audio_device_name_out);
345
fprintf(f, "#\n# Release audio devices in idle (\"Ready\") mode "
346
"(when not needed)\n#\n");
347
fprintf(f, "ReleaseAudioDevices = %d\n\n",session->option_release_devices);
349
fprintf(f, "#\n# MSN (Multiple Subscriber Number) to send to identify\n"
350
"# ourselves at called party\n#\n");
351
fprintf(f, "IdentifyingMSN = %s\n\n", session->msn);
353
fprintf(f, "#\n# These are the MSNs we want to listen on "
354
"(and accept calls)\n#\n");
355
fprintf(f, "ListenOnMSNs = %s\n\n", session->msns);
357
fprintf(f, "#\n# Show Caller ID frame in main window?\n#\n");
358
fprintf(f, "ShowCallerID = %d\n\n", session->option_show_callerid);
360
fprintf(f, "#\n# Show Line Level Checkers in main window?\n#\n");
361
fprintf(f, "ShowLLCheckers = %d\n\n", session->option_show_llcheck);
363
fprintf(f, "#\n# Show control pad (key pad etc.) in main window?\n#\n");
364
fprintf(f, "ShowControlPad = %d\n\n", session->option_show_controlpad);
366
fprintf(f, "#\n# Turn on to make the other party receive silence\n#\n");
367
fprintf(f, "Muted = %d\n\n", session->option_muted);
369
fprintf(f, "#\n# Record Audio stream to file?\n#\n");
370
fprintf(f, "RecordToFile = %d\n\n", session->option_record);
372
fprintf(f, "#\n# When RecordToFile is set, record local channel?\n#\n");
373
fprintf(f, "RecordLocalChannel = %d\n\n", session->option_record_local);
375
fprintf(f, "#\n# When RecordToFile is set, record remote channel?\n#\n");
376
fprintf(f, "RecordRemoteChannel = %d\n\n", session->option_record_remote);
378
fprintf(f, "#\n# Recording file format\n"
379
"# (\"wav\" for Microsoft WAV / "
380
"\"aiff\" for Apple/SGI AIFF)\n#\n");
381
fprintf(f, "RecordingFormat = \"%s\"\n\n",
382
(session->option_recording_format & RECORDING_FORMAT_MAJOR) ==
383
RECORDING_FORMAT_WAV ? "wav" : "aiff");
384
fprintf(f, "#\n# Recording file encoding\n"
385
"# (\"ulaw\" for uLaw / \"s16\" for 16-bit signed)\n#\n");
386
fprintf(f, "RecordingEncoding = \"%s\"\n\n",
387
(session->option_recording_format & RECORDING_FORMAT_MINOR) ==
388
RECORDING_FORMAT_S16 ? "s16" : "ulaw");
390
fprintf(f, "#\n# Preset Names and Numbers\n#\n");
391
for (i = 0; i < SESSION_PRESET_SIZE; i++) {
392
fprintf(f, "PresetName%d = \"%s\"\n", i, session->preset_names[i]);
393
fprintf(f, "PresetNumber%d = \"%s\"\n", i, session->preset_numbers[i]);
398
"#\n# Merge isdnlog callerid history to local history at startup?\n#\n");
399
fprintf(f, "MergeIsdnlog = %d\n\n", session->option_calls_merge);
400
fprintf(f, "#\n# Get data from this number of last days when retrieving "
402
"# isdnlog at startup\n"
403
"# (set to 0 if you prefer an unlimited number of days)\n#\n");
404
fprintf(f, "MergeIsdnlogDays = %d\n\n",
405
session->option_calls_merge_max_days);
407
if (fclose(f) == EOF) {
408
fprintf(stderr, "Warning: Couldn't close options file.\n");
411
fprintf(stderr, "Warning: Can't write to options file.\n");
416
/* Read history file and set dial combo box */
417
void settings_history_read(session_t *session) {
421
char *lineptr = NULL;
425
if (!(homedir = get_homedir())) {
426
fprintf(stderr, "Warning: Couldn't get home dir.\n");
430
if (asprintf(&filename, "%s/." PACKAGE "/%s",
431
homedir, SETTINGS_HISTORY_FILENAME) < 0) {
433
"Warning: Couldn't allocate memory for history filename.\n");
438
fprintf(stdout, "Info: History Filename: %s.\n", filename);
439
if ((f = fopen(filename, "r"))) {
441
got = getline(&lineptr, &linesize, f);
442
if (lineptr[got - 1] == '\n') {
443
lineptr[got - 1] = '\0';
445
if (got > 0 && strlen(lineptr) > 0) {
446
session_history_append(session, lineptr);
448
fprintf(stdout, "Info: History Number: %s.\n", lineptr);
452
if (fclose(f) == EOF) {
453
fprintf(stderr, "Warning: Couldn't close history file.\n");
456
fprintf(stderr, "Warning: No history file available.\n");
461
if (lineptr) free(lineptr);
465
* helper function writing the specified line s to stream f
466
* used as callback by settings_history_write
468
static void settings_history_write_line(gpointer s, gpointer f) {
470
fprintf(f, "%s\n", (char*)s);
475
* write out dial history file
477
void settings_history_write(session_t *session) {
482
if (!(homedir = get_homedir())) {
483
fprintf(stderr, "Warning: Couldn't get home dir.\n");
490
if (asprintf(&filename, "%s/." PACKAGE "/%s",
491
homedir, SETTINGS_HISTORY_FILENAME) < 0) {
493
"Warning: Couldn't allocate memory for history filename.\n");
497
if ((f = fopen(filename, "w"))) {
498
g_list_foreach(session->dial_number_history,
499
settings_history_write_line, f);
501
if (fclose(f) == EOF) {
502
fprintf(stderr, "Warning: Couldn't close history file.\n");
505
fprintf(stderr, "Warning: Can't write to history file.\n");
511
/* Read callerid history file */
512
void settings_callerid_read(session_t *session) {
516
if (!(homedir = get_homedir())) {
517
fprintf(stderr, "Warning: Couldn't get home dir.\n");
521
if (asprintf(&filename, "%s/." PACKAGE "/%s",
522
homedir, SETTINGS_CALLERID_HISTORY_FILENAME) < 0) {
523
fprintf(stderr, "Warning: "
524
"Couldn't allocate memory for caller id history filename.\n");
528
if ((callerid_in = fopen(filename, "r"))) {
529
callerid_parse(session);
530
if (fclose(callerid_in) == EOF) {
531
fprintf(stderr, "Warning: Couldn't close callerid history file.\n");
534
fprintf(stderr, "Warning: No caller id history file available.\n");
541
* write out callerid history file
543
void settings_callerid_write(session_t *session) {
554
if (!(homedir = get_homedir())) {
555
fprintf(stderr, "Warning: Couldn't get home dir.\n");
562
if (asprintf(&filename, "%s/." PACKAGE "/%s",
563
homedir, SETTINGS_CALLERID_HISTORY_FILENAME) < 0) {
564
fprintf(stderr, "Warning: "
565
"Couldn't allocate memory for callerid history filename.\n");
569
if ((f = fopen(filename, "w"))) {
570
for (akt_line = 0; akt_line < session->cid_num; akt_line++)
572
gtk_clist_get_text(GTK_CLIST(session->cid_list), akt_line,
573
CID_COL_TIME, &date);
574
gtk_clist_get_pixtext(GTK_CLIST(session->cid_list), akt_line,
575
CID_COL_TYPE, &type, NULL, NULL, NULL);
576
gtk_clist_get_text(GTK_CLIST(session->cid_list), akt_line,
577
CID_COL_FROM, &from);
578
gtk_clist_get_text(GTK_CLIST(session->cid_list), akt_line,
580
gtk_clist_get_text(GTK_CLIST(session->cid_list), akt_line,
581
CID_COL_DURATION, &duration);
583
fprintf (f, "%-19s|%-3s|%-20s|%-20s|%-10s\n",
584
date, type, from, to, duration);
586
fprintf(stderr, "%-19s|%-3s|%-20s|%-20s|%-10s\n",
587
date, type, from, to, duration);
591
if (fclose(f) == EOF) {
592
fprintf(stderr, "Warning: Couldn't close callerid history file.\n");
595
fprintf(stderr, "Warning: Can't write to callerid history file.\n");