pack_search_request.c

filter: Statementstmt 66.2% 57 / 86 Branchbran 51.4% 36 / 70 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 59.6% 93 / 156 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« pack_add_request.c ↑ Summary pack_search_entry_response.c »
1 #include "pack.h"
2 #include "util.h"
3  
4 #define EHEAD "pack_search_filter: bad filter specification, usage: "
5  
6 static void
7 5 pack_search_filter(SV *dest, AV *filter) {
8 5 ▶ if (filter) {
Branch: 1 branch
BranchTrueFalseTotal
if (filter) { 5 0 5
9 SV **svp;
10 I32 type;
11 5 I32 len = av_len(filter) + 1;
12 5 svp = av_fetch(filter, 0, 0);
13 5 ▶ if (!svp || !*svp)
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !*svp) 5 0 5
if (!svp || !*svp) 0 5 5
14 0 croak(EHEAD "[$filter_type, @args]");
15 5 type = SvIV(*svp);
16 5 ▶ if (type == LDAP_FILTER_PRESENT) {
Branch: 1 branch
BranchTrueFalseTotal
if (type == LDAP_FILTER_PRESENT) { 2 3 5
17 2 SV **svp = av_fetch(filter, 1, 0);
18 2 ▶ if (!svp || !*svp)
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !*svp) 2 0 2
if (!svp || !*svp) 0 2 2
19 0 croak(EHEAD "[LDAP_FILTER_PRESENT, $attribute]");
20 2 pack_raw_utf8(dest, ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE, type, *svp);
21 }
22 else {
23 3 STRLEN offset = start_constructed(dest, ASN1_CONTEXT_SPECIFIC|ASN1_CONSTRUCTED, type);
24 3 switch(type) {
25 0 case LDAP_FILTER_NOT:
26 0 ▶ if (len != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (len != 2) 0 0 0
27 0 croak(EHEAD "[LDAP_FILTER_NOT, \\@child]");
28 /* fall through */
29 case LDAP_FILTER_AND:
30 case LDAP_FILTER_OR:
31 {
32 I32 i;
33 1 ▶ if (len < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (len < 2) 0 1 1
34 0 croak(EHEAD "[LDAP_FILTER_AND, \\@child1, ...]");
35 3 ▶ for (i = 1; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < len; i++) { 2 1 3
36 AV *child;
37 2 SV **svp = av_fetch(filter, i, 0);
38 2 ▶ if (!svp || !*svp || !SvROK(*svp) ||
Branch: 3 branches
BranchTrueFalseTotal
if (!svp || !*svp || !SvROK(*svp) || 2 0 2
if (!svp || !*svp || !SvROK(*svp) || 2 0 2
if (!svp || !*svp || !SvROK(*svp) || 2 0 2
39 2 ▶ !(child = (AV*)SvRV(*svp)) ||
Branch: 1 branch
BranchTrueFalseTotal
!(child = (AV*)SvRV(*svp)) || 2 0 2
40 2 ▶ (SvTYPE(child) != SVt_PVAV))
Branch: 1 branch
BranchTrueFalseTotal
(SvTYPE(child) != SVt_PVAV)) 0 2 2
41 0 croak(EHEAD "[LDAP_FILTER_AND, \\@child1, \\@child2, ...]");
42 2 pack_search_filter(dest, child);
43 }
44 1 break;
45 }
46 1 case LDAP_FILTER_EQ:
47 case LDAP_FILTER_GE:
48 case LDAP_FILTER_LE:
49 case LDAP_FILTER_APPROX:
50 {
51 1 SV **attr = av_fetch(filter, 1, 0);
52 1 SV **val = av_fetch(filter, 2, 0);
53 1 ▶ if (!attr || !*attr || !val || !*val)
Branch: 4 branches
BranchTrueFalseTotal
if (!attr || !*attr || !val || !*val) 1 0 1
if (!attr || !*attr || !val || !*val) 1 0 1
if (!attr || !*attr || !val || !*val) 1 0 1
if (!attr || !*attr || !val || !*val) 0 1 1
54 0 croak(EHEAD "[LDAP_FILTER_EQ, $attribute, $value]");
55 1 pack_string_utf8(dest, *attr);
56 1 pack_string_utf8(dest, *val);
57 1 break;
58 }
59 1 case LDAP_FILTER_SUBSTRINGS:
60 {
61 I32 i;
62 1 SV **attr = av_fetch(filter, 1, 0);
63 STRLEN offset;
64 1 ▶ if (!attr || !*attr || len < 4)
Branch: 3 branches
BranchTrueFalseTotal
if (!attr || !*attr || len < 4) 1 0 1
if (!attr || !*attr || len < 4) 1 0 1
if (!attr || !*attr || len < 4) 0 1 1
65 0 croak(EHEAD "[LDAP_FILTER_SUBSTRINGS, $attribute, $start, @middle, $end]");
66 1 pack_string_utf8(dest, *attr);
67 1 offset = start_sequence(dest);
68 3 ▶ for (i = 2; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < len; i++) { 2 1 3
69 int stype;
70 2 SV **str = av_fetch(filter, i, 0);
71 2 ▶ if (!str || !*str || !SvOK(*str) || !sv_len(*str)) continue;
Branch: 4 branches
BranchTrueFalseTotal
if (!str || !*str || !SvOK(*str) || !sv_len(*str)) continue; 2 0 2
if (!str || !*str || !SvOK(*str) || !sv_len(*str)) continue; 2 0 2
if (!str || !*str || !SvOK(*str) || !sv_len(*str)) continue; 1 1 2
if (!str || !*str || !SvOK(*str) || !sv_len(*str)) continue; 0 1 1
72 1 ▶ if (i == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (i == 2) 1 0 1
73 1 stype = 0;
74 0 ▶ else if (i == len - 1)
Branch: 1 branch
BranchTrueFalseTotal
else if (i == len - 1) 0 0 0
75 0 stype = 2;
76 else
77 0 stype = 1;
78 1 pack_raw_utf8(dest, ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE, stype, *str);
79 }
80 1 end_sequence(dest, offset);
81 1 break;
82 }
83 0 default:
84 0 croak("bad filter type %d", (int)type);
85 break;
86 }
87 3 end_constructed(dest, offset);
88 }
89 }
90 else
91 0 pack_raw_pvn(dest, ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE, LDAP_FILTER_PRESENT, "objectClass", 11);
92 5 }
93  
94 void
95 0 pack_search_request_args(SV *dest,
96 SV *base_dn,
97 enum ldap_scope scope,
98 enum ldap_deref_aliases deref,
99 U32 size_limit,
100 U32 time_limit,
101 U32 types_only,
102 AV *filter,
103 SV *attributes) {
104 0 STRLEN offset = start_constructed(dest, ASN1_APPLICATION|ASN1_CONSTRUCTED, LDAP_OP_SEARCH_REQUEST);
105 0 pack_string_utf8(dest, base_dn);
106 0 pack_enum(dest, scope);
107 0 pack_enum(dest, deref);
108 0 pack_int(dest, size_limit);
109 0 pack_int(dest, time_limit);
110 0 ▶ pack_bool(dest, (types_only ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
pack_bool(dest, (types_only ? 1 : 0)); 0 0 0
111 0 pack_search_filter(dest, filter);
112 0 pack_sequence_of_string_utf8(dest, attributes);
113 0 end_constructed(dest, offset);
114 0 }
115  
116 void
117 3 pack_search_request_ref(SV *dest, HV *hv) {
118 SV *sv;
119 AV *filter;
120 3 STRLEN offset = start_constructed(dest, ASN1_APPLICATION|ASN1_CONSTRUCTED, LDAP_OP_SEARCH_REQUEST);
121 3 pack_string_utf8(dest, hv_fetchs_def_no(hv, "base_dn"));
122 3 pack_enum(dest, SvIV(hv_fetchs_def_no(hv, "scope")));
123 3 pack_enum(dest, SvIV(hv_fetchs_def_no(hv, "deref_aliases")));
124 3 pack_int(dest, SvIV(hv_fetchs_def_no(hv, "size_limit")));
125 3 pack_int(dest, SvIV(hv_fetchs_def_no(hv, "time_limit")));
126 3 ▶ pack_bool(dest, SvTRUE(hv_fetchs_def_no(hv, "types_only")));
Branch: 1 branch
BranchTrueFalseTotal
pack_bool(dest, SvTRUE(hv_fetchs_def_no(hv, "types_only"))); 0 3 3
127 3 sv = hv_fetchs_def_undef(hv, "filter");
128 3 ▶ if (sv && SvOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvOK(sv)) { 3 0 3
if (sv && SvOK(sv)) { 3 0 3
129 3 ▶ if (!SvROK(sv) || !(filter = (AV*)SvRV(sv)) || (SvTYPE(filter) != SVt_PVAV))
Branch: 3 branches
BranchTrueFalseTotal
if (!SvROK(sv) || !(filter = (AV*)SvRV(sv)) || (SvTYPE(filter) != SVt_PVAV)) 3 0 3
if (!SvROK(sv) || !(filter = (AV*)SvRV(sv)) || (SvTYPE(filter) != SVt_PVAV)) 3 0 3
if (!SvROK(sv) || !(filter = (AV*)SvRV(sv)) || (SvTYPE(filter) != SVt_PVAV)) 0 3 3
130 0 croak("pack_search_request_ref: bad filter specification, usage "
131 "[$filter_type, @args]");
132 }
133 0 else filter = 0;
134 3 pack_search_filter(dest, filter);
135 3 pack_sequence_of_string_utf8(dest, hv_fetchs_def_undef(hv, "attributes"));
136 3 end_constructed(dest, offset);
137 3 }
« pack_add_request.c ↑ Summary pack_search_entry_response.c »