From f47182c852601c045f62bd7f669360a920516311 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 8 Jan 2012 22:06:19 +0100 Subject: server_supports(): parse feature list more carefully We have been carefully choosing feature names used in the protocol extensions so that the vocabulary does not contain a word that is a substring of another word, so it is not a real problem, but we have recently added "quiet" feature word, which would mean we cannot later add some other word with "quiet" (e.g. "quiet-push"), which is awkward. Let's make sure that we can eventually be able to do so by teaching the clients and servers that feature words consist of non whitespace letters. This parser also allows us to later add features with parameters e.g. "feature=1.5" (parameter values need to be quoted for whitespaces, but we will worry about the detauls when we do introduce them). Signed-off-by: Junio C Hamano Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- connect.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'connect.c') diff --git a/connect.c b/connect.c index 2ea5c3c0f..912cddeea 100644 --- a/connect.c +++ b/connect.c @@ -101,8 +101,27 @@ struct ref **get_remote_heads(int in, struct ref **list, int server_supports(const char *feature) { - return server_capabilities && - strstr(server_capabilities, feature) != NULL; + return !!parse_feature_request(server_capabilities, feature); +} + +const char *parse_feature_request(const char *feature_list, const char *feature) +{ + int len; + + if (!feature_list) + return NULL; + + len = strlen(feature); + while (*feature_list) { + const char *found = strstr(feature_list, feature); + if (!found) + return NULL; + if ((feature_list == found || isspace(found[-1])) && + (!found[len] || isspace(found[len]) || found[len] == '=')) + return found; + feature_list = found + 1; + } + return NULL; } enum protocol { -- cgit v1.2.1