diff options
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/regex_internal.c | 717 |
1 files changed, 359 insertions, 358 deletions
diff --git a/src/regex/regex_internal.c b/src/regex/regex_internal.c index 3f667a11f..55d16129f 100644 --- a/src/regex/regex_internal.c +++ b/src/regex/regex_internal.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -66,7 +66,7 @@ struct REGEX_INTERNAL_StateSet_MDLL | |||
66 | */ | 66 | */ |
67 | static void | 67 | static void |
68 | state_set_append (struct REGEX_INTERNAL_StateSet *set, | 68 | state_set_append (struct REGEX_INTERNAL_StateSet *set, |
69 | struct REGEX_INTERNAL_State *state) | 69 | struct REGEX_INTERNAL_State *state) |
70 | { | 70 | { |
71 | if (set->off == set->size) | 71 | if (set->off == set->size) |
72 | GNUNET_array_grow (set->states, set->size, set->size * 2 + 4); | 72 | GNUNET_array_grow (set->states, set->size, set->size * 2 + 4); |
@@ -114,8 +114,7 @@ state_add_transition (struct REGEX_INTERNAL_Context *ctx, | |||
114 | 114 | ||
115 | if (NULL == from_state) | 115 | if (NULL == from_state) |
116 | { | 116 | { |
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create Transition.\n"); |
118 | "Could not create Transition.\n"); | ||
119 | return; | 118 | return; |
120 | } | 119 | } |
121 | 120 | ||
@@ -147,7 +146,9 @@ state_add_transition (struct REGEX_INTERNAL_Context *ctx, | |||
147 | /* Add outgoing transition to 'from_state' */ | 146 | /* Add outgoing transition to 'from_state' */ |
148 | from_state->transition_count++; | 147 | from_state->transition_count++; |
149 | GNUNET_CONTAINER_DLL_insert_before (from_state->transitions_head, | 148 | GNUNET_CONTAINER_DLL_insert_before (from_state->transitions_head, |
150 | from_state->transitions_tail, oth, t); | 149 | from_state->transitions_tail, |
150 | oth, | ||
151 | t); | ||
151 | } | 152 | } |
152 | 153 | ||
153 | 154 | ||
@@ -170,7 +171,8 @@ state_remove_transition (struct REGEX_INTERNAL_State *state, | |||
170 | GNUNET_free_non_null (transition->label); | 171 | GNUNET_free_non_null (transition->label); |
171 | 172 | ||
172 | state->transition_count--; | 173 | state->transition_count--; |
173 | GNUNET_CONTAINER_DLL_remove (state->transitions_head, state->transitions_tail, | 174 | GNUNET_CONTAINER_DLL_remove (state->transitions_head, |
175 | state->transitions_tail, | ||
174 | transition); | 176 | transition); |
175 | 177 | ||
176 | GNUNET_free (transition); | 178 | GNUNET_free (transition); |
@@ -207,8 +209,7 @@ state_compare (const void *a, const void *b) | |||
207 | * @return number of edges. | 209 | * @return number of edges. |
208 | */ | 210 | */ |
209 | static unsigned int | 211 | static unsigned int |
210 | state_get_edges (struct REGEX_INTERNAL_State *s, | 212 | state_get_edges (struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges) |
211 | struct REGEX_BLOCK_Edge *edges) | ||
212 | { | 213 | { |
213 | struct REGEX_INTERNAL_Transition *t; | 214 | struct REGEX_INTERNAL_Transition *t; |
214 | unsigned int count; | 215 | unsigned int count; |
@@ -463,10 +464,13 @@ automaton_add_state (struct REGEX_INTERNAL_Automaton *a, | |||
463 | * @param action_cls closure for action. | 464 | * @param action_cls closure for action. |
464 | */ | 465 | */ |
465 | static void | 466 | static void |
466 | automaton_state_traverse (struct REGEX_INTERNAL_State *s, int *marks, | 467 | automaton_state_traverse (struct REGEX_INTERNAL_State *s, |
468 | int *marks, | ||
467 | unsigned int *count, | 469 | unsigned int *count, |
468 | REGEX_INTERNAL_traverse_check check, void *check_cls, | 470 | REGEX_INTERNAL_traverse_check check, |
469 | REGEX_INTERNAL_traverse_action action, void *action_cls) | 471 | void *check_cls, |
472 | REGEX_INTERNAL_traverse_action action, | ||
473 | void *action_cls) | ||
470 | { | 474 | { |
471 | struct REGEX_INTERNAL_Transition *t; | 475 | struct REGEX_INTERNAL_Transition *t; |
472 | 476 | ||
@@ -485,8 +489,13 @@ automaton_state_traverse (struct REGEX_INTERNAL_State *s, int *marks, | |||
485 | if (NULL == check || | 489 | if (NULL == check || |
486 | (NULL != check && GNUNET_YES == check (check_cls, s, t))) | 490 | (NULL != check && GNUNET_YES == check (check_cls, s, t))) |
487 | { | 491 | { |
488 | automaton_state_traverse (t->to_state, marks, count, check, check_cls, | 492 | automaton_state_traverse (t->to_state, |
489 | action, action_cls); | 493 | marks, |
494 | count, | ||
495 | check, | ||
496 | check_cls, | ||
497 | action, | ||
498 | action_cls); | ||
490 | } | 499 | } |
491 | } | 500 | } |
492 | } | 501 | } |
@@ -535,9 +544,13 @@ REGEX_INTERNAL_automaton_traverse (const struct REGEX_INTERNAL_Automaton *a, | |||
535 | else | 544 | else |
536 | s = start; | 545 | s = start; |
537 | 546 | ||
538 | automaton_state_traverse (s, marks, &count, | 547 | automaton_state_traverse (s, |
539 | check, check_cls, | 548 | marks, |
540 | action, action_cls); | 549 | &count, |
550 | check, | ||
551 | check_cls, | ||
552 | action, | ||
553 | action_cls); | ||
541 | } | 554 | } |
542 | 555 | ||
543 | 556 | ||
@@ -582,7 +595,6 @@ struct StringBuffer | |||
582 | * most likely due to increased cache misses. | 595 | * most likely due to increased cache misses. |
583 | */ | 596 | */ |
584 | int16_t synced; | 597 | int16_t synced; |
585 | |||
586 | }; | 598 | }; |
587 | 599 | ||
588 | 600 | ||
@@ -595,14 +607,11 @@ struct StringBuffer | |||
595 | * @return 0 if the strings are the same or both NULL, 1 or -1 if not. | 607 | * @return 0 if the strings are the same or both NULL, 1 or -1 if not. |
596 | */ | 608 | */ |
597 | static int | 609 | static int |
598 | sb_nullstrcmp (const struct StringBuffer *s1, | 610 | sb_nullstrcmp (const struct StringBuffer *s1, const struct StringBuffer *s2) |
599 | const struct StringBuffer *s2) | ||
600 | { | 611 | { |
601 | if ( (GNUNET_YES == s1->null_flag) && | 612 | if ((GNUNET_YES == s1->null_flag) && (GNUNET_YES == s2->null_flag)) |
602 | (GNUNET_YES == s2->null_flag) ) | ||
603 | return 0; | 613 | return 0; |
604 | if ( (GNUNET_YES == s1->null_flag) || | 614 | if ((GNUNET_YES == s1->null_flag) || (GNUNET_YES == s2->null_flag)) |
605 | (GNUNET_YES == s2->null_flag) ) | ||
606 | return -1; | 615 | return -1; |
607 | if (s1->slen != s2->slen) | 616 | if (s1->slen != s2->slen) |
608 | return -1; | 617 | return -1; |
@@ -621,8 +630,7 @@ sb_nullstrcmp (const struct StringBuffer *s1, | |||
621 | * @return 0 if the strings are the same, 1 or -1 if not. | 630 | * @return 0 if the strings are the same, 1 or -1 if not. |
622 | */ | 631 | */ |
623 | static int | 632 | static int |
624 | sb_strcmp (const struct StringBuffer *s1, | 633 | sb_strcmp (const struct StringBuffer *s1, const struct StringBuffer *s2) |
625 | const struct StringBuffer *s2) | ||
626 | { | 634 | { |
627 | if (s1->slen != s2->slen) | 635 | if (s1->slen != s2->slen) |
628 | return -1; | 636 | return -1; |
@@ -640,8 +648,7 @@ sb_strcmp (const struct StringBuffer *s1, | |||
640 | * @param nlen target length for the buffer, must be at least ret->slen | 648 | * @param nlen target length for the buffer, must be at least ret->slen |
641 | */ | 649 | */ |
642 | static void | 650 | static void |
643 | sb_realloc (struct StringBuffer *ret, | 651 | sb_realloc (struct StringBuffer *ret, size_t nlen) |
644 | size_t nlen) | ||
645 | { | 652 | { |
646 | char *old; | 653 | char *old; |
647 | 654 | ||
@@ -649,9 +656,7 @@ sb_realloc (struct StringBuffer *ret, | |||
649 | old = ret->abuf; | 656 | old = ret->abuf; |
650 | ret->abuf = GNUNET_malloc (nlen); | 657 | ret->abuf = GNUNET_malloc (nlen); |
651 | ret->blen = nlen; | 658 | ret->blen = nlen; |
652 | GNUNET_memcpy (ret->abuf, | 659 | GNUNET_memcpy (ret->abuf, ret->sbuf, ret->slen); |
653 | ret->sbuf, | ||
654 | ret->slen); | ||
655 | ret->sbuf = ret->abuf; | 660 | ret->sbuf = ret->abuf; |
656 | GNUNET_free_non_null (old); | 661 | GNUNET_free_non_null (old); |
657 | } | 662 | } |
@@ -664,17 +669,14 @@ sb_realloc (struct StringBuffer *ret, | |||
664 | * @param sarg string to append | 669 | * @param sarg string to append |
665 | */ | 670 | */ |
666 | static void | 671 | static void |
667 | sb_append (struct StringBuffer *ret, | 672 | sb_append (struct StringBuffer *ret, const struct StringBuffer *sarg) |
668 | const struct StringBuffer *sarg) | ||
669 | { | 673 | { |
670 | if (GNUNET_YES == ret->null_flag) | 674 | if (GNUNET_YES == ret->null_flag) |
671 | ret->slen = 0; | 675 | ret->slen = 0; |
672 | ret->null_flag = GNUNET_NO; | 676 | ret->null_flag = GNUNET_NO; |
673 | if (ret->blen < sarg->slen + ret->slen) | 677 | if (ret->blen < sarg->slen + ret->slen) |
674 | sb_realloc (ret, ret->blen + sarg->slen + 128); | 678 | sb_realloc (ret, ret->blen + sarg->slen + 128); |
675 | GNUNET_memcpy (&ret->sbuf[ret->slen], | 679 | GNUNET_memcpy (&ret->sbuf[ret->slen], sarg->sbuf, sarg->slen); |
676 | sarg->sbuf, | ||
677 | sarg->slen); | ||
678 | ret->slen += sarg->slen; | 680 | ret->slen += sarg->slen; |
679 | } | 681 | } |
680 | 682 | ||
@@ -686,8 +688,7 @@ sb_append (struct StringBuffer *ret, | |||
686 | * @param cstr string to append | 688 | * @param cstr string to append |
687 | */ | 689 | */ |
688 | static void | 690 | static void |
689 | sb_append_cstr (struct StringBuffer *ret, | 691 | sb_append_cstr (struct StringBuffer *ret, const char *cstr) |
690 | const char *cstr) | ||
691 | { | 692 | { |
692 | size_t cstr_len = strlen (cstr); | 693 | size_t cstr_len = strlen (cstr); |
693 | 694 | ||
@@ -696,9 +697,7 @@ sb_append_cstr (struct StringBuffer *ret, | |||
696 | ret->null_flag = GNUNET_NO; | 697 | ret->null_flag = GNUNET_NO; |
697 | if (ret->blen < cstr_len + ret->slen) | 698 | if (ret->blen < cstr_len + ret->slen) |
698 | sb_realloc (ret, ret->blen + cstr_len + 128); | 699 | sb_realloc (ret, ret->blen + cstr_len + 128); |
699 | GNUNET_memcpy (&ret->sbuf[ret->slen], | 700 | GNUNET_memcpy (&ret->sbuf[ret->slen], cstr, cstr_len); |
700 | cstr, | ||
701 | cstr_len); | ||
702 | ret->slen += cstr_len; | 701 | ret->slen += cstr_len; |
703 | } | 702 | } |
704 | 703 | ||
@@ -714,9 +713,7 @@ sb_append_cstr (struct StringBuffer *ret, | |||
714 | * @param extra_chars how long will the result be, in addition to 'sarg' length | 713 | * @param extra_chars how long will the result be, in addition to 'sarg' length |
715 | */ | 714 | */ |
716 | static void | 715 | static void |
717 | sb_wrap (struct StringBuffer *ret, | 716 | sb_wrap (struct StringBuffer *ret, const char *format, size_t extra_chars) |
718 | const char *format, | ||
719 | size_t extra_chars) | ||
720 | { | 717 | { |
721 | char *temp; | 718 | char *temp; |
722 | 719 | ||
@@ -725,10 +722,10 @@ sb_wrap (struct StringBuffer *ret, | |||
725 | ret->null_flag = GNUNET_NO; | 722 | ret->null_flag = GNUNET_NO; |
726 | temp = GNUNET_malloc (ret->slen + extra_chars + 1); | 723 | temp = GNUNET_malloc (ret->slen + extra_chars + 1); |
727 | GNUNET_snprintf (temp, | 724 | GNUNET_snprintf (temp, |
728 | ret->slen + extra_chars + 1, | 725 | ret->slen + extra_chars + 1, |
729 | format, | 726 | format, |
730 | (int) ret->slen, | 727 | (int) ret->slen, |
731 | ret->sbuf); | 728 | ret->sbuf); |
732 | GNUNET_free_non_null (ret->abuf); | 729 | GNUNET_free_non_null (ret->abuf); |
733 | ret->abuf = temp; | 730 | ret->abuf = temp; |
734 | ret->sbuf = temp; | 731 | ret->sbuf = temp; |
@@ -748,21 +745,16 @@ sb_wrap (struct StringBuffer *ret, | |||
748 | */ | 745 | */ |
749 | static void | 746 | static void |
750 | sb_printf1 (struct StringBuffer *ret, | 747 | sb_printf1 (struct StringBuffer *ret, |
751 | const char *format, | 748 | const char *format, |
752 | size_t extra_chars, | 749 | size_t extra_chars, |
753 | const struct StringBuffer *sarg) | 750 | const struct StringBuffer *sarg) |
754 | { | 751 | { |
755 | if (ret->blen < sarg->slen + extra_chars + 1) | 752 | if (ret->blen < sarg->slen + extra_chars + 1) |
756 | sb_realloc (ret, | 753 | sb_realloc (ret, sarg->slen + extra_chars + 1); |
757 | sarg->slen + extra_chars + 1); | ||
758 | ret->null_flag = GNUNET_NO; | 754 | ret->null_flag = GNUNET_NO; |
759 | ret->sbuf = ret->abuf; | 755 | ret->sbuf = ret->abuf; |
760 | ret->slen = sarg->slen + extra_chars; | 756 | ret->slen = sarg->slen + extra_chars; |
761 | GNUNET_snprintf (ret->sbuf, | 757 | GNUNET_snprintf (ret->sbuf, ret->blen, format, (int) sarg->slen, sarg->sbuf); |
762 | ret->blen, | ||
763 | format, | ||
764 | (int) sarg->slen, | ||
765 | sarg->sbuf); | ||
766 | } | 758 | } |
767 | 759 | ||
768 | 760 | ||
@@ -777,24 +769,23 @@ sb_printf1 (struct StringBuffer *ret, | |||
777 | */ | 769 | */ |
778 | static void | 770 | static void |
779 | sb_printf2 (struct StringBuffer *ret, | 771 | sb_printf2 (struct StringBuffer *ret, |
780 | const char *format, | 772 | const char *format, |
781 | size_t extra_chars, | 773 | size_t extra_chars, |
782 | const struct StringBuffer *sarg1, | 774 | const struct StringBuffer *sarg1, |
783 | const struct StringBuffer *sarg2) | 775 | const struct StringBuffer *sarg2) |
784 | { | 776 | { |
785 | if (ret->blen < sarg1->slen + sarg2->slen + extra_chars + 1) | 777 | if (ret->blen < sarg1->slen + sarg2->slen + extra_chars + 1) |
786 | sb_realloc (ret, | 778 | sb_realloc (ret, sarg1->slen + sarg2->slen + extra_chars + 1); |
787 | sarg1->slen + sarg2->slen + extra_chars + 1); | ||
788 | ret->null_flag = GNUNET_NO; | 779 | ret->null_flag = GNUNET_NO; |
789 | ret->slen = sarg1->slen + sarg2->slen + extra_chars; | 780 | ret->slen = sarg1->slen + sarg2->slen + extra_chars; |
790 | ret->sbuf = ret->abuf; | 781 | ret->sbuf = ret->abuf; |
791 | GNUNET_snprintf (ret->sbuf, | 782 | GNUNET_snprintf (ret->sbuf, |
792 | ret->blen, | 783 | ret->blen, |
793 | format, | 784 | format, |
794 | (int) sarg1->slen, | 785 | (int) sarg1->slen, |
795 | sarg1->sbuf, | 786 | sarg1->sbuf, |
796 | (int) sarg2->slen, | 787 | (int) sarg2->slen, |
797 | sarg2->sbuf); | 788 | sarg2->sbuf); |
798 | } | 789 | } |
799 | 790 | ||
800 | 791 | ||
@@ -811,27 +802,26 @@ sb_printf2 (struct StringBuffer *ret, | |||
811 | */ | 802 | */ |
812 | static void | 803 | static void |
813 | sb_printf3 (struct StringBuffer *ret, | 804 | sb_printf3 (struct StringBuffer *ret, |
814 | const char *format, | 805 | const char *format, |
815 | size_t extra_chars, | 806 | size_t extra_chars, |
816 | const struct StringBuffer *sarg1, | 807 | const struct StringBuffer *sarg1, |
817 | const struct StringBuffer *sarg2, | 808 | const struct StringBuffer *sarg2, |
818 | const struct StringBuffer *sarg3) | 809 | const struct StringBuffer *sarg3) |
819 | { | 810 | { |
820 | if (ret->blen < sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1) | 811 | if (ret->blen < sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1) |
821 | sb_realloc (ret, | 812 | sb_realloc (ret, sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1); |
822 | sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1); | ||
823 | ret->null_flag = GNUNET_NO; | 813 | ret->null_flag = GNUNET_NO; |
824 | ret->slen = sarg1->slen + sarg2->slen + sarg3->slen + extra_chars; | 814 | ret->slen = sarg1->slen + sarg2->slen + sarg3->slen + extra_chars; |
825 | ret->sbuf = ret->abuf; | 815 | ret->sbuf = ret->abuf; |
826 | GNUNET_snprintf (ret->sbuf, | 816 | GNUNET_snprintf (ret->sbuf, |
827 | ret->blen, | 817 | ret->blen, |
828 | format, | 818 | format, |
829 | (int) sarg1->slen, | 819 | (int) sarg1->slen, |
830 | sarg1->sbuf, | 820 | sarg1->sbuf, |
831 | (int) sarg2->slen, | 821 | (int) sarg2->slen, |
832 | sarg2->sbuf, | 822 | sarg2->sbuf, |
833 | (int) sarg3->slen, | 823 | (int) sarg3->slen, |
834 | sarg3->sbuf); | 824 | sarg3->sbuf); |
835 | } | 825 | } |
836 | 826 | ||
837 | 827 | ||
@@ -844,12 +834,10 @@ sb_printf3 (struct StringBuffer *ret, | |||
844 | static void | 834 | static void |
845 | sb_free (struct StringBuffer *sb) | 835 | sb_free (struct StringBuffer *sb) |
846 | { | 836 | { |
847 | GNUNET_array_grow (sb->abuf, | 837 | GNUNET_array_grow (sb->abuf, sb->blen, 0); |
848 | sb->blen, | ||
849 | 0); | ||
850 | sb->slen = 0; | 838 | sb->slen = 0; |
851 | sb->sbuf = NULL; | 839 | sb->sbuf = NULL; |
852 | sb->null_flag= GNUNET_YES; | 840 | sb->null_flag = GNUNET_YES; |
853 | } | 841 | } |
854 | 842 | ||
855 | 843 | ||
@@ -860,8 +848,7 @@ sb_free (struct StringBuffer *sb) | |||
860 | * @param out output string | 848 | * @param out output string |
861 | */ | 849 | */ |
862 | static void | 850 | static void |
863 | sb_strdup (struct StringBuffer *out, | 851 | sb_strdup (struct StringBuffer *out, const struct StringBuffer *in) |
864 | const struct StringBuffer *in) | ||
865 | 852 | ||
866 | { | 853 | { |
867 | out->null_flag = in->null_flag; | 854 | out->null_flag = in->null_flag; |
@@ -869,9 +856,7 @@ sb_strdup (struct StringBuffer *out, | |||
869 | return; | 856 | return; |
870 | if (out->blen < in->slen) | 857 | if (out->blen < in->slen) |
871 | { | 858 | { |
872 | GNUNET_array_grow (out->abuf, | 859 | GNUNET_array_grow (out->abuf, out->blen, in->slen); |
873 | out->blen, | ||
874 | in->slen); | ||
875 | } | 860 | } |
876 | out->sbuf = out->abuf; | 861 | out->sbuf = out->abuf; |
877 | out->slen = in->slen; | 862 | out->slen = in->slen; |
@@ -886,8 +871,7 @@ sb_strdup (struct StringBuffer *out, | |||
886 | * @param out output string | 871 | * @param out output string |
887 | */ | 872 | */ |
888 | static void | 873 | static void |
889 | sb_strdup_cstr (struct StringBuffer *out, | 874 | sb_strdup_cstr (struct StringBuffer *out, const char *cstr) |
890 | const char *cstr) | ||
891 | { | 875 | { |
892 | if (NULL == cstr) | 876 | if (NULL == cstr) |
893 | { | 877 | { |
@@ -898,9 +882,7 @@ sb_strdup_cstr (struct StringBuffer *out, | |||
898 | out->slen = strlen (cstr); | 882 | out->slen = strlen (cstr); |
899 | if (out->blen < out->slen) | 883 | if (out->blen < out->slen) |
900 | { | 884 | { |
901 | GNUNET_array_grow (out->abuf, | 885 | GNUNET_array_grow (out->abuf, out->blen, out->slen); |
902 | out->blen, | ||
903 | out->slen); | ||
904 | } | 886 | } |
905 | out->sbuf = out->abuf; | 887 | out->sbuf = out->abuf; |
906 | GNUNET_memcpy (out->sbuf, cstr, out->slen); | 888 | GNUNET_memcpy (out->sbuf, cstr, out->slen); |
@@ -942,8 +924,7 @@ needs_parentheses (const struct StringBuffer *str) | |||
942 | return GNUNET_YES; | 924 | return GNUNET_YES; |
943 | } | 925 | } |
944 | /* while '(' before ')', count opening parens */ | 926 | /* while '(' before ')', count opening parens */ |
945 | while ( (NULL != (op = memchr (pos, '(', end - pos))) && | 927 | while ((NULL != (op = memchr (pos, '(', end - pos))) && (op < cl)) |
946 | (op < cl) ) | ||
947 | { | 928 | { |
948 | cnt++; | 929 | cnt++; |
949 | pos = op + 1; | 930 | pos = op + 1; |
@@ -979,10 +960,8 @@ remove_parentheses (struct StringBuffer *str) | |||
979 | if (0) | 960 | if (0) |
980 | return; | 961 | return; |
981 | sbuf = str->sbuf; | 962 | sbuf = str->sbuf; |
982 | if ( (GNUNET_YES == str->null_flag) || | 963 | if ((GNUNET_YES == str->null_flag) || (1 >= (slen = str->slen)) || |
983 | (1 >= (slen = str->slen)) || | 964 | ('(' != str->sbuf[0]) || (')' != str->sbuf[slen - 1])) |
984 | ('(' != str->sbuf[0]) || | ||
985 | (')' != str->sbuf[slen - 1]) ) | ||
986 | return; | 965 | return; |
987 | cnt = 0; | 966 | cnt = 0; |
988 | pos = &sbuf[1]; | 967 | pos = &sbuf[1]; |
@@ -991,19 +970,16 @@ remove_parentheses (struct StringBuffer *str) | |||
991 | cp = memchr (pos, ')', end - pos); | 970 | cp = memchr (pos, ')', end - pos); |
992 | while (NULL != cp) | 971 | while (NULL != cp) |
993 | { | 972 | { |
994 | while ( (NULL != op) && | 973 | while ((NULL != op) && (op < cp)) |
995 | (op < cp) ) | ||
996 | { | 974 | { |
997 | cnt++; | 975 | cnt++; |
998 | pos = op + 1; | 976 | pos = op + 1; |
999 | op = memchr (pos, '(', end - pos); | 977 | op = memchr (pos, '(', end - pos); |
1000 | } | 978 | } |
1001 | while ( (NULL != cp) && | 979 | while ((NULL != cp) && ((NULL == op) || (cp < op))) |
1002 | ( (NULL == op) || | ||
1003 | (cp < op) ) ) | ||
1004 | { | 980 | { |
1005 | if (0 == cnt) | 981 | if (0 == cnt) |
1006 | return; /* can't strip parens */ | 982 | return; /* can't strip parens */ |
1007 | cnt--; | 983 | cnt--; |
1008 | pos = cp + 1; | 984 | pos = cp + 1; |
1009 | cp = memchr (pos, ')', end - pos); | 985 | cp = memchr (pos, ')', end - pos); |
@@ -1030,12 +1006,9 @@ remove_parentheses (struct StringBuffer *str) | |||
1030 | static int | 1006 | static int |
1031 | has_epsilon (const struct StringBuffer *str) | 1007 | has_epsilon (const struct StringBuffer *str) |
1032 | { | 1008 | { |
1033 | return | 1009 | return (GNUNET_YES != str->null_flag) && (0 < str->slen) && |
1034 | (GNUNET_YES != str->null_flag) && | 1010 | ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) && |
1035 | (0 < str->slen) && | 1011 | (')' == str->sbuf[str->slen - 1]); |
1036 | ('(' == str->sbuf[0]) && | ||
1037 | ('|' == str->sbuf[1]) && | ||
1038 | (')' == str->sbuf[str->slen - 1]); | ||
1039 | } | 1012 | } |
1040 | 1013 | ||
1041 | 1014 | ||
@@ -1049,25 +1022,20 @@ has_epsilon (const struct StringBuffer *str) | |||
1049 | * epsilon could be found, NULL if 'str' was NULL | 1022 | * epsilon could be found, NULL if 'str' was NULL |
1050 | */ | 1023 | */ |
1051 | static void | 1024 | static void |
1052 | remove_epsilon (const struct StringBuffer *str, | 1025 | remove_epsilon (const struct StringBuffer *str, struct StringBuffer *ret) |
1053 | struct StringBuffer *ret) | ||
1054 | { | 1026 | { |
1055 | if (GNUNET_YES == str->null_flag) | 1027 | if (GNUNET_YES == str->null_flag) |
1056 | { | 1028 | { |
1057 | ret->null_flag = GNUNET_YES; | 1029 | ret->null_flag = GNUNET_YES; |
1058 | return; | 1030 | return; |
1059 | } | 1031 | } |
1060 | if ( (str->slen > 1) && | 1032 | if ((str->slen > 1) && ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) && |
1061 | ('(' == str->sbuf[0]) && | 1033 | (')' == str->sbuf[str->slen - 1])) |
1062 | ('|' == str->sbuf[1]) && | ||
1063 | (')' == str->sbuf[str->slen - 1]) ) | ||
1064 | { | 1034 | { |
1065 | /* remove epsilon */ | 1035 | /* remove epsilon */ |
1066 | if (ret->blen < str->slen - 3) | 1036 | if (ret->blen < str->slen - 3) |
1067 | { | 1037 | { |
1068 | GNUNET_array_grow (ret->abuf, | 1038 | GNUNET_array_grow (ret->abuf, ret->blen, str->slen - 3); |
1069 | ret->blen, | ||
1070 | str->slen - 3); | ||
1071 | } | 1039 | } |
1072 | ret->sbuf = ret->abuf; | 1040 | ret->sbuf = ret->abuf; |
1073 | ret->slen = str->slen - 3; | 1041 | ret->slen = str->slen - 3; |
@@ -1089,13 +1057,12 @@ remove_epsilon (const struct StringBuffer *str, | |||
1089 | */ | 1057 | */ |
1090 | static int | 1058 | static int |
1091 | sb_strncmp (const struct StringBuffer *str1, | 1059 | sb_strncmp (const struct StringBuffer *str1, |
1092 | const struct StringBuffer *str2, size_t n) | 1060 | const struct StringBuffer *str2, |
1061 | size_t n) | ||
1093 | { | 1062 | { |
1094 | size_t max; | 1063 | size_t max; |
1095 | 1064 | ||
1096 | if ( (str1->slen != str2->slen) && | 1065 | if ((str1->slen != str2->slen) && ((str1->slen < n) || (str2->slen < n))) |
1097 | ( (str1->slen < n) || | ||
1098 | (str2->slen < n) ) ) | ||
1099 | return -1; | 1066 | return -1; |
1100 | max = GNUNET_MAX (str1->slen, str2->slen); | 1067 | max = GNUNET_MAX (str1->slen, str2->slen); |
1101 | if (max > n) | 1068 | if (max > n) |
@@ -1114,8 +1081,7 @@ sb_strncmp (const struct StringBuffer *str1, | |||
1114 | * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise | 1081 | * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise |
1115 | */ | 1082 | */ |
1116 | static int | 1083 | static int |
1117 | sb_strncmp_cstr (const struct StringBuffer *str1, | 1084 | sb_strncmp_cstr (const struct StringBuffer *str1, const char *str2, size_t n) |
1118 | const char *str2, size_t n) | ||
1119 | { | 1085 | { |
1120 | if (str1->slen < n) | 1086 | if (str1->slen < n) |
1121 | return -1; | 1087 | return -1; |
@@ -1131,8 +1097,7 @@ sb_strncmp_cstr (const struct StringBuffer *str1, | |||
1131 | * @param n desired target length | 1097 | * @param n desired target length |
1132 | */ | 1098 | */ |
1133 | static void | 1099 | static void |
1134 | sb_init (struct StringBuffer *sb, | 1100 | sb_init (struct StringBuffer *sb, size_t n) |
1135 | size_t n) | ||
1136 | { | 1101 | { |
1137 | sb->null_flag = GNUNET_NO; | 1102 | sb->null_flag = GNUNET_NO; |
1138 | sb->abuf = sb->sbuf = (0 == n) ? NULL : GNUNET_malloc (n); | 1103 | sb->abuf = sb->sbuf = (0 == n) ? NULL : GNUNET_malloc (n); |
@@ -1152,12 +1117,11 @@ sb_init (struct StringBuffer *sb, | |||
1152 | */ | 1117 | */ |
1153 | static int | 1118 | static int |
1154 | sb_strkcmp (const struct StringBuffer *str1, | 1119 | sb_strkcmp (const struct StringBuffer *str1, |
1155 | const struct StringBuffer *str2, size_t k) | 1120 | const struct StringBuffer *str2, |
1121 | size_t k) | ||
1156 | { | 1122 | { |
1157 | if ( (GNUNET_YES == str1->null_flag) || | 1123 | if ((GNUNET_YES == str1->null_flag) || (GNUNET_YES == str2->null_flag) || |
1158 | (GNUNET_YES == str2->null_flag) || | 1124 | (k > str1->slen) || (str1->slen - k != str2->slen)) |
1159 | (k > str1->slen) || | ||
1160 | (str1->slen - k != str2->slen) ) | ||
1161 | return -1; | 1125 | return -1; |
1162 | return memcmp (&str1->sbuf[k], str2->sbuf, str2->slen); | 1126 | return memcmp (&str1->sbuf[k], str2->sbuf, str2->slen); |
1163 | } | 1127 | } |
@@ -1172,7 +1136,8 @@ sb_strkcmp (const struct StringBuffer *str1, | |||
1172 | * @param s current state. | 1136 | * @param s current state. |
1173 | */ | 1137 | */ |
1174 | static void | 1138 | static void |
1175 | number_states (void *cls, const unsigned int count, | 1139 | number_states (void *cls, |
1140 | const unsigned int count, | ||
1176 | struct REGEX_INTERNAL_State *s) | 1141 | struct REGEX_INTERNAL_State *s) |
1177 | { | 1142 | { |
1178 | struct REGEX_INTERNAL_State **states = cls; | 1143 | struct REGEX_INTERNAL_State **states = cls; |
@@ -1183,10 +1148,9 @@ number_states (void *cls, const unsigned int count, | |||
1183 | } | 1148 | } |
1184 | 1149 | ||
1185 | 1150 | ||
1186 | 1151 | #define PRIS(a) \ | |
1187 | #define PRIS(a) \ | ||
1188 | ((GNUNET_YES == a.null_flag) ? 6 : (int) a.slen), \ | 1152 | ((GNUNET_YES == a.null_flag) ? 6 : (int) a.slen), \ |
1189 | ((GNUNET_YES == a.null_flag) ? "(null)" : a.sbuf) | 1153 | ((GNUNET_YES == a.null_flag) ? "(null)" : a.sbuf) |
1190 | 1154 | ||
1191 | 1155 | ||
1192 | /** | 1156 | /** |
@@ -1205,12 +1169,12 @@ number_states (void *cls, const unsigned int count, | |||
1205 | */ | 1169 | */ |
1206 | static void | 1170 | static void |
1207 | automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | 1171 | automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, |
1208 | const struct StringBuffer *R_last_ik, | 1172 | const struct StringBuffer *R_last_ik, |
1209 | const struct StringBuffer *R_last_kk, | 1173 | const struct StringBuffer *R_last_kk, |
1210 | const struct StringBuffer *R_last_kj, | 1174 | const struct StringBuffer *R_last_kj, |
1211 | struct StringBuffer *R_cur_ij, | 1175 | struct StringBuffer *R_cur_ij, |
1212 | struct StringBuffer *R_cur_l, | 1176 | struct StringBuffer *R_cur_l, |
1213 | struct StringBuffer *R_cur_r) | 1177 | struct StringBuffer *R_cur_r) |
1214 | { | 1178 | { |
1215 | struct StringBuffer R_temp_ij; | 1179 | struct StringBuffer R_temp_ij; |
1216 | struct StringBuffer R_temp_ik; | 1180 | struct StringBuffer R_temp_ik; |
@@ -1235,9 +1199,9 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1235 | * R_cur_r == R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj} | 1199 | * R_cur_r == R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj} |
1236 | */ | 1200 | */ |
1237 | 1201 | ||
1238 | if ( (GNUNET_YES == R_last_ij->null_flag) && | 1202 | if ((GNUNET_YES == R_last_ij->null_flag) && |
1239 | ( (GNUNET_YES == R_last_ik->null_flag) || | 1203 | ((GNUNET_YES == R_last_ik->null_flag) || |
1240 | (GNUNET_YES == R_last_kj->null_flag))) | 1204 | (GNUNET_YES == R_last_kj->null_flag))) |
1241 | { | 1205 | { |
1242 | /* R^{(k)}_{ij} = N | N */ | 1206 | /* R^{(k)}_{ij} = N | N */ |
1243 | R_cur_ij->null_flag = GNUNET_YES; | 1207 | R_cur_ij->null_flag = GNUNET_YES; |
@@ -1245,8 +1209,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1245 | return; | 1209 | return; |
1246 | } | 1210 | } |
1247 | 1211 | ||
1248 | if ( (GNUNET_YES == R_last_ik->null_flag) || | 1212 | if ((GNUNET_YES == R_last_ik->null_flag) || |
1249 | (GNUNET_YES == R_last_kj->null_flag) ) | 1213 | (GNUNET_YES == R_last_kj->null_flag)) |
1250 | { | 1214 | { |
1251 | /* R^{(k)}_{ij} = R^{(k-1)}_{ij} | N */ | 1215 | /* R^{(k)}_{ij} = R^{(k-1)}_{ij} | N */ |
1252 | if (GNUNET_YES == R_last_ij->synced) | 1216 | if (GNUNET_YES == R_last_ij->synced) |
@@ -1299,9 +1263,9 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1299 | remove_epsilon (R_last_ij, &R_temp_ij); | 1263 | remove_epsilon (R_last_ij, &R_temp_ij); |
1300 | remove_parentheses (&R_temp_ij); | 1264 | remove_parentheses (&R_temp_ij); |
1301 | 1265 | ||
1302 | if ( (0 == sb_strcmp (&R_temp_ij, &R_temp_ik)) && | 1266 | if ((0 == sb_strcmp (&R_temp_ij, &R_temp_ik)) && |
1303 | (0 == sb_strcmp (&R_temp_ik, &R_temp_kk)) && | 1267 | (0 == sb_strcmp (&R_temp_ik, &R_temp_kk)) && |
1304 | (0 == sb_strcmp (&R_temp_kk, &R_temp_kj)) ) | 1268 | (0 == sb_strcmp (&R_temp_kk, &R_temp_kj))) |
1305 | { | 1269 | { |
1306 | if (0 == R_temp_ij.slen) | 1270 | if (0 == R_temp_ij.slen) |
1307 | { | 1271 | { |
@@ -1340,7 +1304,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1340 | sb_printf1 (R_cur_r, "%.*s+", 1, &R_temp_ij); | 1304 | sb_printf1 (R_cur_r, "%.*s+", 1, &R_temp_ij); |
1341 | } | 1305 | } |
1342 | } | 1306 | } |
1343 | else if ( (0 == ij_ik_cmp) && (0 == clean_kk_kj_cmp) && (0 != clean_ik_kk_cmp) ) | 1307 | else if ((0 == ij_ik_cmp) && (0 == clean_kk_kj_cmp) && |
1308 | (0 != clean_ik_kk_cmp)) | ||
1344 | { | 1309 | { |
1345 | /* a|ab*b = ab* */ | 1310 | /* a|ab*b = ab* */ |
1346 | if (0 == R_last_kk->slen) | 1311 | if (0 == R_last_kk->slen) |
@@ -1351,7 +1316,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1351 | sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, R_last_kk); | 1316 | sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, R_last_kk); |
1352 | R_cur_l->null_flag = GNUNET_YES; | 1317 | R_cur_l->null_flag = GNUNET_YES; |
1353 | } | 1318 | } |
1354 | else if ( (0 == ij_kj_cmp) && (0 == clean_ik_kk_cmp) && (0 != clean_kk_kj_cmp)) | 1319 | else if ((0 == ij_kj_cmp) && (0 == clean_ik_kk_cmp) && |
1320 | (0 != clean_kk_kj_cmp)) | ||
1355 | { | 1321 | { |
1356 | /* a|bb*a = b*a */ | 1322 | /* a|bb*a = b*a */ |
1357 | if (R_last_kk->slen < 1) | 1323 | if (R_last_kk->slen < 1) |
@@ -1365,8 +1331,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1365 | 1331 | ||
1366 | R_cur_l->null_flag = GNUNET_YES; | 1332 | R_cur_l->null_flag = GNUNET_YES; |
1367 | } | 1333 | } |
1368 | else if ( (0 == ij_ik_cmp) && (0 == kk_kj_cmp) && (! has_epsilon (R_last_ij)) && | 1334 | else if ((0 == ij_ik_cmp) && (0 == kk_kj_cmp) && |
1369 | has_epsilon (R_last_kk)) | 1335 | (! has_epsilon (R_last_ij)) && has_epsilon (R_last_kk)) |
1370 | { | 1336 | { |
1371 | /* a|a(e|b)*(e|b) = a|ab* = a|a|ab|abb|abbb|... = ab* */ | 1337 | /* a|a(e|b)*(e|b) = a|ab* = a|a|ab|abb|abbb|... = ab* */ |
1372 | if (needs_parentheses (&R_temp_kk)) | 1338 | if (needs_parentheses (&R_temp_kk)) |
@@ -1375,8 +1341,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1375 | sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, &R_temp_kk); | 1341 | sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, &R_temp_kk); |
1376 | R_cur_l->null_flag = GNUNET_YES; | 1342 | R_cur_l->null_flag = GNUNET_YES; |
1377 | } | 1343 | } |
1378 | else if ( (0 == ij_kj_cmp) && (0 == ik_kk_cmp) && (! has_epsilon (R_last_ij)) && | 1344 | else if ((0 == ij_kj_cmp) && (0 == ik_kk_cmp) && |
1379 | has_epsilon (R_last_kk)) | 1345 | (! has_epsilon (R_last_ij)) && has_epsilon (R_last_kk)) |
1380 | { | 1346 | { |
1381 | /* a|(e|b)(e|b)*a = a|b*a = a|a|ba|bba|bbba|... = b*a */ | 1347 | /* a|(e|b)(e|b)*a = a|b*a = a|a|ba|bba|bbba|... = b*a */ |
1382 | if (needs_parentheses (&R_temp_kk)) | 1348 | if (needs_parentheses (&R_temp_kk)) |
@@ -1403,15 +1369,12 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1403 | length = R_temp_kk.slen - R_last_ik->slen; | 1369 | length = R_temp_kk.slen - R_last_ik->slen; |
1404 | 1370 | ||
1405 | /* a(ba)*bx = (ab)+x */ | 1371 | /* a(ba)*bx = (ab)+x */ |
1406 | if ( (length > 0) && | 1372 | if ((length > 0) && (GNUNET_YES != R_last_kk->null_flag) && |
1407 | (GNUNET_YES != R_last_kk->null_flag) && | 1373 | (0 < R_last_kk->slen) && (GNUNET_YES != R_last_kj->null_flag) && |
1408 | (0 < R_last_kk->slen) && | 1374 | (0 < R_last_kj->slen) && (GNUNET_YES != R_last_ik->null_flag) && |
1409 | (GNUNET_YES != R_last_kj->null_flag) && | 1375 | (0 < R_last_ik->slen) && |
1410 | (0 < R_last_kj->slen) && | 1376 | (0 == sb_strkcmp (&R_temp_kk, R_last_ik, length)) && |
1411 | (GNUNET_YES != R_last_ik->null_flag) && | 1377 | (0 == sb_strncmp (&R_temp_kk, R_last_kj, length))) |
1412 | (0 < R_last_ik->slen) && | ||
1413 | (0 == sb_strkcmp (&R_temp_kk, R_last_ik, length)) && | ||
1414 | (0 == sb_strncmp (&R_temp_kk, R_last_kj, length)) ) | ||
1415 | { | 1378 | { |
1416 | struct StringBuffer temp_a; | 1379 | struct StringBuffer temp_a; |
1417 | struct StringBuffer temp_b; | 1380 | struct StringBuffer temp_b; |
@@ -1430,9 +1393,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1430 | temp_b.slen = length_r; | 1393 | temp_b.slen = length_r; |
1431 | 1394 | ||
1432 | /* e|(ab)+ = (ab)* */ | 1395 | /* e|(ab)+ = (ab)* */ |
1433 | if ( (GNUNET_YES != R_cur_l->null_flag) && | 1396 | if ((GNUNET_YES != R_cur_l->null_flag) && (0 == R_cur_l->slen) && |
1434 | (0 == R_cur_l->slen) && | 1397 | (0 == temp_b.slen)) |
1435 | (0 == temp_b.slen) ) | ||
1436 | { | 1398 | { |
1437 | sb_printf2 (R_cur_r, "(%.*s%.*s)*", 3, R_last_ik, &temp_a); | 1399 | sb_printf2 (R_cur_r, "(%.*s%.*s)*", 3, R_last_ik, &temp_a); |
1438 | sb_free (R_cur_l); | 1400 | sb_free (R_cur_l); |
@@ -1460,9 +1422,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1460 | sb_printf1 (R_cur_r, "%.*s*", 1, &R_temp_kk); | 1422 | sb_printf1 (R_cur_r, "%.*s*", 1, &R_temp_kk); |
1461 | } | 1423 | } |
1462 | /* aa*a = a+a */ | 1424 | /* aa*a = a+a */ |
1463 | else if ( (0 == clean_ik_kk_cmp) && | 1425 | else if ((0 == clean_ik_kk_cmp) && (0 == clean_kk_kj_cmp) && |
1464 | (0 == clean_kk_kj_cmp) && | 1426 | (! has_epsilon (R_last_ik))) |
1465 | (! has_epsilon (R_last_ik)) ) | ||
1466 | { | 1427 | { |
1467 | if (needs_parentheses (&R_temp_kk)) | 1428 | if (needs_parentheses (&R_temp_kk)) |
1468 | sb_printf2 (R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, &R_temp_kk); | 1429 | sb_printf2 (R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, &R_temp_kk); |
@@ -1477,9 +1438,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1477 | */ | 1438 | */ |
1478 | else | 1439 | else |
1479 | { | 1440 | { |
1480 | eps_check = | 1441 | eps_check = (has_epsilon (R_last_ik) + has_epsilon (R_last_kk) + |
1481 | (has_epsilon (R_last_ik) + has_epsilon (R_last_kk) + | 1442 | has_epsilon (R_last_kj)); |
1482 | has_epsilon (R_last_kj)); | ||
1483 | 1443 | ||
1484 | if (1 == eps_check) | 1444 | if (1 == eps_check) |
1485 | { | 1445 | { |
@@ -1538,18 +1498,26 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1538 | { | 1498 | { |
1539 | if (needs_parentheses (&R_temp_kk)) | 1499 | if (needs_parentheses (&R_temp_kk)) |
1540 | { | 1500 | { |
1541 | sb_printf3 (R_cur_r, "%.*s(%.*s)*%.*s", 3, R_last_ik, &R_temp_kk, | 1501 | sb_printf3 (R_cur_r, |
1542 | R_last_kj); | 1502 | "%.*s(%.*s)*%.*s", |
1503 | 3, | ||
1504 | R_last_ik, | ||
1505 | &R_temp_kk, | ||
1506 | R_last_kj); | ||
1543 | } | 1507 | } |
1544 | else | 1508 | else |
1545 | { | 1509 | { |
1546 | sb_printf3 (R_cur_r, "%.*s%.*s*%.*s", 1, R_last_ik, &R_temp_kk, | 1510 | sb_printf3 (R_cur_r, |
1547 | R_last_kj); | 1511 | "%.*s%.*s*%.*s", |
1512 | 1, | ||
1513 | R_last_ik, | ||
1514 | &R_temp_kk, | ||
1515 | R_last_kj); | ||
1548 | } | 1516 | } |
1549 | } | 1517 | } |
1550 | else | 1518 | else |
1551 | { | 1519 | { |
1552 | sb_printf2 (R_cur_r, "%.*s%.*s", 0, R_last_ik, R_last_kj); | 1520 | sb_printf2 (R_cur_r, "%.*s%.*s", 0, R_last_ik, R_last_kj); |
1553 | } | 1521 | } |
1554 | } | 1522 | } |
1555 | } | 1523 | } |
@@ -1558,15 +1526,13 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1558 | sb_free (&R_temp_kk); | 1526 | sb_free (&R_temp_kk); |
1559 | sb_free (&R_temp_kj); | 1527 | sb_free (&R_temp_kj); |
1560 | 1528 | ||
1561 | if ( (GNUNET_YES == R_cur_l->null_flag) && | 1529 | if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag)) |
1562 | (GNUNET_YES == R_cur_r->null_flag) ) | ||
1563 | { | 1530 | { |
1564 | R_cur_ij->null_flag = GNUNET_YES; | 1531 | R_cur_ij->null_flag = GNUNET_YES; |
1565 | return; | 1532 | return; |
1566 | } | 1533 | } |
1567 | 1534 | ||
1568 | if ( (GNUNET_YES != R_cur_l->null_flag) && | 1535 | if ((GNUNET_YES != R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag)) |
1569 | (GNUNET_YES == R_cur_r->null_flag) ) | ||
1570 | { | 1536 | { |
1571 | struct StringBuffer tmp; | 1537 | struct StringBuffer tmp; |
1572 | 1538 | ||
@@ -1576,8 +1542,7 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1576 | return; | 1542 | return; |
1577 | } | 1543 | } |
1578 | 1544 | ||
1579 | if ( (GNUNET_YES == R_cur_l->null_flag) && | 1545 | if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES != R_cur_r->null_flag)) |
1580 | (GNUNET_YES != R_cur_r->null_flag) ) | ||
1581 | { | 1546 | { |
1582 | struct StringBuffer tmp; | 1547 | struct StringBuffer tmp; |
1583 | 1548 | ||
@@ -1629,8 +1594,7 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1629 | 1594 | ||
1630 | R_last = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n); | 1595 | R_last = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n); |
1631 | R_cur = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n); | 1596 | R_cur = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n); |
1632 | if ( (NULL == R_last) || | 1597 | if ((NULL == R_last) || (NULL == R_cur)) |
1633 | (NULL == R_cur) ) | ||
1634 | { | 1598 | { |
1635 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 1599 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
1636 | GNUNET_free_non_null (R_cur); | 1600 | GNUNET_free_non_null (R_cur); |
@@ -1639,14 +1603,18 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1639 | } | 1603 | } |
1640 | 1604 | ||
1641 | /* create depth-first numbering of the states, initializes 'state' */ | 1605 | /* create depth-first numbering of the states, initializes 'state' */ |
1642 | REGEX_INTERNAL_automaton_traverse (a, a->start, NULL, NULL, &number_states, | 1606 | REGEX_INTERNAL_automaton_traverse (a, |
1643 | states); | 1607 | a->start, |
1608 | NULL, | ||
1609 | NULL, | ||
1610 | &number_states, | ||
1611 | states); | ||
1644 | 1612 | ||
1645 | for (i = 0; i < n; i++) | 1613 | for (i = 0; i < n; i++) |
1646 | GNUNET_assert (NULL != states[i]); | 1614 | GNUNET_assert (NULL != states[i]); |
1647 | for (i = 0; i < n; i++) | 1615 | for (i = 0; i < n; i++) |
1648 | for (j = 0; j < n; j++) | 1616 | for (j = 0; j < n; j++) |
1649 | R_last[i *n + j].null_flag = GNUNET_YES; | 1617 | R_last[i * n + j].null_flag = GNUNET_YES; |
1650 | 1618 | ||
1651 | /* Compute regular expressions of length "1" between each pair of states */ | 1619 | /* Compute regular expressions of length "1" between each pair of states */ |
1652 | for (i = 0; i < n; i++) | 1620 | for (i = 0; i < n; i++) |
@@ -1660,8 +1628,8 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1660 | } | 1628 | } |
1661 | else | 1629 | else |
1662 | { | 1630 | { |
1663 | sb_append_cstr (&R_last[i * n + j], "|"); | 1631 | sb_append_cstr (&R_last[i * n + j], "|"); |
1664 | sb_append_cstr (&R_last[i * n + j], t->label); | 1632 | sb_append_cstr (&R_last[i * n + j], t->label); |
1665 | } | 1633 | } |
1666 | } | 1634 | } |
1667 | /* add self-loop: i is reachable from i via epsilon-transition */ | 1635 | /* add self-loop: i is reachable from i via epsilon-transition */ |
@@ -1695,10 +1663,13 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1695 | */ | 1663 | */ |
1696 | 1664 | ||
1697 | /* Create R_cur[i][j] and simplify the expression */ | 1665 | /* Create R_cur[i][j] and simplify the expression */ |
1698 | automaton_create_proofs_simplify (&R_last[i * n + j], &R_last[i * n + k], | 1666 | automaton_create_proofs_simplify (&R_last[i * n + j], |
1699 | &R_last[k * n + k], &R_last[k * n + j], | 1667 | &R_last[i * n + k], |
1668 | &R_last[k * n + k], | ||
1669 | &R_last[k * n + j], | ||
1700 | &R_cur[i * n + j], | 1670 | &R_cur[i * n + j], |
1701 | &R_cur_l, &R_cur_r); | 1671 | &R_cur_l, |
1672 | &R_cur_r); | ||
1702 | } | 1673 | } |
1703 | } | 1674 | } |
1704 | /* set R_last = R_cur */ | 1675 | /* set R_last = R_cur */ |
@@ -1718,8 +1689,9 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1718 | if (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) | 1689 | if (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) |
1719 | { | 1690 | { |
1720 | states[i]->proof = GNUNET_strndup (R_last[a->start->dfs_id * n + i].sbuf, | 1691 | states[i]->proof = GNUNET_strndup (R_last[a->start->dfs_id * n + i].sbuf, |
1721 | R_last[a->start->dfs_id * n + i].slen); | 1692 | R_last[a->start->dfs_id * n + i].slen); |
1722 | GNUNET_CRYPTO_hash (states[i]->proof, strlen (states[i]->proof), | 1693 | GNUNET_CRYPTO_hash (states[i]->proof, |
1694 | strlen (states[i]->proof), | ||
1723 | &states[i]->hash); | 1695 | &states[i]->hash); |
1724 | } | 1696 | } |
1725 | } | 1697 | } |
@@ -1731,22 +1703,21 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1731 | { | 1703 | { |
1732 | if (states[i]->accepting) | 1704 | if (states[i]->accepting) |
1733 | { | 1705 | { |
1734 | if ( (0 == complete_regex.slen) && | 1706 | if ((0 == complete_regex.slen) && |
1735 | (0 < R_last[a->start->dfs_id * n + i].slen) ) | 1707 | (0 < R_last[a->start->dfs_id * n + i].slen)) |
1736 | { | 1708 | { |
1737 | sb_append (&complete_regex, | 1709 | sb_append (&complete_regex, &R_last[a->start->dfs_id * n + i]); |
1738 | &R_last[a->start->dfs_id * n + i]); | ||
1739 | } | 1710 | } |
1740 | else if ( (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) && | 1711 | else if ((GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) && |
1741 | (0 < R_last[a->start->dfs_id * n + i].slen) ) | 1712 | (0 < R_last[a->start->dfs_id * n + i].slen)) |
1742 | { | 1713 | { |
1743 | sb_append_cstr (&complete_regex, "|"); | 1714 | sb_append_cstr (&complete_regex, "|"); |
1744 | sb_append (&complete_regex, | 1715 | sb_append (&complete_regex, &R_last[a->start->dfs_id * n + i]); |
1745 | &R_last[a->start->dfs_id * n + i]); | ||
1746 | } | 1716 | } |
1747 | } | 1717 | } |
1748 | } | 1718 | } |
1749 | a->canonical_regex = GNUNET_strndup (complete_regex.sbuf, complete_regex.slen); | 1719 | a->canonical_regex = |
1720 | GNUNET_strndup (complete_regex.sbuf, complete_regex.slen); | ||
1750 | 1721 | ||
1751 | /* cleanup */ | 1722 | /* cleanup */ |
1752 | sb_free (&complete_regex); | 1723 | sb_free (&complete_regex); |
@@ -1807,10 +1778,7 @@ dfa_state_create (struct REGEX_INTERNAL_Context *ctx, | |||
1807 | for (i = 0; i < nfa_states->off; i++) | 1778 | for (i = 0; i < nfa_states->off; i++) |
1808 | { | 1779 | { |
1809 | cstate = nfa_states->states[i]; | 1780 | cstate = nfa_states->states[i]; |
1810 | GNUNET_snprintf (pos, | 1781 | GNUNET_snprintf (pos, pos - s->name + len, "%i,", cstate->id); |
1811 | pos - s->name + len, | ||
1812 | "%i,", | ||
1813 | cstate->id); | ||
1814 | pos += strlen (pos); | 1782 | pos += strlen (pos); |
1815 | 1783 | ||
1816 | /* Add a transition for each distinct label to NULL state */ | 1784 | /* Add a transition for each distinct label to NULL state */ |
@@ -1911,7 +1879,12 @@ dfa_remove_unreachable_states (struct REGEX_INTERNAL_Automaton *a) | |||
1911 | s->marked = GNUNET_NO; | 1879 | s->marked = GNUNET_NO; |
1912 | 1880 | ||
1913 | /* 2. traverse dfa from start state and mark all visited states */ | 1881 | /* 2. traverse dfa from start state and mark all visited states */ |
1914 | REGEX_INTERNAL_automaton_traverse (a, a->start, NULL, NULL, &mark_states, NULL); | 1882 | REGEX_INTERNAL_automaton_traverse (a, |
1883 | a->start, | ||
1884 | NULL, | ||
1885 | NULL, | ||
1886 | &mark_states, | ||
1887 | NULL); | ||
1915 | 1888 | ||
1916 | /* 3. delete all states that were not visited */ | 1889 | /* 3. delete all states that were not visited */ |
1917 | for (s = a->states_head; NULL != s; s = s_next) | 1890 | for (s = a->states_head; NULL != s; s = s_next) |
@@ -1990,7 +1963,7 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
1990 | unsigned long long idx; | 1963 | unsigned long long idx; |
1991 | unsigned long long idx1; | 1964 | unsigned long long idx1; |
1992 | 1965 | ||
1993 | if ( (NULL == a) || (0 == a->state_count) ) | 1966 | if ((NULL == a) || (0 == a->state_count)) |
1994 | { | 1967 | { |
1995 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1968 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1996 | "Could not merge nondistinguishable states, automaton was NULL.\n"); | 1969 | "Could not merge nondistinguishable states, automaton was NULL.\n"); |
@@ -1998,7 +1971,8 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
1998 | } | 1971 | } |
1999 | 1972 | ||
2000 | state_cnt = a->state_count; | 1973 | state_cnt = a->state_count; |
2001 | table = GNUNET_malloc_large ((sizeof (uint32_t) * state_cnt * state_cnt / 32) + sizeof (uint32_t)); | 1974 | table = GNUNET_malloc_large ( |
1975 | (sizeof (uint32_t) * state_cnt * state_cnt / 32) + sizeof (uint32_t)); | ||
2002 | if (NULL == table) | 1976 | if (NULL == table) |
2003 | { | 1977 | { |
2004 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 1978 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
@@ -2011,10 +1985,10 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
2011 | /* Mark all pairs of accepting/!accepting states */ | 1985 | /* Mark all pairs of accepting/!accepting states */ |
2012 | for (s1 = a->states_head; NULL != s1; s1 = s1->next) | 1986 | for (s1 = a->states_head; NULL != s1; s1 = s1->next) |
2013 | for (s2 = a->states_head; NULL != s2; s2 = s2->next) | 1987 | for (s2 = a->states_head; NULL != s2; s2 = s2->next) |
2014 | if ( (s1->accepting && !s2->accepting) || | 1988 | if ((s1->accepting && ! s2->accepting) || |
2015 | (!s1->accepting && s2->accepting) ) | 1989 | (! s1->accepting && s2->accepting)) |
2016 | { | 1990 | { |
2017 | idx = (unsigned long long) s1->marked * state_cnt + s2->marked; | 1991 | idx = (unsigned long long) s1->marked * state_cnt + s2->marked; |
2018 | table[idx / 32] |= (1U << (idx % 32)); | 1992 | table[idx / 32] |= (1U << (idx % 32)); |
2019 | } | 1993 | } |
2020 | 1994 | ||
@@ -2027,7 +2001,7 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
2027 | { | 2001 | { |
2028 | for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2->next) | 2002 | for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2->next) |
2029 | { | 2003 | { |
2030 | idx = (unsigned long long) s1->marked * state_cnt + s2->marked; | 2004 | idx = (unsigned long long) s1->marked * state_cnt + s2->marked; |
2031 | if (0 != (table[idx / 32] & (1U << (idx % 32)))) | 2005 | if (0 != (table[idx / 32] & (1U << (idx % 32)))) |
2032 | continue; | 2006 | continue; |
2033 | num_equal_edges = 0; | 2007 | num_equal_edges = 0; |
@@ -2036,28 +2010,30 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
2036 | for (t2 = s2->transitions_head; NULL != t2; t2 = t2->next) | 2010 | for (t2 = s2->transitions_head; NULL != t2; t2 = t2->next) |
2037 | { | 2011 | { |
2038 | if (0 == strcmp (t1->label, t2->label)) | 2012 | if (0 == strcmp (t1->label, t2->label)) |
2039 | { | 2013 | { |
2040 | num_equal_edges++; | 2014 | num_equal_edges++; |
2041 | /* same edge, but targets definitively different, so we're different | 2015 | /* same edge, but targets definitively different, so we're different |
2042 | as well */ | 2016 | as well */ |
2043 | if (t1->to_state->marked > t2->to_state->marked) | 2017 | if (t1->to_state->marked > t2->to_state->marked) |
2044 | idx1 = (unsigned long long) t1->to_state->marked * state_cnt + t2->to_state->marked; | 2018 | idx1 = (unsigned long long) t1->to_state->marked * state_cnt + |
2045 | else | 2019 | t2->to_state->marked; |
2046 | idx1 = (unsigned long long) t2->to_state->marked * state_cnt + t1->to_state->marked; | 2020 | else |
2047 | if (0 != (table[idx1 / 32] & (1U << (idx1 % 32)))) | 2021 | idx1 = (unsigned long long) t2->to_state->marked * state_cnt + |
2048 | { | 2022 | t1->to_state->marked; |
2049 | table[idx / 32] |= (1U << (idx % 32)); | 2023 | if (0 != (table[idx1 / 32] & (1U << (idx1 % 32)))) |
2050 | change = 1; /* changed a marker, need to run again */ | 2024 | { |
2051 | } | 2025 | table[idx / 32] |= (1U << (idx % 32)); |
2052 | } | 2026 | change = 1; /* changed a marker, need to run again */ |
2053 | } | 2027 | } |
2028 | } | ||
2029 | } | ||
2054 | } | 2030 | } |
2055 | if ( (num_equal_edges != s1->transition_count) || | 2031 | if ((num_equal_edges != s1->transition_count) || |
2056 | (num_equal_edges != s2->transition_count) ) | 2032 | (num_equal_edges != s2->transition_count)) |
2057 | { | 2033 | { |
2058 | /* Make sure ALL edges of possible equal states are the same */ | 2034 | /* Make sure ALL edges of possible equal states are the same */ |
2059 | table[idx / 32] |= (1U << (idx % 32)); | 2035 | table[idx / 32] |= (1U << (idx % 32)); |
2060 | change = 1; /* changed a marker, need to run again */ | 2036 | change = 1; /* changed a marker, need to run again */ |
2061 | } | 2037 | } |
2062 | } | 2038 | } |
2063 | } | 2039 | } |
@@ -2145,7 +2121,9 @@ struct REGEX_INTERNAL_Strided_Context | |||
2145 | * @param s current state in the depth-first traversal | 2121 | * @param s current state in the depth-first traversal |
2146 | */ | 2122 | */ |
2147 | static void | 2123 | static void |
2148 | dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label, | 2124 | dfa_add_multi_strides_helper (void *cls, |
2125 | const unsigned int depth, | ||
2126 | char *label, | ||
2149 | struct REGEX_INTERNAL_State *start, | 2127 | struct REGEX_INTERNAL_State *start, |
2150 | struct REGEX_INTERNAL_State *s) | 2128 | struct REGEX_INTERNAL_State *s) |
2151 | { | 2129 | { |
@@ -2159,7 +2137,8 @@ dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label, | |||
2159 | t->label = GNUNET_strdup (label); | 2137 | t->label = GNUNET_strdup (label); |
2160 | t->to_state = s; | 2138 | t->to_state = s; |
2161 | t->from_state = start; | 2139 | t->from_state = start; |
2162 | GNUNET_CONTAINER_DLL_insert (ctx->transitions_head, ctx->transitions_tail, | 2140 | GNUNET_CONTAINER_DLL_insert (ctx->transitions_head, |
2141 | ctx->transitions_tail, | ||
2163 | t); | 2142 | t); |
2164 | } | 2143 | } |
2165 | else | 2144 | else |
@@ -2178,7 +2157,10 @@ dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label, | |||
2178 | else | 2157 | else |
2179 | new_label = GNUNET_strdup (t->label); | 2158 | new_label = GNUNET_strdup (t->label); |
2180 | 2159 | ||
2181 | dfa_add_multi_strides_helper (cls, (depth + 1), new_label, start, | 2160 | dfa_add_multi_strides_helper (cls, |
2161 | (depth + 1), | ||
2162 | new_label, | ||
2163 | start, | ||
2182 | t->to_state); | 2164 | t->to_state); |
2183 | } | 2165 | } |
2184 | } | 2166 | } |
@@ -2195,7 +2177,8 @@ dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label, | |||
2195 | * @param s current state. | 2177 | * @param s current state. |
2196 | */ | 2178 | */ |
2197 | static void | 2179 | static void |
2198 | dfa_add_multi_strides (void *cls, const unsigned int count, | 2180 | dfa_add_multi_strides (void *cls, |
2181 | const unsigned int count, | ||
2199 | struct REGEX_INTERNAL_State *s) | 2182 | struct REGEX_INTERNAL_State *s) |
2200 | { | 2183 | { |
2201 | dfa_add_multi_strides_helper (cls, 0, NULL, s, s); | 2184 | dfa_add_multi_strides_helper (cls, 0, NULL, s, s); |
@@ -2211,10 +2194,10 @@ dfa_add_multi_strides (void *cls, const unsigned int count, | |||
2211 | */ | 2194 | */ |
2212 | void | 2195 | void |
2213 | REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx, | 2196 | REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx, |
2214 | struct REGEX_INTERNAL_Automaton *dfa, | 2197 | struct REGEX_INTERNAL_Automaton *dfa, |
2215 | const unsigned int stride_len) | 2198 | const unsigned int stride_len) |
2216 | { | 2199 | { |
2217 | struct REGEX_INTERNAL_Strided_Context ctx = { stride_len, NULL, NULL }; | 2200 | struct REGEX_INTERNAL_Strided_Context ctx = {stride_len, NULL, NULL}; |
2218 | struct REGEX_INTERNAL_Transition *t; | 2201 | struct REGEX_INTERNAL_Transition *t; |
2219 | struct REGEX_INTERNAL_Transition *t_next; | 2202 | struct REGEX_INTERNAL_Transition *t_next; |
2220 | 2203 | ||
@@ -2222,8 +2205,12 @@ REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx, | |||
2222 | return; | 2205 | return; |
2223 | 2206 | ||
2224 | /* Compute the new transitions of given stride_len */ | 2207 | /* Compute the new transitions of given stride_len */ |
2225 | REGEX_INTERNAL_automaton_traverse (dfa, dfa->start, NULL, NULL, | 2208 | REGEX_INTERNAL_automaton_traverse (dfa, |
2226 | &dfa_add_multi_strides, &ctx); | 2209 | dfa->start, |
2210 | NULL, | ||
2211 | NULL, | ||
2212 | &dfa_add_multi_strides, | ||
2213 | &ctx); | ||
2227 | 2214 | ||
2228 | /* Add all the new transitions to the automaton. */ | 2215 | /* Add all the new transitions to the automaton. */ |
2229 | for (t = ctx.transitions_head; NULL != t; t = t_next) | 2216 | for (t = ctx.transitions_head; NULL != t; t = t_next) |
@@ -2255,7 +2242,8 @@ REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx, | |||
2255 | void | 2242 | void |
2256 | dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | 2243 | dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, |
2257 | struct REGEX_INTERNAL_State *start, | 2244 | struct REGEX_INTERNAL_State *start, |
2258 | struct REGEX_INTERNAL_State *cur, char *label, | 2245 | struct REGEX_INTERNAL_State *cur, |
2246 | char *label, | ||
2259 | unsigned int max_len, | 2247 | unsigned int max_len, |
2260 | struct REGEX_INTERNAL_Transition **transitions_head, | 2248 | struct REGEX_INTERNAL_Transition **transitions_head, |
2261 | struct REGEX_INTERNAL_Transition **transitions_tail) | 2249 | struct REGEX_INTERNAL_Transition **transitions_tail) |
@@ -2266,8 +2254,8 @@ dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | |||
2266 | 2254 | ||
2267 | if (NULL != label && | 2255 | if (NULL != label && |
2268 | ((cur->incoming_transition_count > 1 || GNUNET_YES == cur->accepting || | 2256 | ((cur->incoming_transition_count > 1 || GNUNET_YES == cur->accepting || |
2269 | GNUNET_YES == cur->marked) || (start != dfa->start && max_len > 0 && | 2257 | GNUNET_YES == cur->marked) || |
2270 | max_len == strlen (label)) || | 2258 | (start != dfa->start && max_len > 0 && max_len == strlen (label)) || |
2271 | (start == dfa->start && GNUNET_REGEX_INITIAL_BYTES == strlen (label)))) | 2259 | (start == dfa->start && GNUNET_REGEX_INITIAL_BYTES == strlen (label)))) |
2272 | { | 2260 | { |
2273 | t = GNUNET_new (struct REGEX_INTERNAL_Transition); | 2261 | t = GNUNET_new (struct REGEX_INTERNAL_Transition); |
@@ -2278,7 +2266,12 @@ dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | |||
2278 | 2266 | ||
2279 | if (GNUNET_NO == cur->marked) | 2267 | if (GNUNET_NO == cur->marked) |
2280 | { | 2268 | { |
2281 | dfa_compress_paths_helper (dfa, cur, cur, NULL, max_len, transitions_head, | 2269 | dfa_compress_paths_helper (dfa, |
2270 | cur, | ||
2271 | cur, | ||
2272 | NULL, | ||
2273 | max_len, | ||
2274 | transitions_head, | ||
2282 | transitions_tail); | 2275 | transitions_tail); |
2283 | } | 2276 | } |
2284 | return; | 2277 | return; |
@@ -2301,8 +2294,13 @@ dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | |||
2301 | 2294 | ||
2302 | if (t->to_state != cur) | 2295 | if (t->to_state != cur) |
2303 | { | 2296 | { |
2304 | dfa_compress_paths_helper (dfa, start, t->to_state, new_label, max_len, | 2297 | dfa_compress_paths_helper (dfa, |
2305 | transitions_head, transitions_tail); | 2298 | start, |
2299 | t->to_state, | ||
2300 | new_label, | ||
2301 | max_len, | ||
2302 | transitions_head, | ||
2303 | transitions_tail); | ||
2306 | } | 2304 | } |
2307 | GNUNET_free (new_label); | 2305 | GNUNET_free (new_label); |
2308 | } | 2306 | } |
@@ -2319,7 +2317,8 @@ dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | |||
2319 | */ | 2317 | */ |
2320 | static void | 2318 | static void |
2321 | dfa_compress_paths (struct REGEX_INTERNAL_Context *regex_ctx, | 2319 | dfa_compress_paths (struct REGEX_INTERNAL_Context *regex_ctx, |
2322 | struct REGEX_INTERNAL_Automaton *dfa, unsigned int max_len) | 2320 | struct REGEX_INTERNAL_Automaton *dfa, |
2321 | unsigned int max_len) | ||
2323 | { | 2322 | { |
2324 | struct REGEX_INTERNAL_State *s; | 2323 | struct REGEX_INTERNAL_State *s; |
2325 | struct REGEX_INTERNAL_State *s_next; | 2324 | struct REGEX_INTERNAL_State *s_next; |
@@ -2349,8 +2348,13 @@ dfa_compress_paths (struct REGEX_INTERNAL_Context *regex_ctx, | |||
2349 | } | 2348 | } |
2350 | 2349 | ||
2351 | /* Add strides and mark states that can be deleted. */ | 2350 | /* Add strides and mark states that can be deleted. */ |
2352 | dfa_compress_paths_helper (dfa, dfa->start, dfa->start, NULL, max_len, | 2351 | dfa_compress_paths_helper (dfa, |
2353 | &transitions_head, &transitions_tail); | 2352 | dfa->start, |
2353 | dfa->start, | ||
2354 | NULL, | ||
2355 | max_len, | ||
2356 | &transitions_head, | ||
2357 | &transitions_tail); | ||
2354 | 2358 | ||
2355 | /* Add all the new transitions to the automaton. */ | 2359 | /* Add all the new transitions to the automaton. */ |
2356 | for (t = transitions_head; NULL != t; t = t_next) | 2360 | for (t = transitions_head; NULL != t; t = t_next) |
@@ -2486,8 +2490,9 @@ nfa_state_create (struct REGEX_INTERNAL_Context *ctx, int accepting) | |||
2486 | */ | 2490 | */ |
2487 | static void | 2491 | static void |
2488 | nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret, | 2492 | nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret, |
2489 | struct REGEX_INTERNAL_Automaton *nfa, | 2493 | struct REGEX_INTERNAL_Automaton *nfa, |
2490 | struct REGEX_INTERNAL_StateSet *states, const char *label) | 2494 | struct REGEX_INTERNAL_StateSet *states, |
2495 | const char *label) | ||
2491 | { | 2496 | { |
2492 | struct REGEX_INTERNAL_State *s; | 2497 | struct REGEX_INTERNAL_State *s; |
2493 | unsigned int i; | 2498 | unsigned int i; |
@@ -2516,23 +2521,27 @@ nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret, | |||
2516 | 2521 | ||
2517 | while (NULL != (currentstate = cls_stack.tail)) | 2522 | while (NULL != (currentstate = cls_stack.tail)) |
2518 | { | 2523 | { |
2519 | GNUNET_CONTAINER_MDLL_remove (ST, cls_stack.head, cls_stack.tail, | 2524 | GNUNET_CONTAINER_MDLL_remove (ST, |
2520 | currentstate); | 2525 | cls_stack.head, |
2526 | cls_stack.tail, | ||
2527 | currentstate); | ||
2521 | cls_stack.len--; | 2528 | cls_stack.len--; |
2522 | for (ctran = currentstate->transitions_head; NULL != ctran; | 2529 | for (ctran = currentstate->transitions_head; NULL != ctran; |
2523 | ctran = ctran->next) | 2530 | ctran = ctran->next) |
2524 | { | 2531 | { |
2525 | if (NULL == (clsstate = ctran->to_state)) | 2532 | if (NULL == (clsstate = ctran->to_state)) |
2526 | continue; | 2533 | continue; |
2527 | if (0 != clsstate->contained) | 2534 | if (0 != clsstate->contained) |
2528 | continue; | 2535 | continue; |
2529 | if (0 != nullstrcmp (label, ctran->label)) | 2536 | if (0 != nullstrcmp (label, ctran->label)) |
2530 | continue; | 2537 | continue; |
2531 | state_set_append (ret, clsstate); | 2538 | state_set_append (ret, clsstate); |
2532 | GNUNET_CONTAINER_MDLL_insert_tail (ST, cls_stack.head, cls_stack.tail, | 2539 | GNUNET_CONTAINER_MDLL_insert_tail (ST, |
2533 | clsstate); | 2540 | cls_stack.head, |
2534 | cls_stack.len++; | 2541 | cls_stack.tail, |
2535 | clsstate->contained = 1; | 2542 | clsstate); |
2543 | cls_stack.len++; | ||
2544 | clsstate->contained = 1; | ||
2536 | } | 2545 | } |
2537 | } | 2546 | } |
2538 | } | 2547 | } |
@@ -2540,7 +2549,9 @@ nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret, | |||
2540 | ret->states[i]->contained = 0; | 2549 | ret->states[i]->contained = 0; |
2541 | 2550 | ||
2542 | if (ret->off > 1) | 2551 | if (ret->off > 1) |
2543 | qsort (ret->states, ret->off, sizeof (struct REGEX_INTERNAL_State *), | 2552 | qsort (ret->states, |
2553 | ret->off, | ||
2554 | sizeof (struct REGEX_INTERNAL_State *), | ||
2544 | &state_compare); | 2555 | &state_compare); |
2545 | } | 2556 | } |
2546 | 2557 | ||
@@ -2598,8 +2609,9 @@ nfa_add_star_op (struct REGEX_INTERNAL_Context *ctx) | |||
2598 | 2609 | ||
2599 | if (NULL == a) | 2610 | if (NULL == a) |
2600 | { | 2611 | { |
2601 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2612 | GNUNET_log ( |
2602 | "nfa_add_star_op failed, because there was no element on the stack"); | 2613 | GNUNET_ERROR_TYPE_ERROR, |
2614 | "nfa_add_star_op failed, because there was no element on the stack"); | ||
2603 | return; | 2615 | return; |
2604 | } | 2616 | } |
2605 | 2617 | ||
@@ -2638,8 +2650,9 @@ nfa_add_plus_op (struct REGEX_INTERNAL_Context *ctx) | |||
2638 | 2650 | ||
2639 | if (NULL == a) | 2651 | if (NULL == a) |
2640 | { | 2652 | { |
2641 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2653 | GNUNET_log ( |
2642 | "nfa_add_plus_op failed, because there was no element on the stack"); | 2654 | GNUNET_ERROR_TYPE_ERROR, |
2655 | "nfa_add_plus_op failed, because there was no element on the stack"); | ||
2643 | return; | 2656 | return; |
2644 | } | 2657 | } |
2645 | 2658 | ||
@@ -2667,8 +2680,9 @@ nfa_add_question_op (struct REGEX_INTERNAL_Context *ctx) | |||
2667 | a = ctx->stack_tail; | 2680 | a = ctx->stack_tail; |
2668 | if (NULL == a) | 2681 | if (NULL == a) |
2669 | { | 2682 | { |
2670 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2683 | GNUNET_log ( |
2671 | "nfa_add_question_op failed, because there was no element on the stack"); | 2684 | GNUNET_ERROR_TYPE_ERROR, |
2685 | "nfa_add_question_op failed, because there was no element on the stack"); | ||
2672 | return; | 2686 | return; |
2673 | } | 2687 | } |
2674 | 2688 | ||
@@ -2803,7 +2817,7 @@ REGEX_INTERNAL_construct_nfa (const char *regex, const size_t len) | |||
2803 | { | 2817 | { |
2804 | int altcount; | 2818 | int altcount; |
2805 | int atomcount; | 2819 | int atomcount; |
2806 | } *p; | 2820 | } * p; |
2807 | 2821 | ||
2808 | if (NULL == regex || 0 == strlen (regex) || 0 == len) | 2822 | if (NULL == regex || 0 == strlen (regex) || 0 == len) |
2809 | { | 2823 | { |
@@ -2935,7 +2949,12 @@ REGEX_INTERNAL_construct_nfa (const char *regex, const size_t len) | |||
2935 | nfa->regex = GNUNET_strdup (regex); | 2949 | nfa->regex = GNUNET_strdup (regex); |
2936 | 2950 | ||
2937 | /* create depth-first numbering of the states for pretty printing */ | 2951 | /* create depth-first numbering of the states for pretty printing */ |
2938 | REGEX_INTERNAL_automaton_traverse (nfa, NULL, NULL, NULL, &number_states, NULL); | 2952 | REGEX_INTERNAL_automaton_traverse (nfa, |
2953 | NULL, | ||
2954 | NULL, | ||
2955 | NULL, | ||
2956 | &number_states, | ||
2957 | NULL); | ||
2939 | 2958 | ||
2940 | /* No multistriding added so far */ | 2959 | /* No multistriding added so far */ |
2941 | nfa->is_multistrided = GNUNET_NO; | 2960 | nfa->is_multistrided = GNUNET_NO; |
@@ -2997,7 +3016,7 @@ construct_dfa_states (struct REGEX_INTERNAL_Context *ctx, | |||
2997 | if (0 == state_set_compare (&state_iter->nfa_set, &nfa_set)) | 3016 | if (0 == state_set_compare (&state_iter->nfa_set, &nfa_set)) |
2998 | { | 3017 | { |
2999 | state_contains = state_iter; | 3018 | state_contains = state_iter; |
3000 | break; | 3019 | break; |
3001 | } | 3020 | } |
3002 | } | 3021 | } |
3003 | if (NULL == state_contains) | 3022 | if (NULL == state_contains) |
@@ -3034,7 +3053,8 @@ construct_dfa_states (struct REGEX_INTERNAL_Context *ctx, | |||
3034 | * @return DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy. | 3053 | * @return DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy. |
3035 | */ | 3054 | */ |
3036 | struct REGEX_INTERNAL_Automaton * | 3055 | struct REGEX_INTERNAL_Automaton * |
3037 | REGEX_INTERNAL_construct_dfa (const char *regex, const size_t len, | 3056 | REGEX_INTERNAL_construct_dfa (const char *regex, |
3057 | const size_t len, | ||
3038 | unsigned int max_path_len) | 3058 | unsigned int max_path_len) |
3039 | { | 3059 | { |
3040 | struct REGEX_INTERNAL_Context ctx; | 3060 | struct REGEX_INTERNAL_Context ctx; |
@@ -3130,8 +3150,7 @@ REGEX_INTERNAL_automaton_destroy (struct REGEX_INTERNAL_Automaton *a) | |||
3130 | * @return 0 if string matches, non-0 otherwise | 3150 | * @return 0 if string matches, non-0 otherwise |
3131 | */ | 3151 | */ |
3132 | static int | 3152 | static int |
3133 | evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, | 3153 | evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, const char *string) |
3134 | const char *string) | ||
3135 | { | 3154 | { |
3136 | const char *strp; | 3155 | const char *strp; |
3137 | struct REGEX_INTERNAL_State *s; | 3156 | struct REGEX_INTERNAL_State *s; |
@@ -3173,8 +3192,7 @@ evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, | |||
3173 | * @return 0 if string matches, non-0 otherwise | 3192 | * @return 0 if string matches, non-0 otherwise |
3174 | */ | 3193 | */ |
3175 | static int | 3194 | static int |
3176 | evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, | 3195 | evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, const char *string) |
3177 | const char *string) | ||
3178 | { | 3196 | { |
3179 | const char *strp; | 3197 | const char *strp; |
3180 | char str[2]; | 3198 | char str[2]; |
@@ -3215,7 +3233,7 @@ evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, | |||
3215 | for (i = 0; i < sset.off; i++) | 3233 | for (i = 0; i < sset.off; i++) |
3216 | { | 3234 | { |
3217 | s = sset.states[i]; | 3235 | s = sset.states[i]; |
3218 | if ( (NULL != s) && (s->accepting) ) | 3236 | if ((NULL != s) && (s->accepting)) |
3219 | { | 3237 | { |
3220 | result = 0; | 3238 | result = 0; |
3221 | break; | 3239 | break; |
@@ -3235,8 +3253,7 @@ evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, | |||
3235 | * @return 0 if string matches, non-0 otherwise | 3253 | * @return 0 if string matches, non-0 otherwise |
3236 | */ | 3254 | */ |
3237 | int | 3255 | int |
3238 | REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, | 3256 | REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, const char *string) |
3239 | const char *string) | ||
3240 | { | 3257 | { |
3241 | int result; | 3258 | int result; |
3242 | 3259 | ||
@@ -3321,12 +3338,11 @@ REGEX_INTERNAL_get_first_key (const char *input_string, | |||
3321 | { | 3338 | { |
3322 | size_t size; | 3339 | size_t size; |
3323 | 3340 | ||
3324 | size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len : | 3341 | size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len |
3325 | GNUNET_REGEX_INITIAL_BYTES; | 3342 | : GNUNET_REGEX_INITIAL_BYTES; |
3326 | if (NULL == input_string) | 3343 | if (NULL == input_string) |
3327 | { | 3344 | { |
3328 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3345 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n"); |
3329 | "Given input string was NULL!\n"); | ||
3330 | return 0; | 3346 | return 0; |
3331 | } | 3347 | } |
3332 | GNUNET_CRYPTO_hash (input_string, size, key); | 3348 | GNUNET_CRYPTO_hash (input_string, size, key); |
@@ -3367,21 +3383,16 @@ iterate_initial_edge (unsigned int min_len, | |||
3367 | else | 3383 | else |
3368 | cur_len = 0; | 3384 | cur_len = 0; |
3369 | 3385 | ||
3370 | if ( ( (cur_len >= min_len) || | 3386 | if (((cur_len >= min_len) || (GNUNET_YES == state->accepting)) && |
3371 | (GNUNET_YES == state->accepting) ) && | 3387 | (cur_len > 0) && (NULL != consumed_string)) |
3372 | (cur_len > 0) && | ||
3373 | (NULL != consumed_string) ) | ||
3374 | { | 3388 | { |
3375 | if (cur_len <= max_len) | 3389 | if (cur_len <= max_len) |
3376 | { | 3390 | { |
3377 | if ( (NULL != state->proof) && | 3391 | if ((NULL != state->proof) && |
3378 | (0 != strcmp (consumed_string, | 3392 | (0 != strcmp (consumed_string, state->proof))) |
3379 | state->proof)) ) | ||
3380 | { | 3393 | { |
3381 | (void) state_get_edges (state, edges); | 3394 | (void) state_get_edges (state, edges); |
3382 | GNUNET_CRYPTO_hash (consumed_string, | 3395 | GNUNET_CRYPTO_hash (consumed_string, strlen (consumed_string), &hash); |
3383 | strlen (consumed_string), | ||
3384 | &hash); | ||
3385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3386 | "Start state for string `%s' is %s\n", | 3397 | "Start state for string `%s' is %s\n", |
3387 | consumed_string, | 3398 | consumed_string, |
@@ -3390,13 +3401,12 @@ iterate_initial_edge (unsigned int min_len, | |||
3390 | &hash, | 3401 | &hash, |
3391 | consumed_string, | 3402 | consumed_string, |
3392 | state->accepting, | 3403 | state->accepting, |
3393 | num_edges, edges); | 3404 | num_edges, |
3405 | edges); | ||
3394 | } | 3406 | } |
3395 | 3407 | ||
3396 | if ( (GNUNET_YES == state->accepting) && | 3408 | if ((GNUNET_YES == state->accepting) && (cur_len > 1) && |
3397 | (cur_len > 1) && | 3409 | (state->transition_count < 1) && (cur_len < max_len)) |
3398 | (state->transition_count < 1) && | ||
3399 | (cur_len < max_len) ) | ||
3400 | { | 3410 | { |
3401 | /* Special case for regex consisting of just a string that is shorter than | 3411 | /* Special case for regex consisting of just a string that is shorter than |
3402 | * max_len */ | 3412 | * max_len */ |
@@ -3404,18 +3414,12 @@ iterate_initial_edge (unsigned int min_len, | |||
3404 | edge[0].destination = state->hash; | 3414 | edge[0].destination = state->hash; |
3405 | temp = GNUNET_strdup (consumed_string); | 3415 | temp = GNUNET_strdup (consumed_string); |
3406 | temp[cur_len - 1] = '\0'; | 3416 | temp[cur_len - 1] = '\0'; |
3407 | GNUNET_CRYPTO_hash (temp, | 3417 | GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash_new); |
3408 | cur_len - 1, | ||
3409 | &hash_new); | ||
3410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3411 | "Start state for short string `%s' is %s\n", | 3419 | "Start state for short string `%s' is %s\n", |
3412 | temp, | 3420 | temp, |
3413 | GNUNET_h2s (&hash_new)); | 3421 | GNUNET_h2s (&hash_new)); |
3414 | iterator (iterator_cls, | 3422 | iterator (iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge); |
3415 | &hash_new, | ||
3416 | temp, | ||
3417 | GNUNET_NO, 1, | ||
3418 | edge); | ||
3419 | GNUNET_free (temp); | 3423 | GNUNET_free (temp); |
3420 | } | 3424 | } |
3421 | } | 3425 | } |
@@ -3432,12 +3436,7 @@ iterate_initial_edge (unsigned int min_len, | |||
3432 | temp, | 3436 | temp, |
3433 | edge[0].label, | 3437 | edge[0].label, |
3434 | GNUNET_h2s (&hash_new)); | 3438 | GNUNET_h2s (&hash_new)); |
3435 | iterator (iterator_cls, | 3439 | iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edge); |
3436 | &hash, | ||
3437 | temp, | ||
3438 | GNUNET_NO, | ||
3439 | 1, | ||
3440 | edge); | ||
3441 | GNUNET_free (temp); | 3440 | GNUNET_free (temp); |
3442 | } | 3441 | } |
3443 | } | 3442 | } |
@@ -3446,22 +3445,16 @@ iterate_initial_edge (unsigned int min_len, | |||
3446 | { | 3445 | { |
3447 | for (t = state->transitions_head; NULL != t; t = t->next) | 3446 | for (t = state->transitions_head; NULL != t; t = t->next) |
3448 | { | 3447 | { |
3449 | if (NULL != strchr (t->label, | 3448 | if (NULL != strchr (t->label, (int) '.')) |
3450 | (int) '.')) | ||
3451 | { | 3449 | { |
3452 | /* Wildcards not allowed during starting states */ | 3450 | /* Wildcards not allowed during starting states */ |
3453 | GNUNET_break (0); | 3451 | GNUNET_break (0); |
3454 | continue; | 3452 | continue; |
3455 | } | 3453 | } |
3456 | if (NULL != consumed_string) | 3454 | if (NULL != consumed_string) |
3457 | GNUNET_asprintf (&temp, | 3455 | GNUNET_asprintf (&temp, "%s%s", consumed_string, t->label); |
3458 | "%s%s", | ||
3459 | consumed_string, | ||
3460 | t->label); | ||
3461 | else | 3456 | else |
3462 | GNUNET_asprintf (&temp, | 3457 | GNUNET_asprintf (&temp, "%s", t->label); |
3463 | "%s", | ||
3464 | t->label); | ||
3465 | iterate_initial_edge (min_len, | 3458 | iterate_initial_edge (min_len, |
3466 | max_len, | 3459 | max_len, |
3467 | temp, | 3460 | temp, |
@@ -3489,30 +3482,32 @@ REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a, | |||
3489 | { | 3482 | { |
3490 | struct REGEX_INTERNAL_State *s; | 3483 | struct REGEX_INTERNAL_State *s; |
3491 | 3484 | ||
3492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3485 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n"); |
3493 | "Iterating over starting edges\n"); | ||
3494 | iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES, | 3486 | iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES, |
3495 | GNUNET_REGEX_INITIAL_BYTES, | 3487 | GNUNET_REGEX_INITIAL_BYTES, |
3496 | NULL, a->start, | 3488 | NULL, |
3497 | iterator, iterator_cls); | 3489 | a->start, |
3498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3490 | iterator, |
3499 | "Iterating over DFA edges\n"); | 3491 | iterator_cls); |
3492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n"); | ||
3500 | for (s = a->states_head; NULL != s; s = s->next) | 3493 | for (s = a->states_head; NULL != s; s = s->next) |
3501 | { | 3494 | { |
3502 | struct REGEX_BLOCK_Edge edges[s->transition_count]; | 3495 | struct REGEX_BLOCK_Edge edges[s->transition_count]; |
3503 | unsigned int num_edges; | 3496 | unsigned int num_edges; |
3504 | 3497 | ||
3505 | num_edges = state_get_edges (s, edges); | 3498 | num_edges = state_get_edges (s, edges); |
3506 | if ( ( (NULL != s->proof) && | 3499 | if (((NULL != s->proof) && (0 < strlen (s->proof))) || s->accepting) |
3507 | (0 < strlen (s->proof)) ) || s->accepting) | ||
3508 | { | 3500 | { |
3509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3510 | "Creating DFA edges at `%s' under key %s\n", | 3502 | "Creating DFA edges at `%s' under key %s\n", |
3511 | s->proof, | 3503 | s->proof, |
3512 | GNUNET_h2s (&s->hash)); | 3504 | GNUNET_h2s (&s->hash)); |
3513 | iterator (iterator_cls, &s->hash, s->proof, | 3505 | iterator (iterator_cls, |
3506 | &s->hash, | ||
3507 | s->proof, | ||
3514 | s->accepting, | 3508 | s->accepting, |
3515 | num_edges, edges); | 3509 | num_edges, |
3510 | edges); | ||
3516 | } | 3511 | } |
3517 | s->marked = GNUNET_NO; | 3512 | s->marked = GNUNET_NO; |
3518 | } | 3513 | } |
@@ -3525,7 +3520,8 @@ REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a, | |||
3525 | * Contains the same info as the Regex Iterator parametes except the key, | 3520 | * Contains the same info as the Regex Iterator parametes except the key, |
3526 | * which comes directly from the HashMap iterator. | 3521 | * which comes directly from the HashMap iterator. |
3527 | */ | 3522 | */ |
3528 | struct temporal_state_store { | 3523 | struct temporal_state_store |
3524 | { | ||
3529 | int reachable; | 3525 | int reachable; |
3530 | char *proof; | 3526 | char *proof; |
3531 | int accepting; | 3527 | int accepting; |
@@ -3537,7 +3533,8 @@ struct temporal_state_store { | |||
3537 | /** | 3533 | /** |
3538 | * Store regex iterator and cls in one place to pass to the hashmap iterator. | 3534 | * Store regex iterator and cls in one place to pass to the hashmap iterator. |
3539 | */ | 3535 | */ |
3540 | struct client_iterator { | 3536 | struct client_iterator |
3537 | { | ||
3541 | REGEX_INTERNAL_KeyIterator iterator; | 3538 | REGEX_INTERNAL_KeyIterator iterator; |
3542 | void *iterator_cls; | 3539 | void *iterator_cls; |
3543 | }; | 3540 | }; |
@@ -3573,9 +3570,13 @@ store_all_states (void *cls, | |||
3573 | tmp->num_edges = num_edges; | 3570 | tmp->num_edges = num_edges; |
3574 | edges_size = sizeof (struct REGEX_BLOCK_Edge) * num_edges; | 3571 | edges_size = sizeof (struct REGEX_BLOCK_Edge) * num_edges; |
3575 | tmp->edges = GNUNET_malloc (edges_size); | 3572 | tmp->edges = GNUNET_malloc (edges_size); |
3576 | GNUNET_memcpy(tmp->edges, edges, edges_size); | 3573 | GNUNET_memcpy (tmp->edges, edges, edges_size); |
3577 | GNUNET_CONTAINER_multihashmap_put (hm, key, tmp, | 3574 | GNUNET_assert (GNUNET_YES == |
3578 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 3575 | GNUNET_CONTAINER_multihashmap_put ( |
3576 | hm, | ||
3577 | key, | ||
3578 | tmp, | ||
3579 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | ||
3579 | } | 3580 | } |
3580 | 3581 | ||
3581 | 3582 | ||
@@ -3601,8 +3602,8 @@ mark_as_reachable (struct temporal_state_store *state, | |||
3601 | state->reachable = GNUNET_YES; | 3602 | state->reachable = GNUNET_YES; |
3602 | for (i = 0; i < state->num_edges; i++) | 3603 | for (i = 0; i < state->num_edges; i++) |
3603 | { | 3604 | { |
3604 | child = GNUNET_CONTAINER_multihashmap_get (hm, | 3605 | child = |
3605 | &state->edges[i].destination); | 3606 | GNUNET_CONTAINER_multihashmap_get (hm, &state->edges[i].destination); |
3606 | if (NULL == child) | 3607 | if (NULL == child) |
3607 | { | 3608 | { |
3608 | GNUNET_break (0); | 3609 | GNUNET_break (0); |
@@ -3655,24 +3656,24 @@ reachability_iterator (void *cls, | |||
3655 | * #GNUNET_NO if not. | 3656 | * #GNUNET_NO if not. |
3656 | */ | 3657 | */ |
3657 | static int | 3658 | static int |
3658 | iterate_reachables (void *cls, | 3659 | iterate_reachables (void *cls, const struct GNUNET_HashCode *key, void *value) |
3659 | const struct GNUNET_HashCode *key, | ||
3660 | void *value) | ||
3661 | { | 3660 | { |
3662 | struct client_iterator *ci = cls; | 3661 | struct client_iterator *ci = cls; |
3663 | struct temporal_state_store *state = value; | 3662 | struct temporal_state_store *state = value; |
3664 | 3663 | ||
3665 | if (GNUNET_YES == state->reachable) | 3664 | if (GNUNET_YES == state->reachable) |
3666 | { | 3665 | { |
3667 | ci->iterator (ci->iterator_cls, key, | 3666 | ci->iterator (ci->iterator_cls, |
3668 | state->proof, state->accepting, | 3667 | key, |
3669 | state->num_edges, state->edges); | 3668 | state->proof, |
3669 | state->accepting, | ||
3670 | state->num_edges, | ||
3671 | state->edges); | ||
3670 | } | 3672 | } |
3671 | GNUNET_free (state->edges); | 3673 | GNUNET_free (state->edges); |
3672 | GNUNET_free (state->proof); | 3674 | GNUNET_free (state->proof); |
3673 | GNUNET_free (state); | 3675 | GNUNET_free (state); |
3674 | return GNUNET_YES; | 3676 | return GNUNET_YES; |
3675 | |||
3676 | } | 3677 | } |
3677 | 3678 | ||
3678 | /** | 3679 | /** |