summaryrefslogtreecommitdiff
path: root/cgi.c
diff options
context:
space:
mode:
authorMax Christian Pohle2021-11-27 13:47:24 +0100
committerMax Christian Pohle2021-11-27 13:47:24 +0100
commit9cf4f824ed6f214f0041bd855f69e75e8fba4bcf (patch)
treef52d5b70059b076910baf2eda041cac47569c0a0 /cgi.c
parent87451879bf098521db618052d6068ace1dd62492 (diff)
downloadohmycgi-9cf4f824ed6f214f0041bd855f69e75e8fba4bcf.tar.bz2
ohmycgi-9cf4f824ed6f214f0041bd855f69e75e8fba4bcf.zip
Refactoring, stable&functional intermediate state
Diffstat (limited to 'cgi.c')
-rw-r--r--cgi.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/cgi.c b/cgi.c
index aa86c9a..128eae7 100644
--- a/cgi.c
+++ b/cgi.c
@@ -81,9 +81,7 @@ int print_on_correct_printer(void * user_data, unsigned flags, cups_dest_t * des
81 return 0; 81 return 0;
82} 82}
83 83
84void send_answer_file(Http_Header * http_header, int fd_socket) { 84void send_answer_file(Http_Header * http_header, FILE * f) {
85
86 FILE * f = fdopen((size_t) fd_socket, "w");
87 fputs("HTTP/1.0 200 OK\n", f); 85 fputs("HTTP/1.0 200 OK\n", f);
88 fputs("content-type: text/html\n\n", f); 86 fputs("content-type: text/html\n\n", f);
89 fflush(f); 87 fflush(f);
@@ -96,23 +94,20 @@ void send_answer_file(Http_Header * http_header, int fd_socket) {
96 for(;;) { 94 for(;;) {
97 read_size = fread(buffer, 1, BUFFER_SIZE, file); 95 read_size = fread(buffer, 1, BUFFER_SIZE, file);
98 fwrite(buffer, 1, read_size, f); 96 fwrite(buffer, 1, read_size, f);
99 fflush(f);
100 if(feof(file)) 97 if(feof(file))
101 break; 98 break;
102 } 99 }
103 } else { 100 } else {
104 if(http_header->url) // TODO: too dangerous to check that here, that is too late.
105 fprintf(f, "could not open file \"%s\"\n", &http_header->url[1]); 101 fprintf(f, "could not open file \"%s\"\n", &http_header->url[1]);
106 } 102 }
107 103
108 fflush(f);
109 fclose(f);
110 return; 104 return;
111} 105}
112 106
113void send_answer(Http_Header * http_header, int fd_socket) { 107void send_answer(Http_Header * http_header, FILE * f) {
108
109 char * printer_name = "Brother_QL-720NW"; // TODO: make configurable
114 110
115 char * printer_name = "Brother_QL-720NW";
116 cupsEnumDests(CUPS_DEST_FLAGS_NONE, 111 cupsEnumDests(CUPS_DEST_FLAGS_NONE,
117 0, 112 0,
118 NULL, 113 NULL,
@@ -124,8 +119,7 @@ void send_answer(Http_Header * http_header, int fd_socket) {
124 line1 = NULL; 119 line1 = NULL;
125 line2 = NULL; 120 line2 = NULL;
126 121
127 http_header->url = "/index.html"; 122 send_answer_file(http_header, f);
128 send_answer_file(http_header, fd_socket);
129} 123}
130 124
131 125
..