Remove extraneous semicolons
[openssl.git] / crypto / store / str_mem.c
index a6ca31d66bf3e9fa5c4a6fbbcf07df2089146e75..d7d22366b4baaea5126e362f0f097f399bd361c2 100644 (file)
 #include <openssl/err.h>
 #include "str_locl.h"
 
-struct mem_object_data_st
+/* The memory store is currently highly experimental.  It's meant to become
+   a base store used by other stores for internal caching (for full caching
+   support, aging needs to be added).
+
+   The database use is meant to support as much attribute association as
+   possible, while providing for as small search ranges as possible.
+   This is currently provided for by sorting the entries by numbers that
+   are composed of bits set at the positions indicated by attribute type
+   codes.  This provides for ranges determined by the highest attribute
+   type code value.  A better idea might be to sort by values computed
+   from the range of attributes associated with the object (basically,
+   the difference between the highest and lowest attribute type code)
+   and it's distance from a base (basically, the lowest associated
+   attribute type code).
+*/
+
+typedef struct mem_object_data_st
        {
        STORE_OBJECT *object;
        STORE_ATTR_INFO *attr_info;
        int references;
-       };
+       } MEM_OBJECT_DATA;
 
+DECLARE_STACK_OF(MEM_OBJECT_DATA)
 struct mem_data_st
        {
-       STACK *data;            /* A stack of mem_object_data_st,
-                                  potentially sorted with a wrapper
-                                  around STORE_ATTR_INFO_cmp(). */
+       STACK_OF(MEM_OBJECT_DATA) *data; /* sorted with
+                                         * STORE_ATTR_INFO_compare(). */
        unsigned int compute_components : 1; /* Currently unused, but can
                                                be used to add attributes
                                                from parts of the data. */
        };
 
+DECLARE_STACK_OF(STORE_ATTR_INFO)
 struct mem_ctx_st
        {
        int type;               /* The type we're searching for */
-       STACK *search_attributes; /* Sets of attributes to search for.
-                                    Each element is a STORE_ATTR_INFO. */
-       int search_index;       /* which of the search attributes we found a match
-                                  for, -1 when we still haven't found any */
-       int index;              /* -1 as long as we're searching for the first */
+       STACK_OF(STORE_ATTR_INFO) *search_attributes; /* Sets of
+                                    attributes to search for.  Each
+                                    element is a STORE_ATTR_INFO. */
+       int search_index;       /* which of the search attributes we
+                                  found a match for, -1 when we still
+                                  haven't found any */
+       int index;              /* -1 as long as we're searching for
+                                    the first */
        };
 
 static int mem_init(STORE *s);
 static void mem_clean(STORE *s);
 static STORE_OBJECT *mem_generate(STORE *s, STORE_OBJECT_TYPES type,
-       OPENSSL_ITEM parameters[], OPENSSL_ITEM attributes[]);
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
 static STORE_OBJECT *mem_get(STORE *s, STORE_OBJECT_TYPES type,
-       OPENSSL_ITEM attributes[]);
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
 static int mem_store(STORE *s, STORE_OBJECT_TYPES type,
-       STORE_OBJECT *data, OPENSSL_ITEM attributes[]);
+       STORE_OBJECT *data, OPENSSL_ITEM attributes[],
+       OPENSSL_ITEM parameters[]);
 static int mem_modify(STORE *s, STORE_OBJECT_TYPES type,
        OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[],
-       OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[]);
+       OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[],
+       OPENSSL_ITEM parameters[]);
 static int mem_delete(STORE *s, STORE_OBJECT_TYPES type,
-       OPENSSL_ITEM attributes[]);
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
 static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
-       OPENSSL_ITEM attributes[]);
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
 static STORE_OBJECT *mem_list_next(STORE *s, void *handle);
 static int mem_list_end(STORE *s, void *handle);
 static int mem_list_endp(STORE *s, void *handle);
-static int mem_lock(STORE *s, OPENSSL_ITEM attributes[]);
-static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[]);
-static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)());
+static int mem_lock(STORE *s, OPENSSL_ITEM attributes[],
+       OPENSSL_ITEM parameters[]);
+static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[],
+       OPENSSL_ITEM parameters[]);
+static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)(void));
 
 static STORE_METHOD store_memory =
        {
@@ -146,15 +170,15 @@ static void mem_clean(STORE *s)
        }
 
 static STORE_OBJECT *mem_generate(STORE *s, STORE_OBJECT_TYPES type,
-       OPENSSL_ITEM parameters[], OPENSSL_ITEM attributes[])
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
        {
        STOREerr(STORE_F_MEM_GENERATE, STORE_R_NOT_IMPLEMENTED);
        return 0;
        }
 static STORE_OBJECT *mem_get(STORE *s, STORE_OBJECT_TYPES type,
-       OPENSSL_ITEM attributes[])
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
        {
-       void *context = mem_list_start(s, type, attributes);
+       void *context = mem_list_start(s, type, attributes, parameters);
        
        if (context)
                {
@@ -166,26 +190,36 @@ static STORE_OBJECT *mem_get(STORE *s, STORE_OBJECT_TYPES type,
        return NULL;
        }
 static int mem_store(STORE *s, STORE_OBJECT_TYPES type,
-       STORE_OBJECT *data, OPENSSL_ITEM attributes[])
+       STORE_OBJECT *data, OPENSSL_ITEM attributes[],
+       OPENSSL_ITEM parameters[])
        {
        STOREerr(STORE_F_MEM_STORE, STORE_R_NOT_IMPLEMENTED);
        return 0;
        }
 static int mem_modify(STORE *s, STORE_OBJECT_TYPES type,
        OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[],
-       OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[])
+       OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[],
+       OPENSSL_ITEM parameters[])
        {
-       STOREerr(STORE_F_MEM_STORE, STORE_R_NOT_IMPLEMENTED);
+       STOREerr(STORE_F_MEM_MODIFY, STORE_R_NOT_IMPLEMENTED);
        return 0;
        }
 static int mem_delete(STORE *s, STORE_OBJECT_TYPES type,
-       OPENSSL_ITEM attributes[])
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
        {
        STOREerr(STORE_F_MEM_DELETE, STORE_R_NOT_IMPLEMENTED);
        return 0;
        }
+
+/* The list functions may be the hardest to understand.  Basically,
+   mem_list_start compiles a stack of attribute info elements, and
+   puts that stack into the context to be returned.  mem_list_next
+   will then find the first matching element in the store, and then
+   walk all the way to the end of the store (since any combination
+   of attribute bits above the starting point may match the searched
+   for bit pattern...). */
 static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
-       OPENSSL_ITEM attributes[])
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
        {
        struct mem_ctx_st *context =
                (struct mem_ctx_st *)OPENSSL_malloc(sizeof(struct mem_ctx_st));
@@ -211,7 +245,7 @@ static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
                if (context->search_attributes == NULL)
                        {
                        context->search_attributes =
-                               sk_new((int (*)(const char * const *, const char * const *))STORE_ATTR_INFO_compare);
+                               sk_STORE_ATTR_INFO_new(STORE_ATTR_INFO_compare);
                        if (!context->search_attributes)
                                {
                                STOREerr(STORE_F_MEM_LIST_START,
@@ -219,7 +253,7 @@ static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
                                goto err;
                                }
                        }
-               sk_push(context->search_attributes,(char *)attrs);
+               sk_STORE_ATTR_INFO_push(context->search_attributes,attrs);
                }
        if (!STORE_parse_attrs_endp(attribute_context))
                goto err;
@@ -255,11 +289,14 @@ static STORE_OBJECT *mem_list_next(STORE *s, void *handle)
 
        if (context->search_index == -1)
                {
-               for (i = 0; i < sk_num(context->search_attributes); i++)
+               for (i = 0;
+                    i < sk_STORE_ATTR_INFO_num(context->search_attributes);
+                    i++)
                        {
-                       key.attr_info =
-                               (STORE_ATTR_INFO *)sk_value(context->search_attributes, i);
-                       srch = sk_find_ex(store->data, (char *)&key);
+                       key.attr_info
+                         = sk_STORE_ATTR_INFO_value(context->search_attributes,
+                                                    i);
+                       srch = sk_MEM_OBJECT_DATA_find_ex(store->data, &key);
 
                        if (srch >= 0)
                                {
@@ -272,19 +309,20 @@ static STORE_OBJECT *mem_list_next(STORE *s, void *handle)
                return NULL;
        
        key.attr_info =
-               (STORE_ATTR_INFO *)sk_value(context->search_attributes,
-                       context->search_index);
+               sk_STORE_ATTR_INFO_value(context->search_attributes,
+                                        context->search_index);
        for(srch = context->search_index;
-           srch < sk_num(store->data)
+           srch < sk_MEM_OBJECT_DATA_num(store->data)
+                   && STORE_ATTR_INFO_in_range(key.attr_info,
+                           sk_MEM_OBJECT_DATA_value(store->data, srch))
                    && !(cres = STORE_ATTR_INFO_in_ex(key.attr_info,
-                                (STORE_ATTR_INFO *)sk_value(store->data, srch)));
+                                sk_MEM_OBJECT_DATA_value(store->data, srch)));
            srch++)
                ;
 
        context->search_index = srch;
        if (cres)
-               return ((struct mem_object_data_st *)sk_value(store->data,
-                               srch))->object;
+               return (sk_MEM_OBJECT_DATA_value(store->data, srch))->object;
        return NULL;
        }
 static int mem_list_end(STORE *s, void *handle)
@@ -293,11 +331,11 @@ static int mem_list_end(STORE *s, void *handle)
 
        if (!context)
                {
-               STOREerr(STORE_F_MEM_LIST_NEXT, ERR_R_PASSED_NULL_PARAMETER);
+               STOREerr(STORE_F_MEM_LIST_END, ERR_R_PASSED_NULL_PARAMETER);
                return 0;
                }
        if (context && context->search_attributes)
-               sk_free(context->search_attributes);
+               sk_STORE_ATTR_INFO_free(context->search_attributes);
        if (context) OPENSSL_free(context);
        return 1;
        }
@@ -306,19 +344,22 @@ static int mem_list_endp(STORE *s, void *handle)
        struct mem_ctx_st *context = (struct mem_ctx_st *)handle;
 
        if (!context
-               || context->search_index == sk_num(context->search_attributes))
+           || context->search_index
+              == sk_STORE_ATTR_INFO_num(context->search_attributes))
                return 1;
        return 0;
        }
-static int mem_lock(STORE *s, OPENSSL_ITEM attributes[])
+static int mem_lock(STORE *s, OPENSSL_ITEM attributes[],
+       OPENSSL_ITEM parameters[])
        {
        return 1;
        }
-static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[])
+static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[],
+       OPENSSL_ITEM parameters[])
        {
        return 1;
        }
-static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)())
+static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)(void))
        {
        return 1;
        }