| 1216 | */ |
| 1217 | |
| 1218 | cups_dest_t * /* O - Destination or @code NULL@ */ |
| 1219 | cupsGetDestWithURI(const char *name, /* I - Desired printer name or @code NULL@ */ |
| 1220 | const char *uri) /* I - URI for the printer */ |
| 1221 | { |
| 1222 | cups_dest_t *dest; /* New destination */ |
| 1223 | char temp[1024], /* Temporary string */ |
| 1224 | scheme[256], /* Scheme from URI */ |
| 1225 | userpass[256], /* Username:password from URI */ |
| 1226 | hostname[256], /* Hostname from URI */ |
| 1227 | resource[1024], /* Resource path from URI */ |
| 1228 | *ptr; /* Pointer into string */ |
| 1229 | const char *info; /* printer-info string */ |
| 1230 | int port; /* Port number from URI */ |
| 1231 | |
| 1232 | |
| 1233 | /* |
| 1234 | * Range check input... |
| 1235 | */ |
| 1236 | |
| 1237 | if (!uri) |
| 1238 | { |
| 1239 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
| 1240 | return (NULL); |
| 1241 | } |
| 1242 | |
| 1243 | if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), userpass, sizeof(userpass), hostname, sizeof(hostname), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK || |
| 1244 | (strncmp(uri, "ipp://", 6) && strncmp(uri, "ipps://", 7))) |
| 1245 | { |
| 1246 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad printer-uri."), 1); |
| 1247 | |
| 1248 | return (NULL); |
| 1249 | } |
| 1250 | |
| 1251 | if (name) |
| 1252 | { |
| 1253 | info = name; |
| 1254 | } |
| 1255 | else |
| 1256 | { |
| 1257 | /* |
| 1258 | * Create the name from the URI... |
| 1259 | */ |
| 1260 | |
| 1261 | if (strstr(hostname, "._tcp")) |
| 1262 | { |
| 1263 | /* |
| 1264 | * Use the service instance name... |
| 1265 | */ |
| 1266 | |
| 1267 | if ((ptr = strstr(hostname, "._")) != NULL) |
| 1268 | *ptr = '\0'; |
| 1269 | |
| 1270 | cups_queue_name(temp, hostname, sizeof(temp)); |
| 1271 | name = temp; |
| 1272 | info = hostname; |
| 1273 | } |
| 1274 | else if (!strncmp(resource, "/classes/", 9)) |
| 1275 | { |