File: blacklist.c

package info (click to toggle)
vdr-plugin-epgsearch 1.0.1~beta3-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,764 kB
  • ctags: 2,316
  • sloc: ansic: 23,300; perl: 1,330; sh: 608; makefile: 193
file content (771 lines) | stat: -rw-r--r-- 19,456 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
/*                                                                  -*- c++ -*-
Copyright (C) 2004-2013 Christian Wieninger

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

The author can be reached at cwieninger@gmx.de

The project's page is at http://winni.vdr-developer.org/epgsearch
*/

#include <vector>
#include "epgsearchtools.h"
#include "blacklist.h"
#include "epgsearchcats.h"
#include <vdr/tools.h>
#include "menu_dirselect.h"
#include "changrp.h"
#include "menu_search.h"
#include "menu_searchedit.h"
#include "menu_searchresults.h"
#include <math.h>

cBlacklists Blacklists;

// -- cBlacklist -----------------------------------------------------------------
char *cBlacklist::buffer = NULL;

cBlacklist::cBlacklist(void)
{
    ID = -1;
    *search = 0;
    options = 1;
    useTime = false;
    startTime = 0000;
    stopTime = 2359;
    useChannel = false;
    channelMin = Channels.GetByNumber(cDevice::CurrentChannel());
    channelMax = Channels.GetByNumber(cDevice::CurrentChannel());
    channelGroup = NULL;
    useCase = false;
    mode = 0;
    useTitle = true;
    useSubtitle = true;
    useDescription = true;
    useDuration = false;
    minDuration = 0;
    maxDuration = 130;
    useDayOfWeek = false;
    DayOfWeek = 0;
    buffer = NULL;
    isGlobal = 0;

    useExtEPGInfo = false;
    catvalues = (char**) malloc(SearchExtCats.Count() * sizeof(char*));
    cSearchExtCat *SearchExtCat = SearchExtCats.First();
    int index = 0;
    while (SearchExtCat)
    {
	catvalues[index] = (char*)malloc(MaxFileName);
	*catvalues[index] = 0;
	SearchExtCat = SearchExtCats.Next(SearchExtCat);
	index++;
    }
    ignoreMissingEPGCats = 0;
    fuzzyTolerance = 1;
}

cBlacklist::~cBlacklist(void)
{
  if (buffer) {
    free(buffer);
    buffer = NULL;
  }
  if (catvalues)
  {
      cSearchExtCat *SearchExtCat = SearchExtCats.First();
      int index = 0;
      while (SearchExtCat)
      {
	  free(catvalues[index]);
	  SearchExtCat = SearchExtCats.Next(SearchExtCat);
	  index++;
      }
      free(catvalues);
      catvalues = NULL;
  }
}

cBlacklist& cBlacklist::operator= (const cBlacklist &Blacklist)
{
  char**   catvaluesTemp = this->catvalues;
  memcpy(this, &Blacklist, sizeof(*this));
  this->catvalues = catvaluesTemp;

  cSearchExtCat *SearchExtCat = SearchExtCats.First();
  int index = 0;
  while (SearchExtCat)
  {
      *catvalues[index] = 0;
      strcpy(catvalues[index], Blacklist.catvalues[index]);
      SearchExtCat = SearchExtCats.Next(SearchExtCat);
      index++;
  }
  return *this;
}

