BITOP op_name target_key src_key1 src_key2 src_key3 ... src_keyN */
| 597 | |
| 598 | /* BITOP op_name target_key src_key1 src_key2 src_key3 ... src_keyN */ |
| 599 | void bitopCommand(client *c) { |
| 600 | char *opname = szFromObj(c->argv[1]); |
| 601 | robj *targetkey = c->argv[2]; |
| 602 | robj_roptr o; |
| 603 | int op; |
| 604 | unsigned long j, numkeys; |
| 605 | robj_roptr *objects; /* Array of source objects. */ |
| 606 | unsigned char **src; /* Array of source strings pointers. */ |
| 607 | unsigned long *len, maxlen = 0; /* Array of length of src strings, |
| 608 | and max len. */ |
| 609 | unsigned long minlen = 0; /* Min len among the input keys. */ |
| 610 | unsigned char *res = NULL; /* Resulting string. */ |
| 611 | |
| 612 | /* Parse the operation name. */ |
| 613 | if ((opname[0] == 'a' || opname[0] == 'A') && !strcasecmp(opname,"and")) |
| 614 | op = BITOP_AND; |
| 615 | else if((opname[0] == 'o' || opname[0] == 'O') && !strcasecmp(opname,"or")) |
| 616 | op = BITOP_OR; |
| 617 | else if((opname[0] == 'x' || opname[0] == 'X') && !strcasecmp(opname,"xor")) |
| 618 | op = BITOP_XOR; |
| 619 | else if((opname[0] == 'n' || opname[0] == 'N') && !strcasecmp(opname,"not")) |
| 620 | op = BITOP_NOT; |
| 621 | else if (!strcasecmp(opname, "lshift")) |
| 622 | op = BITOP_LSHIFT; |
| 623 | else if (!strcasecmp(opname, "rshift")) |
| 624 | op = BITOP_RSHIFT; |
| 625 | else { |
| 626 | addReplyErrorObject(c,shared.syntaxerr); |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | /* Sanity check: NOT accepts only a single key argument. */ |
| 631 | if (op == BITOP_NOT && c->argc != 4) { |
| 632 | addReplyError(c,"BITOP NOT must be called with a single source key."); |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | bool fShiftOp = (op == BITOP_LSHIFT) || (op == BITOP_RSHIFT); |
| 637 | long long shift = 0; |
| 638 | |
| 639 | /* Sanity check: SHIFTS only accept a single arg and an integer */ |
| 640 | if (fShiftOp) { |
| 641 | if (c->argc != 5) { |
| 642 | addReplyError(c,"BITOP SHIFT must be called with a single source key and an integer shift."); |
| 643 | return; |
| 644 | } |
| 645 | if (getLongLongFromObject(c->argv[4], &shift) != C_OK) { |
| 646 | addReplyError(c, "BITOP SHIFT's last parameter must be an integer"); |
| 647 | return; |
| 648 | } |
| 649 | if (shift > BITOP_SHIFT_MAX) { |
| 650 | addReplyError(c, "BITOP SHIFT value is too large."); |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | if (op == BITOP_RSHIFT) |
| 655 | shift = -shift; |
| 656 | } |
nothing calls this directly
no test coverage detected