~ubuntu-branches/ubuntu/trusty/isdnutils/trusty

« back to all changes in this revision

Viewing changes to ant-phone/src/settings.c

  • Committer: Package Import Robot
  • Author(s): Steve Langasek
  • Date: 2013-11-15 00:02:58 UTC
  • mfrom: (1.1.8) (31.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131115000258-tt9v3gasgrdml07k
Tags: 1:3.25+dfsg1-3.3ubuntu1
* Merge from Debian unstable:
  - resolves licensing issues with package contents.  LP: #511988.
  - includes proper upstream fix for ipppd on ARM.  LP: #453159.
  - resolves isdnutils-base removal failures.  LP: #813771.
  - fixes capiutils init script to not try to mount obsolete capifs.
    LP: #1064347.
* Remaining changes:
  - Switch libreadline5-dev to libreadline-gplv2-dev since this package
    appears to be GPLv2
  - debian/patches/no-imake.patch: Don't build xisdnload/xmonisdn using
    xmkmf/imake.  This patch was dropped in Debian without explanation;
    it still applies and seems to still be a good idea for eventual
    upstreaming, since imake is quite obsolete.
  - capi.conf: Fix typo for fcdsl2 firmware. LP: #189132.
  - Remove dependencies on /etc/inittab.
    - Disable the installation code to modify /etc/inittab.
    - isdnutils-base: Add ttyI0 example script, which needs to be installed
      in /etc/event.d/ttyI0.
    - isdnvboxserver: Add ttyI1 example script, which needs to be installed
      in /etc/event.d/ttyI1.
    - The two upstart scripts need to be edited.
    - Further improvements and documentation welcome.
* Changes included in Debian:
  - replace calls to ./MAKEDEV with /sbin/MAKEDEV
  - Build-depend on ppp-dev.
  - Switch to newer tcl -dev.
  - update to newer automake
  - debian/rules: use autoreconf to update the autotools in the capi20
    directory
  - debian/{compat,rules,*.files,.dirs}: Convert to Multi-arch.
  - debian/libcapi20-dev.install: Remove .la files (no builds use them).
* Changes included upstream:
  - fix for ARM FTBFS.
  - fix bashisms in vboxplay.
  - debian/patches/{config_libdir,toplevel-make}.patch: add CONFIG_LIBDIR
    override to upstream build system to support Multi-arch.
* Dropped changes:
  - kick dpatch to the curb.
* Handle migrating the blacklist file from
  /etc/modprobe.d/blacklist-capiutils.conf to the path used in Debian,
  /etc/modprobe.d/capiutils.conf.
* Handle rename of /etc/ppp/ip-down.d/99-ipppd and /etc/ppp/ip-up.d/00-ipppd
  to /etc/ppp/ip-down.d/ipppd and /etc/ppp/ip-up.d/ipppd
* Handle rename of /etc/init.d/isdnutils to /etc/init.d/isdnutils-base
* Restore standard.tcl to /usr/share/isdnvboxserver/default; maintainer
  scripts must not depend on contents of /usr/share/doc.
* Apply patches that were preserved in the 3.0 (quilt) migration, but
  were inadvertently not applied:
  - debian/patches/capifax.additional_error_codes.patch
  - debian/patches/capifax.3_1kHz_audio.patch
* Drop debian/isdnutils-base.cron.d, which isn't a cronjob example at all
  but an inittab example gone astray.
* debian/dotconfig*: don't use embedded quotes for paths; this confuses
  vbox's Makefiles something fierce, and causes files to be missed from
  debian/tmp'/usr/share/man/' at install time.
* Fix isdnlog and ipppd to not ship files used in the postinst under
  /usr/share/doc.
* Modernize the upstart examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * functions for dotfile handling (options, history, ...)
3
 
 *
4
 
 * This file is part of ANT (Ant is Not a Telephone)
5
 
 *
6
 
 * Copyright 2002, 2003 Roland Stigge
7
 
 *
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.
12
 
 *
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.
17
 
 *
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
21
 
 *
22
 
 *
23
 
 *
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()
30
 
 */
31
 
 
32
 
/* regular GNU system includes */
33
 
#include <stdio.h>
34
 
#include <unistd.h>
35
 
#include <stdlib.h>
36
 
#include <string.h>
37
 
#include <sys/types.h>
38
 
#include <limits.h>
39
 
 
40
 
/* own header files */
41
 
#include "globals.h"
42
 
#include "session.h"
43
 
#include "settings.h"
44
 
#include "calleridparser.h"
45
 
#include "util.h"
46
 
#include "callerid.h"
47
 
 
48
 
#include "isdn.h"
49
 
#include "isdnlexer.h"
50
 
#include "isdnparser.h"
51
 
#include "isdntree.h"
52
 
 
53
 
extern FILE *callerid_in;
54
 
int callerid_parse(void *session);
55
 
extern FILE *isdn_in;
56
 
int isdn_parse();
57
 
 
58
 
/*
59
 
 * sets an option for the specified session
60
 
 *
61
 
 * used as callback from yyparse()
62
 
 */
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 */
65
 
 
66
 
  if (!strcmp(value, "0") || !strcasecmp(value, "false") ||
67
 
      !strcasecmp(value, "off")) {
68
 
    i_value = 0;
69
 
  } else
70
 
  if (!strcmp(value, "1") || !strcasecmp(value, "true") ||
71
 
      !strcasecmp(value, "on")) {
72
 
    i_value = 1;
73
 
  } else
74
 
    i_value = strtol(value, NULL, 0);
75
 
 
76
 
  /* Settings */
77
 
  if (i_value != INT_MIN) {
78
 
    if (!strcmp(option, "HistorySize")) {
79
 
      session->dial_number_history_maxlen = i_value;
80
 
    }
81
 
    if (!strcmp(option, "CallerIDSize")) {
82
 
      session->cid_num_max = i_value;
83
 
    }
84
 
 
85
 
    if (!strcmp(option, "SaveOptions")) {
86
 
      session->option_save_options = (i_value == 0 ? 0 : 1);
87
 
    }
88
 
 
89
 
    if (!strcmp(option, "ExecOnIncoming")) {
90
 
      free(session->exec_on_incoming);
91
 
      session->exec_on_incoming = strdup(value);
92
 
    }
93
 
    if (!strcmp(option, "PopupOnIncoming")) {
94
 
      session->option_popup = (i_value == 0 ? 0 : 1);
95
 
    }
96
 
 
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;
102
 
      } else { /* wav */
103
 
        session->option_recording_format =
104
 
          (session->option_recording_format & ~RECORDING_FORMAT_MAJOR)
105
 
          | RECORDING_FORMAT_WAV;
106
 
      }
107
 
    }
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;
113
 
      } else { /* ulaw */
114
 
        session->option_recording_format =
115
 
          (session->option_recording_format & ~RECORDING_FORMAT_MINOR)
116
 
          | RECORDING_FORMAT_ULAW;
117
 
      }
