Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMAP PushSubscription #4149

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

JMAP PushSubscription #4149

wants to merge 12 commits into from

Conversation

ksmurchison
Copy link
Contributor

Start of JMAP PushSubscription support

@ksmurchison ksmurchison requested review from rsto and removed request for rsto June 26, 2022 14:33
@ksmurchison ksmurchison marked this pull request as draft June 27, 2022 12:14
imap/jmap_push_subscription.c Show resolved Hide resolved
imap/jmap_push_subscription.c Show resolved Hide resolved
imap/jmap_push_subscription.c Show resolved Hide resolved
imap/jmap_push_subscription.c Outdated Show resolved Hide resolved
imap/jmap_push_subscription.c Outdated Show resolved Hide resolved
imap/mailbox.c Show resolved Hide resolved
imap/mailbox.c Show resolved Hide resolved
imap/pushsub_db.c Outdated Show resolved Hide resolved
unsigned isverified;
int alive;
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reordaring the elements to

struct pushsub_data_new {
    const char *mailbox;
    const char *id;
    const char *subscription;
    unsigned rowid;
    unsigned isverified;
    time_t expires;
    int alive;
};

will reduce the data needed for the structure. (but it depends how the struct is used)

#include <time.h>
#include <stdio.h>
#include <stdint.h>

struct pushsub_data {
    unsigned rowid;
    const char *mailbox;
    uint32_t imap_uid;
    const char *id;
    const char *subscription;
    time_t expires;
    unsigned isverified;
    int alive;
};

struct pushsub_data_new {
    const char *mailbox;
    const char *id;
    const char *subscription;
    unsigned rowid;
    unsigned isverified;
    time_t expires;
    int alive;
};


int main() {
  printf("%lu\n", sizeof(struct pushsub_data));
  printf("%lu\n", sizeof(struct pushsub_data_new));
  return 0;
}

prints

$ clang -Wpadded pad.c -o pad && ./pad
pad.c:7:17: warning: padding struct 'struct pushsub_data' with 4 bytes to align 'mailbox' [-Wpadded]
    const char *mailbox;
                ^
pad.c:9:17: warning: padding struct 'struct pushsub_data' with 4 bytes to align 'id' [-Wpadded]
    const char *id;
                ^
pad.c:16:8: warning: padding size of 'struct pushsub_data_new' with 4 bytes to alignment boundary [-Wpadded]
struct pushsub_data_new {
       ^
3 warnings generated.
56
48

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing struct matches those in the other *_db.h files. I'm not sure we are too worried about 8 bytes

*
*/

#include <config.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include "config.h"? Thus "" instead of <>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing #include matches the other source files

@ksmurchison ksmurchison force-pushed the jmappushsub branch 2 times, most recently from a552b80 to e833ca2 Compare October 27, 2022 14:18
@ksmurchison ksmurchison force-pushed the jmappushsub branch 2 times, most recently from c9463ee to c781e2b Compare October 10, 2023 16:39
@ksmurchison ksmurchison force-pushed the jmappushsub branch 2 times, most recently from 5ebe9cb to 6ed09c3 Compare October 17, 2023 22:35
@ksmurchison ksmurchison requested review from brong and rsto February 5, 2024 20:27
@ksmurchison ksmurchison marked this pull request as ready for review February 5, 2024 20:27
@ksmurchison ksmurchison requested a review from elliefm February 5, 2024 20:28
Copy link
Contributor

@elliefm elliefm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay on a first read, a few nits here and there

fprintf(f, "Message-ID: <%s@%s>\r\n", id, config_servername);

fputs("Content-Type: application/json; charset=utf-8\r\n", f);
fprintf(f, "Content-Length: %lu\r\n", datalen);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler will whinge about %lu on platforms where size_t is not unsigned long, IIRC maybe the BSDs are like this. We have SIZE_T_FMT to deal with it:

Suggested change
fprintf(f, "Content-Length: %lu\r\n", datalen);
fprintf(f, "Content-Length: " SIZE_T_FMT "\r\n", datalen);

fwrite(data, datalen, 1, f);
free(data);

fclose(f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check if we've successfully written this file, and bail out if it went wrong?

append_abort(&as);
}
else {
/* Commit the append to the sieve mailbox */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sieve mailbox?

Comment on lines +67 to +79
enum {
STMT_SELRSRC,
STMT_SELUID,
STMT_SELMBOX,
STMT_INSERT,
STMT_UPDATE,
STMT_DELETE,
STMT_BEGIN,
STMT_COMMIT,
STMT_ROLLBACK
};

#define NUM_STMT 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's 9 of them, not 10?

Comment on lines +403 to +404
syslog(LOG_ERR, "IOERROR: failed to open %s (%s)",
mboxname, error_message(r));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOERRORs should use xsyslog


buf_setcstr(&boxbuf, config_getstring(IMAPOPT_JMAPPUSHSUBSCRIPTIONFOLDER));

res = mboxname_user_mbox(userid, buf_cstring(&boxbuf));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be something like res = mboxname_user_mbox(userid, config_getstring(...));? I don't see what the struct buf gets us here. Maybe it's leftover from an earlier implementation?

@rsto rsto removed their request for review August 20, 2024 06:13
@ksmurchison ksmurchison self-assigned this Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants