support of the enum printf_hook

This commit is contained in:
Andreas Steffen
2009-04-20 09:32:59 +00:00
parent 4af0a77cac
commit d41071802d
10 changed files with 663 additions and 667 deletions
+1
View File
@@ -59,6 +59,7 @@ libstrongswan_la_LIBADD = -lpthread -ldl
libstrongswan_lite_la_SOURCES = \ libstrongswan_lite_la_SOURCES = \
chunk.c chunk.h \ chunk.c chunk.h \
debug.c debug.h \ debug.c debug.h \
enum.c enum.h \
printf_hook.c printf_hook.h \ printf_hook.c printf_hook.h \
settings.c settings.h \ settings.c settings.h \
utils.c utils.h \ utils.c utils.h \
+2 -2
View File
@@ -4056,11 +4056,11 @@ show_connections_status(bool all, const char *name)
if (c->dpd_action != DPD_ACTION_NONE) if (c->dpd_action != DPD_ACTION_NONE)
whack_log(RC_COMMENT whack_log(RC_COMMENT
, "\"%s\"%s: dpd_action: %s;" , "\"%s\"%s: dpd_action: %N;"
" dpd_delay: %lus; dpd_timeout: %lus;" " dpd_delay: %lus; dpd_timeout: %lus;"
, c->name , c->name
, instance , instance
, enum_show(&dpd_action_names, c->dpd_action) , dpd_action_names, c->dpd_action
, (unsigned long) c->dpd_delay , (unsigned long) c->dpd_delay
, (unsigned long) c->dpd_timeout); , (unsigned long) c->dpd_timeout);
+15 -22
View File
@@ -71,7 +71,7 @@ enum_names version_names =
/* RFC 2459 CRL reason codes */ /* RFC 2459 CRL reason codes */
static const char *const crl_reason_name[] = { ENUM(crl_reason_names, REASON_UNSPECIFIED, REASON_REMOVE_FROM_CRL,
"unspecified", "unspecified",
"key compromise", "key compromise",
"ca compromise", "ca compromise",
@@ -81,26 +81,20 @@ static const char *const crl_reason_name[] = {
"certificate hold", "certificate hold",
"reason #7", "reason #7",
"remove from crl" "remove from crl"
}; );
enum_names crl_reason_names =
{ REASON_UNSPECIFIED, REASON_REMOVE_FROM_CRL, crl_reason_name, NULL};
/* RFC 3706 Dead Peer Detection */ /* RFC 3706 Dead Peer Detection */
static const char *const dpd_action_name[] = { ENUM(dpd_action_names, DPD_ACTION_NONE, DPD_ACTION_RESTART,
"none", "none",
"clear", "clear",
"hold", "hold",
"restart" "restart"
}; );
enum_names dpd_action_names =
{ DPD_ACTION_NONE, DPD_ACTION_RESTART, dpd_action_name, NULL};
/* Timer events */ /* Timer events */
static const char *const timer_event_name[] = { ENUM(timer_event_names, EVENT_NULL, EVENT_LOG_DAILY,
"EVENT_NULL", "EVENT_NULL",
"EVENT_REINIT_SECRET", "EVENT_REINIT_SECRET",
"EVENT_SHUNT_SCAN", "EVENT_SHUNT_SCAN",
@@ -113,10 +107,7 @@ static const char *const timer_event_name[] = {
"EVENT_DPD", "EVENT_DPD",
"EVENT_DPD_TIMEOUT", "EVENT_DPD_TIMEOUT",
"EVENT_LOG_DAILY" "EVENT_LOG_DAILY"
}; );
enum_names timer_event_names =
{ EVENT_NULL, EVENT_LOG_DAILY, timer_event_name, NULL };
/* Domain of Interpretation */ /* Domain of Interpretation */
@@ -298,8 +289,10 @@ const char *const payload_name[] = {
NULL NULL
}; };
const char *const payload_name_nat_d[] = { "ISAKMP_NEXT_NAT-D", const char *const payload_name_nat_d[] = {
"ISAKMP_NEXT_NAT-OA", NULL }; "ISAKMP_NEXT_NAT-D",
"ISAKMP_NEXT_NAT-OA", NULL
};
static enum_names payload_names_nat_d = static enum_names payload_names_nat_d =
{ ISAKMP_NEXT_NATD_DRAFTS, ISAKMP_NEXT_NATOA_DRAFTS, payload_name_nat_d, NULL }; { ISAKMP_NEXT_NATD_DRAFTS, ISAKMP_NEXT_NATOA_DRAFTS, payload_name_nat_d, NULL };
@@ -479,14 +472,11 @@ enum_names cert_type_names =
/* Certificate policy names */ /* Certificate policy names */
static const char *const cert_policy_name[] = { ENUM(cert_policy_names, CERT_ALWAYS_SEND, CERT_NEVER_SEND,
"ALWAYS_SEND", "ALWAYS_SEND",
"SEND_IF_ASKED", "SEND_IF_ASKED",
"NEVER_SEND", "NEVER_SEND",
}; );
enum_names cert_policy_names =
{ CERT_ALWAYS_SEND, CERT_NEVER_SEND, cert_policy_name, NULL };
/* Goal BITs for establishing an SA /* Goal BITs for establishing an SA
* Note: we drop the POLICY_ prefix so that logs are more concise. * Note: we drop the POLICY_ prefix so that logs are more concise.
@@ -835,9 +825,11 @@ static const char *const oakley_enc_name_draft_aes_cbc_02[] = {
"OAKLEY_SERPENT_CBC" /* 65004 */, "OAKLEY_SERPENT_CBC" /* 65004 */,
"OAKLEY_TWOFISH_CBC" /* 65005 */, "OAKLEY_TWOFISH_CBC" /* 65005 */,
}; };
static const char *const oakley_enc_name_ssh[] = { static const char *const oakley_enc_name_ssh[] = {
"OAKLEY_TWOFISH_CBC_SSH", "OAKLEY_TWOFISH_CBC_SSH",
}; };
enum_names oakley_enc_names_ssh = enum_names oakley_enc_names_ssh =
{ OAKLEY_TWOFISH_CBC_SSH, OAKLEY_TWOFISH_CBC_SSH, oakley_enc_name_ssh { OAKLEY_TWOFISH_CBC_SSH, OAKLEY_TWOFISH_CBC_SSH, oakley_enc_name_ssh
, NULL }; , NULL };
@@ -926,6 +918,7 @@ static const char *const oakley_group_name_rfc3526[] = {
"OAKLEY_GROUP_MODP6144", "OAKLEY_GROUP_MODP6144",
"OAKLEY_GROUP_MODP8192" "OAKLEY_GROUP_MODP8192"
}; };
enum_names oakley_group_names_rfc3526 = enum_names oakley_group_names_rfc3526 =
{ OAKLEY_GROUP_MODP2048, OAKLEY_GROUP_MODP8192, { OAKLEY_GROUP_MODP2048, OAKLEY_GROUP_MODP8192,
oakley_group_name_rfc3526, NULL }; oakley_group_name_rfc3526, NULL };
+5 -4
View File
@@ -320,7 +320,7 @@ typedef enum {
/* RFC 2459 CRL reason codes */ /* RFC 2459 CRL reason codes */
extern enum_names crl_reason_names; extern enum_name_t *crl_reason_names;
typedef enum { typedef enum {
REASON_UNSPECIFIED = 0, REASON_UNSPECIFIED = 0,
@@ -335,7 +335,7 @@ typedef enum {
/* RFC 3706 Dead Peer Detection */ /* RFC 3706 Dead Peer Detection */
extern enum_names dpd_action_names; extern enum_name_t *dpd_action_names;
typedef enum { typedef enum {
DPD_ACTION_NONE = 0, DPD_ACTION_NONE = 0,
@@ -347,7 +347,7 @@ typedef enum {
/* Timer events */ /* Timer events */
extern enum_names timer_event_names; extern enum_name_t *timer_event_names;
enum event_type { enum event_type {
EVENT_NULL, /* non-event */ EVENT_NULL, /* non-event */
@@ -798,7 +798,8 @@ typedef u_int16_t cpi_t;
extern enum_names ident_names; extern enum_names ident_names;
extern enum_names cert_type_names; extern enum_names cert_type_names;
extern enum_names cert_policy_names;
extern enum_name_t *cert_policy_names;
typedef enum certpolicy { typedef enum certpolicy {
CERT_ALWAYS_SEND = 0, /* the default */ CERT_ALWAYS_SEND = 0, /* the default */
+1 -1
View File
@@ -391,7 +391,7 @@ parse_crl_reasonCode(chunk_t object)
} }
DBG(DBG_PARSING, DBG(DBG_PARSING,
DBG_log(" '%s'", enum_name(&crl_reason_names, reason)) DBG_log(" '%N'", crl_reason_names, reason)
) )
return reason; return reason;
} }
+2 -4
View File
@@ -3573,8 +3573,7 @@ main_inR2_outI3(struct msg_digest *md)
if (RSA_auth) if (RSA_auth)
{ {
DBG(DBG_CONTROL, DBG(DBG_CONTROL,
DBG_log("our certificate policy is %s" DBG_log("our certificate policy is %N", cert_policy_names, cert_policy)
, enum_name(&cert_policy_names, cert_policy))
) )
if (mycert.type != CERT_NONE) if (mycert.type != CERT_NONE)
{ {
@@ -3988,8 +3987,7 @@ main_inI3_outR3_tail(struct msg_digest *md
if (RSA_auth) if (RSA_auth)
{ {
DBG(DBG_CONTROL, DBG(DBG_CONTROL,
DBG_log("our certificate policy is %s" DBG_log("our certificate policy is %N", cert_policy_names, cert_policy)
, enum_name(&cert_policy_names, cert_policy))
) )
if (mycert.type != CERT_NONE) if (mycert.type != CERT_NONE)
{ {
+3
View File
@@ -94,6 +94,9 @@ void library_init(char *settings)
PRINTF_HOOK_ARGTYPE_END); PRINTF_HOOK_ARGTYPE_END);
pfh->add_handler(pfh, 'B', chunk_printf_hook, pfh->add_handler(pfh, 'B', chunk_printf_hook,
PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_END); PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_END);
pfh->add_handler(pfh, 'N', enum_printf_hook,
PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_INT,
PRINTF_HOOK_ARGTYPE_END);
pfh->add_handler(pfh, 'T', time_printf_hook, pfh->add_handler(pfh, 'T', time_printf_hook,
PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_INT, PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_INT,
PRINTF_HOOK_ARGTYPE_END); PRINTF_HOOK_ARGTYPE_END);
+2 -2
View File
@@ -746,12 +746,12 @@ void fmt_state(bool all, struct state *st, time_t n
fmt_conn_instance(c, inst); fmt_conn_instance(c, inst);
snprintf(state_buf, state_buf_len snprintf(state_buf, state_buf_len
, "#%lu: \"%s\"%s %s (%s); %s in %lds%s%s%s%s" , "#%lu: \"%s\"%s %s (%s); %N in %lds%s%s%s%s"
, st->st_serialno , st->st_serialno
, c->name, inst , c->name, inst
, enum_name(&state_names, st->st_state) , enum_name(&state_names, st->st_state)
, state_story[st->st_state - STATE_MAIN_R0] , state_story[st->st_state - STATE_MAIN_R0]
, enum_name(&timer_event_names, st->st_event->ev_type) , timer_event_names, st->st_event->ev_type
, delta , delta
, np1, np2, eo, dpd); , np1, np2, eo, dpd);
+22 -22
View File
@@ -98,11 +98,11 @@ event_schedule(enum event_type type, time_t tm, struct state *st)
DBG(DBG_CONTROL, DBG(DBG_CONTROL,
if (st == NULL) if (st == NULL)
DBG_log("inserting event %s, timeout in %lu seconds" DBG_log("inserting event %N, timeout in %lu seconds"
, enum_show(&timer_event_names, type), (unsigned long)tm); , timer_event_names, type, (unsigned long)tm);
else else
DBG_log("inserting event %s, timeout in %lu seconds for #%lu" DBG_log("inserting event %N, timeout in %lu seconds for #%lu"
, enum_show(&timer_event_names, type), (unsigned long)tm , timer_event_names, type, (unsigned long)tm
, ev->ev_state->st_serialno)); , ev->ev_state->st_serialno));
if (evlist == (struct event *) NULL if (evlist == (struct event *) NULL
@@ -122,11 +122,11 @@ event_schedule(enum event_type type, time_t tm, struct state *st)
#ifdef NEVER /* this seems to be overkill */ #ifdef NEVER /* this seems to be overkill */
DBG(DBG_CONTROL, DBG(DBG_CONTROL,
if (evt->ev_state == NULL) if (evt->ev_state == NULL)
DBG_log("event added after event %s" DBG_log("event added after event %N"
, enum_show(&timer_event_names, evt->ev_type)); , timer_event_names, evt->ev_type);
else else
DBG_log("event added after event %s for #%lu" DBG_log("event added after event %N for #%lu"
, enum_show(&timer_event_names, evt->ev_type) , timer_event_names, evt->ev_type,
, evt->ev_state->st_serialno)); , evt->ev_state->st_serialno));
#endif /* NEVER */ #endif /* NEVER */
@@ -161,9 +161,9 @@ handle_timer_event(void)
if (tm < ev->ev_time) if (tm < ev->ev_time)
{ {
DBG(DBG_CONTROL, DBG_log("called while no event expired (%lu/%lu, %s)" DBG(DBG_CONTROL, DBG_log("called while no event expired (%lu/%lu, %N)"
, (unsigned long)tm, (unsigned long)ev->ev_time , (unsigned long)tm, (unsigned long)ev->ev_time
, enum_show(&timer_event_names, type))); , timer_event_names, type));
/* This will happen if the most close-to-expire event was /* This will happen if the most close-to-expire event was
* a retransmission or cleanup, and we received a packet * a retransmission or cleanup, and we received a packet
@@ -178,8 +178,8 @@ handle_timer_event(void)
DBG(DBG_CONTROL, DBG(DBG_CONTROL,
if (evlist != (struct event *) NULL) if (evlist != (struct event *) NULL)
DBG_log("event after this is %s in %ld seconds" DBG_log("event after this is %N in %ld seconds"
, enum_show(&timer_event_names, evlist->ev_type) , timer_event_names, evlist->ev_type
, (long) (evlist->ev_time - tm))); , (long) (evlist->ev_time - tm)));
/* for state-associated events, pick up the state pointer /* for state-associated events, pick up the state pointer
@@ -428,8 +428,8 @@ handle_timer_event(void)
nat_traversal_ka_event(); nat_traversal_ka_event();
break; break;
default: default:
loglog(RC_LOG_SERIOUS, "INTERNAL ERROR: ignoring unknown expiring event %s" loglog(RC_LOG_SERIOUS, "INTERNAL ERROR: ignoring unknown expiring event %N"
, enum_show(&timer_event_names, type)); , timer_event_names, type);
} }
free(ev); free(ev);
@@ -452,12 +452,12 @@ next_event(void)
DBG(DBG_CONTROL, DBG(DBG_CONTROL,
if (evlist->ev_state == NULL) if (evlist->ev_state == NULL)
DBG_log("next event %s in %ld seconds" DBG_log("next event %N in %ld seconds"
, enum_show(&timer_event_names, evlist->ev_type) , timer_event_names, evlist->ev_type
, (long)evlist->ev_time - (long)tm); , (long)evlist->ev_time - (long)tm);
else else
DBG_log("next event %s in %ld seconds for #%lu" DBG_log("next event %N in %ld seconds for #%lu"
, enum_show(&timer_event_names, evlist->ev_type) , timer_event_names, evlist->ev_type
, (long)evlist->ev_time - (long)tm , (long)evlist->ev_time - (long)tm
, evlist->ev_state->st_serialno)); , evlist->ev_state->st_serialno));
@@ -481,8 +481,8 @@ delete_event(struct state *st)
{ {
if (*ev == NULL) if (*ev == NULL)
{ {
DBG(DBG_CONTROL, DBG_log("event %s to be deleted not found", DBG(DBG_CONTROL, DBG_log("event %N to be deleted not found",
enum_show(&timer_event_names, st->st_event->ev_type))); timer_event_names, st->st_event->ev_type));
break; break;
} }
if ((*ev) == st->st_event) if ((*ev) == st->st_event)
@@ -516,8 +516,8 @@ delete_dpd_event(struct state *st)
{ {
if (*ev == NULL) if (*ev == NULL)
{ {
DBG(DBG_CONTROL, DBG_log("event %s to be deleted not found", DBG(DBG_CONTROL, DBG_log("event %N to be deleted not found",
enum_show(&timer_event_names, st->st_dpd_event->ev_type))); timer_event_names, st->st_dpd_event->ev_type));
break; break;
} }
if ((*ev) == st->st_dpd_event) if ((*ev) == st->st_dpd_event)
+2 -2
View File
@@ -2245,9 +2245,9 @@ verify_x509cert(const x509cert_t *cert, bool strict, time_t *until)
} }
break; break;
case CERT_REVOKED: case CERT_REVOKED:
plog("certificate was revoked on %T, reason: %s" plog("certificate was revoked on %T, reason: %N"
, &revocationDate, TRUE , &revocationDate, TRUE
, enum_name(&crl_reason_names, revocationReason)); , crl_reason_names, revocationReason);
remove_x509_public_key(cert); remove_x509_public_key(cert);
return FALSE; return FALSE;
case CERT_UNKNOWN: case CERT_UNKNOWN: