Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
57484397
Commit
57484397
authored
Feb 25, 2019
by
antirez
Browse files
RESP3: refactoring of CLIENT SETNAME to implement SETNAME in HELLO.
parent
3b420034
Changes
1
Show whitespace changes
Inline
Side-by-side
src/networking.c
View file @
57484397
...
@@ -1803,6 +1803,45 @@ sds getAllClientsInfoString(int type) {
...
@@ -1803,6 +1803,45 @@ sds getAllClientsInfoString(int type) {
return
o
;
return
o
;
}
}
/* This function implements CLIENT SETNAME, including replying to the
* user with an error if the charset is wrong (in that case C_ERR is
* returned). If the function succeeeded C_OK is returned, and it's up
* to the caller to send a reply if needed.
*
* Setting an empty string as name has the effect of unsetting the
* currently set name: the client will remain unnamed.
*
* This function is also used to implement the HELLO SETNAME option. */
int
clientSetNameOrReply
(
client
*
c
,
robj
*
name
)
{
int
len
=
sdslen
(
name
->
ptr
);
char
*
p
=
name
->
ptr
;
/* Setting the client name to an empty string actually removes
* the current name. */
if
(
len
==
0
)
{
if
(
c
->
name
)
decrRefCount
(
c
->
name
);
c
->
name
=
NULL
;
addReply
(
c
,
shared
.
ok
);
return
C_OK
;
}
/* Otherwise check if the charset is ok. We need to do this otherwise
* CLIENT LIST format will break. You should always be able to
* split by space to get the different fields. */
for
(
int
j
=
0
;
j
<
len
;
j
++
)
{
if
(
p
[
j
]
<
'!'
||
p
[
j
]
>
'~'
)
{
/* ASCII is assumed. */
addReplyError
(
c
,
"Client names cannot contain spaces, "
"newlines or special characters."
);
return
C_ERR
;
}
}
if
(
c
->
name
)
decrRefCount
(
c
->
name
);
c
->
name
=
name
;
incrRefCount
(
name
);
return
C_OK
;
}
void
clientCommand
(
client
*
c
)
{
void
clientCommand
(
client
*
c
)
{
listNode
*
ln
;
listNode
*
ln
;
listIter
li
;
listIter
li
;
...
@@ -1979,32 +2018,7 @@ NULL
...
@@ -1979,32 +2018,7 @@ NULL
addReply
(
c
,
shared
.
czero
);
addReply
(
c
,
shared
.
czero
);
}
}
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"setname"
)
&&
c
->
argc
==
3
)
{
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"setname"
)
&&
c
->
argc
==
3
)
{
int
j
,
len
=
sdslen
(
c
->
argv
[
2
]
->
ptr
);
if
(
clientSetNameOrReply
(
c
,
c
->
argv
[
2
])
==
C_OK
)
char
*
p
=
c
->
argv
[
2
]
->
ptr
;
/* Setting the client name to an empty string actually removes
* the current name. */
if
(
len
==
0
)
{
if
(
c
->
name
)
decrRefCount
(
c
->
name
);
c
->
name
=
NULL
;
addReply
(
c
,
shared
.
ok
);
return
;
}
/* Otherwise check if the charset is ok. We need to do this otherwise
* CLIENT LIST format will break. You should always be able to
* split by space to get the different fields. */
for
(
j
=
0
;
j
<
len
;
j
++
)
{
if
(
p
[
j
]
<
'!'
||
p
[
j
]
>
'~'
)
{
/* ASCII is assumed. */
addReplyError
(
c
,
"Client names cannot contain spaces, "
"newlines or special characters."
);
return
;
}
}
if
(
c
->
name
)
decrRefCount
(
c
->
name
);
c
->
name
=
c
->
argv
[
2
];
incrRefCount
(
c
->
name
);
addReply
(
c
,
shared
.
ok
);
addReply
(
c
,
shared
.
ok
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"getname"
)
&&
c
->
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"getname"
)
&&
c
->
argc
==
2
)
{
if
(
c
->
name
)
if
(
c
->
name
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment