reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
MySqlDb.hxx
Go to the documentation of this file.
1#if !defined(RESIP_MYSQLDB_HXX)
2#define RESIP_MYSQLDB_HXX
3
4#ifdef WIN32
5#include <mysql.h>
6#else
7#include <mysql/mysql.h>
8#endif
9
10#include "rutil/Data.hxx"
11#include "repro/SqlDb.hxx"
12
13namespace resip
14{
15 class TransactionUser;
16}
17
18namespace repro
19{
20
21class MySqlDb: public SqlDb
22{
23 public:
25 const resip::Data& dbServer,
26 const resip::Data& user,
27 const resip::Data& password,
29 unsigned int port,
31
33
34 virtual bool addUser( const Key& key, const UserRecord& rec );
35 virtual UserRecord getUser( const Key& key ) const;
36 virtual resip::Data getUserAuthInfo( const Key& key ) const;
37 virtual Key firstUserKey();// return empty if no more
38 virtual Key nextUserKey(); // return empty if no more
39
40 virtual bool addTlsPeerIdentity( const Key& key, const TlsPeerIdentityRecord& rec );
41 virtual TlsPeerIdentityRecord getTlsPeerIdentity( const Key& key ) const;
42 virtual Key firstTlsPeerIdentityKey();// return empty if no more
43 virtual Key nextTlsPeerIdentityKey(); // return empty if no more
44
45 // Perform a query that expects a single result/row - returns all column/field data in a vector
46 virtual int singleResultQuery(const resip::Data& queryCommand, std::vector<resip::Data>& fields) const;
47
48 private:
49 // Db manipulation routines
50 virtual bool dbWriteRecord(const Table table,
51 const resip::Data& key,
52 const resip::Data& data);
53 virtual bool dbReadRecord(const Table table,
54 const resip::Data& key,
55 resip::Data& data) const; // return false if not found
56 virtual resip::Data dbNextKey(const Table table,
57 bool first=true); // return empty if no more
58 virtual bool dbNextRecord(const Table table,
59 const resip::Data& key,
60 resip::Data& data,
61 bool forUpdate, // specifying to add SELECT ... FOR UPDATE so the rows are locked
62 bool first=false); // return false if no more
63 virtual bool dbBeginTransaction(const Table table);
64
65 void initialize() const;
66 void disconnectFromDatabase() const;
67 int connectToDatabase() const;
68 int query(const resip::Data& queryCommand, MYSQL_RES** result) const;
69 virtual int query(const resip::Data& queryCommand) const;
70 resip::Data& escapeString(const resip::Data& str, resip::Data& escapedStr) const;
71
72 resip::Data mDBServer;
73 resip::Data mDBUser;
74 resip::Data mDBPassword;
75 resip::Data mDBName;
76 unsigned int mDBPort;
77 resip::Data mCustomUserAuthQuery;
78
79 mutable MYSQL* mConn;
80 mutable MYSQL_RES* mResult[MaxTable];
81
82 void userWhereClauseToDataStream(const Key& key, resip::DataStream& ds) const;
83 void tlsPeerIdentityWhereClauseToDataStream(const Key& key, resip::DataStream& ds) const;
84};
85
86}
87#endif
88
89/* ====================================================================
90 * The Vovida Software License, Version 1.0
91 *
92 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
93 *
94 * Redistribution and use in source and binary forms, with or without
95 * modification, are permitted provided that the following conditions
96 * are met:
97 *
98 * 1. Redistributions of source code must retain the above copyright
99 * notice, this list of conditions and the following disclaimer.
100 *
101 * 2. Redistributions in binary form must reproduce the above copyright
102 * notice, this list of conditions and the following disclaimer in
103 * the documentation and/or other materials provided with the
104 * distribution.
105 *
106 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
107 * and "Vovida Open Communication Application Library (VOCAL)" must
108 * not be used to endorse or promote products derived from this
109 * software without prior written permission. For written
110 * permission, please contact vocal@vovida.org.
111 *
112 * 4. Products derived from this software may not be called "VOCAL", nor
113 * may "VOCAL" appear in their name, without prior written
114 * permission of Vovida Networks, Inc.
115 *
116 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
117 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
118 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
119 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
120 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
121 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
122 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
123 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
124 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
125 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
126 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
127 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
128 * DAMAGE.
129 *
130 * ====================================================================
131 */
virtual TlsPeerIdentityRecord getTlsPeerIdentity(const Key &key) const
virtual Key firstTlsPeerIdentityKey()
virtual bool addUser(const Key &key, const UserRecord &rec)
virtual Key nextUserKey()
virtual Key firstUserKey()
virtual int singleResultQuery(const resip::Data &queryCommand, std::vector< resip::Data > &fields) const
MySqlDb(const resip::ConfigParse &config, const resip::Data &dbServer, const resip::Data &user, const resip::Data &password, const resip::Data &databaseName, unsigned int port, const resip::Data &customUserAuthQuery)
virtual UserRecord getUser(const Key &key) const
virtual bool addTlsPeerIdentity(const Key &key, const TlsPeerIdentityRecord &rec)
virtual resip::Data getUserAuthInfo(const Key &key) const
virtual Key nextTlsPeerIdentityKey()
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