-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathactions.c
1984 lines (1776 loc) · 60.4 KB
/
actions.c
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
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/actions.c,v $
*
* Purpose : Declares functions to work with actions files
*
* Copyright : Written by and Copyright (C) 2001-2016 the
* Privoxy team. http://www.privoxy.org/
*
* Based on the Internet Junkbuster originally written
* by and Copyright (C) 1997 Anonymous Coders and
* Junkbusters Corporation. http://www.junkbusters.com
*
* 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.
*
* The GNU General Public License should be included with
* this file. If not, you can view it at
* http://www.gnu.org/copyleft/gpl.html
* or write to the Free Software Foundation, Inc., 59
* Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*********************************************************************/
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#ifdef FEATURE_PTHREAD
#include <pthread.h>
#endif
#include "project.h"
#include "jcc.h"
#include "list.h"
#include "actions.h"
#include "miscutil.h"
#include "errlog.h"
#include "loaders.h"
#include "encode.h"
#include "urlmatch.h"
#include "cgi.h"
#include "ssplit.h"
#include "filters.h"
/*
* We need the main list of options.
*
* First, we need a way to tell between boolean, string, and multi-string
* options. For string and multistring options, we also need to be
* able to tell the difference between a "+" and a "-". (For bools,
* the "+"/"-" information is encoded in "add" and "mask"). So we use
* an enumerated type (well, the preprocessor equivalent). Here are
* the values:
*/
enum action_value_type {
AV_NONE = 0, /* +opt -opt */
AV_ADD_STRING = 1, /* +stropt{string} */
AV_REM_STRING = 2, /* -stropt */
AV_ADD_MULTI = 3, /* +multiopt{string} +multiopt{string2} */
AV_REM_MULTI = 4 /* -multiopt{string} -multiopt */
};
/*
* We need a structure to hold the name, flag changes,
* type, and string index.
*/
struct action_name
{
const char * name;
unsigned long mask; /* a bit set to "0" = remove action */
unsigned long add; /* a bit set to "1" = add action */
enum action_value_type value_type; /* an AV_... constant */
int index; /* index into strings[] or multi[] */
};
/*
* And with those building blocks in place, here's the array.
*/
static const struct action_name action_names[] =
{
/*
* Well actually there's no data here - it's in actionlist.h
* This keeps it together to make it easy to change.
*
* Here's the macros used to format it:
*/
#define DEFINE_ACTION_MULTI(name,index) \
{ "+" name, ACTION_MASK_ALL, 0, AV_ADD_MULTI, index }, \
{ "-" name, ACTION_MASK_ALL, 0, AV_REM_MULTI, index },
#define DEFINE_ACTION_STRING(name,flag,index) \
{ "+" name, ACTION_MASK_ALL, flag, AV_ADD_STRING, index }, \
{ "-" name, ~flag, 0, AV_REM_STRING, index },
#define DEFINE_ACTION_BOOL(name,flag) \
{ "+" name, ACTION_MASK_ALL, flag }, \
{ "-" name, ~flag, 0 },
#define DEFINE_ACTION_ALIAS 1 /* Want aliases please */
#include "actionlist.h"
#undef DEFINE_ACTION_MULTI
#undef DEFINE_ACTION_STRING
#undef DEFINE_ACTION_BOOL
#undef DEFINE_ACTION_ALIAS
{ NULL, 0, 0 } /* End marker */
};
#ifndef FUZZ
static
#endif
int load_one_actions_file(struct client_state *csp, int fileid);
/*********************************************************************
*
* Function : merge_actions
*
* Description : Merge two actions together.
* Similar to "dest += src".
*
* Parameters :
* 1 : dest = Actions to modify.
* 2 : src = Action to add.
*
* Returns : JB_ERR_OK or JB_ERR_MEMORY
*
*********************************************************************/
jb_err merge_actions (struct action_spec *dest,
const struct action_spec *src)
{
int i;
jb_err err;
dest->mask &= src->mask;
dest->add &= src->mask;
dest->add |= src->add;
for (i = 0; i < ACTION_STRING_COUNT; i++)
{
char * str = src->string[i];
if (str)
{
freez(dest->string[i]);
dest->string[i] = strdup_or_die(str);
}
}
for (i = 0; i < ACTION_MULTI_COUNT; i++)
{
if (src->multi_remove_all[i])
{
/* Remove everything from dest */
list_remove_all(dest->multi_remove[i]);
dest->multi_remove_all[i] = 1;
err = list_duplicate(dest->multi_add[i], src->multi_add[i]);
}
else if (dest->multi_remove_all[i])
{
/*
* dest already removes everything, so we only need to worry
* about what we add.
*/
list_remove_list(dest->multi_add[i], src->multi_remove[i]);
err = list_append_list_unique(dest->multi_add[i], src->multi_add[i]);
}
else
{
/* No "remove all"s to worry about. */
list_remove_list(dest->multi_add[i], src->multi_remove[i]);
err = list_append_list_unique(dest->multi_remove[i], src->multi_remove[i]);
if (!err) err = list_append_list_unique(dest->multi_add[i], src->multi_add[i]);
}
if (err)
{
return err;
}
}
return JB_ERR_OK;
}
/*********************************************************************
*
* Function : copy_action
*
* Description : Copy an action_specs.
* Similar to "dest = src".
*
* Parameters :
* 1 : dest = Destination of copy.
* 2 : src = Source for copy.
*
* Returns : JB_ERR_OK or JB_ERR_MEMORY
*
*********************************************************************/
jb_err copy_action (struct action_spec *dest,
const struct action_spec *src)
{
int i;
jb_err err = JB_ERR_OK;
free_action(dest);
memset(dest, '\0', sizeof(*dest));
dest->mask = src->mask;
dest->add = src->add;
for (i = 0; i < ACTION_STRING_COUNT; i++)
{
char * str = src->string[i];
if (str)
{
str = strdup_or_die(str);
dest->string[i] = str;
}
}
for (i = 0; i < ACTION_MULTI_COUNT; i++)
{
dest->multi_remove_all[i] = src->multi_remove_all[i];
err = list_duplicate(dest->multi_remove[i], src->multi_remove[i]);
if (err)
{
return err;
}
err = list_duplicate(dest->multi_add[i], src->multi_add[i]);
if (err)
{
return err;
}
}
return err;
}
/*********************************************************************
*
* Function : free_action_spec
*
* Description : Frees an action_spec and the memory used by it.
*
* Parameters :
* 1 : src = Source to free.
*
* Returns : N/A
*
*********************************************************************/
void free_action_spec(struct action_spec *src)
{
free_action(src);
freez(src);
}
/*********************************************************************
*
* Function : free_action
*
* Description : Destroy an action_spec. Frees memory used by it,
* except for the memory used by the struct action_spec
* itself.
*
* Parameters :
* 1 : src = Source to free.
*
* Returns : N/A
*
*********************************************************************/
void free_action (struct action_spec *src)
{
int i;
if (src == NULL)
{
return;
}
for (i = 0; i < ACTION_STRING_COUNT; i++)
{
freez(src->string[i]);
}
for (i = 0; i < ACTION_MULTI_COUNT; i++)
{
destroy_list(src->multi_remove[i]);
destroy_list(src->multi_add[i]);
}
memset(src, '\0', sizeof(*src));
}
/*********************************************************************
*
* Function : get_action_token
*
* Description : Parses a line for the first action.
* Modifies its input array, doesn't allocate memory.
* e.g. given:
* *line=" +abc{def} -ghi "
* Returns:
* *line=" -ghi "
* *name="+abc"
* *value="def"
*
* Parameters :
* 1 : line = [in] The line containing the action.
* [out] Start of next action on line, or
* NULL if we reached the end of line before
* we found an action.
* 2 : name = [out] Start of action name, null
* terminated. NULL on EOL
* 3 : value = [out] Start of action value, null
* terminated. NULL if none or EOL.
*
* Returns : JB_ERR_OK => Ok
* JB_ERR_PARSE => Mismatched {} (line was trashed anyway)
*
*********************************************************************/
jb_err get_action_token(char **line, char **name, char **value)
{
char * str = *line;
char ch;
/* set default returns */
*line = NULL;
*name = NULL;
*value = NULL;
/* Eat any leading whitespace */
while ((*str == ' ') || (*str == '\t'))
{
str++;
}
if (*str == '\0')
{
return 0;
}
if (*str == '{')
{
/* null name, just value is prohibited */
return JB_ERR_PARSE;
}
*name = str;
/* parse option */
while (((ch = *str) != '\0') &&
(ch != ' ') && (ch != '\t') && (ch != '{'))
{
if (ch == '}')
{
/* error, '}' without '{' */
return JB_ERR_PARSE;
}
str++;
}
*str = '\0';
if (ch != '{')
{
/* no value */
if (ch == '\0')
{
/* EOL - be careful not to run off buffer */
*line = str;
}
else
{
/* More to parse next time. */
*line = str + 1;
}
return JB_ERR_OK;
}
str++;
*value = str;
/* The value ends with the first non-escaped closing curly brace */
while ((str = strchr(str, '}')) != NULL)
{
if (str[-1] == '\\')
{
/* Overwrite the '\' so the action doesn't see it. */
string_move(str-1, str);
continue;
}
break;
}
if (str == NULL)
{
/* error */
*value = NULL;
return JB_ERR_PARSE;
}
/* got value */
*str = '\0';
*line = str + 1;
chomp(*value);
return JB_ERR_OK;
}
/*********************************************************************
*
* Function : action_used_to_be_valid
*
* Description : Checks if unrecognized actions were valid in earlier
* releases.
*
* Parameters :
* 1 : action = The string containing the action to check.
*
* Returns : True if yes, otherwise false.
*
*********************************************************************/
static int action_used_to_be_valid(const char *action)
{
static const char * const formerly_valid_actions[] = {
"inspect-jpegs",
"kill-popups",
"send-vanilla-wafer",
"send-wafer",
"treat-forbidden-connects-like-blocks",
"vanilla-wafer",
"wafer"
};
unsigned int i;
for (i = 0; i < SZ(formerly_valid_actions); i++)
{
if (0 == strcmpic(action, formerly_valid_actions[i]))
{
return TRUE;
}
}
return FALSE;
}
/*********************************************************************
*
* Function : get_actions
*
* Description : Parses a list of actions.
*
* Parameters :
* 1 : line = The string containing the actions.
* Will be written to by this function.
* 2 : alias_list = Custom alias list, or NULL for none.
* 3 : cur_action = Where to store the action. Caller
* allocates memory.
*
* Returns : JB_ERR_OK => Ok
* JB_ERR_PARSE => Parse error (line was trashed anyway)
* nonzero => Out of memory (line was trashed anyway)
*
*********************************************************************/
jb_err get_actions(char *line,
struct action_alias * alias_list,
struct action_spec *cur_action)
{
jb_err err;
init_action(cur_action);
cur_action->mask = ACTION_MASK_ALL;
while (line)
{
char * option = NULL;
char * value = NULL;
err = get_action_token(&line, &option, &value);
if (err)
{
return err;
}
if (option)
{
/* handle option in 'option' */
/* Check for standard action name */
const struct action_name * action = action_names;
while ((action->name != NULL) && (0 != strcmpic(action->name, option)))
{
action++;
}
if (action->name != NULL)
{
/* Found it */
cur_action->mask &= action->mask;
cur_action->add &= action->mask;
cur_action->add |= action->add;
switch (action->value_type)
{
case AV_NONE:
if (value != NULL)
{
log_error(LOG_LEVEL_ERROR,
"Action %s does not take parameters but %s was given.",
action->name, value);
return JB_ERR_PARSE;
}
break;
case AV_ADD_STRING:
{
/* add single string. */
if ((value == NULL) || (*value == '\0'))
{
if (0 == strcmpic(action->name, "+block"))
{
/*
* XXX: Temporary backwards compatibility hack.
* XXX: should include line number.
*/
value = "No reason specified.";
log_error(LOG_LEVEL_ERROR,
"block action without reason found. This may "
"become a fatal error in future versions.");
}
else
{
return JB_ERR_PARSE;
}
}
/* FIXME: should validate option string here */
freez (cur_action->string[action->index]);
cur_action->string[action->index] = strdup(value);
if (NULL == cur_action->string[action->index])
{
return JB_ERR_MEMORY;
}
break;
}
case AV_REM_STRING:
{
/* remove single string. */
freez (cur_action->string[action->index]);
break;
}
case AV_ADD_MULTI:
{
/* append multi string. */
struct list * remove_p = cur_action->multi_remove[action->index];
struct list * add_p = cur_action->multi_add[action->index];
if ((value == NULL) || (*value == '\0'))
{
return JB_ERR_PARSE;
}
list_remove_item(remove_p, value);
err = enlist_unique(add_p, value, 0);
if (err)
{
return err;
}
break;
}
case AV_REM_MULTI:
{
/* remove multi string. */
struct list * remove_p = cur_action->multi_remove[action->index];
struct list * add_p = cur_action->multi_add[action->index];
if ((value == NULL) || (*value == '\0')
|| ((*value == '*') && (value[1] == '\0')))
{
/*
* no option, or option == "*".
*
* Remove *ALL*.
*/
list_remove_all(remove_p);
list_remove_all(add_p);
cur_action->multi_remove_all[action->index] = 1;
}
else
{
/* Valid option - remove only 1 option */
if (!cur_action->multi_remove_all[action->index])
{
/* there isn't a catch-all in the remove list already */
err = enlist_unique(remove_p, value, 0);
if (err)
{
return err;
}
}
list_remove_item(add_p, value);
}
break;
}
default:
/* Shouldn't get here unless there's memory corruption. */
assert(0);
return JB_ERR_PARSE;
}
}
else
{
/* try user aliases. */
const struct action_alias * alias = alias_list;
while ((alias != NULL) && (0 != strcmpic(alias->name, option)))
{
alias = alias->next;
}
if (alias != NULL)
{
/* Found it */
merge_actions(cur_action, alias->action);
}
else if (((size_t)2 < strlen(option)) && action_used_to_be_valid(option+1))
{
log_error(LOG_LEVEL_ERROR, "Action '%s' is no longer valid "
"in this Privoxy release. Ignored.", option+1);
}
else if (((size_t)2 < strlen(option)) && 0 == strcmpic(option+1, "hide-forwarded-for-headers"))
{
log_error(LOG_LEVEL_FATAL, "The action 'hide-forwarded-for-headers' "
"is no longer valid in this Privoxy release. "
"Use 'change-x-forwarded-for' instead.");
}
else
{
/* Bad action name */
/*
* XXX: This is a fatal error and Privoxy will later on exit
* in load_one_actions_file() because of an "invalid line".
*
* It would be preferable to name the offending option in that
* error message, but currently there is no way to do that and
* we have to live with two error messages for basically the
* same reason.
*/
log_error(LOG_LEVEL_ERROR, "Unknown action or alias: %s", option);
return JB_ERR_PARSE;
}
}
}
}
return JB_ERR_OK;
}
/*********************************************************************
*
* Function : init_current_action
*
* Description : Zero out an action.
*
* Parameters :
* 1 : dest = An uninitialized current_action_spec.
*
* Returns : N/A
*
*********************************************************************/
void init_current_action (struct current_action_spec *dest)
{
memset(dest, '\0', sizeof(*dest));
dest->flags = ACTION_MOST_COMPATIBLE;
}
/*********************************************************************
*
* Function : init_action
*
* Description : Zero out an action.
*
* Parameters :
* 1 : dest = An uninitialized action_spec.
*
* Returns : N/A
*
*********************************************************************/
void init_action (struct action_spec *dest)
{
memset(dest, '\0', sizeof(*dest));
}
/*********************************************************************
*
* Function : merge_current_action
*
* Description : Merge two actions together.
* Similar to "dest += src".
* Differences between this and merge_actions()
* is that this one doesn't allocate memory for
* strings (so "src" better be in memory for at least
* as long as "dest" is, and you'd better free
* "dest" using "free_current_action").
* Also, there is no mask or remove lists in dest.
* (If we're applying it to a URL, we don't need them)
*
* Parameters :
* 1 : dest = Current actions, to modify.
* 2 : src = Action to add.
*
* Returns 0 : no error
* !=0 : error, probably JB_ERR_MEMORY.
*
*********************************************************************/
jb_err merge_current_action (struct current_action_spec *dest,
const struct action_spec *src)
{
int i;
jb_err err = JB_ERR_OK;
dest->flags &= src->mask;
dest->flags |= src->add;
for (i = 0; i < ACTION_STRING_COUNT; i++)
{
char * str = src->string[i];
if (str)
{
str = strdup_or_die(str);
freez(dest->string[i]);
dest->string[i] = str;
}
}
for (i = 0; i < ACTION_MULTI_COUNT; i++)
{
if (src->multi_remove_all[i])
{
/* Remove everything from dest, then add src->multi_add */
err = list_duplicate(dest->multi[i], src->multi_add[i]);
if (err)
{
return err;
}
}
else
{
list_remove_list(dest->multi[i], src->multi_remove[i]);
err = list_append_list_unique(dest->multi[i], src->multi_add[i]);
if (err)
{
return err;
}
}
}
return err;
}
/*********************************************************************
*
* Function : update_action_bits_for_tag
*
* Description : Updates the action bits based on the action sections
* whose tag patterns match a provided tag.
*
* Parameters :
* 1 : csp = Current client state (buffers, headers, etc...)
* 2 : tag = The tag on which the update should be based on
*
* Returns : 0 if no tag matched, or
* 1 otherwise
*
*********************************************************************/
int update_action_bits_for_tag(struct client_state *csp, const char *tag)
{
struct file_list *fl;
struct url_actions *b;
int updated = 0;
int i;
assert(tag);
assert(list_contains_item(csp->tags, tag));
/* Run through all action files, */
for (i = 0; i < MAX_AF_FILES; i++)
{
if (((fl = csp->actions_list[i]) == NULL) || ((b = fl->f) == NULL))
{
/* Skip empty files */
continue;
}
/* and through all the action patterns, */
for (b = b->next; NULL != b; b = b->next)
{
/* skip everything but TAG patterns, */
if (!(b->url->flags & PATTERN_SPEC_TAG_PATTERN))
{
continue;
}
/* and check if one of the tag patterns matches the tag, */
if (0 == regexec(b->url->pattern.tag_regex, tag, 0, NULL, 0))
{
/* if it does, update the action bit map, */
if (merge_current_action(csp->action, b->action))
{
log_error(LOG_LEVEL_ERROR,
"Out of memory while changing action bits");
}
/* and signal the change. */
updated = 1;
}
}
}
return updated;
}
/*********************************************************************
*
* Function : check_negative_tag_patterns
*
* Description : Updates the action bits based on NO-*-TAG patterns.
*
* Parameters :
* 1 : csp = Current client state (buffers, headers, etc...)
* 2 : flag = The tag pattern type
*
* Returns : JB_ERR_OK in case off success, or
* JB_ERR_MEMORY on out-of-memory error.
*
*********************************************************************/
jb_err check_negative_tag_patterns(struct client_state *csp, unsigned int flag)
{
struct list_entry *tag;
struct file_list *fl;
struct url_actions *b = NULL;
int i;
for (i = 0; i < MAX_AF_FILES; i++)
{
fl = csp->actions_list[i];
if ((fl == NULL) || ((b = fl->f) == NULL))
{
continue;
}
for (b = b->next; NULL != b; b = b->next)
{
int tag_found = 0;
if (0 == (b->url->flags & flag))
{
continue;
}
for (tag = csp->tags->first; NULL != tag; tag = tag->next)
{
if (0 == regexec(b->url->pattern.tag_regex, tag->str, 0, NULL, 0))
{
/*
* The pattern matches at least one tag, thus the action
* section doesn't apply and we don't need to look at the
* other tags.
*/
tag_found = 1;
break;
}
}
if (!tag_found)
{
/*
* The pattern doesn't match any tags,
* thus the action section applies.
*/
if (merge_current_action(csp->action, b->action))
{
log_error(LOG_LEVEL_ERROR,
"Out of memory while changing action bits");
return JB_ERR_MEMORY;
}
log_error(LOG_LEVEL_HEADER, "Updated action bits based on: %s",
b->url->spec);
}
}
}
return JB_ERR_OK;
}
/*********************************************************************
*
* Function : free_current_action
*
* Description : Free memory used by a current_action_spec.
* Does not free the current_action_spec itself.
*
* Parameters :
* 1 : src = Source to free.
*
* Returns : N/A
*
*********************************************************************/
void free_current_action(struct current_action_spec *src)
{
int i;
for (i = 0; i < ACTION_STRING_COUNT; i++)
{
freez(src->string[i]);
}
for (i = 0; i < ACTION_MULTI_COUNT; i++)
{
destroy_list(src->multi[i]);
}
memset(src, '\0', sizeof(*src));
}
static struct file_list *current_actions_file[MAX_AF_FILES] = {
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
};
#ifdef FEATURE_GRACEFUL_TERMINATION
/*********************************************************************
*
* Function : unload_current_actions_file
*
* Description : Unloads current actions file - reset to state at
* beginning of program.
*
* Parameters : None
*
* Returns : N/A
*
*********************************************************************/
void unload_current_actions_file(void)
{
int i;
for (i = 0; i < MAX_AF_FILES; i++)
{
if (current_actions_file[i])
{
current_actions_file[i]->unloader = unload_actions_file;
current_actions_file[i] = NULL;
}
}
}
#endif /* FEATURE_GRACEFUL_TERMINATION */
/*********************************************************************
*
* Function : unload_actions_file
*
* Description : Unloads an actions module.
*
* Parameters :
* 1 : file_data = the data structure associated with the
* actions file.
*
* Returns : N/A
*
*********************************************************************/
void unload_actions_file(void *file_data)
{
struct url_actions * next;
struct url_actions * cur = (struct url_actions *)file_data;
while (cur != NULL)
{
next = cur->next;
free_pattern_spec(cur->url);