summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@gmail.com>2011-09-11 23:34:11 +0200
committerGeorge Kadianakis <desnacked@gmail.com>2011-09-11 23:34:11 +0200
commitc6811c57cb75b2c594b2a6fffaca0c5ae4c19e0a (patch)
tree3b60b2997c9153675e7f77861924c028caab4a02 /src/common/util.c
parent31361074216534b0a4c6377730c09b261ca4ef4e (diff)
downloadtor-c6811c57cb75b2c594b2a6fffaca0c5ae4c19e0a.tar.gz
tor-c6811c57cb75b2c594b2a6fffaca0c5ae4c19e0a.zip
Enforce transport names being C identifiers.
Introduce string_is_C_identifier() and use it to enforce transport names according to the 180 spec.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 63172c36a3..5fc2cbeabc 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -719,6 +719,34 @@ find_str_at_start_of_line(const char *haystack, const char *needle)
return NULL;
}
+/** Returns true if <b>string</b> could be a C identifier.
+ A C identifier must begin with a letter or an underscore and the
+ rest of its characters can be letters, numbers or underscores. No
+ length limit is imposed. */
+int
+string_is_C_identifier(const char *string)
+{
+ size_t iter;
+ size_t length = strlen(string);
+ if (!length)
+ return 0;
+
+ for (iter = 0; iter < length ; iter++) {
+ if (iter == 0) {
+ if (!(TOR_ISALPHA(string[iter]) ||
+ string[iter] == '_'))
+ return 0;
+ } else {
+ if (!(TOR_ISALPHA(string[iter]) ||
+ TOR_ISDIGIT(string[iter]) ||
+ string[iter] == '_'))
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
/** Return true iff the 'len' bytes at 'mem' are all zero. */
int
tor_mem_is_zero(const char *mem, size_t len)