MCPcopy Create free account
hub / github.com/F-Stack/f-stack / helloCommand

Function helloCommand

app/redis-6.2.6/src/networking.c:2976–3049  ·  view source on GitHub ↗

HELLO [ [AUTH ] [SETNAME ] ] */

Source from the content-addressed store, hash-verified

2974
2975/* HELLO [<protocol-version> [AUTH <user> <password>] [SETNAME <name>] ] */
2976void helloCommand(client *c) {
2977 long long ver = 0;
2978 int next_arg = 1;
2979
2980 if (c->argc >= 2) {
2981 if (getLongLongFromObjectOrReply(c, c->argv[next_arg++], &ver,
2982 "Protocol version is not an integer or out of range") != C_OK) {
2983 return;
2984 }
2985
2986 if (ver < 2 || ver > 3) {
2987 addReplyError(c,"-NOPROTO unsupported protocol version");
2988 return;
2989 }
2990 }
2991
2992 for (int j = next_arg; j < c->argc; j++) {
2993 int moreargs = (c->argc-1) - j;
2994 const char *opt = c->argv[j]->ptr;
2995 if (!strcasecmp(opt,"AUTH") && moreargs >= 2) {
2996 redactClientCommandArgument(c, j+1);
2997 redactClientCommandArgument(c, j+2);
2998 if (ACLAuthenticateUser(c, c->argv[j+1], c->argv[j+2]) == C_ERR) {
2999 addReplyError(c,"-WRONGPASS invalid username-password pair or user is disabled.");
3000 return;
3001 }
3002 j += 2;
3003 } else if (!strcasecmp(opt,"SETNAME") && moreargs) {
3004 if (clientSetNameOrReply(c, c->argv[j+1]) == C_ERR) return;
3005 j++;
3006 } else {
3007 addReplyErrorFormat(c,"Syntax error in HELLO option '%s'",opt);
3008 return;
3009 }
3010 }
3011
3012 /* At this point we need to be authenticated to continue. */
3013 if (!c->authenticated) {
3014 addReplyError(c,"-NOAUTH HELLO must be called with the client already "
3015 "authenticated, otherwise the HELLO AUTH <user> <pass> "
3016 "option can be used to authenticate the client and "
3017 "select the RESP protocol version at the same time");
3018 return;
3019 }
3020
3021 /* Let's switch to the specified RESP mode. */
3022 if (ver) c->resp = ver;
3023 addReplyMapLen(c,6 + !server.sentinel_mode);
3024
3025 addReplyBulkCString(c,"server");
3026 addReplyBulkCString(c,"redis");
3027
3028 addReplyBulkCString(c,"version");
3029 addReplyBulkCString(c,REDIS_VERSION);
3030
3031 addReplyBulkCString(c,"proto");
3032 addReplyLongLong(c,c->resp);
3033

Callers

nothing calls this directly

Calls 11

addReplyErrorFunction · 0.85
strcasecmpFunction · 0.85
ACLAuthenticateUserFunction · 0.85
clientSetNameOrReplyFunction · 0.85
addReplyErrorFormatFunction · 0.85
addReplyMapLenFunction · 0.85
addReplyBulkCStringFunction · 0.85
addReplyLongLongFunction · 0.85
addReplyLoadedModulesFunction · 0.85

Tested by

no test coverage detected