web_persist.ml 3.63 KB
Newer Older
Stephane Glondu's avatar
Stephane Glondu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
(**************************************************************************)
(*                                BELENIOS                                *)
(*                                                                        *)
(*  Copyright © 2012-2015 Inria                                           *)
(*                                                                        *)
(*  This program is free software: you can redistribute it and/or modify  *)
(*  it under the terms of the GNU Affero General Public License as        *)
(*  published by the Free Software Foundation, either version 3 of the    *)
(*  License, or (at your option) any later version, with the additional   *)
(*  exemption that compiling, linking, and/or using OpenSSL is allowed.   *)
(*                                                                        *)
(*  This program is distributed in the hope that it will be useful, but   *)
(*  WITHOUT ANY WARRANTY; without even the implied warranty of            *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *)
(*  Affero General Public License for more details.                       *)
(*                                                                        *)
(*  You should have received a copy of the GNU Affero General Public      *)
(*  License along with this program.  If not, see                         *)
(*  <http://www.gnu.org/licenses/>.                                       *)
(**************************************************************************)

22
open Lwt
23
open Serializable_builtin_j
24
open Serializable_t
25
open Common
26

27 28 29
type election_state =
  [ `Open
  | `Closed
30
  | `EncryptedTally of int * int * string
31
  | `Tallied of plaintext
32 33
  ]

34 35 36 37 38 39 40 41
let election_states = Ocsipersist.open_table "election_states"

let get_election_state x =
  try_lwt Ocsipersist.find election_states x
  with Not_found -> return `Open

let set_election_state x s =
  Ocsipersist.add election_states x s
42

43 44 45 46 47 48 49 50 51 52 53
let election_dates = Ocsipersist.open_table "election_dates"

let past = datetime_of_string "\"2015-10-01 00:00:00.000000\""

let get_election_date x =
  try_lwt Ocsipersist.find election_dates x
  with Not_found -> return past

let set_election_date x d =
  Ocsipersist.add election_dates x d

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
let store = Ocsipersist.open_store "site"

lwt main_election =
  Ocsipersist.make_persistent store "main_election" None

lwt featured =
  Ocsipersist.make_persistent store "featured_elections" []

let add_featured_election x =
  lwt the_featured = Ocsipersist.get featured in
  if List.mem x the_featured then (
    return ()
  ) else (
    Ocsipersist.set featured (x :: the_featured)
  )

let rec list_remove x = function
  | [] -> []
  | y :: ys -> if x = y then ys else y :: (list_remove x ys)

let remove_featured_election x =
  lwt the_featured = Ocsipersist.get featured in
  Ocsipersist.set featured (list_remove x the_featured)

let is_featured_election x =
  lwt the_featured = Ocsipersist.get featured in
  return (List.mem x the_featured)

let get_featured_elections () =
  Ocsipersist.get featured

let get_main_election () =
  Ocsipersist.get main_election

let set_main_election x =
  Ocsipersist.set main_election (Some x)

let unset_main_election () =
  Ocsipersist.set main_election None
93 94 95 96 97 98 99 100 101

let election_pds = Ocsipersist.open_table "election_pds"

let get_partial_decryptions x =
  try_lwt Ocsipersist.find election_pds x
  with Not_found -> return []

let set_partial_decryptions x pds =
  Ocsipersist.add election_pds x pds
Stephane Glondu's avatar
Stephane Glondu committed
102 103 104 105 106 107 108 109 110

let auth_configs = Ocsipersist.open_table "auth_configs"

let get_auth_config x =
  try_lwt Ocsipersist.find auth_configs x
  with Not_found -> return []

let set_auth_config x c =
  Ocsipersist.add auth_configs x c