FB_CALLMONITOR: use standard file read/write function to support use of configDb

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@7456 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2015-01-05 21:26:46 +00:00
parent 20924a8102
commit 60c9be5edb
2 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- change: FB_CALLMONITOR: use standard file read/write function to support use of configDb
- bugfix: FB_CALLMONITOR: fix phonebook file read when using configDb (Forum #30244) - bugfix: FB_CALLMONITOR: fix phonebook file read when using configDb (Forum #30244)
- feature: 70_XBMC: added commands: openmovieid, openepisodeid, addon, jsonraw (thanks to siggi85) - feature: 70_XBMC: added commands: openmovieid, openepisodeid, addon, jsonraw (thanks to siggi85)
- fix: 70_XBMC: made fork attribute to close file handles correctly - fix: 70_XBMC: made fork attribute to close file handles correctly

View File

@ -600,7 +600,9 @@ sub FB_CALLMONITOR_writeToCache($$$)
my ($hash, $number, $txt) = @_; my ($hash, $number, $txt) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $file = AttrVal($name, "reverse-search-cache-file", ""); my $file = AttrVal($name, "reverse-search-cache-file", "");
my $err;
my @cachefile;
$file =~ s/(^\s+|\s+$)//g; $file =~ s/(^\s+|\s+$)//g;
$hash->{helper}{CACHE}{$number} = $txt; $hash->{helper}{CACHE}{$number} = $txt;
@ -608,14 +610,17 @@ sub FB_CALLMONITOR_writeToCache($$$)
if($file ne "") if($file ne "")
{ {
Log3 $name, 4, "FB_CALLMONITOR ($name) - opening cache file $file for writing $number ($txt)"; Log3 $name, 4, "FB_CALLMONITOR ($name) - opening cache file $file for writing $number ($txt)";
if(open(CACHEFILE, ">>$file"))
foreach my $key (keys %{$hash->{helper}{CACHE}})
{ {
print CACHEFILE "$number|$txt\n"; push @cachefile, "$key|".$hash->{helper}{CACHE}{$key};
close(CACHEFILE);
} }
else
$err = FileWrite($file,@cachefile);
if(defined($err) && $err)
{ {
Log3 $name, 2, "FB_CALLMONITOR ($name) - could not open cache file for writing"; Log3 $name, 2, "FB_CALLMONITOR ($name) - could not write cache file: $err";
} }
} }
} }
@ -676,8 +681,6 @@ sub FB_CALLMONITOR_readPhonebook($;$$)
return "Could not read FritzBox phonebook file - $err"; return "Could not read FritzBox phonebook file - $err";
} }
$phonebook = join("", @lines); $phonebook = join("", @lines);
Log3 $name, 2, "FB_CALLMONITOR ($name) - found FritzBox phonebook $phonebook_file"; Log3 $name, 2, "FB_CALLMONITOR ($name) - found FritzBox phonebook $phonebook_file";
@ -776,7 +779,7 @@ sub FB_CALLMONITOR_loadCacheFile($;$)
my @tmpline; my @tmpline;
my $count_contacts; my $count_contacts;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $err;
$file = AttrVal($hash->{NAME}, "reverse-search-cache-file", "") unless(defined($file)); $file = AttrVal($hash->{NAME}, "reverse-search-cache-file", "") unless(defined($file));
$file =~ s/(^\s+|\s+$)//g; $file =~ s/(^\s+|\s+$)//g;
@ -785,11 +788,11 @@ sub FB_CALLMONITOR_loadCacheFile($;$)
delete($hash->{helper}{CACHE}) if(defined($hash->{helper}{CACHE})); delete($hash->{helper}{CACHE}) if(defined($hash->{helper}{CACHE}));
Log3 $hash->{NAME}, 3, "FB_CALLMONITOR ($name) - loading cache file $file"; Log3 $hash->{NAME}, 3, "FB_CALLMONITOR ($name) - loading cache file $file";
if(open(CACHEFILE, "$file"))
{ ($err, @cachefile) = FileRead($file);
@cachefile = <CACHEFILE>;
close(CACHEFILE); unless(defined($err) and $err)
{
foreach my $line (@cachefile) foreach my $line (@cachefile)
{ {
if(not $line =~ /^\s*$/) if(not $line =~ /^\s*$/)
@ -809,7 +812,7 @@ sub FB_CALLMONITOR_loadCacheFile($;$)
} }
else else
{ {
Log3 $name, 3, "FB_CALLMONITOR ($name) - could not open cache file"; Log3 $name, 3, "FB_CALLMONITOR ($name) - could not open cache file: $err";
} }
} }
} }