void cBlacklist::CopyFromTemplate(const cSearchExt* templ)
{
  options = templ->options;
  useTime = templ->useTime;
  startTime = templ->startTime;
  stopTime = templ->stopTime;
  useChannel = templ->useChannel;
  useCase = templ->useCase;
  mode = templ->mode;
  useTitle = templ->useTitle;
  useSubtitle = templ->useSubtitle;
  useDescription = templ->useDescription;
  useDuration = templ->useDuration;
  minDuration = templ->minDuration;
  maxDuration = templ->maxDuration;
  useDayOfWeek = templ->useDayOfWeek;
  DayOfWeek = templ->DayOfWeek;
  useExtEPGInfo = templ->useExtEPGInfo;
  isGlobal = 0;

  cSearchExtCat *SearchExtCat = SearchExtCats.First();
  int index = 0;
  while (SearchExtCat)
  {
      strcpy(catvalues[index], templ->catvalues[index]);
      SearchExtCat = SearchExtCats.Next(SearchExtCat);
      index++;
  }

  channelMin = templ->channelMin;
  channelMax = templ->channelMax;
  if (channelGroup)
      free(channelGroup);
  if (templ->channelGroup)
      channelGroup = strdup(templ->channelGroup);
  fuzzyTolerance = templ->fuzzyTolerance;
  ignoreMissingEPGCats = templ->ignoreMissingEPGCats;
}

bool cBlacklist::operator< (const cListObject &ListObject)
{
  cBlacklist *BL = (cBlacklist *)&ListObject;
  return strcasecmp(search, BL->search) < 0;
}

const char *cBlacklist::ToText(void)
{
  char tmp_Start[5] = "";
  char tmp_Stop[5] = "";
  char tmp_minDuration[5] = "";
  char tmp_maxDuration[5] = "";
  char* tmp_chanSel = NULL;
  char* tmp_search = NULL;
  char* tmp_catvalues = NULL;

  free(buffer);
  tmp_search = strdup(search);
  while(strstr(tmp_search, "|"))
    tmp_search = strreplace(tmp_search, "|", "!^pipe^!"); // ugly: replace a pipe with something, that should not happen to be part of a regular expression

  strreplace(tmp_search, ':', '|');

  if (useTime)
  {
    sprintf(tmp_Start, "%04d", startTime);
    sprintf(tmp_Stop, "%04d", stopTime);
  }
  if (useDuration)
  {
    sprintf(tmp_minDuration, "%04d", minDuration);
    sprintf(tmp_maxDuration, "%04d", maxDuration);
  }

  if (useChannel==1)
  {
      if (channelMin->Number() < channelMax->Number())
	  msprintf(&tmp_chanSel, "%s|%s", CHANNELSTRING(channelMin), CHANNELSTRING(channelMax));
      else
	  msprintf(&tmp_chanSel, "%s", CHANNELSTRING(channelMin));
  }
  if (useChannel==2)
  {
      int channelGroupNr = ChannelGroups.GetIndex(channelGroup);
      if (channelGroupNr == -1)
      {
	  LogFile.eSysLog("channel group %s does not exist!", channelGroup);
	  useChannel = 0;
      }
      else
	  tmp_chanSel = strdup(channelGroup);
  }

  if (useExtEPGInfo)
  {
      cSearchExtCat *SearchExtCat = SearchExtCats.First();
      int index = 0;
      while (SearchExtCat)
      {
	  char* catvalue = NULL;
	  if (msprintf(&catvalue, "%s", catvalues[index])!=-1)
          {
	      while(strstr(catvalue, ":"))
	          catvalue = strreplace(catvalue, ":", "!^colon^!"); // ugly: replace with something, that should not happen to be part ofa category value
	      while(strstr(catvalue, "|"))
	          catvalue = strreplace(catvalue, "|", "!^pipe^!"); // ugly: replace with something, that should not happen to be part of a regular expression

	      if (index == 0)
	          msprintf(&tmp_catvalues, "%d#%s", SearchExtCat->id, catvalue);
	      else
	      {
	          char* temp = tmp_catvalues;
	          msprintf(&tmp_catvalues, "%s|%d#%s", tmp_catvalues, SearchExtCat->id, catvalue);
	          free(temp);
	      }
          }
	  SearchExtCat = SearchExtCats.Next(SearchExtCat);
	  index++;
	  free(catvalue);
      }
  }

  msprintf(&buffer, "%d:%s:%d:%s:%s:%d:%s:%d:%d:%d:%d:%d:%d:%s:%s:%d:%d:%d:%s:%d:%d:%d",
	   ID,
	   tmp_search,
	   useTime,
	   tmp_Start,
	   tmp_Stop,
	   useChannel,
	   (useChannel>0 && useChannel<3)?tmp_chanSel:"0",
	   useCase,
	   mode,
	   useTitle,
	   useSubtitle,
	   useDescription,
	   useDuration,
	   tmp_minDuration,
	   tmp_maxDuration,
	   useDayOfWeek,
	   DayOfWeek,
	   useExtEPGInfo,
	   useExtEPGInfo?tmp_catvalues:"",
	   fuzzyTolerance,
	   ignoreMissingEPGCats,
	   isGlobal);


  if (tmp_chanSel)
      free(tmp_chanSel);
  if (tmp_search)
      free(tmp_search);
  if (tmp_catvalues)
      free(tmp_catvalues);


  return buffer;
}

