reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
PostgreSqlDb.hxx
Go to the documentation of this file.
1#if !defined(RESIP_POSTGRESQLDB_HXX)
2#define RESIP_POSTGRESQLDB_HXX
3
4#include <libpq-fe.h>
5
6#include "rutil/Data.hxx"
7#include "repro/SqlDb.hxx"
8
9namespace resip
10{
11 class TransactionUser;
12}
13
14namespace repro
15{
16
17class PostgreSqlDb: public SqlDb
18{
19 public:
22 const resip::Data& dbServer,
23 const resip::Data& user,
24 const resip::Data& password,
26 unsigned int port,
28
30
31 virtual bool addUser( const Key& key, const UserRecord& rec );
32 virtual UserRecord getUser( const Key& key ) const;
33 virtual resip::Data getUserAuthInfo( const Key& key ) const;
34 virtual Key firstUserKey();// return empty if no more
35 virtual Key nextUserKey(); // return empty if no more
36
37 virtual bool addTlsPeerIdentity( const Key& key, const TlsPeerIdentityRecord& rec );
38 virtual TlsPeerIdentityRecord getTlsPeerIdentity( const Key& key ) const;
39 virtual Key firstTlsPeerIdentityKey();// return empty if no more
40 virtual Key nextTlsPeerIdentityKey(); // return empty if no more
41
42 // Perform a query that expects a single result/row - returns all column/field data in a vector
43 virtual int singleResultQuery(const resip::Data& queryCommand, std::vector<resip::Data>& fields) const;
44
45 private:
46 // Db manipulation routines
47 virtual bool dbWriteRecord(const Table table,
48 const resip::Data& key,
49 const resip::Data& data);
50 virtual bool dbReadRecord(const Table table,
51 const resip::Data& key,
52 resip::Data& data) const; // return false if not found
53 virtual resip::Data dbNextKey(const Table table,
54 bool first=true); // return empty if no more
55 virtual bool dbNextRecord(const Table table,
56 const resip::Data& key,
57 resip::Data& data,
58 bool forUpdate, // specifying to add SELECT ... FOR UPDATE so the rows are locked
59 bool first=false); // return false if no more
60 virtual bool dbBeginTransaction(const Table table);
61
62 void initialize() const;
63 void disconnectFromDatabase() const;
64 int connectToDatabase() const;
65 int query(const resip::Data& queryCommand, PGresult** result) const;
66 virtual int query(const resip::Data& queryCommand) const;
67 resip::Data& escapeString(const resip::Data& str, resip::Data& escapedStr) const;
68
69 resip::Data mDBConnInfo;
70 resip::Data mDBServer;
71 resip::Data mDBUser;
72 resip::Data mDBPassword;
73 resip::Data mDBName;
74 unsigned int mDBPort;
75 resip::Data mCustomUserAuthQuery;
76
77 mutable PGconn* mConn;
78 mutable PGresult* mResult[MaxTable];
79 mutable int mRow[MaxTable];
80
81 void userWhereClauseToDataStream(const Key& key, resip::DataStream& ds) const;
82 void tlsPeerIdentityWhereClauseToDataStream(const Key& key, resip::DataStream& ds) const;
83};
84
85}
86#endif
87
88/* ====================================================================
89 *
90 * Copyright (c) 2015 Daniel Pocock. All rights reserved.
91 *
92 * Redistribution and use in source and binary forms, with or without
93 * modification, are permitted provided that the following conditions
94 * are met:
95 *
96 * 1. Redistributions of source code must retain the above copyright
97 * notice, this list of conditions and the following disclaimer.
98 *
99 * 2. Redistributions in binary form must reproduce the above copyright
100 * notice, this list of conditions and the following disclaimer in
101 * the documentation and/or other materials provided with the
102 * distribution.
103 *
104 * 3. Neither the name of the author(s) nor the names of any contributors
105 * may be used to endorse or promote products derived from this software
106 * without specific prior written permission.
107 *
108 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
109 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
110 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
111 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
112 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
113 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
114 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
115 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
116 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
117 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
118 * SUCH DAMAGE.
119 *
120 * ====================================================================
121 */
122
virtual TlsPeerIdentityRecord getTlsPeerIdentity(const Key &key) const
virtual resip::Data getUserAuthInfo(const Key &key) const
virtual Key firstTlsPeerIdentityKey()
virtual Key nextTlsPeerIdentityKey()
virtual Key firstUserKey()
virtual UserRecord getUser(const Key &key) const
PostgreSqlDb(const resip::ConfigParse &config, const resip::Data &dbConnInfo, const resip::Data &dbServer, const resip::Data &user, const resip::Data &password, const resip::Data &databaseName, unsigned int port, const resip::Data &customUserAuthQuery)
virtual Key nextUserKey()
virtual bool addUser(const Key &key, const UserRecord &rec)
virtual int singleResultQuery(const resip::Data &queryCommand, std::vector< resip::Data > &fields) const
virtual bool addTlsPeerIdentity(const Key &key, const TlsPeerIdentityRecord &rec)
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;
void list()
Definition userAdmin.cxx:66