char *qd_entity_opt_string(qd_entity_t *entity, const char* attribute, const char* default_value) { if (qd_entity_has(entity, attribute)) return qd_entity_get_string(entity, attribute); else return default_value ? strdup(default_value) : NULL; }
bool qd_entity_opt_bool(qd_entity_t *entity, const char* attribute, bool default_value) { if (qd_entity_has(entity, attribute)) { bool result = qd_entity_get_bool(entity, attribute); if (!qd_error_code()) return result; } return default_value; }
long qd_entity_opt_long(qd_entity_t *entity, const char* attribute, long default_value) { if (qd_entity_has(entity, attribute)) { long result = qd_entity_get_long(entity, attribute); if (!qd_error_code()) return result; } return default_value; }
qd_error_t qd_log_entity(qd_entity_t *entity) { qd_error_clear(); char* module = qd_entity_get_string(entity, "module"); QD_ERROR_RET(); sys_mutex_lock(log_source_lock); qd_log_source_t *src = qd_log_source_lh(module); /* The original log source */ free(module); qd_log_source_t copy = *src; /* A copy to modify outside the lock. */ sys_mutex_unlock(log_source_lock); if (qd_entity_has(entity, "enable")) { char *enable = qd_entity_get_string(entity, "enable"); copy.mask = enable_mask(enable); free(enable); } QD_ERROR_RET(); if (qd_entity_has(entity, "timestamp")) copy.timestamp = qd_entity_get_bool(entity, "timestamp"); QD_ERROR_RET(); if (qd_entity_has(entity, "source")) copy.source = qd_entity_get_bool(entity, "source"); QD_ERROR_RET(); if (qd_entity_has(entity, "output")) { log_sink_free_lh(copy.sink); /* DEFAULT source may already have a sink */ char* output = qd_entity_get_string(entity, "output"); QD_ERROR_RET(); copy.sink = log_sink_lh(output); free(output); if (copy.sink->syslog) /* Timestamp off for syslog. */ copy.timestamp = 0; } sys_mutex_lock(log_source_lock); *src = copy; sys_mutex_unlock(log_source_lock); return qd_error_code(); }
// True if entity has any of attributes. static bool has_attrs(qd_entity_t *entity, const char **attributes, int n) { for (int i = 0; i < n; ++i) if (qd_entity_has(entity, attributes[i])) return true; return false; }