bool cBlacklist::Parse(const char *s)
{
  char *line;
  char *pos;
  char *pos_next;
  int parameter = 1;
  int valuelen;
  char value[MaxFileName];

  pos = line = strdup(s);
  pos_next = pos + strlen(pos);
  if (*pos_next == '\n') *pos_next = 0;
  while (*pos) {
    while (*pos == ' ') pos++;
    if (*pos) {
      if (*pos != ':') {
        pos_next = strchr(pos, ':');
        if (!pos_next)
          pos_next = pos + strlen(pos);
        valuelen = pos_next - pos + 1;
        if (valuelen > MaxFileName) valuelen = MaxFileName;
        strn0cpy(value, pos, valuelen);
        pos = pos_next;
        switch (parameter) {
	    case 1:  ID = atoi(value);
		break;
	    case 2:  strcpy(search, value);
	      break;
	    case 3:  useTime = atoi(value);
	      break;
	    case 4:  startTime = atoi(value);
		break;
	    case 5:  stopTime = atoi(value);
	      break;
	    case 6:  useChannel = atoi(value);
		break;
	    case 7:
		if (useChannel == 0)
		{
		    channelMin = NULL;
		    channelMax = NULL;
		}
		else if (useChannel == 1)
		{
		    int minNum=0, maxNum=0;
		    int fields = sscanf(value, "%d-%d", &minNum, &maxNum);
		    if (fields == 0) // stored with ID
		    {
#ifdef __FreeBSD__
			char *channelMinbuffer = MALLOC(char, 32);
			char *channelMaxbuffer = MALLOC(char, 32);
			int channels = sscanf(value, "%31[^|]|%31[^|]", channelMinbuffer, channelMaxbuffer);
#else
			char *channelMinbuffer = NULL;
			char *channelMaxbuffer = NULL;
			int channels = sscanf(value, "%a[^|]|%a[^|]", &channelMinbuffer, &channelMaxbuffer);
#endif
			channelMin = Channels.GetByChannelID(tChannelID::FromString(channelMinbuffer), true, true);
			if (!channelMin)
			{
			    LogFile.eSysLog("ERROR: channel %s not defined", channelMinbuffer);
			    channelMin = channelMax = NULL;
			    useChannel = 0;
			}
			if (channels == 1)
			    channelMax = channelMin;
			else
			{
			    channelMax = Channels.GetByChannelID(tChannelID::FromString(channelMaxbuffer), true, true);
			    if (!channelMax)
			    {
				LogFile.eSysLog("ERROR: channel %s not defined", channelMaxbuffer);
				channelMin = channelMax = NULL;
				useChannel = 0;
			    }
			}
			free(channelMinbuffer);
			free(channelMaxbuffer);
		    }
		}
		else if (useChannel == 2)
		    channelGroup = strdup(value);
	      break;
	    case 8:  useCase = atoi(value);
	      break;
	    case 9:  mode = atoi(value);
		break;
	    case 10: useTitle = atoi(value);
		break;
	    case 11: useSubtitle = atoi(value);
		break;
	    case 12: useDescription = atoi(value);
		break;
	    case 13: useDuration = atoi(value);
		break;
	    case 14: minDuration = atoi(value);
		break;
	    case 15: maxDuration = atoi(value);
		break;
	    case 16: useDayOfWeek = atoi(value);
			break;
	    case 17: DayOfWeek = atoi(value);
			break;
	    case 18: useExtEPGInfo = atoi(value);
			break;
	    case 19:
		if (!ParseExtEPGValues(value))
		{
		    LogFile.eSysLog("ERROR reading ext. EPG values - 1");
		    free(line);
		    return false;
		}
		break;
	    case 20: fuzzyTolerance = atoi(value);
		break;
            case 21: ignoreMissingEPGCats = atoi(value);
         	break;
            case 22: isGlobal = atoi(value);
         	break;
	    default:
	        break;
        } //switch
      }
      parameter++;
    }
    if (*pos) pos++;
  } //while

  strreplace(search, '|', ':');
  while(strstr(search, "!^pipe^!"))
      strreplace(search, "!^pipe^!", "|");

  free(line);
  return (parameter >= 19) ? true : false;
}

