From 45f87c7ab21048ae642cc5c53565386142798e25 Mon Sep 17 00:00:00 2001 From: aabacchus Date: Sat, 27 May 2023 19:38:30 +0100 Subject: parse_cgi.c write to socket --- parse_cgi.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/parse_cgi.c b/parse_cgi.c index fb345a0..5e92359 100644 --- a/parse_cgi.c +++ b/parse_cgi.c @@ -3,14 +3,44 @@ #include #include #include +#include +#include #include #include "cJSON.h" +#define SOCK_PATH "/tmp/kissbot" + #ifndef __OpenBSD__ #define pledge(a, b) (0) #endif +int +sock_write(char *msg, ...) { + struct sockaddr_un remote = {.sun_family = AF_UNIX}; + int s = socket(AF_UNIX, SOCK_STREAM, 0); + if (s == -1) + err(1, "socket"); + + strlcpy(remote.sun_path, SOCK_PATH, + sizeof(remote.sun_path)-1); + if (connect(s, (struct sockaddr *)&remote, + sizeof(SOCK_PATH) + sizeof(remote.sun_family)) == -1) + err(1, "connect"); + + va_list ap; + va_start(ap, msg); + if (vdprintf(s, msg, ap) < 0) { + va_end(ap); + close(s); + err(1, "send"); + } + va_end(ap); + + close(s); + return 0; +} + int main(int argc, char **argv) { if (pledge("stdio rpath", NULL) == -1) { perror("pledge"); @@ -56,10 +86,11 @@ int main(int argc, char **argv) { 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");
+	    if (cJSON_IsString(name)) {
+	        printf("%s commited %.10s: %s\n", name->valuestring, id->valuestring, msg->valuestring);
+	        sock_write("%s commited %.10s: %s\n", name->valuestring, id->valuestring, msg->valuestring);
+	    } else
+	        printf("Failed to find commit info.\n");
 
 	    cJSON_Delete(json);
 	    printf("
\n"); -- cgit 1.4.1-2-gfad0