Normalize /subscribe to accept a parameter rather than having two endpoints
[blerg.git] / cgi / cgi_blerg.c
index de325c3..9df908b 100644 (file)
@@ -342,36 +342,30 @@ int main(int argc, char *argv[]) {
 
                auth_logout(ac.name, ac.token);
                respond_JSON_Success();
-       } else if (strncmp(path, "/subscribe", 10) == 0 || strncmp(path, "/unsubscribe", 12) == 0) {
+       } else if (strncmp(path, "/subscribe", 10) == 0) {
                if (!check_auth(&ac))
                        exit(0);
 
-               if (path[1] == 'u') {
-                       if (path[12] != '/') {
-                               respond_404();
-                               exit(0);
-                       }
-
-                       ret = parse_url_info(path + 13, &info);
-                       if ((ret & URL_INFO_NAME) == 0) {
-                               respond_404();
-                               exit(0);
-                       }
+               if (path[10] != '/') {
+                       respond_404();
+                       exit(0);
+               }
 
-                       subscription_remove(ac.name, info.name);
-               } else {
-                       if (path[10] != '/') {
-                               respond_404();
-                               exit(0);
-                       }
+               ret = parse_url_info(path + 11, &info);
+               if ((ret & URL_INFO_NAME) == 0) {
+                       respond_404();
+                       exit(0);
+               }
 
-                       ret = parse_url_info(path + 11, &info);
-                       if ((ret & URL_INFO_NAME) == 0) {
-                               respond_404();
-                               exit(0);
-                       }
+               const char *subscribed = cgi_getentrystr("subscribed");
 
+               if (strncmp(subscribed, "true", 4) == 0) {
                        subscription_add(ac.name, info.name);
+               } else if (strncmp(subscribed, "false", 5) == 0) {
+                       subscription_remove(ac.name, info.name);
+               } else {
+                       respond_JSON_Failure();
+                       exit(0);
                }
                respond_JSON_Success();
        } else if (strncmp(path, "/feed", 6) == 0) {