1 /* Copyright (c) 2001-2004, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
7 * \file recommend_pkg.c
8 * \brief Code related to the recommended-packages subsystem.
13 #include "core/or/or.h"
14 #include "feature/dirauth/recommend_pkg.h"
16 /** Return true iff <b>line</b> is a valid RecommendedPackages line.
21 "package" SP PACKAGENAME SP VERSION SP URL SP DIGESTS NL
23 PACKAGENAME = NONSPACE
26 DIGESTS = DIGEST | DIGESTS SP DIGEST
27 DIGEST = DIGESTTYPE "=" DIGESTVAL
29 NONSPACE = one or more non-space printing characters
31 DIGESTVAL = DIGESTTYPE = one or more non-=, non-" " characters.
38 validate_recommended_package_line(const char *line
)
40 const char *cp
= line
;
46 cp = strchr(cp, ' '); \
51 WORD(); /* skip packagename */
53 WORD(); /* skip version */
55 WORD(); /* Skip URL */
58 /* Skip digesttype=digestval + */
61 const char *start_of_word
= cp
;
62 const char *end_of_word
= strchr(cp
, ' ');
64 end_of_word
= cp
+ strlen(cp
);
66 if (start_of_word
== end_of_word
)
69 const char *eq
= memchr(start_of_word
, '=', end_of_word
- start_of_word
);
73 if (eq
== start_of_word
)
75 if (eq
== end_of_word
- 1)
77 if (memchr(eq
+1, '=', end_of_word
- (eq
+1)))
81 if (0 == *end_of_word
)
87 /* If we reach this point, we have at least 1 entry. */
88 tor_assert(n_entries
> 0);