Skip to content

Commit

Permalink
Response with error for sticker set,inc,dec and add missing asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Dec 12, 2024
1 parent b1677bf commit bd36b5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/command/StickerCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Instance.hxx"
#include "util/StringAPI.hxx"
#include "util/ScopeExit.hxx"
#include "util/StringCompare.hxx"
#include "tag/Settings.hxx"
#include "tag/ParseName.hxx"
#include "tag/Names.hxx"
Expand Down Expand Up @@ -456,16 +457,31 @@ handle_sticker(Client &client, Request args, Response &r)
return handler->List(uri);

/* 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]);
}

/* 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]);
}

/* 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]);
}

/* delete */
if ((args.size() == 3 || args.size() == 4) && StringIsEqual(cmd, "delete"))
Expand Down
5 changes: 2 additions & 3 deletions src/sticker/Database.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,9 @@ StickerDatabase::StoreValue(const char *type, const char *uri,
assert(type != nullptr);
assert(uri != nullptr);
assert(name != nullptr);
assert(*name != 0);
assert(value != nullptr);

if (StringIsEmpty(name))
return;

if (!UpdateValue(type, uri, name, value))
InsertValue(type, uri, name, value);
}
Expand Down Expand Up @@ -367,6 +365,7 @@ StickerDatabase::DeleteValue(const char *type, const char *uri,

assert(type != nullptr);
assert(uri != nullptr);
assert(name != nullptr);

BindAll(s, type, uri, name);

Expand Down

0 comments on commit bd36b5e

Please sign in to comment.