Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

ses_prv.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: ses_prv.h,v 1.18 2006/01/09 12:38:38 tat Exp $
00009  */
00010 
00011 #ifndef _KLONE_SESPRV_H_
00012 #define _KLONE_SESPRV_H_
00013 
00014 #include "klone_conf.h"
00015 #ifdef HAVE_LIBOPENSSL
00016 #include <openssl/hmac.h>
00017 #include <openssl/evp.h>
00018 #include <openssl/rand.h>
00019 #endif /* HAVE_LIBOPENSSL */
00020 #include <u/libu.h>
00021 #include <klone/session.h>
00022 #include <klone/request.h>
00023 #include <klone/response.h>
00024 #include <klone/vars.h>
00025 #include <klone/http.h>
00026 #include <klone/atom.h>
00027 #include <klone/md5.h>
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 typedef int (*session_load_t)(session_t*);
00034 typedef int (*session_save_t)(session_t*);
00035 typedef int (*session_remove_t)(session_t*);
00036 typedef int (*session_term_t)(session_t*);
00037 
00038 /* session type */
00039 enum { 
00040     SESSION_TYPE_UNKNOWN, 
00041     SESSION_TYPE_FILE, 
00042     SESSION_TYPE_MEMORY, 
00043     SESSION_TYPE_CLIENT
00044 };
00045 
00046 enum { 
00047     SESSION_ID_LENGTH = MD5_DIGEST_LEN,         /* sid length       */
00048     SESSION_ID_BUFSZ = 1 + SESSION_ID_LENGTH    /* sid buffer size  */
00049 };
00050 
00051 /* hmac and cipher key size */
00052 enum { 
00053     HMAC_KEY_SIZE = 64, 
00054     #ifdef HAVE_LIBOPENSSL
00055     CIPHER_KEY_SIZE = EVP_MAX_KEY_LENGTH, 
00056     CIPHER_IV_SIZE = EVP_MAX_IV_LENGTH
00057     #else
00058     CIPHER_KEY_SIZE = 64, CIPHER_IV_SIZE = 64
00059     #endif
00060  };
00061 
00062 /* session runtime parameters */
00063 typedef struct session_opt_s
00064 {
00065     /* common session options */
00066     int type;       /* type of sessions (file, memory, client-side)  */
00067     int max_age;    /* max allowed age of sessions                   */
00068     int encrypt;    /* >0 when client-side session encryption is on  */
00069     int compress;   /* >0 when client-side session compression is on */
00070     #ifdef HAVE_LIBOPENSSL
00071     const EVP_CIPHER *cipher; /* encryption cipher algorithm         */
00072     unsigned char cipher_key[CIPHER_KEY_SIZE]; /* cipher secret key  */
00073     unsigned char cipher_iv[CIPHER_IV_SIZE];   /* cipher Init Vector */
00074     #endif
00075 
00076     /* file session options/struct                                   */
00077     char path[U_FILENAME_MAX]; /* session save path                  */
00078     unsigned char session_key[CIPHER_KEY_SIZE]; /* session secret key*/
00079     unsigned char session_iv[CIPHER_IV_SIZE];   /* session init vect */
00080 
00081     /* in-memory session options/struct                              */
00082     atoms_t *atoms; /* atom list used to store in-memory sessions    */
00083     size_t max_count;   /* max # of in-memory sessions               */
00084     size_t mem_limit;   /* max (total) size of in-memory sessions    */
00085 
00086     /* client-side options/structs                                   */
00087     #ifdef HAVE_LIBOPENSSL
00088     HMAC_CTX hmac_ctx;  /* openssl HMAC context                      */
00089     const EVP_MD *hash; /* client-side session HMAC hash algorithm   */
00090     char hmac_key[HMAC_KEY_SIZE]; /* session HMAC secret key         */
00091     #endif
00092 } session_opt_t;
00093 
00094 struct session_s
00095 {
00096     vars_t *vars;               /* variable list                              */
00097     request_t *rq;              /* request bound to this session              */
00098     response_t *rs;             /* response bound to this session             */
00099     char filename[U_FILENAME_MAX];/* session filename                         */
00100     char id[SESSION_ID_BUFSZ];  /* session ID                                 */
00101     int removed;                /* >0 if the calling session has been deleted */
00102     int mtime;                  /* last modified time                         */
00103     session_load_t load;        /* ptr to the driver load function            */
00104     session_save_t save;        /* ptr to the driver save function            */
00105     session_remove_t remove;    /* ptr to the driver remove function          */
00106     session_term_t term;        /* ptr to the driver term function            */
00107     session_opt_t *so;          /* runtime option                             */
00108 };
00109 
00110 /* main c'tor */
00111 int session_create(session_opt_t*, request_t*, response_t*, session_t**);
00112 
00113 /* driver c'tor */
00114 int session_client_create(session_opt_t*, request_t*, response_t*, session_t**);
00115 int session_file_create(session_opt_t*, request_t*, response_t*, session_t**);
00116 int session_mem_create(session_opt_t*, request_t*, response_t*, session_t**);
00117 
00118 /* private functions */
00119 int session_prv_init(session_t *, request_t *, response_t *);
00120 int session_prv_load_from_io(session_t *, io_t *);
00121 int session_prv_save_to_io(session_t*, io_t *);
00122 int session_prv_save_var(var_t *, void*);
00123 int session_prv_calc_maxsize(var_t *v, void *p);
00124 int session_prv_save_to_buf(session_t *ss, char **pbuf, size_t *psz);
00125 int session_prv_load_from_buf(session_t *ss, char *buf, size_t size);
00126 int session_prv_set_id(session_t *ss, const char *sid);
00127 
00128 /* init/term funcs */
00129 int session_module_init(u_config_t *config, session_opt_t **pso);
00130 int session_file_module_init(u_config_t *config, session_opt_t *pso);
00131 int session_mem_module_init(u_config_t *config, session_opt_t *pso);
00132 int session_client_module_init(u_config_t *config, session_opt_t *pso);
00133 int session_module_term(session_opt_t *so);
00134 int session_module_term(session_opt_t *so);
00135 
00136 #ifdef __cplusplus
00137 }
00138 #endif 
00139 
00140 #endif

←Products
© 2005-2006 - KoanLogic S.r.l. - All rights reserved