diff options
-rw-r--r-- | parse_cgi.c | 39 |
1 files 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 <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/socket.h> +#include <sys/un.h> #include <unistd.h> #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("<h2>stdin</h2>\n<pre>"); - 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("</pre>\n"); |