! \brief return number of chars printed or 0 if space exceeded; assumes buffer size of at least MAX_BRANCH_PARAM_LEN */
| 2767 | assumes buffer size of at least MAX_BRANCH_PARAM_LEN |
| 2768 | */ |
| 2769 | int branch_builder( unsigned int hash_index, |
| 2770 | /* only either parameter useful */ |
| 2771 | unsigned int label, char * char_v, |
| 2772 | int branch, |
| 2773 | char *branch_str, int *len ) |
| 2774 | { |
| 2775 | |
| 2776 | char *begin; |
| 2777 | int size; |
| 2778 | |
| 2779 | /* hash id provided ... start with it */ |
| 2780 | size=MAX_BRANCH_PARAM_LEN; |
| 2781 | begin=branch_str; |
| 2782 | *len=0; |
| 2783 | |
| 2784 | memcpy(begin, MCOOKIE, MCOOKIE_LEN ); |
| 2785 | size-=MCOOKIE_LEN;begin+=MCOOKIE_LEN; |
| 2786 | |
| 2787 | if (int2reverse_hex( &begin, &size, hash_index)==-1) |
| 2788 | return 0; |
| 2789 | |
| 2790 | if (size) { |
| 2791 | *begin=BRANCH_SEPARATOR; |
| 2792 | begin++; size--; |
| 2793 | } else return 0; |
| 2794 | |
| 2795 | /* string with request's characteristic value ... use it ... */ |
| 2796 | if (char_v) { |
| 2797 | if (memcpy(begin,char_v,MD5_LEN)) { |
| 2798 | begin+=MD5_LEN; size-=MD5_LEN; |
| 2799 | } else return 0; |
| 2800 | } else { /* ... use the "label" value otherwise */ |
| 2801 | if (int2reverse_hex( &begin, &size, label )==-1) |
| 2802 | return 0; |
| 2803 | } |
| 2804 | |
| 2805 | if (size) { |
| 2806 | *begin=BRANCH_SEPARATOR; |
| 2807 | begin++; size--; |
| 2808 | } else return 0; |
| 2809 | |
| 2810 | if (int2reverse_hex( &begin, &size, branch)==-1) |
| 2811 | return 0; |
| 2812 | |
| 2813 | *len=MAX_BRANCH_PARAM_LEN-size; |
| 2814 | return size; |
| 2815 | |
| 2816 | } |
| 2817 | |
| 2818 | |
| 2819 | char* via_builder( unsigned int *len, |
no test coverage detected