bool cBlacklist::ParseExtEPGValues(const char *s)
{
  char *line;
  char *pos;
  char *pos_next;
  int valuelen;
  char value[MaxFileName];

  pos = line = strdup(s);
  pos_next = pos + strlen(pos);
  if (*pos_next == '\n') *pos_next = 0;
  while (*pos) {
    while (*pos == ' ') pos++;
    if (*pos) {
      if (*pos != '|') {
        pos_next = strchr(pos, '|');
        if (!pos_next)
          pos_next = pos + strlen(pos);
        valuelen = pos_next - pos + 1;
        if (valuelen > MaxFileName) valuelen = MaxFileName;
        strn0cpy(value, pos, valuelen);
        pos = pos_next;
	if (!ParseExtEPGEntry(value))
	{
	    LogFile.eSysLog("ERROR reading ext. EPG value: %s", value);
	    free(line);
	    return false;
	}
      }
    }
    if (*pos) pos++;
  } //while

  free(line);
  return true;
}

bool cBlacklist::ParseExtEPGEntry(const char *s)
{
  char *line;
  char *pos;
  char *pos_next;
  int parameter = 1;
  int valuelen;
  char value[MaxFileName];
  int currentid = -1;

  pos = line = strdup(s);
  pos_next = pos + strlen(pos);
  if (*pos_next == '\n') *pos_next = 0;
  while (*pos) {
    while (*pos == ' ') pos++;
    if (*pos) {
      if (*pos != '#') {
        pos_next = strchr(pos, '#');
        if (!pos_next)
          pos_next = pos + strlen(pos);
        valuelen = pos_next - pos + 1;
        if (valuelen > MaxFileName) valuelen = MaxFileName;
        strn0cpy(value, pos, valuelen);
        pos = pos_next;
        switch (parameter) {
	    case 1:
	    {
		currentid = atoi(value);
		int index = SearchExtCats.GetIndexFromID(currentid);
		if (index > -1)
		    strcpy(catvalues[index], "");
	    }
	    break;
	    case 2:
		if (currentid > -1)
		{
		    int index = SearchExtCats.GetIndexFromID(currentid);
		    if (index > -1)
		    {
			while(strstr(value, "!^colon^!"))
			    strreplace(value, "!^colon^!", ":");
			while(strstr(value, "!^pipe^!"))
			    strreplace(value, "!^pipe^!", "|");
			strcpy(catvalues[index], value);
		    }
		}
	      break;
	    default:
              break;
        } //switch
      }
      parameter++;
    }
    if (*pos) pos++;
  } //while

  free(line);
  return (parameter >= 2) ? true : false;
}

