00001
00002
00003
00004
00005
00006
00007
00008
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
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
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,
00048 SESSION_ID_BUFSZ = 1 + SESSION_ID_LENGTH
00049 };
00050
00051
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
00063 typedef struct session_opt_s
00064 {
00065
00066 int type;
00067 int max_age;
00068 int encrypt;
00069 int compress;
00070 #ifdef HAVE_LIBOPENSSL
00071 const EVP_CIPHER *cipher;
00072 unsigned char cipher_key[CIPHER_KEY_SIZE];
00073 unsigned char cipher_iv[CIPHER_IV_SIZE];
00074 #endif
00075
00076
00077 char path[U_FILENAME_MAX];
00078 unsigned char session_key[CIPHER_KEY_SIZE];
00079 unsigned char session_iv[CIPHER_IV_SIZE];
00080
00081
00082 atoms_t *atoms;
00083 size_t max_count;
00084 size_t mem_limit;
00085
00086
00087 #ifdef HAVE_LIBOPENSSL
00088 HMAC_CTX hmac_ctx;
00089 const EVP_MD *hash;
00090 char hmac_key[HMAC_KEY_SIZE];
00091 #endif
00092 } session_opt_t;
00093
00094 struct session_s
00095 {
00096 vars_t *vars;
00097 request_t *rq;
00098 response_t *rs;
00099 char filename[U_FILENAME_MAX];
00100 char id[SESSION_ID_BUFSZ];
00101 int removed;
00102 int mtime;
00103 session_load_t load;
00104 session_save_t save;
00105 session_remove_t remove;
00106 session_term_t term;
00107 session_opt_t *so;
00108 };
00109
00110
00111 int session_create(session_opt_t*, request_t*, response_t*, session_t**);
00112
00113
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
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
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