X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=891182a35b70d4460aa2082914753090305f6621;hb=f8eeeaf9b783ebbab30672629abf3920db286811;hp=3aa952fd77adcf4ed706ceafa6607ebcdef00321;hpb=c7088e4999f2e5dd33259948c806f4e2706e77ce;p=elogind.git diff --git a/src/shared/util.c b/src/shared/util.c index 3aa952fd7..891182a35 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5462,6 +5462,19 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) { return r; } +bool http_etag_is_valid(const char *etag) { + if (isempty(etag)) + return false; + + if (!endswith(etag, "\"")) + return false; + + if (!startswith(etag, "\"") && !startswith(etag, "W/\"")) + return false; + + return true; +} + bool http_url_is_valid(const char *url) { const char *p; @@ -8025,3 +8038,45 @@ void sigkill_wait(pid_t *pid) { if (kill(*pid, SIGKILL) > 0) (void) wait_for_terminate(*pid, NULL); } + +int syslog_parse_priority(const char **p, int *priority, bool with_facility) { + int a = 0, b = 0, c = 0; + int k; + + assert(p); + assert(*p); + assert(priority); + + if ((*p)[0] != '<') + return 0; + + if (!strchr(*p, '>')) + return 0; + + if ((*p)[2] == '>') { + c = undecchar((*p)[1]); + k = 3; + } else if ((*p)[3] == '>') { + b = undecchar((*p)[1]); + c = undecchar((*p)[2]); + k = 4; + } else if ((*p)[4] == '>') { + a = undecchar((*p)[1]); + b = undecchar((*p)[2]); + c = undecchar((*p)[3]); + k = 5; + } else + return 0; + + if (a < 0 || b < 0 || c < 0 || + (!with_facility && (a || b || c > 7))) + return 0; + + if (with_facility) + *priority = a*100 + b*10 + c; + else + *priority = (*priority & LOG_FACMASK) | c; + + *p += k; + return 1; +}