| 1234 | */ |
| 1235 | |
| 1236 | static int /* O - File descriptor or -1 on error */ |
| 1237 | create_job_file( |
| 1238 | ippeve_job_t *job, /* I - Job */ |
| 1239 | char *fname, /* I - Filename buffer */ |
| 1240 | size_t fnamesize, /* I - Size of filename buffer */ |
| 1241 | const char *directory, /* I - Directory to store in */ |
| 1242 | const char *ext) /* I - Extension (`NULL` for default) */ |
| 1243 | { |
| 1244 | char name[256], /* "Safe" filename */ |
| 1245 | *nameptr; /* Pointer into filename */ |
| 1246 | const char *job_name; /* job-name value */ |
| 1247 | |
| 1248 | |
| 1249 | /* |
| 1250 | * Make a name from the job-name attribute... |
| 1251 | */ |
| 1252 | |
| 1253 | if ((job_name = ippGetString(ippFindAttribute(job->attrs, "job-name", IPP_TAG_NAME), 0, NULL)) == NULL) |
| 1254 | job_name = "untitled"; |
| 1255 | |
| 1256 | for (nameptr = name; *job_name && nameptr < (name + sizeof(name) - 1); job_name ++) |
| 1257 | { |
| 1258 | if (isalnum(*job_name & 255) || *job_name == '-') |
| 1259 | { |
| 1260 | *nameptr++ = (char)tolower(*job_name & 255); |
| 1261 | } |
| 1262 | else |
| 1263 | { |
| 1264 | *nameptr++ = '_'; |
| 1265 | |
| 1266 | while (job_name[1] && !isalnum(job_name[1] & 255) && job_name[1] != '-') |
| 1267 | job_name ++; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | *nameptr = '\0'; |
| 1272 | |
| 1273 | /* |
| 1274 | * Figure out the extension... |
| 1275 | */ |
| 1276 | |
| 1277 | if (!ext) |
| 1278 | { |
| 1279 | if (!strcasecmp(job->format, "image/jpeg")) |
| 1280 | ext = "jpg"; |
| 1281 | else if (!strcasecmp(job->format, "image/png")) |
| 1282 | ext = "png"; |
| 1283 | else if (!strcasecmp(job->format, "image/pwg-raster")) |
| 1284 | ext = "pwg"; |
| 1285 | else if (!strcasecmp(job->format, "image/urf")) |
| 1286 | ext = "urf"; |
| 1287 | else if (!strcasecmp(job->format, "application/pdf")) |
| 1288 | ext = "pdf"; |
| 1289 | else if (!strcasecmp(job->format, "application/postscript")) |
| 1290 | ext = "ps"; |
| 1291 | else if (!strcasecmp(job->format, "application/vnd.hp-pcl")) |
| 1292 | ext = "pcl"; |
| 1293 | else |
no test coverage detected