mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 16:37:01 +00:00
[10387] Fixed quote parsing after optional arg in chat commands.
This is restore work .guid commands for example.
This commit is contained in:
parent
23be9ae496
commit
ddd0c4567b
3 changed files with 39 additions and 18 deletions
|
|
@ -2261,9 +2261,10 @@ char* ChatHandler::ExtractLiteralArg(char** args, char const* lit /*= NULL*/)
|
||||||
* Function extract quote-like string (any characters guarded by some special character, in our cases ['")
|
* Function extract quote-like string (any characters guarded by some special character, in our cases ['")
|
||||||
*
|
*
|
||||||
* @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces)
|
* @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces)
|
||||||
|
* @param asis control save quote string wrappers
|
||||||
* @return quote-like string, or NULL if args empty or not appropriate content.
|
* @return quote-like string, or NULL if args empty or not appropriate content.
|
||||||
*/
|
*/
|
||||||
char* ChatHandler::ExtractQuotedArg( char** args )
|
char* ChatHandler::ExtractQuotedArg( char** args, bool asis /*= false*/ )
|
||||||
{
|
{
|
||||||
if (!*args || !**args)
|
if (!*args || !**args)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -2271,32 +2272,50 @@ char* ChatHandler::ExtractQuotedArg( char** args )
|
||||||
if (**args != '\'' && **args != '"' && **args != '[')
|
if (**args != '\'' && **args != '"' && **args != '[')
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
char guard[2] = " "; // guard[1] == '\0'
|
char guard = (*args)[0];
|
||||||
|
|
||||||
guard[0] = (*args)[0];
|
if (guard == '[')
|
||||||
|
guard = ']';
|
||||||
|
|
||||||
if (guard[0] == '[')
|
char* tail = (*args)+1; // start scan after first quote symbol
|
||||||
guard[0] = ']';
|
char* head = asis ? *args : tail; // start arg
|
||||||
|
|
||||||
char* str = strtok((*args)+1, guard); // skip start guard symbol
|
while (*tail && *tail != guard)
|
||||||
|
++tail;
|
||||||
|
|
||||||
char* tail = strtok(NULL, "");
|
if (!*tail || tail[1] && !isWhiteSpace(tail[1])) // fail
|
||||||
*args = tail ? tail : (char*)""; // *args don't must be NULL
|
return NULL;
|
||||||
|
|
||||||
|
if (!tail[1]) // quote is last char in string
|
||||||
|
{
|
||||||
|
if (!asis)
|
||||||
|
*tail = '\0';
|
||||||
|
}
|
||||||
|
else // quote isn't last char
|
||||||
|
{
|
||||||
|
if (asis)
|
||||||
|
++tail;
|
||||||
|
|
||||||
|
*tail = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
*args = tail+1;
|
||||||
|
|
||||||
SkipWhiteSpaces(args);
|
SkipWhiteSpaces(args);
|
||||||
|
|
||||||
return str;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function extract quote-like string or literal if quote not detected
|
* Function extract quote-like string or literal if quote not detected
|
||||||
*
|
*
|
||||||
* @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces)
|
* @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces)
|
||||||
|
* @param asis control save quote string wrappers
|
||||||
* @return quote/literal string, or NULL if args empty or not appropriate content.
|
* @return quote/literal string, or NULL if args empty or not appropriate content.
|
||||||
*/
|
*/
|
||||||
char* ChatHandler::ExtractQuotedOrLiteralArg(char** args)
|
char* ChatHandler::ExtractQuotedOrLiteralArg(char** args, bool asis /*= false*/)
|
||||||
{
|
{
|
||||||
char *arg = ExtractQuotedArg(args);
|
char *arg = ExtractQuotedArg(args, asis);
|
||||||
if (!arg)
|
if (!arg)
|
||||||
arg = ExtractLiteralArg(args);
|
arg = ExtractLiteralArg(args);
|
||||||
return arg;
|
return arg;
|
||||||
|
|
@ -2518,14 +2537,15 @@ char* ChatHandler::ExtractLinkArg(char** args, char const* const* linkTypes /*=
|
||||||
* Function extract name/number/quote/shift-link-like string
|
* Function extract name/number/quote/shift-link-like string
|
||||||
*
|
*
|
||||||
* @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces)
|
* @param args variable pointer to non parsed args string, updated at function call to new position (with skipped white spaces)
|
||||||
|
* @param asis control save quote string wrappers
|
||||||
* @return extracted arg string, or NULL if args empty or not appropriate content.
|
* @return extracted arg string, or NULL if args empty or not appropriate content.
|
||||||
*/
|
*/
|
||||||
char* ChatHandler::ExtractArg( char** args )
|
char* ChatHandler::ExtractArg( char** args, bool asis /*= false*/ )
|
||||||
{
|
{
|
||||||
if (!*args || !**args)
|
if (!*args || !**args)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
char* arg = ExtractQuotedOrLiteralArg(args);
|
char* arg = ExtractQuotedOrLiteralArg(args, asis);
|
||||||
if (!arg)
|
if (!arg)
|
||||||
arg = ExtractLinkArg(args);
|
arg = ExtractLinkArg(args);
|
||||||
|
|
||||||
|
|
@ -2541,7 +2561,7 @@ char* ChatHandler::ExtractArg( char** args )
|
||||||
*/
|
*/
|
||||||
char* ChatHandler::ExtractOptNotLastArg(char** args)
|
char* ChatHandler::ExtractOptNotLastArg(char** args)
|
||||||
{
|
{
|
||||||
char* arg = ExtractArg(args);
|
char* arg = ExtractArg(args, true);
|
||||||
|
|
||||||
// have more data
|
// have more data
|
||||||
if (*args && **args)
|
if (*args && **args)
|
||||||
|
|
|
||||||
|
|
@ -572,14 +572,15 @@ class ChatHandler
|
||||||
bool ExtractOptUInt32(char** args, uint32& val, uint32 defVal);
|
bool ExtractOptUInt32(char** args, uint32& val, uint32 defVal);
|
||||||
bool ExtractFloat(char** args, float& val);
|
bool ExtractFloat(char** args, float& val);
|
||||||
bool ExtractOptFloat(char** args, float& val, float defVal);
|
bool ExtractOptFloat(char** args, float& val, float defVal);
|
||||||
char* ExtractQuotedArg(char** args); // string with " or [] or ' around
|
char* ExtractQuotedArg(char** args, bool asis = false);
|
||||||
|
// string with " or [] or ' around
|
||||||
char* ExtractLiteralArg(char** args, char const* lit = NULL);
|
char* ExtractLiteralArg(char** args, char const* lit = NULL);
|
||||||
// literal string (until whitespace and not started from "['|), any or 'lit' if provided
|
// literal string (until whitespace and not started from "['|), any or 'lit' if provided
|
||||||
char* ExtractQuotedOrLiteralArg(char** args);
|
char* ExtractQuotedOrLiteralArg(char** args, bool asis = false);
|
||||||
bool ExtractOnOff(char** args, bool& value);
|
bool ExtractOnOff(char** args, bool& value);
|
||||||
char* ExtractLinkArg(char** args, char const* const* linkTypes = NULL, int* foundIdx = NULL, char** keyPair = NULL, char** somethingPair = NULL);
|
char* ExtractLinkArg(char** args, char const* const* linkTypes = NULL, int* foundIdx = NULL, char** keyPair = NULL, char** somethingPair = NULL);
|
||||||
// shift-link like arg (with aditional info if need)
|
// shift-link like arg (with aditional info if need)
|
||||||
char* ExtractArg(char** args); // any name/number/quote/shift-link strings
|
char* ExtractArg(char** args, bool asis = false); // any name/number/quote/shift-link strings
|
||||||
char* ExtractOptNotLastArg(char** args); // extract name/number/quote/shift-link arg only if more data in args for parse
|
char* ExtractOptNotLastArg(char** args); // extract name/number/quote/shift-link arg only if more data in args for parse
|
||||||
|
|
||||||
char* ExtractKeyFromLink(char** text, char const* linkType, char** something1 = NULL);
|
char* ExtractKeyFromLink(char** text, char const* linkType, char** something1 = NULL);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10386"
|
#define REVISION_NR "10387"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue