From bef7e1a6f6ed28d580b331063baa35b34a8f1d25 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Sat, 4 Dec 2021 14:29:49 +0100 Subject: Prepared `letter` type and updated CSS --- Makefile | 5 +++- README.md | 3 +++ cgi.c | 23 +++++++++++++++++- default.css | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 51 +++------------------------------------ letter.html | 24 +++++++++++++++++++ main.c | 35 +++++++++++++++++++++++++++ 7 files changed, 171 insertions(+), 50 deletions(-) create mode 100644 README.md create mode 100644 default.css create mode 100644 letter.html diff --git a/Makefile b/Makefile index 14c362c..8051094 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ cflags.debug := -Wall -o0 -g -DDEBUG=1 cflags.release := -os -s CFLAGS := ${cflags.${BUILD}} -LIBS := -lcups +LIBS := -lcups -lmagic CFLAGS += -L/usr/local/lib CFLAGS += -I/usr/local/include @@ -14,6 +14,9 @@ FILES := cgi.c http_parser.c test: main ./main.${BUILD} +test_param: main + ./main.${BUILD} --test1 -a -b -c --test2 --pidfile=foo --pidfile foobar + main: clean $(CC) $(CFLAGS) -o $@.${BUILD} $(FILES) main.c $(LIBS) diff --git a/README.md b/README.md new file mode 100644 index 0000000..0f7b2aa --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +ohmycgi 😇 - the missing piece + + diff --git a/cgi.c b/cgi.c index 81149af..a1f5ae2 100644 --- a/cgi.c +++ b/cgi.c @@ -37,9 +37,11 @@ #include "main.h" #include +#include static const char * line1 = NULL, * line2 = NULL; + int print_on_correct_printer(void * user_data, unsigned flags, cups_dest_t * dest) { if(!strstr(dest->name, user_data)) { // DEBUG("> Wrong printer name: '%s'; try next printer...\n", dest->name); @@ -89,7 +91,26 @@ int print_on_correct_printer(void * user_data, unsigned flags, cups_dest_t * des void send_answer_file(Http_Header * http_header, FILE * f) { fputs("HTTP/1.0 200 OK\n", f); - fputs("content-type: text/html\n\n", f); + + DEBUG("> PROBLEM: %s\n", &http_header->url[strlen(http_header->url) - 4]); + if(0 == strncmp(&http_header->url[strlen(http_header->url) - 4], ".css", 4)) { + fputs("content-type: text/css", f); + } else { + + magic_t magic = magic_open(MAGIC_MIME); + + magic_load(magic, NULL); + // magic_compile(magic, NULL); + const char * mime_type = magic_file(magic, &http_header->url[1]); + if(mime_type) + fprintf(f, "content-type: %s\n\n", mime_type); + else + fputs("content-type: text/html; charset=utf-8", f); + // fprintf(f, "content-type: %s; charset=utf-8\n\n", magic_file(magic, &http_header->url[1])); + magic_close(magic); + } + + fputs("\n\n", f); fflush(f); #define BUFFER_SIZE 1024 diff --git a/default.css b/default.css new file mode 100644 index 0000000..64f121e --- /dev/null +++ b/default.css @@ -0,0 +1,80 @@ +@charset "UTF-8"; + +html,body { + background: Window; + font: caption; + color: WindowText; + margin:0; + height:100%; + overflow:hidden; + line-height: 1.5; + letter-spacing: 0.033em; +} + +body { + padding:2em; +} + +h1 { + margin-top:0; +} + +label { + font-size:x-small; + color:GrayText; +} + +form { + border:2px solid Window; + border-radius: 1em; + padding: 2em; + background: AppWorkspace; +} + +input, textarea { + background: Menu; + color: MenuText; + cursor:pointer; + font: caption; + padding: 0.3em 0.5em; + width:25ex; + height:6em; + border: 3px ridge; + border-width: 0px 0px 2px 0px; + border-color: ButtonShadow; + margin-right:2em; +} + +input.label { + height:1.5em; +} + +input[type="submit"] { + width:inherit; + height:inherit; + border-radius:1ex; + border-width:2px; + font-weight:bold; + background-color: ButtonFace; + color: ButtonText; +} + +input:hover, input:active, textarea:hover, textarea:active { + background-color:Highlight; + color:HighlightText; +} + +div.content { + position: relative; + width:50%; +} + +div.content textarea[name="text"] { + height:12em; + width:100%; +} + +br.clear { + clear:both; +} + diff --git a/index.html b/index.html index 9b5ffdf..897fcb8 100644 --- a/index.html +++ b/index.html @@ -4,59 +4,14 @@ print label - + -

Simple label

-
- +
+
diff --git a/letter.html b/letter.html new file mode 100644 index 0000000..19ed778 --- /dev/null +++ b/letter.html @@ -0,0 +1,24 @@ + + + + + print letter + + + +
+

Letter

+
+
+
+
+
+ + +
+
+ + + + diff --git a/main.c b/main.c index 887680a..5fa11e8 100644 --- a/main.c +++ b/main.c @@ -132,6 +132,41 @@ int main(const int argc, char const * argv[]) { int port = atoi(argc > 1 ? argv[1] : "8080"); 0 == port ? port = 8080 : port; + + // char * pidfile = NULL; + + + // char ** next_param = NULL; + // for(int i=1; i