summaryrefslogtreecommitdiff
path: root/serve.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2021-09-14 11:30:50 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-09-14 10:56:19 -0700
commit5ef260d2d124c0fcd799bd4aaf6fa1793a6c74de (patch)
tree6a908fa2f124cba2b08b4a3f593f13607544397b /serve.c
parentserve: rename is_command() to parse_command() (diff)
downloadtgif-5ef260d2d124c0fcd799bd4aaf6fa1793a6c74de.tar.xz
serve: return capability "value" from get_capability()
When the client sends v2 capabilities, they may be simple, like: foo or have a value like: foo=bar (all of the current capabilities actually expect a value, but the protocol allows for boolean ones). We use get_capability() to make sure the client's pktline matches a capability. In doing so, we parse enough to see the "=" and the value (if any), but we immediately forget it. Nobody cares for now, because they end up parsing the values out later using has_capability(). But in preparation for changing that, let's pass back a pointer so the callers know what we found. Note that unlike has_capability(), we'll return NULL for a "simple" capability. Distinguishing these will be useful for some future patches. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'serve.c')
-rw-r--r--serve.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/serve.c b/serve.c
index fd88b95343..78a4e83554 100644
--- a/serve.c
+++ b/serve.c
@@ -139,7 +139,7 @@ void protocol_v2_advertise_capabilities(void)
strbuf_release(&value);
}
-static struct protocol_capability *get_capability(const char *key)
+static struct protocol_capability *get_capability(const char *key, const char **value)
{
int i;
@@ -149,8 +149,16 @@ static struct protocol_capability *get_capability(const char *key)
for (i = 0; i < ARRAY_SIZE(capabilities); i++) {
struct protocol_capability *c = &capabilities[i];
const char *out;
- if (skip_prefix(key, c->name, &out) && (!*out || *out == '='))
+ if (!skip_prefix(key, c->name, &out))
+ continue;
+ if (!*out) {
+ *value = NULL;
return c;
+ }
+ if (*out++ == '=') {
+ *value = out;
+ return c;
+ }
}
return NULL;
@@ -158,7 +166,8 @@ static struct protocol_capability *get_capability(const char *key)
static int is_valid_capability(const char *key)
{
- const struct protocol_capability *c = get_capability(key);
+ const char *value;
+ const struct protocol_capability *c = get_capability(key, &value);
return c && c->advertise(the_repository, NULL);
}
@@ -168,7 +177,8 @@ static int parse_command(const char *key, struct protocol_capability **command)
const char *out;
if (skip_prefix(key, "command=", &out)) {
- struct protocol_capability *cmd = get_capability(out);
+ const char *value;
+ struct protocol_capability *cmd = get_capability(out, &value);
if (*command)
die("command '%s' requested after already requesting command '%s'",