Skip to content

Commit

Permalink
Merge pull request cyrusimap#4432 from cyrusimap/dav_sharing_reply_co…
Browse files Browse the repository at this point in the history
…mmon_name

DAV sharing invite-reply common-name
  • Loading branch information
ksmurchison authored Mar 15, 2023
2 parents 6aaabab + 758c40f commit ef6a684
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 15 deletions.
25 changes: 25 additions & 0 deletions cassandane/Cassandane/Cyrus/Caldav.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use warnings;
use DateTime;
use JSON::XS;
use Net::CalDAVTalk 0.12;
use Net::DAVTalk::XMLParser;
use File::Basename;
use Data::Dumper;
use Text::VCardFast;

Expand Down Expand Up @@ -2322,6 +2324,29 @@ EOF
$CalDAV->Request('POST', $notification, $reply,
'Content-Type' => 'application/davsharing+xml');

xlog $self, "fetch invite reply";
($adds) = $mantalk->SyncEventLinks("/dav/notifications/user/manifold");
$self->assert_equals(scalar %$adds, 1);
$notification = (keys %$adds)[0];

my $res = $mantalk->Request('GET', $notification);
my $xml = xmlToHash($res->{content});
my $CS = 'http://calendarserver.org/ns/';
$reply = $xml->{"{$CS}invite-reply"};
$self->assert_not_null($reply);
$self->assert_not_null($reply->{"{$CS}invite-accepted"});
$self->assert_str_equals($mantalk->fullpath($CalendarId) . "/",
$reply->{"{$CS}hosturl"}{'{DAV:}href'}{content});
$self->assert_str_equals(basename($notification),
$reply->{"{$CS}in-reply-to"}{content});

# need to version-gate features that aren't in 3.0...
my ($maj, $min) = Cassandane::Instance->get_version();
if ($maj > 3 || ($maj == 3 && $min >= 9)) {
$self->assert_str_equals('Test User',
$reply->{"{$CS}common-name"}{content});
}

xlog $self, "get calendars as manifold";
my $ManCal = $mantalk->GetCalendars();
$self->assert_num_equals(2, scalar @$ManCal);
Expand Down
35 changes: 20 additions & 15 deletions imap/http_dav.c
Original file line number Diff line number Diff line change
Expand Up @@ -1858,30 +1858,35 @@ int proppatch_principalname(xmlNodePtr prop, unsigned set,
return 0;
}

/* Callback to fetch DAV:displayname for principals */
static int propfind_principalname(const xmlChar *name, xmlNsPtr ns,
struct propfind_ctx *fctx,
xmlNodePtr prop __attribute__((unused)),
xmlNodePtr resp __attribute__((unused)),
struct propstat propstat[],
void *rock __attribute__((unused)))
HIDDEN void dav_get_principalname(const char *userid, struct buf *buf)
{
/* XXX Do LDAP/SQL lookup here */
buf_reset(&fctx->buf);
buf_reset(buf);

if (fctx->req_tgt->userid) {
if (userid) {
const char *annotname = DAV_ANNOT_NS "<" XML_NS_DAV ">displayname";
char *mailboxname = caldav_mboxname(fctx->req_tgt->userid, NULL);
int r = annotatemore_lookupmask(mailboxname, annotname,
fctx->req_tgt->userid, &fctx->buf);
char *mailboxname = caldav_mboxname(userid, NULL);
int r = annotatemore_lookupmask(mailboxname, annotname, userid, buf);

free(mailboxname);
if (r || !buf_len(&fctx->buf)) {
buf_printf(&fctx->buf, "%s", fctx->req_tgt->userid);
if (r || !buf_len(buf)) {
buf_setcstr(buf, userid);
}
}
else {
buf_printf(&fctx->buf, "no userid");
buf_setcstr(buf, "no userid");
}
}

/* Callback to fetch DAV:displayname for principals */
static int propfind_principalname(const xmlChar *name, xmlNsPtr ns,
struct propfind_ctx *fctx,
xmlNodePtr prop __attribute__((unused)),
xmlNodePtr resp __attribute__((unused)),
struct propstat propstat[],
void *rock __attribute__((unused)))
{
dav_get_principalname(fctx->req_tgt->userid, &fctx->buf);

xml_add_prop(HTTP_OK, fctx->ns[NS_DAV], &propstat[PROPSTAT_OK],
name, ns, BAD_CAST buf_cstring(&fctx->buf), 0);
Expand Down
3 changes: 3 additions & 0 deletions imap/http_dav.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,7 @@ int proppatch_restype(xmlNodePtr prop, unsigned set, struct proppatch_ctx *pctx,
int principal_parse_path(const char *path, struct request_target_t *tgt,
const char **resultstr);

void dav_get_principalname(const char *userid, struct buf *buf);


#endif /* HTTP_DAV_H */
20 changes: 20 additions & 0 deletions imap/http_dav_sharing.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,26 @@ static int notify_get(struct transaction_t *txn, struct mailbox *mailbox,
xmlNewChild(reply, NULL, BAD_CAST "summary", comment);
xmlFree(comment);
}

if (sharee) {
struct request_target_t tgt = { .allow = ALLOW_CAL };
xmlChar *princ_path = xmlNodeGetContent(sharee);
const char *errstr = NULL;

if (principal_parse_path((const char *) princ_path,
&tgt, &errstr) == 0) {
struct buf name = BUF_INITIALIZER;

dav_get_principalname(tgt.userid, &name);
request_target_fini(&tgt);

xmlNewChild(reply, NULL,
BAD_CAST "common-name", BAD_CAST buf_cstring(&name));
buf_free(&name);
}

xmlFree(princ_path);
}
}
else {
/* Unknown type - return as-is */
Expand Down

0 comments on commit ef6a684

Please sign in to comment.