Migrated asn1_parser_t to INIT/METHOD macros
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 2 Dec 2010 21:12:02 +0000 (22:12 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 2 Dec 2010 21:12:02 +0000 (22:12 +0100)
src/libstrongswan/asn1/asn1_parser.c

index 3e5bbba..5c9be2c 100644 (file)
@@ -78,10 +78,8 @@ struct private_asn1_parser_t {
        chunk_t blobs[ASN1_MAX_LEVEL + 2];
 };
 
-/**
- * Implementation of asn1_parser_t.iterate
- */
-static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
+METHOD(asn1_parser_t, iterate, bool,
+       private_asn1_parser_t *this, int *objectID, chunk_t *object)
 {
        chunk_t *blob, *blob1;
        u_char *start_ptr;
@@ -234,43 +232,33 @@ end:
        return this->success;
 }
 
-/**
- * Implementation of asn1_parser_t.get_level
- */
-static u_int get_level(private_asn1_parser_t *this)
+METHOD(asn1_parser_t, get_level, u_int,
+private_asn1_parser_t *this)
 {
        return this->level0 + this->objects[this->line].level;
 }
 
-/**
- * Implementation of asn1_parser_t.set_top_level
- */
-static void set_top_level(private_asn1_parser_t *this, u_int level0)
+METHOD(asn1_parser_t, set_top_level, void,
+       private_asn1_parser_t *this, u_int level0)
 {
        this->level0 = level0;
 }
 
-/**
- * Implementation of asn1_parser_t.set_flags
- */
-static void set_flags(private_asn1_parser_t *this, bool implicit, bool private)
+METHOD(asn1_parser_t, set_flags, void,
+       private_asn1_parser_t *this, bool implicit, bool private)
 {
        this->implicit = implicit;
        this->private = private;
 }
 
-/**
- * Implementation of asn1_parser_t.success
- */
-static bool success(private_asn1_parser_t *this)
+METHOD(asn1_parser_t, success, bool,
+       private_asn1_parser_t *this)
 {
        return this->success;
 }
 
-/**
- * Implementation of asn1_parser_t.destroy
- */
-static void destroy(private_asn1_parser_t *this)
+METHOD(asn1_parser_t, destroy, void,
+       private_asn1_parser_t *this)
 {
        free(this);
 }
@@ -280,20 +268,22 @@ static void destroy(private_asn1_parser_t *this)
  */
 asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, chunk_t blob)
 {
-       private_asn1_parser_t *this = malloc_thing(private_asn1_parser_t);
-
-       memset(this, '\0', sizeof(private_asn1_parser_t));
-       this->objects = objects;
-       this->blobs[0] = blob;
-       this->line = -1;
-       this->success = TRUE;
-
-       this->public.iterate = (bool (*)(asn1_parser_t*, int*, chunk_t*))iterate;
-       this->public.get_level = (u_int (*)(asn1_parser_t*))get_level;
-       this->public.set_top_level = (void (*)(asn1_parser_t*, u_int))set_top_level;
-       this->public.set_flags = (void (*)(asn1_parser_t*, bool, bool))set_flags;
-       this->public.success = (bool (*)(asn1_parser_t*))success;
-       this->public.destroy = (void (*)(asn1_parser_t*))destroy;
+       private_asn1_parser_t *this;
+
+       INIT(this,
+               .public = {
+                       .iterate = _iterate,
+                       .get_level = _get_level,
+                       .set_top_level = _set_top_level,
+                       .set_flags = _set_flags,
+                       .success = _success,
+                       .destroy = _destroy,
+               },              
+               .objects = objects,
+               .blobs[0] = blob,
+               .line = -1,
+               .success = TRUE,
+       );
 
        return &this->public;
 }