118
 
    }
119
 
 
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);
125
 
      }
126
 
    }
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);
132
 
      }
133
 
    }
134
 
 
135
 
    if (!strcmp(option, "MergeIsdnlog")) {
136
 
      session->option_calls_merge = (i_value == 0 ? 0 : 1);
137
 
    }
138
 
    if (!strcmp(option, "MergeIsdnlogDays")) {
139
 
      session->option_calls_merge_max_days = i_value;
140
 
    }
141
 
 
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);
146
 
    }
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);
151
 
    }
152
 
    if (!strcmp(option, "ReleaseAudioDevices")) {
153
 
      session->option_release_devices = (i_value == 0 ? 0 : 1);
154
 
    }
155
 
    if (!strcmp(option, "IdentifyingMSN") &&
156
 
        !strcmp(session->msn, "")) { /* may be overridden */
157
 
      free(session->msn);
158
 
      session->msn = strdup(value);
159
 
    }
160
 
    if (!strcmp(option, "ListenOnMSNs") &&
161
 
        !strcmp(session->msns, "")) { /* may be overridden */
162
 
      free(session->msns);
163
 
      session->msns = strdup(value);
164
 
    }
165
 
 
166
 
    /* GUI state */
167
 
    if (!strcmp(option, "ShowCallerID")) {
168
 
      session->option_show_callerid = (i_value == 0 ? 0 : 1);
169
 
    }
