#include bool get_database_from_uri(const char *uri, char *d, size_t max) { char *start = NULL, *end = NULL; size_t to_copy = 0; assert(uri); start = index(uri, '/'); if (!start || *(start+1) == '\0') return false; start = index(start+1, '/'); if (!start || *(start+1) == '\0') return false; start++; end = index(start, '/'); /* Maybe a query? */ if (!end) end = index(start, '?'); /* Fallback to end of string */ if (!end) end = index(start, '\0'); to_copy = end - start; if (to_copy >= max) to_copy = max - 1; /* copy and terminate */ strncpy(d, start, to_copy); d[to_copy] = '\0'; return true; } bool get_last_value_as_uint64(evapp_ctx *ctx, u_int64_t *i) { char *c = rindex(evapp_request(ctx)->uri, '/'); if (c == NULL || *(++c) == '\0') return false; errno = 0; *i = (u_int64_t) strtoll(c, NULL, 10); if (errno != 0) return false; return true; }