diff options
Diffstat (limited to 'cgi.c')
-rw-r--r-- | cgi.c | 16 |
1 files changed, 5 insertions, 11 deletions
@@ -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 | ||
84 | void send_answer_file(Http_Header * http_header, int fd_socket) { | 84 | void 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 | ||
113 | void send_answer(Http_Header * http_header, int fd_socket) { | 107 | void 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 | ||