#include #include #include #include #include #include #include "cJSON.h" #ifndef __OpenBSD__ #define pledge(a, b) (0) #endif int main(int argc, char **argv) { if (pledge("stdio rpath", NULL) == -1) { perror("pledge"); return 1; } printf("Status: 200 OK\r\n"); printf("Content-Type: text/html\r\n"); printf("\r\n"); printf("\n\n\nCGI\n\n"); size_t bufn = 0; char *buf = NULL; ssize_t n; while (1) { buf = realloc(buf, bufn + 4096 + 1); if (buf == NULL) err(1, "realloc"); n = read(0, buf+bufn, 4096); if (n == -1) err(1, "read"); if (n == 0) break; bufn += n; } n += bufn; buf[n] = '\0'; if (n > 0) { cJSON *json = cJSON_ParseWithLength(buf, n), *commits, *c, *id, *msg, *a, *name; if (json == NULL) errx(1, "parsing JSON failed"); commits = cJSON_GetObjectItemCaseSensitive(json, "commits"); c = cJSON_GetArrayItem(commits, 0); id = cJSON_GetObjectItemCaseSensitive(c, "id"); msg = cJSON_GetObjectItemCaseSensitive(c, "message"); a = cJSON_GetObjectItemCaseSensitive(c, "author"); name = cJSON_GetObjectItemCaseSensitive(a, "name"); printf("

stdin

\n
");

	    if (cJSON_IsString(name))
	    	printf("%s commited %.10s: %s\n", name->valuestring, id->valuestring, msg->valuestring);
	    else
		printf("Failed to find commit info.\n");

	    cJSON_Delete(json);
	    printf("
\n"); } free(buf); printf("\n"); return 0; }