| 250 | */ |
| 251 | |
| 252 | int /* O - New number of destinations */ |
| 253 | cupsAddDest(const char *name, /* I - Destination name */ |
| 254 | const char *instance, /* I - Instance name or @code NULL@ for none/primary */ |
| 255 | int num_dests, /* I - Number of destinations */ |
| 256 | cups_dest_t **dests) /* IO - Destinations */ |
| 257 | { |
| 258 | int i; /* Looping var */ |
| 259 | cups_dest_t *dest; /* Destination pointer */ |
| 260 | cups_dest_t *parent = NULL; /* Parent destination */ |
| 261 | cups_option_t *doption, /* Current destination option */ |
| 262 | *poption; /* Current parent option */ |
| 263 | |
| 264 | |
| 265 | if (!name || !dests) |
| 266 | return (0); |
| 267 | |
| 268 | if (!cupsGetDest(name, instance, num_dests, *dests)) |
| 269 | { |
| 270 | if (instance && !cupsGetDest(name, NULL, num_dests, *dests)) |
| 271 | { |
| 272 | // Add destination first... |
| 273 | if (!cups_add_dest(name, NULL, &num_dests, dests)) |
| 274 | return (num_dests); |
| 275 | } |
| 276 | |
| 277 | if ((dest = cups_add_dest(name, instance, &num_dests, dests)) == NULL) |
| 278 | return (num_dests); |
| 279 | |
| 280 | /* |
| 281 | * Find the base dest again now the array has been realloc'd. |
| 282 | */ |
| 283 | |
| 284 | parent = cupsGetDest(name, NULL, num_dests, *dests); |
| 285 | |
| 286 | if (instance && parent && parent->num_options > 0) |
| 287 | { |
| 288 | /* |
| 289 | * Copy options from parent... |
| 290 | */ |
| 291 | |
| 292 | dest->options = calloc((size_t)parent->num_options, sizeof(cups_option_t)); |
| 293 | |
| 294 | if (dest->options) |
| 295 | { |
| 296 | dest->num_options = parent->num_options; |
| 297 | |
| 298 | for (i = dest->num_options, doption = dest->options, |
| 299 | poption = parent->options; |
| 300 | i > 0; |
| 301 | i --, doption ++, poption ++) |
| 302 | { |
| 303 | doption->name = _cupsStrRetain(poption->name); |
| 304 | doption->value = _cupsStrRetain(poption->value); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 |
no test coverage detected