chiark / gitweb /
logind: remove per-user runtime dir again if setup fails
[elogind.git] / src / import / curl-util.c
index eaaebaef42fc98166389f711cbb273d3bd73cb20..313b04b0b82e57369bcbb0576dc8d42bbd0289cf 100644 (file)
@@ -236,6 +236,7 @@ CurlGlue *curl_glue_unref(CurlGlue *g) {
 
         sd_event_source_unref(g->timer);
         sd_event_unref(g->event);
+        free(g);
 
         return NULL;
 }
@@ -413,3 +414,36 @@ int curl_header_strdup(const void *contents, size_t sz, const char *field, char
         *value = s;
         return 1;
 }
+
+int curl_parse_http_time(const char *t, usec_t *ret) {
+        const char *e;
+        locale_t loc;
+        struct tm tm;
+        time_t v;
+
+        assert(t);
+        assert(ret);
+
+        loc = newlocale(LC_TIME_MASK, "C", (locale_t) 0);
+        if (loc == (locale_t) 0)
+                return -errno;
+
+        /* RFC822 */
+        e = strptime_l(t, "%a, %d %b %Y %H:%M:%S %Z", &tm, loc);
+        if (!e || *e != 0)
+                /* RFC 850 */
+                e = strptime_l(t, "%A, %d-%b-%y %H:%M:%S %Z", &tm, loc);
+        if (!e || *e != 0)
+                /* ANSI C */
+                e = strptime_l(t, "%a %b %d %H:%M:%S %Y", &tm, loc);
+        freelocale(loc);
+        if (!e || *e != 0)
+                return -EINVAL;
+
+        v = timegm(&tm);
+        if (v == (time_t) -1)
+                return -EINVAL;
+
+        *ret = (usec_t) v * USEC_PER_SEC;
+        return 0;
+}