Skip to content

Commit

Permalink
Bump & check version in JSON protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
GJDuck committed Jun 30, 2022
1 parent eeef5a9 commit 2d1d3bf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-rc1
1.0.0-rc2
2 changes: 1 addition & 1 deletion doc/e9patch.1
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,6 @@ Default: \fBfalse\fR (disabled)
\fB\-\-version\fR
Print the version and exit.
.SH "SEE ALSO"
\fIe9tool\fR(1), \fIe9compile\fR, \fIe9afl\fR(1), \fIredfat\fR(1)
\fIe9tool\fR(1), \fIe9compile\fR(1), \fIe9afl\fR(1), \fIredfat\fR(1)
.SH AUTHOR
\fBe9patch\fR is written by Gregory J. Duck <[email protected]>.
13 changes: 12 additions & 1 deletion src/e9patch/e9api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static void queuePatch(Binary *B, Instr *I, const Trampoline *T)
*/
static Binary *parseBinary(const Message &msg)
{
const char *filename = nullptr;
const char *filename = nullptr, *version = nullptr;
Mode mode = MODE_ELF_EXE;
bool have_mode = false, dup = false;
for (unsigned i = 0; i < msg.num_params; i++)
Expand All @@ -197,13 +197,24 @@ static Binary *parseBinary(const Message &msg)
mode = (Mode)msg.params[i].value.integer;
have_mode = true;
break;
case PARAM_VERSION:
dup = dup || (version != nullptr);
version = msg.params[i].value.string;
break;
default:
break;
}
}
if (filename == nullptr)
error("failed to parse \"binary\" message (id=%u); missing "
"\"filename\" parameter", msg.id);
if (version == nullptr)
error("failed to parse \"binary\" message (id=%u); missing "
"\"version\" parameter", msg.id);
if (strcmp(version, STRING(VERSION)) != 0)
error("failed to parse \"binary\" message (id=%u); invalid "
"version \"%s\"; expected \"%s\"", msg.id, version,
STRING(VERSION));
if (dup)
error("failed to parse \"binary\" message (id=%u); duplicate "
"parameters detected", msg.id);
Expand Down
6 changes: 6 additions & 0 deletions src/e9patch/e9json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ static bool validateParam(Method method, ParamName paramName)
{
case PARAM_FILENAME:
case PARAM_MODE:
case PARAM_VERSION:
return true;
default:
return false;
Expand Down Expand Up @@ -1113,6 +1114,10 @@ static void parseParams(Parser &parser, Message &msg)
else if (strcmp(parser.s, "template") == 0)
name = PARAM_TEMPLATE;
break;
case 'v':
if (strcmp(parser.s, "version") == 0)
name = PARAM_VERSION;
break;
}
expectToken(parser, ':');
if (!validateParam(msg.method, name))
Expand Down Expand Up @@ -1144,6 +1149,7 @@ static void parseParams(Parser &parser, Message &msg)
break;
case PARAM_FILENAME:
case PARAM_NAME:
case PARAM_VERSION:
expectToken(parser, TOKEN_STRING);
value.string = dupString(parser.s);
break;
Expand Down
1 change: 1 addition & 0 deletions src/e9patch/e9json.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum ParamName
PARAM_PROTECTION,
PARAM_TEMPLATE,
PARAM_TRAMPOLINE,
PARAM_VERSION,
};

/*
Expand Down
3 changes: 3 additions & 0 deletions src/e9tool/e9frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ unsigned e9tool::sendBinaryMessage(FILE *out, const char *mode,
const char *filename)
{
sendMessageHeader(out, "binary");
sendParamHeader(out, "version");
sendString(out, STRING(VERSION));
sendSeparator(out);
sendParamHeader(out, "filename");
sendString(out, filename);
sendSeparator(out);
Expand Down

0 comments on commit 2d1d3bf

Please sign in to comment.