1extern crate c2rust_bitfields;
2extern crate libc;
3extern crate core;
4extern "C" {
5 fn sdsnew(init: *const libc::c_char) -> sds;
6 fn sdsempty() -> sds;
7 fn sdsfree(s: sds);
8 fn sdscatfmt(s: sds, fmt: *const libc::c_char, _: ...) -> sds;
9 fn listCreate() -> *mut list;
10 fn listRelease(list: *mut list);
11 fn listAddNodeTail(list: *mut list, value: *mut libc::c_void) -> *mut list;
12 fn zmalloc(size: size_t) -> *mut libc::c_void;
13 fn zcalloc(size: size_t) -> *mut libc::c_void;
14 fn zfree(ptr: *mut libc::c_void);
15 fn parseReply(parser: *mut ReplyParser, p_ctx: *mut libc::c_void) -> libc::c_int;
16}
17pub type __uint8_t = libc::c_uchar;
18pub type __uint16_t = libc::c_ushort;
19pub type __uint32_t = libc::c_uint;
20pub type __uint64_t = libc::c_ulong;
21pub type size_t = libc::c_ulong;
22pub type uint8_t = __uint8_t;
23pub type uint16_t = __uint16_t;
24pub type uint32_t = __uint32_t;
25pub type uint64_t = __uint64_t;
26pub type sds = *mut libc::c_char;
27#[derive(Copy, Clone)]
28#[repr(C, packed)]
29pub struct sdshdr8 {
30 pub len: uint8_t,
31 pub alloc: uint8_t,
32 pub flags: libc::c_uchar,
33 pub buf: [libc::c_char; 0],
34}
35#[derive(Copy, Clone)]
36#[repr(C, packed)]
37pub struct sdshdr16 {
38 pub len: uint16_t,
39 pub alloc: uint16_t,
40 pub flags: libc::c_uchar,
41 pub buf: [libc::c_char; 0],
42}
43#[derive(Copy, Clone)]
44#[repr(C, packed)]
45pub struct sdshdr32 {
46 pub len: uint32_t,
47 pub alloc: uint32_t,
48 pub flags: libc::c_uchar,
49 pub buf: [libc::c_char; 0],
50}
51#[derive(Copy, Clone)]
52#[repr(C, packed)]
53pub struct sdshdr64 {
54 pub len: uint64_t,
55 pub alloc: uint64_t,
56 pub flags: libc::c_uchar,
57 pub buf: [libc::c_char; 0],
58}
59#[derive(Copy, Clone)]
60#[repr(C)]
61pub struct listNode {
62 pub prev: *mut listNode,
63 pub next: *mut listNode,
64 pub value: *mut libc::c_void,
65}
66#[derive(Copy, Clone)]
67#[repr(C)]
68pub struct list {
69 pub head: *mut listNode,
70 pub tail: *mut listNode,
71 pub dup: Option::<unsafe extern "C" fn(*mut libc::c_void) -> *mut libc::c_void>,
72 pub free: Option::<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
73 pub match_0: Option::<
74 unsafe extern "C" fn(*mut libc::c_void, *mut libc::c_void) -> libc::c_int,
75 >,
76 pub len: libc::c_ulong,
77}
78#[derive(Copy, Clone)]
79#[repr(C)]
80pub struct ReplyParser {
81 pub curr_location: *const libc::c_char,
82 pub callbacks: ReplyParserCallbacks,
83}
84#[derive(Copy, Clone)]
85#[repr(C)]
86pub struct ReplyParserCallbacks {
87 pub null_array_callback: Option::<
88 unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, size_t) -> (),
89 >,
90 pub null_bulk_string_callback: Option::<
91 unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, size_t) -> (),
92 >,
93 pub bulk_string_callback: Option::<
94 unsafe extern "C" fn(
95 *mut libc::c_void,
96 *const libc::c_char,
97 size_t,
98 *const libc::c_char,
99 size_t,
100 ) -> (),
101 >,
102 pub error_callback: Option::<
103 unsafe extern "C" fn(
104 *mut libc::c_void,
105 *const libc::c_char,
106 size_t,
107 *const libc::c_char,
108 size_t,
109 ) -> (),
110 >,
111 pub simple_str_callback: Option::<
112 unsafe extern "C" fn(
113 *mut libc::c_void,
114 *const libc::c_char,
115 size_t,
116 *const libc::c_char,
117 size_t,
118 ) -> (),
119 >,
120 pub long_callback: Option::<
121 unsafe extern "C" fn(
122 *mut libc::c_void,
123 libc::c_longlong,
124 *const libc::c_char,
125 size_t,
126 ) -> (),
127 >,
128 pub array_callback: Option::<
129 unsafe extern "C" fn(
130 *mut ReplyParser,
131 *mut libc::c_void,
132 size_t,
133 *const libc::c_char,
134 ) -> (),
135 >,
136 pub set_callback: Option::<
137 unsafe extern "C" fn(
138 *mut ReplyParser,
139 *mut libc::c_void,
140 size_t,
141 *const libc::c_char,
142 ) -> (),
143 >,
144 pub map_callback: Option::<
145 unsafe extern "C" fn(
146 *mut ReplyParser,
147 *mut libc::c_void,
148 size_t,
149 *const libc::c_char,
150 ) -> (),
151 >,
152 pub bool_callback: Option::<
153 unsafe extern "C" fn(
154 *mut libc::c_void,
155 libc::c_int,
156 *const libc::c_char,
157 size_t,
158 ) -> (),
159 >,
160 pub double_callback: Option::<
161 unsafe extern "C" fn(
162 *mut libc::c_void,
163 libc::c_double,
164 *const libc::c_char,
165 size_t,
166 ) -> (),
167 >,
168 pub big_number_callback: Option::<
169 unsafe extern "C" fn(
170 *mut libc::c_void,
171 *const libc::c_char,
172 size_t,
173 *const libc::c_char,
174 size_t,
175 ) -> (),
176 >,
177 pub verbatim_string_callback: Option::<
178 unsafe extern "C" fn(
179 *mut libc::c_void,
180 *const libc::c_char,
181 *const libc::c_char,
182 size_t,
183 *const libc::c_char,
184 size_t,
185 ) -> (),
186 >,
187 pub attribute_callback: Option::<
188 unsafe extern "C" fn(
189 *mut ReplyParser,
190 *mut libc::c_void,
191 size_t,
192 *const libc::c_char,
193 ) -> (),
194 >,
195 pub null_callback: Option::<
196 unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, size_t) -> (),
197 >,
198 pub error: Option::<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
199}
200#[derive(Copy, Clone)]
201#[repr(C)]
202pub struct CallReply {
203 pub private_data: *mut libc::c_void,
204 pub original_proto: sds,
205 pub proto: *const libc::c_char,
206 pub proto_len: size_t,
207 pub type_0: libc::c_int,
208 pub flags: libc::c_int,
209 pub len: size_t,
210 pub val: C2RustUnnamed,
211 pub deferred_error_list: *mut list,
212 pub attribute: *mut CallReply,
213}
214#[derive(Copy, Clone)]
215#[repr(C)]
216pub union C2RustUnnamed {
217 pub str_0: *const libc::c_char,
218 pub verbatim_str: C2RustUnnamed_0,
219 pub ll: libc::c_longlong,
220 pub d: libc::c_double,
221 pub array: *mut CallReply,
222}
223#[derive(Copy, Clone)]
224#[repr(C)]
225pub struct C2RustUnnamed_0 {
226 pub str_0: *const libc::c_char,
227 pub format: *const libc::c_char,
228}
229#[inline]
230unsafe extern "C" fn sdslen(s: sds) -> size_t {
231 let mut flags: libc::c_uchar = *s.offset(-(1 as libc::c_int) as isize)
232 as libc::c_uchar;
233 match flags as libc::c_int & 7 as libc::c_int {
234 0 => return (flags as libc::c_int >> 3 as libc::c_int) as size_t,
235 1 => {
236 return (*(s
237 .offset(-(core::mem::size_of::<sdshdr8>() as libc::c_ulong as isize))
238 as *mut sdshdr8))
239 .len as size_t;
240 }
241 2 => {
242 return (*(s
243 .offset(-(core::mem::size_of::<sdshdr16>() as libc::c_ulong as isize))
244 as *mut sdshdr16))
245 .len as size_t;
246 }
247 3 => {
248 return (*(s
249 .offset(-(core::mem::size_of::<sdshdr32>() as libc::c_ulong as isize))
250 as *mut sdshdr32))
251 .len as size_t;
252 }
253 4 => {
254 return (*(s
255 .offset(-(core::mem::size_of::<sdshdr64>() as libc::c_ulong as isize))
256 as *mut sdshdr64))
257 .len;
258 }
259 _ => {}
260 }
261 return 0 as libc::c_int as size_t;
262}
263unsafe extern "C" fn callReplySetSharedData(
264 mut rep: *mut CallReply,
265 mut type_0: libc::c_int,
266 mut proto: *const libc::c_char,
267 mut proto_len: size_t,
268 mut extra_flags: libc::c_int,
269) {
270 (*rep).type_0 = type_0;
271 (*rep).proto = proto;
272 (*rep).proto_len = proto_len;
273 (*rep).flags |= extra_flags;
274}
275unsafe extern "C" fn callReplyNull(
276 mut ctx: *mut libc::c_void,
277 mut proto: *const libc::c_char,
278 mut proto_len: size_t,
279) {
280 let mut rep: *mut CallReply = ctx as *mut CallReply;
281 callReplySetSharedData(
282 rep,
283 4 as libc::c_int,
284 proto,
285 proto_len,
286 (1 as libc::c_int) << 2 as libc::c_int,
287 );
288}
289unsafe extern "C" fn callReplyNullBulkString(
290 mut ctx: *mut libc::c_void,
291 mut proto: *const libc::c_char,
292 mut proto_len: size_t,
293) {
294 let mut rep: *mut CallReply = ctx as *mut CallReply;
295 callReplySetSharedData(rep, 4 as libc::c_int, proto, proto_len, 0 as libc::c_int);
296}
297unsafe extern "C" fn callReplyNullArray(
298 mut ctx: *mut libc::c_void,
299 mut proto: *const libc::c_char,
300 mut proto_len: size_t,
301) {
302 let mut rep: *mut CallReply = ctx as *mut CallReply;
303 callReplySetSharedData(rep, 4 as libc::c_int, proto, proto_len, 0 as libc::c_int);
304}
305unsafe extern "C" fn callReplyBulkString(
306 mut ctx: *mut libc::c_void,
307 mut str: *const libc::c_char,
308 mut len: size_t,
309 mut proto: *const libc::c_char,
310 mut proto_len: size_t,
311) {
312 let mut rep: *mut CallReply = ctx as *mut CallReply;
313 callReplySetSharedData(rep, 0 as libc::c_int, proto, proto_len, 0 as libc::c_int);
314 (*rep).len = len;
315 (*rep).val.str_0 = str;
316}
317unsafe extern "C" fn callReplyError(
318 mut ctx: *mut libc::c_void,
319 mut str: *const libc::c_char,
320 mut len: size_t,
321 mut proto: *const libc::c_char,
322 mut proto_len: size_t,
323) {
324 let mut rep: *mut CallReply = ctx as *mut CallReply;
325 callReplySetSharedData(rep, 1 as libc::c_int, proto, proto_len, 0 as libc::c_int);
326 (*rep).len = len;
327 (*rep).val.str_0 = str;
328}
329unsafe extern "C" fn callReplySimpleStr(
330 mut ctx: *mut libc::c_void,
331 mut str: *const libc::c_char,
332 mut len: size_t,
333 mut proto: *const libc::c_char,
334 mut proto_len: size_t,
335) {
336 let mut rep: *mut CallReply = ctx as *mut CallReply;
337 callReplySetSharedData(rep, 0 as libc::c_int, proto, proto_len, 0 as libc::c_int);
338 (*rep).len = len;
339 (*rep).val.str_0 = str;
340}
341unsafe extern "C" fn callReplyLong(
342 mut ctx: *mut libc::c_void,
343 mut val: libc::c_longlong,
344 mut proto: *const libc::c_char,
345 mut proto_len: size_t,
346) {
347 let mut rep: *mut CallReply = ctx as *mut CallReply;
348 callReplySetSharedData(rep, 2 as libc::c_int, proto, proto_len, 0 as libc::c_int);
349 (*rep).val.ll = val;
350}
351unsafe extern "C" fn callReplyDouble(
352 mut ctx: *mut libc::c_void,
353 mut val: libc::c_double,
354 mut proto: *const libc::c_char,
355 mut proto_len: size_t,
356) {
357 let mut rep: *mut CallReply = ctx as *mut CallReply;
358 callReplySetSharedData(
359 rep,
360 8 as libc::c_int,
361 proto,
362 proto_len,
363 (1 as libc::c_int) << 2 as libc::c_int,
364 );
365 (*rep).val.d = val;
366}
367unsafe extern "C" fn callReplyVerbatimString(
368 mut ctx: *mut libc::c_void,
369 mut format: *const libc::c_char,
370 mut str: *const libc::c_char,
371 mut len: size_t,
372 mut proto: *const libc::c_char,
373 mut proto_len: size_t,
374) {
375 let mut rep: *mut CallReply = ctx as *mut CallReply;
376 callReplySetSharedData(
377 rep,
378 10 as libc::c_int,
379 proto,
380 proto_len,
381 (1 as libc::c_int) << 2 as libc::c_int,
382 );
383 (*rep).len = len;
384 (*rep).val.verbatim_str.str_0 = str;
385 (*rep).val.verbatim_str.format = format;
386}
387unsafe extern "C" fn callReplyBigNumber(
388 mut ctx: *mut libc::c_void,
389 mut str: *const libc::c_char,
390 mut len: size_t,
391 mut proto: *const libc::c_char,
392 mut proto_len: size_t,
393) {
394 let mut rep: *mut CallReply = ctx as *mut CallReply;
395 callReplySetSharedData(
396 rep,
397 9 as libc::c_int,
398 proto,
399 proto_len,
400 (1 as libc::c_int) << 2 as libc::c_int,
401 );
402 (*rep).len = len;
403 (*rep).val.str_0 = str;
404}
405unsafe extern "C" fn callReplyBool(
406 mut ctx: *mut libc::c_void,
407 mut val: libc::c_int,
408 mut proto: *const libc::c_char,
409 mut proto_len: size_t,
410) {
411 let mut rep: *mut CallReply = ctx as *mut CallReply;
412 callReplySetSharedData(
413 rep,
414 7 as libc::c_int,
415 proto,
416 proto_len,
417 (1 as libc::c_int) << 2 as libc::c_int,
418 );
419 (*rep).val.ll = val as libc::c_longlong;
420}
421unsafe extern "C" fn callReplyParseCollection(
422 mut parser: *mut ReplyParser,
423 mut rep: *mut CallReply,
424 mut len: size_t,
425 mut proto: *const libc::c_char,
426 mut elements_per_entry: size_t,
427) {
428 (*rep).len = len;
429 (*rep)
430 .val
431 .array = zcalloc(
432 elements_per_entry
433 .wrapping_mul(len)
434 .wrapping_mul(core::mem::size_of::<CallReply>() as libc::c_ulong),
435 ) as *mut CallReply;
436 let mut i: size_t = 0 as libc::c_int as size_t;
437 while i < len.wrapping_mul(elements_per_entry) {
438 let mut j: size_t = 0 as libc::c_int as size_t;
439 while j < elements_per_entry {
440 let ref mut fresh0 = (*((*rep).val.array).offset(i.wrapping_add(j) as isize))
441 .private_data;
442 *fresh0 = (*rep).private_data;
443 parseReply(
444 parser,
445 ((*rep).val.array).offset(i as isize).offset(j as isize)
446 as *mut libc::c_void,
447 );
448 (*((*rep).val.array).offset(i.wrapping_add(j) as isize)).flags
449 |= (1 as libc::c_int) << 1 as libc::c_int;
450 if (*((*rep).val.array).offset(i.wrapping_add(j) as isize)).flags
451 & (1 as libc::c_int) << 2 as libc::c_int != 0
452 {
453 (*rep).flags |= (1 as libc::c_int) << 2 as libc::c_int;
454 }
455 j = j.wrapping_add(1);
456 }
457 i = (i as libc::c_ulong).wrapping_add(elements_per_entry) as size_t as size_t;
458 }
459 (*rep).proto = proto;
460 (*rep)
461 .proto_len = ((*parser).curr_location).offset_from(proto) as libc::c_long
462 as size_t;
463}
464unsafe extern "C" fn callReplyAttribute(
465 mut parser: *mut ReplyParser,
466 mut ctx: *mut libc::c_void,
467 mut len: size_t,
468 mut proto: *const libc::c_char,
469) {
470 let mut rep: *mut CallReply = ctx as *mut CallReply;
471 (*rep)
472 .attribute = zcalloc(core::mem::size_of::<CallReply>() as libc::c_ulong)
473 as *mut CallReply;
474 (*(*rep).attribute).len = len;
475 (*(*rep).attribute).type_0 = 11 as libc::c_int;
476 callReplyParseCollection(
477 parser,
478 (*rep).attribute,
479 len,
480 proto,
481 2 as libc::c_int as size_t,
482 );
483 (*(*rep).attribute).flags
484 |= (1 as libc::c_int) << 1 as libc::c_int
485 | (1 as libc::c_int) << 2 as libc::c_int;
486 (*(*rep).attribute).private_data = (*rep).private_data;
487 parseReply(parser, rep as *mut libc::c_void);
488 (*rep).proto = proto;
489 (*rep)
490 .proto_len = ((*parser).curr_location).offset_from(proto) as libc::c_long
491 as size_t;
492 (*rep).flags |= (1 as libc::c_int) << 2 as libc::c_int;
493}
494unsafe extern "C" fn callReplyArray(
495 mut parser: *mut ReplyParser,
496 mut ctx: *mut libc::c_void,
497 mut len: size_t,
498 mut proto: *const libc::c_char,
499) {
500 let mut rep: *mut CallReply = ctx as *mut CallReply;
501 (*rep).type_0 = 3 as libc::c_int;
502 callReplyParseCollection(parser, rep, len, proto, 1 as libc::c_int as size_t);
503}
504unsafe extern "C" fn callReplySet(
505 mut parser: *mut ReplyParser,
506 mut ctx: *mut libc::c_void,
507 mut len: size_t,
508 mut proto: *const libc::c_char,
509) {
510 let mut rep: *mut CallReply = ctx as *mut CallReply;
511 (*rep).type_0 = 6 as libc::c_int;
512 callReplyParseCollection(parser, rep, len, proto, 1 as libc::c_int as size_t);
513 (*rep).flags |= (1 as libc::c_int) << 2 as libc::c_int;
514}
515unsafe extern "C" fn callReplyMap(
516 mut parser: *mut ReplyParser,
517 mut ctx: *mut libc::c_void,
518 mut len: size_t,
519 mut proto: *const libc::c_char,
520) {
521 let mut rep: *mut CallReply = ctx as *mut CallReply;
522 (*rep).type_0 = 5 as libc::c_int;
523 callReplyParseCollection(parser, rep, len, proto, 2 as libc::c_int as size_t);
524 (*rep).flags |= (1 as libc::c_int) << 2 as libc::c_int;
525}
526unsafe extern "C" fn callReplyParseError(mut ctx: *mut libc::c_void) {
527 let mut rep: *mut CallReply = ctx as *mut CallReply;
528 (*rep).type_0 = -(1 as libc::c_int);
529}
530unsafe extern "C" fn freeCallReplyInternal(mut rep: *mut CallReply) {
531 if (*rep).type_0 == 3 as libc::c_int || (*rep).type_0 == 6 as libc::c_int {
532 let mut i: size_t = 0 as libc::c_int as size_t;
533 while i < (*rep).len {
534 freeCallReplyInternal(((*rep).val.array).offset(i as isize));
535 i = i.wrapping_add(1);
536 }
537 zfree((*rep).val.array as *mut libc::c_void);
538 }
539 if (*rep).type_0 == 5 as libc::c_int || (*rep).type_0 == 11 as libc::c_int {
540 let mut i_0: size_t = 0 as libc::c_int as size_t;
541 while i_0 < (*rep).len {
542 freeCallReplyInternal(
543 ((*rep).val.array)
544 .offset(i_0.wrapping_mul(2 as libc::c_int as libc::c_ulong) as isize),
545 );
546 freeCallReplyInternal(
547 ((*rep).val.array)
548 .offset(i_0.wrapping_mul(2 as libc::c_int as libc::c_ulong) as isize)
549 .offset(1 as libc::c_int as isize),
550 );
551 i_0 = i_0.wrapping_add(1);
552 }
553 zfree((*rep).val.array as *mut libc::c_void);
554 }
555 if !((*rep).attribute).is_null() {
556 freeCallReplyInternal((*rep).attribute);
557 zfree((*rep).attribute as *mut libc::c_void);
558 }
559}
560#[no_mangle]
561pub unsafe extern "C" fn freeCallReply(mut rep: *mut CallReply) {
562 if (*rep).flags & (1 as libc::c_int) << 0 as libc::c_int == 0 {
563 return;
564 }
565 if (*rep).flags & (1 as libc::c_int) << 1 as libc::c_int != 0 {
566 freeCallReplyInternal(rep);
567 }
568 sdsfree((*rep).original_proto);
569 if !((*rep).deferred_error_list).is_null() {
570 listRelease((*rep).deferred_error_list);
571 }
572 zfree(rep as *mut libc::c_void);
573}
574static mut DefaultParserCallbacks: ReplyParserCallbacks = unsafe {
575 {
576 let mut init = ReplyParserCallbacks {
577 null_array_callback: Some(
578 callReplyNullArray
579 as unsafe extern "C" fn(
580 *mut libc::c_void,
581 *const libc::c_char,
582 size_t,
583 ) -> (),
584 ),
585 null_bulk_string_callback: Some(
586 callReplyNullBulkString
587 as unsafe extern "C" fn(
588 *mut libc::c_void,
589 *const libc::c_char,
590 size_t,
591 ) -> (),
592 ),
593 bulk_string_callback: Some(
594 callReplyBulkString
595 as unsafe extern "C" fn(
596 *mut libc::c_void,
597 *const libc::c_char,
598 size_t,
599 *const libc::c_char,
600 size_t,
601 ) -> (),
602 ),
603 error_callback: Some(
604 callReplyError
605 as unsafe extern "C" fn(
606 *mut libc::c_void,
607 *const libc::c_char,
608 size_t,
609 *const libc::c_char,
610 size_t,
611 ) -> (),
612 ),
613 simple_str_callback: Some(
614 callReplySimpleStr
615 as unsafe extern "C" fn(
616 *mut libc::c_void,
617 *const libc::c_char,
618 size_t,
619 *const libc::c_char,
620 size_t,
621 ) -> (),
622 ),
623 long_callback: Some(
624 callReplyLong
625 as unsafe extern "C" fn(
626 *mut libc::c_void,
627 libc::c_longlong,
628 *const libc::c_char,
629 size_t,
630 ) -> (),
631 ),
632 array_callback: Some(
633 callReplyArray
634 as unsafe extern "C" fn(
635 *mut ReplyParser,
636 *mut libc::c_void,
637 size_t,
638 *const libc::c_char,
639 ) -> (),
640 ),
641 set_callback: Some(
642 callReplySet
643 as unsafe extern "C" fn(
644 *mut ReplyParser,
645 *mut libc::c_void,
646 size_t,
647 *const libc::c_char,
648 ) -> (),
649 ),
650 map_callback: Some(
651 callReplyMap
652 as unsafe extern "C" fn(
653 *mut ReplyParser,
654 *mut libc::c_void,
655 size_t,
656 *const libc::c_char,
657 ) -> (),
658 ),
659 bool_callback: Some(
660 callReplyBool
661 as unsafe extern "C" fn(
662 *mut libc::c_void,
663 libc::c_int,
664 *const libc::c_char,
665 size_t,
666 ) -> (),
667 ),
668 double_callback: Some(
669 callReplyDouble
670 as unsafe extern "C" fn(
671 *mut libc::c_void,
672 libc::c_double,
673 *const libc::c_char,
674 size_t,
675 ) -> (),
676 ),
677 big_number_callback: Some(
678 callReplyBigNumber
679 as unsafe extern "C" fn(
680 *mut libc::c_void,
681 *const libc::c_char,
682 size_t,
683 *const libc::c_char,
684 size_t,
685 ) -> (),
686 ),
687 verbatim_string_callback: Some(
688 callReplyVerbatimString
689 as unsafe extern "C" fn(
690 *mut libc::c_void,
691 *const libc::c_char,
692 *const libc::c_char,
693 size_t,
694 *const libc::c_char,
695 size_t,
696 ) -> (),
697 ),
698 attribute_callback: Some(
699 callReplyAttribute
700 as unsafe extern "C" fn(
701 *mut ReplyParser,
702 *mut libc::c_void,
703 size_t,
704 *const libc::c_char,
705 ) -> (),
706 ),
707 null_callback: Some(
708 callReplyNull
709 as unsafe extern "C" fn(
710 *mut libc::c_void,
711 *const libc::c_char,
712 size_t,
713 ) -> (),
714 ),
715 error: Some(
716 callReplyParseError as unsafe extern "C" fn(*mut libc::c_void) -> (),
717 ),
718 };
719 init
720 }
721};
722unsafe extern "C" fn callReplyParse(mut rep: *mut CallReply) {
723 if (*rep).flags & (1 as libc::c_int) << 1 as libc::c_int != 0 {
724 return;
725 }
726 let mut parser: ReplyParser = {
727 let mut init = ReplyParser {
728 curr_location: (*rep).proto,
729 callbacks: DefaultParserCallbacks,
730 };
731 init
732 };
733 parseReply(&mut parser, rep as *mut libc::c_void);
734 (*rep).flags |= (1 as libc::c_int) << 1 as libc::c_int;
735}
736#[no_mangle]
737pub unsafe extern "C" fn callReplyType(mut rep: *mut CallReply) -> libc::c_int {
738 if rep.is_null() {
739 return -(1 as libc::c_int);
740 }
741 callReplyParse(rep);
742 return (*rep).type_0;
743}
744#[no_mangle]
745pub unsafe extern "C" fn callReplyGetString(
746 mut rep: *mut CallReply,
747 mut len: *mut size_t,
748) -> *const libc::c_char {
749 callReplyParse(rep);
750 if (*rep).type_0 != 0 as libc::c_int && (*rep).type_0 != 1 as libc::c_int {
751 return 0 as *const libc::c_char;
752 }
753 if !len.is_null() {
754 *len = (*rep).len;
755 }
756 return (*rep).val.str_0;
757}
758#[no_mangle]
759pub unsafe extern "C" fn callReplyGetLongLong(
760 mut rep: *mut CallReply,
761) -> libc::c_longlong {
762 callReplyParse(rep);
763 if (*rep).type_0 != 2 as libc::c_int {
764 return -(9223372036854775807 as libc::c_longlong) - 1 as libc::c_longlong;
765 }
766 return (*rep).val.ll;
767}
768#[no_mangle]
769pub unsafe extern "C" fn callReplyGetDouble(mut rep: *mut CallReply) -> libc::c_double {
770 callReplyParse(rep);
771 if (*rep).type_0 != 8 as libc::c_int {
772 return (-(9223372036854775807 as libc::c_longlong) - 1 as libc::c_longlong)
773 as libc::c_double;
774 }
775 return (*rep).val.d;
776}
777#[no_mangle]
778pub unsafe extern "C" fn callReplyGetBool(mut rep: *mut CallReply) -> libc::c_int {
779 callReplyParse(rep);
780 if (*rep).type_0 != 7 as libc::c_int {
781 return -(2147483647 as libc::c_int) - 1 as libc::c_int;
782 }
783 return (*rep).val.ll as libc::c_int;
784}
785#[no_mangle]
786pub unsafe extern "C" fn callReplyGetLen(mut rep: *mut CallReply) -> size_t {
787 callReplyParse(rep);
788 match (*rep).type_0 {
789 0 | 1 | 3 | 6 | 5 | 11 => return (*rep).len,
790 _ => return 0 as libc::c_int as size_t,
791 };
792}
793unsafe extern "C" fn callReplyGetCollectionElement(
794 mut rep: *mut CallReply,
795 mut idx: size_t,
796 mut elements_per_entry: libc::c_int,
797) -> *mut CallReply {
798 if idx >= ((*rep).len).wrapping_mul(elements_per_entry as libc::c_ulong) {
799 return 0 as *mut CallReply;
800 }
801 return ((*rep).val.array).offset(idx as isize);
802}
803#[no_mangle]
804pub unsafe extern "C" fn callReplyGetArrayElement(
805 mut rep: *mut CallReply,
806 mut idx: size_t,
807) -> *mut CallReply {
808 callReplyParse(rep);
809 if (*rep).type_0 != 3 as libc::c_int {
810 return 0 as *mut CallReply;
811 }
812 return callReplyGetCollectionElement(rep, idx, 1 as libc::c_int);
813}
814#[no_mangle]
815pub unsafe extern "C" fn callReplyGetSetElement(
816 mut rep: *mut CallReply,
817 mut idx: size_t,
818) -> *mut CallReply {
819 callReplyParse(rep);
820 if (*rep).type_0 != 6 as libc::c_int {
821 return 0 as *mut CallReply;
822 }
823 return callReplyGetCollectionElement(rep, idx, 1 as libc::c_int);
824}
825unsafe extern "C" fn callReplyGetMapElementInternal(
826 mut rep: *mut CallReply,
827 mut idx: size_t,
828 mut key: *mut *mut CallReply,
829 mut val: *mut *mut CallReply,
830 mut type_0: libc::c_int,
831) -> libc::c_int {
832 callReplyParse(rep);
833 if (*rep).type_0 != type_0 {
834 return -(1 as libc::c_int);
835 }
836 if idx >= (*rep).len {
837 return -(1 as libc::c_int);
838 }
839 if !key.is_null() {
840 *key = callReplyGetCollectionElement(
841 rep,
842 idx.wrapping_mul(2 as libc::c_int as libc::c_ulong),
843 2 as libc::c_int,
844 );
845 }
846 if !val.is_null() {
847 *val = callReplyGetCollectionElement(
848 rep,
849 idx
850 .wrapping_mul(2 as libc::c_int as libc::c_ulong)
851 .wrapping_add(1 as libc::c_int as libc::c_ulong),
852 2 as libc::c_int,
853 );
854 }
855 return 0 as libc::c_int;
856}
857#[no_mangle]
858pub unsafe extern "C" fn callReplyGetMapElement(
859 mut rep: *mut CallReply,
860 mut idx: size_t,
861 mut key: *mut *mut CallReply,
862 mut val: *mut *mut CallReply,
863) -> libc::c_int {
864 return callReplyGetMapElementInternal(rep, idx, key, val, 5 as libc::c_int);
865}
866#[no_mangle]
867pub unsafe extern "C" fn callReplyGetAttribute(
868 mut rep: *mut CallReply,
869) -> *mut CallReply {
870 return (*rep).attribute;
871}
872#[no_mangle]
873pub unsafe extern "C" fn callReplyGetAttributeElement(
874 mut rep: *mut CallReply,
875 mut idx: size_t,
876 mut key: *mut *mut CallReply,
877 mut val: *mut *mut CallReply,
878) -> libc::c_int {
879 return callReplyGetMapElementInternal(rep, idx, key, val, 5 as libc::c_int);
880}
881#[no_mangle]
882pub unsafe extern "C" fn callReplyGetBigNumber(
883 mut rep: *mut CallReply,
884 mut len: *mut size_t,
885) -> *const libc::c_char {
886 callReplyParse(rep);
887 if (*rep).type_0 != 9 as libc::c_int {
888 return 0 as *const libc::c_char;
889 }
890 *len = (*rep).len;
891 return (*rep).val.str_0;
892}
893#[no_mangle]
894pub unsafe extern "C" fn callReplyGetVerbatim(
895 mut rep: *mut CallReply,
896 mut len: *mut size_t,
897 mut format: *mut *const libc::c_char,
898) -> *const libc::c_char {
899 callReplyParse(rep);
900 if (*rep).type_0 != 10 as libc::c_int {
901 return 0 as *const libc::c_char;
902 }
903 *len = (*rep).len;
904 if !format.is_null() {
905 *format = (*rep).val.verbatim_str.format;
906 }
907 return (*rep).val.verbatim_str.str_0;
908}
909#[no_mangle]
910pub unsafe extern "C" fn callReplyGetProto(
911 mut rep: *mut CallReply,
912 mut proto_len: *mut size_t,
913) -> *const libc::c_char {
914 *proto_len = (*rep).proto_len;
915 return (*rep).proto;
916}
917#[no_mangle]
918pub unsafe extern "C" fn callReplyGetPrivateData(
919 mut rep: *mut CallReply,
920) -> *mut libc::c_void {
921 return (*rep).private_data;
922}
923#[no_mangle]
924pub unsafe extern "C" fn callReplyIsResp3(mut rep: *mut CallReply) -> libc::c_int {
925 return (*rep).flags & (1 as libc::c_int) << 2 as libc::c_int;
926}
927#[no_mangle]
928pub unsafe extern "C" fn callReplyDeferredErrorList(
929 mut rep: *mut CallReply,
930) -> *mut list {
931 return (*rep).deferred_error_list;
932}
933#[no_mangle]
934pub unsafe extern "C" fn callReplyCreate(
935 mut reply: sds,
936 mut deferred_error_list: *mut list,
937 mut private_data: *mut libc::c_void,
938) -> *mut CallReply {
939 let mut res: *mut CallReply = zmalloc(
940 core::mem::size_of::<CallReply>() as libc::c_ulong,
941 ) as *mut CallReply;
942 (*res).flags = (1 as libc::c_int) << 0 as libc::c_int;
943 (*res).original_proto = reply;
944 (*res).proto = reply as *const libc::c_char;
945 (*res).proto_len = sdslen(reply);
946 (*res).private_data = private_data;
947 (*res).attribute = 0 as *mut CallReply;
948 (*res).deferred_error_list = deferred_error_list;
949 return res;
950}
951#[no_mangle]
952pub unsafe extern "C" fn callReplyCreateError(
953 mut reply: sds,
954 mut private_data: *mut libc::c_void,
955) -> *mut CallReply {
956 let mut err_buff: sds = reply;
957 if *err_buff.offset(0 as libc::c_int as isize) as libc::c_int != '-' as i32 {
958 err_buff = sdscatfmt(
959 sdsempty(),
960 b"-ERR %S\r\n\0" as *const u8 as *const libc::c_char,
961 reply,
962 );
963 sdsfree(reply);
964 }
965 let mut deferred_error_list: *mut list = listCreate();
966 (*deferred_error_list)
967 .free = core::mem::transmute::<
968 Option::<unsafe extern "C" fn(sds) -> ()>,
969 Option::<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
970 >(Some(sdsfree as unsafe extern "C" fn(sds) -> ()));
971 listAddNodeTail(
972 deferred_error_list,
973 sdsnew(err_buff as *const libc::c_char) as *mut libc::c_void,
974 );
975 return callReplyCreate(err_buff, deferred_error_list, private_data);
976}