|
@@ -0,0 +1,46 @@
|
|
|
+
|
|
|
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
|
|
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
|
|
|
+
|
|
|
+
|
|
|
+#include "orconfig.h"
|
|
|
+#include "lib/encoding/keyval.h"
|
|
|
+#include "lib/log/escape.h"
|
|
|
+#include "lib/log/torlog.h"
|
|
|
+#include "lib/log/util_bug.h"
|
|
|
+
|
|
|
+#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+
|
|
|
+ * "value" is optional, to indicate the empty string. Log at logging
|
|
|
+ * <b>severity</b> if something ugly happens. */
|
|
|
+int
|
|
|
+string_is_key_value(int severity, const char *string)
|
|
|
+{
|
|
|
+
|
|
|
+ const char *equal_sign_pos = NULL;
|
|
|
+
|
|
|
+ tor_assert(string);
|
|
|
+
|
|
|
+ if (strlen(string) < 2) {
|
|
|
+ tor_log(severity, LD_GENERAL, "'%s' is too short to be a k=v value.",
|
|
|
+ escaped(string));
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ equal_sign_pos = strchr(string, '=');
|
|
|
+ if (!equal_sign_pos) {
|
|
|
+ tor_log(severity, LD_GENERAL, "'%s' is not a k=v value.", escaped(string));
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (equal_sign_pos == string) {
|
|
|
+ tor_log(severity, LD_GENERAL, "'%s' is not a valid k=v value.",
|
|
|
+ escaped(string));
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+}
|