New file user_functions.c contains skeleton code for the /ctdl/u/... calls
authorArt Cancro <ajc@citadel.org>
Wed, 12 Sep 2018 03:54:48 +0000 (23:54 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 12 Sep 2018 03:54:48 +0000 (23:54 -0400)
webcit-ng/Makefile
webcit-ng/api.txt
webcit-ng/request.c
webcit-ng/user_functions.c [new file with mode: 0644]
webcit-ng/webcit.h

index 4182603c1fa41a2451b2784764754d0097913918..645e0260693768a8a6e03635753e08c77b155838 100644 (file)
@@ -1,4 +1,4 @@
-OBJS := http.o main.o request.o ssl.o static.o tcp_sockets.o webserver.o ctdlclient.o admin_functions.o room_functions.o util.o caldav_reports.o messages.o ctdlfunctions.o ctdl_commands.o forum_view.o html2html.o text2html.o
+OBJS := http.o main.o request.o ssl.o static.o tcp_sockets.o webserver.o ctdlclient.o admin_functions.o room_functions.o util.o caldav_reports.o messages.o ctdlfunctions.o ctdl_commands.o forum_view.o html2html.o text2html.o user_functions.o
 CFLAGS := -ggdb
 LDFLAGS := 
 
index f750caf0b20c8dbe2724089cc0e249e4c3bd5f5f..4621f9bec94d1d02263eceb3a64e2efc26de81a4 100644 (file)
@@ -2,6 +2,7 @@
 Method         URI                             Function
 ------         ------------------------------  -------------------------------------
 GET            /ctdl/a/landing.html            Site root redirects to here
+GET            /ctdl/r/                        returns a JSON-encoded list of accessible rooms
 OPTIONS                /ctdl/r/ROOMNAME/               returns just what you'd expect
 PROPFIND       /ctdl/r/ROOMNAME/               Show a bunch of crap
 GET            /ctdl/r/ROOMNAME/               Returns information about the room (name, view, etc.) in JSON format
@@ -10,3 +11,4 @@ GET           /ctdl/r/ROOMNAME/msgs.new       JSON array of message list in room (new messages)
 GET            /ctdl/c/info                    Returns a JSON representation of the output of an INFO server command
 POST           /ctdl/a/login
 GET            /ctdl/a/whoami
+GET            /ctdl/u/USERNAME/userpic        Returns an image containing the photo/avatar of the specified user
index 0a20ed271177ebe76a90549ee95bc1881c937e09..71b1290bcb819c72c5443515caa3c80fc01e62bf 100644 (file)
@@ -160,7 +160,7 @@ void perform_request(struct http_transaction *h)
                ctdl_r(h, c);
                break;
        case 'u':               // /ctdl/u/ == RESTful path to users
-               do_404(h);
+               ctdl_u(h, c);
                break;
        default:
                do_404(h);
diff --git a/webcit-ng/user_functions.c b/webcit-ng/user_functions.c
new file mode 100644 (file)
index 0000000..7067ec7
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * User functions
+ *
+ * Copyright (c) 1996-2018 by the citadel.org team
+ *
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include "webcit.h"
+
+
+/*
+ * Client requested an object related to a user.
+ */
+void object_in_user(struct http_transaction *h, struct ctdlsession *c)
+{
+       char buf[1024];
+       long msgnum = (-1);
+       char unescaped_euid[1024];
+
+       extract_token(buf, h->uri, 4, '/', sizeof buf);
+
+       if (!strcasecmp(buf, "userpic")) {              // FIXME do this
+               do_404(h);
+               return;
+       }
+
+       do_404(h);                                      // unknown object
+       return;
+}
+
+
+/*
+ * Handle REST/DAV requests for the user itself (such as /ctdl/u/username
+ * or /ctdl/i/username/ but *not* specific properties of the user)
+ */
+void the_user_itself(struct http_transaction *h, struct ctdlsession *c)
+{
+       do_404(h);
+}
+
+
+/*
+ * Dispatcher for "/ctdl/u" and "/ctdl/u/" for the user list
+ */
+void user_list(struct http_transaction *h, struct ctdlsession *c)
+{
+       do_404(h);
+}
+
+
+/*
+ * Dispatcher for paths starting with /ctdl/u/
+ */
+void ctdl_u(struct http_transaction *h, struct ctdlsession *c)
+{
+       char requested_username[128];
+       char buf[1024];
+
+       // All user-related functions require accessing the user in question.
+       extract_token(requested_username, h->uri, 3, '/', sizeof requested_username);
+       unescape_input(requested_username);
+
+       if (IsEmptyStr(requested_username)) {   //      /ctdl/u/
+               user_list(h, c);
+               return;
+       }
+
+       // Try to access the user...
+       if (strcasecmp(requested_username, c->room)) {
+               do_404(h);
+       } else {
+               do_404(h);
+               return;
+       }
+
+       // At this point we have accessed the requested user account.
+       if (num_tokens(h->uri, '/') == 4) {     //      /ctdl/u/username
+               the_user_itself(h, c);
+               return;
+       }
+
+       extract_token(buf, h->uri, 4, '/', sizeof buf);
+       if (num_tokens(h->uri, '/') == 5) {
+               if (IsEmptyStr(buf)) {
+                       the_user_itself(h, c);  //      /ctdl/u/username/       ( same as /ctdl/u/username )
+               } else {
+                       object_in_user(h, c);   //      /ctdl/u/username/object
+               }
+               return;
+       }
+
+       if (num_tokens(h->uri, '/') == 6) {
+               object_in_user(h, c);   //      /ctdl/u/username/object/ or possibly /ctdl/u/username/object/component
+               return;
+       }
+
+       // If we get to this point, the client specified a valid user but requested an action we don't know how to perform.
+       do_404(h);
+}
index 4d5f51c56c124b0bb95eae83aa851f221b41d924..af08f6fddb2c3d307c1c76fe1705f748f564347a 100644 (file)
@@ -135,6 +135,7 @@ int uds_connectsock(char *sockpath);
 int tcp_connectsock(char *host, char *service);
 void ctdl_a(struct http_transaction *, struct ctdlsession *);
 void ctdl_r(struct http_transaction *, struct ctdlsession *);
+void ctdl_u(struct http_transaction *, struct ctdlsession *);
 struct ctdlsession *connect_to_citadel(struct http_transaction *);
 void disconnect_from_citadel(struct ctdlsession *);
 char *header_val(struct http_transaction *h, char *requested_header);