bool cBlacklist::Save(FILE *f)
{
  return fprintf(f, "%s\n", ToText()) > 0;
}

cEvent * cBlacklist::GetEventByBlacklist(const cSchedule *schedules, const cEvent *Start, int MarginStop)
{
  cEvent *pe = NULL;
  cEvent *p1 = NULL;

  if (Start)
      p1 = schedules->Events()->Next(Start);
  else
      p1 = schedules->Events()->First();

  time_t tNow=time(NULL);
  char* szTest = NULL;
  char* searchText = strdup(search);

  if (!useCase)
      ToLower(searchText);

  int searchStart = 0, searchStop = 0;
  if (useTime)
  {
	searchStart = startTime;
	searchStop = stopTime;
	if (searchStop < searchStart)
		searchStop += 2400;
  }
  int minSearchDuration = 0;
  int maxSearchDuration = 0;
  if (useDuration)
  {
      minSearchDuration = minDuration/100*60 + minDuration%100;
      maxSearchDuration = maxDuration/100*60 + maxDuration%100;
  }

  for (cEvent *p = p1; p; p = schedules->Events()->Next(p))
  {
     if(!p)
     {
        break;
     }

     if (szTest)
     {
	free(szTest);
	szTest = NULL;
     }

     // ignore events without title
     if (!p->Title() || strlen(p->Title()) == 0)
	 continue;

     msprintf(&szTest, "%s%s%s%s%s", (useTitle?p->Title():""), (useSubtitle||useDescription)?"~":"",
	      (useSubtitle?p->ShortText():""),useDescription?"~":"",
	      (useDescription?p->Description():""));

     if (tNow < p->EndTime() + MarginStop * 60)
     {
        if (!useCase)
	    ToLower(szTest);

        if (useTime)
        {
		time_t tEvent = p->StartTime();
		struct tm tmEvent;
		localtime_r(&tEvent, &tmEvent);
		int eventStart = tmEvent.tm_hour*100 + tmEvent.tm_min;
		int eventStart2 = tmEvent.tm_hour*100 + tmEvent.tm_min + 2400;
		if ((eventStart < searchStart || eventStart > searchStop) &&
		    (eventStart2 < searchStart || eventStart2 > searchStop))
			continue;
        }
        if (useDuration)
        {
		int duration = p->Duration()/60;
		if (minSearchDuration > duration || maxSearchDuration < duration)
		    continue;
        }

	if (useDayOfWeek)
	{
	    time_t tEvent = p->StartTime();
	    struct tm tmEvent;
	    localtime_r(&tEvent, &tmEvent);
	    if (DayOfWeek >= 0 && DayOfWeek != tmEvent.tm_wday)
		continue;
	    if (DayOfWeek < 0)
	    {
		int iFound = 0;
		for(int i=0; i<7; i++)
		    if (abs(DayOfWeek) & (int)pow(2,i) && i == tmEvent.tm_wday)
		    {
			iFound = 1;
			break;
		    }
		if (!iFound)
		    continue;
	    }
	}

 	if (strlen(szTest) > 0)
	{
	    if (!MatchesSearchMode(szTest, searchText, mode," ,;|~", fuzzyTolerance))
		continue;
	}

	if (useExtEPGInfo && !MatchesExtEPGInfo(p))
	    continue;
	pe=p;
	break;
     }
  }
  if (szTest)
	free(szTest);
  free(searchText);
  return pe;
}

