1 --- /src/rastertokmlf.c 2006-11-17 09:49:53.297930424 +0100
2 +++ /src/rastertokmlf.c.new 2006-11-17 09:49:53.252954942 +0100
4 int write_bmp_header(cups_page_header_t *header, FILE *file);
7 -int /* 1 = success, 0 = failure */
8 - find_printer_make(const char *deviceuri, /* I - URI to connect on */
12 - http_t *http; /* HTTP connection to server */
13 - char method[HTTP_MAX_URI], /* URI method */
14 - userpass[HTTP_MAX_URI], /* username:password */
15 - server[HTTP_MAX_URI], /* Server */
16 - resource[HTTP_MAX_URI]; /* Resource path */
17 - int port; /* Port number */
18 - ipp_t *request, /* IPP request */
19 - *response; /* IPP response */
20 - ipp_attribute_t *attrptr; /* Attribute pointer */
21 - int pass=2; /* Did we pass the test? */
22 - char printer_uri[HTTP_MAX_URI];
23 - char *delim; /* Delimiter in file */
26 - char device[IPP_MAX_NAME], /* Device filename */
27 - probefile[IPP_MAX_NAME], /* Probe filename */
28 - basedevice[IPP_MAX_NAME]; /* Base device filename for ports */
30 - FILE *probe; /* /proc/parport/n/autoprobe file */
31 - char line[1024], /* Line from file */
32 - //device_id[1024], /* Device ID string */
34 - //make[IPP_MAX_NAME], /* Make from file */
35 - model[IPP_MAX_NAME]; /* Model from file */
41 - if (!strncmp(deviceuri, "usb:",4))
43 - if (!strncmp(deviceuri, "usb://",6))
45 - strlcpy(make, deviceuri + 6, IPP_MAX_NAME);
47 - if ((delim = strchr(make, '/')) != NULL)
51 - //if(!strncmp(deviceuri+6,"KONICA",6))
59 - if ((probe = fopen("/proc/bus/usb/devices", "r")) != NULL)
63 - memset(mfg, 0, sizeof(mfg));
64 - memset(model, 0, sizeof(model));
66 - while (fgets(line, sizeof(line), probe) != NULL)
69 - * Strip trailing newline.
72 - if ((delim = strrchr(line, '\n')) != NULL)
75 - * See if it is a printer device ("P: ...")
78 - if (strncmp(line, "S:", 2) == 0)
81 - * String attribute...
84 - if (strncmp(line, "S: Manufacturer=", 17) == 0)
86 - strlcpy(mfg, line + 17, sizeof(mfg));
87 - fprintf(stderr, "DEBUG: mfg is %s usb %d\n", mfg, i);
88 - if (strcmp(mfg, "Hewlett-Packard") == 0)
91 - else if (strncmp(line, "S: Product=", 12) == 0)
92 - strlcpy(model, line + 12, sizeof(model));
94 - else if (strncmp(line, "I:", 2) == 0 &&
95 - (strstr(line, "Driver=printer") != NULL ||
96 - strstr(line, "Driver=usblp") != NULL) &&
100 - * We were processing a printer device; send the info out...
103 - sprintf(device, "/dev/usb/lp%d", i);
104 - if (access(device, 0))
106 - sprintf(device, "/dev/usb/usblp%d", i);
108 - if (access(device, 0))
109 - sprintf(device, "/dev/usblp%d", i);
112 - fprintf(stderr, "DEBUG: direct usb:%s \"%s %s\" \"USB Printer #%d\"\n",
113 - device, mfg, model, i + 1);
115 - if (!strncmp(deviceuri+4,device,sizeof(device)))
117 - strlcpy(make, mfg, IPP_MAX_NAME);
124 - memset(mfg, 0, sizeof(mfg));
125 - memset(model, 0, sizeof(model));
133 - * Just check manually for USB devices...
135 - for (i = 0; i < 16; i ++)
137 - sprintf(device, "/dev/usb/lp%d", i);
139 - if (access(device, 0))
141 - sprintf(device, "/dev/usb/usblp%d", i);
143 - if (access(device, 0))
145 - sprintf(device, "/dev/usblp%d", i);
147 - if (access(device, 0))
152 - fprintf(stderr, "DEBUG: direct usb:%s \"Unknown\" \"USB Printer #%d\"\n", device, i + 1);
159 - else if (!strncmp(deviceuri, "socket:",7) ||
160 - !strncmp(deviceuri, "lpd:",4))
163 - * Connect to the server...
165 - httpSeparate(deviceuri, method, userpass, server, &port, resource);
167 - snprintf(printer_uri, sizeof(printer_uri),
168 - "http://%s:%d/ipp.cgi",server,port);
170 - //httpSeparate(printer_uri, method, userpass, server, &port, resource);
171 - if ((http = httpConnect(server, port)) == NULL)
173 - fprintf(stderr, "DEBUG: Unable to connect to %s on port %d\n", server, port);
178 - * Initialize things...
182 - request = ippNew();
185 - * Submit the IPP request...
188 - request->request.op.version[1] = 1;
189 - request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
190 - request->request.op.request_id = 1;
192 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
193 - "attributes-charset", NULL,
195 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
196 - "attributes-natural-language", NULL,
198 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
199 - "printer-uri", NULL, printer_uri);
201 - response = cupsDoRequest(http, request, "/ipp.cgi"); //resource);
203 - if (response == NULL)
206 - curtime = time(NULL);
208 - fprintf(stderr, "DEBUG: \b\b\b\b\bFAIL]\n");
209 - fprintf(stderr, "DEBUG: ERROR %x\n", cupsLastError());
210 - fprintf(stderr, "DEBUG: (%s) @ %s\n",
211 - ippErrorString(cupsLastError()), ctime(&curtime));
216 - attrptr=ippFindAttribute(response, "printer-make-and-model" , IPP_TAG_ZERO);
222 - fprintf(stderr, "DEBUG: \b\b\b\b\bFAIL]\n");
223 - fprintf(stderr, "DEBUG: (%lu bytes in response)\n",
224 - (unsigned long)ippLength(response));
231 - //fprintf(stderr, "DEBUG: \b\b\b\b\bPASS]\n");
232 - //fprintf(stderr, "DEBUG: (%lu bytes in response)\n",
233 - // (unsigned long)ippLength(response));
234 - fprintf(stderr, "DEBUG: printer maker is %s\n", attrptr->values[0].string.text);
235 - strlcpy(make,attrptr->values[0].string.text,msize);
239 - fputs("DEBUG: RECEIVED", stderr);
240 - fprintf(stderr, "DEBUG: status-code = %04x\n",
241 - response->request.status.status_code);
243 - ippDelete(response);
248 - else if (!strncmp(deviceuri, "parallel:",9))
250 - strlcpy(basedevice, "/dev/unknown-parallel",sizeof(basedevice));
251 - for (i = 0; i < 4; i ++)
254 - * First compare the device with deviceuri
256 - sprintf(device, "/dev/lp%d", i);
257 - if (!strncmp(deviceuri+9,device,8))
259 - strlcpy(basedevice, "/dev/lp",sizeof(basedevice));
263 - sprintf(device, "/dev/parallel/%d", i);
264 - if (!strncmp(deviceuri+9,device,15))
266 - strlcpy(basedevice, "/dev/parallel/", sizeof(basedevice));
270 - sprintf(device, "/dev/par%d", i);
271 - if (!strncmp(deviceuri+9,device,9))
273 - strlcpy(basedevice, "/dev/par",sizeof(basedevice));
277 - sprintf(device, "/dev/printers/%d", i);
278 - if (!strncmp(deviceuri+9,device,14))
280 - strlcpy(basedevice, "/dev/printers/",sizeof(basedevice));
286 - * Then try looking at the probe file...
290 - * Linux 2.4 kernel has different path...
293 - sprintf(probefile, "/proc/sys/dev/parport/parport%d/autoprobe", i);
294 - probe = fopen(probefile, "r");
299 - * Found a probe file!
302 - memset(make, 0, msize);
303 - memset(model, 0, sizeof(model));
304 - strlcpy(model, "Unknown",sizeof(model));
306 - while (fgets(line, sizeof(line), probe) != NULL)
309 - * Strip trailing ; and/or newline.
311 - if ((delim = strrchr(line, ';')) != NULL)
313 - else if ((delim = strrchr(line, '\n')) != NULL)
317 - * Look for MODEL and MANUFACTURER lines...
320 - if (strncmp(line, "MODEL:", 6) == 0 &&
321 - strncmp(line, "MODEL:Unknown", 13) != 0)
323 - strlcpy(model, line + 6, sizeof(model));
325 - else if (strncmp(line, "MANUFACTURER:", 13) == 0 &&
326 - strncmp(line, "MANUFACTURER:Unknown", 20) != 0)
328 - strlcpy(make, line + 13, msize);
336 - fprintf(stderr, "DEBUG: direct parallel:%s%d \"%s %s\" \"Parallel Port #%d\"\n",
337 - basedevice, i, make, model, i + 1);
342 - fprintf(stderr, "DEBUG: direct parallel:%s%d \"%s\" \"Parallel Port #%d\"\n",
343 - basedevice, i, model, i + 1);
355 * 'Setup()' - Prepare the printer for printing.
358 const char *device_uri; /* The device for the printer... */
359 cups_lang_t *language; /* Language information */
363 //reset colormatching flag
364 pImage = (PIMAGEHEADER)malloc(sizeof(IMAGEHEADER));
365 pImage->InitCM_HT = 0;
370 - char make[IPP_MAX_NAME];
371 fprintf(stderr, "DEBUG: deviceuri is %s\n",device_uri);
373 - //temporarily disable model check for magicolor 5430 DL
374 - //ret = find_printer_make(device_uri, make, sizeof(make));
379 - //fprintf(stderr, "ERROR: No Printer Information!\n");
380 - fprintf(stderr, "ERROR: Printer Not Found!\n");
383 - else if ( (1==ret) && (strncmp(make ,"KONICA", 6) ))
385 - //fprintf(stderr, "ERROR: Wrong Printer Found!\n");// %s\n",make);
386 - fprintf(stderr, "ERROR: Printer Not Found!\n");
391 - fprintf(stderr, "DEBUG: ipp/mdsn case, let it pass!\n");