object_in_user() is a master function which calls slave functions fetch_user_bio...
[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  * Fetch a user photo (avatar)
20  */
21 void fetch_user_photo(struct http_transaction *h, struct ctdlsession *c)
22 {
23         char username[1024];
24
25         extract_token(username, h->uri, 3, '/', sizeof username);
26
27         do_404(h);      // FIXME finish this
28 }
29
30
31 /*
32  * Fetch a user bio (profile)
33  */
34 void fetch_user_bio(struct http_transaction *h, struct ctdlsession *c)
35 {
36         char username[1024];
37
38         extract_token(username, h->uri, 3, '/', sizeof username);
39
40         do_404(h);      // FIXME finish this
41 }
42
43
44 /*
45  * Client requested an object related to a user.
46  */
47 void object_in_user(struct http_transaction *h, struct ctdlsession *c)
48 {
49         char buf[1024];
50         long msgnum = (-1);
51         char unescaped_euid[1024];
52
53         extract_token(buf, h->uri, 4, '/', sizeof buf);
54
55         if (!strcasecmp(buf, "userpic")) {              // user photo (avatar)
56                 fetch_user_photo(h, c);
57                 return;
58         }
59
60         if (!strcasecmp(buf, "bio")) {                  // user bio (profile)
61                 fetch_user_bio(h, c);
62                 return;
63         }
64
65         do_404(h);                                      // unknown object
66         return;
67 }
68
69
70 /*
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)
73  */
74 void the_user_itself(struct http_transaction *h, struct ctdlsession *c)
75 {
76         do_404(h);
77 }
78
79
80 /*
81  * Dispatcher for "/ctdl/u" and "/ctdl/u/" for the user list
82  */
83 void user_list(struct http_transaction *h, struct ctdlsession *c)
84 {
85         do_404(h);
86 }
87
88
89 /*
90  * Dispatcher for paths starting with /ctdl/u/
91  */
92 void ctdl_u(struct http_transaction *h, struct ctdlsession *c)
93 {
94         char requested_username[128];
95         char buf[1024];
96
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);
100
101         if (IsEmptyStr(requested_username)) {   //      /ctdl/u/
102                 user_list(h, c);
103                 return;
104         }
105
106         // Try to access the user...
107         if (strcasecmp(requested_username, c->room)) {
108                 do_404(h);
109         } else {
110                 do_404(h);
111                 return;
112         }
113
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);
117                 return;
118         }
119
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 )
124                 } else {
125                         object_in_user(h, c);   //      /ctdl/u/username/object
126                 }
127                 return;
128         }
129
130         if (num_tokens(h->uri, '/') == 6) {
131                 object_in_user(h, c);   //      /ctdl/u/username/object/ or possibly /ctdl/u/username/object/component
132                 return;
133         }
134
135         // If we get to this point, the client specified a valid user but requested an action we don't know how to perform.
136         do_404(h);
137 }