// returns a pointer array to the matching search results
cSearchResults* cBlacklist::Run(cSearchResults* pSearchResults, int MarginStop)
{
    LogFile.Log(3,"start search for blacklist '%s'", search);

    cSchedulesLock schedulesLock;
    const cSchedules *schedules;
    schedules = cSchedules::Schedules(schedulesLock);
    if(!schedules) {
	LogFile.Log(1,"schedules are currently locked! try again later.");
	return NULL;
    }

    const cSchedule *Schedule = schedules->First();

    while (Schedule) {
	cChannel* channel = Channels.GetByChannelID(Schedule->ChannelID(),true,true);
	if (!channel)
	{
	    Schedule = (const cSchedule *)schedules->Next(Schedule);
	    continue;
	}

        if (useChannel == 1 && channelMin && channelMax)
	{
	    if (channelMin->Number() > channel->Number() || channelMax->Number() < channel->Number())
	    {
		Schedule = (const cSchedule *)schedules->Next(Schedule);
		continue;
	    }
	}
        if (useChannel == 2 && channelGroup)
	{
	    cChannelGroup* group = ChannelGroups.GetGroupByName(channelGroup);
	    if (!group || !group->ChannelInGroup(channel))
	    {
		Schedule = (const cSchedule *)schedules->Next(Schedule);
		continue;
	    }
	}

	if (useChannel == 3)
	{
	    if (channel->Ca() >= CA_ENCRYPTED_MIN)
	    {
		Schedule = (const cSchedule *)schedules->Next(Schedule);
		continue;
	    }
	}

        const cEvent *pPrevEvent = NULL;
        do {
	    const cEvent* event = GetEventByBlacklist(Schedule, pPrevEvent, MarginStop);
	    pPrevEvent = event;
	    if (event && Channels.GetByChannelID(event->ChannelID(),true,true))
	    {
		if (!pSearchResults) pSearchResults = new cSearchResults;
		pSearchResults->Add(new cSearchResult(event, this));
	    }
        } while(pPrevEvent);
        Schedule = (const cSchedule *)schedules->Next(Schedule);
    }
    LogFile.Log(3,"found %d event(s) for blacklist '%s'", pSearchResults?pSearchResults->Count():0, search);

    return pSearchResults;
}

bool cBlacklist::MatchesExtEPGInfo(const cEvent* e)
{
    if (!e || !e->Description())
	return false;
    cSearchExtCat* SearchExtCat = SearchExtCats.First();
    while (SearchExtCat)
    {
	char* value = NULL;
	int index = SearchExtCats.GetIndexFromID(SearchExtCat->id);
	if (index > -1)
	    value = catvalues[index];
	if (value && strlen(value) > 0)
	{
	    char* testvalue = GetExtEPGValue(e, SearchExtCat);
	    if (!testvalue)
		return false;

	    // compare not case sensitive
	    char* valueLower = strdup(value);
	    ToLower(valueLower);
	    ToLower(testvalue);
	    if (!MatchesSearchMode(testvalue, valueLower, SearchExtCat->searchmode, ",;|~", fuzzyTolerance))
	    {
		free(testvalue);
		free(valueLower);
		return false;
	    }
	    free(testvalue);
	    free(valueLower);
	}
	SearchExtCat = SearchExtCats.Next(SearchExtCat);
    }
    return true;
}

// -- cBlacklists ----------------------------------------------------------------
int cBlacklists::GetNewID()
{
    int newID = -1;
    cMutexLock BlacklistLock(this);
    cBlacklist *l = (cBlacklist *)First();
    while (l) {
	newID = max(newID, l->ID);
	l = (cBlacklist *)l->Next();
    }
    return newID+1;
}

cBlacklist* cBlacklists::GetBlacklistFromID(int ID)
{
    if (ID == -1)
	return NULL;
    cMutexLock BlacklistLock(this);
    cBlacklist *l = (cBlacklist *)First();
    while (l) {
	if (l->ID == ID)
	    return l;
	l = (cBlacklist *)l->Next();
    }
    return NULL;
}

bool cBlacklists::Exists(const cBlacklist* Blacklist)
{
    cMutexLock BlacklistLock(this);
    cBlacklist *l = (cBlacklist*)First();
    while (l)
    {
	if (l == Blacklist)
	    return true;
	l = (cBlacklist*)l->Next();
    }
    return false;
}