commit:2ed464c9a551f74387dd8a719df6a0fe3760ab10
author:Chip Black
committer:Chip Black
date:Fri Jul 25 17:52:09 2014 -0500
parents:32321bfee03406ebbcb13542def0a75b00426ac5
Normalize /subscribe to accept a parameter rather than having two endpoints
diff --git a/cgi/cgi_blerg.c b/cgi/cgi_blerg.c
line changes: +17/-23
index de325c3..9df908b
--- a/cgi/cgi_blerg.c
+++ b/cgi/cgi_blerg.c
@@ -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) {