summaryrefslogtreecommitdiffhomepage
path: root/libs/sgi-webuci/boa-patches/200-plugin_api.patch
blob: 78933da68f9066459cb594ff4c4a13504861d0f1 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
Index: boa-0.94.14rc21/src/list.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ boa-0.94.14rc21/src/list.h	2008-06-11 10:25:04.000000000 +0200
@@ -0,0 +1,601 @@
+#ifndef _LINUX_LIST_H
+#define _LINUX_LIST_H
+
+#include <stddef.h>
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr:	the pointer to the member.
+ * @type:	the type of the container struct this is embedded in.
+ * @member:	the name of the member within the struct.
+ *
+ */
+#ifndef container_of
+#define container_of(ptr, type, member) (			\
+	(type *)( (char *)ptr - offsetof(type,member) ))
+#endif
+
+
+/*
+ * Simple doubly linked list implementation.
+ *
+ * Some of the internal functions ("__xxx") are useful when
+ * manipulating whole lists rather than single entries, as
+ * sometimes we already know the next/prev entries and we can
+ * generate better code by using them directly rather than
+ * using the generic single-entry routines.
+ */
+
+struct list_head {
+	struct list_head *next, *prev;
+};
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+	struct list_head name = LIST_HEAD_INIT(name)
+
+static inline void INIT_LIST_HEAD(struct list_head *list)
+{
+	list->next = list;
+	list->prev = list;
+}
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_add(struct list_head *new,
+			      struct list_head *prev,
+			      struct list_head *next)
+{
+	next->prev = new;
+	new->next = next;
+	new->prev = prev;
+	prev->next = new;
+}
+
+/**
+ * list_add - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it after
+ *
+ * Insert a new entry after the specified head.
+ * This is good for implementing stacks.
+ */
+static inline void list_add(struct list_head *new, struct list_head *head)
+{
+	__list_add(new, head, head->next);
+}
+
+
+/**
+ * list_add_tail - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it before
+ *
+ * Insert a new entry before the specified head.
+ * This is useful for implementing queues.
+ */
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
+{
+	__list_add(new, head->prev, head);
+}
+
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_del(struct list_head * prev, struct list_head * next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+/**
+ * list_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ * Note: list_empty() on entry does not return true after this, the entry is
+ * in an undefined state.
+ */
+static inline void list_del(struct list_head *entry)
+{
+	__list_del(entry->prev, entry->next);
+	entry->next = NULL;
+	entry->prev = NULL;
+}
+
+/**
+ * list_replace - replace old entry by new one
+ * @old : the element to be replaced
+ * @new : the new element to insert
+ *
+ * If @old was empty, it will be overwritten.
+ */
+static inline void list_replace(struct list_head *old,
+				struct list_head *new)
+{
+	new->next = old->next;
+	new->next->prev = new;
+	new->prev = old->prev;
+	new->prev->next = new;
+}
+
+static inline void list_replace_init(struct list_head *old,
+					struct list_head *new)
+{
+	list_replace(old, new);
+	INIT_LIST_HEAD(old);
+}
+
+/**
+ * list_del_init - deletes entry from list and reinitialize it.
+ * @entry: the element to delete from the list.
+ */
+static inline void list_del_init(struct list_head *entry)
+{
+	__list_del(entry->prev, entry->next);
+	INIT_LIST_HEAD(entry);
+}
+
+/**
+ * list_move - delete from one list and add as another's head
+ * @list: the entry to move
+ * @head: the head that will precede our entry
+ */
+static inline void list_move(struct list_head *list, struct list_head *head)
+{
+	__list_del(list->prev, list->next);
+	list_add(list, head);
+}
+
+/**
+ * list_move_tail - delete from one list and add as another's tail
+ * @list: the entry to move
+ * @head: the head that will follow our entry
+ */
+static inline void list_move_tail(struct list_head *list,
+				  struct list_head *head)
+{
+	__list_del(list->prev, list->next);
+	list_add_tail(list, head);
+}
+
+/**
+ * list_is_last - tests whether @list is the last entry in list @head
+ * @list: the entry to test
+ * @head: the head of the list
+ */
+static inline int list_is_last(const struct list_head *list,
+				const struct list_head *head)
+{
+	return list->next == head;
+}
+
+/**
+ * list_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+static inline int list_empty(const struct list_head *head)
+{
+	return head->next == head;
+}
+
+/**
+ * list_empty_careful - tests whether a list is empty and not being modified
+ * @head: the list to test
+ *
+ * Description:
+ * tests whether a list is empty _and_ checks that no other CPU might be
+ * in the process of modifying either member (next or prev)
+ *
+ * NOTE: using list_empty_careful() without synchronization
+ * can only be safe if the only activity that can happen
+ * to the list entry is list_del_init(). Eg. it cannot be used
+ * if another CPU could re-list_add() it.
+ */
+static inline int list_empty_careful(const struct list_head *head)
+{
+	struct list_head *next = head->next;
+	return (next == head) && (next == head->prev);
+}
+
+static inline void __list_splice(struct list_head *list,
+				 struct list_head *head)
+{
+	struct list_head *first = list->next;
+	struct list_head *last = list->prev;
+	struct list_head *at = head->next;
+
+	first->prev = head;
+	head->next = first;
+
+	last->next = at;
+	at->prev = last;
+}
+
+/**
+ * list_splice - join two lists
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ */
+static inline void list_splice(struct list_head *list, struct list_head *head)
+{
+	if (!list_empty(list))
+		__list_splice(list, head);
+}
+
+/**
+ * list_splice_init - join two lists and reinitialise the emptied list.
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ *
+ * The list at @list is reinitialised
+ */
+static inline void list_splice_init(struct list_head *list,
+				    struct list_head *head)
+{
+	if (!list_empty(list)) {
+		__list_splice(list, head);
+		INIT_LIST_HEAD(list);
+	}
+}
+
+/**
+ * list_entry - get the struct for this entry
+ * @ptr:	the &struct list_head pointer.
+ * @type:	the type of the struct this is embedded in.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_entry(ptr, type, member) \
+	container_of(ptr, type, member)
+
+/**
+ * list_first_entry - get the first element from a list
+ * @ptr:	the list head to take the element from.
+ * @type:	the type of the struct this is embedded in.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_first_entry(ptr, type, member) \
+	list_entry((ptr)->next, type, member)
+
+/**
+ * list_for_each	-	iterate over a list
+ * @pos:	the &struct list_head to use as a loop cursor.
+ * @head:	the head for your list.
+ */
+#define list_for_each(pos, head) \
+	for (pos = (head)->next; pos != (head); \
+        	pos = pos->next)
+
+/**
+ * __list_for_each	-	iterate over a list
+ * @pos:	the &struct list_head to use as a loop cursor.
+ * @head:	the head for your list.
+ *
+ * This variant differs from list_for_each() in that it's the
+ * simplest possible list iteration code, no prefetching is done.
+ * Use this for code that knows the list to be very short (empty
+ * or 1 entry) most of the time.
+ */
+#define __list_for_each(pos, head) \
+	for (pos = (head)->next; pos != (head); pos = pos->next)
+
+/**
+ * list_for_each_prev	-	iterate over a list backwards
+ * @pos:	the &struct list_head to use as a loop cursor.
+ * @head:	the head for your list.
+ */
+#define list_for_each_prev(pos, head) \
+	for (pos = (head)->prev; pos != (head); \
+        	pos = pos->prev)
+
+/**
+ * list_for_each_safe - iterate over a list safe against removal of list entry
+ * @pos:	the &struct list_head to use as a loop cursor.
+ * @n:		another &struct list_head to use as temporary storage
+ * @head:	the head for your list.
+ */
+#define list_for_each_safe(pos, n, head) \
+	for (pos = (head)->next, n = pos->next; pos != (head); \
+		pos = n, n = pos->next)
+
+/**
+ * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
+ * @pos:	the &struct list_head to use as a loop cursor.
+ * @n:		another &struct list_head to use as temporary storage
+ * @head:	the head for your list.
+ */
+#define list_for_each_prev_safe(pos, n, head) \
+	for (pos = (head)->prev, n = pos->prev; \
+	     pos != (head); \
+	     pos = n, n = pos->prev)
+
+/**
+ * list_for_each_entry	-	iterate over list of given type
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_for_each_entry(pos, head, member)				\
+	for (pos = list_entry((head)->next, typeof(*pos), member);	\
+	     &pos->member != (head); 	\
+	     pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_reverse - iterate backwards over list of given type.
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_reverse(pos, head, member)			\
+	for (pos = list_entry((head)->prev, typeof(*pos), member);	\
+	     &pos->member != (head); 	\
+	     pos = list_entry(pos->member.prev, typeof(*pos), member))
+
+/**
+ * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
+ * @pos:	the type * to use as a start point
+ * @head:	the head of the list
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
+ */
+#define list_prepare_entry(pos, head, member) \
+	((pos) ? : list_entry(head, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_continue - continue iteration over list of given type
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Continue to iterate over list of given type, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue(pos, head, member) 		\
+	for (pos = list_entry(pos->member.next, typeof(*pos), member);	\
+	     &pos->member != (head);	\
+	     pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_continue_reverse - iterate backwards from the given point
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Start to iterate over list of given type backwards, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_reverse(pos, head, member)		\
+	for (pos = list_entry(pos->member.prev, typeof(*pos), member);	\
+	     &pos->member != (head);	\
+	     pos = list_entry(pos->member.prev, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_from - iterate over list of given type from the current point
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type, continuing from current position.
+ */
+#define list_for_each_entry_from(pos, head, member) 			\
+	for (; &pos->member != (head);	\
+	     pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @pos:	the type * to use as a loop cursor.
+ * @n:		another type * to use as temporary storage
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe(pos, n, head, member)			\
+	for (pos = list_entry((head)->next, typeof(*pos), member),	\
+		n = list_entry(pos->member.next, typeof(*pos), member);	\
+	     &pos->member != (head); 					\
+	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_for_each_entry_safe_continue
+ * @pos:	the type * to use as a loop cursor.
+ * @n:		another type * to use as temporary storage
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type, continuing after current point,
+ * safe against removal of list entry.
+ */
+#define list_for_each_entry_safe_continue(pos, n, head, member) 		\
+	for (pos = list_entry(pos->member.next, typeof(*pos), member), 		\
+		n = list_entry(pos->member.next, typeof(*pos), member);		\
+	     &pos->member != (head);						\
+	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_for_each_entry_safe_from
+ * @pos:	the type * to use as a loop cursor.
+ * @n:		another type * to use as temporary storage
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type from current point, safe against
+ * removal of list entry.
+ */
+#define list_for_each_entry_safe_from(pos, n, head, member) 			\
+	for (n = list_entry(pos->member.next, typeof(*pos), member);		\
+	     &pos->member != (head);						\
+	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_for_each_entry_safe_reverse
+ * @pos:	the type * to use as a loop cursor.
+ * @n:		another type * to use as temporary storage
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Iterate backwards over list of given type, safe against removal
+ * of list entry.
+ */
+#define list_for_each_entry_safe_reverse(pos, n, head, member)		\
+	for (pos = list_entry((head)->prev, typeof(*pos), member),	\
+		n = list_entry(pos->member.prev, typeof(*pos), member);	\
+	     &pos->member != (head); 					\
+	     pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+
+/*
+ * Double linked lists with a single pointer list head.
+ * Mostly useful for hash tables where the two pointer list head is
+ * too wasteful.
+ * You lose the ability to access the tail in O(1).
+ */
+
+struct hlist_head {
+	struct hlist_node *first;
+};
+
+struct hlist_node {
+	struct hlist_node *next, **pprev;
+};
+
+#define HLIST_HEAD_INIT { .first = NULL }
+#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
+static inline void INIT_HLIST_NODE(struct hlist_node *h)
+{
+	h->next = NULL;
+	h->pprev = NULL;
+}
+
+static inline int hlist_unhashed(const struct hlist_node *h)
+{
+	return !h->pprev;
+}
+
+static inline int hlist_empty(const struct hlist_head *h)
+{
+	return !h->first;
+}
+
+static inline void __hlist_del(struct hlist_node *n)
+{
+	struct hlist_node *next = n->next;
+	struct hlist_node **pprev = n->pprev;
+	*pprev = next;
+	if (next)
+		next->pprev = pprev;
+}
+
+static inline void hlist_del(struct hlist_node *n)
+{
+	__hlist_del(n);
+	n->next = NULL;
+	n->pprev = NULL;
+}
+
+static inline void hlist_del_init(struct hlist_node *n)
+{
+	if (!hlist_unhashed(n)) {
+		__hlist_del(n);
+		INIT_HLIST_NODE(n);
+	}
+}
+
+
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+{
+	struct hlist_node *first = h->first;
+	n->next = first;
+	if (first)
+		first->pprev = &n->next;
+	h->first = n;
+	n->pprev = &h->first;
+}
+
+
+/* next must be != NULL */
+static inline void hlist_add_before(struct hlist_node *n,
+					struct hlist_node *next)
+{
+	n->pprev = next->pprev;
+	n->next = next;
+	next->pprev = &n->next;
+	*(n->pprev) = n;
+}
+
+static inline void hlist_add_after(struct hlist_node *n,
+					struct hlist_node *next)
+{
+	next->next = n->next;
+	n->next = next;
+	next->pprev = &n->next;
+
+	if(next->next)
+		next->next->pprev  = &next->next;
+}
+
+#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
+
+#define hlist_for_each(pos, head) \
+	for (pos = (head)->first; pos; pos = pos->next)
+
+#define hlist_for_each_safe(pos, n, head) \
+	for (pos = (head)->first; pos; pos = n)
+
+/**
+ * hlist_for_each_entry	- iterate over list of given type
+ * @tpos:	the type * to use as a loop cursor.
+ * @pos:	the &struct hlist_node to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry(tpos, pos, head, member)			 \
+	for (pos = (head)->first; pos &&				 \
+		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
+	     pos = pos->next)
+
+/**
+ * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
+ * @tpos:	the type * to use as a loop cursor.
+ * @pos:	the &struct hlist_node to use as a loop cursor.
+ * @member:	the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry_continue(tpos, pos, member)		\
+	for (pos = (pos)->next; pos &&					\
+	     ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;});   \
+	     pos = pos->next)
+
+/**
+ * hlist_for_each_entry_from - iterate over a hlist continuing from current point
+ * @tpos:	the type * to use as a loop cursor.
+ * @pos:	the &struct hlist_node to use as a loop cursor.
+ * @member:	the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry_from(tpos, pos, member)			 \
+	for (; pos &&			 \
+		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
+	     pos = pos->next)
+
+/**
+ * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @tpos:	the type * to use as a loop cursor.
+ * @pos:	the &struct hlist_node to use as a loop cursor.
+ * @n:		another &struct hlist_node to use as temporary storage
+ * @head:	the head for your list.
+ * @member:	the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member) 		 \
+	for (pos = (head)->first;					 \
+	     pos && ({ n = pos->next; 1; }) && 				 \
+		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
+	     pos = n)
+
+#endif
Index: boa-0.94.14rc21/src/plugin.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ boa-0.94.14rc21/src/plugin.c	2008-06-11 10:25:04.000000000 +0200
@@ -0,0 +1,198 @@
+/*
+ * Simple plugin API for boa
+ * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "boa.h"
+#include "list.h"
+#include <dlfcn.h>
+#include <glob.h>
+
+static LIST_HEAD(plugins);
+
+struct httpd_plugin *plugin_lookup(request *req)
+{
+	struct list_head *l;
+	list_for_each(l, &plugins)
+	{
+		struct httpd_plugin *p =
+			container_of(l, struct httpd_plugin, list);
+
+		if (!strncmp(req->request_uri, p->prefix, strlen(p->prefix)))
+			return p;
+	}
+	return NULL;
+}
+
+static int plugin_run(request *req, struct httpd_plugin *p)
+{
+	struct http_context ctx;
+    int child_pid;
+
+	SQUASH_KA(req);
+
+	memset(&ctx, 0, sizeof(ctx));
+	ctx.uri = req->request_uri;
+	switch(req->method) {
+		case M_POST:
+			ctx.request_method = "POST";
+			break;
+		case M_HEAD:
+			ctx.request_method = "HEAD";
+			break;
+		case M_GET:
+			ctx.request_method = "GET";
+			break;
+	}
+	ctx.server_addr = req->local_ip_addr;
+	switch (req->http_version) {
+		case HTTP09:
+			ctx.server_proto = "HTTP/0.9";
+			break;
+		case HTTP10:
+			ctx.server_proto = "HTTP/1.0";
+			break;
+		case HTTP11:
+			ctx.server_proto = "HTTP/1.1";
+			break;
+	}
+	ctx.query_string = req->query_string;
+	ctx.remote_addr = req->remote_ip_addr;
+	ctx.remote_port = req->remote_port;
+	if (req->method == M_POST) {
+		if (req->content_type)
+			ctx.content_type = req->content_type;
+		else
+			ctx.content_type = default_type;
+		ctx.content_length = req->content_length;
+	}
+#ifdef ACCEPT_ON
+	if (req->accept[0])
+		ctx.http_accept = req->accept;
+#endif
+
+    p->prepare_req(p, &ctx);
+	child_pid = fork();
+
+	switch(child_pid) {
+    case -1:
+        log_error_doc(req);
+        perror("fork");
+        send_r_error(req);
+        return 0;
+
+	case 0:
+        if (dup2(req->fd, STDOUT_FILENO) == -1) {
+            log_error_doc(req);
+            perror("dup2 - fd");
+            _exit(1);
+        }
+        if (set_block_fd(req->fd) == -1) {
+            log_error_doc(req);
+            perror("cgi-fcntl");
+            _exit(1);
+        }
+        if (req->method == M_POST) {
+            dup2(req->read_data_fd, STDIN_FILENO);
+            close(req->read_data_fd);
+            close(req->post_data_fd);
+			set_block_fd(STDIN_FILENO);
+        }
+
+        if (cgi_log_fd)
+            dup2(cgi_log_fd, STDERR_FILENO);
+
+	    p->handle_req(p, &ctx);
+		exit(0);
+        break;
+    }
+
+    return 1;
+}
+
+int plugin_handle(request * req)
+{
+	struct httpd_plugin *p;
+
+	p = plugin_lookup(req);
+	if (!p)
+		return 0;
+
+	return plugin_run(req, p);
+}
+
+static void plugin_load(const char *p, const char *dir)
+{
+	struct httpd_plugin *plugin;
+	void *dl;
+
+	/* ignore directories */
+	if (p[strlen(p) - 1] == '/')
+		return;
+
+	dl = dlopen(p, RTLD_NOW);
+	if (!dl) {
+		fprintf(stderr, "Unable to load plugin '%s': %d\n", p, dlerror());
+		return;
+	}
+
+	plugin = dlsym(dl, "httpd_plugin");
+	if (!plugin)
+		goto error;
+
+	INIT_LIST_HEAD(&plugin->list);
+	plugin->dir = dir;
+
+	if (plugin->init(plugin) != 1)
+		goto error;
+
+	if (!plugin->prefix)
+		goto error_init;
+
+	list_add(&plugin->list, &plugins);
+	return;
+
+error_init:
+	plugin->done(plugin);
+error:
+	fprintf(stderr, "Plugin '%s' failed to initialize\n", p);
+	dlclose(dl);
+}
+
+#define WILDCARD_SUFFIX "/*.so"
+
+int plugin_init(char *path)
+{
+	int buflen = 128;
+	char *plugindir;
+	glob_t g;
+	char *s;
+	int i;
+
+	s = malloc(strlen(path) + sizeof(WILDCARD_SUFFIX) + 1);
+	strcpy(s, path);
+	strcat(s, WILDCARD_SUFFIX);
+	glob(s, GLOB_MARK, NULL, &g);
+	free(s);
+
+	for (i = 0; i < g.gl_pathc; i++)
+		plugin_load(g.gl_pathv[i], path);
+
+	globfree(&g);
+}
+
+
Index: boa-0.94.14rc21/src/request.c
===================================================================
--- boa-0.94.14rc21.orig/src/request.c	2005-02-22 15:11:29.000000000 +0100
+++ boa-0.94.14rc21/src/request.c	2008-06-11 10:25:04.000000000 +0200
@@ -59,6 +59,7 @@
         dequeue(&request_free, request_free); /* dequeue the head */
     } else {
         req = (request *) malloc(sizeof (request));
+		memset(req, 0, sizeof(request));
         if (!req) {
             log_error_time();
             perror("malloc for new request");
@@ -793,6 +794,8 @@
 
 int process_header_end(request * req)
 {
+	int ret;
+
     if (!req->logline) {
         log_error_doc(req);
         fputs("No logline in process_header_end\n", stderr);
@@ -855,19 +858,35 @@
     }
 
     if (req->method == M_POST) {
-        req->post_data_fd = create_temporary_file(1, NULL, 0);
+        if (!req->plugin) {
+            req->post_data_fd = create_temporary_file(1, NULL, 0);
+        } else {
+            int fd[2];
+            if (pipe(&fd[0]) != -1) {
+                req->post_data_fd = fd[1];
+                req->read_data_fd = fd[0];
+                set_nonblock_fd(req->post_data_fd);
+            }
+        }
         if (req->post_data_fd == 0) {
             /* errors already logged */
             send_r_error(req);
             return 0;
         }
-        if (fcntl(req->post_data_fd, F_SETFD, 1) == -1) {
-            boa_perror(req, "unable to set close-on-exec for req->post_data_fd!");
-            close(req->post_data_fd);
-            req->post_data_fd = 0;
-            return 0;
+        if (!req->plugin) {
+            if (fcntl(req->post_data_fd, F_SETFD, 1) == -1) {
+                boa_perror(req, "unable to set close-on-exec for req->post_data_fd!");
+                close(req->post_data_fd);
+                req->post_data_fd = 0;
+                return 0;
+            }
+            return(1); /* success */
         }
-        return 1;             /* success */
+    }
+
+    ret = plugin_handle(req);
+    if (ret) {
+        return ret;
     }
 
     if (req->cgi_type) {
Index: boa-0.94.14rc21/src/Makefile.in
===================================================================
--- boa-0.94.14rc21.orig/src/Makefile.in	2005-02-22 04:02:40.000000000 +0100
+++ boa-0.94.14rc21/src/Makefile.in	2008-06-11 10:25:04.000000000 +0200
@@ -15,7 +15,7 @@
 srcdir = @srcdir@
 VPATH = @srcdir@:@srcdir@/../extras
 LDFLAGS = @LDFLAGS@
-LIBS = @LIBS@
+LIBS = @LIBS@ -ldl
 CFLAGS = @CFLAGS@
 CPPFLAGS = @CPPFLAGS@ -I@srcdir@ -I.
 @ifGNUmake@DEPEND = .depend
@@ -26,6 +26,7 @@
 SOURCES = alias.c boa.c buffer.c cgi.c cgi_header.c config.c escape.c \
 	get.c hash.c ip.c log.c mmap_cache.c pipe.c queue.c range.c \
 	read.c request.c response.c signals.c util.c sublog.c \
+	plugin.c \
 	@ASYNCIO_SOURCE@ @ACCESSCONTROL_SOURCE@
 
 OBJS = $(SOURCES:.c=.o) timestamp.o @STRUTIL@
Index: boa-0.94.14rc21/src/boa.h
===================================================================
--- boa-0.94.14rc21.orig/src/boa.h	2005-02-22 15:11:29.000000000 +0100
+++ boa-0.94.14rc21/src/boa.h	2008-06-11 10:25:04.000000000 +0200
@@ -38,6 +38,7 @@
 #include <fcntl.h>
 #include <limits.h>             /* OPEN_MAX */
 #include <setjmp.h>
+#include <stdbool.h>
 
 #include <netinet/in.h>
 
@@ -49,6 +50,7 @@
 #include "compat.h"             /* oh what fun is porting */
 #include "defines.h"
 #include "globals.h"
+#include "boa-plugin.h"
 
 /* alias */
 void add_alias(const char *fakename, const char *realname, enum ALIAS type);
@@ -225,5 +227,10 @@
 void range_pool_push(Range * r);
 int ranges_fixup(request * req);
 int range_parse(request * req, const char *str);
- 
+
+/* plugins */
+int plugin_init(char *path);
+int plugin_handle(request * req);
+struct httpd_plugin *plugin_lookup(request *req);
+
 #endif
Index: boa-0.94.14rc21/src/config.c
===================================================================
--- boa-0.94.14rc21.orig/src/config.c	2005-02-22 15:11:29.000000000 +0100
+++ boa-0.94.14rc21/src/config.c	2008-06-11 10:25:04.000000000 +0200
@@ -64,6 +64,7 @@
 char *error_log_name;
 char *access_log_name;
 char *cgi_log_name;
+char *plugin_root = NULL;
 
 int use_localtime;
 
@@ -165,6 +166,7 @@
     {"CGINice", S2A, c_set_int, &cgi_nice},
 #endif
     {"CGIEnv", S2A, c_add_cgi_env, NULL},
+    {"PluginRoot", S1A, c_set_string, &plugin_root},
 };
 
 static void c_add_cgi_env(char *v1, char *v2, void *t)
@@ -544,6 +546,22 @@
                 single_post_limit);
         exit(EXIT_FAILURE);
     }
+	if (plugin_root) {
+		char *plugin_path = plugin_root;
+		char *next;
+
+		do {
+			next = strchr(plugin_path, ':');
+			if (next) {
+				*next = 0;
+				next++;
+			}
+
+			plugin_init(plugin_path);
+			plugin_path = next;
+		} while (plugin_path);
+		free(plugin_root);
+	}
 
     if (vhost_root && virtualhost) {
         fprintf(stderr, "Both VHostRoot and VirtualHost were enabled, and "
Index: boa-0.94.14rc21/src/alias.c
===================================================================
--- boa-0.94.14rc21.orig/src/alias.c	2005-02-22 15:11:29.000000000 +0100
+++ boa-0.94.14rc21/src/alias.c	2008-06-11 10:25:04.000000000 +0200
@@ -246,6 +246,7 @@
 
     uri_len = strlen(req->request_uri);
     current = find_alias(req->request_uri, uri_len);
+	req->plugin = !!plugin_lookup(req);
     if (current) {
         if (current->type == SCRIPTALIAS) /* Script */
             return init_script_alias(req, current, uri_len);
@@ -263,7 +264,7 @@
                uri_len - current->fake_len + 1);
 
         if (current->type == REDIRECT) { /* Redirect */
-            if (req->method == M_POST) { /* POST to non-script */
+            if ((req->method == M_POST) && !req->plugin) { /* POST to non-script */
                 /* it's not a cgi, but we try to POST??? */
                 log_error_doc(req);
                 fputs("POST to non-script is disallowed.\n", stderr);
@@ -432,7 +433,7 @@
         else
             req->cgi_type = CGI;
         return 1;
-    } else if (req->method == M_POST) { /* POST to non-script */
+    } else if ((req->method == M_POST) && !req->plugin) { /* POST to non-script */
         /* it's not a cgi, but we try to POST??? */
         log_error_doc(req);
         fputs("POST to non-script disallowed.\n", stderr);
Index: boa-0.94.14rc21/src/globals.h
===================================================================
--- boa-0.94.14rc21.orig/src/globals.h	2005-02-22 15:11:29.000000000 +0100
+++ boa-0.94.14rc21/src/globals.h	2008-06-11 10:25:04.000000000 +0200
@@ -158,6 +158,7 @@
     char *host;                 /* what we end up using for 'host', no matter the contents of header_host */
 
     int post_data_fd;           /* fd for post data tmpfile */
+    int read_data_fd;           /* fd for post data input (plugin) */
 
     char *path_info;            /* env variable */
     char *path_translated;      /* env variable */
@@ -193,6 +194,8 @@
     char accept[MAX_ACCEPT_LENGTH]; /* Accept: fields */
 #endif
 
+    bool plugin;
+
     struct request *next;       /* next */
     struct request *prev;       /* previous */
 };
Index: boa-0.94.14rc21/src/read.c
===================================================================
--- boa-0.94.14rc21.orig/src/read.c	2005-02-23 16:41:55.000000000 +0100
+++ boa-0.94.14rc21/src/read.c	2008-06-11 10:25:04.000000000 +0200
@@ -375,8 +375,11 @@
 
     if (bytes_to_write == 0) {  /* nothing left in buffer to write */
         req->header_line = req->header_end = req->buffer;
-        if (req->filepos >= req->filesize)
-            return init_cgi(req);
+        if (req->filepos >= req->filesize) {
+			if (req->post_data_fd > 0)
+				close(req->post_data_fd);
+	        return init_cgi(req);
+		}
         /* if here, we can safely assume that there is more to read */
         req->status = BODY_READ;
         return 1;
Index: boa-0.94.14rc21/src/boa-plugin.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ boa-0.94.14rc21/src/boa-plugin.h	2008-06-11 10:25:04.000000000 +0200
@@ -0,0 +1,67 @@
+#ifndef _HTTPD_PLUGIN_H__
+#define _HTTPD_PLUGIN_H__
+
+#include "list.h"
+
+/*
+ * Definition for HTTP server plugins
+ *
+ * The context that the plugin is called with for
+ * a single http request. It gets allocated in the
+ * persistent context before prepare_req and freed
+ * there afterwards (still active in the forked
+ * context at handle_req time)
+ */
+struct http_context
+{
+	char *uri;
+	char *request_method;
+	char *server_addr;
+	char *server_proto;
+	char *query_string;
+	char *remote_addr;
+	unsigned int remote_port;
+	char *content_type;
+	char *content_length;
+	char *http_accept;
+
+	void *priv;
+};
+
+/*
+ * the main data structure of httpd plugins.
+ */
+struct httpd_plugin
+{
+	/* used by the web server */
+	struct list_head list;
+
+	/* only page requests matching 'prefix' are passed
+	 * to prepare_req and handle_req */
+	const char *prefix;
+
+	/* directory that the plugin was found in */
+	const char *dir;
+
+	/* initialize the plugin, if the return value is nonzero,
+	 * the plugin will not be used */
+	int (*init)(struct httpd_plugin *);
+
+	/* free all memory associated with the plugin */
+	void (*done)(struct httpd_plugin *);
+
+	/* prepare a page request. this is executed in the main context,
+	 * so pay attention to memory usage. should not print any data
+	 * to stdout */
+	int (*prepare_req)(struct httpd_plugin *, struct http_context *);
+
+	/* handle the request. can print output data to stdout */
+	int (*handle_req)(struct httpd_plugin *, struct http_context *);
+
+	/* pointer for private data structures of the plugin */
+	void *priv;
+};
+
+#define HTTPD_PLUGIN struct httpd_plugin httpd_plugin =
+
+#endif