Message ID | 20200513005424.81369-8-sandals@crustytoothpaste.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | SHA-256 part 2/3: protocol functionality | expand |
On Wed, 13 May 2020 at 02:58, brian m. carlson <sandals@crustytoothpaste.net> wrote: > +int server_feature_v2(const char *c, const char **v) > +{ > + int i; > + > + for (i = 0; i < server_capabilities_v2.argc; i++) { > + const char *out; > + if (skip_prefix(server_capabilities_v2.argv[i], c, &out) && > + (*out == '=')) { > + *v = out + 1; > + return 1; > + } > + } > + return 0; > +} > + This looks like it was based on `server_supports_feature()`, which explains the "1 means yup got it, 0 means no match". The name of `server_supports_feature()` does suggest the boolean nature of return value. For this new function, I would perhaps have expected "0 means success, negative means error". That said, I'm not familiar with connect.c. Let's see how this is used... > int server_supports_feature(const char *c, const char *feature, > int die_on_error) > { Just a thought: Maybe this existing function could learn to take a pointer (or NULL) and assign to it if we have a '=' (possibly even requiring a '=' if this new pointer is non-NULL). I dunno, maybe two similar functions are better after all than having one with modes like that. Martin
diff --git a/connect.c b/connect.c index 4027fd4677..4df9e77206 100644 --- a/connect.c +++ b/connect.c @@ -84,6 +84,21 @@ int server_supports_v2(const char *c, int die_on_error) return 0; } +int server_feature_v2(const char *c, const char **v) +{ + int i; + + for (i = 0; i < server_capabilities_v2.argc; i++) { + const char *out; + if (skip_prefix(server_capabilities_v2.argv[i], c, &out) && + (*out == '=')) { + *v = out + 1; + return 1; + } + } + return 0; +} + int server_supports_feature(const char *c, const char *feature, int die_on_error) { diff --git a/connect.h b/connect.h index 5f2382e018..4d76a6017d 100644 --- a/connect.h +++ b/connect.h @@ -19,6 +19,7 @@ struct packet_reader; enum protocol_version discover_version(struct packet_reader *reader); int server_supports_v2(const char *c, int die_on_error); +int server_feature_v2(const char *c, const char **v); int server_supports_feature(const char *c, const char *feature, int die_on_error);
So far in protocol v2, all of our server capabilities that have values have not had values that we've been interested in parsing. For example, we receive but ignore the agent value. However, in a future commit, we're going to want to parse out the value of a server capability. To make this easy, add a function, server_feature_v2, that can fetch the value provided as part of the server capability. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> --- connect.c | 15 +++++++++++++++ connect.h | 1 + 2 files changed, 16 insertions(+)