Debian Codegraph @

src/lib/object_store/ObjectStoreToken.cpp

raw
1 /*
2 * Copyright (c) 2013 SURFnet bv
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 ObjectStoreToken.cpp
29
30 The object store abstract token base class
31 *****************************************************************************/
32
33 #include "config.h"
34 #include "log.h"
35 #include "ObjectStoreToken.h"
36
37 // OSToken is a concrete implementation of ObjectStoreToken base class.
38 #include "OSToken.h"
39
40 #ifdef HAVE_OBJECTSTORE_BACKEND_DB
41 // DBToken is a concrete implementation of ObjectSToreToken that stores the objects and attributes in an SQLite3 database.
42 #include "DBToken.h"
43 #endif
44
45 typedef ObjectStoreToken* (*CreateToken)(const std::string , const std::string , const ByteString& , const ByteString& );
46 typedef ObjectStoreToken* (*AccessToken)(const std::string &, const std::string &);
47
48 static CreateToken static_createToken = reinterpret_cast<CreateToken>(OSToken::createToken);
49 static AccessToken static_accessToken = reinterpret_cast<AccessToken>(OSToken::accessToken);
50
51 // Create a new token
52 /*static*/ bool ObjectStoreToken::selectBackend(const std::string &backend)
53 {
54 if (backend == "file")
55 {
56 static_createToken = reinterpret_cast<CreateToken>(OSToken::createToken);
57 static_accessToken = reinterpret_cast<AccessToken>(OSToken::accessToken);
58 }
59 #ifdef HAVE_OBJECTSTORE_BACKEND_DB
60 else if (backend == "db")
61 {
62 static_createToken = reinterpret_cast<CreateToken>(DBToken::createToken);
63 static_accessToken = reinterpret_cast<AccessToken>(DBToken::accessToken);
64 }
65 #endif
66 else
67 {
68 ERROR_MSG("Unknown value (%s) for objectstore.backend in configuration", backend.c_str());
69 return false;
70 }
71
72 return true;
73 }
74
75 ObjectStoreToken* ObjectStoreToken::createToken(const std::string basePath, const std::string tokenDir, const ByteString& label, const ByteString& serial)
76 {
77 return static_createToken(basePath,tokenDir,label,serial);
78 }
79
80 // Access an existing token
81 /*static*/ ObjectStoreToken *ObjectStoreToken::accessToken(const std::string &basePath, const std::string &tokenDir)
82 {
83 return static_accessToken(basePath, tokenDir);
84 }