New file user_functions.c contains skeleton code for the /ctdl/u/... calls
[citadel.git] / webcit-ng / user_functions.c
1 /*
2  * User functions
3  *
4  * Copyright (c) 1996-2018 by the citadel.org team
5  *
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.
8  *
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.
13  */
14
15 #include "webcit.h"
16
17
18 /*
19  * Client requested an object related to a user.
20  */
21 void object_in_user(struct http_transaction *h, struct ctdlsession *c)
22 {
23         char buf[1024];
24         long msgnum = (-1);
25         char unescaped_euid[1024];
26
27         extract_token(buf, h->uri, 4, '/', sizeof buf);
28
29         if (!strcasecmp(buf, "userpic")) {              // FIXME do this
30                 do_404(h);
31                 return;
32         }
33
34         do_404(h);                                      // unknown object
35         return;
36 }
37
38
39 /*
40  * Handle REST/DAV requests for the user itself (such as /ctdl/u/username
41  * or /ctdl/i/username/ but *not* specific properties of the user)
42  */
43 void the_user_itself(struct http_transaction *h, struct ctdlsession *c)
44 {
45         do_404(h);
46 }
47
48
49 /*
50  * Dispatcher for "/ctdl/u" and "/ctdl/u/" for the user list
51  */
52 void user_list(struct http_transaction *h, struct ctdlsession *c)
53 {
54         do_404(h);
55 }
56
57
58 /*
59  * Dispatcher for paths starting with /ctdl/u/
60  */
61 void ctdl_u(struct http_transaction *h, struct ctdlsession *c)
62 {
63         char requested_username[128];
64         char buf[1024];
65
66         // All user-related functions require accessing the user in question.
67         extract_token(requested_username, h->uri, 3, '/', sizeof requested_username);
68         unescape_input(requested_username);
69
70         if (IsEmptyStr(requested_username)) {   //      /ctdl/u/
71                 user_list(h, c);
72                 return;
73         }
74
75         // Try to access the user...
76         if (strcasecmp(requested_username, c->room)) {
77                 do_404(h);
78         } else {
79                 do_404(h);
80                 return;
81         }
82
83         // At this point we have accessed the requested user account.
84         if (num_tokens(h->uri, '/') == 4) {     //      /ctdl/u/username
85                 the_user_itself(h, c);
86                 return;
87         }
88
89         extract_token(buf, h->uri, 4, '/', sizeof buf);
90         if (num_tokens(h->uri, '/') == 5) {
91                 if (IsEmptyStr(buf)) {
92                         the_user_itself(h, c);  //      /ctdl/u/username/       ( same as /ctdl/u/username )
93                 } else {
94                         object_in_user(h, c);   //      /ctdl/u/username/object
95                 }
96                 return;
97         }
98
99         if (num_tokens(h->uri, '/') == 6) {
100                 object_in_user(h, c);   //      /ctdl/u/username/object/ or possibly /ctdl/u/username/object/component
101                 return;
102         }
103
104         // If we get to this point, the client specified a valid user but requested an action we don't know how to perform.
105         do_404(h);
106 }