| 55 | */ |
| 56 | |
| 57 | cupsd_printer_t * /* O - New printer */ |
| 58 | cupsdAddPrinter(const char *name) /* I - Name of printer */ |
| 59 | { |
| 60 | cupsd_printer_t *p; /* New printer */ |
| 61 | char uri[1024], /* Printer URI */ |
| 62 | uuid[64]; /* Printer UUID */ |
| 63 | |
| 64 | |
| 65 | /* |
| 66 | * Range check input... |
| 67 | */ |
| 68 | |
| 69 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddPrinter(\"%s\")", name); |
| 70 | |
| 71 | /* |
| 72 | * Create a new printer entity... |
| 73 | */ |
| 74 | |
| 75 | if ((p = calloc(1, sizeof(cupsd_printer_t))) == NULL) |
| 76 | { |
| 77 | cupsdLogMessage(CUPSD_LOG_CRIT, "Unable to allocate memory for printer - %s", |
| 78 | strerror(errno)); |
| 79 | return (NULL); |
| 80 | } |
| 81 | |
| 82 | _cupsRWInit(&p->lock); |
| 83 | |
| 84 | cupsdSetString(&p->name, name); |
| 85 | cupsdSetString(&p->info, name); |
| 86 | cupsdSetString(&p->hostname, ServerName); |
| 87 | |
| 88 | httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, |
| 89 | ServerName, RemotePort, "/printers/%s", name); |
| 90 | cupsdSetString(&p->uri, uri); |
| 91 | cupsdSetString(&p->uuid, httpAssembleUUID(ServerName, RemotePort, name, 0, |
| 92 | uuid, sizeof(uuid))); |
| 93 | cupsdSetDeviceURI(p, "file:///dev/null"); |
| 94 | |
| 95 | p->config_time = time(NULL); |
| 96 | p->state = IPP_PRINTER_STOPPED; |
| 97 | p->state_time = time(NULL); |
| 98 | p->accepting = 0; |
| 99 | p->shared = DefaultShared; |
| 100 | |
| 101 | _cupsRWLockWrite(&MimeDatabase->lock); |
| 102 | |
| 103 | p->filetype = mimeAddType(MimeDatabase, "printer", name); |
| 104 | |
| 105 | _cupsRWUnlock(&MimeDatabase->lock); |
| 106 | |
| 107 | cupsdSetString(&p->job_sheets[0], "none"); |
| 108 | cupsdSetString(&p->job_sheets[1], "none"); |
| 109 | |
| 110 | cupsdSetString(&p->error_policy, ErrorPolicy); |
| 111 | cupsdSetString(&p->op_policy, DefaultPolicy); |
| 112 | |
| 113 | p->op_policy_ptr = DefaultPolicyPtr; |
| 114 |
no test coverage detected