summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Christian Pohle2021-12-04 14:29:49 +0100
committerMax Christian Pohle2021-12-04 14:29:49 +0100
commitbef7e1a6f6ed28d580b331063baa35b34a8f1d25 (patch)
tree2fdf190056351d42430bc2241f2c788f02673264
parent512c406b4fb3bc4054073608707ae07f65a65890 (diff)
downloadohmycgi-labelprinter.tar.bz2
ohmycgi-labelprinter.zip
Prepared `letter` type and updated CSSlabelprinter
-rw-r--r--Makefile5
-rw-r--r--README.md3
-rw-r--r--cgi.c23
-rw-r--r--default.css80
-rw-r--r--index.html51
-rw-r--r--letter.html24
-rw-r--r--main.c35
7 files changed, 171 insertions, 50 deletions
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
4cflags.release := -os -s 4cflags.release := -os -s
5CFLAGS := ${cflags.${BUILD}} 5CFLAGS := ${cflags.${BUILD}}
6 6
7LIBS := -lcups 7LIBS := -lcups -lmagic
8 8
9CFLAGS += -L/usr/local/lib 9CFLAGS += -L/usr/local/lib
10CFLAGS += -I/usr/local/include 10CFLAGS += -I/usr/local/include
@@ -14,6 +14,9 @@ FILES := cgi.c http_parser.c
14test: main 14test: main
15 ./main.${BUILD} 15 ./main.${BUILD}
16 16
17test_param: main
18 ./main.${BUILD} --test1 -a -b -c --test2 --pidfile=foo --pidfile foobar
19
17main: clean 20main: clean
18 $(CC) $(CFLAGS) -o $@.${BUILD} $(FILES) main.c $(LIBS) 21 $(CC) $(CFLAGS) -o $@.${BUILD} $(FILES) main.c $(LIBS)
19 22
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0f7b2aa
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
1ohmycgi 😇 - the missing piece
2
3
diff --git a/cgi.c b/cgi.c
index 81149af..a1f5ae2 100644
--- a/cgi.c
+++ b/cgi.c
@@ -37,9 +37,11 @@
37 37
38#include "main.h" 38#include "main.h"
39#include <cups/cups.h> 39#include <cups/cups.h>
40#include <magic.h>
40 41
41static const char * line1 = NULL, * line2 = NULL; 42static const char * line1 = NULL, * line2 = NULL;
42 43
44
43int print_on_correct_printer(void * user_data, unsigned flags, cups_dest_t * dest) { 45int print_on_correct_printer(void * user_data, unsigned flags, cups_dest_t * dest) {
44 if(!strstr(dest->name, user_data)) { 46 if(!strstr(dest->name, user_data)) {
45 // DEBUG("> Wrong printer name: '%s'; try next printer...\n", dest->name); 47 // 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
89 91
90void send_answer_file(Http_Header * http_header, FILE * f) { 92void send_answer_file(Http_Header * http_header, FILE * f) {
91 fputs("HTTP/1.0 200 OK\n", f); 93 fputs("HTTP/1.0 200 OK\n", f);
92 fputs("content-type: text/html\n\n", f); 94
95 DEBUG("> PROBLEM: %s\n", &http_header->url[strlen(http_header->url) - 4]);
96 if(0 == strncmp(&http_header->url[strlen(http_header->url) - 4], ".css", 4)) {
97 fputs("content-type: text/css", f);
98 } else {
99
100 magic_t magic = magic_open(MAGIC_MIME);
101
102 magic_load(magic, NULL);
103 // magic_compile(magic, NULL);
104 const char * mime_type = magic_file(magic, &http_header->url[1]);
105 if(mime_type)
106 fprintf(f, "content-type: %s\n\n", mime_type);
107 else
108 fputs("content-type: text/html; charset=utf-8", f);
109 // fprintf(f, "content-type: %s; charset=utf-8\n\n", magic_file(magic, &http_header->url[1]));
110 magic_close(magic);
111 }
112
113 fputs("\n\n", f);
93 fflush(f); 114 fflush(f);
94 115
95 #define BUFFER_SIZE 1024 116 #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 @@
1@charset "UTF-8";
2
3html,body {
4 background: Window;
5 font: caption;
6 color: WindowText;
7 margin:0;
8 height:100%;
9 overflow:hidden;
10 line-height: 1.5;
11 letter-spacing: 0.033em;
12}
13
14body {
15 padding:2em;
16}
17
18h1 {
19 margin-top:0;
20}
21
22label {
23 font-size:x-small;
24 color:GrayText;
25}
26
27form {
28 border:2px solid Window;
29 border-radius: 1em;
30 padding: 2em;
31 background: AppWorkspace;
32}
33
34input, textarea {
35 background: Menu;
36 color: MenuText;
37 cursor:pointer;
38 font: caption;
39 padding: 0.3em 0.5em;
40 width:25ex;
41 height:6em;
42 border: 3px ridge;
43 border-width: 0px 0px 2px 0px;
44 border-color: ButtonShadow;
45 margin-right:2em;
46}
47
48input.label {
49 height:1.5em;
50}
51
52input[type="submit"] {
53 width:inherit;
54 height:inherit;
55 border-radius:1ex;
56 border-width:2px;
57 font-weight:bold;
58 background-color: ButtonFace;
59 color: ButtonText;
60}
61
62input:hover, input:active, textarea:hover, textarea:active {
63 background-color:Highlight;
64 color:HighlightText;
65}
66
67div.content {
68 position: relative;
69 width:50%;
70}
71
72div.content textarea[name="text"] {
73 height:12em;
74 width:100%;
75}
76
77br.clear {
78 clear:both;
79}
80
diff --git a/index.html b/index.html
index 9b5ffdf..897fcb8 100644
--- a/index.html
+++ b/index.html
@@ -4,59 +4,14 @@
4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head> 5 <head>
6 <title>print label</title> 6 <title>print label</title>
7 <style> 7 <link rel="stylesheet" type="text/css" href="default.css"/>
8 html,body {
9 font: caption;
10 background-color: Background;
11 margin:0;
12 height:100%;
13 overflow:hidden;
14 }
15 body {
16 padding:2em;
17 }
18 h1 {
19 margin-top:0;
20 }
21 label {
22 font-size:x-small;
23 color:GrayText;
24 }
25 form {
26 border:2px solid Background;
27 border-radius: 1em;
28 padding: 2em;
29 background: AppWorkspace;
30 }
31 input {
32 background: AppWorkspace;
33 cursor:pointer;
34 font: caption;
35 padding: 0.3em 0.5em;
36 width:20ex;
37 border: 3px ridge;
38 border-width: 0px 0px 3px 0px;
39 border-color: ButtonShadow;
40 }
41
42 input[type="submit"] {
43 width:inherit;
44 background: AppWorkspace;
45 margin-left:2em;
46 border-radius:0.5em;
47 border-width:3px;
48 font-weight:bold;
49 }
50
51 </style>
52 </head> 8 </head>
53
54 <body> 9 <body>
55 10
56 <form method="post" enctype="multipart/form-data"> 11 <form method="post" enctype="multipart/form-data">
57 <h1>Simple label</h1> 12 <h1>Simple label</h1>
58 <label>line1<br/><input type="text" name="line1" /></label><br/> 13 <label>line1<br/><input type="text" class="label" name="line1" /></label><br/>
59 <label>line2<br/><input type="text" name="line2" /></label> 14 <label>line2<br/><input type="text" class="label" name="line2" /></label>
60 <input type="submit" value="print" /> 15 <input type="submit" value="print" />
61 </form> 16 </form>
62 </body> 17 </body>
diff --git a/letter.html b/letter.html
new file mode 100644
index 0000000..19ed778
--- /dev/null
+++ b/letter.html
@@ -0,0 +1,24 @@
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5 <title>print letter</title>
6 <link rel="stylesheet" type="text/css" href="default.css"/>
7 </head>
8 <body>
9 <form method="post" enctype="multipart/form-data">
10 <h1>Letter</h1>
11 <div class="content">
12 <label>sender<br/><textarea name="sender"></textarea></label><br/>
13 <label>receiver<br/><textarea name="receiver"></textarea></label><br/>
14 <label>text<br/><textarea name="text"></textarea></label><br/>
15 </div>
16 <input type="submit" value="print" />
17 <input type="submit" value="download" />
18 <br class="clear" />
19 </form>
20 </body>
21</html>
22
23<!-- vim: tabstop=4 shiftwidth=4 expandtab
24-->
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[]) {
132 int port = atoi(argc > 1 ? argv[1] : "8080"); 132 int port = atoi(argc > 1 ? argv[1] : "8080");
133 0 == port ? port = 8080 : port; 133 0 == port ? port = 8080 : port;
134 134
135
136 // char * pidfile = NULL;
137
138
139 // char ** next_param = NULL;
140 // for(int i=1; i<argc; i++) {
141 // switch(strspn(argv[i], "-")) {
142 // case 1: // one minus (short param)
143 // if(argv[i][2] != '\0') // one minus, one param and a null char
144 // break;
145 // if(next_param)
146 // err(EXIT_FAILURE, "wrong parameter: %s\n", argv[i]);
147 // switch(argv[i][1]) {
148 // case 't': puts("t was chosen"); break;
149 // case 'e': puts("e was chosen"); break;
150 // case 's': puts("s was chosen"); break;
151 // }
152 // break;
153 // case 2: // two minus (long param)
154 // if(next_param)
155 // err(EXIT_FAILURE, "wrong parameter: %s\n", argv[i]);
156 // if(0 == strcmp("pidfile", &argv[i][2])) {
157 // next_param = &pidfile;
158 // }
159 // break;
160 // default:
161 // // pidfile = (char*) argv[i];
162 // *next_param = (char*) argv[i];
163 // }
164 // }
165
166 // printf("pidfile is '%s'\n", pidfile);
167
168 // return EXIT_SUCCESS;
169
135 struct sockaddr_in address = { 170 struct sockaddr_in address = {
136 .sin_family = AF_INET, 171 .sin_family = AF_INET,
137 .sin_addr.s_addr = INADDR_ANY, 172 .sin_addr.s_addr = INADDR_ANY,
..