From 04e6c0c9429703b2a039f8d00c95d0c49a831b9a Mon Sep 17 00:00:00 2001 From: Ken Murchison Date: Wed, 6 Sep 2023 14:00:58 -0400 Subject: [PATCH] jmap_api.c: store non-standard methods in separate hash table --- imap/http_jmap.c | 3 +++ imap/jmap_api.c | 20 ++++++++++++++++---- imap/jmap_api.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/imap/http_jmap.c b/imap/http_jmap.c index 7885d983381..85dbbabb062 100644 --- a/imap/http_jmap.c +++ b/imap/http_jmap.c @@ -149,6 +149,7 @@ struct namespace_t namespace_jmap = { */ static jmap_settings_t my_jmap_settings = { + HASH_TABLE_INITIALIZER, HASH_TABLE_INITIALIZER, NULL, { 0 }, @@ -182,6 +183,7 @@ static void jmap_init(struct buf *serverinfo) initialize_JMAP_error_table(); construct_hash_table(&my_jmap_settings.methods, 128, 0); + construct_hash_table(&my_jmap_settings.methods_nonstandard, 128, 0); my_jmap_settings.server_capabilities = json_object(); jmap_core_init(&my_jmap_settings); @@ -240,6 +242,7 @@ static void jmap_reset(void) static void jmap_shutdown(void) { free_hash_table(&my_jmap_settings.methods, NULL); + free_hash_table(&my_jmap_settings.methods_nonstandard, NULL); json_decref(my_jmap_settings.server_capabilities); ptrarray_fini(&my_jmap_settings.getblob_handlers); int i; diff --git a/imap/jmap_api.c b/imap/jmap_api.c index 457c2eba14c..bcb25cd3a94 100644 --- a/imap/jmap_api.c +++ b/imap/jmap_api.c @@ -430,9 +430,21 @@ HIDDEN void jmap_finireq(jmap_req_t *req) req->perf_details = NULL; } -static jmap_method_t *find_methodproc(const char *name, hash_table *jmap_methods) +static const jmap_method_t *find_methodproc(const char *name, + strarray_t *using_capabilities, + jmap_settings_t *settings) { - return hash_lookup(name, jmap_methods); + const jmap_method_t *mp = hash_lookup(name, &settings->methods); + + if (!mp || strarray_find(using_capabilities, mp->capability, 0) < 0) { + mp = hash_lookup(name, &settings->methods_nonstandard); + + if (mp && strarray_find(using_capabilities, mp->capability, 0) < 0) { + mp = NULL; + } + } + + return mp; } struct mbstate { @@ -724,8 +736,8 @@ HIDDEN int jmap_api(struct transaction_t *txn, json_incref(args); /* Find the message processor */ - mp = find_methodproc(mname, &settings->methods); - if (!mp || strarray_find(&using_capabilities, mp->capability, 0) < 0) { + mp = find_methodproc(mname, &using_capabilities, settings); + if (!mp) { json_array_append_new(resp, json_pack("[s {s:s} s]", "error", "type", "unknownMethod", tag)); json_decref(args); diff --git a/imap/jmap_api.h b/imap/jmap_api.h index fa3b4c6cd0e..8b9257868a8 100644 --- a/imap/jmap_api.h +++ b/imap/jmap_api.h @@ -125,6 +125,7 @@ enum { typedef struct { hash_table methods; + hash_table methods_nonstandard; json_t *server_capabilities; int64_t limits[JMAP_NUM_LIMITS]; // internal state