diff options
Diffstat (limited to 'cgi.c')
-rw-r--r-- | cgi.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -42,12 +42,16 @@ static const char * line1 = NULL, * line2 = NULL; | |||
42 | 42 | ||
43 | int print_on_correct_printer(void * user_data, unsigned flags, cups_dest_t * dest) { | 43 | int print_on_correct_printer(void * user_data, unsigned flags, cups_dest_t * dest) { |
44 | if(!strstr(dest->name, user_data)) { | 44 | if(!strstr(dest->name, user_data)) { |
45 | printf("> Wrong name: %s continue search\n", dest->name); | 45 | // DEBUG("> Wrong printer name: '%s'; try next printer...\n", dest->name); |
46 | return 1; | 46 | return 1; |
47 | } | 47 | } |
48 | 48 | ||
49 | if(!dest || !line1 || !line2) { | 49 | DEBUG("> Correct printer found: %s\n", dest->name); |
50 | printf("FAILED: %p %p %p\n", dest, line1, line2); | 50 | |
51 | if(!dest | ||
52 | || !line1 | ||
53 | || !line2) { | ||
54 | DEBUG("> Nothing to print or printer not found: %p %p %p\n", dest, line1, line2); | ||
51 | return 1; | 55 | return 1; |
52 | } | 56 | } |
53 | 57 | ||
@@ -63,20 +67,22 @@ int print_on_correct_printer(void * user_data, unsigned flags, cups_dest_t * des | |||
63 | cups_dinfo_t * info = cupsCopyDestInfo(CUPS_HTTP_DEFAULT, dest); | 67 | cups_dinfo_t * info = cupsCopyDestInfo(CUPS_HTTP_DEFAULT, dest); |
64 | 68 | ||
65 | if (cupsCreateDestJob(CUPS_HTTP_DEFAULT, dest, info, &job_id, "My Document", num_options, options) == IPP_STATUS_OK) | 69 | if (cupsCreateDestJob(CUPS_HTTP_DEFAULT, dest, info, &job_id, "My Document", num_options, options) == IPP_STATUS_OK) |
66 | printf("Created job: %d\n", job_id); | 70 | DEBUG("> Created job: %d\n", job_id); |
67 | else | 71 | else |
68 | printf("Unable to create job: %s\n", cupsLastErrorString()); | 72 | DEBUG("> Unable to create job: %s\n", cupsLastErrorString()); |
69 | 73 | ||
70 | if (cupsStartDestDocument(CUPS_HTTP_DEFAULT, dest, info, job_id, "filename.pdf", CUPS_FORMAT_TEXT, num_options, options, 1) == HTTP_STATUS_CONTINUE) | 74 | if (cupsStartDestDocument(CUPS_HTTP_DEFAULT, dest, info, job_id, "filename.pdf", CUPS_FORMAT_TEXT, num_options, options, 1) == HTTP_STATUS_CONTINUE) |
71 | { | 75 | { |
76 | DEBUG("> printing label:\n>\t%s\n>\t%s\n", line1, line2); | ||
77 | |||
72 | cupsWriteRequestData(CUPS_HTTP_DEFAULT, line1, strlen(line1)); | 78 | cupsWriteRequestData(CUPS_HTTP_DEFAULT, line1, strlen(line1)); |
73 | cupsWriteRequestData(CUPS_HTTP_DEFAULT, "\n", 1); | 79 | cupsWriteRequestData(CUPS_HTTP_DEFAULT, "\n", 1); |
74 | cupsWriteRequestData(CUPS_HTTP_DEFAULT, line2, strlen(line2)); | 80 | cupsWriteRequestData(CUPS_HTTP_DEFAULT, line2, strlen(line2)); |
75 | 81 | ||
76 | if (cupsFinishDestDocument(CUPS_HTTP_DEFAULT, dest, info) == IPP_STATUS_OK) | 82 | if (cupsFinishDestDocument(CUPS_HTTP_DEFAULT, dest, info) == IPP_STATUS_OK) |
77 | puts("Document send succeeded."); | 83 | DEBUG("> Document send succeeded."); |
78 | else | 84 | else |
79 | printf("Document send failed: %s\n", cupsLastErrorString()); | 85 | DEBUG("> Document send failed: %s\n", cupsLastErrorString()); |
80 | } | 86 | } |
81 | return 0; | 87 | return 0; |
82 | } | 88 | } |
@@ -116,16 +122,18 @@ void send_answer(Http_Header * http_header, FILE * f) { | |||
116 | print_on_correct_printer, | 122 | print_on_correct_printer, |
117 | printer_name | 123 | printer_name |
118 | ); | 124 | ); |
125 | |||
119 | line1 = NULL; | 126 | line1 = NULL; |
120 | line2 = NULL; | 127 | line2 = NULL; |
121 | 128 | ||
122 | send_answer_file(http_header, f); | 129 | send_answer_file(http_header, f); |
123 | } | 130 | } |
124 | 131 | ||
125 | |||
126 | void next_part(Http_Header * http_header, const char * content, size_t content_size) { | 132 | void next_part(Http_Header * http_header, const char * content, size_t content_size) { |
127 | if(!http_header->content_disposition) | 133 | if(!http_header->content_disposition) { |
134 | DEBUG("> No Content-Disposition header found\n"); | ||
128 | return; | 135 | return; |
136 | } | ||
129 | 137 | ||
130 | if(strstr(http_header->content_disposition, "name=\"line1\"")) { | 138 | if(strstr(http_header->content_disposition, "name=\"line1\"")) { |
131 | line1 = content; | 139 | line1 = content; |