void cxtbuffer_write () { if ( cxtbuffer == NULL ) { return; } connection *next; next = NULL; FILE *cxtFile; char cxtfname[4096]; sprintf(cxtfname, "%sstats.%s.%ld", dpath, dev, tstamp.tv_sec); cxtFile = fopen(cxtfname, "w"); if (cxtFile == NULL) { printf("[E] ERROR: Cant open file %s\n",cxtfname); /* Free them anyways! */ while ( cxtbuffer != NULL ) { next = cxtbuffer->next; cxtbuffer_free(cxtbuffer); cxtbuffer = next; } printf("[W] connections went to visit /dev/null\n"); } else { while ( cxtbuffer != NULL ) { format_write(cxtFile, cxtbuffer); next = cxtbuffer->next; cxtbuffer_free(cxtbuffer); cxtbuffer = next; } fclose(cxtFile); } cxtbuffer = NULL; }
static void check_content_type(const char *accepted_type) { const char *actual_type = getenv("CONTENT_TYPE"); if (!actual_type) actual_type = ""; if (strcmp(actual_type, accepted_type)) { http_status(415, "Unsupported Media Type"); hdr_nocache(); end_headers(); format_write(1, "Expected POST with Content-Type '%s'," " but received '%s' instead.\n", accepted_type, actual_type); exit(0); } }
static void hdr_int(const char *name, uintmax_t value) { format_write(1, "%s: %" PRIuMAX "\r\n", name, value); }
static void hdr_str(const char *name, const char *value) { format_write(1, "%s: %s\r\n", name, value); }
static void http_status(unsigned code, const char *msg) { format_write(1, "Status: %u %s\r\n", code, msg); }