4 * Copyright (c) 1996-2018 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
19 * Fetch a user photo (avatar)
21 void fetch_user_photo(struct http_transaction *h, struct ctdlsession *c)
25 extract_token(username, h->uri, 3, '/', sizeof username);
27 do_404(h); // FIXME finish this
32 * Fetch a user bio (profile)
34 void fetch_user_bio(struct http_transaction *h, struct ctdlsession *c)
38 extract_token(username, h->uri, 3, '/', sizeof username);
40 do_404(h); // FIXME finish this
45 * Client requested an object related to a user.
47 void object_in_user(struct http_transaction *h, struct ctdlsession *c)
51 char unescaped_euid[1024];
53 extract_token(buf, h->uri, 4, '/', sizeof buf);
55 if (!strcasecmp(buf, "userpic")) { // user photo (avatar)
56 fetch_user_photo(h, c);
60 if (!strcasecmp(buf, "bio")) { // user bio (profile)
65 do_404(h); // unknown object
71 * Handle REST/DAV requests for the user itself (such as /ctdl/u/username
72 * or /ctdl/i/username/ but *not* specific properties of the user)
74 void the_user_itself(struct http_transaction *h, struct ctdlsession *c)
81 * Dispatcher for "/ctdl/u" and "/ctdl/u/" for the user list
83 void user_list(struct http_transaction *h, struct ctdlsession *c)
90 * Dispatcher for paths starting with /ctdl/u/
92 void ctdl_u(struct http_transaction *h, struct ctdlsession *c)
94 char requested_username[128];
97 // All user-related functions require accessing the user in question.
98 extract_token(requested_username, h->uri, 3, '/', sizeof requested_username);
99 unescape_input(requested_username);
101 if (IsEmptyStr(requested_username)) { // /ctdl/u/
106 // Try to access the user...
107 if (strcasecmp(requested_username, c->room)) {
114 // At this point we have accessed the requested user account.
115 if (num_tokens(h->uri, '/') == 4) { // /ctdl/u/username
116 the_user_itself(h, c);
120 extract_token(buf, h->uri, 4, '/', sizeof buf);
121 if (num_tokens(h->uri, '/') == 5) {
122 if (IsEmptyStr(buf)) {
123 the_user_itself(h, c); // /ctdl/u/username/ ( same as /ctdl/u/username )
125 object_in_user(h, c); // /ctdl/u/username/object
130 if (num_tokens(h->uri, '/') == 6) {
131 object_in_user(h, c); // /ctdl/u/username/object/ or possibly /ctdl/u/username/object/component
135 // If we get to this point, the client specified a valid user but requested an action we don't know how to perform.