reintegrated bus-refactoring branch

This commit is contained in:
Martin Willi
2008-10-14 08:52:13 +00:00
parent 1adaa02bb2
commit a985db3ff3
30 changed files with 967 additions and 939 deletions
+49 -22
View File
@@ -34,7 +34,7 @@ G_DEFINE_TYPE(NMStrongswanPlugin, nm_strongswan_plugin, NM_TYPE_VPN_PLUGIN)
* Private data of NMStrongswanPlugin
*/
typedef struct {
bus_listener_t listener;
listener_t listener;
ike_sa_t *ike_sa;
NMVPNPlugin *plugin;
nm_creds_t *creds;
@@ -95,32 +95,54 @@ static void signal_ipv4_config(NMVPNPlugin *plugin, child_sa_t *child_sa)
}
/**
* Bus listen function to wait for SA establishing
* signal failure to NM, connecting failed
*/
bool listen_bus(bus_listener_t *listener, signal_t signal, level_t level,
int thread, ike_sa_t *ike_sa, void *data,
char* format, va_list args)
static void signal_failure(NMVPNPlugin *plugin)
{
/* TODO: NM does not handle this failure!?
nm_vpn_plugin_failure(plugin, NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED); */
nm_vpn_plugin_set_state(plugin, NM_VPN_SERVICE_STATE_STOPPED);
}
/**
* Implementation of listener_t.ike_state_change
*/
static bool ike_state_change(listener_t *listener, ike_sa_t *ike_sa,
ike_sa_state_t state)
{
NMStrongswanPluginPrivate *private = (NMStrongswanPluginPrivate*)listener;
if (private->ike_sa == ike_sa)
{
switch (signal)
switch (state)
{
case CHD_UP_SUCCESS:
if (data)
{
signal_ipv4_config(private->plugin, (child_sa_t*)data);
return FALSE;
}
/* FALL */
case IKE_UP_FAILED:
case CHD_UP_FAILED:
/* TODO: NM does not handle this failure!?
nm_vpn_plugin_failure(private->plugin,
NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED); */
nm_vpn_plugin_set_state(private->plugin,
NM_VPN_SERVICE_STATE_STOPPED);
case IKE_DESTROYING:
signal_failure(private->plugin);
return FALSE;
default:
break;
}
}
return TRUE;
}
/**
* Implementation of listener_t.child_state_change
*/
static bool child_state_change(listener_t *listener, ike_sa_t *ike_sa,
child_sa_t *child_sa, child_sa_state_t state)
{
NMStrongswanPluginPrivate *private = (NMStrongswanPluginPrivate*)listener;
if (private->ike_sa == ike_sa)
{
switch (state)
{
case CHILD_INSTALLED:
signal_ipv4_config(private->plugin, child_sa);
return FALSE;
case CHILD_DESTROYING:
signal_failure(private->plugin);
return FALSE;
default:
break;
@@ -435,8 +457,13 @@ static gboolean disconnect(NMVPNPlugin *plugin, GError **err)
*/
static void nm_strongswan_plugin_init(NMStrongswanPlugin *plugin)
{
NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin)->plugin = NM_VPN_PLUGIN(plugin);
NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin)->listener.signal = listen_bus;
NMStrongswanPluginPrivate *private;
private = NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin);
private->plugin = NM_VPN_PLUGIN(plugin);
memset(&private->listener.log, 0, sizeof(listener_t));
private->listener.ike_state_change = ike_state_change;
private->listener.child_state_change = child_state_change;
}
/**
+3 -3
View File
@@ -359,15 +359,15 @@ static void request_query_config(xmlTextReaderPtr reader, xmlTextWriterPtr write
/**
* callback which logs to a XML writer
*/
static bool xml_callback(xmlTextWriterPtr writer, signal_t signal, level_t level,
ike_sa_t* ike_sa, void *data, char* format, va_list args)
static bool xml_callback(xmlTextWriterPtr writer, debug_t group, level_t level,
ike_sa_t* ike_sa, char* format, va_list args)
{
if (level <= 1)
{
/* <item> */
xmlTextWriterStartElement(writer, "item");
xmlTextWriterWriteFormatAttribute(writer, "level", "%d", level);
xmlTextWriterWriteFormatAttribute(writer, "source", "%N", signal_names, signal);
xmlTextWriterWriteFormatAttribute(writer, "source", "%N", debug_names, group);
xmlTextWriterWriteFormatAttribute(writer, "thread", "%u", pthread_self());
xmlTextWriterWriteVFormatString(writer, format, args);
xmlTextWriterEndElement(writer);
+6 -7
View File
@@ -49,13 +49,11 @@ struct private_sql_logger_t {
bool recursive;
};
/**
* Implementation of bus_listener_t.signal.
* Implementation of bus_listener_t.log.
*/
static bool signal_(private_sql_logger_t *this, signal_t signal, level_t level,
int thread, ike_sa_t* ike_sa, void *data,
char *format, va_list args)
static bool log_(private_sql_logger_t *this, debug_t group, level_t level,
int thread, ike_sa_t* ike_sa, char *format, va_list args)
{
if (this->recursive)
{
@@ -111,7 +109,7 @@ static bool signal_(private_sql_logger_t *this, signal_t signal, level_t level,
DB_BLOB, remote_host->get_address(remote_host));
this->db->execute(this->db, NULL, "INSERT INTO logs ("
"local_spi, signal, level, msg) VALUES (?, ?, ?, ?)",
DB_BLOB, local_spi, DB_INT, signal, DB_INT, level,
DB_BLOB, local_spi, DB_INT, group, DB_INT, level,
DB_TEXT, buffer);
}
this->recursive = FALSE;
@@ -134,7 +132,8 @@ sql_logger_t *sql_logger_create(database_t *db)
{
private_sql_logger_t *this = malloc_thing(private_sql_logger_t);
this->public.listener.signal = (bool(*)(bus_listener_t*,signal_t,level_t,int,ike_sa_t*,void*,char*,va_list))signal_;
memset(&this->public.listener, 0, sizeof(listener_t));
this->public.listener.log = (bool(*)(listener_t*,debug_t,level_t,int,ike_sa_t*,char*,va_list))log_;
this->public.destroy = (void(*)(sql_logger_t*))destroy;
this->db = db;
+1 -1
View File
@@ -36,7 +36,7 @@ struct sql_logger_t {
/**
* Implements bus_listener_t interface
*/
bus_listener_t listener;
listener_t listener;
/**
* Destry the backend.
+2 -2
View File
@@ -55,8 +55,8 @@ struct stroke_log_info_t {
/**
* logging to the stroke interface
*/
static bool stroke_log(stroke_log_info_t *info, signal_t signal, level_t level,
ike_sa_t *ike_sa, void *data, char *format, va_list args)
static bool stroke_log(stroke_log_info_t *info, debug_t group, level_t level,
ike_sa_t *ike_sa, char *format, va_list args)
{
if (level <= info->level)
{
+11 -9
View File
@@ -336,9 +336,9 @@ static void stroke_purge(private_stroke_socket_t *this,
CERT_X509_OCSP_RESPONSE);
}
signal_t get_signal_from_logtype(char *type)
debug_t get_group_from_name(char *type)
{
if (strcasecmp(type, "any") == 0) return SIG_ANY;
if (strcasecmp(type, "any") == 0) return DBG_ANY;
else if (strcasecmp(type, "mgr") == 0) return DBG_MGR;
else if (strcasecmp(type, "ike") == 0) return DBG_IKE;
else if (strcasecmp(type, "chd") == 0) return DBG_CHD;
@@ -354,29 +354,31 @@ signal_t get_signal_from_logtype(char *type)
/**
* set the verbosity debug output
*/
static void stroke_loglevel(private_stroke_socket_t *this, stroke_msg_t *msg, FILE *out)
static void stroke_loglevel(private_stroke_socket_t *this,
stroke_msg_t *msg, FILE *out)
{
signal_t signal;
debug_t group;
pop_string(msg, &(msg->loglevel.type));
DBG1(DBG_CFG, "received stroke: loglevel %d for %s",
msg->loglevel.level, msg->loglevel.type);
signal = get_signal_from_logtype(msg->loglevel.type);
if (signal < 0)
group = get_group_from_name(msg->loglevel.type);
if (group < 0)
{
fprintf(out, "invalid type (%s)!\n", msg->loglevel.type);
return;
}
charon->outlog->set_level(charon->outlog, signal, msg->loglevel.level);
charon->syslog->set_level(charon->syslog, signal, msg->loglevel.level);
charon->outlog->set_level(charon->outlog, group, msg->loglevel.level);
charon->syslog->set_level(charon->syslog, group, msg->loglevel.level);
}
/**
* set various config options
*/
static void stroke_config(private_stroke_socket_t *this, stroke_msg_t *msg, FILE *out)
static void stroke_config(private_stroke_socket_t *this,
stroke_msg_t *msg, FILE *out)
{
this->cred->cachecrl(this->cred, msg->config.cachecrl);
}