Skip to content

Commit

Permalink
jmap_api.c: store non-standard methods in separate hash table
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Sep 6, 2023
1 parent 225f0d1 commit 04e6c0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions imap/http_jmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct namespace_t namespace_jmap = {
*/

static jmap_settings_t my_jmap_settings = {
HASH_TABLE_INITIALIZER,
HASH_TABLE_INITIALIZER,
NULL,
{ 0 },
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions imap/jmap_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions imap/jmap_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04e6c0c

Please sign in to comment.