Lines Matching refs:root
44 static int ber_dump_element(struct ber *ber, struct ber_element *root);
45 static void ber_dump_header(struct ber *ber, struct ber_element *root);
756 * root fully populated element tree
763 ber_write_elements(struct ber *ber, struct ber_element *root)
768 len = ber_calc_len(root);
784 if (ber_dump_element(ber, root) == -1)
799 * root if NULL, build up an element tree from what we receive on
810 struct ber_element *root = elm;
812 if (root == NULL) {
813 if ((root = ber_get_element(0)) == NULL)
817 DPRINTF("read ber elements, root %p\n", root);
819 if (ber_read_element(ber, root) == -1) {
820 /* Cleanup if root was allocated by us */
822 ber_free_elements(root);
826 return root;
830 ber_free_elements(struct ber_element *root)
832 if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE ||
833 root->be_encoding == BER_TYPE_SET))
834 ber_free_elements(root->be_sub);
835 if (root->be_next)
836 ber_free_elements(root->be_next);
837 if (root->be_free && (root->be_encoding == BER_TYPE_OCTETSTRING ||
838 root->be_encoding == BER_TYPE_BITSTRING ||
839 root->be_encoding == BER_TYPE_OBJECT))
840 free(root->be_val);
841 free(root);
845 ber_calc_len(struct ber_element *root)
852 if (root->be_sub && (root->be_encoding == BER_TYPE_SEQUENCE ||
853 root->be_encoding == BER_TYPE_SET))
854 root->be_len = ber_calc_len(root->be_sub);
857 if (root->be_type > BER_TYPE_SINGLE_MAX)
858 for (t = root->be_type; t > 0; t >>= 7)
860 if (root->be_len >= BER_TAG_MORE)
861 for (s = root->be_len; s > 0; s >>= 8)
865 if (root->be_next)
866 size += ber_calc_len(root->be_next);
869 if (root->be_type == BER_TYPE_EOC && root->be_len == 0)
872 return (root->be_len + size);
880 ber_dump_element(struct ber *ber, struct ber_element *root)
886 ber_dump_header(ber, root);
888 switch (root->be_encoding) {
892 l = (unsigned long long)root->be_numeric;
893 for (i = root->be_len; i > 0; i--) {
902 ber_write(ber, root->be_val, root->be_len);
909 if (root->be_sub && ber_dump_element(ber, root->be_sub) == -1)
914 if (root->be_next == NULL)
916 return ber_dump_element(ber, root->be_next);
920 ber_dump_header(struct ber *ber, struct ber_element *root)
928 if (root->be_type <= BER_TYPE_SINGLE_MAX) {
929 id = root->be_type | (root->be_class << BER_CLASS_SHIFT);
930 if (root->be_encoding == BER_TYPE_SEQUENCE ||
931 root->be_encoding == BER_TYPE_SET)
936 id = BER_TAG_MASK | (root->be_class << BER_CLASS_SHIFT);
937 if (root->be_encoding == BER_TYPE_SEQUENCE ||
938 root->be_encoding == BER_TYPE_SET)
943 for (t = 0, type = root->be_type; type > 0; type >>= 7)
953 if (root->be_len < BER_TAG_MORE) {
955 ber_putc(ber, root->be_len);
957 for (t = 0, size = root->be_len; size > 0; size >>= 8)