Skip to content

Commit 5afd29a

Browse files
chore(warteraum): remove support for v1 API
I could not find any evidence anyone has been using this API this year (except some AI companies' crawler bots sending GET requests to the wrong endpoints), so it seems like it's as good a time as any to pull the plug. The old endpoints now return 410 Gone. bahnhofshalle without JavaScript will now use the v2 API as a fallback, meaning that the user will be shown JSON instead of a (lackluster) HTML page. Due to the whitespace changes, it is easiest to review this change with `git diff -b`.
1 parent 2244fd8 commit 5afd29a

File tree

5 files changed

+73
-144
lines changed

5 files changed

+73
-144
lines changed

README.adoc

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -148,42 +148,7 @@ authenticate itself:
148148
API `v1`
149149
~~~~~~~
150150

151-
GET `/api/v1/queue`
152-
^^^^^^^^^^^^^^^^^^^
153-
154-
Same as `/api/v2/queue`, since v2 didn't introduce any changes.
155-
156-
POST `/api/v1/queue/add`
157-
^^^^^^^^^^^^^^^^^^^^^^^^
158-
159-
|=============================================
160-
| Request Content-Type | `application/x-www-form-urlencoded`
161-
| Response Content-Type | `text/html`
162-
| Authentication | no
163-
|=============================================
164-
165-
This is the legacy endpoint to add text to the queue. It enabled
166-
interacting with it via a `<form>` in the old web app. The form
167-
sent as part of the request should have the following fields:
168-
169-
|=============================================
170-
| `text` | text to be added to the queue
171-
|=============================================
172-
173-
The response format has been changed since the previous implementation.
174-
I sincerly hope that nobody scraped the resulting page.
175-
176-
|=============================================
177-
| HTTP Status | Meaning
178-
| 200 | Success, text added
179-
| 400 | Illegal method or malformed request
180-
| 415 | Request body too big or text field longer allowed (usually 512 bytes)
181-
|=============================================
182-
183-
DELETE `/api/v1/queue/del/<id>`
184-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185-
186-
Same as `/api/v2/queue/<id>`, `v2` only changed the endpoint URL.
151+
Unsupported since version 2.2.0.
187152

188153
Bug Bounty
189154
----------
@@ -336,6 +301,12 @@ and only possible with a knowledge of `warteraum` internals.
336301
Changelog
337302
---------
338303
304+
2.2.0 (unreleased)
305+
~~~~~~~~~~~~~~~~~~
306+
307+
* `warteraum`
308+
** Remove support for the `v1` API completely.
309+
339310
2.1.0
340311
~~~~~
341312

bahnhofshalle/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h1>flipdot-gschichtler</h1>
2222
<main>
2323
<section id="send-new">
2424
<h2>display your <span id="display-what">text</span> on the flipdot panel</h2>
25-
<form id="send-form" action="/api/v1/queue/add" method="post" enctype="application/x-www-form-urlencoded">
25+
<form id="send-form" action="/api/v2/queue/add" method="post" enctype="application/x-www-form-urlencoded">
2626
<div class="input-button">
2727
<input name="text" id="text" type="text" placeholder="Text">
2828
<input type="submit" value="Send" id="submit">

warteraum/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ warteraum: http_string.o emitjson.o queue.o routing.o form.o auth.o main.o
2626
hashtoken: hashtoken.o http_string.o
2727
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
2828

29-
main.o: main.c queue.h routing.h form.h v1_static.h emitjson.h \
29+
main.o: main.c queue.h routing.h form.h emitjson.h \
3030
auth.h http_string.h $(HTTPSERVER)
3131

3232
form.o: form.c http_string.h $(HTTPSERVER)

warteraum/main.c

Lines changed: 64 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "form.h"
1717
#include "auth.h"
1818

19-
#include "v1_static.h" /* static strings for v1 api */
20-
2119
#define LISTEN_PORT 9000 /* port to listen on */
2220
#define MAX_BODY_LEN 8192 /* max body size we'll parse */
2321
#define MAX_TEXT_LEN 512 /* max length of a queue text */
@@ -89,15 +87,11 @@ enum warteraum_result {
8987
WARTERAUM_INTERNAL_ERROR = 4,
9088
WARTERAUM_FULL_ERROR = 5,
9189
WARTERAUM_ENTRY_NOT_FOUND = 6,
92-
WARTERAUM_TOO_LONG = 7
93-
};
94-
95-
enum warteraum_version {
96-
WARTERAUM_API_V1,
97-
WARTERAUM_API_V2
90+
WARTERAUM_TOO_LONG = 7,
91+
WARTERAUM_UNSUPPORTED_API_VERSION = 8,
9892
};
9993

100-
void response_error(enum warteraum_result e, bool legacy_response, http_request_t *request, http_response_t *response) {
94+
void response_error(enum warteraum_result e, http_request_t *request, http_response_t *response) {
10195
// response_error should never be called with
10296
// WARTERAUM_OK, so this is considered a error 500
10397
const http_string_t errors[] = {
@@ -109,57 +103,46 @@ void response_error(enum warteraum_result e, bool legacy_response, http_request_
109103
STATIC_HTTP_STRING("queue is full (max id reached)"),
110104
STATIC_HTTP_STRING("queue entry not found"),
111105
STATIC_HTTP_STRING("body or other input too long"),
106+
STATIC_HTTP_STRING("api version is no longer supported"),
112107
};
113108

114-
const int codes[] = { 500, 400, 401, 404, 500, 503, 404, 413 };
109+
const int codes[] = { 500, 400, 401, 404, 500, 503, 404, 413, 410 };
110+
111+
size_t buf_size = 0;
112+
char *buf = NULL;
113+
FILE *out = open_memstream(&buf, &buf_size);
114+
struct ej_context ctx;
115+
bool static_buf = false;
116+
117+
ej_init(&ctx, out);
115118

116-
if(legacy_response) {
117-
// /api/v1/queue/add returns a HTML response
118-
// we emulate this behavior, however not exactly
119+
if(out == NULL) {
120+
buf = INTERNAL_ERROR_STATIC;
121+
buf_size = sizeof(INTERNAL_ERROR_STATIC) - 1;
119122

120-
http_response_status(response, codes[e]);
121-
http_response_header(response, "Content-Type", "text/html");
122-
http_response_body(response, QUEUE_ADD_V1_FAILURE, sizeof(QUEUE_ADD_V1_FAILURE) - 1);
123-
http_respond(request, response);
123+
static_buf = true;
124+
e = WARTERAUM_INTERNAL_ERROR;
124125
} else {
125-
size_t buf_size = 0;
126-
char *buf = NULL;
127-
FILE *out = open_memstream(&buf, &buf_size);
128-
struct ej_context ctx;
129-
bool static_buf = false;
130-
131-
ej_init(&ctx, out);
132-
133-
if(out == NULL) {
134-
buf = INTERNAL_ERROR_STATIC;
135-
buf_size = sizeof(INTERNAL_ERROR_STATIC) - 1;
136-
137-
static_buf = true;
138-
e = WARTERAUM_INTERNAL_ERROR;
139-
} else {
140-
ej_object(&ctx);
141-
EJ_STATIC_BIND(&ctx, "error");
142-
ej_string(&ctx, errors[e].buf, (size_t) errors[e].len);
143-
ej_object_end(&ctx);
144-
145-
fclose(out);
146-
}
126+
ej_object(&ctx);
127+
EJ_STATIC_BIND(&ctx, "error");
128+
ej_string(&ctx, errors[e].buf, (size_t) errors[e].len);
129+
ej_object_end(&ctx);
147130

148-
http_response_status(response, codes[e]);
149-
http_response_header(response, "Content-Type", "application/json");
150-
http_response_body(response, buf, static_buf ? buf_size : (int) ctx.written);
151-
http_respond(request, response);
131+
fclose(out);
132+
}
152133

153-
if(!static_buf) {
154-
free(buf);
155-
}
134+
http_response_status(response, codes[e]);
135+
http_response_header(response, "Content-Type", "application/json");
136+
http_response_body(response, buf, static_buf ? buf_size : (int) ctx.written);
137+
http_respond(request, response);
138+
139+
if(!static_buf) {
140+
free(buf);
156141
}
157142
}
158143

159-
// GET /api/{v1, v2}/queue
160-
enum warteraum_result response_queue(enum warteraum_version v, http_request_t *request, http_response_t *response) {
161-
(void) v; // surpress warning for now
162-
144+
// GET /api/v2/queue
145+
enum warteraum_result response_queue(http_request_t *request, http_response_t *response) {
163146
unsigned int queue_length = 0;
164147

165148
struct ej_context ctx;
@@ -208,8 +191,8 @@ enum warteraum_result response_queue(enum warteraum_version v, http_request_t *r
208191
return WARTERAUM_OK;
209192
}
210193

211-
// POST /api/{v1,v2}/queue/add
212-
enum warteraum_result response_queue_add(enum warteraum_version version, http_request_t *request, http_response_t *response) {
194+
// POST /api/v2/queue/add
195+
enum warteraum_result response_queue_add(http_request_t *request, http_response_t *response) {
213196
http_string_t text;
214197
const struct form_field_spec request_spec[] = {
215198
{ STATIC_HTTP_STRING("text"), FIELD_TYPE_STRING, &text }
@@ -269,48 +252,38 @@ enum warteraum_result response_queue_add(enum warteraum_version version, http_re
269252
return WARTERAUM_INTERNAL_ERROR;
270253
}
271254

272-
if(version == WARTERAUM_API_V1) {
273-
http_response_status(response, 200);
274-
http_response_header(response, "Content-Type", "text/html");
275-
http_response_body(response, QUEUE_ADD_V1_SUCCESS, sizeof(QUEUE_ADD_V1_SUCCESS) - 1);
276-
http_respond(request, response);
277-
} else {
278-
struct ej_context ctx;
279-
char *buf = NULL;
280-
size_t buf_size = 0;
281-
FILE *out = open_memstream(&buf, &buf_size);
255+
struct ej_context ctx;
256+
char *buf = NULL;
257+
size_t buf_size = 0;
258+
FILE *out = open_memstream(&buf, &buf_size);
282259

283-
if(out == NULL) {
284-
return WARTERAUM_INTERNAL_ERROR;
285-
}
260+
if(out == NULL) {
261+
return WARTERAUM_INTERNAL_ERROR;
262+
}
286263

287-
ej_init(&ctx, out);
264+
ej_init(&ctx, out);
288265

289-
ej_object(&ctx);
290-
EJ_STATIC_BIND(&ctx, "id");
291-
ej_uint(&ctx, flip_queue.last->id);
292-
EJ_STATIC_BIND(&ctx, "text");
293-
ej_string(&ctx, flip_queue.last->string, flip_queue.last->string_size);
294-
ej_object_end(&ctx);
266+
ej_object(&ctx);
267+
EJ_STATIC_BIND(&ctx, "id");
268+
ej_uint(&ctx, flip_queue.last->id);
269+
EJ_STATIC_BIND(&ctx, "text");
270+
ej_string(&ctx, flip_queue.last->string, flip_queue.last->string_size);
271+
ej_object_end(&ctx);
295272

296-
fclose(out);
273+
fclose(out);
297274

298-
http_response_status(response, 200);
299-
http_response_header(response, "Content-Type", "application/json");
300-
http_response_body(response, buf, (int) ctx.written);
301-
http_respond(request, response);
275+
http_response_status(response, 200);
276+
http_response_header(response, "Content-Type", "application/json");
277+
http_response_body(response, buf, (int) ctx.written);
278+
http_respond(request, response);
302279

303-
free(buf);
304-
}
280+
free(buf);
305281

306282
return WARTERAUM_OK;
307283
}
308284

309-
// DELETE /api/v1/queue/del/<id>
310285
// DELETE /api/v2/queue/<id>
311-
enum warteraum_result response_queue_del(http_string_t id_str, enum warteraum_version v, http_request_t *request, http_response_t *response) {
312-
(void) v; // surpress warning for now
313-
286+
enum warteraum_result response_queue_del(http_string_t id_str, http_request_t *request, http_response_t *response) {
314287
http_string_t content_type = http_request_header(request, "Content-Type");
315288
http_string_t method = http_request_method(request);
316289

@@ -401,38 +374,28 @@ void handle_request(http_request_t *request) {
401374
int count = split_segments(target, &segs);
402375

403376
enum warteraum_result status = WARTERAUM_NOT_FOUND;
404-
enum warteraum_version api_version;
405-
bool v1_html_response = false;
406377

407378
if(count < 0) {
408379
status = WARTERAUM_INTERNAL_ERROR;
409380
} else {
410381
if(SEGMENT_MATCH(0, "api", segs, count)) {
411382
if(SEGMENT_MATCH(1, "v1", segs, count)) {
412-
api_version = WARTERAUM_API_V1;
413-
414383
if(SEGMENT_MATCH(2, "queue", segs, count)) {
415-
if(count == 3) {
416-
status = response_queue(api_version, request, response);
417-
} else if(SEGMENT_MATCH_LAST(3, "add", segs, count)) {
418-
// this endpoint returns html in /api/v1
419-
v1_html_response = true;
420-
status = response_queue_add(api_version, request, response);
421-
} else if(SEGMENT_MATCH(3, "del", segs, count) && count == 5) {
422-
status = response_queue_del(segs[4], api_version, request, response);
384+
if(count == 3
385+
|| SEGMENT_MATCH_LAST(3, "add", segs, count)
386+
|| (SEGMENT_MATCH(3, "del", segs, count) && count == 5)) {
387+
status = WARTERAUM_UNSUPPORTED_API_VERSION;
423388
}
424389
}
425390
} else if(SEGMENT_MATCH(1, "v2", segs, count)) {
426-
api_version = WARTERAUM_API_V2;
427-
428391
if(SEGMENT_MATCH(2, "queue", segs, count)) {
429392
if(count == 3) {
430-
status = response_queue(api_version, request, response);
393+
status = response_queue(request, response);
431394
} else if(SEGMENT_MATCH_LAST(3, "add", segs, count)) {
432-
status = response_queue_add(api_version, request, response);
395+
status = response_queue_add(request, response);
433396
} else if(count == 4) {
434397
// /api/v2/queue/<id>
435-
status = response_queue_del(segs[3], api_version, request, response);
398+
status = response_queue_del(segs[3], request, response);
436399
}
437400
}
438401
}
@@ -442,7 +405,7 @@ void handle_request(http_request_t *request) {
442405
free(segs);
443406

444407
if(status != WARTERAUM_OK) {
445-
response_error(status, v1_html_response, request, response);
408+
response_error(status, request, response);
446409
}
447410
}
448411

warteraum/v1_static.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)