170
 
    if (!strcmp(option, "ShowLLCheckers")) {
171
 
      session->option_show_llcheck = (i_value == 0 ? 0 : 1);
172
 
    }
173
 
    if (!strcmp(option, "ShowControlPad")) {
174
 
      session->option_show_controlpad = (i_value == 0 ? 0 : 1);
175
 
    }
176
 
    if (!strcmp(option, "Muted")) {
177
 
      session->option_muted = (i_value == 0 ? 0 : 1);
178
 
    }
179
 
    if (!strcmp(option, "RecordToFile")) {
180
 
      session->option_record = (i_value == 0 ? 0 : 1);
181
 
    }
182
 
    if (!strcmp(option, "RecordLocalChannel")) {
183
 
      session->option_record_local = (i_value == 0 ? 0 : 1);
184
 
    }
185
 
    if (!strcmp(option, "RecordRemoteChannel")) {
186
 
      session->option_record_remote = (i_value == 0 ? 0 : 1);
187
 
    }
188
 
 
189
 
  }
190
 
}
191
 
 
192
 
/*
193
 
 * Read options from options file and isdn4linux config
194
 
 *
195
 
 * Here, we parse the config file and _change_ options. The defaults
196
 
 * will be all set at init time
197
 
 */
198
 
void settings_options_read(session_t *session) {
199
 
  char *homedir;
200
 
  char *filename;
201
 
 
202
 
  /* read isdn4linux config */
203
 
  isdn_lexer_init(ISDN_CONFIG_FILENAME);
204
 
  if (!isdn_in) {
205
 
    fprintf(stderr, "Warning: Couldn't read ISDN config file.\n");
206
 
  } else {
207
 
    isdn_tree_node_t* node;
208
 
    
209
 
    isdn_parse();
210
 
    isdn_lexer_deinit();
211
 
    if (debug > 1) {
212
 
      printf("ISDN config file (%s) contents:\n", ISDN_CONFIG_FILENAME);
213
 
      isdn_tree_dump();
214
 
    }
215
 
    /* get calls file name if possible */
216
 
    node = isdn_tree;
217
 
    while (node != NULL) {
218
 
      if (node->type == ISDN_NODE_TYPE_SECTION &&
219
 
          !strcmp(node->name, "ISDNLOG"))
220
 
      {
221
 
        isdn_tree_node_t* entry = node->content.section;
222
 
 
223
 
        while (entry != NULL ) {
224
 
          if (entry->type == ISDN_NODE_TYPE_ENTRY &&
225
 
              !strcmp(entry->name, "LOGFILE"))
226
 
          {
227
 
            if (isdn_calls_filename_from_config)
228
 
              free(isdn_calls_filename_from_config);
229
 
            isdn_calls_filename_from_config = strdup(entry->content.value);
230
 
          }
231
 
          entry = entry->next;
232
 
        }
233
 
      }
234
 
      node = node->next;
235
 
    }
236
 
    
237
 
    isdn_tree_free();
238
 
  }
239
 
 
240
 
  if (!(homedir = get_homedir())) {
241
 
    fprintf(stderr, "Warning: Couldn't get home dir.\n");
242
 
    return;
243
 
  }
244
 
 
245
 
  /* dotfile */
246
 
  if (asprintf(&filename, "%s/." PACKAGE "/%s",
247
 
               homedir, SETTINGS_OPTIONS_FILENAME) < 0)
248
 
  {
249
 
    fprintf(stderr,
250
 
            "Warning: Couldn't allocate memory for options filename.\n");
251
 
    return;
252
 
  }
253
 
 
254
 
  isdn_lexer_init(filename);
255
 
  if (!isdn_in) {
256
 
    fprintf(stderr, "Warning: No options file available.\n");
257
 
  } else {
258
 
    isdn_tree_node_t* node;
259
 
 
260
 
    isdn_parse();
261
 
    isdn_lexer_deinit();
262
 
    node = isdn_tree;
263
 
    if (debug > 1) {
264
 
      printf("Options file (%s) contents:\n", filename);
265
 
      isdn_tree_dump();
266
 
    }
267
 
    /* actually set options */
268
 
    while (node != NULL) {
269
 
      switch (node->type) {
270
 
        case ISDN_NODE_TYPE_ENTRY:
271
 
          if (debug)
272
 
            printf("Setting \"%s\" to \"%s\"...\n",
273
 
                   node->name, node->content.value);
274
 
          settings_option_set(session, node->name, node->content.value);
275
 
          break;
276
 
        case ISDN_NODE_TYPE_SECTION:
277
 
          fprintf(stderr, "Warning: Unexpected section \"%s\".\n", node->name);
278
 
          break;
279
 
        case ISDN_NODE_TYPE_SUBSECTION:
280
 
          fprintf(stderr,
281
 
                  "Warning: Unexpected subsection \"%s\".\n", node->name);
282
 
          break;
283
 
        default:
284
 
          fprintf(stderr, "Unknown ISDN_NODE_TYPE\n");
285
 
      }
286
 
    
287
 
      node = node->next;
288
 
    }
289
 
 
290
 
    isdn_tree_free();
291
 
  }
292
 
  free(filename);
293
 
}
294
 
 
295
 
