Skip to content

Commit

Permalink
jmap_patchobject_apply() now has a fourth (flags) argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Jul 26, 2023
1 parent 99d9e0a commit e301bd7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 26 deletions.
22 changes: 11 additions & 11 deletions imap/jmap_calendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ static void patch_current_defaultalerts_into_args(json_t *arg,
json_t *cur = json_object(); /* Container for current defaultAlerts */
json_object_set(cur, propname, cur_alerts);

json_t *new = jmap_patchobject_apply(cur, patches, parser->invalid);
json_t *new = jmap_patchobject_apply(cur, patches, parser->invalid, 0);

/* Add patched defaultAlerts to /set args */
json_object_foreach(new, field, jval) {
Expand Down Expand Up @@ -2966,7 +2966,7 @@ static int getcalendarevents_getinstances(json_t *jsevent,
if (override) {
if (json_object_get(override, "excluded") != json_true()) {
/* Instance is a recurrence override */
json_t *myevent = jmap_patchobject_apply(jsevent, override, NULL);
json_t *myevent = jmap_patchobject_apply(jsevent, override, NULL, 0);
getcalendarevents_filterinstance(myevent, props, eid->raw, cdata->ical_uid);
if (json_object_get(override, "start") == NULL) {
json_object_set_new(myevent, "start", json_string(jscalrecurid));
Expand Down Expand Up @@ -4917,14 +4917,14 @@ static void updateevent_apply_patch_override(struct jmap_caleventid *eid,
json_t *new_override = NULL;
if (old_override) {
/* Patch an existing override */
json_t *old_instance = jmap_patchobject_apply(old_event, old_override, NULL);
new_instance = jmap_patchobject_apply(old_instance, event_patch, invalid);
json_t *old_instance = jmap_patchobject_apply(old_event, old_override, NULL, 0);
new_instance = jmap_patchobject_apply(old_instance, event_patch, invalid, 0);
updateevent_validate_ids(old_instance, new_instance, invalid);
json_decref(old_instance);
}
else {
/* Create a new override */
new_instance = jmap_patchobject_apply(old_event, event_patch, invalid);
new_instance = jmap_patchobject_apply(old_event, event_patch, invalid, 0);
updateevent_validate_ids(old_event, new_instance, invalid);
}
if (!new_instance) {
Expand Down Expand Up @@ -5029,7 +5029,7 @@ static void updateevent_apply_patch_event(json_t *old_event,
/* Apply patch to main event */
json_t *old_mainevent = json_deep_copy(old_event);
json_object_del(old_mainevent, "recurrenceOverrides");
new_event = jmap_patchobject_apply(old_mainevent, mainevent_patch, invalid);
new_event = jmap_patchobject_apply(old_mainevent, mainevent_patch, invalid, 0);
if (!new_event) {
*err = json_pack("{s:s}", "type", "invalidPatch");
json_decref(old_mainevent);
Expand All @@ -5046,7 +5046,7 @@ static void updateevent_apply_patch_event(json_t *old_event,
json_object_set(old_exp_overrides, recurid, old_override);
continue;
}
json_t *override = jmap_patchobject_apply(new_event, old_override, NULL);
json_t *override = jmap_patchobject_apply(new_event, old_override, NULL, 0);
if (override) {
json_object_set_new(old_exp_overrides, recurid, override);
}
Expand All @@ -5060,7 +5060,7 @@ static void updateevent_apply_patch_event(json_t *old_event,
json_t *new_exp_overrides = NULL;
if (json_object_size(old_exp_overrides)) {
json_t *old_wrapper = json_pack("{s:O}", "recurrenceOverrides", old_exp_overrides);
json_t *new_wrapper = jmap_patchobject_apply(old_wrapper, overrides_patch, invalid);
json_t *new_wrapper = jmap_patchobject_apply(old_wrapper, overrides_patch, invalid, 0);
if (!new_wrapper) {
*err = json_pack("{s:s}", "type", "invalidPatch");
json_decref(old_wrapper);
Expand Down Expand Up @@ -5109,7 +5109,7 @@ static void updateevent_apply_patch_event(json_t *old_event,
}
else {
/* Apply the patch as provided */
new_event = jmap_patchobject_apply(old_event, event_patch, invalid);
new_event = jmap_patchobject_apply(old_event, event_patch, invalid, 0);
if (!new_event) {
*err = json_pack("{s:s}", "type", "invalidPatch");
goto done;
Expand Down Expand Up @@ -7647,7 +7647,7 @@ static void _calendarevent_copy(jmap_req_t *req,
context_begin_cdata(jmapctx, mbentry, cdata);
json_t *src_event = jmapical_tojmap(src_ical, NULL, jmapctx);
if (src_event) {
dst_event = jmap_patchobject_apply(src_event, jevent, NULL);
dst_event = jmap_patchobject_apply(src_event, jevent, NULL, 0);
}
json_decref(src_event);
if (!dst_event) {
Expand Down Expand Up @@ -9303,7 +9303,7 @@ static int principal_getavailability_ical_cb(icalcomponent *comp,
json_t *jval;
json_object_foreach(joverrides, recurid, jval) {
if (!strcmpsafe(recurid, buf_cstring(rock->buf))) {
jevent = jmap_patchobject_apply(rock->jevent, jval, NULL);
jevent = jmap_patchobject_apply(rock->jevent, jval, NULL, 0);
break;
}
}
Expand Down
17 changes: 10 additions & 7 deletions imap/jmap_contact.c
Original file line number Diff line number Diff line change
Expand Up @@ -5182,7 +5182,7 @@ static int _contact_set_update(jmap_req_t *req, unsigned kind,
r = HTTP_UNPROCESSABLE;
goto done;
}
jupdated = jmap_patchobject_apply(jcurrent, jcard, NULL);
jupdated = jmap_patchobject_apply(jcurrent, jcard, NULL, 0);
json_decref(jcurrent);
if (JNOTNULL(jupdated)) {
json_object_del(jupdated, "addressbookId");
Expand Down Expand Up @@ -5379,7 +5379,7 @@ static void _contact_copy(jmap_req_t *req,
goto done;
}

dst_card = jmap_patchobject_apply(src_card, jcard, NULL);
dst_card = jmap_patchobject_apply(src_card, jcard, NULL, 0);
json_object_del(dst_card, "id"); // immutable and WILL change
json_decref(src_card);

Expand Down Expand Up @@ -7180,7 +7180,7 @@ static json_t *jmap_card_from_vcard(const char *userid,
hash_enumerate(&props_by_name, &props_by_name_cb, &crock);

if (crock.patch) {
json_t *patched = jmap_patchobject_apply(jcard, crock.patch, NULL);
json_t *patched = jmap_patchobject_apply(jcard, crock.patch, NULL, 0);

json_decref(crock.patch);
json_decref(jcard);
Expand Down Expand Up @@ -8489,7 +8489,8 @@ static unsigned _jsmultiobject_to_card(struct jmap_parser *parser, json_t *jval,

json_object_foreach(patches, lang, jpatch) {
json_t *altobj =
jmap_patchobject_apply(obj, jpatch, parser->invalid);
jmap_patchobject_apply(obj, jpatch,
parser->invalid, PATCH_ALLOW_ARRAY);

if (altobj) {
const char *this_lang =
Expand Down Expand Up @@ -8796,7 +8797,8 @@ static unsigned _jsname_to_vcard(struct jmap_parser *parser, json_t *jval,

json_object_foreach(patches, lang, jpatch) {
json_t *altname =
jmap_patchobject_apply(jval, jpatch, parser->invalid);
jmap_patchobject_apply(jval, jpatch,
parser->invalid, PATCH_ALLOW_ARRAY);

if (altname) {
struct l10n_by_id_t my_l10n = { l10n->deflang, lang, NULL };
Expand Down Expand Up @@ -9108,7 +9110,8 @@ static unsigned _jsspeak_to_vcard(struct jmap_parser *parser,

json_object_foreach(patches, lang, jpatch) {
json_t *altobj =
jmap_patchobject_apply(jval, jpatch, parser->invalid);
jmap_patchobject_apply(jval, jpatch,
parser->invalid, PATCH_ALLOW_ARRAY);

if (altobj) {
struct l10n_by_id_t my_l10n = { l10n->deflang, lang, NULL };
Expand Down Expand Up @@ -10749,7 +10752,7 @@ static int _card_set_update(jmap_req_t *req, unsigned kind,
vcardcomponent_free(vcard);

/* Apply the patch as provided */
json_t *new_obj = jmap_patchobject_apply(old_obj, jcard, invalid);
json_t *new_obj = jmap_patchobject_apply(old_obj, jcard, invalid, 0);

json_decref(old_obj);
if (!new_obj) {
Expand Down
2 changes: 1 addition & 1 deletion imap/jmap_ical.c
Original file line number Diff line number Diff line change
Expand Up @@ -7299,7 +7299,7 @@ static void overrides_to_ical(icalcomponent *comp,

/* Create overridden event from patch and master event */
json_t *ex;
if (!(ex = jmap_patchobject_apply(master, myoverride, NULL))) {
if (!(ex = jmap_patchobject_apply(master, myoverride, NULL, 0))) {
jmap_parser_invalid(parser, recuridval);
json_decref(myoverride);
continue;
Expand Down
8 changes: 4 additions & 4 deletions imap/jmap_mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -11886,7 +11886,7 @@ static int _email_bulkupdate_plan_keywords(struct email_bulkupdate *bulk, ptrarr
json_t *aggregated_keywords = _email_bulkupdate_aggregate_keywords(bulk,
uidrec->email_id, &seenseq_by_mbox_id);
update->full_keywords = jmap_patchobject_apply(aggregated_keywords,
update->keywords, NULL);
update->keywords, NULL, 0);
json_decref(aggregated_keywords);
}
else {
Expand Down Expand Up @@ -11928,7 +11928,7 @@ static int _email_bulkupdate_plan_keywords(struct email_bulkupdate *bulk, ptrarr
_email_keywords_fini(&keywords);
json_t *new_keywords;
if (update->patch_keywords) {
new_keywords = jmap_patchobject_apply(current_keywords, update->keywords, NULL);
new_keywords = jmap_patchobject_apply(current_keywords, update->keywords, NULL, 0);
}
else {
new_keywords = json_incref(update->keywords);
Expand Down Expand Up @@ -12007,7 +12007,7 @@ static int _email_bulkupdate_plan_snooze(struct email_bulkupdate *bulk,
update->snoozed_uidrec->uid);
json_t *patch = update->snoozed;

update->snoozed = jmap_patchobject_apply(orig, patch, NULL);
update->snoozed = jmap_patchobject_apply(orig, patch, NULL, 0);
json_decref(orig);
json_decref(patch);
}
Expand Down Expand Up @@ -12899,7 +12899,7 @@ static void _email_update_bulk(jmap_req_t *req,
json_pack("{s:s}", "type", "notFound"));
}
else {
json_t *new = jmap_patchobject_apply(cur, update->mailboxids, NULL);
json_t *new = jmap_patchobject_apply(cur, update->mailboxids, NULL, 0);
if (!json_object_size(new)) {
jmap_parser_invalid(&parser, "mailboxIds");
}
Expand Down
2 changes: 1 addition & 1 deletion imap/jmap_mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,7 @@ static int _mbox_update_validate_serverset(jmap_req_t *req,
json_t *jcurRights = _mbox_get_myrights(req, mbentry);
json_t *jold = json_pack("{s:o}", "myRights", json_copy(jcurRights));
json_t *invalid = json_array();
json_t *jnew = jmap_patchobject_apply(jold, jpatch, invalid);
json_t *jnew = jmap_patchobject_apply(jold, jpatch, invalid, 0);
if (json_array_size(invalid) == 0) {
json_t *jnewRights = json_object_get(jnew, "myRights");
if (!json_equal(jcurRights, jnewRights)) {
Expand Down
2 changes: 1 addition & 1 deletion imap/jmap_notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ static void _notes_update_cb(const char *id, message_t *msg,
id, error_message(r));
}
else {
json_t *new_note = jmap_patchobject_apply(note, patch, NULL);
json_t *new_note = jmap_patchobject_apply(note, patch, NULL, 0);

if (new_note) {
r = _note_create(msg_mailbox(msg), new_note, &updated_note);
Expand Down
2 changes: 1 addition & 1 deletion imap/jmap_vacation.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ static void vacation_update(struct jmap_req *req,

/* Update VacationResponse object */

json_t *new_vacation = jmap_patchobject_apply(vacation, patch, NULL);
json_t *new_vacation = jmap_patchobject_apply(vacation, patch, NULL, 0);
json_decref(vacation);
vacation = new_vacation;

Expand Down

0 comments on commit e301bd7

Please sign in to comment.