Response with error for sticker set,inc,dec and add missing asserts

This commit is contained in:
jcorporation
2024-12-12 19:39:17 +01:00
parent b1677bf79c
commit bd36b5e310
2 changed files with 21 additions and 6 deletions

@ -17,6 +17,7 @@
#include "Instance.hxx" #include "Instance.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/StringCompare.hxx"
#include "tag/Settings.hxx" #include "tag/Settings.hxx"
#include "tag/ParseName.hxx" #include "tag/ParseName.hxx"
#include "tag/Names.hxx" #include "tag/Names.hxx"
@ -456,16 +457,31 @@ handle_sticker(Client &client, Request args, Response &r)
return handler->List(uri); return handler->List(uri);
/* set */ /* set */
if (args.size() == 5 && StringIsEqual(cmd, "set")) if (args.size() == 5 && StringIsEqual(cmd, "set")) {
if (StringIsEmpty(sticker_name)) {
r.FmtError(ACK_ERROR_ARG, "empty sticker name");
return CommandResult::ERROR;
}
return handler->Set(uri, sticker_name, args[4]); return handler->Set(uri, sticker_name, args[4]);
}
/* inc */ /* inc */
if (args.size() == 5 && StringIsEqual(cmd, "inc")) if (args.size() == 5 && StringIsEqual(cmd, "inc")) {
if (StringIsEmpty(sticker_name)) {
r.FmtError(ACK_ERROR_ARG, "empty sticker name");
return CommandResult::ERROR;
}
return handler->Inc(uri, sticker_name, args[4]); return handler->Inc(uri, sticker_name, args[4]);
}
/* dec */ /* dec */
if (args.size() == 5 && StringIsEqual(cmd, "dec")) if (args.size() == 5 && StringIsEqual(cmd, "dec")) {
if (StringIsEmpty(sticker_name)) {
r.FmtError(ACK_ERROR_ARG, "empty sticker name");
return CommandResult::ERROR;
}
return handler->Dec(uri, sticker_name, args[4]); return handler->Dec(uri, sticker_name, args[4]);
}
/* delete */ /* delete */
if ((args.size() == 3 || args.size() == 4) && StringIsEqual(cmd, "delete")) if ((args.size() == 3 || args.size() == 4) && StringIsEqual(cmd, "delete"))

@ -283,11 +283,9 @@ StickerDatabase::StoreValue(const char *type, const char *uri,
assert(type != nullptr); assert(type != nullptr);
assert(uri != nullptr); assert(uri != nullptr);
assert(name != nullptr); assert(name != nullptr);
assert(*name != 0);
assert(value != nullptr); assert(value != nullptr);
if (StringIsEmpty(name))
return;
if (!UpdateValue(type, uri, name, value)) if (!UpdateValue(type, uri, name, value))
InsertValue(type, uri, name, value); InsertValue(type, uri, name, value);
} }
@ -367,6 +365,7 @@ StickerDatabase::DeleteValue(const char *type, const char *uri,
assert(type != nullptr); assert(type != nullptr);
assert(uri != nullptr); assert(uri != nullptr);
assert(name != nullptr);
BindAll(s, type, uri, name); BindAll(s, type, uri, name);