/*
296
 
 * write options to options file (in dotfile directory)
297
 
 */
298
 
void settings_options_write(session_t *session) {
299
 
  int i;
300
 
  char *homedir;
301
 
  char *filename;
302
 
  FILE *f;
303
 
 
304
 
  if (!(homedir = get_homedir())) {
305
 
    fprintf(stderr, "Warning: Couldn't get home dir.\n");
306
 
    return;
307
 
  }
308
 
 
309
 
  if (touch_dotdir())
310
 
    return;
311
 
 
312
 
  if (asprintf(&filename, "%s/." PACKAGE "/%s",
313
 
               homedir, SETTINGS_OPTIONS_FILENAME) < 0) {
314
 
    fprintf(stderr,
315
 
            "Warning: Couldn't allocate memory for options filename.\n");
316
 
    return;
317
 
  }
318
 
 
319
 
  if ((f = fopen(filename, "w"))) {
320
 
    fprintf(f, "# " PACKAGE " options file \n\n");
321
 
 
322
 
    fprintf(f, "#\n# Number of dialed numbers to remember\n#\n");
323
 
    fprintf(f, "HistorySize = %u\n\n", session->dial_number_history_maxlen);
324
 
 
325
 
    fprintf(f, "#\n# Maximum number of rows Caller ID window\n#\n");
326
 
    fprintf(f, "CallerIDSize = %u\n\n", session->cid_num_max);
327
 
 
328
 
    fprintf(f, "#\n# Automatically save options on exit?\n#\n");
329
 
    fprintf(f, "SaveOptions = %d\n\n", session->option_save_options);
330
 
 
331
 
    fprintf(f, "#\n# Execute an arbitrary command on incoming call\n#\n");
332
 
    fprintf(f, "ExecOnIncoming = \"%s\"\n\n", session->exec_on_incoming);
333
 
 
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);
337
 
 
338
 
    fprintf(f, "#\n# Audio recording device\n#\n");
339
 
    fprintf(f, "AudioDeviceIn = %s\n\n", session->audio_device_name_in);
340
 
 
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);
344
 
 
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);
348
 
 
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);
352
 
 
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);
356
 
 
357
 
    fprintf(f, "#\n# Show Caller ID frame in main window?\n#\n");
358
 
    fprintf(f, "ShowCallerID = %d\n\n", session->option_show_callerid);
359
 
 
360
 
    fprintf(f, "#\n# Show Line Level Checkers in main window?\n#\n");
361
 
    fprintf(f, "ShowLLCheckers = %d\n\n", session->option_show_llcheck);
362
 
 
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);
365
 
 
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);
368
 
 
369
 
    fprintf(f, "#\n# Record Audio stream to file?\n#\n");
370
 
    fprintf(f, "RecordToFile = %d\n\n", session->option_record);
371
 
 
372
 
    fprintf(f, "#\n# When RecordToFile is set, record local channel?\n#\n");
373
 
    fprintf(f, "RecordLocalChannel = %d\n\n", session->option_record_local);
374
 
 
375
 
    fprintf(f, "#\n# When RecordToFile is set, record remote channel?\n#\n");
376
 
    fprintf(f, "RecordRemoteChannel = %d\n\n", session->option_record_remote);
377
 
 
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");
389
 
 
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]);
394
 
    }
395
 
    fprintf(f, "\n");
396
 
 
397
 
    fprintf(f,
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 "
401
 
               "data from\n"
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);
406
 
 
407
 
    if (fclose(f) == EOF) {
408
 
      fprintf(stderr, "Warning: Couldn't close options file.\n");
409
 
    }
410
 
  } else if (debug) {
411
 
    fprintf(stderr, "Warning: Can't write to options file.\n");
412
 
  }
413
 
  free(filename);
414
 
}
415
 
 
416
 
/* Read history file and set dial combo box */
417
 
void settings_history_read(session_t *session) {
418
 
  char *homedir;
419
 
  char *filename;
420
 
  FILE *f;
421
 
  char *lineptr = NULL;
422
 
  size_t linesize = 0;
423
 
  ssize_t got;
424
 
 
425
 
  if (!(homedir = get_homedir())) {
426
 
    fprintf(stderr, "Warning: Couldn't get home dir.\n");
427
 
    return;
428
 
  }
429
 
 
430
 
  if (asprintf(&filename, "%s/." PACKAGE "/%s",
431
 
               homedir, SETTINGS_HISTORY_FILENAME) < 0) {
432
 
    fprintf(stderr,
433
 
            "Warning: Couldn't allocate memory for history filename.\n");
434
 
    return;
435
 
  }
436
 
 
437
 
  if (debug)
438
 
    fprintf(stdout, "Info: History Filename: %s.\n", filename);
439
 
  if ((f = fopen(filename, "r"))) {
440
 
    do {
441
 
      got = getline(&lineptr, &linesize, f);
442
 
      if (lineptr[got - 1] == '\n') {
443
 
        lineptr[got - 1] = '\0';
444
 
      }
445
 
      if (got > 0 && strlen(lineptr) > 0) {
446
 
        session_history_append(session, lineptr);
447
 
        if (debug)
448
 
          fprintf(stdout, "Info: History Number: %s.\n", lineptr);
449
 
      }
450
 
    } while (got > 0);
451
 
    
452
 
    if (fclose(f) == EOF) {
453
 
      fprintf(stderr, "Warning: Couldn't close history file.\n");
454
 
    }
455
 
  } else if (debug) {
456
 
    fprintf(stderr, "Warning: No history file available.\n");
457
 
  }
458
 
 
459
 
  free(filename);
460
 
  
461
 
  if (lineptr) free(lineptr);
462
 
}
463
 
 
464
 
/*
465
 
 * helper function writing the specified line s to stream f
466
 
 * used as callback by settings_history_write
467
 
 */
468
 
static void settings_history_write_line(gpointer s, gpointer f) {
469
 
  if (strcmp(s, "")) {
470
 
    fprintf(f, "%s\n", (char*)s);
471
 
  }
472
 
}
473
 
 
474
 
/*
475
 
 * write out dial history file
476
 
 */
477
 
void settings_history_write(session_t *session) {
478
 
  char *homedir;
479
 
  char *filename;
480
 
  FILE *f;
481
 
 
482
 
  if (!(homedir = get_homedir())) {
483
 
    fprintf(stderr, "Warning: Couldn't get home dir.\n");
484
 
    return;
485
 
  }
486
 
  
487
 
  if (touch_dotdir())
488
 
    return;
489
 
 
490
 
  if (asprintf(&filename, "%s/." PACKAGE "/%s",
491
 
               homedir, SETTINGS_HISTORY_FILENAME) < 0) {
492
 
    fprintf(stderr,
493
 
            "Warning: Couldn't allocate memory for history filename.\n");
494
 
    return;
495
 
  }
496
 
 
497
 
  if ((f = fopen(filename, "w"))) {
498
 
    g_list_foreach(session->dial_number_history, 
499
 
                   settings_history_write_line, f);
500
 
 
501
 
    if (fclose(f) == EOF) {
502
 
      fprintf(stderr, "Warning: Couldn't close history file.\n");
503
 
    }
504
 
  } else if (debug) {
505
 
    fprintf(stderr, "Warning: Can't write to history file.\n");
506
 
  }
507
 
 
508
 
  free(filename);
509
 
}
510
 
 
511
 
/* Read callerid history file */
512
 
void settings_callerid_read(session_t *session) {
513
 
  char *homedir;
514
 
  char *filename;
515
 
 
516
 
  if (!(homedir = get_homedir())) {
517
 
    fprintf(stderr, "Warning: Couldn't get home dir.\n");
518
 
    return;
519
 
  }
520
 
 
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");
525
 
    return;
526
 
  }
527
 
 
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");
532
 
    }
533
 
  } else if (debug) {
534
 
    fprintf(stderr, "Warning: No caller id history file available.\n");
535
 
  }
536
 
 
537
 
  free(filename);
538
 
}
539
 
 
540
 
/*
541
 
 * write out callerid history file
542
 
 */
543
 
void settings_callerid_write(session_t *session) {
544
 
  char *homedir;
545
 
  char *filename;
546
 
  FILE *f;
547
 
  int akt_line;
548
 
  gchar *date;
549
 
  gchar *type;
550
 
  gchar *from;
551
 
  gchar *to;
552
 
  gchar *duration;
553
 
 
554
 
  if (!(homedir = get_homedir())) {
555
 
    fprintf(stderr, "Warning: Couldn't get home dir.\n");
556
 
    return;
557
 
  }
558
 
 
559
 
  if (touch_dotdir())
560
 
    return;
561
 
 
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");
566
 
    return;
567
 
  }
568
 
  
569
 
  if ((f = fopen(filename, "w"))) {
570
 
    for (akt_line = 0; akt_line < session->cid_num; akt_line++)
571
 
    {
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,
579
 
                         CID_COL_TO, &to);
580
 
      gtk_clist_get_text(GTK_CLIST(session->cid_list), akt_line,
581
 
                         CID_COL_DURATION, &duration);
582
 
      
583
 
      fprintf (f, "%-19s|%-3s|%-20s|%-20s|%-10s\n",
584
 
               date, type, from, to, duration);
585
 
      if (debug > 1)
586
 
      fprintf(stderr, "%-19s|%-3s|%-20s|%-20s|%-10s\n",
587
 
                date, type, from, to, duration);
588
 
      
589
 
    }
590
 
 
591
 
    if (fclose(f) == EOF) {
592
 
      fprintf(stderr, "Warning: Couldn't close callerid history file.\n");
593
 
    }
594
 
  } else if (debug) {
595
 
    fprintf(stderr, "Warning: Can't write to callerid history file.\n");
596
 
  }
597
 
 
598
 
  free(filename);
599
 
 
600
 
}
601