Parse a stream ID in the format given by clients to Redis, that is * - , and converts it into a streamID structure. If * the specified ID is invalid C_ERR is returned and an error is reported * to the client, otherwise C_OK is returned. The ID may be in incomplete * form, just stating the milliseconds time part of the stream. In such a case * the missing part is set according to the v
| 1685 | * |
| 1686 | * If 'c' is set to NULL, no reply is sent to the client. */ |
| 1687 | int streamGenericParseIDOrReply(client *c, const robj *o, streamID *id, uint64_t missing_seq, int strict) { |
| 1688 | char buf[128]; |
| 1689 | if (sdslen(o->ptr) > sizeof(buf)-1) goto invalid; |
| 1690 | memcpy(buf,o->ptr,sdslen(o->ptr)+1); |
| 1691 | |
| 1692 | if (strict && (buf[0] == '-' || buf[0] == '+') && buf[1] == '\0') |
| 1693 | goto invalid; |
| 1694 | |
| 1695 | /* Handle the "-" and "+" special cases. */ |
| 1696 | if (buf[0] == '-' && buf[1] == '\0') { |
| 1697 | id->ms = 0; |
| 1698 | id->seq = 0; |
| 1699 | return C_OK; |
| 1700 | } else if (buf[0] == '+' && buf[1] == '\0') { |
| 1701 | id->ms = UINT64_MAX; |
| 1702 | id->seq = UINT64_MAX; |
| 1703 | return C_OK; |
| 1704 | } |
| 1705 | |
| 1706 | /* Parse <ms>-<seq> form. */ |
| 1707 | char *dot = strchr(buf,'-'); |
| 1708 | if (dot) *dot = '\0'; |
| 1709 | unsigned long long ms, seq; |
| 1710 | if (string2ull(buf,&ms) == 0) goto invalid; |
| 1711 | if (dot && string2ull(dot+1,&seq) == 0) goto invalid; |
| 1712 | if (!dot) seq = missing_seq; |
| 1713 | id->ms = ms; |
| 1714 | id->seq = seq; |
| 1715 | return C_OK; |
| 1716 | |
| 1717 | invalid: |
| 1718 | if (c) addReplyError(c,"Invalid stream ID specified as stream " |
| 1719 | "command argument"); |
| 1720 | return C_ERR; |
| 1721 | } |
| 1722 | |
| 1723 | /* Wrapper for streamGenericParseIDOrReply() used by module API. */ |
| 1724 | int streamParseID(const robj *o, streamID *id) { |
no test coverage detected