scan_search_request.c

filter: Statementstmt 61.9% 78 / 126 Branchbran 41.9% 26 / 62 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 55.3% 104 / 188 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Gateway.xs ↑ Summary scan_raw.c »
1 #include "scan.h"
2 #include "enum2sv.h"
3 #include "enums.h"
4  
5 static void
6 10 scan_search_filter(const char** src, const char* max, SV *filter_ref) {
7 U8 type;
8 U32 filter_type;
9 10 AV *filter = newAV();
10 10 sv_upgrade(filter_ref, SVt_RV);
11 10 SvRV_set(filter_ref, (SV*)filter);
12 10 SvROK_on(filter_ref);
13  
14 10 scan_tag(src, max, &type, &filter_type);
15  
16 10 av_push(filter, newSVsv(ldap_filter2sv_noinc(filter_type)));
17  
18 10 ▶ if (type == (ASN1_CONTEXT_SPECIFIC | ASN1_PRIMITIVE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (type == (ASN1_CONTEXT_SPECIFIC | ASN1_PRIMITIVE)) { 4 6 10
19 SV *attr;
20 4 ▶ if (filter_type != LDAP_FILTER_PRESENT)
Branch: 1 branch
BranchTrueFalseTotal
if (filter_type != LDAP_FILTER_PRESENT) 0 4 4
21 0 croak("scan_search_filter: bad packet");
22 4 attr = newSV(0);
23 4 av_push(filter, attr);
24 4 scan_raw_utf8_notag(src, max, attr);
25 }
26 else {
27 STRLEN len;
28 6 ▶ if (type != (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED))
Branch: 1 branch
BranchTrueFalseTotal
if (type != (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED)) 0 6 6
29 0 croak("scan_search_filter: bad packet");
30 6 scan_length(src, max, &len);
31 6 max = *src + len;
32  
33 6 switch (filter_type) {
34 2 case LDAP_FILTER_AND:
35 case LDAP_FILTER_OR:
36 2 ▶ if (len) {
Branch: 1 branch
BranchTrueFalseTotal
if (len) { 2 0 2
37 6 ▶ while (*src < max) {
Branch: 1 branch
BranchTrueFalseTotal
while (*src < max) { 4 2 6
38 4 SV *child = newSV(0);
39 4 av_push(filter, child);
40 4 scan_search_filter(src, max, child);
41 }
42 }
43 2 break;
44 0 case LDAP_FILTER_NOT:
45 {
46 0 SV *child = newSV(0);
47 0 av_push(filter, child);
48 0 scan_search_filter(src, max, child);
49 0 break;
50 }
51 2 case LDAP_FILTER_EQ:
52 case LDAP_FILTER_GE:
53 case LDAP_FILTER_LE:
54 case LDAP_FILTER_APPROX:
55 {
56 2 SV *desc = newSV(0);
57 2 SV *value = newSV(0);
58 2 av_push(filter, desc);
59 2 av_push(filter, value);
60 2 scan_string_utf8(src, max, desc);
61 2 scan_string_utf8(src, max, value);
62 2 break;
63 }
64 2 case LDAP_FILTER_SUBSTRINGS:
65 {
66 2 SV *attr = newSV(0);
67 int last_state;
68 2 av_push(filter, attr);
69 2 scan_string_utf8(src, max, attr);
70
71 2 ▶ scan_sequence(src, max, &len);
Branch: 2 branches
BranchTrueFalseTotal
scan_sequence(src, max, &len); 2 0 2
scan_sequence(src, max, &len); 2 0 2
72
73 2 last_state = 0;
74 2 max = *src + len;
75 4 ▶ while (*src < max) {
Branch: 1 branch
BranchTrueFalseTotal
while (*src < max) { 2 2 4
76 U8 type;
77 U32 state;
78 2 SV *substr = newSV(0);
79 2 av_push(filter, substr);
80 2 scan_raw_utf8(src, max, &type, &state, substr);
81 2 ▶ if (state > 2 || state < last_state) goto error;
Branch: 2 branches
BranchTrueFalseTotal
if (state > 2 || state < last_state) goto error; 2 0 2
if (state > 2 || state < last_state) goto error; 0 2 2
82
83 2 switch (state) {
84 2 case 0:
85 2 state = 1;
86 2 break;
87 0 case 2:
88 0 state = 3;
89 0 case 1:
90 0 ▶ if (last_state == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (last_state == 0) { 0 0 0
91 0 av_pop(filter);
92 0 av_push(filter, &PL_sv_undef);
93 0 av_push(filter, substr);
94 }
95 0 break;
96 0 default:
97 0 goto error;
98 }
99 2 last_state = state;
100 }
101 2 ▶ if (last_state < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (last_state < 2) 2 0 2
102 2 av_push(filter, &PL_sv_undef);
103  
104 2 break;
105 0 error:
106 0 croak("scan_search_filter: bad substring chain");
107 break;
108 }
109 0 case LDAP_FILTER_EXT:
110 {
111 U8 type;
112 U32 tag;
113 0 HV *hv = newHV();
114 0 av_push(filter, newRV_noinc((SV*)hv));
115 0 scan_tag(src, max, &type, &tag);
116 0 ▶ if (tag == 1 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) {
Branch: 2 branches
BranchTrueFalseTotal
if (tag == 1 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) { 0 0 0
if (tag == 1 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) { 0 0 0
117 0 SV *sv = newSV(0);
118 0 hv_stores(hv, "matching_rule_id", sv);
119 0 scan_raw_utf8_notag(src, max, sv);
120 0 scan_tag(src, max, &type, &tag);
121 }
122 0 ▶ if (tag == 2 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) {
Branch: 2 branches
BranchTrueFalseTotal
if (tag == 2 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) { 0 0 0
if (tag == 2 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) { 0 0 0
123 0 SV *sv = newSV(0);
124 0 hv_stores(hv, "attribute", sv);
125 0 scan_raw_utf8_notag(src, max, sv);
126 0 scan_tag(src, max, &type, &tag);
127 }
128 0 ▶ if (tag == 3 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) {
Branch: 2 branches
BranchTrueFalseTotal
if (tag == 3 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) { 0 0 0
if (tag == 3 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) { 0 0 0
129 0 SV *sv = newSV(0);
130 0 hv_stores(hv, "value", sv);
131 0 scan_raw_utf8_notag(src, max, sv);
132 0 ▶ if (*src == max) break;
Branch: 1 branch
BranchTrueFalseTotal
if (*src == max) break; 0 0 0
133 0 scan_tag(src, max, &type, &tag);
134 0 ▶ if (tag == 4 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) {
Branch: 2 branches
BranchTrueFalseTotal
if (tag == 4 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) { 0 0 0
if (tag == 4 && type == ASN1_CONTEXT_SPECIFIC|ASN1_PRIMITIVE) { 0 0 0
135 I32 v;
136 0 scan_numeric_notag(src, max, &v);
137 0 ▶ if (v)
Branch: 1 branch
BranchTrueFalseTotal
if (v) 0 0 0
138 0 hv_stores(hv, "dn_attributes", newSVsv(&PL_sv_yes));
139 0 break;
140 }
141 }
142 0 croak("scan_search_filter: bad packet, invalid MatchingRuleAssertion element");
143 break;
144 }
145 0 default:
146 0 croak("scan_search_filter: unknown filter type %d", (int)filter_type);
147 }
148 }
149 10 }
150  
151 6 void scan_search_request(const char** src, const char* max, HV *out) {
152  
153 U32 e;
154 STRLEN len;
155 SV *filter;
156 SV *sv;
157
158 6 sv = newSV(0);
159 6 hv_stores(out, "base_dn", sv);
160 6 scan_string_utf8(src, max, sv);
161  
162 6 scan_enum(src, max, &e);
163 6 ▶ if (e > 2) croak("scan_search_request: bad value scope: %u", (unsigned int)e);
Branch: 1 branch
BranchTrueFalseTotal
if (e > 2) croak("scan_search_request: bad value scope: %u", (unsigned int)e); 0 6 6
164 6 hv_stores(out, "scope", newSVsv(ldap_scope2sv_noinc(e)));
165  
166 6 scan_enum(src, max, &e);
167 6 ▶ if (e > 3) croak("scan_search_request: bad value deref aliases: %u", (unsigned int)e);
Branch: 1 branch
BranchTrueFalseTotal
if (e > 3) croak("scan_search_request: bad value deref aliases: %u", (unsigned int)e); 0 6 6
168 6 hv_stores(out, "deref_aliases", newSVsv(ldap_deref_aliases2sv_noinc(e)));
169  
170 6 scan_unsigned_numeric(src, max, &e);
171 if (e < 0) croak("scan_search_request: bad value size limit: %u", (unsigned int)e);
172 6 ▶ if (e) hv_stores(out, "size_limit", newSVuv(e));
Branch: 1 branch
BranchTrueFalseTotal
if (e) hv_stores(out, "size_limit", newSVuv(e)); 2 4 6
173  
174 6 scan_int(src, max, &e);
175 if (e < 0) croak("scan_search_request: bad value time limit: %d", (unsigned int)e);
176 6 ▶ if (e) hv_stores(out, "time_limit", newSVuv(e));
Branch: 1 branch
BranchTrueFalseTotal
if (e) hv_stores(out, "time_limit", newSVuv(e)); 2 4 6
177  
178 6 scan_bool(src, max, &e);
179 6 ▶ if (e) hv_stores(out, "types_only", newSVsv(&PL_sv_yes));
Branch: 1 branch
BranchTrueFalseTotal
if (e) hv_stores(out, "types_only", newSVsv(&PL_sv_yes)); 0 6 6
180  
181 6 filter = newSV(0);
182 6 hv_stores(out, "filter", filter);
183 6 scan_search_filter(src, max, filter);
184  
185 /* now for the attributelist */
186 6 ▶ scan_sequence(src, max, &len);
Branch: 2 branches
BranchTrueFalseTotal
scan_sequence(src, max, &len); 6 0 6
scan_sequence(src, max, &len); 6 0 6
187 6 ▶ if (len > max - *src)
Branch: 1 branch
BranchTrueFalseTotal
if (len > max - *src) 0 6 6
188 0 croak("scan_search_request: packet too short");
189
190 6 ▶ if (len) {
Branch: 1 branch
BranchTrueFalseTotal
if (len) { 2 4 6
191 2 AV *attrs = newAV();
192 2 hv_stores(out, "attributes", newRV_noinc((SV*)attrs));
193 2 scan_array_of_string_utf8(src, *src + len, attrs);
194 }
195 6 }
« Gateway.xs ↑ Summary scan_raw.c »