+/*********************************************************************
+ *
+ * Function : parse_numeric_value
+ *
+ * Description : Parse the value of a directive that can only have
+ * a single numeric value. Terminates with a fatal error
+ * if the value is NULL or not numeric.
+ *
+ * Parameters :
+ * 1 : name: The name of the directive. Used for log messages.
+ * 2 : value: The value to parse
+ *
+ *
+ * Returns : The numerical value as integer
+ *
+ *********************************************************************/
+static int parse_numeric_value(const char *name, const char *value)
+{
+ int number;
+ char *endptr;
+
+ assert(name != NULL);
+ assert(value != NULL);
+
+ if ((value == NULL) || (*value == '\0'))
+ {
+ log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
+ }
+
+ number = (int)strtol(value, &endptr, 0);
+ if (*endptr != '\0')
+ {
+ log_error(LOG_LEVEL_FATAL,
+ "Directive '%s' used with non-numerical value: '%s'", name, value);
+ }
+
+ return number;
+
+}
+
+
+/*********************************************************************
+ *
+ * Function : parse_toggle_value
+ *
+ * Description : Parse the value of a directive that can only be
+ * enabled or disabled. Terminates with a fatal error
+ * if the value is NULL or something other than 0 or 1.
+ *
+ * Parameters :
+ * 1 : name: The name of the directive. Used for log messages.
+ * 2 : value: The value to parse
+ *
+ *
+ * Returns : The numerical toggle state
+ *
+ *********************************************************************/
+static int parse_toggle_state(const char *name, const char *value)
+{
+ int toggle_state;
+ assert(name != NULL);
+ assert(value != NULL);
+
+ if ((value == NULL) || (*value == '\0'))
+ {
+ log_error(LOG_LEVEL_FATAL, "Directive %s used without argument", name);
+ }
+
+ toggle_state = atoi(value);
+
+ /*
+ * Also check the length as atoi() doesn't mind
+ * garbage after a valid integer, but we do.
+ */
+ if (((toggle_state != 0) && (toggle_state != 1)) || (strlen(value) != 1))
+ {
+ log_error(LOG_LEVEL_FATAL,
+ "Directive %s used with invalid argument '%s'. Use either '0' or '1'.",
+ name, value);
+ }
+
+ return toggle_state;
+
+}
+
+
+/*********************************************************************
+ *
+ * Function : parse_client_header_order
+ *
+ * Description : Parse the value of the header-order directive
+ *
+ * Parameters :
+ * 1 : ordered_header_list: List to insert the ordered
+ * headers into.
+ * 2 : ordered_headers: The ordered header names separated
+ * by spaces or tabs.
+ *
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+static void parse_client_header_order(struct list *ordered_header_list, const char *ordered_headers)
+{
+ char *original_headers_copy;
+ char **vector;
+ size_t max_segments;
+ int number_of_headers;
+ int i;
+
+ assert(ordered_header_list != NULL);
+ assert(ordered_headers != NULL);
+
+ if (ordered_headers == NULL)
+ {
+ log_error(LOG_LEVEL_FATAL, "header-order used without argument");
+ }
+
+ /*
+ * XXX: This estimate is guaranteed to be high enough as we
+ * let ssplit() ignore empty fields, but also a bit wasteful.
+ * The same hack is used in get_last_url() so it looks like
+ * a real solution is needed.
+ */
+ max_segments = strlen(ordered_headers) / 2;
+ if (max_segments == 0)
+ {
+ max_segments = 1;
+ }
+ vector = malloc_or_die(max_segments * sizeof(char *));
+
+ original_headers_copy = strdup_or_die(ordered_headers);
+
+ number_of_headers = ssplit(original_headers_copy, "\t ", vector, max_segments);
+ if (number_of_headers == -1)
+ {
+ log_error(LOG_LEVEL_FATAL, "Failed to split ordered headers");
+ }
+
+ for (i = 0; i < number_of_headers; i++)
+ {
+ if (JB_ERR_OK != enlist(ordered_header_list, vector[i]))
+ {
+ log_error(LOG_LEVEL_FATAL,
+ "Failed to enlist ordered header: %s", vector[i]);
+ }
+ }
+
+ freez(vector);
+ freez(original_headers_copy);
+
+ return;
+
+}
+
+