]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-oauth2: Move oauth2_parse_json() to oauth2-request.c.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 5 Jun 2020 19:00:03 +0000 (21:00 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 7 Dec 2020 08:59:28 +0000 (08:59 +0000)
src/lib-oauth2/oauth2-request.c
src/lib-oauth2/oauth2.c

index ce3ec649471e330fdea1483fbe14820e5194dad9..e72e39d824045b29ba8de57f7103cf7a87915e34 100644 (file)
@@ -72,6 +72,57 @@ oauth2_request_continue(struct oauth2_request *req, const char *error)
        oauth2_request_callback(req, &res);
 }
 
+void oauth2_parse_json(struct oauth2_request *req)
+{
+       enum json_type type;
+       const char *token, *error;
+       int ret;
+
+       while((ret = json_parse_next(req->parser, &type, &token)) > 0) {
+               if (req->field_name == NULL) {
+                       if (type != JSON_TYPE_OBJECT_KEY) break;
+                       /* cannot use t_strdup because we might
+                          have to read more */
+                       req->field_name = p_strdup(req->pool, token);
+               } else if (type < JSON_TYPE_STRING) {
+                       /* this should be last allocation */
+                       p_free(req->pool, req->field_name);
+                       json_parse_skip(req->parser);
+               } else {
+                       if (!array_is_created(&req->fields))
+                               p_array_init(&req->fields, req->pool, 4);
+                       struct oauth2_field *field =
+                               array_append_space(&req->fields);
+                       field->name = req->field_name;
+                       req->field_name = NULL;
+                       field->value = p_strdup(req->pool, token);
+               }
+       }
+
+       /* read more */
+       if (ret == 0) return;
+
+       io_remove(&req->io);
+
+       if (ret > 0) {
+               (void)json_parser_deinit(&req->parser, &error);
+               error = "Invalid response data";
+       } else if (i_stream_read_eof(req->is) &&
+                  req->is->v_offset == 0 && req->is->stream_errno == 0) {
+               /* discard error, empty response is OK. */
+               (void)json_parser_deinit(&req->parser, &error);
+               error = NULL;
+       } else if (json_parser_deinit(&req->parser, &error) == 0) {
+               error = NULL;
+       } else {
+               i_assert(error != NULL);
+       }
+
+       i_stream_unref(&req->is);
+
+       req->json_parsed_cb(req, error);
+}
+
 static void
 oauth2_request_response(const struct http_response *response,
                        struct oauth2_request *req)
index 06ed743e2dc63785fe7e070023c486df7dfc2833..295c98c12afea2d97d1bf7ac4acdaf7ef75aa43d 100644 (file)
@@ -1,7 +1,6 @@
 /* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "ioloop.h"
 #include "istream.h"
 #include "http-client.h"
 #include "json-tree.h"
@@ -35,57 +34,6 @@ int oauth2_json_tree_build(const buffer_t *json, struct json_tree **tree_r,
        return ret;
 }
 
-void oauth2_parse_json(struct oauth2_request *req)
-{
-       enum json_type type;
-       const char *token, *error;
-       int ret;
-
-       while((ret = json_parse_next(req->parser, &type, &token)) > 0) {
-               if (req->field_name == NULL) {
-                       if (type != JSON_TYPE_OBJECT_KEY) break;
-                       /* cannot use t_strdup because we might
-                          have to read more */
-                       req->field_name = p_strdup(req->pool, token);
-               } else if (type < JSON_TYPE_STRING) {
-                       /* this should be last allocation */
-                       p_free(req->pool, req->field_name);
-                       json_parse_skip(req->parser);
-               } else {
-                       if (!array_is_created(&req->fields))
-                               p_array_init(&req->fields, req->pool, 4);
-                       struct oauth2_field *field =
-                               array_append_space(&req->fields);
-                       field->name = req->field_name;
-                       req->field_name = NULL;
-                       field->value = p_strdup(req->pool, token);
-               }
-       }
-
-       /* read more */
-       if (ret == 0) return;
-
-       io_remove(&req->io);
-
-       if (ret > 0) {
-               (void)json_parser_deinit(&req->parser, &error);
-               error = "Invalid response data";
-       } else if (i_stream_read_eof(req->is) &&
-                  req->is->v_offset == 0 && req->is->stream_errno == 0) {
-               /* discard error, empty response is OK. */
-               (void)json_parser_deinit(&req->parser, &error);
-               error = NULL;
-       } else if (json_parser_deinit(&req->parser, &error) == 0) {
-               error = NULL;
-       } else {
-               i_assert(error != NULL);
-       }
-
-       i_stream_unref(&req->is);
-
-       req->json_parsed_cb(req, error);
-}
-
 void oauth2_request_abort(struct oauth2_request **_req)
 {
        struct oauth2_request *req = *_req;