]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Add http_client_init_[private_]auto()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 27 Jun 2023 21:00:08 +0000 (00:00 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:09 +0000 (12:34 +0200)
src/lib-http/http-client.c
src/lib-http/http-client.h

index 92428ccce88abc48d7c0853b9c2f76361e919e23..6f4b739827b05480839319e5c2338579d24ef2c2 100644 (file)
@@ -192,6 +192,19 @@ struct http_client *http_client_init(const struct http_client_settings *set,
                                       event_parent);
 }
 
+int http_client_init_auto(struct event *event_parent,
+                         struct http_client **client_r, const char **error_r)
+{
+       const struct http_client_settings *set;
+
+       if (settings_get(event_parent, &http_client_setting_parser_info,
+                        0, &set, error_r) < 0)
+               return -1;
+       *client_r = http_client_init(set, event_parent);
+       settings_free(set);
+       return 0;
+}
+
 struct http_client *
 http_client_init_private(const struct http_client_settings *set,
                         struct event *event_parent)
@@ -199,6 +212,20 @@ http_client_init_private(const struct http_client_settings *set,
        return http_client_init_shared(NULL, set, event_parent);
 }
 
+int http_client_init_private_auto(struct event *event_parent,
+                                 struct http_client **client_r,
+                                 const char **error_r)
+{
+       const struct http_client_settings *set;
+
+       if (settings_get(event_parent, &http_client_setting_parser_info,
+                        0, &set, error_r) < 0)
+               return -1;
+       *client_r = http_client_init_private(set, event_parent);
+       settings_free(set);
+       return 0;
+}
+
 void http_client_deinit(struct http_client **_client)
 {
        struct http_client *client = *_client;
index 753dd7b51fe98dcbca8ecb951dedb1a94e585cb8..7d7d2bdc4758c6a767b6659493c33b2b428aa84f 100644 (file)
@@ -472,10 +472,17 @@ void http_client_request_start_tunnel(struct http_client_request *req,
    be overriden for specific requests with http_client_request_set_event(). */
 struct http_client *http_client_init(const struct http_client_settings *set,
                                     struct event *event_parent);
+/* Same as http_client_init(), but pull settings automatically. */
+int http_client_init_auto(struct event *event_parent,
+                         struct http_client **client_r, const char **error_r);
 /* Create a client without a shared context. */
 struct http_client *
 http_client_init_private(const struct http_client_settings *set,
                         struct event *event_parent);
+/* Same as http_client_init_private(), but pull settings automatically. */
+int http_client_init_private_auto(struct event *event_parent,
+                                 struct http_client **client_r,
+                                 const char **error_r);
 struct http_client *
 http_client_init_shared(struct http_client_context *cctx,
                        const struct http_client_settings *set,