+static const char key_afm_prefix[] = "X-AFM-";
+static const char key_http_port[] = "http-port";
+
+#define HTTP_PORT_MIN 31000
+#define HTTP_PORT_MAX 32759
+#define HTTP_PORT_IS_VALID(port) (HTTP_PORT_MIN <= (port) && (port) <= HTTP_PORT_MAX)
+#define HTTP_PORT_COUNT (HTTP_PORT_MAX - HTTP_PORT_MIN + 1)
+#define HTTP_PORT_ACNT ((HTTP_PORT_COUNT + 31) >> 5)
+#define HTTP_PORT_ASFT(port) (((port) - HTTP_PORT_MIN) & 31)
+#define HTTP_PORT_AIDX(port) (((port) - HTTP_PORT_MIN) >> 5)
+#define HTTP_PORT_TEST(array,port) ((((array)[HTTP_PORT_AIDX(port)]) >> HTTP_PORT_ASFT(port)) & 1)
+#define HTTP_PORT_SET(array,port) (((array)[HTTP_PORT_AIDX(port)]) |= (((uint32_t)1) << HTTP_PORT_ASFT(port)))
+
+static uint32_t *port_bits = NULL;
+
+static const char *default_permissions[] = {
+ "urn:AGL:token:valid"
+};
+
+/*
+ * normalize unit files: remove comments, remove heading blanks,
+ * make single lines
+ */
+static void normalize_unit_file(char *content)
+{
+ char *read, *write, c;
+
+ read = write = content;
+ c = *read++;
+ while (c) {
+ switch (c) {
+ case '\n':
+ case ' ':
+ case '\t':
+ c = *read++;
+ break;
+ case '#':
+ case ';':
+ do { c = *read++; } while(c && c != '\n');
+ break;
+ default:
+ *write++ = c;
+ do { *write++ = c = *read++; } while(c && c != '\n');
+ if (write - content >= 2 && write[-2] == '\\')
+ (--write)[-1] = ' ';
+ break;
+ }
+ }
+ *write = c;
+}