| 687 | | static ret_t |
|---|
| 688 | | substitute_token_guts (cherokee_buffer_t *buf1, cherokee_buffer_t *buf2, char *token, char token_len, char *replacement) |
|---|
| 689 | | { |
|---|
| 690 | | if (replacement == NULL) { |
|---|
| 691 | | return cherokee_buffer_substitute_string (buf1, buf2, token, token_len, "", 0); |
|---|
| 692 | | } |
|---|
| 693 | | |
|---|
| 694 | | return cherokee_buffer_substitute_string (buf1, buf2, token, token_len, replacement, strlen(replacement)); |
|---|
| 695 | | } |
|---|
| | 688 | /* Substitute all instances of (token) found in vbuf[*pidx_buf]; |
|---|
| | 689 | * if at least one (token) instance is found, then contents |
|---|
| | 690 | * resulting from substitution(s) are copied to the buffer |
|---|
| | 691 | * in next position of (vbuf) and (*pidx_buf) is updated to point |
|---|
| | 692 | * to current content buffer. |
|---|
| | 693 | * NOTE: only the first 2 positions in vbuf are used |
|---|
| | 694 | * (flip/flop algorithm). |
|---|
| | 695 | */ |
|---|
| | 696 | static ret_t |
|---|
| | 697 | substitute_vbuf_token ( |
|---|
| | 698 | cherokee_buffer_t **vbuf, size_t *pidx_buf, |
|---|
| | 699 | char *token, int token_len, |
|---|
| | 700 | char *replacement) |
|---|
| | 701 | { |
|---|
| | 702 | ret_t ret; |
|---|
| | 703 | |
|---|
| | 704 | if (replacement == NULL) |
|---|
| | 705 | replacement = ""; |
|---|
| | 706 | |
|---|
| | 707 | /* Substitute all instances of token in vbuf[*pidx_buf], |
|---|
| | 708 | * if everything goes well then result is copied in next index position |
|---|
| | 709 | * of vbuf[] and in this case we can increment the index position. |
|---|
| | 710 | * NOTE: *pidx_buf ^= 1 is faster than *pidx_buf = (*pidx_buf + 1) % 2 |
|---|
| | 711 | */ |
|---|
| | 712 | ret = cherokee_buffer_substitute_string ( |
|---|
| | 713 | vbuf[*pidx_buf], vbuf[*pidx_buf ^ 1], |
|---|
| | 714 | token, token_len, replacement, strlen(replacement)); |
|---|
| | 715 | if (ret == ret_ok) |
|---|
| | 716 | *pidx_buf ^= 1; |
|---|
| | 717 | |
|---|
| | 718 | return ret; |
|---|
| | 719 | } |
|---|
| | 720 | |
|---|
| | 721 | |
|---|
| | 722 | /* Useful macros to declare, to initialize and to handle an array of |
|---|
| | 723 | * two flip/flop temporary buffers (used for substitution purposes). |
|---|
| | 724 | */ |
|---|
| | 725 | |
|---|
| | 726 | #define VTMP_INIT_SUBST(thread, vtmp, buffer_pattern) \ |
|---|
| | 727 | vtmp[0] = THREAD_TMP_BUF1(thread); \ |
|---|
| | 728 | vtmp[1] = THREAD_TMP_BUF2(thread); \ |
|---|
| | 729 | cherokee_buffer_clean (vtmp[0]); \ |
|---|
| | 730 | cherokee_buffer_clean (vtmp[1]); \ |
|---|
| | 731 | cherokee_buffer_add_buffer (vtmp[0], (buffer_pattern)) |
|---|
| | 732 | |
|---|
| | 733 | #define VTMP_SUBSTITUTE_TOKEN(token, val) \ |
|---|
| | 734 | substitute_vbuf_token (vtmp, &idx_tmp, (token), sizeof(token)-1, (val)) |
|---|
| | 735 | |
|---|
| 708 | | size_t idx_tmp = 0; |
|---|
| 709 | | cherokee_buffer_t *vtmp[2]; |
|---|
| 710 | | |
|---|
| 711 | | #define substitute_token(idx, token, val) \ |
|---|
| 712 | | (idx = (substitute_token_guts(vtmp[idx], vtmp[(idx) ^ 1], token, sizeof(token)-1, (val)) == ret_ok ? (idx ^ 1) : (idx & 1))) |
|---|
| 713 | | |
|---|
| 714 | | /* Initialize array of tmp buffers |
|---|
| 715 | | */ |
|---|
| 716 | | vtmp[0] = THREAD_TMP_BUF1(thread); |
|---|
| 717 | | vtmp[1] = THREAD_TMP_BUF2(thread); |
|---|
| 718 | | |
|---|
| 719 | | /* Clear tmp buffers. |
|---|
| 720 | | */ |
|---|
| 721 | | cherokee_buffer_clean(vtmp[0]); |
|---|
| 722 | | cherokee_buffer_clean(vtmp[1]); |
|---|
| 723 | | |
|---|
| 724 | | /* Add entry text |
|---|
| 725 | | */ |
|---|
| 726 | | cherokee_buffer_add_buffer (vtmp[0], &props->entry); |
|---|
| 727 | | |
|---|
| | 749 | size_t idx_tmp = 0; |
|---|
| | 750 | |
|---|
| | 751 | /* Initialize temporary substitution buffers |
|---|
| | 752 | */ |
|---|
| | 753 | VTMP_INIT_SUBST (thread, vtmp, &props->entry); |
|---|
| | 754 | |
|---|
| 824 | | cherokee_thread_t *thread = HANDLER_THREAD(dhdl); |
|---|
| 825 | | cherokee_buffer_t *vtmp[2]; |
|---|
| 826 | | size_t idx_tmp = 0; |
|---|
| 827 | | |
|---|
| 828 | | /* Initialize array of tmp buffers |
|---|
| 829 | | */ |
|---|
| 830 | | vtmp[0] = THREAD_TMP_BUF1(thread); |
|---|
| 831 | | vtmp[1] = THREAD_TMP_BUF2(thread); |
|---|
| 832 | | |
|---|
| 833 | | /* Clear tmp buffers. |
|---|
| 834 | | */ |
|---|
| 835 | | cherokee_buffer_clean(vtmp[0]); |
|---|
| 836 | | cherokee_buffer_clean(vtmp[1]); |
|---|
| 837 | | |
|---|
| 838 | | /* Add entry text |
|---|
| 839 | | */ |
|---|
| 840 | | cherokee_buffer_add_buffer (vtmp[0], &props->entry); |
|---|
| | 852 | cherokee_thread_t *thread = HANDLER_THREAD(dhdl); |
|---|
| | 853 | size_t idx_tmp = 0; |
|---|
| | 854 | |
|---|
| | 855 | /* Initialize temporary substitution buffers |
|---|
| | 856 | */ |
|---|
| | 857 | VTMP_INIT_SUBST (thread, vtmp, &props->entry); |
|---|
| 848 | | substitute_token (idx_tmp, "%icon%", icon); |
|---|
| 849 | | substitute_token (idx_tmp, "%icon_alt%", "[DIR]"); |
|---|
| 850 | | |
|---|
| 851 | | substitute_token (idx_tmp, "%file_link%", "../"); |
|---|
| 852 | | substitute_token (idx_tmp, "%file_name%", "Parent Directory"); |
|---|
| 853 | | |
|---|
| 854 | | substitute_token (idx_tmp, "%date%", NULL); |
|---|
| 855 | | substitute_token (idx_tmp, "%size_unit%", NULL); |
|---|
| 856 | | substitute_token (idx_tmp, "%size%", "-"); |
|---|
| 857 | | substitute_token (idx_tmp, "%user%", NULL); |
|---|
| 858 | | substitute_token (idx_tmp, "%group%", NULL); |
|---|
| | 865 | VTMP_SUBSTITUTE_TOKEN ("%icon%", icon); |
|---|
| | 866 | VTMP_SUBSTITUTE_TOKEN ("%icon_alt%", "[DIR]"); |
|---|
| | 867 | |
|---|
| | 868 | VTMP_SUBSTITUTE_TOKEN ("%file_link%", "../"); |
|---|
| | 869 | VTMP_SUBSTITUTE_TOKEN ("%file_name%", "Parent Directory"); |
|---|
| | 870 | |
|---|
| | 871 | VTMP_SUBSTITUTE_TOKEN ("%date%", NULL); |
|---|
| | 872 | VTMP_SUBSTITUTE_TOKEN ("%size_unit%", NULL); |
|---|
| | 873 | VTMP_SUBSTITUTE_TOKEN ("%size%", "-"); |
|---|
| | 874 | VTMP_SUBSTITUTE_TOKEN ("%user%", NULL); |
|---|
| | 875 | VTMP_SUBSTITUTE_TOKEN ("%group%", NULL); |
|---|
| 869 | | render_header_footer_vbles (cherokee_handler_dirlist_t *dhdl, cherokee_buffer_t *buffer, cherokee_buffer_t *bufpattern) |
|---|
| 870 | | { |
|---|
| 871 | | cherokee_thread_t *thread = HANDLER_THREAD(dhdl); |
|---|
| 872 | | cherokee_buffer_t *vtmp[2]; |
|---|
| 873 | | size_t idx_tmp = 0; |
|---|
| 874 | | |
|---|
| 875 | | /* Initialize array of tmp buffers |
|---|
| 876 | | */ |
|---|
| 877 | | vtmp[0] = THREAD_TMP_BUF1(thread); |
|---|
| 878 | | vtmp[1] = THREAD_TMP_BUF2(thread); |
|---|
| 879 | | |
|---|
| 880 | | /* Clear tmp buffers. |
|---|
| 881 | | */ |
|---|
| 882 | | cherokee_buffer_clean(vtmp[0]); |
|---|
| 883 | | cherokee_buffer_clean(vtmp[1]); |
|---|
| 884 | | |
|---|
| 885 | | /* Add entry text |
|---|
| 886 | | */ |
|---|
| 887 | | cherokee_buffer_add_buffer (vtmp[0], bufpattern); |
|---|
| | 886 | render_header_footer_vbles (cherokee_handler_dirlist_t *dhdl, cherokee_buffer_t *buffer, cherokee_buffer_t *buf_pattern) |
|---|
| | 887 | { |
|---|
| | 888 | cherokee_buffer_t *vtmp[2]; |
|---|
| | 889 | cherokee_thread_t *thread = HANDLER_THREAD(dhdl); |
|---|
| | 890 | size_t idx_tmp = 0; |
|---|
| | 891 | |
|---|
| | 892 | /* Initialize temporary substitution buffers |
|---|
| | 893 | */ |
|---|
| | 894 | VTMP_INIT_SUBST (thread, vtmp, buf_pattern); |
|---|
| 903 | | substitute_token (idx_tmp, "%order_name%", |
|---|
| 904 | | (dhdl->sort == Name_Down) ? "N" : "n"); |
|---|
| 905 | | substitute_token (idx_tmp, "%order_size%", |
|---|
| 906 | | (dhdl->sort == Size_Down) ? "S" : "s"); |
|---|
| 907 | | substitute_token (idx_tmp, "%order_date%", |
|---|
| 908 | | (dhdl->sort == Date_Down) ? "D" : "d"); |
|---|
| | 910 | VTMP_SUBSTITUTE_TOKEN ("%order_name%", (dhdl->sort == Name_Down) ? "N" : "n"); |
|---|
| | 911 | VTMP_SUBSTITUTE_TOKEN ("%order_size%", (dhdl->sort == Size_Down) ? "S" : "s"); |
|---|
| | 912 | VTMP_SUBSTITUTE_TOKEN ("%order_date%", (dhdl->sort == Date_Down) ? "D" : "d"); |
|---|