--- /dev/null
+/*
+ * siri/evars.h
+ */
+#ifndef SIRI_EVARS_H_
+#define SIRI_EVARS_H_
+
+#include <siri/siri.h>
+
+void siri_evars_parse(siri_t * siri);
+
+#endif /* SIRI_EVARS_H_ */
#include <siri/help/help.h>
#include <siri/siri.h>
#include <siri/version.h>
+#include <siri/evars.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* read siridb main application configuration */
siri_cfg_init(&siri);
+ siri_evars_parse(&siri);
+
/* start SiriDB. (this start the event loop etc.) */
if (siri_start() && !siri_err)
{
siri.args->config,
cfgparser_errmsg(rc));
exit(EXIT_FAILURE);
+ return;
}
- else if (option->tp != CFGPARSER_TP_STRING)
+
+ if (option->tp != CFGPARSER_TP_STRING)
{
log_critical(
"Error reading '%s' in '%s': %s. ",
siri.args->config,
"error: expecting a string value");
exit(EXIT_FAILURE);
+ return;
}
- else
- {
- if (*option->val->string == '[')
- {
- /* an IPv6 address... */
- for (port = address = option->val->string + 1; *port; port++)
- {
- if (*port == ']')
- {
- *port = 0;
- port++;
- break;
- }
- }
- }
- else
- {
- port = address = option->val->string;
- }
- for (; *port; port++)
+ if (*option->val->string == '[')
+ {
+ /* an IPv6 address... */
+ for (port = address = option->val->string + 1; *port; port++)
{
- if (*port == ':')
+ if (*port == ']')
{
*port = 0;
port++;
break;
}
}
+ }
+ else
+ {
+ port = address = option->val->string;
+ }
+
+ for (; *port; port++)
+ {
+ if (*port == ':')
+ {
+ *port = 0;
+ port++;
+ break;
+ }
+ }
+
+ if ( !strlen(address) ||
+ strlen(address) >= SIRI_CFG_MAX_LEN_ADDRESS ||
+ !xstr_is_int(port) ||
+ strcpy(address_pt, address) == NULL ||
+ xstr_replace_str(
+ address_pt,
+ "%HOSTNAME",
+ hostname,
+ SIRI_CFG_MAX_LEN_ADDRESS))
+ {
+ log_critical(
+ "Error reading '%s' in '%s': "
+ "error: got an unexpected value '%s:%s'.",
+ option_name,
+ siri.args->config,
+ address,
+ port);
+ exit(EXIT_FAILURE);
+ }
+ else
+ {
+ test_port = atoi(port);
- if ( !strlen(address) ||
- strlen(address) >= SIRI_CFG_MAX_LEN_ADDRESS ||
- !xstr_is_int(port) ||
- strcpy(address_pt, address) == NULL ||
- xstr_replace_str(
- address_pt,
- "%HOSTNAME",
- hostname,
- SIRI_CFG_MAX_LEN_ADDRESS))
+ if (test_port < 1 || test_port > 65535)
{
log_critical(
"Error reading '%s' in '%s': "
- "error: got an unexpected value '%s:%s'.",
+ "error: port should be between 1 and 65535, got '%d'.",
option_name,
siri.args->config,
- address,
- port);
+ test_port);
exit(EXIT_FAILURE);
}
else
{
- test_port = atoi(port);
-
- if (test_port < 1 || test_port > 65535)
- {
- log_critical(
- "Error reading '%s' in '%s': "
- "error: port should be between 1 and 65535, got '%d'.",
- option_name,
- siri.args->config,
- test_port);
- exit(EXIT_FAILURE);
- }
- else
- {
- *port_pt = (uint16_t) test_port;
- }
-
- log_debug("Read '%s' from config: %s:%d",
- option_name,
- address_pt,
- *port_pt);
+ *port_pt = (uint16_t) test_port;
}
+ log_debug("Read '%s' from config: %s:%d",
+ option_name,
+ address_pt,
+ *port_pt);
}
}
username,
password)) == NULL)
{
- log_warning("User authentication request failed: invalid credentials");
+ if (strcmp(username, "sa") == 0)
+ {
+ log_warning(
+ "User authentication request failed: "
+ "invalid credentials for user `sa`, "
+ "did you mean to use the default database user `iris`?");
+ }
+ else
+ {
+ log_warning(
+ "User authentication request failed: invalid credentials");
+ }
return CPROTO_ERR_AUTH_CREDENTIALS;
}
--- /dev/null
+/*
+ * siri/evars.c
+ */
+
+#include <siri/evars.h>
+
+static void evars__u8(const char * evar, uint8_t * u8)
+{
+ char * u8str = getenv(evar);
+ if (!u8str)
+ return;
+
+ *u8 = (uint8_t) strtoul(u8str, NULL, 10);
+}
+
+static void evars__u16(const char * evar, uint16_t * u16)
+{
+ char * u16str = getenv(evar);
+ if (!u16str)
+ return;
+
+ *u16 = (uint16_t) strtoul(u16str, NULL, 10);
+}
+
+static void evars__sizet(const char * evar, size_t * sz)
+{
+ char * sizetstr = getenv(evar);
+ if (!sizetstr)
+ return;
+
+ *sz = (size_t) strtoull(sizetstr, NULL, 10);
+}
+
+static void evars__double(const char * evar, double * d)
+{
+ char * doublestr = getenv(evar);
+ if (!doublestr)
+ return;
+
+ *d = strtod(doublestr, NULL);
+}
+
+static void evars__str(const char * evar, char ** straddr)
+{
+ char * str = getenv(evar);
+ if (!str || !(str = strdup(str)))
+ return;
+
+ free(*straddr);
+ *straddr = str;
+}
+
+
+void siri_evars_parse(siri_t * siri)
+{
+
+}
}
+int sirinet_extract_addr_port(
+ const char * s,
+ char * addr,
+ uint16_t * port)
+{
+ if (*option->val->string == '[')
+ {
+ /* an IPv6 address... */
+ for (port = address = option->val->string + 1; *port; port++)
+ {
+ if (*port == ']')
+ {
+ *port = 0;
+ port++;
+ break;
+ }
+ }
+ }
+ else
+ {
+ port = address = option->val->string;
+ }
+
+ for (; *port; port++)
+ {
+ if (*port == ':')
+ {
+ *port = 0;
+ port++;
+ break;
+ }
+ }
+
+ if ( !strlen(address) ||
+ strlen(address) >= SIRI_CFG_MAX_LEN_ADDRESS ||
+ !xstr_is_int(port) ||
+ strcpy(address_pt, address) == NULL ||
+ xstr_replace_str(
+ address_pt,
+ "%HOSTNAME",
+ hostname,
+ SIRI_CFG_MAX_LEN_ADDRESS))
+ {
+ log_critical(
+ "Error reading '%s' in '%s': "
+ "error: got an unexpected value '%s:%s'.",
+ option_name,
+ siri.args->config,
+ address,
+ port);
+ exit(EXIT_FAILURE);
+ }
+ else
+ {
+ test_port = atoi(port);
+
+ if (test_port < 1 || test_port > 65535)
+ {
+ log_critical(
+ "Error reading '%s' in '%s': "
+ "error: port should be between 1 and 65535, got '%d'.",
+ option_name,
+ siri.args->config,
+ test_port);
+ exit(EXIT_FAILURE);
+ }
+ else
+ {
+ *port_pt = (uint16_t) test_port;
+ }
+
+ log_debug("Read '%s' from config: %s:%d",
+ option_name,
+ address_pt,
+ *port_pt);
+ }
+}