cupsd_location_t * /* O - New policy operation */ cupsdAddPolicyOp(cupsd_policy_t *p, /* I - Policy */ cupsd_location_t *po, /* I - Policy operation to copy */ ipp_op_t op) /* I - IPP operation code */ { cupsd_location_t *temp; /* New policy operation */ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddPolicyOp(p=%p, po=%p, op=%x(%s))", p, po, op, ippOpString(op)); if (!p) return (NULL); if (!p->ops) p->ops = cupsArrayNew3((cups_array_func_t)compare_ops, NULL, (cups_ahash_func_t)hash_op, 128, (cups_acopy_func_t)NULL, (cups_afree_func_t)cupsdFreeLocation); if (!p->ops) return (NULL); if ((temp = cupsdCopyLocation(po)) != NULL) { temp->op = op; temp->limit = CUPSD_AUTH_LIMIT_IPP; cupsArrayAdd(p->ops, temp); } return (temp); }
cupsd_policy_t * /* O - Policy */ cupsdAddPolicy(const char *policy) /* I - Name of policy */ { cupsd_policy_t *temp; /* Pointer to policy */ if (!policy) return (NULL); if (!Policies) Policies = cupsArrayNew3((cups_array_func_t)compare_policies, NULL, (cups_ahash_func_t)NULL, 0, (cups_acopy_func_t)NULL, (cups_afree_func_t)free_policy); if (!Policies) return (NULL); if ((temp = calloc(1, sizeof(cupsd_policy_t))) != NULL) { cupsdSetString(&temp->name, policy); cupsArrayAdd(Policies, temp); } return (temp); }
cups_array_t * /* O - Array */ _cupsMessageNew(void *context) /* I - User data */ { return (cupsArrayNew3((cups_array_func_t)cups_message_compare, context, (cups_ahash_func_t)NULL, 0, (cups_acopy_func_t)NULL, (cups_afree_func_t)cups_message_free)); }
cups_array_t * /* O - Array */ cupsArrayNew2(cups_array_func_t f, /* I - Comparison function or @code NULL@ for an unsorted array */ void *d, /* I - User data or @code NULL@ */ cups_ahash_func_t h, /* I - Hash function or @code NULL@ for unhashed lookups */ int hsize) /* I - Hash size (>= 0) */ { return (cupsArrayNew3(f, d, h, hsize, 0, 0)); }
int /* O - 1 on success, 0 on failure */ cupsdAddString(cups_array_t **a, /* IO - String array */ const char *s) /* I - String to copy and add */ { if (!*a) *a = cupsArrayNew3((cups_array_func_t)strcmp, NULL, (cups_ahash_func_t)NULL, 0, (cups_acopy_func_t)_cupsStrAlloc, (cups_afree_func_t)_cupsStrFree); return (cupsArrayAdd(*a, (char *)s)); }
cups_array_t * /* O - Array */ _cupsArrayNewStrings(const char *s, /* I - Delimited strings or NULL */ char delim) /* I - Delimiter character */ { cups_array_t *a; /* Array */ if ((a = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsStrAlloc, (cups_afree_func_t)_cupsStrFree)) != NULL) _cupsArrayAddStrings(a, s, delim); return (a); }
static void cupsd_send_notification( cupsd_subscription_t *sub, /* I - Subscription object */ cupsd_event_t *event) /* I - Event to send */ { ipp_state_t state; /* IPP event state */ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsd_send_notification(sub=%p(%d), event=%p(%s))", sub, sub->id, event, cupsdEventName(event->event)); /* * Allocate the events array as needed... */ if (!sub->events) { sub->events = cupsArrayNew3((cups_array_func_t)NULL, NULL, (cups_ahash_func_t)NULL, 0, (cups_acopy_func_t)NULL, (cups_afree_func_t)cupsd_delete_event); if (!sub->events) { cupsdLogMessage(CUPSD_LOG_CRIT, "Unable to allocate memory for subscription #%d!", sub->id); return; } } /* * Purge an old event as needed... */ if (cupsArrayCount(sub->events) >= MaxEvents) { /* * Purge the oldest event in the cache... */ cupsArrayRemove(sub->events, cupsArrayFirst(sub->events)); sub->first_event_id ++; } /* * Add the event to the subscription. Since the events array is * always MaxEvents in length, and since we will have already * removed an event from the subscription cache if we hit the * event cache limit, we don't need to check for overflow here... */ cupsArrayAdd(sub->events, event); /* * Deliver the event... */ if (sub->recipient) { for (;;) { if (sub->pipe < 0) cupsd_start_notifier(sub); cupsdLogMessage(CUPSD_LOG_DEBUG2, "sub->pipe=%d", sub->pipe); if (sub->pipe < 0) break; event->attrs->state = IPP_IDLE; while ((state = ippWriteFile(sub->pipe, event->attrs)) != IPP_DATA) if (state == IPP_ERROR) break; if (state == IPP_ERROR) { if (errno == EPIPE) { /* * Notifier died, try restarting it... */ cupsdLogMessage(CUPSD_LOG_WARN, "Notifier for subscription %d (%s) went away, " "retrying!", sub->id, sub->recipient); cupsdEndProcess(sub->pid, 0); close(sub->pipe); sub->pipe = -1; continue; } cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to send event for subscription %d (%s)!", sub->id, sub->recipient); } /* * If we get this far, break out of the loop... */ break; } } /* * Bump the event sequence number... */ sub->next_event_id ++; }
static void colord_register_printer( cupsd_printer_t *p) /* I - printer */ { char ppdfile[1024], /* PPD filename */ iccfile[1024]; /* ICC filename */ ppd_file_t *ppd; /* PPD file */ cups_array_t *profiles; /* Profile paths array */ ppd_attr_t *attr; /* Profile attributes */ const char *device_colorspace; /* Device colorspace */ char *format[3]; /* Qualifier format tuple */ /* * Ensure we have a D-Bus connection... */ if (!colord_con) return; /* * Try opening the PPD file for this printer... */ snprintf(ppdfile, sizeof(ppdfile), "%s/ppd/%s.ppd", ServerRoot, p->name); if ((ppd = _ppdOpenFile(ppdfile, _PPD_LOCALIZATION_ICC_PROFILES)) == NULL) return; /* * Find out the qualifier format */ colord_get_qualifier_format(ppd, format); /* * See if we have any embedded profiles... */ profiles = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); for (attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); attr; attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL)) if (attr->spec[0] && attr->value && attr->value[0]) { if (attr->value[0] != '/') snprintf(iccfile, sizeof(iccfile), "%s/profiles/%s", DataDir, attr->value); else strlcpy(iccfile, attr->value, sizeof(iccfile)); if (_cupsFileCheck(iccfile, _CUPS_FILE_CHECK_FILE, !RunUser, cupsdLogFCMessage, p)) continue; colord_create_profile(profiles, p->name, attr->spec, COLORD_SPACE_UNKNOWN, format, iccfile, COLORD_SCOPE_TEMP); } /* * Add the grayscale profile first. We always have a grayscale profile. */ colord_create_profile(profiles, p->name, "Gray..", COLORD_SPACE_GRAY, format, NULL, COLORD_SCOPE_TEMP); /* * Then add the RGB/CMYK/DeviceN color profile... */ device_colorspace = "unknown"; switch (ppd->colorspace) { case PPD_CS_RGB : case PPD_CS_CMY : device_colorspace = COLORD_SPACE_RGB; colord_create_profile(profiles, p->name, "RGB..", COLORD_SPACE_RGB, format, NULL, COLORD_SCOPE_TEMP); break; case PPD_CS_RGBK : case PPD_CS_CMYK : device_colorspace = COLORD_SPACE_CMYK; colord_create_profile(profiles, p->name, "CMYK..", COLORD_SPACE_CMYK, format, NULL, COLORD_SCOPE_TEMP); break; case PPD_CS_GRAY : device_colorspace = COLORD_SPACE_GRAY; break; case PPD_CS_N : colord_create_profile(profiles, p->name, "DeviceN..", COLORD_SPACE_UNKNOWN, format, NULL, COLORD_SCOPE_TEMP); break; } /* * Register the device with colord. */ cupsdLogMessage(CUPSD_LOG_INFO, "Registering ICC color profiles for \"%s\".", p->name); colord_create_device(p, ppd, profiles, device_colorspace, format, COLORD_RELATION_SOFT, COLORD_SCOPE_TEMP); /* * Free any memory we used... */ cupsArrayDelete(profiles); free(format[0]); free(format[1]); free(format[2]); ppdClose(ppd); }
cups_array_t * /* O - Array */ cupsArrayNew(cups_array_func_t f, /* I - Comparison function or @code NULL@ for an unsorted array */ void *d) /* I - User data pointer or @code NULL@ */ { return (cupsArrayNew3(f, d, 0, 0, 0, 0)); }