int /* O - New number of options */ cupsRemoveOption( const char *name, /* I - Option name */ int num_options, /* I - Current number of options */ cups_option_t **options) /* IO - Options */ { int i; /* Looping var */ cups_option_t *option; /* Current option */ DEBUG_printf(("2cupsRemoveOption(name=\"%s\", num_options=%d, options=%p)", name, num_options, options)); /* * Range check input... */ if (!name || num_options < 1 || !options) { DEBUG_printf(("3cupsRemoveOption: Returning %d", num_options)); return (num_options); } /* * Loop for the option... */ for (i = num_options, option = *options; i > 0; i --, option ++) if (!_cups_strcasecmp(name, option->name)) break; if (i) { /* * Remove this option from the array... */ DEBUG_puts("4cupsRemoveOption: Found option, removing it..."); num_options --; i --; _cupsStrFree(option->name); _cupsStrFree(option->value); if (i > 0) memmove(option, option + 1, (size_t)i * sizeof(cups_option_t)); } /* * Return the new number of options... */ DEBUG_printf(("3cupsRemoveOption: Returning %d", num_options)); return (num_options); }
int /* O - 1 on success, 0 on failure */ cupsSetServerCredentials( const char *path, /* I - Path to keychain/directory */ const char *common_name, /* I - Default common name for server */ int auto_create) /* I - 1 = automatically create self-signed certificates */ { char temp[1024]; /* Default path buffer */ DEBUG_printf(("cupsSetServerCredentials(path=\"%s\", common_name=\"%s\", auto_create=%d)", path, common_name, auto_create)); /* * Use defaults as needed... */ if (!path) path = http_gnutls_default_path(temp, sizeof(temp)); /* * Range check input... */ if (!path || !common_name) { _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); return (0); } _cupsMutexLock(&tls_mutex); /* * Free old values... */ if (tls_keypath) _cupsStrFree(tls_keypath); if (tls_common_name) _cupsStrFree(tls_common_name); /* * Save the new values... */ tls_keypath = _cupsStrAlloc(path); tls_auto_create = auto_create; tls_common_name = _cupsStrAlloc(common_name); _cupsMutexUnlock(&tls_mutex); return (1); }
void cupsdSetStringf(char **s, /* O - New string */ const char *f, /* I - Printf-style format string */ ...) /* I - Additional args as needed */ { char v[4096]; /* Formatting string value */ va_list ap; /* Argument pointer */ char *olds; /* Old string */ if (!s) return; olds = *s; if (f) { va_start(ap, f); vsnprintf(v, sizeof(v), f, ap); va_end(ap); *s = _cupsStrAlloc(v); } else *s = NULL; if (olds) _cupsStrFree(olds); }
void cgiSetVariable(const char *name, /* I - Name of variable */ const char *value) /* I - Value of variable */ { int i; /* Looping var */ _cgi_var_t *var; /* Returned variable */ if (name == NULL || value == NULL) return; fprintf(stderr, "cgiSetVariable: %s=\"%s\"\n", name, value); if ((var = cgi_find_variable(name)) == NULL) { cgi_add_variable(name, 0, value); cgi_sort_variables(); } else { for (i = 0; i < var->nvalues; i ++) if (var->values[i]) _cupsStrFree((char *)var->values[i]); var->values[0] = _cupsStrAlloc(value); var->nvalues = 1; } }
static void cups_globals_free(_cups_globals_t *cg) /* I - Pointer to global data */ { _cups_buffer_t *buffer, /* Current read/write buffer */ *next; /* Next buffer */ if (cg->last_status_message) _cupsStrFree(cg->last_status_message); for (buffer = cg->cups_buffers; buffer; buffer = next) { next = buffer->next; free(buffer); } cupsArrayDelete(cg->leg_size_lut); cupsArrayDelete(cg->ppd_size_lut); cupsArrayDelete(cg->pwg_size_lut); httpClose(cg->http); _httpFreeCredentials(cg->tls_credentials); cupsFileClose(cg->stdio_files[0]); cupsFileClose(cg->stdio_files[1]); cupsFileClose(cg->stdio_files[2]); cupsFreeOptions(cg->cupsd_num_settings, cg->cupsd_settings); free(cg); }
void cupsdClearString(char **s) /* O - String value */ { if (s && *s) { _cupsStrFree(*s); *s = NULL; } }
void cupsFreeOptions( int num_options, /* I - Number of options */ cups_option_t *options) /* I - Pointer to options */ { int i; /* Looping var */ DEBUG_printf(("cupsFreeOptions(num_options=%d, options=%p)", num_options, (void *)options)); if (num_options <= 0 || !options) return; for (i = 0; i < num_options; i ++) { _cupsStrFree(options[i].name); _cupsStrFree(options[i].value); } free(options); }
void cgiClearVariables(void) { int i, j; /* Looping vars */ _cgi_var_t *v; /* Current variable */ fputs("DEBUG: cgiClearVariables called.\n", stderr); for (v = form_vars, i = form_count; i > 0; v ++, i --) { _cupsStrFree(v->name); for (j = 0; j < v->nvalues; j ++) if (v->values[j]) _cupsStrFree(v->values[j]); } form_count = 0; cgi_unlink_file(); }
void cupsFreeJobs(int num_jobs, /* I - Number of jobs */ cups_job_t *jobs) /* I - Jobs */ { int i; /* Looping var */ cups_job_t *job; /* Current job */ if (num_jobs <= 0 || !jobs) return; for (i = num_jobs, job = jobs; i > 0; i --, job ++) { _cupsStrFree(job->dest); _cupsStrFree(job->user); _cupsStrFree(job->format); _cupsStrFree(job->title); } free(jobs); }
void cupsdSetString(char **s, /* O - New string */ const char *v) /* I - String value */ { if (!s || *s == v) return; if (*s) _cupsStrFree(*s); if (v) *s = _cupsStrAlloc(v); else *s = NULL; }
void cgiSetArray(const char *name, /* I - Name of variable */ int element, /* I - Element number (0 to N) */ const char *value) /* I - Value of variable */ { int i; /* Looping var */ _cgi_var_t *var; /* Returned variable */ if (name == NULL || value == NULL || element < 0 || element > 100000) return; fprintf(stderr, "DEBUG: cgiSetArray: %s[%d]=\"%s\"\n", name, element, value); if ((var = cgi_find_variable(name)) == NULL) { cgi_add_variable(name, element, value); cgi_sort_variables(); } else { if (element >= var->avalues) { const char **temp; /* Temporary pointer */ temp = (const char **)realloc((void *)(var->values), sizeof(char *) * (size_t)(element + 16)); if (!temp) return; var->avalues = element + 16; var->values = temp; } if (element >= var->nvalues) { for (i = var->nvalues; i < element; i ++) var->values[i] = NULL; var->nvalues = element + 1; } else if (var->values[element]) _cupsStrFree((char *)var->values[element]); var->values[element] = _cupsStrAlloc(value); } }
void _cupsSetError(ipp_status_t status, /* I - IPP status code */ const char *message, /* I - status-message value */ int localize) /* I - Localize the message? */ { _cups_globals_t *cg; /* Global data */ if (!message && errno) { message = strerror(errno); localize = 0; } cg = _cupsGlobals(); cg->last_error = status; if (cg->last_status_message) { _cupsStrFree(cg->last_status_message); cg->last_status_message = NULL; } if (message) { if (localize) { /* * Get the message catalog... */ if (!cg->lang_default) cg->lang_default = cupsLangDefault(); cg->last_status_message = _cupsStrAlloc(_cupsLangString(cg->lang_default, message)); } else cg->last_status_message = _cupsStrAlloc(message); } DEBUG_printf(("4_cupsSetError: last_error=%s, last_status_message=\"%s\"", ippErrorString(cg->last_error), cg->last_status_message)); }
void cgiSetSize(const char *name, /* I - Name of variable */ int size) /* I - Number of elements (0 to N) */ { int i; /* Looping var */ _cgi_var_t *var; /* Returned variable */ if (name == NULL || size < 0 || size > 100000) return; if ((var = cgi_find_variable(name)) == NULL) return; if (size >= var->avalues) { const char **temp; /* Temporary pointer */ temp = (const char **)realloc((void *)(var->values), sizeof(char *) * (size_t)(size + 16)); if (!temp) return; var->avalues = size + 16; var->values = temp; } if (size > var->nvalues) { for (i = var->nvalues; i < size; i ++) var->values[i] = NULL; } else if (size < var->nvalues) { for (i = size; i < var->nvalues; i ++) if (var->values[i]) _cupsStrFree((void *)(var->values[i])); } var->nvalues = size; }
static void ppd_mark_option(ppd_file_t *ppd, /* I - PPD file */ const char *option, /* I - Option name */ const char *choice) /* I - Choice name */ { int i, j; /* Looping vars */ ppd_option_t *o; /* Option pointer */ ppd_choice_t *c, /* Choice pointer */ *oldc, /* Old choice pointer */ key; /* Search key for choice */ struct lconv *loc; /* Locale data */ DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")", ppd, option, choice)); /* * AP_D_InputSlot is the "default input slot" on MacOS X, and setting * it clears the regular InputSlot choices... */ if (!_cups_strcasecmp(option, "AP_D_InputSlot")) { cupsArraySave(ppd->options); if ((o = ppdFindOption(ppd, "InputSlot")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } cupsArrayRestore(ppd->options); } /* * Check for custom options... */ cupsArraySave(ppd->options); o = ppdFindOption(ppd, option); cupsArrayRestore(ppd->options); if (!o) return; loc = localeconv(); if (!_cups_strncasecmp(choice, "Custom.", 7)) { /* * Handle a custom option... */ if ((c = ppdFindChoice(o, "Custom")) == NULL) return; if (!_cups_strcasecmp(option, "PageSize")) { /* * Handle custom page sizes... */ ppdPageSize(ppd, choice); } else { /* * Handle other custom options... */ ppd_coption_t *coption; /* Custom option */ ppd_cparam_t *cparam; /* Custom parameter */ char *units; /* Custom points units */ if ((coption = ppdFindCustomOption(ppd, option)) != NULL) { if ((cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params)) == NULL) return; switch (cparam->type) { case PPD_CUSTOM_CURVE : case PPD_CUSTOM_INVCURVE : case PPD_CUSTOM_REAL : cparam->current.custom_real = (float)_cupsStrScand(choice + 7, NULL, loc); break; case PPD_CUSTOM_POINTS : cparam->current.custom_points = (float)_cupsStrScand(choice + 7, &units, loc); if (units) { if (!_cups_strcasecmp(units, "cm")) cparam->current.custom_points *= 72.0f / 2.54f; else if (!_cups_strcasecmp(units, "mm")) cparam->current.custom_points *= 72.0f / 25.4f; else if (!_cups_strcasecmp(units, "m")) cparam->current.custom_points *= 72.0f / 0.0254f; else if (!_cups_strcasecmp(units, "in")) cparam->current.custom_points *= 72.0f; else if (!_cups_strcasecmp(units, "ft")) cparam->current.custom_points *= 12.0f * 72.0f; } break; case PPD_CUSTOM_INT : cparam->current.custom_int = atoi(choice + 7); break; case PPD_CUSTOM_PASSCODE : case PPD_CUSTOM_PASSWORD : case PPD_CUSTOM_STRING : if (cparam->current.custom_string) _cupsStrFree(cparam->current.custom_string); cparam->current.custom_string = _cupsStrAlloc(choice + 7); break; } } } /* * Make sure that we keep the option marked below... */ choice = "Custom"; } else if (choice[0] == '{') { /* * Handle multi-value custom options... */ ppd_coption_t *coption; /* Custom option */ ppd_cparam_t *cparam; /* Custom parameter */ char *units; /* Custom points units */ int num_vals; /* Number of values */ cups_option_t *vals, /* Values */ *val; /* Value */ if ((c = ppdFindChoice(o, "Custom")) == NULL) return; if ((coption = ppdFindCustomOption(ppd, option)) != NULL) { num_vals = cupsParseOptions(choice, 0, &vals); for (i = 0, val = vals; i < num_vals; i ++, val ++) { if ((cparam = ppdFindCustomParam(coption, val->name)) == NULL) continue; switch (cparam->type) { case PPD_CUSTOM_CURVE : case PPD_CUSTOM_INVCURVE : case PPD_CUSTOM_REAL : cparam->current.custom_real = (float)_cupsStrScand(val->value, NULL, loc); break; case PPD_CUSTOM_POINTS : cparam->current.custom_points = (float)_cupsStrScand(val->value, &units, loc); if (units) { if (!_cups_strcasecmp(units, "cm")) cparam->current.custom_points *= 72.0f / 2.54f; else if (!_cups_strcasecmp(units, "mm")) cparam->current.custom_points *= 72.0f / 25.4f; else if (!_cups_strcasecmp(units, "m")) cparam->current.custom_points *= 72.0f / 0.0254f; else if (!_cups_strcasecmp(units, "in")) cparam->current.custom_points *= 72.0f; else if (!_cups_strcasecmp(units, "ft")) cparam->current.custom_points *= 12.0f * 72.0f; } break; case PPD_CUSTOM_INT : cparam->current.custom_int = atoi(val->value); break; case PPD_CUSTOM_PASSCODE : case PPD_CUSTOM_PASSWORD : case PPD_CUSTOM_STRING : if (cparam->current.custom_string) _cupsStrFree(cparam->current.custom_string); cparam->current.custom_string = _cupsStrRetain(val->value); break; } } cupsFreeOptions(num_vals, vals); } } else { for (i = o->num_choices, c = o->choices; i > 0; i --, c ++) if (!_cups_strcasecmp(c->choice, choice)) break; if (!i) return; } /* * Option found; mark it and then handle unmarking any other options. */ if (o->ui != PPD_UI_PICKMANY) { /* * Unmark all other choices... */ if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, c)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } if (!_cups_strcasecmp(option, "PageSize") || !_cups_strcasecmp(option, "PageRegion")) { /* * Mark current page size... */ for (j = 0; j < ppd->num_sizes; j ++) ppd->sizes[j].marked = !_cups_strcasecmp(ppd->sizes[j].name, choice); /* * Unmark the current PageSize or PageRegion setting, as * appropriate... */ cupsArraySave(ppd->options); if (!_cups_strcasecmp(option, "PageSize")) { if ((o = ppdFindOption(ppd, "PageRegion")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } } else { if ((o = ppdFindOption(ppd, "PageSize")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } } cupsArrayRestore(ppd->options); } else if (!_cups_strcasecmp(option, "InputSlot")) { /* * Unmark ManualFeed option... */ cupsArraySave(ppd->options); if ((o = ppdFindOption(ppd, "ManualFeed")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } cupsArrayRestore(ppd->options); } else if (!_cups_strcasecmp(option, "ManualFeed") && !_cups_strcasecmp(choice, "True")) { /* * Unmark InputSlot option... */ cupsArraySave(ppd->options); if ((o = ppdFindOption(ppd, "InputSlot")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } cupsArrayRestore(ppd->options); } } c->marked = 1; cupsArrayAdd(ppd->marked, c); }
int /* O - Number of options */ cupsAddOption(const char *name, /* I - Name of option */ const char *value, /* I - Value of option */ int num_options,/* I - Number of options */ cups_option_t **options) /* IO - Pointer to options */ { cups_option_t *temp; /* Pointer to new option */ int insert, /* Insertion point */ diff; /* Result of search */ DEBUG_printf(("2cupsAddOption(name=\"%s\", value=\"%s\", num_options=%d, options=%p)", name, value, num_options, (void *)options)); if (!name || !name[0] || !value || !options || num_options < 0) { DEBUG_printf(("3cupsAddOption: Returning %d", num_options)); return (num_options); } if (!_cups_strcasecmp(name, "cupsPrintQuality")) num_options = cupsRemoveOption("print-quality", num_options, options); else if (!_cups_strcasecmp(name, "print-quality")) num_options = cupsRemoveOption("cupsPrintQuality", num_options, options); /* * Look for an existing option with the same name... */ if (num_options == 0) { insert = 0; diff = 1; } else { insert = cups_find_option(name, num_options, *options, num_options - 1, &diff); if (diff > 0) insert ++; } if (diff) { /* * No matching option name... */ DEBUG_printf(("4cupsAddOption: New option inserted at index %d...", insert)); if (num_options == 0) temp = (cups_option_t *)malloc(sizeof(cups_option_t)); else temp = (cups_option_t *)realloc(*options, sizeof(cups_option_t) * (size_t)(num_options + 1)); if (!temp) { DEBUG_puts("3cupsAddOption: Unable to expand option array, returning 0"); return (0); } *options = temp; if (insert < num_options) { DEBUG_printf(("4cupsAddOption: Shifting %d options...", (int)(num_options - insert))); memmove(temp + insert + 1, temp + insert, (size_t)(num_options - insert) * sizeof(cups_option_t)); } temp += insert; temp->name = _cupsStrAlloc(name); num_options ++; } else { /* * Match found; free the old value... */ DEBUG_printf(("4cupsAddOption: Option already exists at index %d...", insert)); temp = *options + insert; _cupsStrFree(temp->value); } temp->value = _cupsStrAlloc(value); DEBUG_printf(("3cupsAddOption: Returning %d", num_options)); return (num_options); }