isc_result_t isccc_cc_checkdup(isccc_symtab_t *symtab, isccc_sexpr_t *message, isccc_time_t now) { const char *_frm; const char *_to; char *_ser = NULL, *_tim = NULL, *tmp; isc_result_t result; char *key; size_t len; isccc_symvalue_t value; isccc_sexpr_t *_ctrl; _ctrl = isccc_alist_lookup(message, "_ctrl"); if (!isccc_alist_alistp(_ctrl) || isccc_cc_lookupstring(_ctrl, "_ser", &_ser) != ISC_R_SUCCESS || isccc_cc_lookupstring(_ctrl, "_tim", &_tim) != ISC_R_SUCCESS) return (ISC_R_FAILURE); INSIST(_ser != NULL); INSIST(_tim != NULL); /* * _frm and _to are optional. */ tmp = NULL; if (isccc_cc_lookupstring(_ctrl, "_frm", &tmp) != ISC_R_SUCCESS) _frm = ""; else _frm = tmp; tmp = NULL; if (isccc_cc_lookupstring(_ctrl, "_to", &tmp) != ISC_R_SUCCESS) _to = ""; else _to = tmp; /* * Ensure there is no newline in any of the strings. This is so * we can write them to a file later. */ if (has_whitespace(_frm) || has_whitespace(_to) || has_whitespace(_ser) || has_whitespace(_tim)) return (ISC_R_FAILURE); len = strlen(_frm) + strlen(_to) + strlen(_ser) + strlen(_tim) + 4; key = malloc(len); if (key == NULL) return (ISC_R_NOMEMORY); snprintf(key, len, "%s;%s;%s;%s", _frm, _to, _ser, _tim); value.as_uinteger = now; result = isccc_symtab_define(symtab, key, ISCCC_SYMTYPE_CCDUP, value, isccc_symexists_reject); if (result != ISC_R_SUCCESS) { free(key); return (result); } return (ISC_R_SUCCESS); }
/** * Add quotes around any argv with whitespaces. */ void add_quotes(char **argv, int argc) { int i; for (i = 0; i < argc; ++i) { if (has_whitespace(argv[i])) { int len = strlen(argv[i]) + 3; char *tmp = argv[i]; argv[i] = malloc(len * sizeof(char)); snprintf(argv[i], len, "\"%s\"", tmp); free(tmp); } } }