Added database and fetcher plugin features
authorMartin Willi <martin@revosec.ch>
Wed, 21 Sep 2011 08:28:03 +0000 (10:28 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 14 Oct 2011 08:05:45 +0000 (10:05 +0200)
src/libstrongswan/plugins/plugin_feature.c
src/libstrongswan/plugins/plugin_feature.h
src/libstrongswan/plugins/plugin_loader.c

index 4b75174..682963b 100644 (file)
@@ -38,6 +38,7 @@ ENUM(plugin_feature_names, FEATURE_NONE, FEATURE_CUSTOM,
        "EAP_SERVER",
        "EAP_CLIENT",
        "DATABASE",
+       "FETCHER",
        "CUSTOM",
 );
 
@@ -65,8 +66,6 @@ bool plugin_feature_matches(plugin_feature_t *a, plugin_feature_t *b)
                                return a->dh_group == b->dh_group;
                        case FEATURE_RNG:
                                return a->rng_quality <= b->rng_quality;
-                       case FEATURE_DATABASE:
-                               return a->database == b->database;
                        case FEATURE_PRIVKEY:
                        case FEATURE_PRIVKEY_GEN:
                        case FEATURE_PUBKEY:
@@ -83,6 +82,10 @@ bool plugin_feature_matches(plugin_feature_t *a, plugin_feature_t *b)
                        case FEATURE_EAP_SERVER:
                        case FEATURE_EAP_PEER:
                                return a->eap == b->eap;
+                       case FEATURE_DATABASE:
+                               return a->database == DB_ANY || a->database == b->database;
+                       case FEATURE_FETCHER:
+                               return a->fetcher == NULL || streq(a->fetcher, b->fetcher);
                        case FEATURE_CUSTOM:
                                return streq(a->custom, b->custom);
                }
@@ -148,13 +151,6 @@ char* plugin_feature_get_string(plugin_feature_t *feature)
                                return str;
                        }
                        break;
-               case FEATURE_DATABASE:
-                       if (asprintf(&str, "%N:%N", plugin_feature_names, feature->type,
-                                       db_driver_names, feature->database) > 0)
-                       {
-                               return str;
-                       }
-                       break;
                case FEATURE_PRIVKEY:
                case FEATURE_PRIVKEY_GEN:
                case FEATURE_PUBKEY:
@@ -196,13 +192,27 @@ char* plugin_feature_get_string(plugin_feature_t *feature)
                                return str;
                        }
                        break;
-               case FEATURE_CUSTOM:
+               case FEATURE_DATABASE:
                        if (asprintf(&str, "%N:%N", plugin_feature_names, feature->type,
                                        db_driver_names, feature->database) > 0)
                        {
                                return str;
                        }
                        break;
+               case FEATURE_FETCHER:
+                       if (asprintf(&str, "%N:%s", plugin_feature_names, feature->type,
+                                       feature->fetcher) > 0)
+                       {
+                               return str;
+                       }
+                       break;
+               case FEATURE_CUSTOM:
+                       if (asprintf(&str, "%N:%s", plugin_feature_names, feature->type,
+                                       feature->custom) > 0)
+                       {
+                               return str;
+                       }
+                       break;
        }
        if (!str)
        {
index 706663b..c10c3c4 100644 (file)
@@ -129,6 +129,8 @@ struct plugin_feature_t {
                FEATURE_EAP_PEER,
                /** database_t */
                FEATURE_DATABASE,
+               /** fetcher_t */
+               FEATURE_FETCHER,
                /** custom feature, described with a string */
                FEATURE_CUSTOM,
        } type;
@@ -169,6 +171,8 @@ struct plugin_feature_t {
                eap_type_t eap;
                /** FEATURE_DATABASE */
                db_driver_t database;
+               /** FEATURE_FETCHER */
+               char *fetcher;
                /** FEATURE_CUSTOM */
                char *custom;
 
@@ -252,6 +256,8 @@ struct plugin_feature_t {
 #define _PLUGIN_FEATURE_CERT_ENCODE(kind, type)                                __PLUGIN_FEATURE(kind, CERT_ENCODE, .cert = type)
 #define _PLUGIN_FEATURE_EAP_SERVER(kind, type)                         __PLUGIN_FEATURE(kind, EAP_SERVER, .eap = type)
 #define _PLUGIN_FEATURE_EAP_PEER(kind, type)                           __PLUGIN_FEATURE(kind, EAP_PEER, .eap = type)
+#define _PLUGIN_FEATURE_DATABASE(kind, type)                           __PLUGIN_FEATURE(kind, DATABASE, .database = type)
+#define _PLUGIN_FEATURE_FETCHER(kind, type)                                    __PLUGIN_FEATURE(kind, FETCHER, .fetcher = type)
 
 #define __PLUGIN_FEATURE_REGISTER(type, _f)                                    (plugin_feature_t){ FEATURE_REGISTER, FEATURE_##type, .reg.f = _f }
 #define __PLUGIN_FEATURE_REGISTER_BUILDER(type, _f, _final)    (plugin_feature_t){ FEATURE_REGISTER, FEATURE_##type, .reg = {.f = _f, .final = _final, }}
@@ -266,6 +272,8 @@ struct plugin_feature_t {
 #define _PLUGIN_FEATURE_REGISTER_PUBKEY(type, f, final)                __PLUGIN_FEATURE_REGISTER_BUILDER(type, f, final)
 #define _PLUGIN_FEATURE_REGISTER_CERT_DECODE(type, f, final)__PLUGIN_FEATURE_REGISTER_BUILDER(type, f, final)
 #define _PLUGIN_FEATURE_REGISTER_CERT_ENCODE(type, f, final)__PLUGIN_FEATURE_REGISTER_BUILDER(type, f, final)
+#define _PLUGIN_FEATURE_REGISTER_DATABASE(type, f)                     __PLUGIN_FEATURE_REGISTER(type, f)
+#define _PLUGIN_FEATURE_REGISTER_FETCHER(type, f)                      __PLUGIN_FEATURE_REGISTER(type, f)
 
 #define _PLUGIN_FEATURE_CALLBACK(_cb, _data) (plugin_feature_t){ FEATURE_CALLBACK, FEATURE_NONE, .cb = { .f = _cb, .data = _data } }
 
index cd942a7..831a106 100644 (file)
@@ -307,6 +307,8 @@ static bool load_feature(private_plugin_loader_t *this, plugin_entry_t *entry,
                case FEATURE_PUBKEY:
                case FEATURE_CERT_DECODE:
                case FEATURE_CERT_ENCODE:
+               case FEATURE_DATABASE:
+               case FEATURE_FETCHER:
                        /* require a registration function */
                        if (!reg ||
                                (reg->kind == FEATURE_REGISTER && reg->type != feature->type))
@@ -372,6 +374,13 @@ static bool load_feature(private_plugin_loader_t *this, plugin_entry_t *entry,
                                lib->creds->add_builder(lib->creds, CRED_CERTIFICATE,
                                                                        feature->cert, reg->reg.final, reg->reg.f);
                                break;
+                       case FEATURE_DATABASE:
+                               lib->db->add_database(lib->db, reg->reg.f);
+                               break;
+                       case FEATURE_FETCHER:
+                               lib->fetcher->add_fetcher(lib->fetcher, reg->reg.f,
+                                                                                 feature->fetcher);
+                               break;
                        default:
                                break;
                }